['mark' => "1", 'title' => '累计登录魔力宝贝旅人 1天', 'status' => 1], // status: 1=未完成,2=已完成,3=已领取 2 => ['mark' => "2", 'title' => '累计登录魔力宝贝旅人 3天', 'status' => 1], 3 => ['mark' => "3", 'title' => '累计登录魔力宝贝旅人 5天', 'status' => 1], 4 => ['mark' => "4", 'title' => '完成一次 职业进阶', 'status' => 1], 5 => ['mark' => "5", 'title' => '等级达到 Lv33', 'status' => 1], 6 => ['mark' => "6", 'title' => '等级达到 Lv41', 'status' => 1], 7 => ['mark' => "7", 'title' => '等级达到 Lv55', 'status' => 1], 8 => ['mark' => "8", 'title' => '个人评分达到 8000', 'status' => 1], 9 => ['mark' => "9", 'title' => '个人评分达到 12000', 'status' => 1], 10 => ['mark' => "10", 'title' => '游戏内完成一次 充值', 'status' => 1], 11 => ['mark' => "11", 'title' => '累计充值达到 10000魔币', 'status' => 1], 12 => ['mark' => "12", 'title' => '累计充值达到 20000魔币', 'status' => 1], ]; // 预约 public function reservation(){ $userInfo = $this->userInfo; $lrInfo = $userInfo['lr_info']; if($lrInfo['is_appointment'] == 2){ return $this->resultFail('您已预约,无需重复预约!'); } if(time() >= $this->expiration_date['end']){ return $this->resultFail('此活动已于2026年01月18号截止!', -100); } $nowTime = NOW_TIMESTAMP; $res = Db::table('lr_user_info')->where(['user_id' => $userInfo['id']])->update([ 'is_appointment' => 2, 'appointment_time' => date('Y-m-d H:i:s', $nowTime), 'update_time' => date('Y-m-d H:i:s', $nowTime) ]); if($res>0){ return $this->resultSuccess([], '预约成功!'); } return $this->resultFail('预约失败,请稍后重试!'); } // 游戏角色列表 public function getRole(){ // 区服ID 判断 $server_id = input('server_id', 0); if(empty($server_id) || !in_array($server_id, [1000, 10082, 10083, 10084])){ return $this->resultFail('区服数据有误!'); } // 游戏ID 判断 $game_id = input('game_id', ''); if(!in_array($game_id, [10, 20, 344, 345, 503])){ $this->resultFail('当前游戏不支持此活动!'); } $roleList = Db::table('nw_member_game_server') // , 'channel_id' => $this->channel_id ->where(['member_id' => $this->userInfo['id'], 'game_id' => $game_id, 'serverid' => $server_id]) ->field('mgs_id,roleid as role_id,rolename as role_name,rolelevel as role_level,serverid as server_id,servername as server_name') ->order('mgs_id desc')->group('roleid')->select(); return $this->resultSuccess(['list' => $roleList]); } // 绑定角色 public function bandRole(){ // 角色ID 判断 $mgs_id = input('mgs_id', 0); if(empty($mgs_id)){ return $this->resultFail('参数有误!'); } // 区服ID 判断 $server_id = input('server_id', 0); if(empty($server_id) || !in_array($server_id, [1000, 10082, 10083, 10084])){ return $this->resultFail('区服数据有误!'); } // 游戏ID 判断 $game_id = input('game_id', ''); if(!in_array($game_id, [10, 20, 344, 345, 503])){ $this->resultFail('当前游戏不支持此活动!'); } if(!empty($this->userInfo['lr_info']['role_id'])){ return $this->resultFail('已绑定,无法修改!'); } $roleInfo = Db::table('nw_member_game_server')->where(['mgs_id' => $mgs_id])->find(); if(!$roleInfo){ return $this->resultFail('查询 角色信息 失败!'); } $sub_username = Db::table('nw_subaccount')->where(['member_id' => $this->userInfo['id'], 'game_id' => $game_id])->value('sub_username'); if(!$sub_username){ return $this->resultFail('查询 账号信息 失败!'); } $channel_id = Db::table('nw_member_game_server')->where(['member_id' => $this->userInfo['id'], 'game_id' => $game_id, 'serverid' => $server_id])->value('channel_id'); if(!$channel_id){ return $this->resultFail('查询 账户渠道信息 失败!'); } $this->judgmentChannel($channel_id); $data = [ 'game_id' => $game_id, // 'channel_id' => $channel_id, 'sub_username' => $sub_username, 'role_id' => $roleInfo['roleid'], 'role_name' => $roleInfo['rolename'], 'server_id' => $server_id, 'server_name' => $roleInfo['servername'], 'band_role_time' => date('Y-m-d H:i:s', NOW_TIMESTAMP), 'update_time' => date('Y-m-d H:i:s', NOW_TIMESTAMP), ]; $res = Db::table('lr_user_info')->where(['id' => $this->userInfo['lr_info']['id']])->update($data); if(!$res){ return $this->resultFail('绑定失败,请稍后重试!'); } return $this->resultSuccess([], '绑定成功!'); } // 任务列表 public function getTask(){ $taskList = $this->taskList; $list = Db::table('lr_user_task')->where(['user_id' => $this->userInfo['id']])->select(); foreach ($list as $k => $v){ if(isset($taskList[$v['mark']])){ $taskList[$v['mark']]['status'] = $v['status']; } } // 抽奖次数 $lottery_count = Db::table('lr_user_info')->where(['user_id' => $this->userInfo['id']])->value('lottery_count'); return $this->resultSuccess(['list' => $taskList, 'lottery_count' => $lottery_count??0]); } // 完成任务 - 测试,不对外 public function getTaskComplete(){ if($this->getJudgmentTask()){ return $this->resultFail('请先绑定角色!'); } $mark = input('mark', 0); if(empty($mark)){ return $this->resultFail('参数有误!'); } $info = Db::table('lr_user_task')->where(['user_id' => $this->userInfo['id'], 'mark' => $mark])->find(); if($info){ if($info['status'] == 2){ return $this->resultFail('任务已完成,请领取奖励!'); } else { return $this->resultFail('任务已存在,请勿重复提交!'); } } $taskList = $this->taskList; $codeByList = array_column($taskList, 'title', 'mark'); $data = [ 'user_id' => $this->userInfo['id'], 'mark' => $mark, 'title' => $codeByList[$mark], 'status' => 2, // 1=已完成,2=已领取 'craete_time' => date('Y-m-d H:i:s', NOW_TIMESTAMP) ]; Db::table('lr_user_task')->insert($data); // TODO: 增加抽奖次数 return $this->resultSuccess([], '任务完成,奖励已发放!'); } // 中奖记录 public function getLotteryLog(){ $list = Db::table('lr_user_winning')->where(['user_id' => $this->userInfo['id']])->order('id desc')->select(); return $this->resultSuccess(['list' => $list]); } // 抽奖 public function handleLottery(){ if($this->getJudgmentTask()){ return $this->resultFail('请先绑定角色!', -101); } if(time() >= $this->expiration_date['end']){ return $this->resultFail('此活动已于2026年01月18号截止!', -100); } if($this->userInfo['lr_info']['lottery_count'] <= 0){ return $this->resultFail('暂无抽奖次数,请先完成任务!', -102); } // 奖品池配置 $prizePool = [ // ['客户端标识', '奖品名称', '类型', '权重', '标识码|代金卷ID'], ['prize_mark' => 1, 'prize_name' => '殿堂礼包', 'type' => 'pack', 'weight' => 11, 'mark_code' => 'pack_001'], ['prize_mark' => 2, 'prize_name' => '勇者晋级礼包', 'type' => 'pack', 'weight' => 11, 'mark_code' => 'pack_002'], ['prize_mark' => 3, 'prize_name' => '勇者冒险礼包', 'type' => 'pack', 'weight' => 11, 'mark_code' => 'pack_003'], ['prize_mark' => 4, 'prize_name' => '勇者荣耀礼包', 'type' => 'pack', 'weight' => 11, 'mark_code' => 'pack_004'], ['prize_mark' => 5, 'prize_name' => '1元代金券', 'type' => 'coupon', 'weight' => 14, 'mark_code' => 'coupon_001'], ['prize_mark' => 6, 'prize_name' => '25元代金券', 'type' => 'coupon', 'weight' => 11, 'mark_code' => 'coupon_002'], ['prize_mark' => 7, 'prize_name' => '40元代金券', 'type' => 'coupon', 'weight' => 11, 'mark_code' => 'coupon_003'], ['prize_mark' => 8, 'prize_name' => '65元代金券', 'type' => 'coupon', 'weight' => 11, 'mark_code' => 'coupon_004'], ['prize_mark' => 9, 'prize_name' => '100元代金券', 'type' => 'coupon', 'weight' => 11, 'mark_code' => 'coupon_005'], ]; $drawCount = 0; // 已抽次数 $winningList = Db::table('lr_user_winning')->where(['user_id' => $this->userInfo['id']])->select(); $userWinningHistory = []; if($winningList){ foreach($winningList as $v){ $userWinningHistory[] = ['prize_mark' => $v['prize_mark'], 'prize_type' => $v['prize_type']]; } $drawCount = count($userWinningHistory); } if($drawCount >= 12){ return $this->resultFail('所有抽奖任务已完成!'); } $handleService = new \app\api\service\mlbb\HandleService(); // 抽奖 $drawInfo = (new \app\api\library\mlbb\LotteryService($prizePool))->draw($userWinningHistory); // array(5) { ["prize_mark"]=> int(2) ["prize_name"]=> string(18) "勇者晋级礼包" ["type"]=> string(4) "pack" ["weight"]=> int(11) ["mark_code"]=> string(8) "pack_002"} Db::startTrans(); try { $content = ""; // ## 发放奖品获取 if($drawInfo['type'] == 'pack'){ // 礼包兑换码(游戏兑换) $giftResult = $handleService->getCacheGiftCode($drawInfo['mark_code']); if($giftResult['code'] != 200 || empty($giftResult['data']['code'])){ throw new \Exception('礼包码发放失败!', -112); } $content = $giftResult['data']['code']; } else { // 代金券(发放到祈盟账户) $getMemCou = $handleService->getMemberCoupon($drawInfo['mark_code'], $this->userInfo['id']); if($getMemCou['code'] != 200 || empty($getMemCou['data']['code'])){ throw new \Exception("{$getMemCou['msg']}({$getMemCou['code']})", -114); } } // ## 保存中奖记录 $data = [ 'user_id' => $this->userInfo['id'], 'prize_mark' => $drawInfo['prize_mark'], 'prize_name' => $drawInfo['prize_name'], 'prize_type' => $drawInfo['type']==='pack'?1:2, // 1=礼包,2=代金券 'content' => $content, // 中奖内容(礼包=兑换码,2=代金卷) 'create_time' => date('Y-m-d H:i:s', NOW_TIMESTAMP) ]; $winningRes = Db::table('lr_user_winning')->insert($data); if(!$winningRes){ return $this->resultFail('记录保存失败!', -120); } $userRes = Db::table('lr_user_info')->where(['user_id' => $this->userInfo['id']])->setDec('lottery_count'); if(!$userRes){ return $this->resultFail('抽奖次数扣除失败!', -121); } if($drawInfo['type'] == "pack"){ // 更新礼包码状态 $prizeGiftRes = Db::table('lr_prize_gift')->where(['code' => $content])->update(['user_id' => $this->userInfo['id'], 'status' => 2, 'claim_time' => date('Y-m-d H:i:s', NOW_TIMESTAMP)]); if(!$prizeGiftRes){ return $this->resultFail('礼包记录使用失败!', -122); } $res = Db::table('lr_prize')->where(['mark_code' => $drawInfo['mark_code']])->setDec('remaining_num'); if(!$res){ return $this->resultFail('礼包操作失败!', -123); } } // 使用数量+1 $res = Db::table('lr_prize')->where(['mark_code' => $drawInfo['mark_code']])->setInc('use_num'); if(!$res){ return $this->resultFail('礼包操作失败!', -124); } $result = [ 'prize_mark' => $drawInfo['prize_mark'], 'prize_name' => $drawInfo['prize_name'], 'prize_type' => $drawInfo['type']==='pack'?1:2, // 1=礼包,2=代金券 'content' => $content, // 中奖内容(礼包=兑换码,2=代金卷) ]; Db::commit(); } catch (\Exception $e) { Db::rollback(); if($e->getCode() <= -120){ $handleService->addCacheGiftCode($drawInfo['mark_code'], [$content]); // 回滚礼包码 } log_message("MLBB#Game.handleLottery - error: {$e->getMessage()}", 'log', LOG_PATH . 'mlbb_log/'); return $this->resultFail("抽奖失败, {$e->getMessage()}({$e->getCode()})", -199); } return $this->resultSuccess(['info' => $result]); } }