Activity.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <?php
  2. namespace app\api\controller\mlbb;
  3. use app\api\service\mlbb\HandleService;
  4. use think\Db;
  5. /**
  6. * 活动管理
  7. */
  8. class Activity extends Mlbb
  9. {
  10. // 冒险团礼包对应的 兑换标识(三个阶段)
  11. protected $propArr = [
  12. // 0 => ['prop_code' => '活动标识', 'act_id' => '活动 ID', 'act_sub_id' => '子活动 ID'],
  13. 1 => ['prop_code' => 'mxtlb_001', 'act_id' => '250225', 'act_sub_id' => '1'],
  14. 2 => ['prop_code' => 'mxtlb_002', 'act_id' => '250225', 'act_sub_id' => '2'],
  15. 3 => ['prop_code' => 'mxtlb_003', 'act_id' => '250225', 'act_sub_id' => '3'],
  16. ];
  17. /**
  18. * 冒险团详情
  19. *
  20. * PS: 任何玩家登录无渠道标识链接,无下载按钮;玩家集结团邀请分享 ,其他玩家登录进来,同样无渠道标识,无下载按钮。
  21. * A渠道玩家登录B渠道标识链接,下载游戏是B渠道包,集结团邀请分享的链接带有B标识,其他玩家登录进来下载的都是B渠道包。
  22. *
  23. * @return \think\response\Json|null
  24. * @throws \think\Exception
  25. * @throws \think\db\exception\DataNotFoundException
  26. * @throws \think\db\exception\ModelNotFoundException
  27. * @throws \think\exception\DbException
  28. */
  29. public function getInfo(){
  30. // if($this->getJudgmentTask()){
  31. // return $this->resultFail('请先绑定角色!');
  32. // }
  33. $phaseList = ['mxtlb_001' => 1, 'mxtlb_002' => 1, 'mxtlb_003' => 1]; // 阶段任务及状态: 1=未完成,2=已完成、3=已领取
  34. if(time() <= $this->expiration_date['start']){
  35. return $this->resultSuccess([
  36. 'list' => [],
  37. 'mark_code' => "", // 冒险团邀请码
  38. 'phase_list' => $phaseList, // 阶段任务状态
  39. ]);
  40. }
  41. $mark_code = input('mark_code', '');
  42. $userInfo = $this->userInfo;
  43. $userLvInfo = $this->userInfo['lr_info'];
  44. $gatheringInfo = Db::table('lr_user_gathering')->where('user_id', $userInfo['id'])->find();
  45. // 判断用户是否加入冒险团
  46. if(!$gatheringInfo){
  47. $num = Db::table('lr_user_gathering')->where('code', $mark_code)->count();
  48. // 判断是否别人冒险团邀请进来的,并判断冒险团人数是否已满;未满则加入,人数已满则自己为队长;
  49. if($num < 5 && $mark_code){ // 加入冒险团
  50. $data = [
  51. 'user_id' => $userInfo['id'],
  52. 'user_name' => $userInfo['username'],
  53. 'channel_id' => $userLvInfo['channel_id'],
  54. 'type' => 2, // 类型:1=团长,2=团员
  55. 'code' => $mark_code,
  56. // 'role_id' => $userLvInfo['role_id'],
  57. // 'role_name' => $userLvInfo['role_name'],
  58. 'create_time' => date('Y-m-d H:i:s', NOW_TIMESTAMP)
  59. ];
  60. } else { // 创建冒险团
  61. $mark_code = $this->getMarkCode();
  62. $data = [
  63. 'user_id' => $userInfo['id'],
  64. 'user_name' => $userInfo['username'],
  65. 'channel_id' => $userLvInfo['channel_id'],
  66. 'type' => 1, // 1=团长,2=团员
  67. 'code' => $mark_code, // 生成6位随机码
  68. // 'role_id' => $userLvInfo['role_id'],
  69. // 'role_name' => $userLvInfo['role_name'],
  70. 'create_time' => date('Y-m-d H:i:s', NOW_TIMESTAMP)
  71. ];
  72. }
  73. try {
  74. $res = Db::table('lr_user_gathering')->insert($data);
  75. if(!$res){
  76. return $this->resultFail('冒险团创建失败,请稍后再试!', -100);
  77. }
  78. } catch (\Exception $e) {
  79. return $this->resultFail('冒险团创建异常,请稍后再试!', -199);
  80. }
  81. }else{
  82. $mark_code = $gatheringInfo['code'];
  83. }
  84. $list = Db::table('lr_user_gathering')->where(['code' => $mark_code])->select();
  85. // ## 判断完成任务状态
  86. $gatheringCount = Db::table('lr_user_gathering')->where(['code' => $mark_code])->count();
  87. if($gatheringCount < 5){
  88. $phaseList = ['mxtlb_001' => 2, 'mxtlb_002' => 2, 'mxtlb_003' => 1];
  89. } else if($gatheringCount >= 5){
  90. $phaseList = ['mxtlb_001' => 2, 'mxtlb_002' => 2, 'mxtlb_003' => 2];
  91. }
  92. // 判断是否已领取
  93. $claimBtProp = Db::table('lr_claim')->where(['prop_code' => ['in', ['mxtlb_001', 'mxtlb_002', 'mxtlb_003']], 'user_id' => $userInfo['id']])->field('id,prop_code')->column('prop_code,issue_status');
  94. foreach ($claimBtProp as $k=>$v){
  95. foreach ($phaseList as $k2=>$v2){
  96. if($k == $k2){
  97. $phaseList[$k] = 3;
  98. // if($v['issue_status'] == 2){
  99. // }
  100. }
  101. }
  102. }
  103. return $this->resultSuccess([
  104. 'list' => $list,
  105. 'mark_code' => $mark_code, // 冒险团邀请码
  106. 'phase_list' => $phaseList, // 阶段任务状态
  107. ]);
  108. }
  109. // 冒险团礼包领取
  110. public function claim(){
  111. if(time() <= $this->expiration_date['start']){
  112. return $this->resultFail('12月18日10:00开放领取!', -100);
  113. }
  114. if(time() >= $this->expiration_date['end']){
  115. return $this->resultFail('此活动已于2026年01月18号截止!', -100);
  116. }
  117. if($this->getJudgmentTask()){
  118. return $this->resultFail('请先绑定角色!', -101);
  119. }
  120. // if($this->userInfo['id'] != '103523'){
  121. // return $this->resultFail('礼包补货中,请5点以后再来尝试!', -100);
  122. // }
  123. $phase_num = input('phase_num', 0); // 阶段:1=第一阶段,2=第二阶段,3=第三阶段
  124. $mark_code = input('mark_code', '');
  125. if(!in_array($phase_num, [1, 2, 3]) || empty($mark_code)){
  126. return $this->resultFail('参数有误!', -100);
  127. }
  128. // 判断阶段任务是否完成
  129. $count = Db::table('lr_user_gathering')->where(['code' => $mark_code])->count();
  130. if($phase_num == 1 && $count <= 0){
  131. return $this->resultFail('阶段任务未完成,无法领取!', -110);
  132. } else if($phase_num > 2 && $count < 5){
  133. return $this->resultFail('第三阶段任务未完成,无法领取!', -111);
  134. }
  135. // 每阶段对应的 兑换标识
  136. $prop_Info = $this->propArr[$phase_num];
  137. $info = Db::table('lr_claim')->where(['prop_code' => $prop_Info['prop_code'], 'user_id' => $this->userInfo['id']])->find();
  138. if($info){
  139. return $this->resultSuccess([], '已领取成功!');
  140. }
  141. $data = [
  142. 'user_id' => $this->userInfo['id'],
  143. 'prop_code' => $prop_Info['prop_code'],
  144. 'issue_status' => 2, // 1=未发放,2=已发放
  145. 'create_time' => date('Y-m-d H:i:s', NOW_TIMESTAMP)
  146. ];
  147. Db::startTrans();
  148. try {
  149. // ## 发放游戏内道具
  150. $entendData = [
  151. 'sub_username' => $this->userInfo['lr_info']['sub_username'],
  152. 'server_id' => $this->userInfo['lr_info']['server_id'],
  153. 'server_name' => $this->userInfo['lr_info']['server_name'],
  154. 'role_id' => $this->userInfo['lr_info']['role_id'],
  155. 'role_name' => $this->userInfo['lr_info']['role_name'],
  156. 'actId' => $prop_Info['act_id'],
  157. 'actSubId' => $prop_Info['act_sub_id'],
  158. ];
  159. $res = (new HandleService())->entendRewards($entendData);
  160. if($res['code'] != 200){
  161. throw new \Exception("{$res['msg']}({$res['code']})", -122);
  162. }
  163. $result = Db::table('lr_claim')->insert($data);
  164. if(!$result){
  165. throw new \Exception('领取失败', -120);
  166. }
  167. // 阶段三,发放代金卷
  168. if($prop_Info['prop_code'] == 'mxtlb_003'){
  169. $getMemCou = (new \app\api\service\mlbb\HandleService())->getMemberCoupon('coupon_009', $this->userInfo['id']);
  170. if($getMemCou['code'] != 200 || empty($getMemCou['data']['code'])){
  171. throw new \Exception("{$getMemCou['msg']}({$getMemCou['code']})", -121);
  172. }
  173. }
  174. Db::commit();
  175. } catch (\Exception $e) {
  176. Db::rollback();
  177. return $this->resultFail('领取异常:'.$e->getMessage()."({$e->getCode()})", -199);
  178. }
  179. return $this->resultSuccess([], '领取成功');
  180. }
  181. }