ReleaseController.class.php 2.22 KB
<?php
/**
 * Created by PhpStorm.
 * User: 大熊
 * Date: 2018/5/17
 * Time: 15:05
 */

namespace Apicp\Controller\News;

use Apicp\Controller\AbstractController;
use Common\Common\Constant;
use Common\Common\NewsHelper;
use Common\Service\ArticleService;
use Common\Service\ClassService;
use Think\Log;

class ReleaseController extends AbstractController
{
    public function index_post()
    {
        $param = I('post.');

        // 获取数据信息
        $service = new ArticleService();
        $data = $service->get($param['article_id']);

        // 不为定时发布时不做处理
        if ($data['news_status'] != Constant::NEWS_STATUS_TIMING_RELEASE) {
            $this->_result = ['state' => true];
            return true;
        }

        // 判断素材状态,若转码成功则为发布状态,否则为预发布状态
        $updateData = ['news_status' => Constant::NEWS_STATUS_SEND];
        if ($data['convert_status'] == Constant::FILE_STATUS_CONVERT) {
            $updateData['news_status'] = Constant::NEWS_STATUS_READY_SEND;
        }

        $service->update($param['article_id'], $updateData);

        // 当为发布时
        if ($updateData['news_status'] == Constant::NEWS_STATUS_SEND) {
            try {
                // 获取顶级分类名称
                $classServ = new ClassService();
                $class = $classServ->getTopClass($data['class_id']);
                $data['class_name'] = $class['class_name'];

                // 发送未读提醒
                if ($data['is_notice'] == Constant::NEWS_IS_NOTICE_TRUE) {
                    $newsHelper = &NewsHelper::instance();
                    list($uids_all, $uids_read, $uids_unread) = $newsHelper->getReadData($param['article_id']);
                    $newsHelper->sendUnreadMsg($uids_unread, $data);
                }

                // RPC推送到运营中心
                if ($data['is_recommend'] == Constant::NEWS_IS_RECOMMEND_TRUE) {
                    $service->addNewsRpc($param['article_id'], []);
                }
            } catch (\Exception $e) {
                Log::record('头条立即发布错误'.$e->getMessage());
            }
        }

        $this->_result = ['state' => true];
        return true;
    }
}