123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864 |
- <?php
- /**
- * 看电视 得勋章 赢大奖(由集卡活动改写)
- * @author xusong
- * @version 0.0.1
- * @datetime 2019.07.25
- */
- namespace Home\Logic\Activityv2;
- class LookTvLogic extends BaseLogic
- {
- private $act_id;
- private $uid;
- private $userinfo;
- private $activityinfo;
- private $vip_level;
- /**
- * [_initialize 前置操作-继承公共前置方法]
- * @author Devil
- * @blog http://gong.gg/
- * @version 0.0.1
- * @datetime 2016-12-03T12:39:08+0800
- */
- public function _initialize() {
- // 调用父类前置方法
- parent::_initialize();
- $this->uid = trim(I('uid'));
-
- if(!$this->userinfo = M('iptv_users')->where(['uid'=>$this->uid])->find()){
- $this->responseError('uid 参数非法');
- }
- $act_id = I('act_id',0,'intval');
- $act_name = I('act_code');
- if($act_id){
- $where['id'] = $act_id;
- }else{
- $where['activity_code'] = $act_name;
- }
- if(!$activityinfo = M('activity_v2')->where($where)->find()){
- $this->responseError('act_id 或 act_code 参数非法');
- }
-
- $this->act_id = $activityinfo['id'];
- $this->activityinfo = $activityinfo;
- //检查vip鉴权方式
- $this->vip_level = I('is_vip') >= 1 ? 1 : 0;
- }
- /**
- * 获取活动状态
- * @return [type] [description]
- */
- public function getActStatus()
- {
- //开始时间结束时间未作限制
- if($this->activityinfo['is_enable'] == 1){
- $this->responseSuccess(1, "请求成功!");
- }else{
- $this->responseSuccess(-1, "请求成功!");
- }
- }
-
- /**
- * 提交用户资料
- * @return [type] [description]
- */
- public function setUserInfo()
- {
- $phone = trim(I('phone'));
- if (empty($phone)) {
- $this->responseError('参数错误!');
- }
- //检测手机号码是否正确
- if (!preg_match('/^1[345789]\d{9}$/ims', $phone)) {
- $this->responseError('手机号填写有误!');
- }
- //更新用户活动手机号码
- $where = array(
- 'uid'=>$this->uid,
- 'act_id'=>$this->act_id,
- );
- if ($id = M('activity_user_v2')->where($where)->getField('id')){
- $update['user_phone']= $phone;
- $update['updated_at']= date('Y-m-d H:i:s');
- if(M('activity_user_v2')->where(['id'=>$id])->save($update)===false){
- Writelog(M()->getLastSql(),'sql','prize');
- $this->responseError("更新失败!");
- }
- }else{
- $insert_data = array(
- 'uid'=>$this->uid,
- 'act_id'=>$this->act_id,
- 'user_phone'=>$phone,
- 'created_at'=>date('Y-m-d H:i:s'),
- 'updated_at'=>date('Y-m-d H:i:s')
- );
- if(!M('activity_user_v2')->add($insert_data)){
- Writelog(M()->getLastSql(),'sql','prize');
- $this->responseError("登记失败!");
- }
- }
- $this->responseSuccess(0, "登记成功!");
- }
-
- /**
- * 提交用户资料
- * @return [type] [description]
- */
- public function setUserInfoByphone()
- {
- $phone = trim(I('phone'));
- $address = trim(I('address'));
- $receiver = trim(I('receiver'));
- if (!($phone && $address && $receiver)) {
- $this->responseError('参数错误!');
- }
- //检测手机号码是否正确
- if (!preg_match('/^1[345789]\d{9}$/ims', $phone)) {
- $this->responseError('手机号填写有误!');
- }
- //更新用户活动手机号码
- $where = array(
- 'uid'=>$this->uid,
- 'act_id'=>$this->act_id,
- );
- if ($id = M('activity_user_v2')->where($where)->getField('id')){
- $update['user_phone']= $phone;
- $update['address'] = $address;
- $update['receiver'] = $receiver;
- $update['updated_at'] = date('Y-m-d H:i:s');
- if(M('activity_user_v2')->where(['id'=>$id])->save($update)===false){
- Writelog(M()->getLastSql(),'sql','prize');
- $this->responseError("更新失败!");
- }
- }else{
- $insert_data = array(
- 'uid'=>$this->uid,
- 'act_id'=>$this->act_id,
- 'user_phone'=>$phone,
- 'address'=>$address,
- 'receiver'=>$receiver,
- 'created_at'=>date('Y-m-d H:i:s'),
- 'updated_at'=>date('Y-m-d H:i:s'),
- );
- if(!M('activity_user_v2')->add($insert_data)){
- Writelog(M()->getLastSql(),'sql','prize');
- $this->responseError("登记失败!");
- }
- }
- $this->responseSuccess(0, "登记成功!");
- }
-
- //获取网页二维码
- public function getQrcode()
- {
- $this->responseSuccess($this->createQrcode());
- }
- /**
- * 活动规则说明
- * @return [type] [description]
- */
- public function getActivityInfo()
- {
- //获取中奖信息
- $data['rank'] = $this->prizelog('localhost');
- unset($data['act']['prize_list']);
- unset($data['act']['prize_rule']);
- //获取当前用户中奖信息
- $map['act_id'] = $this->act_id;
- $map['uid'] = $this->uid;
- $map['rule_id'] = array("neq", 0);
- //$data['my_prizes'] = M('prize_log_v2')->field('prize_id,prize_name')->where($map)->select();
- $my_prizes = M('prize_log_v2')->field('created_at,prize_id')->where($map)->select() ? : array();
- if($my_prizes){
- foreach ($my_prizes as $k=>$value) {
- $my_prizes[$k]['prize_name'] = $prizes[$value['prize_id']]['prize_name'];
- $data['my_prizes'][] = ['prize_id'=>$value['prize_id'],'prize_name'=>$prizes[$value['prize_id']]['prize_name']];
- }
- }
- $data['collects'] = $this->_getUserCollect();
- //获取用户剩余中奖次数
- $data['remain_chance'] = $this->_getUserChance();
- $this->responseSuccess($data);
- }
- //集物
- public function collect()
- {
- if(I('run')!='complate'){
- $rand = rand(1,2);
- if($rand != 1){
- $this->responseError('未抽中!', -1);
- }
- }
- $type = I('type');
- $lists = ['gx'=>1,'yy'=>2,'cy'=>3,'ds'=>4,'kx'=>5];
- $collect_id = $lists[$type] ?: 0 ;
- if(empty($collect_id)){
- $this->responseError('type 类型错误!', -1);
- }
- $where = array(
- 'act_id' =>$this->act_id,
- 'uid' =>$this->uid,
- 'collect_id'=>$collect_id
- );
- //判断是否收集到了此卡
- if(M('activity_collect')->where($where)->find()){
- $this->responseError('您已获得过该卡片,不可重复获取哟!', -1);
- }
- // echo $collect_id;die;
- $collect_list = json_decode($this->activityinfo['collect_list'],TRUE);
- $collect_list = array_column($collect_list,null,'collect_id');
- $results[] = array(
- 'collect_id'=>$collect_list[$collect_id]['collect_id'],
- 'collect_name'=>$collect_list[$collect_id]['collect_name'],
- 'collect_img'=>$collect_list[$collect_id]['collect_img'] ? __MY_URL__.$collect_list[$collect_id]['collect_img'] : '',
- );
- //写入集物表
- foreach ($results as $row) {
- $insert[] = array(
- 'act_id'=>$this->act_id,
- 'uid' =>$this->uid,
- 'collect_id'=>$row['collect_id'],
- 'operate' =>1,
- 'date' =>date('Ymd'),
- 'created_at'=>date('Y-m-d H:i:s')
- );
- }
- M('activity_collect')->addAll($insert);
- $return_data = ['collect_status'=>'yes','collect_list'=>$results];
- $this->responseSuccess($return_data);
- }
- //获取集物信息
- //集物
- public function getUserCollects()
- {
- $collects = $this->_getUserCollect();
- if($collects){
- $this->responseSuccess($collects);
- }else{
- $this->responseError('没有抽奖记录!', -3, ['error'=>'error']);
- }
- }
- private function _getUserCollect()
- {
- //写入集物表
- $where = array(
- 'act_id'=>$this->act_id,
- 'uid' =>$this->uid,
- );
- $collects = M('activity_collect')->where($where)->group('collect_id')->getField('collect_id,sum(operate) as num');
- $collects = $collects ? : [];
- // echo M()->getLastSql();
- $allCollects = json_decode($this->activityinfo['collect_list'],TRUE);
- if(!$allCollects){
- $this->responseError('没有集物列表!', -3, ['error'=>'error']);
- }
- $collect_id_sum = $should_collect_sum = 0 ;
- foreach ($allCollects as $key => $row) {
- $return[$key] = array(
- 'collect_id'=>$row['collect_id'],
- 'collect_name'=>$row['collect_name'],
- 'collect_img'=>$row['collect_img'] ? __MY_URL__.$row['collect_img'] : '',
- 'num'=>$collects[$row['collect_id']] > 0 ? $collects[$row['collect_id']] : 0
- );
- if($collects[$row['collect_id']] > 0){
- $collect_id_sum += $row['collect_id'];
- }
- $should_collect_sum += $row['collect_id'];
- }
- if($collect_id_sum == $should_collect_sum){
- $collect['complate'][] = array(
- 'exchange_id'=>1,
- 'collect_ids'=>implode(',',[1,2,3,4,5])
- );
- // $collect['complate'][] = array(
- // 'exchange_id'=>2,
- // 'collect_ids'=>implode(',',[1,2,3,4,5,6,7,8,9])
- // );
- $collect['collect'] = $return;
- }else{
- $collect['complate'] = [];
- $collect['collect'] = $return;
- }
- return $collect;
- }
- /**
- * 获取虚拟道具卡
- * @param [type] $uid [description]
- * @return [type] [description]
- */
- public function getVitualCard()
- {
- if($daoju_name = trim(I('daoju_name'))){
- if(!in_array($daoju_name, ['reborn_card'])){
- $this->responseError('daoju_name 参数非法');
- }
- } else {
- $this->responseError('daoju_name 参数非法');
- }
- $remain = $this->_getVitualCard($daoju_name);
- $this->responseSuccess($remain,'剩余道具数量');
- }
-
- /**
- * 获取虚拟卡
- * @param [type] $uid [description]
- * @return [type] [description]
- */
- private function _getVitualCard($daoju_name)
- {
- $map['uid'] = $this->uid;
- $map['act_id'] = $this->act_id;
- $map['date'] = date('Ymd');
- $map['name'] = $daoju_name;
- $daoju = M('activity_daoju')->field('operate,count(*) as total')->where($map)->group('operate')->select();
- $daoju = array_column($daoju, 'total', 'operate');
- $count = $daoju['add'] - $daoju['reduce'];
- if($daoju_name == 'reborn_card'){
- if($this->vip_level == 2){
- $remain_chance = 2 + $count;
- }elseif($this->vip_level ==1){
- $remain_chance = 1 + $count;
- }else{
- $remain_chance = 0 + $count;
- }
- }
- return $remain_chance > 0 ? $remain_chance : 0;
- }
- /**
- * 获取用户当日抽奖次数
- * @param [type] $uid [description]
- * @return [type] [description]
- */
- private function _getUserChance()
- {
- $map['uid'] = $this->uid;
- $map['act_id'] = $this->act_id;
- $map['date'] = date('Ymd');
- $chance = M('activity_take_part')->where($map)->getField('number') ? : 0;
- // var_dump($chance);die;
- if($this->activityinfo['is_test'] ==1){
- if(I('is_test') ==1){
- return $remain_chance = 1000 - $chance;
- }
- }
-
- if($this->vip_level >=1){
- $remain_chance = ($this->vip_level * $this->activityinfo['vip_chance']) - $chance;
- }else{
- $remain_chance = $this->activityinfo['novip_chance'] - $chance;
- }
- return $remain_chance > 0 ? $remain_chance : 0;
-
- }
- /**
- * 获取用户当日抽奖次数
- * @param [type] $uid [description]
- * @return [type] [description]
- */
- private function _useUserChance()
- {
- $map['uid'] = $this->uid;
- $map['act_id'] = $this->act_id;
- $map['date'] = date('Ymd');
- $data = M('activity_take_part')->where($map)->find();
- // var_dump($chance);die;
- if($data){
- $data['number'] += 1;
- $bool = M('activity_take_part')->save($data);
- }else{
- $map['number'] = 1;
- $map['created_at'] = date('Y-m-d H:i:s');
- $bool = M('activity_take_part')->add($map);
- }
- if(!$bool){
- $this->responseError('服务异常',-1);
- }
- }
-
- /**
- * 使用虚拟道具
- * @param [type] $uid [description]
- * @return [type] [description]
- */
- public function useVitualCard()
- {
- $remain_reborn_card = $this->_getVitualCard('reborn_card');
- if($remain_reborn_card >= 1){
- $insert = array(
- 'uid' => $this->uid,
- 'act_id' => $this->act_id,
- 'date' => date('Ymd'),
- 'operate' => 'reduce',
- 'name' => 'reborn_card'
- );
- if(M('activity_daoju')->add($insert)){
- $this->responseSuccess();
- }else{
- $this->responseError('网络异常!', -1);
- }
- }else{
- $this->responseError('您没有复活卡拉!', -3);
- }
- }
- /**
- * 获取用户剩余抽奖次数
- * @return [type] [description]
- */
- public function getPrizeNum()
- {
- $remain_chance = $this->_getUserChance();
- $this->responseSuccess($remain_chance);
- }
- /**
- * 所有中奖记录查询
- */
- public function prizelog($model = ''){
- $error[] = ['error' => 'error'];
- $where['pl.act_id'] = $this->act_id;
- $where['pl.prize_status'] = 1;
- $data = M('prize_log_v2')->alias('pl')
- ->join(array('left join '.C("DB_PREFIX").'activity_user_v2 as iu on iu.uid = pl.uid and iu.act_id = '.$this->act_id))
- ->where($where)
- ->order('pl.id desc')
- ->field('pl.prize_id,pl.created_at,pl.uid,iu.user_phone')
- ->select();
- $prizes = json_decode($this->activityinfo['prize_list'],TRUE);
- foreach ($prizes as $value) {
- $prize_list[$value['prize_id']] = $value;
- }
- if($data){
- foreach ($data as $key=>$value) {
- $data[$key]['prize_name'] = $prize_list[$value['prize_id']]['prize_name'];
- $data[$key]['prize_img'] = __MY_URL__.$prize_list[$value['prize_id']]['prize_img'];
- }
- }
- //增加虚拟中奖信息
- $default_data = $this->getPrizeDefault();
-
- if($data || $default_data){
- if($data){
- foreach ($data as $k=>$v){
- if($v['user_phone']){
- $data[$k]['user_phone'] = substr_replace($v['user_phone'],'****',3,4);
- }else {
- $data[$k]['user_phone'] = substr_replace($v['uid'],'****',6);
- }
- unset($data[$k]['uid']);
- }
- }
- if($data && $default_data){
- $data = array_merge($default_data,$data);
- }else{
- $data = $data ? : $default_data;
- }
- array_multisort(array_column($data,'created_at'),SORT_DESC,$data);
- if($model == 'localhost'){
- return $data;
- }
- $this->responseSuccess($data, '查询成功!');
- }else{
- if($model == 'localhost'){
- return array();
- }
- $this->responseError('没有抽奖记录!', -3, $error);
- }
- }
- /**
- * 我的中奖记录查询
- */
- public function userPrizelog(){
- $error[] = ['error' => 'error'];
- //获取用户
- if($user_phone = M('activity_user_v2')->where(['uid'=>$this->uid,'act_id'=>$this->act_id])->getField('user_phone')){
- $phone_staus = 1;//填过
- }else{
- $phone_staus = 2;//填过
- }
- $where = array();
- $where['pl.prize_status'] = ['gt',0];
- $where['pl.uid'] = $this->uid;
- $where['pl.act_id'] = $this->act_id;
- $data = M('prize_log_v2')->alias('pl')
- ->where($where)
- ->order('pl.id desc')
- ->field('pl.prize_id,pl.created_at')
- ->select();
- // echo M()->getLastSql();die;
- $prizes = json_decode($this->activityinfo['prize_list'],TRUE);
- foreach ($prizes as $value) {
- $prize_list[$value['prize_id']] = $value;
- }
- $flag = $data ? 1 : 0;
- if($flag){
- if($data){
- foreach ($data as $k => $v){
- $data[$k]['prize_name'] = $prize_list[$v['prize_id']]['prize_name'];
- $data[$k]['prize_object'] = 'real';
- $data[$k]['show_image'] = $prize_list[$v['prize_id']]['prize_img'] ? __MY_URL__.$prize_list[$v['prize_id']]['prize_img']:null;
- unset($data[$k]['prize_id']);
- }
- }
- $return_data = array(
- 'my_prizes'=>$data,
- 'user_phone'=>['phone_status'=>$phone_staus,'user_phone'=>$user_phone ? :''],
- 'prize_status'=>$data ? 'real' : 'vitual'
- );
- $this->responseSuccess($return_data, '查询成功!');
- }else{
- $this->responseError('没有抽奖记录!', -3, $error);
- }
- }
- /**
- * 抽奖
- */
- public function prize(){
- $error[] = ['error' => 'error'];
- //查看是否抽过奖
- $where = [
- 'act_id'=>$this->act_id,
- 'uid'=>$this->uid,
- 'prize_status'=>['gt',0]
- ];
- if($prize_status=M('prize_log_v2')->where($where)->getField('prize_status')){
- //$this->responseError('您已经兑换过奖品啦!', -1);
- if($prize_status == 1){
- $res = array();
- $res['yes']['prize_name'] = '玩具大礼包'; //中奖项
- $res['yes']['prize_status'] = 'real';
- $res['yes']['prize_img'] = '';
- }else{
- $res = array();
- $res['yes']['prize_name'] = '荣誉勋章'; //中奖项
- $res['yes']['prize_status'] = 'vitual';
- $res['yes']['prize_img'] = '';
- }
- $this->responseSuccess($res, '抽奖成功!');
- }
- //判断是否有完成的集合
- $result = $this->_getUserCollect();
- if(!$result['complate']){
- $this->responseError('没有完成的集合!', -3, $error);
- }
- // $exchanges = array_column($result['complate'], null, 'exchange_id');
- // $collect_ids = $exchanges[1]['collect_ids'];
- // $collect_arr = explode(',', $collect_ids);
- // //消耗兑换卡
- // foreach ($collect_arr as $key => $value) {
- // $datalist[] = ['act_id'=>$this->act_id,'uid'=>$this->uid,'collect_id'=>$value,'operate'=>-1,'date'=>date('Ymd'),'created_at'=>date('Y-m-d H:i:s')];
- // }
- // M('activity_collect')->addAll($datalist);
- //开始抽奖
- $prize_data = $this->_get_prize();
- unset($prize_data['yes']['rule_id']);
- $this->responseSuccess($prize_data, '抽奖成功!');
- }
- private function _get_prize() {
- $result = $this->getPrizeSetDeatil();
- $this->_writePrizeLog($result);
- $res = array();
- $res['yes']['prize_name'] = $result['prize_name']; //中奖项
- $res['yes']['prize_status'] = $result['prize_object'] ? : 'none';
- $res['yes']['prize_img'] = $result['prize_img'] ? __MY_URL__.$result['prize_img'] : '';
- $res['yes']['rule_id'] = $result['rule_id'];
- return $res;
- }
-
- /**
- * @param desc 写入抽奖日志
- * @param type $result
- */
- private function _writePrizeLog(&$result) {
- $log_data['uid'] = $this->uid;
- $log_data['prize_id'] = $result['prize_id'];
- $log_data['is_vip'] = $this->vip_level;
- $log_data['act_id'] = $this->act_id;
- $log_data['created_at'] = date('Y-m-d H:i:s');
- $log_data['date'] = date('Ymd');
- $log_data['rule_id'] = $result['rule_id'];
- $log_data['prize_status'] = $result['prize_object'] == 'real' ? 1:2;
- if(!M('prize_log_v2')->add($log_data)){
- Writelog(M()->getLastSql(),'sql','activity');
- $this->responseError('系统繁忙抽奖失败', -1);
- }
- }
-
- /**
- * 返回中奖的信息
- */
- private function getPrizeSetDeatil()
- {
- $prize_list = json_decode($this->activityinfo['prize_list'],TRUE);//获取奖项设置
- if($prize_list){
- foreach ($prize_list as $row) {
- $limit_sales[$row['prize_id']] = $row;
- if($row['prize_level']== 0){
- $impossible_prize = ['prize_id'=>$row['prize_id'],'prize_name'=>$row['prize_name'],'rule_id'=>0,'prize_img'=>'','prize_status'=>0];
- }
- }
- }
- //获取所有规则
- $rules = json_decode($this->activityinfo['prize_rule'],TRUE);
- if(!$rules){
- return $impossible_prize;
- }
-
- $swithc_no = '';
- foreach ($rules as $value) {
- if($value['rule_status'] == 0){
- $swithc_no = $swithc_no. 0;
- continue;
- }
- //1.检查是否符合身份
- if(FALSE === $this->_checkRuleRole($value['rule_role'])){
- $swithc_no = $swithc_no. 1;
- continue;
- }
- //2.检查中奖日期设置
- if(FALSE === $this->_checkRuleDate($value['rule_date'])){
- $swithc_no = $swithc_no. 2;
- continue;
- }
- //3.检查时段设置
- if(FALSE === $this->_checkRuleHour($value['rule_hour'])){
- $swithc_no = $swithc_no. 3;
- continue;
- }
- //4.概率摇奖
- if(FALSE === $this->_getRandNum($value['rule_probability'])){
- $swithc_no = $swithc_no. 4;
- continue;
- }
- //5.查询是否超出当前规则下的出奖数
- if(FALSE === $this->_checkCurrentRuleSale($value)){
- $swithc_no = $swithc_no. 5;
- continue;
- }
- //6.查询是否超出奖品总数
- if(FALSE === $this->_checkGolabRule($value,$limit_sales)){
- $swithc_no = $swithc_no. 6;
- continue;
- }
- Writelog('uid: '.$this->uid.'跳出关卡: '.$swithc_no,'switch','activityv2');
- $prize = $limit_sales[$value['rule_prize_id']];
- $prize['rule_id'] = $value['rule_id'];
- return $prize;
- }
- Writelog('uid: '.$this->uid.'跳出关卡: '.$swithc_no,'switch','activityv2');
- return $impossible_prize;
- }
-
- /**
- * 获取转盘信息
- */
- public function prizeData(){
- $error[] = ['error' => 'error'];
- $data = array();
- $data['userp']['prize_num'] = $this->_getUserChance();
- $data['userp']['user_phone'] = $this->userinfo['user_phone'] ? :$this->userinfo['uid'];
- //转盘信息
- $turn_data = json_decode($this->activityinfo['prize_list'],TRUE);
- if($turn_data){
- foreach ($turn_data as $k => $v){
- if($v['prize_status'] == 0){
- unset($turn_data[$k]);
- continue;
- }
- if($v['prize_img']){
- $turn_data[$k]['prize_img'] = __MY_URL__.$v['prize_img'];
- }
- unset($turn_data[$k]['prize_num']);
- unset($turn_data[$k]['prize_level']);
- unset($turn_data[$k]['prize_status']);
- }
- $data['prize_data'] = $turn_data;
- }else{
- $this->responseError('获取失败!', -1, $error);
- }
- $this->responseSuccess($data, '查询成功!');
- }
-
- private function getPrizeDefault()
- {
- $map['pd.act_id'] = $this->act_id;
- $prizes = json_decode($this->activityinfo['prize_list'],true);
- foreach ($prizes as $key=>$v){
- $prize_list[$v['prize_id']] = $v;
- }
- // var_dump($prize_list);die;
- $data = M('prize_default_v2')->where(['act_id'=>$this->act_id])->select();
- if($data){
- foreach ($data as $value) {
- $return_data[] = array(
- 'created_at'=>$value['prize_date'],
- 'prize_name'=>$prize_list[$value['prize_id']]['prize_name'],
- 'prize_img'=>$prize_list[$value['prize_id']]['prize_img'] ? __MY_URL__.$prize_list[$value['prize_id']]['prize_img']:'',
- 'user_phone'=>substr_replace($value['phone'],'****',3,4),
- );
- }
- }
- return $return_data;
- }
-
- /**
- * @desc 检查中奖规则关于身份设置
- */
- private function _checkRuleRole($rule_role)
- {
- $role = $this->vip_level ? '会员' : '普通用户';
- if(FALSE !== strpos($rule_role, '不限')){
- return TRUE;
- }
- if($rule_role != '虚拟用户'){
- if(in_array($role, explode(',', $rule_role))){
- return TRUE;
- }
- }
- return FALSE;
- }
- /**
- * @desc 检查中奖规则关于日期
- */
- private function _checkRuleDate($rule_date)
- {
- if(FALSE !== strpos($rule_date,'每日')){
- return TRUE;
- }
- //时间段
- if(strpos($rule_date,'至')){
- $date = explode('至', $rule_date);
- if((time()>=strtotime($date[0])) && time()< strtotime($date[1])){
- return TRUE;
- }else{
- return FALSE;
- }
- }else{
- if(date('Y-m-d') == $rule_date){
- return TRUE;
- }else{
- return FALSE;
- }
- }
- }
-
- /**
- * @desc 检查中奖规则关于时间段
- */
- private function _checkRuleHour($rule_hour)
- {
- $hour = explode('至', $rule_hour);
- if((date('H:i')>= trim($hour[0])) && (date('H:i')< trim($hour[1]))){
- return TRUE;
- }else{
- return FALSE;
- }
- }
- /**
- * @desc 概率摇奖
- * @param type $rule_probability
- * @return boolean
- */
- private function _getRandNum($rule_probability)
- {
- if($rule_probability == 0){
- return FALSE;
- }
- $tmp = explode('/', $rule_probability);
- $rand_array = range(1, $tmp[1]);
- shuffle($rand_array);
- $get_randnum = array_slice($rand_array, 0, $tmp[0]);
- Writelog('uid: '.$this->uid.'抽签: '.json_encode($get_randnum),'switch','activityv2');
- if(in_array($tmp[0], $get_randnum)){
- return TRUE;
- }else{
- return FALSE;
- }
- }
- /**
- * @desc 查询符合当前规则
- */
- private function _checkCurrentRuleSale(&$rule)
- {
- //查询当前规则下的中奖数,如果为-1则无限制
- if($rule['rule_num'] == -1){
- return TRUE;
- }
- if((FALSE!==strpos($rule['rule_date'],'至')) && ($rule['rule_cycle']=='total')){
- $rule_date = explode('至', $rule['rule_date']);
- $where['rule_id'] = $rule['rule_id'];
- $where['act_id'] = $this->act_id;
- $where['date'] = ['between',[date('Ymd', strtotime($rule_date[0])),date('Ymd', strtotime($rule_date[1]))]];
- $countNum = M('Prize_log_v2')->where($where)->count();
- Writelog('当前1:'.$countNum.'规则:'.$rule['rule_num'],'info','activityv2');
- return $countNum >= $rule['rule_num'] ? FALSE : TRUE;
- }else{
- $where['date'] = date('Ymd');
- $where['rule_id'] = $rule['rule_id'];
- $where['act_id'] = $this->act_id;
- $countNum = M('Prize_log_v2')->where($where)->count();
- Writelog('当前2:'.$countNum.'规则:'.$rule['rule_num'],'info','activityv2');
- // echo M()->getLastSql();die;
- return $countNum >= $rule['rule_num'] ? FALSE : TRUE;
- }
- }
-
- /**
- * @desc 不能超过奖品总数
- */
- private function _checkGolabRule(&$rule,&$limit_sales)
- {
- if($limit_sales[$rule['rule_prize_id']]['prize_num'] == -1){
- return TRUE;
- }
- $countNum = M('Prize_log_v2')->where(['prize_id'=>$rule['rule_prize_id'],'act_id'=>$this->act_id])->count();
- // echo M()->getLastSql();die;
- Writelog('当前3:'.$countNum.'总量:'.$limit_sales[$rule['rule_prize_id']]['prize_num'],'info','activityv2');
- return $countNum >= $limit_sales[$rule['rule_prize_id']]['prize_num'] ? FALSE : TRUE;
- }
- }
|