ChildDay2Logic.class.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805
  1. <?php
  2. /**
  3. * 佩奇拼图活动(由萌鸡快跑活动改写)
  4. * @author xusong
  5. * @version 0.0.1
  6. * @datetime 2019.07.25
  7. */
  8. namespace Home\Logic\Activityv2;
  9. class ChildDay2Logic extends BaseLogic
  10. {
  11. private $act_id;
  12. private $uid;
  13. private $userinfo;
  14. private $activityinfo;
  15. private $vip_level;
  16. /**
  17. * [_initialize 前置操作-继承公共前置方法]
  18. * @author Devil
  19. * @blog http://gong.gg/
  20. * @version 0.0.1
  21. * @datetime 2016-12-03T12:39:08+0800
  22. */
  23. public function _initialize() {
  24. // 调用父类前置方法
  25. parent::_initialize();
  26. $this->uid = trim(I('uid'));
  27. if(!$this->userinfo = M('iptv_users')->where(['uid'=>$this->uid])->find()){
  28. $this->responseError('uid 参数非法');
  29. }
  30. $this->act_id = (int)I('act_id');
  31. if(!$this->activityinfo = M('Activity_v2')->where(['id'=>$this->act_id])->find()){
  32. $this->responseError('act_id 参数非法');
  33. }
  34. $is_vip = I('is_vip') || I('vip_level') ? I('is_vip') || I('vip_level') : 0;
  35. //检查vip鉴权方式
  36. $this->vip_level = $is_vip >= 1 ? 1 : 0;
  37. }
  38. /**
  39. * 获取活动状态
  40. * @return [type] [description]
  41. */
  42. public function getActStatus()
  43. {
  44. //开始时间结束时间未作限制
  45. if($this->activityinfo['is_enable'] == 1){
  46. $this->responseSuccess(1, "请求成功!");
  47. }else{
  48. $this->responseSuccess(-1, "请求成功!");
  49. }
  50. }
  51. /**
  52. * 提交用户资料
  53. * @return [type] [description]
  54. */
  55. public function setUserInfo()
  56. {
  57. $phone = trim(I('phone'));
  58. if (empty($phone)) {
  59. $this->responseError('参数错误!');
  60. }
  61. //检测手机号码是否正确
  62. if (!preg_match('/^1[345789]\d{9}$/ims', $phone)) {
  63. $this->responseError('手机号填写有误!');
  64. }
  65. //更新用户活动手机号码
  66. $where = array(
  67. 'uid'=>$this->uid,
  68. 'act_id'=>$this->act_id,
  69. );
  70. if ($id = M('activity_user_v2')->where($where)->getField('id')){
  71. $update['user_phone']= $phone;
  72. $update['updated_at']= date('Y-m-d H:i:s');
  73. if(M('activity_user_v2')->where(['id'=>$id])->save($update)===false){
  74. Writelog(M()->getLastSql(),'sql','prize');
  75. $this->responseError("更新失败!");
  76. }
  77. }else{
  78. $insert_data = array(
  79. 'uid'=>$this->uid,
  80. 'act_id'=>$this->act_id,
  81. 'user_phone'=>$phone,
  82. 'created_at'=>date('Y-m-d H:i:s'),
  83. 'updated_at'=>date('Y-m-d H:i:s')
  84. );
  85. if(!M('activity_user_v2')->add($insert_data)){
  86. Writelog(M()->getLastSql(),'sql','prize');
  87. $this->responseError("登记失败!");
  88. }
  89. }
  90. $this->responseSuccess(0, "登记成功!");
  91. }
  92. /**
  93. * 提交用户资料
  94. * @return [type] [description]
  95. */
  96. public function setUserInfoByphone()
  97. {
  98. $phone = trim(I('phone'));
  99. $address = trim(I('address'));
  100. $receiver = trim(I('receiver'));
  101. if (!($phone && $address && $receiver)) {
  102. $this->responseError('参数错误!');
  103. }
  104. //检测手机号码是否正确
  105. if (!preg_match('/^1[345789]\d{9}$/ims', $phone)) {
  106. $this->responseError('手机号填写有误!');
  107. }
  108. //更新用户活动手机号码
  109. $where = array(
  110. 'uid'=>$this->uid,
  111. 'act_id'=>$this->act_id,
  112. );
  113. if ($id = M('activity_user_v2')->where($where)->getField('id')){
  114. $update['user_phone']= $phone;
  115. $update['address'] = $address;
  116. $update['receiver'] = $receiver;
  117. $update['updated_at'] = date('Y-m-d H:i:s');
  118. if(M('activity_user_v2')->where(['id'=>$id])->save($update)===false){
  119. Writelog(M()->getLastSql(),'sql','prize');
  120. $this->responseError("更新失败!");
  121. }
  122. }else{
  123. $insert_data = array(
  124. 'uid'=>$this->uid,
  125. 'act_id'=>$this->act_id,
  126. 'user_phone'=>$phone,
  127. 'address'=>$address,
  128. 'receiver'=>$receiver,
  129. 'created_at'=>date('Y-m-d H:i:s'),
  130. 'updated_at'=>date('Y-m-d H:i:s'),
  131. );
  132. if(!M('activity_user_v2')->add($insert_data)){
  133. Writelog(M()->getLastSql(),'sql','prize');
  134. $this->responseError("登记失败!");
  135. }
  136. }
  137. $this->responseSuccess(0, "登记成功!");
  138. }
  139. //获取网页二维码
  140. public function getQrcode()
  141. {
  142. $this->responseSuccess($this->createQrcode());
  143. }
  144. /**
  145. * 活动规则说明
  146. * @return [type] [description]
  147. */
  148. public function getActivityInfo()
  149. {
  150. // //获取活动规则信息
  151. $data['act'] = $this->activityinfo;
  152. $data['act']['info'] = explode('######', $this->activityinfo['introduce']);
  153. $data['act']['info'][0] = mb_substr(htmlspecialchars_decode($data['act']['info'][0]), 0, -3) ;
  154. $data['act']['info'][1] = mb_substr(htmlspecialchars_decode($data['act']['info'][1]), 4);
  155. //获取当前活动的手机号码
  156. $user_phone = M('activity_user_v2')->where(['act_id'=>$this->act_id,'uid'=>$this->uid])->getField('user_phone');
  157. if ($user_phone) {
  158. $data['user']['user_phone'] = $user_phone;
  159. }
  160. //获取奖品信息
  161. $prizes_tmp = json_decode($this->activityinfo['prize_list'],TRUE);
  162. foreach ($prizes_tmp as $key => $v) {
  163. $prizes[$v['prize_id']] = $v;
  164. if($v['prize_status'] == 0 || $v['prize_status'] == -1){
  165. continue;
  166. }
  167. $prize_list[] = ['id'=>$v['prize_id'],'prize_name'=>$v['prize_name'],'prize_img'=>$v['prize_img']];
  168. }
  169. // var_dump($prizes);die;
  170. $data['prizes'] = $prize_list;
  171. //获取中奖信息
  172. $data['rank'] = $this->prizelog('localhost');
  173. unset($data['act']['prize_list']);
  174. unset($data['act']['prize_rule']);
  175. //获取当前用户中奖信息
  176. $map['act_id'] = $this->act_id;
  177. $map['uid'] = $this->uid;
  178. $map['rule_id'] = array("neq", 0);
  179. //$data['my_prizes'] = M('prize_log_v2')->field('prize_id,prize_name')->where($map)->select();
  180. $my_prizes = M('prize_log_v2')->field('created_at,prize_id')->where($map)->select() ? : array();
  181. if($my_prizes){
  182. foreach ($my_prizes as $k=>$value) {
  183. $my_prizes[$k]['prize_name'] = $prizes[$value['prize_id']]['prize_name'];
  184. $data['my_prizes'][] = ['prize_id'=>$value['prize_id'],'prize_name'=>$prizes[$value['prize_id']]['prize_name']];
  185. }
  186. }
  187. //获取用户剩余中奖次数
  188. $data['remain_chance'] = $this->_getUserChance();
  189. $this->responseSuccess($data);
  190. }
  191. //建立游戏角色
  192. public function createRole()
  193. {
  194. if(!(I('role'))){
  195. $this->responseError('请选择角色!', -1);
  196. }
  197. if(!in_array(I('role'), ['yellow_pig','red_pig','blue_pig'])){
  198. $this->responseError('role参数不合法', -1);
  199. }
  200. //查看是否存在角色,存在及更新
  201. if(M('activity_chick_run')->where(['uid'=>$this->uid])->find()){
  202. $this->responseError('账号已存在!', -1);
  203. }
  204. $insertData = array(
  205. 'uid'=>$this->uid,
  206. 'role'=>I('role'),
  207. 'created_at'=>date('Y-m-d H:i:s'),
  208. 'updated_at'=>date('Y-m-d H:i:s'),
  209. 'date'=>date('Ymd')
  210. );
  211. if(M('activity_chick_run')->add($insertData)){
  212. $this->responseSuccess(['success'=>'success'], '创建角色成功!');
  213. }else{
  214. $this->responseError('网络异常!', -1);
  215. }
  216. }
  217. //建立游戏角色
  218. private function _getRole()
  219. {
  220. //查看是否存在角色,存在及更新
  221. $role_info = M('activity_chick_run')->where(['uid'=>$this->uid])->find();
  222. return $role_info ? $role_info : FALSE;
  223. }
  224. //获取角色信息
  225. public function getRoleInfo()
  226. {
  227. $info = $this->_getRole();
  228. if($info){
  229. $this->responseSuccess($info);
  230. }else{
  231. $this->responseError('游戏角色未建立!', -1);
  232. }
  233. }
  234. /**
  235. * 获取虚拟道具卡
  236. * @param [type] $uid [description]
  237. * @return [type] [description]
  238. */
  239. public function getVitualCard()
  240. {
  241. if($daoju_name = trim(I('daoju_name'))){
  242. if(!in_array($daoju_name, ['reborn_card'])){
  243. $this->responseError('daoju_name 参数非法');
  244. }
  245. } else {
  246. $this->responseError('daoju_name 参数非法');
  247. }
  248. $remain = $this->_getVitualCard($daoju_name);
  249. $this->responseSuccess($remain,'剩余道具数量');
  250. }
  251. /**
  252. * 获取虚拟卡
  253. * @param [type] $uid [description]
  254. * @return [type] [description]
  255. */
  256. private function _getVitualCard($daoju_name)
  257. {
  258. $map['uid'] = $this->uid;
  259. $map['act_id'] = $this->act_id;
  260. $map['date'] = date('Ymd');
  261. $map['name'] = $daoju_name;
  262. $daoju = M('activity_daoju')->field('operate,count(*) as total')->where($map)->group('operate')->select();
  263. $daoju = array_column($daoju, 'total', 'operate');
  264. $count = $daoju['add'] - $daoju['reduce'];
  265. if($daoju_name == 'reborn_card'){
  266. if($this->vip_level == 2){
  267. $remain_chance = 2 + $count;
  268. }elseif($this->vip_level ==1){
  269. $remain_chance = 1 + $count;
  270. }else{
  271. $remain_chance = 0 + $count;
  272. }
  273. }
  274. return $remain_chance > 0 ? $remain_chance : 0;
  275. }
  276. /**
  277. * 获取用户当日抽奖次数
  278. * @param [type] $uid [description]
  279. * @return [type] [description]
  280. */
  281. public function _getUserChance()
  282. {
  283. $map['uid'] = $this->uid;
  284. $map['act_id'] = $this->act_id;
  285. $map['date'] = date('Ymd');
  286. $chance = M('prize_log_v2')->where($map)->count();
  287. if($this->activityinfo['is_test'] ==1){
  288. if(I('is_test') ==1){
  289. return $remain_chance = 1000 - $chance;
  290. }
  291. }
  292. if($this->vip_level >=1){
  293. $remain_chance = ($this->vip_level * $this->activityinfo['vip_chance'] + $this->activityinfo['novip_chance'] - $chance);
  294. }else{
  295. $remain_chance = $this->activityinfo['novip_chance'] - $chance;
  296. }
  297. return $remain_chance > 0 ? $remain_chance : 0;
  298. }
  299. /**
  300. * 使用虚拟道具
  301. * @param [type] $uid [description]
  302. * @return [type] [description]
  303. */
  304. public function useVitualCard()
  305. {
  306. $remain_reborn_card = $this->_getVitualCard('reborn_card');
  307. if($remain_reborn_card >= 1){
  308. $insert = array(
  309. 'uid' => $this->uid,
  310. 'act_id' => $this->act_id,
  311. 'date' => date('Ymd'),
  312. 'operate' => 'reduce',
  313. 'name' => 'reborn_card'
  314. );
  315. if(M('activity_daoju')->add($insert)){
  316. $this->responseSuccess();
  317. }else{
  318. $this->responseError('网络异常!', -1);
  319. }
  320. }else{
  321. $this->responseError('您没有复活卡拉!', -3);
  322. }
  323. }
  324. /**
  325. * 获取用户剩余抽奖次数
  326. * @return [type] [description]
  327. */
  328. public function getPrizeNum()
  329. {
  330. $remain_chance = $this->_getUserChance();
  331. $this->responseSuccess($remain_chance);
  332. }
  333. /**
  334. * 所有中奖记录查询
  335. */
  336. public function prizelog($model = ''){
  337. $error[] = ['error' => 'error'];
  338. $where['pl.act_id'] = $this->act_id;
  339. $where['pl.prize_status'] = 1;
  340. $data = M('prize_log_v2')->alias('pl')
  341. ->join(array('left join '.C("DB_PREFIX").'activity_user_v2 as iu on iu.uid = pl.uid and iu.act_id = '.$this->act_id))
  342. ->where($where)
  343. ->order('pl.id desc')
  344. ->field('pl.prize_id,pl.created_at,pl.uid,iu.user_phone')
  345. ->select();
  346. $prizes = json_decode($this->activityinfo['prize_list'],TRUE);
  347. foreach ($prizes as $value) {
  348. $prize_list[$value['prize_id']] = $value;
  349. }
  350. if($data){
  351. foreach ($data as $key=>$value) {
  352. $data[$key]['prize_name'] = $prize_list[$value['prize_id']]['prize_name'];
  353. $data[$key]['prize_img'] = __MY_URL__.$prize_list[$value['prize_id']]['prize_img'];
  354. }
  355. }
  356. //增加虚拟中奖信息
  357. $default_data = $this->getPrizeDefault();
  358. if($data || $default_data){
  359. if($data){
  360. foreach ($data as $k=>$v){
  361. if($v['user_phone']){
  362. $data[$k]['user_phone'] = substr_replace($v['user_phone'],'****',3,4);
  363. }else {
  364. $data[$k]['user_phone'] = substr_replace($v['uid'],'****',6);
  365. }
  366. unset($data[$k]['uid']);
  367. }
  368. }
  369. if($data && $default_data){
  370. $data = array_merge($default_data,$data);
  371. }else{
  372. $data = $data ? : $default_data;
  373. }
  374. array_multisort(array_column($data,'created_at'),SORT_DESC,$data);
  375. if($model == 'localhost'){
  376. return $data;
  377. }
  378. $this->responseSuccess($data, '查询成功!');
  379. }else{
  380. if($model == 'localhost'){
  381. return array();
  382. }
  383. $this->responseError('没有抽奖记录!', -3, $error);
  384. }
  385. }
  386. /**
  387. * 我的中奖记录查询
  388. */
  389. public function userPrizelog(){
  390. $error[] = ['error' => 'error'];
  391. //获取用户
  392. if($user_phone = M('activity_user_v2')->where(['uid'=>$this->uid,'act_id'=>$this->act_id])->getField('user_phone')){
  393. $phone_staus = 1;//填过
  394. }else{
  395. $phone_staus = 2;//填过
  396. }
  397. $where = array();
  398. $where['pl.prize_status'] = ['gt',0];
  399. $where['pl.uid'] = $this->uid;
  400. $where['pl.act_id'] = $this->act_id;
  401. $data = M('prize_log_v2')->alias('pl')
  402. ->where($where)
  403. ->order('pl.id desc')
  404. ->field('pl.prize_id,pl.created_at')
  405. ->select();
  406. // echo M()->getLastSql();die;
  407. $prizes = json_decode($this->activityinfo['prize_list'],TRUE);
  408. foreach ($prizes as $value) {
  409. $prize_list[$value['prize_id']] = $value;
  410. }
  411. $flag = $data ? 1 : 0;
  412. if($flag){
  413. if($data){
  414. foreach ($data as $k => $v){
  415. $data[$k]['prize_name'] = $prize_list[$v['prize_id']]['prize_name'];
  416. $data[$k]['prize_object'] = $prize_list[$v['prize_id']]['prize_object'];
  417. $data[$k]['show_image'] = $prize_list[$v['prize_id']]['prize_img'] ? __MY_URL__.$prize_list[$v['prize_id']]['prize_img']:null;
  418. unset($data[$k]['prize_id']);
  419. }
  420. }
  421. $return_data = array(
  422. 'my_prizes'=>$data,
  423. 'user_phone'=>['phone_status'=>$phone_staus,'user_phone'=>$user_phone ? :''],
  424. 'prize_status'=>$data ? 'real' : 'vitual'
  425. );
  426. $this->responseSuccess($return_data, '查询成功!');
  427. }else{
  428. $this->responseError('没有抽奖记录!', -3, $error);
  429. }
  430. }
  431. /**
  432. * 抽奖
  433. */
  434. public function prize(){
  435. $error[] = ['error' => 'error'];
  436. $chance = $this->_getUserChance();
  437. if(!$chance){
  438. $this->responseError('您今天的抽奖次数用完了!', -1, $error);
  439. }
  440. //开始抽奖
  441. $prize_data = $this->_get_prize();
  442. unset($prize_data['yes']['rule_id']);
  443. $this->responseSuccess($prize_data, '抽奖成功!');
  444. }
  445. private function _get_prize() {
  446. $result = $this->getPrizeSetDeatil();
  447. // var_dump($result);die;
  448. $this->_writePrizeLog($result);
  449. $res = array();
  450. $res['yes']['prize_name'] = $result['prize_name']; //中奖项
  451. $res['yes']['prize_status'] = $result['prize_object'] ? : 'none';
  452. $res['yes']['prize_img'] = $result['prize_img'] ? __MY_URL__.$result['prize_img'] : '';
  453. $res['yes']['rule_id'] = $result['rule_id'];
  454. return $res;
  455. }
  456. /**
  457. * @param desc 写入抽奖日志
  458. * @param type $result
  459. */
  460. private function _writePrizeLog(&$result) {
  461. $log_data['uid'] = $this->uid;
  462. $log_data['prize_id'] = $result['prize_id'];
  463. $log_data['is_vip'] = $this->vip_level;
  464. $log_data['act_id'] = $this->act_id;
  465. $log_data['created_at'] = date('Y-m-d H:i:s');
  466. $log_data['date'] = date('Ymd');
  467. $log_data['rule_id'] = $result['rule_id'];
  468. $log_data['prize_status'] = $result['prize_status'];
  469. if(!M('prize_log_v2')->add($log_data)){
  470. Writelog(M()->getLastSql(),'sql','activity');
  471. $this->responseError('系统繁忙抽奖失败', -1);
  472. }
  473. }
  474. /**
  475. * 返回中奖的信息
  476. */
  477. private function getPrizeSetDeatil()
  478. {
  479. $prize_list = json_decode($this->activityinfo['prize_list'],TRUE);//获取奖项设置
  480. if($prize_list){
  481. foreach ($prize_list as $row) {
  482. $limit_sales[$row['prize_id']] = $row;
  483. if($row['prize_level']== 0){
  484. $impossible_prize = ['prize_id'=>$row['prize_id'],'prize_name'=>$row['prize_name'],'rule_id'=>0,'prize_img'=>'','prize_status'=>0];
  485. }
  486. }
  487. }
  488. //获取所有规则
  489. $rules = json_decode($this->activityinfo['prize_rule'],TRUE);
  490. if(!$rules){
  491. return $impossible_prize;
  492. }
  493. if(I('run')!='complate'){
  494. return $impossible_prize;
  495. }
  496. //0元vip兑换券,前端传
  497. $vip_0 = I('vip_0','uncan');
  498. //如果中了一次实物奖就不允许中第二次
  499. $map = array(
  500. 'act_id'=> $this->act_id,
  501. 'uid'=> $this->uid,
  502. 'prize_status'=>['gt',0],
  503. );
  504. $count = M('Prize_log_v2')->where($map)->count();
  505. if($count == 3){
  506. return $impossible_prize;
  507. }
  508. // var_dump($count);die;
  509. $swithc_no = '';
  510. foreach ($rules as $value) {
  511. if($value['rule_status'] == 0){
  512. $swithc_no = $swithc_no. 0;
  513. continue;
  514. }
  515. //1.检查是否符合身份
  516. if(FALSE === $this->_checkRuleRole($value['rule_role'])){
  517. $swithc_no = $swithc_no. 1;
  518. continue;
  519. }
  520. //2.检查中奖日期设置
  521. if(FALSE === $this->_checkRuleDate($value['rule_date'])){
  522. $swithc_no = $swithc_no. 2;
  523. continue;
  524. }
  525. //3.检查时段设置
  526. if(FALSE === $this->_checkRuleHour($value['rule_hour'])){
  527. $swithc_no = $swithc_no. 3;
  528. continue;
  529. }
  530. //4.概率摇奖
  531. if(FALSE === $this->_getRandNum($value['rule_probability'])){
  532. $swithc_no = $swithc_no. 4;
  533. continue;
  534. }
  535. //5.查询是否超出当前规则下的出奖数
  536. if(FALSE === $this->_checkCurrentRuleSale($value)){
  537. $swithc_no = $swithc_no. 5;
  538. continue;
  539. }
  540. //6.查询是否超出奖品总数
  541. if(FALSE === $this->_checkGolabRule($value,$limit_sales)){
  542. $swithc_no = $swithc_no. 6;
  543. continue;
  544. }
  545. // var_dump($value);
  546. Writelog('uid: '.$this->uid.'跳出关卡: '.$swithc_no,'switch','activityv2');
  547. $prize = $limit_sales[$value['rule_prize_id']];
  548. // var_dump($prize);die;
  549. //一人实物奖至多只能中一次
  550. if($prize['prize_object'] == 'real'){
  551. $map = array(
  552. 'act_id'=> $this->act_id,
  553. 'uid'=> $this->uid,
  554. 'prize_status'=>1
  555. );
  556. if(M('Prize_log_v2')->where($map)->find()){
  557. continue;
  558. }
  559. }
  560. // 0元包只能是某一类用户中
  561. if($prize['prize_object'] == 'vitual' && $prize['prize_name'] == '少儿会员0元包'){
  562. if($vip_0 != 'can'){
  563. continue;
  564. }
  565. if(!M('activity_silence')->where(['uid'=>$this->uid])->find()){
  566. continue;
  567. }
  568. $map = array(
  569. 'act_id'=> $this->act_id,
  570. 'uid'=> $this->uid,
  571. 'prize_status'=>2
  572. );
  573. if(M('Prize_log_v2')->where($map)->find()){
  574. continue;
  575. }
  576. $prize['prize_status'] = 2;
  577. }
  578. if($prize['prize_name'] == '快乐购套券'){
  579. $map = array(
  580. 'act_id'=> $this->act_id,
  581. 'uid'=> $this->uid,
  582. 'prize_status'=>3
  583. );
  584. if(M('Prize_log_v2')->where($map)->find()){
  585. continue;
  586. }
  587. $prize['prize_status'] = 3;
  588. }
  589. $prize['rule_id'] = $value['rule_id'];
  590. return $prize;
  591. }
  592. Writelog('uid: '.$this->uid.'跳出关卡: '.$swithc_no,'switch','activityv2');
  593. return $impossible_prize;
  594. }
  595. /**
  596. * 获取转盘信息
  597. */
  598. public function prizeData(){
  599. $error[] = ['error' => 'error'];
  600. $data = array();
  601. $data['userp']['prize_num'] = $this->_getUserChance();
  602. $data['userp']['user_phone'] = $this->userinfo['user_phone'] ? :$this->userinfo['uid'];
  603. //转盘信息
  604. $turn_data = json_decode($this->activityinfo['prize_list'],TRUE);
  605. if($turn_data){
  606. foreach ($turn_data as $k => $v){
  607. if($v['prize_status'] == 0){
  608. unset($turn_data[$k]);
  609. continue;
  610. }
  611. if($v['prize_img']){
  612. $turn_data[$k]['prize_img'] = __MY_URL__.$v['prize_img'];
  613. }
  614. unset($turn_data[$k]['prize_num']);
  615. unset($turn_data[$k]['prize_level']);
  616. unset($turn_data[$k]['prize_status']);
  617. }
  618. $data['prize_data'] = $turn_data;
  619. }else{
  620. $this->responseError('获取失败!', -1, $error);
  621. }
  622. $this->responseSuccess($data, '查询成功!');
  623. }
  624. private function getPrizeDefault()
  625. {
  626. $map['pd.act_id'] = $this->act_id;
  627. $prizes = json_decode($this->activityinfo['prize_list'],true);
  628. foreach ($prizes as $key=>$v){
  629. $prize_list[$v['prize_id']] = $v;
  630. }
  631. // var_dump($prize_list);die;
  632. $data = M('prize_default_v2')->where(['act_id'=>$this->act_id])->select();
  633. if($data){
  634. foreach ($data as $value) {
  635. $return_data[] = array(
  636. 'created_at'=>$value['prize_date'],
  637. 'prize_name'=>$prize_list[$value['prize_id']]['prize_name'],
  638. 'prize_img'=>$prize_list[$value['prize_id']]['prize_img'] ? __MY_URL__.$prize_list[$value['prize_id']]['prize_img']:'',
  639. 'user_phone'=>substr_replace($value['phone'],'****',3,4),
  640. );
  641. }
  642. }
  643. return $return_data;
  644. }
  645. /**
  646. * @desc 检查中奖规则关于身份设置
  647. */
  648. private function _checkRuleRole($rule_role)
  649. {
  650. $role = $this->vip_level ? '会员' : '普通用户';
  651. if(FALSE !== strpos($rule_role, '不限')){
  652. return TRUE;
  653. }
  654. if($rule_role != '虚拟用户'){
  655. if(in_array($role, explode(',', $rule_role))){
  656. return TRUE;
  657. }
  658. }
  659. return FALSE;
  660. }
  661. /**
  662. * @desc 检查中奖规则关于日期
  663. */
  664. private function _checkRuleDate($rule_date)
  665. {
  666. if(FALSE !== strpos($rule_date,'每日')){
  667. return TRUE;
  668. }
  669. //时间段
  670. if(strpos($rule_date,'至')){
  671. $date = explode('至', $rule_date);
  672. if((time()>=strtotime($date[0])) && time()< strtotime($date[1])){
  673. return TRUE;
  674. }else{
  675. return FALSE;
  676. }
  677. }else{
  678. if(date('Y-m-d') == $rule_date){
  679. return TRUE;
  680. }else{
  681. return FALSE;
  682. }
  683. }
  684. }
  685. /**
  686. * @desc 检查中奖规则关于时间段
  687. */
  688. private function _checkRuleHour($rule_hour)
  689. {
  690. $hour = explode('至', $rule_hour);
  691. if((date('H:i')>= trim($hour[0])) && (date('H:i')< trim($hour[1]))){
  692. return TRUE;
  693. }else{
  694. return FALSE;
  695. }
  696. }
  697. /**
  698. * @desc 概率摇奖
  699. * @param type $rule_probability
  700. * @return boolean
  701. */
  702. private function _getRandNum($rule_probability)
  703. {
  704. if($rule_probability == 0){
  705. return FALSE;
  706. }
  707. $tmp = explode('/', $rule_probability);
  708. $rand_array = range(1, $tmp[1]);
  709. shuffle($rand_array);
  710. $get_randnum = array_slice($rand_array, 0, $tmp[0]);
  711. Writelog('uid: '.$this->uid.'抽签: '.json_encode($get_randnum),'switch','activityv2');
  712. if(in_array($tmp[0], $get_randnum)){
  713. return TRUE;
  714. }else{
  715. return FALSE;
  716. }
  717. }
  718. /**
  719. * @desc 查询符合当前规则
  720. */
  721. private function _checkCurrentRuleSale(&$rule)
  722. {
  723. //查询当前规则下的中奖数,如果为-1则无限制
  724. if($rule['rule_num'] == -1){
  725. return TRUE;
  726. }
  727. if((FALSE!==strpos($rule['rule_date'],'至')) && ($rule['rule_cycle']=='total')){
  728. $rule_date = explode('至', $rule['rule_date']);
  729. $where['rule_id'] = $rule['rule_id'];
  730. $where['act_id'] = $this->act_id;
  731. $where['date'] = ['between',[date('Ymd', strtotime($rule_date[0])),date('Ymd', strtotime($rule_date[1]))]];
  732. $countNum = M('Prize_log_v2')->where($where)->count();
  733. Writelog('当前1:'.$countNum.'规则:'.$rule['rule_num'],'info','activityv2');
  734. return $countNum >= $rule['rule_num'] ? FALSE : TRUE;
  735. }else{
  736. $where['date'] = date('Ymd');
  737. $where['rule_id'] = $rule['rule_id'];
  738. $where['act_id'] = $this->act_id;
  739. $countNum = M('Prize_log_v2')->where($where)->count();
  740. Writelog('当前2:'.$countNum.'规则:'.$rule['rule_num'],'info','activityv2');
  741. // echo M()->getLastSql();die;
  742. return $countNum >= $rule['rule_num'] ? FALSE : TRUE;
  743. }
  744. }
  745. /**
  746. * @desc 不能超过奖品总数
  747. */
  748. private function _checkGolabRule(&$rule,&$limit_sales)
  749. {
  750. if($limit_sales[$rule['rule_prize_id']]['prize_num'] == -1){
  751. return TRUE;
  752. }
  753. $countNum = M('Prize_log_v2')->where(['prize_id'=>$rule['rule_prize_id'],'act_id'=>$this->act_id])->count();
  754. // echo M()->getLastSql();die;
  755. Writelog('当前3:'.$countNum.'总量:'.$limit_sales[$rule['rule_prize_id']]['prize_num'],'info','activityv2');
  756. return $countNum >= $limit_sales[$rule['rule_prize_id']]['prize_num'] ? FALSE : TRUE;
  757. }
  758. }