<?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;
}
}
PHP Yii 框架抽奖列表 大转盘抽奖接口(附源码)
于 2022-11-02 11:06:32 首次发布