| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- <?php
- namespace app\api\controller\mlbb;
- use app\api\service\mlbb\HandleService;
- use think\Db;
- /**
- * 活动管理
- */
- class Activity extends Mlbb
- {
- // 冒险团礼包对应的 兑换标识(三个阶段)
- protected $propArr = [
- // 0 => ['prop_code' => '活动标识', 'act_id' => '活动 ID', 'act_sub_id' => '子活动 ID'],
- 1 => ['prop_code' => 'mxtlb_001', 'act_id' => '250225', 'act_sub_id' => '1'],
- 2 => ['prop_code' => 'mxtlb_002', 'act_id' => '250225', 'act_sub_id' => '2'],
- 3 => ['prop_code' => 'mxtlb_003', 'act_id' => '250225', 'act_sub_id' => '3'],
- ];
- /**
- * 冒险团详情
- *
- * PS: 任何玩家登录无渠道标识链接,无下载按钮;玩家集结团邀请分享 ,其他玩家登录进来,同样无渠道标识,无下载按钮。
- * A渠道玩家登录B渠道标识链接,下载游戏是B渠道包,集结团邀请分享的链接带有B标识,其他玩家登录进来下载的都是B渠道包。
- *
- * @return \think\response\Json|null
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function getInfo(){
- // if($this->getJudgmentTask()){
- // return $this->resultFail('请先绑定角色!');
- // }
- $phaseList = ['mxtlb_001' => 1, 'mxtlb_002' => 1, 'mxtlb_003' => 1]; // 阶段任务及状态: 1=未完成,2=已完成、3=已领取
- if(time() <= $this->expiration_date['start']){
- return $this->resultSuccess([
- 'list' => [],
- 'mark_code' => "", // 冒险团邀请码
- 'phase_list' => $phaseList, // 阶段任务状态
- ]);
- }
- $mark_code = input('mark_code', '');
- $userInfo = $this->userInfo;
- $userLvInfo = $this->userInfo['lr_info'];
- $gatheringInfo = Db::table('lr_user_gathering')->where('user_id', $userInfo['id'])->find();
- // 判断用户是否加入冒险团
- if(!$gatheringInfo){
- $num = Db::table('lr_user_gathering')->where('code', $mark_code)->count();
- // 判断是否别人冒险团邀请进来的,并判断冒险团人数是否已满;未满则加入,人数已满则自己为队长;
- if($num < 5 && $mark_code){ // 加入冒险团
- $data = [
- 'user_id' => $userInfo['id'],
- 'user_name' => $userInfo['username'],
- 'channel_id' => $userLvInfo['channel_id'],
- 'type' => 2, // 类型:1=团长,2=团员
- 'code' => $mark_code,
- // 'role_id' => $userLvInfo['role_id'],
- // 'role_name' => $userLvInfo['role_name'],
- 'create_time' => date('Y-m-d H:i:s', NOW_TIMESTAMP)
- ];
- } else { // 创建冒险团
- $mark_code = $this->getMarkCode();
- $data = [
- 'user_id' => $userInfo['id'],
- 'user_name' => $userInfo['username'],
- 'channel_id' => $userLvInfo['channel_id'],
- 'type' => 1, // 1=团长,2=团员
- 'code' => $mark_code, // 生成6位随机码
- // 'role_id' => $userLvInfo['role_id'],
- // 'role_name' => $userLvInfo['role_name'],
- 'create_time' => date('Y-m-d H:i:s', NOW_TIMESTAMP)
- ];
- }
- try {
- $res = Db::table('lr_user_gathering')->insert($data);
- if(!$res){
- return $this->resultFail('冒险团创建失败,请稍后再试!', -100);
- }
- } catch (\Exception $e) {
- return $this->resultFail('冒险团创建异常,请稍后再试!', -199);
- }
- }else{
- $mark_code = $gatheringInfo['code'];
- }
- $list = Db::table('lr_user_gathering')->where(['code' => $mark_code])->select();
- // ## 判断完成任务状态
- $gatheringCount = Db::table('lr_user_gathering')->where(['code' => $mark_code])->count();
- if($gatheringCount < 5){
- $phaseList = ['mxtlb_001' => 2, 'mxtlb_002' => 2, 'mxtlb_003' => 1];
- } else if($gatheringCount >= 5){
- $phaseList = ['mxtlb_001' => 2, 'mxtlb_002' => 2, 'mxtlb_003' => 2];
- }
- // 判断是否已领取
- $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');
- foreach ($claimBtProp as $k=>$v){
- foreach ($phaseList as $k2=>$v2){
- if($k == $k2){
- $phaseList[$k] = 3;
- // if($v['issue_status'] == 2){
- // }
- }
- }
- }
- return $this->resultSuccess([
- 'list' => $list,
- 'mark_code' => $mark_code, // 冒险团邀请码
- 'phase_list' => $phaseList, // 阶段任务状态
- ]);
- }
- // 冒险团礼包领取
- public function claim(){
- if(time() <= $this->expiration_date['start']){
- return $this->resultFail('12月18日10:00开放领取!', -100);
- }
- if(time() >= $this->expiration_date['end']){
- return $this->resultFail('此活动已于2026年01月18号截止!', -100);
- }
- if($this->getJudgmentTask()){
- return $this->resultFail('请先绑定角色!', -101);
- }
- // if($this->userInfo['id'] != '103523'){
- // return $this->resultFail('礼包补货中,请5点以后再来尝试!', -100);
- // }
- $phase_num = input('phase_num', 0); // 阶段:1=第一阶段,2=第二阶段,3=第三阶段
- $mark_code = input('mark_code', '');
- if(!in_array($phase_num, [1, 2, 3]) || empty($mark_code)){
- return $this->resultFail('参数有误!', -100);
- }
- // 判断阶段任务是否完成
- $count = Db::table('lr_user_gathering')->where(['code' => $mark_code])->count();
- if($phase_num == 1 && $count <= 0){
- return $this->resultFail('阶段任务未完成,无法领取!', -110);
- } else if($phase_num > 2 && $count < 5){
- return $this->resultFail('第三阶段任务未完成,无法领取!', -111);
- }
- // 每阶段对应的 兑换标识
- $prop_Info = $this->propArr[$phase_num];
- $info = Db::table('lr_claim')->where(['prop_code' => $prop_Info['prop_code'], 'user_id' => $this->userInfo['id']])->find();
- if($info){
- return $this->resultSuccess([], '已领取成功!');
- }
- $data = [
- 'user_id' => $this->userInfo['id'],
- 'prop_code' => $prop_Info['prop_code'],
- 'issue_status' => 2, // 1=未发放,2=已发放
- 'create_time' => date('Y-m-d H:i:s', NOW_TIMESTAMP)
- ];
- Db::startTrans();
- try {
- // ## 发放游戏内道具
- $entendData = [
- 'sub_username' => $this->userInfo['lr_info']['sub_username'],
- 'server_id' => $this->userInfo['lr_info']['server_id'],
- 'server_name' => $this->userInfo['lr_info']['server_name'],
- 'role_id' => $this->userInfo['lr_info']['role_id'],
- 'role_name' => $this->userInfo['lr_info']['role_name'],
- 'actId' => $prop_Info['act_id'],
- 'actSubId' => $prop_Info['act_sub_id'],
- ];
- $res = (new HandleService())->entendRewards($entendData);
- if($res['code'] != 200){
- throw new \Exception("{$res['msg']}({$res['code']})", -122);
- }
- $result = Db::table('lr_claim')->insert($data);
- if(!$result){
- throw new \Exception('领取失败', -120);
- }
- // 阶段三,发放代金卷
- if($prop_Info['prop_code'] == 'mxtlb_003'){
- $getMemCou = (new \app\api\service\mlbb\HandleService())->getMemberCoupon('coupon_009', $this->userInfo['id']);
- if($getMemCou['code'] != 200 || empty($getMemCou['data']['code'])){
- throw new \Exception("{$getMemCou['msg']}({$getMemCou['code']})", -121);
- }
- }
- Db::commit();
- } catch (\Exception $e) {
- Db::rollback();
- return $this->resultFail('领取异常:'.$e->getMessage()."({$e->getCode()})", -199);
- }
- return $this->resultSuccess([], '领取成功');
- }
- }
|