PHP Yii 框架抽奖列表 大转盘抽奖接口(附源码)

<?php
/**
 * Class LotteryController
 * AppLication: LotteryController
 * Author:C 
 */

class LotteryListController extends BaseLotteryController
{

    /**
     * AppLication: actionIndex
     * Author: C
     * @throws CException 
     * 抽奖列表,包含 用户可见范围
     */
    public function actionIndex()
    {
        $json = $this->json;
        self::isRequired(array('userid', 'eid'), true);
        $allSee = []; 
        //取可见范围 
        $cache = new LotteryListCache(['eid' => $this->eid]);
        $userinfo = new Userinfo();
        $user = $userinfo->queryCache($this->uid, ['did','lableid'], $this->eid);
        $assigns = [
            'prize_configure' => ['field' => 'toall', 'toall' => '1,2'],
            'isrange' => '1',
            'uid' => $this->uid,
            'did' => empty($user['did']) ? '0' : '0,' . $user['did'],
            'lid' => $user['lableid'],
        ];
        $lotteryId =  $cache->getAsID($assigns,'');
        if (empty($lotteryId)){
            $lotteryId = [0];
        }
        $redisCache = Yii::app()->redisCache;
        $prizeConfigSet = [];

        foreach ($lotteryId as $key => $val){
            $prizeConfigSet[$key] = $redisCache->hgetall((new Lottery())->getRedisKey($json['eid'],$val),$val);
        }
        $lotterySql = 'select id,award_name,frequency,logo,consume_score,start_time,end_time,prize from {{prize_configure}} where obj_type !='.Lottery::OBJ_TYPE_TRAIN.' and isdelete = '.Lottery::ISDELETE_NORMAL.' and switch = 1 AND toall = 1  AND eid = ' . $json['eid'];
        $lotteryRes = self::queryPagesBase($lotterySql, [] , ' order by  id desc', false);
        $lotteryRes['data'] = array_merge($lotteryRes['data'],array_filter($prizeConfigSet));

		// 重新组装数据
        foreach($lotteryRes['data'] as $key => $val){
            $allSee[$key]['id'] = $val['id'];
            $allSee[$key]['awardName'] = $val['award_name'];
            $allSee[$key]['logo'] = $this->attachmentUrl($val['logo']);
            $allSee[$key]['start_time'] = $val['start_time'];
            $allSee[$key]['end_time'] = $val['end_time'];
            $stock = json_decode($val['prize'], true);
            $arrColum = array_column($stock, 'stock');
            $allSee[$key]['surplusStock'] = strval(array_sum($arrColum));
        }
        $score_record = Yii::getTableByNum('score_record', $json['eid']);  //模表
        $scoreCountSql = "SELECT sum(addscore) FROM {$score_record} WHERE eid= " . $json['eid'] . " AND uid = '" . $json['userid'] . "' ";
        $scoreCount = Yii::app()->db->createCommand($scoreCountSql)->queryScalar();
        $allSeeRow['data']['lotteryList'] = array_values($allSee);
        $allSeeRow['counts'] = $lotteryRes['counts'];
        $allSeeRow['data']['scoreCount'] = $scoreCount;
        $allSeeRow['data']['wechat'] = Enterprise::getSecdomain($this->eid, 'wechat');
        self::echojson($allSeeRow);
    }

 	/**
     * AppLication: getRedisKey
     * Author:C
     * @param $eid
     * @param $id
     * @return string 
     * 获取redis 的key
     */
    public function getRedisKey($eid,$id){
        return  'lottery'.':'.$eid.':'.$id;
    }
}

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

付煜晨

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值