LiveController.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: 201901
  5. * Date: 2020/3/3
  6. * Time: 15:01
  7. */
  8. namespace backend\controllers;
  9. use backend\base\CommonController;
  10. use backend\base\Help;
  11. use backend\server\UploadFile;
  12. use common\models\CategoryCity;
  13. use common\models\Live;
  14. use Yii;
  15. class LiveController extends CommonController
  16. {
  17. /**
  18. * 直播管理页面
  19. * @return string
  20. */
  21. public function actionLive()
  22. {
  23. return $this->render('live');
  24. }
  25. /**
  26. * 直播管理数据
  27. * @return mixed
  28. */
  29. public function actionLiveform()
  30. {
  31. $model = new Live();
  32. $rows = $model->getList(Yii::$app->request->post());
  33. if ($rows != null) {
  34. foreach ($rows as &$val) {
  35. $val['create_at'] = date('Y-m-d H:i', $val['create_at']);
  36. }
  37. return Help::JsonData(0, Yii::t('app', 'get_success'), $model->Total(Yii::$app->request->post()), $rows);
  38. }
  39. return Help::JsonCode(Help::ERROR, Yii::t('app', 'get_error'));
  40. }
  41. /**
  42. * 直播管理添加页面
  43. * @return string
  44. */
  45. public function actionLiveadd()
  46. {
  47. $city = $this->City();
  48. return $this->render('liveadd', ['city' => $city]);
  49. }
  50. /**
  51. * 直播管理添加数据
  52. * @return mixed
  53. */
  54. public function actionLiveaddform()
  55. {
  56. $input = Yii::$app->request->post();
  57. $model = new Live();
  58. $model->scenario = 'add';
  59. if (is_object($model)) {
  60. if ($model->load($input, '') && $model->save()) return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'add_success'));
  61. }
  62. return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'add_error'), $model->errors);
  63. }
  64. /**
  65. * 直播管理修改页面
  66. * @return string
  67. */
  68. public function actionLiveedit()
  69. {
  70. $model = new Live();
  71. $input = Yii::$app->request->get();
  72. $row = $model::findOne($input['id']);
  73. if ($row != null) {
  74. $city = $this->City();
  75. return $this->render('liveedit', ['model' => $row, 'city' => $city]);
  76. }
  77. }
  78. /**
  79. * 直播管理修改数据
  80. * @return mixed
  81. */
  82. public function actionLiveeditform()
  83. {
  84. $input = Yii::$app->request->post();
  85. $model = new Live();
  86. if (!empty($input)) {
  87. $row = $model::findOne($input['id']);
  88. if ($row != null) {
  89. if ($row->load($input, '') && $row->save(false)) return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'edit_success'));
  90. }
  91. }
  92. return Help::JsonCode(Help::ERROR, Yii::t('app', 'edit_error'), $row->errors);
  93. }
  94. /**
  95. * 直播管理删除
  96. * @return mixed
  97. */
  98. public function actionSetlive()
  99. {
  100. $model = new Live();
  101. $input = Yii::$app->request->post();
  102. $row = $model::findOne($input['id']);
  103. if ($row != null) {
  104. switch ($input['type']) {
  105. case 'del':
  106. if ($row->delete()) return Help::JsonCode(Help::SUCCESS, '删除成功');
  107. break;
  108. case 'sort':
  109. if (is_numeric($input['sort'])) {
  110. $row->sort = $input['sort'];
  111. }
  112. break;
  113. }
  114. if ($row->save(false)) return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'edit_success'));
  115. }
  116. return Help::JsonCode(Help::ERROR, '操作失败');
  117. }
  118. /**
  119. * 选择区域
  120. * @return mixed
  121. */
  122. private function City()
  123. {
  124. $city = CategoryCity::find()->select(['id', 'city_name'])
  125. ->andWhere(['del' => 1, 'state' => 1, 'pid' => 0])
  126. ->orderBy(['sort' => SORT_DESC])->asArray()->all();
  127. if (!empty($city)) {
  128. foreach ($city as &$val) {
  129. $val['son'] = CategoryCity::find()->select(['id', 'city_name'])
  130. ->andWhere(['del' => 1, 'state' => 1, 'pid' => $val['id']])
  131. ->orderBy(['sort' => SORT_DESC])->asArray()->all();
  132. }
  133. }
  134. return $city;
  135. }
  136. //直播评论页面
  137. public function actionLiveremark()
  138. {
  139. $lmodel = new \common\models\Live();
  140. $data = $lmodel::findOne(Yii::$app->request->get('id'));
  141. return $this->render('liveremark', ['liveremark_check' => $data['remark_check'], 'live_id' => $data['id']]);
  142. }
  143. //直播评论数据
  144. public function actionLiveremarkform()
  145. {
  146. $input = Yii::$app->request->post();
  147. // p($input);die;
  148. $rmodel = new \common\models\LiveRemark();
  149. $rmodel->is_show = 1;
  150. $data = $rmodel->getList($input);
  151. if (!empty($data['data'])) {
  152. return Help::JsonData(0, Yii::t('app', 'get_success'), $data['count'], $data['data']);
  153. }
  154. return Help::JsonCode(Help::ERROR, Yii::t('app', 'get_error'));
  155. //TOO
  156. }
  157. //开启人工验证后的评论数据
  158. public function actionCheckstart()
  159. {
  160. $input = Yii::$app->request->post();
  161. if (empty($input['returntime'])) exit();
  162. set_time_limit(0);//无限请求超时时间
  163. $startTime = time();
  164. while (true) {
  165. sleep(1);
  166. // usleep(5000000);//0.5秒
  167. //若得到数据则马上返回数据给客服端,并结束本次请求
  168. $rmodel = new \common\models\LiveRemark();
  169. $rmodel->is_show = 2;
  170. $data = $rmodel->getList($input);
  171. if ($data['count'] - $input['oldcount'] > 0) {
  172. $input['oldcount'] == 0 ? $data['data'] = array_slice($data['data'], 0) : $data['data'] = array_slice($data['data'], 0, -$input['oldcount']);
  173. // $data['data'] = array_slice($data['data'],0,-$input['oldcount']);
  174. // p($data);die;
  175. return Help::JsonCode(Help::SUCCESS, '加载成功', $data);
  176. }
  177. //服务器($_POST['time']*0.5)秒后告诉客服端无数据
  178. if (time() - $startTime >= $input['returntime']) {
  179. return Help::JsonCode(Help::ERROR, '暂无数据', '');
  180. }
  181. }
  182. }
  183. //修改人工审核
  184. public function actionAllremarkcheck()
  185. {
  186. $input = Yii::$app->request->post();
  187. $lmodel = new \common\models\Live();
  188. $data = $lmodel::findOne($input['id']);
  189. if (!empty($data)) {
  190. $data->remark_check = $input['state'];
  191. if ($data->save(false)) return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'edit_success'));
  192. }
  193. return Help::JsonCode(Help::ERROR, Yii::t('app', 'edit_error'));
  194. }
  195. //官方主持人发送 initiator 1、游客发送 2、官方发送
  196. public function actionComperesend()
  197. {
  198. $input = Yii::$app->request->post();
  199. $input['is_show'] = 2;
  200. $input['initiator'] = 1;
  201. $lrmodel = new \common\models\LiveRemark();
  202. $lrmodel->load($input, '');
  203. if ($lrmodel->validate() && $lrmodel->save()) {
  204. return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'add_success'));
  205. }
  206. return Help::JsonCode(Help::ERROR, Yii::t('app', 'add_error'));
  207. }
  208. }