123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862 |
- <?php
- /**
- * 佩奇拼图活动(由萌鸡快跑活动改写)
- * @author xusong
- * @version 0.0.1
- * @datetime 2019.07.25
- */
- namespace Home\Logic\Activityv2;
- class MengbaoLogic 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 参数非法');
- }
-
- $this->act_id = (int)I('act_id');
- if(!$this->activityinfo = M('Activity_v2')->where(['id'=>$this->act_id])->find()){
- $this->responseError('act_id 参数非法');
- }
- //检查vip鉴权方式
- $this->vip_level = I('is_vip') >= 0 ? I('is_vip') : 0;
- }
- public function getMengbaoList()
- {
- $page = I('page',1);
- $limit = I('limit',8);
- $count = M('activity_mengbao')->where(['is_show'=>1])->count();
- $order = I('order','id');
- if($order == 'id'){
- $order = 'id asc';
- }else{
- $order = 'score desc , id asc';
- }
- $maxPage = ceil($count/$limit);
- $error = ['error'=>'error'];
- if( ($page < 1) || ($page > $maxPage)){
- $this->responseError('没有更多萌宝资料!', -3, $error);
- }
- $data = M('activity_mengbao')->field('id as mengbao_id,name,age,image,media_id,media_num,score')->where(['is_show'=>1])->order($order)->limit(($page-1)*$limit,$limit)->select();
- foreach ($data as $key=>$value) {
- $data[$key]['image'] = __MY_URL__.$value['image'];
- }
- $this->responseSuccess($data,'萌宝资料');
- }
- /**
- * 获取活动状态
- * @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, "登记成功!");
- }
- public function vote()
- {
- $score = I('score',1);
- $mengbao_id = I('mengbao_id');
- $remain_vote_chance = $this->_getVoteChance();
- if(($remain_chance = $remain_vote_chance - $score) < 0){
- $this->responseError('您没有足够的投票次数,投票失败');
- }
- //更新萌宝获得总票数
- M('activity_mengbao')->where(['id'=>$mengbao_id])->setInc('score',$score);
- if($this->vip_level==2){
- //已投票数
- $vip_vote = M('activity_vip_vote')->where(['uid'=>$this->uid,'act_id'=>$this->act_id])->field('id,num')->find();
- $alrady_vip_vote = $vip_vote['num'] ? : 0;
- //剩余数
- $remain_vip_vote = 200 - $alrady_vip_vote;
- $diff = $remain_vip_vote - $score;
- if($diff >= 0){
- M('activity_vip_vote')->where(['id'=>$vip_vote['id']])->setInc('num',$diff);
- }else{
- M('activity_vip_vote')->where(['id'=>$vip_vote['id']])->save(['num'=>200]);
- }
- }
- //插入
- $insert_data = [
- 'act_id'=>$this->act_id,
- 'uid' =>$this->uid,
- 'num' =>$score,
- 'mengbao_id'=>$mengbao_id,
- 'created_at'=>date('Y-m-d H:i:s'),
- 'date' =>date('Ymd')
- ];
- M('activity_vote')->add($insert_data);
- $this->responseSuccess(['num'=>$remain_chance],'投票成功,去参与抽奖吧');
- }
- /**ascii码从小到大排序
- * @param array $params
- * @return bool|string
- */
- function asc_sort($params = array())
- {
- if (!empty($params)) {
- $p = ksort($params);
- if ($p) {
- $str = '';
- foreach ($params as $k => $val) {
- $str .= $k . '=' . $val . '&';
- }
- $strs = rtrim($str, '&');
- return $strs;
- }
- }
- return false;
- }
- public function checkYearVip(){
- $uid = $this->uid;
- $ip = get_client_ip();
- $mac = I('mac');
- $version = I('version');
- $params = [
- 'userid'=>$uid,
- 'skuid'=>'30441',
- 'stime'=>'20200116000000',
- 'etime'=>'20201231000000',
- 'business_id'=>'1',
- 'ip'=>$ip,
- 'mac'=>$mac
- ];
- if(empty($uid) || empty($mac) || empty($version)){
- $this->responseError('检查uid mac version 参数',-1);
- }
- $data_json = json_encode($params,JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
- $asc_sort_arr = [
- 'version'=>$version,
- 'data'=>$data_json
- ];
- $asc_sort = $this->asc_sort($asc_sort_arr);
- $secret_key = '82dawe3ihz!@~5d32s(*%aaa(#aa&jy$';
- $params_string = strtolower($asc_sort.'&secret_key='.$secret_key);
- $sign = sha1($params_string);
- $request_string = 'sign='.$sign.'&version='.$version.'&data='.$data_json;
- //测试地址
- $url = 'http://10.2.204.141:8081/cms/ever_active_product';
- $ch = curl_init($url);
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
- curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $request_string); //设置提交的字符串
- $output = curl_exec($ch);
- $error_num = curl_errno($ch);
- curl_close($ch);
- if($error_num){
- Writelog($error_num,'error_num','curl_error');
- $this->responseError('服务异常', -1);
- }
- // $output = '{"msg":"是活动内订购","err":"0","status":"1111"}';
- $return = json_decode($output,true);
- if($return['status']== '0000'){
- $this->responseSuccess(['status'=>0],'is year_vip');
- }else{
- $this->responseSuccess(['status'=>2],'is not year_vip');
- }
- }
-
- /**
- * 获取剩余投票次数
- */
- public function _getVoteChance()
- {
- if($this->vip_level >= 1){
- $vote = 10;
- }else{
- $vote = 5;
- }
- $add = 0;
- if($this->vip_level ==2){
- $num = M('activity_vip_vote')->where(['uid'=>$this->uid,'act_id'=>$this->act_id])->getField('num');
- if($num === null){
- $insert = [
- 'act_id'=>$this->act_id,
- 'uid'=>$this->uid,
- 'num'=>0,
- 'created_at'=>date('Y-m-d H:i:s')
- ];
- M('activity_vip_vote')->add($insert);
- }
- $add = 200 - $num;
- }
- $vote += $add;
- //查看当前已投票次数
- $alreay_num = M('activity_vote')->where(['date'=>date('Ymd'),'uid'=>$this->uid,'act_id'=>$this->act_id])->sum('num');
- //查看当前应有票数
- if($vote <= $alreay_num){
- return 0;
- }
- return $vote > $alreay_num ? $vote - $alreay_num : 0;
- }
- /**
- * 获取剩余投票次数
- */
- public function getVoteChance()
- {
- $data['num'] = $this->_getVoteChance();
- $this->responseSuccess($data,'投票剩余次数');
- }
- /**
- * 提交用户资料
- * @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, "登记成功!");
- }
-
- /**
- * 活动规则说明
- * @return [type] [description]
- */
- public function getActivityInfo()
- {
- // //获取活动规则信息
- $data['act'] = $this->activityinfo;
- $data['act']['info'] = explode('######', $this->activityinfo['introduce']);
- $data['act']['info'][0] = mb_substr(htmlspecialchars_decode($data['act']['info'][0]), 0, -3) ;
- $data['act']['info'][1] = mb_substr(htmlspecialchars_decode($data['act']['info'][1]), 4);
- //获取当前活动的手机号码
- $user_phone = M('activity_user_v2')->where(['act_id'=>$this->act_id,'uid'=>$this->uid])->getField('user_phone');
- if ($user_phone) {
- $data['user']['user_phone'] = $user_phone;
- }
- //获取奖品信息
- $prizes_tmp = json_decode($this->activityinfo['prize_list'],TRUE);
- foreach ($prizes_tmp as $key => $v) {
- $prizes[$v['prize_id']] = $v;
- if($v['prize_status'] == 0 || $v['prize_status'] == -1){
- continue;
- }
- $prize_list[] = ['id'=>$v['prize_id'],'prize_name'=>$v['prize_name'],'prize_img'=>$v['prize_img']];
- }
- // var_dump($prizes);die;
- $data['prizes'] = $prize_list;
- //获取中奖信息
- $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['remain_chance'] = $this->_getUserChance();
- $this->responseSuccess($data);
- }
- /**
- * 获取用户当日抽奖次数
- * @param [type] $uid [description]
- * @return [type] [description]
- */
- public function _getUserChance()
- {
- $map['uid'] = $this->uid;
- $map['act_id'] = $this->act_id;
- $map['date'] = date('Ymd');
- $chance = M('prize_log_v2')->where($map)->count();
- if(($this->activityinfo['is_test'] == 1) && (I('is_test') == 1)){
- return 1;
- }
-
- if($chance){
- return 0;
- }
- //是否参与了投票
- $bool = M('activity_vote')->where([$map])->find();
- if($bool){
- return 1;
- }else{
- return -1;
- }
- }
-
- /**
- * 获取用户剩余抽奖次数
- * @return [type] [description]
- */
- public function getPrizeNum()
- {
- $remain_chance = $this->_getUserChance();
- if($remain_chance == 0){
- $this->responseSuccess(['num'=>0],'您今天的抽奖次数用完了');
- }
- if($remain_chance == 1){
- $this->responseSuccess(['num'=>1],'您今天的剩余次数');
- }
- if($remain_chance == -1){
- $this->responseSuccess(['num'=>-1],'参与投票,即可抽奖');
- }
- }
- /**
- * 所有中奖记录查询
- */
- 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'] = 1;
- $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'];
- $chance = $this->_getUserChance();
- if($chance == 0){
- $this->responseError('您今天的抽奖次数用完了');
- }
- if($chance == -1){
- $this->responseSuccess('参与投票,即可抽奖');
- }
-
- //开始抽奖
- $prize_data = $this->_get_prize();
- unset($prize_data['yes']['rule_id']);
- $this->responseSuccess($prize_data, '抽奖成功!');
- }
- private function _get_prize() {
- $result = $this->getPrizeSetDeatil();
- // var_dump($result);die;
- $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_status'];
- 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;
- }
-
- if(I('run')!='complate'){
- return $impossible_prize;
- }
- //如果中了一次实物奖就不允许中第二次
- $map = array(
- 'act_id'=> $this->act_id,
- 'uid'=> $this->uid,
- 'prize_status'=>1,
- );
- if(M('Prize_log_v2')->where($map)->find()){
- 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;
- }
- //8.如果中了一次实物奖就不允许中第二次
- if('real'== $limit_sales[$value['rule_prize_id']]['prize_object']){
- if(M('Prize_log_v2')->where(['act_id'=>$this->act_id,'uid'=>$this->uid,'prize_status'=>1])->find()){
- $swithc_no = $swithc_no. 8;
- continue;
- }
- }
- Writelog('uid: '.$this->uid.'跳出关卡: '.$swithc_no,'switch','activityv2');
- $prize = $limit_sales[$value['rule_prize_id']];
- $prize['rule_id'] = $value['rule_id'];
- $prize['prize_status'] = 1;
- 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;
- }
- }
|