123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769 |
- <?php
- /**
- * 佩奇拼图活动(由萌鸡快跑活动改写)
- * @author xusong
- * @version 0.0.1
- * @datetime 2019.07.25
- */
- namespace Home\Logic\Activityv2;
- class RecylingLogic 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') >= 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['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);
- }
- //建立游戏角色
- public function createRole()
- {
- if(!(I('role'))){
- $this->responseError('请选择角色!', -1);
- }
- if(!in_array(I('role'), ['yellow_pig','red_pig','blue_pig'])){
- $this->responseError('role参数不合法', -1);
- }
- //查看是否存在角色,存在及更新
- if(M('activity_chick_run')->where(['uid'=>$this->uid])->find()){
- $this->responseError('账号已存在!', -1);
- }
- $insertData = array(
- 'uid'=>$this->uid,
- 'role'=>I('role'),
- 'created_at'=>date('Y-m-d H:i:s'),
- 'updated_at'=>date('Y-m-d H:i:s'),
- 'date'=>date('Ymd')
- );
- if(M('activity_chick_run')->add($insertData)){
- $this->responseSuccess(['success'=>'success'], '创建角色成功!');
- }else{
- $this->responseError('网络异常!', -1);
- }
- }
- //建立游戏角色
- private function _getRole()
- {
- //查看是否存在角色,存在及更新
- $role_info = M('activity_chick_run')->where(['uid'=>$this->uid])->find();
- return $role_info ? $role_info : FALSE;
- }
- //获取角色信息
- public function getRoleInfo()
- {
- $info = $this->_getRole();
- if($info){
- $this->responseSuccess($info);
- }else{
- $this->responseError('游戏角色未建立!', -1);
- }
- }
- /**
- * 获取虚拟道具卡
- * @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]
- */
- 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){
- if(I('is_test') ==1){
- return $remain_chance = 1000 - $chance;
- }
- }
-
- if($this->vip_level >=1){
- $remain_chance = ($this->vip_level * $this->activityinfo['vip_chance'] + $this->activityinfo['novip_chance'] - $chance);
- }else{
- $remain_chance = $this->activityinfo['novip_chance'] - $chance;
- }
- return $remain_chance > 0 ? $remain_chance : 0;
-
- }
-
- /**
- * 使用虚拟道具
- * @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'] = 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){
- $this->responseError('您今天的抽奖次数用完了!', -1, $error);
- }
-
- //开始抽奖
- $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;
- }
- // //7.如果是限免视频对次数进行限制
- // if('限免视频'==$limit_sales[$value['rule_prize_id']]['prize_name']){
- // if( 6<= M('prize_program')->where(['uid'=>$this->uid,'act_id'=>$this->act_id,'style'=>'source'])->count()){
- // $swithc_no = $swithc_no. 7;
- // 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;
- }
- }
|