DefaultController.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace mobile\modules\live\controllers;
  3. use common\Helps\Time;
  4. use common\models\CategoryCity;
  5. use mobile\modules\live\base\BaseController;
  6. use Yii;
  7. use common\models\Live;
  8. use common\models\House;
  9. /**
  10. * Default controller for the `dinglongwan` module
  11. */
  12. class DefaultController extends BaseController
  13. {
  14. /**
  15. * 直播模块首页
  16. * Renders the index view for the module
  17. * @return string
  18. */
  19. public function actionIndex()
  20. {
  21. //获取模块内容
  22. $module = Yii::$app->hostserver->module;
  23. $input = Yii::$app->request->get();
  24. if (!empty($input['city'])) {
  25. $cmodel = new \common\models\CategoryCity();
  26. $input['city'] = array_column($cmodel->GetAllSon($input['city']), 'id');
  27. }
  28. $lmodel = new Live();
  29. //获取所有直播地区
  30. $res = $lmodel->getListArea();
  31. if (!empty($res)) {
  32. foreach ($res as &$val) {
  33. $val['pid'] = CategoryCity::find()->select(['pid'])->andWhere(['del' => 1, 'id' => $val['city']])->asArray()->one()['pid'];
  34. if (!empty($val['pid'])) $val['house']['f'] = CategoryCity::find()->select(['id', 'city_name'])->andWhere(['del' => 1, 'id' => $val['pid']])->asArray()->one();
  35. }
  36. }
  37. $c = array_column($res, 'house');
  38. $province = array_column($c, 'f', 'province');
  39. $data = $lmodel->showList($input);
  40. if (!empty($data)) {
  41. foreach ($data as &$val) {
  42. $val['pid'] = CategoryCity::find()->select(['pid'])->andWhere(['del' => 1, 'id' => $val['city']])->asArray()->one()['pid'];
  43. if (!empty($val['pid'])) $val['house']['f'] = CategoryCity::find()->select(['id', 'city_name'])->andWhere(['del' => 1, 'id' => $val['pid']])->asArray()->one();
  44. $val['state'] = Time::getLiveState($val['video_url'], $val['time']);
  45. $house = House::findOne($val['hid']);
  46. if (!empty($house['area'])) {
  47. $val['swt'] = $house['area'];
  48. }else{
  49. $val['swt'] = $house['city'];
  50. }
  51. }
  52. }
  53. return $this->render($this->action->id, [
  54. 'module' => $module['module'],
  55. 'Data' => $data,
  56. 'province' => isset($province) ? $province : '',
  57. ]);
  58. }
  59. }