RecylingLogic.class.php 27 KB

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