RemindController.class.php 2.55 KB
<?php
/**
 * 直播观看批量提醒接口
 * Created by PhpStorm.
 * User: yingcai
 * Date: 2018/1/15
 * Time: 下午3:15
 */

namespace Apicp\Controller\Room;

use Common\Common\Constant;
use Common\Service\MainService;
use Common\Service\RangeService;

class RemindController  extends AbstractController
{
    /** @var MainService */
    protected $mainServ;
    /** @var RangeService */
    protected $rangeServ;

    public function before_action($action = '')
    {

        if (!parent::before_action($action)) {

            return false;
        }

        // 实例化直播表
        $this->mainServ = new MainService();
        // 实例化观看直播权限范围表
        $this->rangeServ = new RangeService();

        return true;
    }

    /**
     * Remind
     * @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');
        }

        // 获取直播信息
        $mainDetail = $this->mainServ->get($lmId);

        // 直播信息不存在
        if (empty($mainDetail)) {

            E('_ERR_LIVE_IS_NOT_EXIST');
        }

        // 格式化直播状态
        $live_status = $this->mainServ->live_status(
            $mainDetail['live_status'],
            $mainDetail['start_time']
        );

        // 不是未开始和进行中的直播,不能提醒
        if (!in_array($live_status, [
            Constant::LIVE_WEB_STATUS_NOT_START,
            Constant::LIVE_WEB_STATUS_ING
        ])) {

            E('_ERR_LIVE_REMIND_STATUS');
        }

        // 批量发布提醒消息
        $this->remind_live($mainDetail);

        return true;
    }

    /**
     * 批量发布提醒消息
     * @param array $mainDetail 直播详情数组
     * @return bool
     */
    protected function remind_live($mainDetail)
    {
        // 获取未参与列表
        list(, $uids_unwatch) = $this->rangeServ->getWatchDataUids($mainDetail['lm_id']);

        $params = [
            'uids' => $uids_unwatch,
            'lm_id' => $mainDetail['lm_id'],
            'name' => $mainDetail['name'],
            'start_time' => $mainDetail['start_time'],
            'estimated_duration' => $mainDetail['estimated_duration'],
            'desc' => $mainDetail['desc'],
        ];

        // 发送消息
        $this->mainServ->sendMsg($params, MainService::MSG_REMAIND_NO_JOIN_USERS);

        return true;
    }
}