SendDrawController.class.php 1.97 KB
<?php
/**
 * 【积分抽奖-手机端】中奖发消息
 *
 * @author: heyuelong
 * @date: 2018年3月26日11:18:11
 */

namespace Api\Controller\Activity;

use Common\Common\Constant;
use Common\Service\ActivityService;
use Common\Service\RecordService;

class SendDrawController extends \Api\Controller\AbstractController
{

    /** @var ActivityService */
    protected $_activity_service;
    /** @var RecordService */
    protected $_record_service;

    public function before_action($action = '')
    {

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

            return false;
        }

        // 实例化活动
        $this->_activity_service = new ActivityService();
        // 实例抽奖记录表
        $this->_record_service = new RecordService();
        return true;
    }

    /**
     * @return bool
     */
    public function Index_post()
    {
        $lr_id = I('post.lr_id', 0);
        if (empty($lr_id)) {
            E('_EMPTY_ACTIVITY_LR_ID');
        }

        $conds = [
            'lr_id' => $lr_id,
            'uid' => $this->uid,
            'lr_stauts' => '0'
        ];

        $record_info = $this->_record_service->get_by_conds($conds);

        // 获取活动详细内容
        $info = $this->_activity_service->get_by_conds(
            [
                'ac_id' => $record_info['ac_id'],
                'activity_status > ?' => 0
            ]
        );

        // 如果已经中奖
        if (Constant::HAVE_PRIZE == $record_info['is_prize']) {

            // 消息参数
            $params = [
                'uids' => $this->uid,
                'ac_id' => $record_info['ac_id'],
                'name' => $record_info['lp_name'],
                'title' => $info['title'],
                'start_time' => $info['start_time'],
                'end_time' => $info['end_time'],
                'integral' => $info['integral']
            ];

            $this->_record_service->send_msg($params, Constant::MSG_PRIZE);
        }

        return true;
    }

}