123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234 |
- <?php
- /**
- * Created by PhpStorm.
- * User: 201901
- * Date: 2020/3/3
- * Time: 15:01
- */
- namespace backend\controllers;
- use backend\base\CommonController;
- use backend\base\Help;
- use backend\server\UploadFile;
- use common\models\CategoryCity;
- use common\models\Live;
- use Yii;
- class LiveController extends CommonController
- {
- /**
- * 直播管理页面
- * @return string
- */
- public function actionLive()
- {
- return $this->render('live');
- }
- /**
- * 直播管理数据
- * @return mixed
- */
- public function actionLiveform()
- {
- $model = new Live();
- $rows = $model->getList(Yii::$app->request->post());
- if ($rows != null) {
- foreach ($rows as &$val) {
- $val['create_at'] = date('Y-m-d H:i', $val['create_at']);
- }
- return Help::JsonData(0, Yii::t('app', 'get_success'), $model->Total(Yii::$app->request->post()), $rows);
- }
- return Help::JsonCode(Help::ERROR, Yii::t('app', 'get_error'));
- }
- /**
- * 直播管理添加页面
- * @return string
- */
- public function actionLiveadd()
- {
- $city = $this->City();
- return $this->render('liveadd', ['city' => $city]);
- }
- /**
- * 直播管理添加数据
- * @return mixed
- */
- public function actionLiveaddform()
- {
- $input = Yii::$app->request->post();
- $model = new Live();
- $model->scenario = 'add';
- if (is_object($model)) {
- if ($model->load($input, '') && $model->save()) return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'add_success'));
- }
- return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'add_error'), $model->errors);
- }
- /**
- * 直播管理修改页面
- * @return string
- */
- public function actionLiveedit()
- {
- $model = new Live();
- $input = Yii::$app->request->get();
- $row = $model::findOne($input['id']);
- if ($row != null) {
- $city = $this->City();
- return $this->render('liveedit', ['model' => $row, 'city' => $city]);
- }
- }
- /**
- * 直播管理修改数据
- * @return mixed
- */
- public function actionLiveeditform()
- {
- $input = Yii::$app->request->post();
- $model = new Live();
- if (!empty($input)) {
- $row = $model::findOne($input['id']);
- if ($row != null) {
- if ($row->load($input, '') && $row->save(false)) return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'edit_success'));
- }
- }
- return Help::JsonCode(Help::ERROR, Yii::t('app', 'edit_error'), $row->errors);
- }
- /**
- * 直播管理删除
- * @return mixed
- */
- public function actionSetlive()
- {
- $model = new Live();
- $input = Yii::$app->request->post();
- $row = $model::findOne($input['id']);
- if ($row != null) {
- switch ($input['type']) {
- case 'del':
- if ($row->delete()) return Help::JsonCode(Help::SUCCESS, '删除成功');
- break;
- case 'sort':
- if (is_numeric($input['sort'])) {
- $row->sort = $input['sort'];
- }
- break;
- }
- if ($row->save(false)) return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'edit_success'));
- }
- return Help::JsonCode(Help::ERROR, '操作失败');
- }
- /**
- * 选择区域
- * @return mixed
- */
- private function City()
- {
- $city = CategoryCity::find()->select(['id', 'city_name'])
- ->andWhere(['del' => 1, 'state' => 1, 'pid' => 0])
- ->orderBy(['sort' => SORT_DESC])->asArray()->all();
- if (!empty($city)) {
- foreach ($city as &$val) {
- $val['son'] = CategoryCity::find()->select(['id', 'city_name'])
- ->andWhere(['del' => 1, 'state' => 1, 'pid' => $val['id']])
- ->orderBy(['sort' => SORT_DESC])->asArray()->all();
- }
- }
- return $city;
- }
- //直播评论页面
- public function actionLiveremark()
- {
- $lmodel = new \common\models\Live();
- $data = $lmodel::findOne(Yii::$app->request->get('id'));
- return $this->render('liveremark', ['liveremark_check' => $data['remark_check'], 'live_id' => $data['id']]);
- }
- //直播评论数据
- public function actionLiveremarkform()
- {
- $input = Yii::$app->request->post();
- // p($input);die;
- $rmodel = new \common\models\LiveRemark();
- $rmodel->is_show = 1;
- $data = $rmodel->getList($input);
- if (!empty($data['data'])) {
- return Help::JsonData(0, Yii::t('app', 'get_success'), $data['count'], $data['data']);
- }
- return Help::JsonCode(Help::ERROR, Yii::t('app', 'get_error'));
- //TOO
- }
- //开启人工验证后的评论数据
- public function actionCheckstart()
- {
- $input = Yii::$app->request->post();
- if (empty($input['returntime'])) exit();
- set_time_limit(0);//无限请求超时时间
- $startTime = time();
- while (true) {
- sleep(1);
- // usleep(5000000);//0.5秒
- //若得到数据则马上返回数据给客服端,并结束本次请求
- $rmodel = new \common\models\LiveRemark();
- $rmodel->is_show = 2;
- $data = $rmodel->getList($input);
- if ($data['count'] - $input['oldcount'] > 0) {
- $input['oldcount'] == 0 ? $data['data'] = array_slice($data['data'], 0) : $data['data'] = array_slice($data['data'], 0, -$input['oldcount']);
- // $data['data'] = array_slice($data['data'],0,-$input['oldcount']);
- // p($data);die;
- return Help::JsonCode(Help::SUCCESS, '加载成功', $data);
- }
- //服务器($_POST['time']*0.5)秒后告诉客服端无数据
- if (time() - $startTime >= $input['returntime']) {
- return Help::JsonCode(Help::ERROR, '暂无数据', '');
- }
- }
- }
- //修改人工审核
- public function actionAllremarkcheck()
- {
- $input = Yii::$app->request->post();
- $lmodel = new \common\models\Live();
- $data = $lmodel::findOne($input['id']);
- if (!empty($data)) {
- $data->remark_check = $input['state'];
- if ($data->save(false)) return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'edit_success'));
- }
- return Help::JsonCode(Help::ERROR, Yii::t('app', 'edit_error'));
- }
- //官方主持人发送 initiator 1、游客发送 2、官方发送
- public function actionComperesend()
- {
- $input = Yii::$app->request->post();
- $input['is_show'] = 2;
- $input['initiator'] = 1;
- $lrmodel = new \common\models\LiveRemark();
- $lrmodel->load($input, '');
- if ($lrmodel->validate() && $lrmodel->save()) {
- return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'add_success'));
- }
- return Help::JsonCode(Help::ERROR, Yii::t('app', 'add_error'));
- }
- }
|