<?php /** * 【后台】快速发布接口 * Created by PhpStorm. * User: yingcai * Date: 2018/1/16 * Time: 上午10:19 */ namespace Apicp\Controller\Room; use Common\Common\Constant; use Common\Service\CronService; use Common\Service\MainService; use Common\Service\RangeService; class PublishController extends AbstractController { /** * Publish * @author houyingcai * @desc 快速发布接口 * @param Int lm_id:true:1 直播活动ID * @return bool */ public function Index_post() { $lmId = I('post.lm_id', 0, 'rintval'); // 直播ID不能为空 if (!$lmId) { E('_EMPTY_LIVE_ID'); } $mainServ = new MainService(); // 判断是否还有一条直播活动 $hasAnotherLive = $mainServ->get_by_conds(['live_status' => Constant::LIVE_STATUS_PUBLISHED]); if (!empty($hasAnotherLive)) { E('_ERR_ONLY_ONE_LIVE_EVENT_CAN_BE_PLAYED_AT_THE_SAME_TIME'); } // 获取直播信息 $mainDetail = $mainServ->get($lmId); // 直播信息不存在 if (empty($mainDetail)) { E('_ERR_LIVE_IS_NOT_EXIST'); } // 不是草稿不允许发布 if ($mainDetail['live_status'] != Constant::LIVE_STATUS_DEAFT) { E('_ERR_LIVE_STATUS_NOT_DEAFT'); } // 判断开始时间 if ($mainDetail['start_time'] <= MILLI_TIME) { E(L('_ERR_PARAMS_NON_COMPLIANT', ['name' => '开始时间', 'why' => '不得早于当前时间'])); } // 更新主表的直播状态 $mainServ->update($lmId, ['live_status' => Constant::LIVE_STATUS_PUBLISHED]); // 获取权限范围 $rangeServ = new RangeService(); $range = $rangeServ->getData(['lm_id' => $lmId]); // 格式化权限数据 $range = $this->formatRangeData($range); // 发布时推送消息提醒 if (Constant::NOTICE_POSTING_TRUE == $mainDetail['notice_posting']) { $mainServ->pushMsg($mainDetail, $range); } $cronServ = new CronService(); // 直播开始前 (分钟)推送消息提醒 if ($mainDetail['notice_will_start'] > 0) { // 直播开始前 推送消息的时间点 $cronServ->createCron( $mainDetail['lm_id'], 'live_notice_will_start', Constant::TYPE_LIVE_WILL_START, $mainDetail['start_time'] - $mainDetail['notice_will_start'] * 60 * 1000 ); } // 直播开始时推送消息 if (Constant::NOTICE_START_TRUE == $mainDetail['notice_start']) { $cronServ->createCron( $mainDetail['lm_id'], 'live_notice_start', Constant::TYPE_LIVE_START, $mainDetail['start_time'] ); } if (Constant::RECOMEND_TRUE == $mainDetail['recomend']) { // 移动端首页推荐 $mainServ->openOrCloseRecommender($mainDetail, $range); } return true; } /** * 格式化权限数据 * @param array $range 权限范围 * @return array */ private function formatRangeData($range) { $right = []; // 非全公司 if (Constant::RANGE_IS_ALL_TRUE != $range['is_all']) { $right['uids'] = !empty($range['user_list']) ? array_column($range['user_list'], 'uid') : ''; $right['dp_ids'] = !empty($range['dp_list']) ? array_column($range['dp_list'], 'dp_id') : ''; $right['job_ids'] = !empty($range['job_list']) ? array_column($range['job_list'], 'job_id') : ''; $right['role_ids'] = !empty($range['role_list']) ? array_column($range['role_list'], 'role_id') : ''; $right['tag_ids'] = !empty($range['tag_list']) ? array_column($range['tag_list'], 'tag_id') : ''; } else { $right['is_all'] = Constant::RANGE_IS_ALL_TRUE; } return $right; } }