PayRechargeController.php 70 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670
  1. <?php
  2. namespace App\Http\Controllers\Game;
  3. use App\Facade\TableName;
  4. use App\Game\GlobalUserInfo;
  5. use App\Game\Services\OuroGameService;
  6. use App\Http\Controllers\Controller;
  7. use App\Http\helper\NumConfig;
  8. use App\Models\Order;
  9. use App\Services\OrderServices;
  10. use App\Services\PaidRewardStatisticsService;
  11. use App\Utility\SetNXLock;
  12. use App\Util;
  13. use Illuminate\Http\Request;
  14. use Illuminate\Support\Facades\App;
  15. use Illuminate\Support\Facades\DB;
  16. use Illuminate\Support\Facades\Redis;
  17. class PayRechargeController extends Controller
  18. {
  19. /**
  20. * 设置用户语言环境
  21. */
  22. private function setUserLocale($request)
  23. {
  24. $user = $request->user();
  25. if ($user) {
  26. $locale = GlobalUserInfo::getLocaleByUserID($user->UserID, 'en');
  27. App::setLocale($locale);
  28. }
  29. }
  30. // 充值记录
  31. public function orderList(Request $request)
  32. {
  33. $user_id = (int)$request->globalUser->UserID;//$request->get('user_id', 1);
  34. $page = $request->get('page', 1);
  35. $pageSize = $request->get('pageSize', 20);
  36. $redisKey = 'PayRecharge_orderList_'.$user_id;
  37. if (!SetNXLock::getExclusiveLock($redisKey)) {
  38. return apiReturnFail(['web.withdraw.try_again_later','Tente novamente mais tarde']);
  39. }
  40. $where[] = ['user_id', $user_id];
  41. $where[] = ['pay_status', 1];
  42. $cacheTime = 60 * rand(1, 2);
  43. // $list = cache()->remember($user_id . '_order_list', $cacheTime, function () use ($where, $pageSize) {
  44. //
  45. // return Order::where($where)
  46. // ->orderBy('finished_at', 'desc')
  47. // ->selectRaw('amount,payment_code,order_sn as payment_sn,finished_at,created_at,pay_status')
  48. // ->paginate(15,['*'],'page',1);
  49. // });
  50. $list = Order::query()->where($where)
  51. ->orderBy('finished_at', 'desc')
  52. ->selectRaw('amount,payment_code,order_sn as payment_sn,finished_at,created_at,pay_status,type')
  53. ->paginate($pageSize);
  54. // ->paginate(15,['*'],'page',1);
  55. foreach ($list as &$val) {
  56. $val->amount = number_format($val->amount, 2, '.', '');
  57. }
  58. SetNXLock::release($redisKey);
  59. return apiReturnSuc($list);
  60. }
  61. // 首充
  62. public function firstPay(Request $request)
  63. {
  64. $user = $request->user();
  65. $user_recharge = DB::table(TableName::QPAccountsDB() . 'YN_VIPAccount')
  66. ->where('UserID', $user->UserID)
  67. ->value('Recharge') ?: 0;
  68. if($user_recharge)return apiReturnSuc();
  69. $firstPayGift = DB::table('agent.dbo.recharge_gift')
  70. ->where('gift_id', 301)->first();
  71. if(!$firstPayGift) return apiReturnFail();
  72. $names = DB::table('agent.dbo.admin_configs')
  73. ->where([
  74. 'type' => 'pay_method',
  75. 'status' => 1,
  76. ])
  77. ->selectRaw('id, name, status, new_pay_type as type')
  78. ->orderByDesc('sort')->get()->toArray();
  79. $list = DB::table('agent.dbo.recharge_gear')
  80. ->select('id','money','favorable_price','give')
  81. ->orderBy('money', 'asc')->where('status', 1)->get();
  82. $gear = Util::filterGearByDevice(\GuzzleHttp\json_encode($names));
  83. foreach ($list as &$val) {
  84. $val->favorable_price = $val->favorable_price + $val->give;
  85. $val->gear = $gear;
  86. $val->recommend = 0;
  87. if($val->money == $firstPayGift->recommend){
  88. $val->recommend = 1;
  89. }
  90. }
  91. return apiReturnSuc(compact('list', 'firstPayGift'));
  92. }
  93. // 首充礼包(带倒计时逻辑)
  94. public function firstPayGift(Request $request)
  95. {
  96. $user = $request->user();
  97. $this->setUserLocale($request);
  98. // 获取礼包配置
  99. $giftConfig = DB::table('agent.dbo.recharge_gift')
  100. ->where('gift_id', 301)
  101. ->first();
  102. if (!$giftConfig) {
  103. return apiReturnFail(['web.gift.config_not_exists', __('web.gift.config_not_exists')]);
  104. }
  105. // 检查用户是否购买了首充礼包
  106. $giftRecord = DB::table('agent.dbo.first_pay_gift_records')
  107. ->where('user_id', $user->UserID)
  108. ->first();
  109. // ========== 未购买礼包:返回充值列表 + 礼包配置 + 倒计时 ==========
  110. if (!$giftRecord) {
  111. // 获取充值档位列表
  112. $list = DB::table('agent.dbo.recharge_gear')
  113. ->select('money', 'favorable_price', 'give', 'gear')
  114. ->orderBy('money', 'asc')
  115. ->where('status', 1)
  116. ->where('in_shop', 1)
  117. ->get();
  118. foreach ($list as &$val) {
  119. $val->favorable_price = $val->favorable_price + $val->give;
  120. $val->recommend = 0;
  121. if ($val->money == $giftConfig->recommend) {
  122. $val->recommend = 1;
  123. }
  124. if (!empty($val->gear)) {
  125. $val->gear = Util::filterGearByDevice($val->gear);
  126. }
  127. }
  128. // ========== 处理倒计时逻辑(仅未购买时) ==========
  129. $redisKey = "first_pay_gift_timer_{$user->UserID}";
  130. $currentTime = time();
  131. $timeLeft = 0;
  132. $timerData = Redis::get($redisKey);
  133. if ($timerData) {
  134. $timerData = json_decode($timerData, true);
  135. $firstRequestTime = $timerData['first_request_time'];
  136. $phase = $timerData['phase'];
  137. // 阶段1:valid_h倒计时
  138. if ($phase === 'first') {
  139. $expireTime = $firstRequestTime + ($giftConfig->valid_h * 3600);
  140. if ($currentTime >= $expireTime) {
  141. $expireDate = date('Y-m-d', $expireTime);
  142. $currentDate = date('Y-m-d', $currentTime);
  143. if ($expireDate !== $currentDate) {
  144. // 进入阶段2
  145. $nextDayStart = time();
  146. $newExpireTime = $nextDayStart + ($giftConfig->valid_h_2 * 3600);
  147. $newTimerData = [
  148. 'first_request_time' => $firstRequestTime,
  149. 'phase' => 'daily',
  150. 'current_cycle_start' => $nextDayStart,
  151. 'last_expire_time' => $newExpireTime
  152. ];
  153. Redis::set($redisKey, json_encode($newTimerData));
  154. $timeLeft = max(0, $newExpireTime - $currentTime);
  155. }
  156. } else {
  157. $timeLeft = $expireTime - $currentTime;
  158. }
  159. }
  160. // 阶段2:每日循环
  161. elseif ($phase === 'daily') {
  162. $currentCycleStart = $timerData['current_cycle_start'];
  163. $expireTime = $currentCycleStart + ($giftConfig->valid_h_2 * 3600);
  164. if ($currentTime >= $expireTime) {
  165. $expireDate = date('Y-m-d', $expireTime);
  166. $currentDate = date('Y-m-d', $currentTime);
  167. if ($expireDate !== $currentDate) {
  168. $todayStart = time();
  169. $newExpireTime = $todayStart + ($giftConfig->valid_h_2 * 3600);
  170. $newTimerData = [
  171. 'first_request_time' => $firstRequestTime,
  172. 'phase' => 'daily',
  173. 'current_cycle_start' => $todayStart,
  174. 'last_expire_time' => $newExpireTime
  175. ];
  176. Redis::set($redisKey, json_encode($newTimerData));
  177. $timeLeft = max(0, $newExpireTime - $currentTime);
  178. }
  179. } else {
  180. $timeLeft = $expireTime - $currentTime;
  181. }
  182. }
  183. } else {
  184. // 首次请求,初始化倒计时
  185. $expireTime = $currentTime + ($giftConfig->valid_h * 3600);
  186. $timerData = [
  187. 'first_request_time' => $currentTime,
  188. 'phase' => 'first',
  189. 'last_expire_time' => $expireTime
  190. ];
  191. Redis::set($redisKey, json_encode($timerData));
  192. $timeLeft = $giftConfig->valid_h * 3600;
  193. }
  194. return apiReturnSuc([
  195. 'has_purchased' => false, // 未购买标记
  196. 'list' => $list, // 充值档位列表
  197. 'gift_info' => [
  198. 'gift_id' => $giftConfig->gift_id,
  199. 'gift_name' => $giftConfig->gift_name,
  200. 'total_bonus' => $giftConfig->total_bonus,
  201. 'bonus_instantly' => $giftConfig->bonus_instantly,
  202. 'day_rewards' => $giftConfig->day_rewards ? json_decode($giftConfig->day_rewards) : null,
  203. 'betting_bonus' => $giftConfig->betting_bonus ? json_decode($giftConfig->betting_bonus) : null,
  204. 'betting_task' => $giftConfig->betting_task ? json_decode($giftConfig->betting_task) : null,
  205. ],
  206. 'time_left' => $timeLeft, // ✅ 倒计时(未购买时展示)
  207. 'expire_at' => time() + $timeLeft // ✅ 过期时间戳
  208. ]);
  209. }
  210. // ========== 已购买礼包:返回任务进度(无倒计时) ==========
  211. // 获取用户当前累计下注次数(从RecordUserGameCount表)
  212. $currentTotalBetCount = DB::table(TableName::QPRecordDB() . 'RecordUserGameCount')
  213. ->where('UserID', $user->UserID)
  214. ->sum('Cnt') ?? 0;
  215. // 获取用户当前累计下注金额(从统计表,用于下注任务)
  216. $userStats = DB::table('QPRecordDB.dbo.RecordUserTotalStatistics')
  217. ->where('UserID', $user->UserID)
  218. ->first();
  219. $currentTotalBetAmount = $userStats->TotalBet ?? 0;
  220. // 更新下注进度到礼包记录(betting_current_bet存储下注次数,用于下注奖励)
  221. DB::table('agent.dbo.first_pay_gift_records')
  222. ->where('user_id', $user->UserID)
  223. ->update([
  224. 'betting_current_bet' => $currentTotalBetCount,
  225. 'updated_at' => date('Y-m-d H:i:s')
  226. ]);
  227. // 重新获取最新记录
  228. $giftRecord = DB::table('agent.dbo.first_pay_gift_records')
  229. ->where('user_id', $user->UserID)
  230. ->first();
  231. // 解析任务数据
  232. $dayRewardsData = $giftRecord->day_rewards_data ? json_decode($giftRecord->day_rewards_data, true) : null;
  233. $bettingBonusData = $giftRecord->betting_bonus_data ? json_decode($giftRecord->betting_bonus_data, true) : null;
  234. $bettingTaskData = $giftRecord->betting_task_data ? json_decode($giftRecord->betting_task_data, true) : null;
  235. // 计算当前是购买后的第几天(所有任务都需要用到)
  236. $purchaseDate = date('Y-m-d', strtotime($giftRecord->created_at));
  237. $today = date('Y-m-d');
  238. $daysPassed = floor((strtotime($today) - strtotime($purchaseDate)) / 86400);
  239. // 构建返回数据
  240. $giftInfo = [
  241. 'gift_id' => $giftRecord->gift_id,
  242. 'gift_name' => $giftRecord->gift_name,
  243. 'total_bonus' => (float)$giftRecord->total_bonus,
  244. 'bonus_instantly' => (float)$giftRecord->bonus_instantly,
  245. 'pay_amount' => (float)$giftRecord->pay_amount,
  246. ];
  247. // 每日奖励进度
  248. if ($dayRewardsData) {
  249. $startDay = $dayRewardsData['start_day'] ?? 1;
  250. $bonusDay = $dayRewardsData['bonus_day'] ?? 0;
  251. $claimedDays = $giftRecord->day_rewards_claimed;
  252. // $startDay = $startDay-1;
  253. // 判断每日奖励状态
  254. // 0=不可领取, 1=可领取, 2=已领取, 3=过期
  255. $dayRewardStatus = 0; // 默认不可领取
  256. // 检查是否过期(购买后7天)
  257. if ($daysPassed >= 7) {
  258. $dayRewardStatus = 3; // 过期
  259. } elseif ($daysPassed >= $startDay-1) {
  260. // 计算今天是第几个奖励日(从起始天数开始)
  261. $rewardIndex = $daysPassed - ($startDay-1);
  262. if ($rewardIndex < $bonusDay) {
  263. // 在奖励期内
  264. if ($claimedDays > $rewardIndex) {
  265. $dayRewardStatus = 2; // 已领取
  266. } else {
  267. // 即便前几天漏领,后续奖励仍可继续领取(漏掉的视为作废)
  268. $dayRewardStatus = 1; // 可领取
  269. }
  270. } else {
  271. // 超过奖励天数
  272. $dayRewardStatus = 2; // 已领取完
  273. }
  274. }
  275. $giftInfo['day_rewards'] = [
  276. 'total_bonus' => (float)$giftRecord->day_rewards_total,
  277. 'bonus_day' => $bonusDay,
  278. 'start_day' => $startDay,
  279. 'bonus' => $dayRewardsData['bonus'] ?? [],
  280. 'daysPassed' => $daysPassed,
  281. 'claimed_days' => $claimedDays,
  282. 'progress' => $claimedDays . '/' . $bonusDay,
  283. 'status' => $dayRewardStatus, // 0=不可领取, 1=可领取, 2=已领取, 3=过期
  284. 'status_text' => [
  285. __('web.gift.status_cannot_claim'),
  286. __('web.gift.status_can_claim'),
  287. __('web.gift.status_claimed'),
  288. __('web.gift.status_expired')
  289. ][$dayRewardStatus] ?? __('web.gift.status_unknown')
  290. ];
  291. }
  292. // 下注奖励进度(使用下注次数)
  293. if ($bettingBonusData) {
  294. $perBet = $bettingBonusData['per_bet'] ?? 100; // 每次下注次数要求
  295. $perBetBonus = $bettingBonusData['per_bet_bonus'] ?? 2; // 每次奖励金额(不是百分比)
  296. $currentBetCount = $giftRecord->betting_current_bet; // 当前累计下注次数
  297. $totalBonusLimit = $giftRecord->betting_bonus_total; // 总奖励上限
  298. $claimedAmount = $giftRecord->betting_bonus_claimed; // 已领取金额
  299. $remainingBonus = $totalBonusLimit - $claimedAmount; // 剩余可领取金额
  300. // 每次可领取的金额(直接使用配置的值,不是百分比计算)
  301. $perReward = (float)$perBetBonus;
  302. // 根据当前下注次数计算已达成的次数
  303. $completedTimes = floor($currentBetCount / $perBet);
  304. // 已领取的次数
  305. $claimedTimes = $claimedAmount > 0 ? floor($claimedAmount / $perReward) : 0;
  306. // 当前可领取次数(但不能超过剩余总额)
  307. $canClaimTimes = $completedTimes - $claimedTimes;
  308. $maxCanClaimTimes = floor($remainingBonus / $perReward); // 剩余总额最多可领次数
  309. $canClaimTimes = min($canClaimTimes, $maxCanClaimTimes);
  310. // 当前可领取金额
  311. $canClaimAmount = min($canClaimTimes * $perReward, $remainingBonus);
  312. // 计算下次领取需要的下注次数
  313. $nextClaimBet = 0;
  314. if ($remainingBonus > 0 && $canClaimTimes == 0) {
  315. // 还有剩余奖励但当前不能领取,计算还需下注多少次
  316. $nextClaimBet = ($claimedTimes + 1) * $perBet - $currentBetCount;
  317. }
  318. // 判断下注奖励状态
  319. // 0=不可领取(可领取金额为0), 1=可领取, 2=已领取(所有奖励都领完), 3=过期
  320. $bettingBonusStatus = 0; // 默认不可领取
  321. // 检查是否过期(购买后7天)
  322. if ($daysPassed >= 7) {
  323. $bettingBonusStatus = 3; // 过期
  324. } elseif ($remainingBonus <= 0) {
  325. $bettingBonusStatus = 2; // 已领取完
  326. } elseif ($canClaimAmount > 0) {
  327. $bettingBonusStatus = 1; // 可领取
  328. } else {
  329. $bettingBonusStatus = 0; // 不可领取(下注次数不足)
  330. }
  331. $giftInfo['betting_bonus'] = [
  332. 'total_bonus' => (float)$totalBonusLimit, // 总奖励上限
  333. 'per_bet' => $perBet, // 每次下注次数要求
  334. 'per_bet_bonus' => $perReward, // 每次奖励金额(实际金额)
  335. // 'per_reward' => $perReward, // 每次奖励金额(保持兼容)
  336. 'current_bet' => (float)$currentBetCount, // 当前累计下注次数
  337. 'claimed_amount' => (float)$claimedAmount, // 已领取金额
  338. 'remaining_bonus' => (float)$remainingBonus, // 剩余可领金额
  339. 'can_claim_amount' => (float)$canClaimAmount, // 当前可领取金额
  340. 'can_claim_times' => max(0, $canClaimTimes), // 当前可领取次数
  341. 'next_claim_bet' => max(0, $nextClaimBet), // 下次领取还需下注次数
  342. 'progress' => round($currentBetCount, 0) . '/' . round($claimedTimes * $perBet + $perBet, 0), // 当前进度/下次领取目标(次数)
  343. 'status' => $bettingBonusStatus, // 0=不可领取, 1=可领取, 2=已领取, 3=过期
  344. 'status_text' => [
  345. __('web.gift.status_cannot_claim'),
  346. __('web.gift.status_can_claim'),
  347. __('web.gift.status_claimed'),
  348. __('web.gift.status_expired')
  349. ][$bettingBonusStatus] ?? __('web.gift.status_unknown')
  350. ];
  351. }
  352. // 下注任务进度(使用下注金额)
  353. if ($bettingTaskData) {
  354. $betPayTimes = $bettingTaskData['bet_pay_times'] ?? 60;
  355. $requiredBet = $giftRecord->pay_amount * $betPayTimes;
  356. $currentProgress = $currentTotalBetAmount / NumConfig::NUM_VALUE; // 使用下注金额,不是次数
  357. $taskCompleted = $currentProgress >= $requiredBet;
  358. $isClaimed = $giftRecord->betting_task_claimed == 1;
  359. // 判断下注任务状态
  360. // 0=不可领取, 1=可领取, 2=已领取, 3=过期
  361. $bettingTaskStatus = 0; // 默认不可领取
  362. // 检查是否过期(购买后7天)
  363. if ($daysPassed >= 7) {
  364. $bettingTaskStatus = 3; // 过期
  365. } elseif ($isClaimed) {
  366. $bettingTaskStatus = 2; // 已领取
  367. } elseif ($taskCompleted) {
  368. $bettingTaskStatus = 1; // 可领取(任务完成且未领取)
  369. } else {
  370. $bettingTaskStatus = 0; // 不可领取(任务未完成)
  371. }
  372. $giftInfo['betting_task'] = [
  373. 'total_bonus' => (float)$giftRecord->betting_task_total,
  374. 'bet_pay_times' => $betPayTimes,
  375. 'required_bet' => $requiredBet, // 需要下注的金额
  376. 'current_bet' => (float)$currentProgress, // 当前累计下注
  377. 'progress' => round($currentProgress, 2) . '/' . $requiredBet,
  378. 'status' => $bettingTaskStatus, // 0=不可领取, 1=可领取, 2=已领取, 3=过期
  379. 'status_text' => [
  380. __('web.gift.status_cannot_claim'),
  381. __('web.gift.status_can_claim'),
  382. __('web.gift.status_claimed'),
  383. __('web.gift.status_expired')
  384. ][$bettingTaskStatus] ?? __('web.gift.status_unknown')
  385. ];
  386. }
  387. $giftInfo['expired'] = strtotime(date('Y-m-d',strtotime($giftRecord->created_at)))+86400*7;
  388. return apiReturnSuc([
  389. 'has_purchased' => true, // 已购买标记
  390. 'gift_info' => $giftInfo
  391. // ✅ 已购买用户不返回倒计时
  392. ]);
  393. }
  394. /**
  395. * 领取首充礼包奖励
  396. */
  397. public function claimFirstPayGiftReward(Request $request)
  398. {
  399. $user = $request->user();
  400. $userId = $user->UserID;
  401. $rewardType = $request->input('reward_type'); // 'day_reward', 'betting_bonus', 'betting_task'
  402. $this->setUserLocale($request);
  403. // 获取礼包记录
  404. $giftRecord = DB::table('agent.dbo.first_pay_gift_records')
  405. ->where('user_id', $userId)
  406. ->first();
  407. if (!$giftRecord) {
  408. return apiReturnFail(['web.gift.not_purchased', __('web.gift.not_purchased')]);
  409. }
  410. $rewardAmount = 0;
  411. try {
  412. // 每日奖励领取
  413. if ($rewardType === 'day_reward') {
  414. $dayRewardsData = json_decode($giftRecord->day_rewards_data, true);
  415. if (!$dayRewardsData) {
  416. return apiReturnFail(['web.gift.no_day_rewards_config', __('web.gift.no_day_rewards_config')]);
  417. }
  418. $bonusDay = $dayRewardsData['bonus_day'] ?? 0;
  419. $startDay = $dayRewardsData['start_day'] ?? 1;
  420. $bonusArray = $dayRewardsData['bonus'] ?? [];
  421. $claimedDays = $giftRecord->day_rewards_claimed;
  422. // 检查是否还有可领取的天数
  423. if ($claimedDays >= $bonusDay) {
  424. return apiReturnFail(['web.gift.day_rewards_all_claimed', __('web.gift.day_rewards_all_claimed')]);
  425. }
  426. // 计算当前是购买后的第几天
  427. $purchaseDate = date('Y-m-d', strtotime($giftRecord->created_at));
  428. $currentDate = date('Y-m-d');
  429. $daysPassed = floor((strtotime($currentDate) - strtotime($purchaseDate)) / 86400);
  430. // 检查是否到了可以领取的天数(从第start_day天开始)
  431. if ($daysPassed < $startDay-1) {
  432. return apiReturnFail(['web.gift.day_rewards_not_time', str_replace(':day', $startDay, __('web.gift.day_rewards_not_time'))]);
  433. }
  434. // 计算今天应该领取第几天的奖励
  435. // 例如:start_day=2,今天是第3天,应该领取第1个奖励(索引0)
  436. $todayRewardIndex = $daysPassed - ($startDay-1);
  437. // 检查是否超过奖励天数
  438. if ($todayRewardIndex >= $bonusDay) {
  439. return apiReturnFail(['web.gift.day_rewards_expired', __('web.gift.day_rewards_expired')]);
  440. }
  441. // 检查今天是否已领取
  442. $lastClaimDate = $giftRecord->day_last_claim_date;
  443. if ($lastClaimDate && $lastClaimDate === $currentDate) {
  444. return apiReturnFail(['web.gift.day_rewards_claimed_today', __('web.gift.day_rewards_claimed_today')]);
  445. }
  446. // 检查是否跳过了某些天(过期不补领)
  447. // 如果今天应该领第5天的奖励,但用户只领了3天,那就直接领第5天的
  448. if ($todayRewardIndex > $claimedDays) {
  449. // 跳过了一些天,更新已领取天数为今天的索引
  450. $claimedDays = $todayRewardIndex;
  451. }
  452. // 计算今天可领取的奖励(使用todayRewardIndex作为索引)
  453. $todayBonusPercent = $bonusArray[$todayRewardIndex] ?? 0;
  454. $rewardAmount = round($giftRecord->pay_amount * $todayBonusPercent / 100, 2);
  455. // 更新记录
  456. DB::table('agent.dbo.first_pay_gift_records')
  457. ->where('user_id', $userId)
  458. ->update([
  459. 'day_rewards_claimed' => $todayRewardIndex + 1, // 已领取到第几天(索引+1)
  460. 'day_last_claim_date' => $currentDate,
  461. 'updated_at' => date('Y-m-d H:i:s')
  462. ]);
  463. }
  464. // 下注奖励领取(使用下注次数)
  465. elseif ($rewardType === 'betting_bonus') {
  466. $bettingBonusData = json_decode($giftRecord->betting_bonus_data, true);
  467. if (!$bettingBonusData) {
  468. return apiReturnFail(['web.gift.no_betting_bonus_config', __('web.gift.no_betting_bonus_config')]);
  469. }
  470. // 检查是否过期(购买后7天)
  471. $purchaseDate = date('Y-m-d', strtotime($giftRecord->created_at));
  472. $currentDate = date('Y-m-d');
  473. $daysPassed = floor((strtotime($currentDate) - strtotime($purchaseDate)) / 86400);
  474. if ($daysPassed >= 7) {
  475. return apiReturnFail(['web.gift.betting_bonus_expired', __('web.gift.betting_bonus_expired')]);
  476. }
  477. // 获取最新的下注次数
  478. $currentBetCount = DB::table(TableName::QPRecordDB() . 'RecordUserGameCount')
  479. ->where('UserID', $userId)
  480. ->sum('Cnt') ?? 0;
  481. $perBet = $bettingBonusData['per_bet'] ?? 100; // 每次下注次数要求
  482. $perBetBonus = $bettingBonusData['per_bet_bonus'] ?? 2; // 每次奖励金额(不是百分比)
  483. $totalBonusLimit = $giftRecord->betting_bonus_total; // 总奖励上限
  484. $claimedAmount = $giftRecord->betting_bonus_claimed; // 已领取金额
  485. $remainingBonus = $totalBonusLimit - $claimedAmount; // 剩余可领金额
  486. // 检查是否还有剩余奖励
  487. if ($remainingBonus <= 0) {
  488. return apiReturnFail(['web.gift.betting_bonus_all_claimed', __('web.gift.betting_bonus_all_claimed')]);
  489. }
  490. // 每次可领取的金额(直接使用配置的值,不是百分比计算)
  491. $perReward = (float)$perBetBonus;
  492. // 根据当前下注次数计算已达成的次数
  493. $completedTimes = floor($currentBetCount / $perBet);
  494. // 已领取的次数
  495. $claimedTimes = $claimedAmount > 0 ? floor($claimedAmount / $perReward) : 0;
  496. // 可领取次数(下注达成的次数 - 已领取次数)
  497. $canClaimTimes = $completedTimes - $claimedTimes;
  498. // 检查是否可以领取
  499. if ($canClaimTimes <= 0) {
  500. $neededBets = (($claimedTimes + 1) * $perBet - $currentBetCount);
  501. return apiReturnFail(['web.gift.betting_bonus_insufficient', str_replace(':times', $neededBets, __('web.gift.betting_bonus_insufficient'))]);
  502. }
  503. // ✅ 一次性领取所有已达成的奖励(但不能超过剩余总额)
  504. $totalCanClaimAmount = $canClaimTimes * $perReward; // 理论可领取总额
  505. $rewardAmount = min($totalCanClaimAmount, $remainingBonus); // 实际领取金额(不超过剩余总额)
  506. $actualClaimTimes = floor($rewardAmount / $perReward); // 实际领取次数
  507. // 更新记录(同时更新下注次数)
  508. DB::table('agent.dbo.first_pay_gift_records')
  509. ->where('user_id', $userId)
  510. ->update([
  511. 'betting_bonus_claimed' => $giftRecord->betting_bonus_claimed + $rewardAmount,
  512. 'betting_current_bet' => $currentBetCount, // 更新最新下注次数
  513. 'updated_at' => date('Y-m-d H:i:s')
  514. ]);
  515. \Log::info('下注奖励领取', [
  516. 'user_id' => $userId,
  517. 'can_claim_times' => $canClaimTimes,
  518. 'actual_claim_times' => $actualClaimTimes,
  519. 'reward_amount' => $rewardAmount
  520. ]);
  521. }
  522. // 下注任务领取(使用下注金额)
  523. elseif ($rewardType === 'betting_task') {
  524. if ($giftRecord->betting_task_claimed == 1) {
  525. return apiReturnFail(['web.gift.betting_task_claimed', __('web.gift.betting_task_claimed')]);
  526. }
  527. $bettingTaskData = json_decode($giftRecord->betting_task_data, true);
  528. if (!$bettingTaskData) {
  529. return apiReturnFail(['web.gift.no_betting_task_config', __('web.gift.no_betting_task_config')]);
  530. }
  531. // 检查是否过期(购买后7天)
  532. $purchaseDate = date('Y-m-d', strtotime($giftRecord->created_at));
  533. $currentDate = date('Y-m-d');
  534. $daysPassed = floor((strtotime($currentDate) - strtotime($purchaseDate)) / 86400);
  535. if ($daysPassed >= 7) {
  536. return apiReturnFail(['web.gift.betting_task_expired', __('web.gift.betting_task_expired')]);
  537. }
  538. // 获取最新的下注金额
  539. $userStats = DB::table('QPRecordDB.dbo.RecordUserTotalStatistics')
  540. ->where('UserID', $userId)
  541. ->first();
  542. $currentBetAmount = ($userStats->TotalBet ?? 0) / NumConfig::NUM_VALUE;
  543. $betPayTimes = $bettingTaskData['bet_pay_times'] ?? 60;
  544. $requiredBet = $giftRecord->pay_amount * $betPayTimes;
  545. if ($currentBetAmount < $requiredBet) {
  546. return apiReturnFail(['web.gift.betting_task_insufficient', str_replace(':amount', $requiredBet, __('web.gift.betting_task_insufficient'))]);
  547. }
  548. $rewardAmount = $giftRecord->betting_task_total;
  549. // 更新记录
  550. DB::table('agent.dbo.first_pay_gift_records')
  551. ->where('user_id', $userId)
  552. ->update([
  553. 'betting_task_claimed' => 1,
  554. 'updated_at' => date('Y-m-d H:i:s')
  555. ]);
  556. }
  557. else {
  558. return apiReturnFail(['web.gift.invalid_reward_type', __('web.gift.invalid_reward_type')]);
  559. }
  560. // 添加奖励到用户账户
  561. if ($rewardAmount > 0) {
  562. OuroGameService::AddScore($userId, $rewardAmount * NumConfig::NUM_VALUE, 52, true); // 52=首充礼包奖励
  563. $userRecharge = DB::table('QPAccountsDB.dbo.YN_VIPAccount')->lock('with(nolock)')
  564. ->where('UserID', $userId)
  565. ->value('Recharge') ?: 0;
  566. if ($userRecharge > 0) {
  567. app(PaidRewardStatisticsService::class)
  568. ->incrementRecordByDateIDAndType(date('Ymd'), 'first_recharge_claim',
  569. $rewardAmount * NumConfig::NUM_VALUE);
  570. }
  571. \Log::info('首充礼包奖励领取', [
  572. 'user_id' => $userId,
  573. 'reward_type' => $rewardType,
  574. 'amount' => $rewardAmount
  575. ]);
  576. }
  577. return apiReturnSuc([
  578. 'amount' => $rewardAmount,
  579. 'message' => str_replace(':amount', $rewardAmount, __('web.gift.claim_success'))
  580. ]);
  581. } catch (\Exception $e) {
  582. \Log::error('首充礼包奖励领取失败', [
  583. 'user_id' => $userId,
  584. 'error' => $e->getMessage()
  585. ]);
  586. return apiReturnFail(['web.gift.claim_failed', str_replace(':error', $e->getMessage(), __('web.gift.claim_failed'))]);
  587. }
  588. }
  589. /**
  590. * 获取首充礼包数据(包含充值档位列表)
  591. * @param $firstPayGift 礼包配置
  592. * @param $timeLeft 剩余秒数(已经是用户实际剩余时间)
  593. */
  594. private function getFirstPayGiftData($firstPayGift, $timeLeft)
  595. {
  596. // 获取支付方式
  597. // $names = DB::table('agent.dbo.admin_configs')
  598. // ->where([
  599. // 'type' => 'pay_method',
  600. // 'status' => 1,
  601. // ])
  602. // ->selectRaw('id, name, status, new_pay_type as type')
  603. // ->orderByDesc('sort')
  604. // ->get()
  605. // ->toArray();
  606. // 获取充值档位
  607. $list = DB::table('agent.dbo.recharge_gear')
  608. ->select('money', 'favorable_price', 'give','gear')
  609. ->orderBy('money', 'asc')
  610. ->where('status', 1)
  611. ->where('in_shop', 1)
  612. ->get();
  613. // $gear = \GuzzleHttp\json_encode($names);
  614. foreach ($list as &$val) {
  615. $val->favorable_price = $val->favorable_price + $val->give;
  616. // $val->gear = $gear;
  617. $val->recommend = 0;
  618. if ($val->money == $firstPayGift->recommend) {
  619. $val->recommend = 1;
  620. }
  621. if (!empty($val->gear)) {
  622. $val->gear = Util::filterGearByDevice($val->gear);
  623. }
  624. }
  625. return apiReturnSuc([
  626. 'list' => $list,
  627. 'gift_info' => [
  628. 'gift_id' => $firstPayGift->gift_id,
  629. 'gift_name' => $firstPayGift->gift_name,
  630. 'total_bonus' => $firstPayGift->total_bonus,
  631. 'bonus_instantly' => $firstPayGift->bonus_instantly,
  632. 'day_rewards' => $firstPayGift->day_rewards?json_decode($firstPayGift->day_rewards):'',
  633. 'betting_bonus' => $firstPayGift->betting_bonus?json_decode($firstPayGift->betting_bonus):'',
  634. 'betting_task' => $firstPayGift->betting_task?json_decode($firstPayGift->betting_task):'',
  635. ],
  636. 'time_left' => $timeLeft, // 剩余秒数
  637. 'expire_at' => time() + $timeLeft // 过期时间戳
  638. ]);
  639. }
  640. public function firstPayMulti(Request $request)
  641. {
  642. $user = LoginController::checkLogin($request);
  643. if($user){
  644. if(env('CONFIG_24680_NFTD_99',0)==0)if($user->Channel==99)return apiReturnFail();
  645. $fpkey='Firstpay_'.$user->UserID;
  646. if(Redis::exists($fpkey)){
  647. $data=Redis::get($fpkey);
  648. $data=json_decode($data,true);
  649. $data['timeleft']=86400-(time()-$data['buytime']);
  650. return apiReturnSuc(['leftitem'=>$data]);
  651. }
  652. $user_recharge = DB::table(TableName::QPAccountsDB() . 'YN_VIPAccount')
  653. ->where('UserID', $user->UserID)
  654. ->value('Recharge') ?: 0;
  655. if($user_recharge)return apiReturnFail();
  656. }
  657. $items=DB::table('agent.dbo.recharge_gear')
  658. ->where('status',1)
  659. ->where('second_give','>',0)
  660. ->where('first_pay','>=', 1)
  661. ->select('gift_id','money','give','favorable_price','second_give')->get()->each(function($item){
  662. $item->id=28;
  663. })->toArray();
  664. $default=count($items)-1;
  665. return apiReturnSuc(compact('items','default'));
  666. }
  667. // 破产礼包
  668. public function bankruptcyGift(Request $request)
  669. {
  670. $user = $request->user();
  671. $this->setUserLocale($request);
  672. // 判断用户是否充值
  673. $user_recharge = DB::table(TableName::QPAccountsDB() . 'YN_VIPAccount')
  674. ->where('UserID', $user->UserID)
  675. ->value('Recharge') ?: 0;
  676. if ($user_recharge <= 0) {
  677. return apiReturnFail(['web.gift.user_not_recharged', __('web.gift.user_not_recharged')]);
  678. }
  679. // 获取所有破产礼包配置 (gift_id=302)
  680. $bankruptcyGifts = DB::table('agent.dbo.recharge_gift')
  681. ->where('gift_id', 302)
  682. ->get();
  683. if ($bankruptcyGifts->isEmpty()) {
  684. return apiReturnFail(['web.gift.bankruptcy_gift_not_exists', __('web.gift.bankruptcy_gift_not_exists')]);
  685. }
  686. $userData = null;
  687. if ($user->UserID > 0) {
  688. $userData = GlobalUserInfo::getGameUserInfo('UserID', $user->UserID);
  689. if ($userData) $userData = GlobalUserInfo::toWebData($userData);
  690. }
  691. $result = [];
  692. // 遍历每条礼包配置,根据 recommend 关联 recharge_gear
  693. foreach ($bankruptcyGifts as $gift) {
  694. $gear = DB::table('agent.dbo.recharge_gear')
  695. ->select('money', 'favorable_price', 'gear')
  696. ->where('money', $gift->recommend)
  697. ->where('status', 1)
  698. ->first();
  699. if ($gear) {
  700. $gear->gift_id = $gift->gift_id;
  701. $gear->total_bonus = $gift->total_bonus;
  702. $gear->bonus = $gift->total_bonus - 100;
  703. if (!empty($gear->gear)) {
  704. $gear->gear = Util::filterGearByDevice($gear->gear,$userData);
  705. }
  706. $result[] = $gear;
  707. }
  708. }
  709. // 按 money 排序
  710. usort($result, function($a, $b) {
  711. return $a->money <=> $b->money;
  712. });
  713. return apiReturnSuc($result);
  714. }
  715. // 每日首充礼包
  716. public function dailyFirstRechargeGift(Request $request)
  717. {
  718. $user = $request->user();
  719. $this->setUserLocale($request);
  720. // 检查用户今日是否已充值(完成任意档位充值后入口消失)
  721. $todayStart = date('Y-m-d') . ' 00:00:00';
  722. $todayEnd = date('Y-m-d') . ' 23:59:59';
  723. $todayRecharge = DB::table('agent.dbo.order')
  724. ->where('user_id', $user->UserID)
  725. ->where('pay_status', 1)
  726. ->where('GiftsID', 303)
  727. ->where('pay_at', '>=', $todayStart)
  728. ->where('pay_at', '<=', $todayEnd)
  729. ->first();
  730. // 如果今日已充值,返回入口消失标记
  731. if ($todayRecharge) {
  732. return apiReturnSuc([
  733. 'has_recharged_today' => true,
  734. 'message' => __('web.gift.recharged_today')
  735. ]);
  736. }
  737. // 获取每日首充礼包配置 (gift_id=303)
  738. $dailyGifts = DB::table('agent.dbo.recharge_gift')
  739. ->where('gift_id', 303)
  740. ->get();
  741. if ($dailyGifts->isEmpty()) {
  742. return apiReturnFail(['web.gift.daily_first_recharge_not_exists', __('web.gift.daily_first_recharge_not_exists')]);
  743. }
  744. $result = [];
  745. // 遍历每条礼包配置,根据 recommend 关联 recharge_gear
  746. foreach ($dailyGifts as $gift) {
  747. $gear = DB::table('agent.dbo.recharge_gear')
  748. ->select('money', 'favorable_price', 'gear', 'give')
  749. ->where('money', $gift->recommend)
  750. ->where('status', 1)
  751. ->first();
  752. if ($gear) {
  753. $gear->gift_id = $gift->gift_id;
  754. $gear->total_bonus = $gift->total_bonus;
  755. $gear->bonus = $gift->total_bonus - 100;
  756. $gear->recommend = $gift->first_pay?1:0;
  757. if (!empty($gear->gear)) {
  758. $gear->gear = Util::filterGearByDevice($gear->gear);
  759. }
  760. $result[] = $gear;
  761. }
  762. }
  763. // 按 money 排序
  764. usort($result, function($a, $b) {
  765. return $a->money <=> $b->money;
  766. });
  767. return apiReturnSuc([
  768. 'has_recharged_today' => false,
  769. 'list' => $result
  770. ]);
  771. }
  772. // 每日礼包(三档充值)
  773. public function dailyGift(Request $request)
  774. {
  775. $user = $request->user();
  776. $this->setUserLocale($request);
  777. // 获取每日礼包配置 (gift_id=304),应该有3档
  778. $dailyGifts = DB::table('agent.dbo.recharge_gift')
  779. ->where('gift_id', 304)
  780. ->orderBy('recommend', 'asc')
  781. ->get();
  782. if ($dailyGifts->isEmpty()) {
  783. return apiReturnFail(['web.gift.daily_gift_not_exists', __('web.gift.daily_gift_not_exists')]);
  784. }
  785. if ($dailyGifts->count() > 3) {
  786. // 如果配置超过3档,只取前3档
  787. $dailyGifts = $dailyGifts->take(3);
  788. }
  789. // 检查用户今日每档的充值状态
  790. $todayStart = date('Y-m-d') . ' 00:00:00';
  791. $todayEnd = date('Y-m-d') . ' 23:59:59';
  792. $todayRecharges = DB::table('agent.dbo.order')
  793. ->where('user_id', $user->UserID)
  794. ->where('GiftsID', 304)
  795. ->where('pay_status', 1)
  796. ->where('pay_at', '>=', $todayStart)
  797. ->where('pay_at', '<=', $todayEnd)
  798. ->pluck('amount')
  799. ->toArray();
  800. $result = [];
  801. $completedCount = 0;
  802. // 遍历每档配置
  803. foreach ($dailyGifts as $index => $gift) {
  804. $gear = DB::table('agent.dbo.recharge_gear')
  805. ->select('money', 'favorable_price', 'gear', 'give')
  806. ->where('money', $gift->recommend)
  807. ->where('status', 1)
  808. ->first();
  809. if ($gear) {
  810. // 检查该档位今日是否已充值(使用浮点数比较,允许小数点精度差异)
  811. $isCompleted = false;
  812. foreach ($todayRecharges as $rechargeAmount) {
  813. if (abs($rechargeAmount/100 - $gift->recommend) < 0.01) {
  814. $isCompleted = true;
  815. break;
  816. }
  817. }
  818. if ($isCompleted) {
  819. $completedCount++;
  820. }
  821. $gear->gift_id = $gift->gift_id;
  822. $gear->total_bonus = $gift->total_bonus;
  823. $gear->bonus = $gift->total_bonus - 100;
  824. $gear->is_completed = $isCompleted; // 是否已完成
  825. $gear->gear_index = $index + 1; // 档位序号(1,2,3)
  826. $gear->recommend = $gift->first_pay?1:0;
  827. if (!empty($gear->gear)) {
  828. $gear->gear = Util::filterGearByDevice($gear->gear);
  829. }
  830. $result[] = $gear;
  831. }
  832. }
  833. // 获取额外奖励金额(从任意一档的 task_bonus 字段获取,task_bonus 是数字字段)
  834. $taskBonus = null;
  835. $firstGift = $dailyGifts->first();
  836. if ($firstGift && $firstGift->task_bonus !== null) {
  837. $taskBonus = round((float)$firstGift->task_bonus, 2);
  838. }
  839. // 检查是否可以领取额外奖励(三档都完成)
  840. $canClaimBonus = ($completedCount >= 3 && $taskBonus > 0);
  841. // 检查是否已领取过额外奖励
  842. $hasClaimedBonus = false;
  843. if ($canClaimBonus) {
  844. $redisKey = "daily_gift_bonus_claimed_{$user->UserID}_" . date('Y-m-d');
  845. $hasClaimedBonus = Redis::exists($redisKey);
  846. }
  847. return apiReturnSuc([
  848. 'list' => $result,
  849. 'completed_count' => $completedCount,
  850. 'total_count' => count($result),
  851. 'can_claim_bonus' => $canClaimBonus && !$hasClaimedBonus,
  852. 'has_claimed_bonus' => $hasClaimedBonus,
  853. 'task_bonus' => $taskBonus
  854. ]);
  855. }
  856. // 领取每日礼包三档完成后的额外奖励
  857. public function claimDailyGiftBonus(Request $request)
  858. {
  859. $user = $request->user();
  860. $userId = $user->UserID;
  861. $this->setUserLocale($request);
  862. // 检查三档是否都已完成
  863. $todayStart = date('Y-m-d') . ' 00:00:00';
  864. $todayEnd = date('Y-m-d') . ' 23:59:59';
  865. // 获取每日礼包配置
  866. $dailyGifts = DB::table('agent.dbo.recharge_gift')
  867. ->where('gift_id', 304)
  868. ->orderBy('recommend', 'asc')
  869. ->get()
  870. ->take(3);
  871. if ($dailyGifts->isEmpty()) {
  872. return apiReturnFail(['web.gift.daily_gift_not_exists', __('web.gift.daily_gift_not_exists')]);
  873. }
  874. // 检查每档今日是否都已充值
  875. $todayRecharges = DB::table('agent.dbo.order')
  876. ->where('user_id', $userId)
  877. ->where('GiftsID', 304)
  878. ->where('pay_status', 1)
  879. ->where('pay_at', '>=', $todayStart)
  880. ->where('pay_at', '<=', $todayEnd)
  881. ->pluck('amount')
  882. ->toArray();
  883. $completedCount = 0;
  884. foreach ($dailyGifts as $gift) {
  885. // 检查该档位是否已充值(使用浮点数比较)
  886. $isCompleted = false;
  887. foreach ($todayRecharges as $rechargeAmount) {
  888. if (abs($rechargeAmount/100 - $gift->recommend) < 0.01) {
  889. $isCompleted = true;
  890. break;
  891. }
  892. }
  893. if ($isCompleted) {
  894. $completedCount++;
  895. }
  896. }
  897. if ($completedCount < 3) {
  898. return apiReturnFail(['web.gift.three_tiers_not_completed', __('web.gift.three_tiers_not_completed')]);
  899. }
  900. // 检查是否已领取过
  901. $redisKey = "daily_gift_bonus_claimed_{$userId}_" . date('Y-m-d');
  902. if (Redis::exists($redisKey)) {
  903. return apiReturnFail(['web.gift.bonus_already_claimed_today', __('web.gift.bonus_already_claimed_today')]);
  904. }
  905. // 获取奖励金额(从任意一档的 task_bonus 获取,task_bonus 是数字字段)
  906. $firstGift = $dailyGifts->first();
  907. $rewardAmount = 0;
  908. if ($firstGift && $firstGift->task_bonus !== null) {
  909. $rewardAmount = round((float)$firstGift->task_bonus, 2);
  910. }
  911. if ($rewardAmount <= 0) {
  912. return apiReturnFail(['web.gift.bonus_config_not_exists', __('web.gift.bonus_config_not_exists')]);
  913. }
  914. try {
  915. // 发放奖励
  916. OuroGameService::AddScore($userId, $rewardAmount * NumConfig::NUM_VALUE, 52, true); // 52=礼包奖励
  917. $userRecharge = DB::table('QPAccountsDB.dbo.YN_VIPAccount')->lock('with(nolock)')
  918. ->where('UserID', $userId)
  919. ->value('Recharge') ?: 0;
  920. if ($userRecharge > 0) {
  921. app(PaidRewardStatisticsService::class)
  922. ->incrementRecordByDateIDAndType(date('Ymd'), 'daily_gift_claim',
  923. $rewardAmount * NumConfig::NUM_VALUE);
  924. }
  925. // 标记已领取
  926. Redis::setex($redisKey, 86400, 1); // 24小时过期
  927. \Log::info('每日礼包额外奖励领取成功', [
  928. 'user_id' => $userId,
  929. 'reward_amount' => $rewardAmount
  930. ]);
  931. return apiReturnSuc([
  932. 'amount' => $rewardAmount,
  933. 'message' => str_replace(':amount', $rewardAmount, __('web.gift.claim_success'))
  934. ]);
  935. } catch (\Exception $e) {
  936. \Log::error('每日礼包额外奖励领取失败', [
  937. 'user_id' => $userId,
  938. 'error' => $e->getMessage()
  939. ]);
  940. return apiReturnFail(['web.gift.claim_failed', str_replace(':error', $e->getMessage(), __('web.gift.claim_failed'))]);
  941. }
  942. }
  943. public function getSecondGive(Request $request)
  944. {
  945. $user = $request->user();
  946. $fpkey='Firstpay_'.$user->UserID;
  947. if(Redis::exists($fpkey)){
  948. $data=Redis::get($fpkey);
  949. $data=json_decode($data,true);
  950. $data['timeleft']=86400-(time()-$data['buytime']);
  951. if($data['timeleft']<=0) {
  952. Redis::del($fpkey);
  953. //加钱
  954. if($data['second_give']){
  955. $czReason=$data['czReason'];
  956. $cjReason=$data['cjReason'];
  957. [$OrgScore,$NowScore]=OuroGameService::AddScore($user->UserID,$data['second_give']*NumConfig::NUM_VALUE,$cjReason);
  958. //更新二次领钱记录
  959. DB::table(TableName::agent() . 'guide_payment')->where('UserID',$user->UserID)->update([
  960. 'GetSecondTime' => now(),
  961. 'SecondScoreNum'=>$data['second_give']*NumConfig::NUM_VALUE
  962. ]);
  963. return apiReturnSuc(compact('OrgScore','NowScore'));
  964. }
  965. return apiReturnSuc();
  966. }
  967. }
  968. return apiReturnFail(['web.withdraw.try_again_later','Tente novamente mais tarde']);
  969. }
  970. /**
  971. * 连续未充值 VIP 礼包(gift_id=305)—— 检查条件和返回档位
  972. */
  973. public function vipInactiveGift(Request $request)
  974. {
  975. $user = $request->user();
  976. $this->setUserLocale($request);
  977. $userId = $user->UserID;
  978. // 1. VIP 判断:是否有过充值(YN_VIPAccount.Recharge > 0)
  979. $userRecharge = DB::table(TableName::QPAccountsDB() . 'YN_VIPAccount')
  980. ->where('UserID', $userId)
  981. ->value('Recharge') ?: 0;
  982. if ($userRecharge <= 0) {
  983. // 不满足条件:不是 VIP 用户
  984. return apiReturnSuc([
  985. 'status' => 0,
  986. 'message' => __('web.gift.vip_inactive_not_vip')
  987. ]);
  988. }
  989. // 2. 检查最近一次充值时间,计算连续未充值天数
  990. $lastOrder = DB::table('agent.dbo.order')
  991. ->where('user_id', $userId)
  992. ->where('pay_status', 1)
  993. ->where('GiftsID','<>', 305)
  994. ->orderBy('pay_at', 'desc')
  995. ->first();
  996. if (!$lastOrder) {
  997. return apiReturnSuc([
  998. 'status' => 0,
  999. 'message' => __('web.gift.vip_inactive_not_vip')
  1000. ]);
  1001. }
  1002. $lastDate = date('Y-m-d', strtotime($lastOrder->pay_at));
  1003. $today = date('Y-m-d');
  1004. $diffDays = (strtotime($today) - strtotime($lastDate)) / 86400;
  1005. // 连续未充值天数:如果最后一次充值是昨天,则未充值天数为0;如果是前天,则为1;以此类推
  1006. // 需要 >= 3 天,即最后一次充值至少是3天前
  1007. $inactiveDays = max(0, (int)$diffDays - 1);
  1008. if ($inactiveDays < 3) {
  1009. // 不满足条件:连续未充值天数不足
  1010. return apiReturnSuc([
  1011. 'status' => 0,
  1012. 'message' => __('web.gift.vip_inactive_days_insufficient'),
  1013. 'inactive_days' => $inactiveDays
  1014. ]);
  1015. }
  1016. // 3. 计算总充值与平均单笔(从 RecordUserTotalStatistics)
  1017. $stat = DB::table(TableName::QPRecordDB() . 'RecordUserTotalStatistics')
  1018. ->where('UserID', $userId)
  1019. ->select('Recharge', 'RechargeTimes')
  1020. ->first();
  1021. $totalRecharge = (float)($stat->Recharge ?? 0); // 转换为元
  1022. $rechargeTimes = (int)($stat->RechargeTimes ?? 0);
  1023. if ($totalRecharge <= 0 || $rechargeTimes <= 0) {
  1024. return apiReturnSuc([
  1025. 'status' => 0,
  1026. 'message' => __('web.gift.vip_inactive_not_vip')
  1027. ]);
  1028. }
  1029. $user = null;
  1030. if ($userId > 0) {
  1031. $user = GlobalUserInfo::getGameUserInfo('UserID', $userId);
  1032. if ($user) $user = GlobalUserInfo::toWebData($user);
  1033. }
  1034. $avgRecharge = $totalRecharge / $rechargeTimes;
  1035. // 4. 按规则选择礼包金额
  1036. $amount = null;
  1037. if ($totalRecharge < 50) {
  1038. $amount = $avgRecharge < 15 ? 9.99 : 19.99;
  1039. } else {
  1040. if ($avgRecharge < 15) {
  1041. $amount = 19.99;
  1042. } elseif ($avgRecharge >= 15 && $avgRecharge < 20) {
  1043. $amount = 29.99;
  1044. } else {
  1045. $amount = 39.99;
  1046. }
  1047. }
  1048. // 5. 查询最近一条 7 日礼包记录状态(用于判断是否进入新一轮)
  1049. $record = DB::table('agent.dbo.inactive_vip_gift_records')
  1050. ->where('user_id', $userId)
  1051. ->where('gift_id', 305)
  1052. ->orderBy('id', 'desc')
  1053. ->first();
  1054. /*
  1055. * status 定义:
  1056. * 0 不满足条件
  1057. * 1 满足条件未充值
  1058. * 2 满足条件已充值,奖励未全部领取
  1059. * 3 满足条件已充值,奖励全部领取
  1060. * 4 满足条件已充值,7天礼包已过期
  1061. */
  1062. $status = 1;
  1063. $timeLeft = 0; // 倒计时剩余秒数
  1064. if ($record && strtotime($record->expired_at) >= time()) {
  1065. // 当前轮次仍有效:根据领取进度展示状态
  1066. $allClaimedMask = (1 << 7) - 1; // 0b1111111
  1067. $status = (($record->claimed_days_mask & $allClaimedMask) == $allClaimedMask) ? 3 : 2;
  1068. } else {
  1069. // 无记录 or 上一轮已过期:可进入新一轮,走未充值倒计时逻辑
  1070. // 满足条件但未充值:检查24小时倒计时(每天重置)
  1071. $today = date('Y-m-d');
  1072. $timerKey = "vip_inactive_gift_timer_{$userId}_{$today}";
  1073. $timerData = Redis::get($timerKey);
  1074. if ($timerData) {
  1075. $timerData = json_decode($timerData, true);
  1076. $expireTime = $timerData['expire_time'] ?? 0;
  1077. $timeLeft = max(0, $expireTime - time());
  1078. if ($timeLeft <= 0) {
  1079. // 今天的倒计时已结束,不再显示礼包
  1080. $status = 0;
  1081. }
  1082. } else {
  1083. // 今天首次检测到满足条件,初始化24小时倒计时
  1084. // 从当前时间开始,24小时后过期
  1085. $expireTime = time() + 86400; // 24小时后
  1086. $ttl = 86400 + 3600; // Redis过期时间设为25小时,确保跨天也能获取
  1087. Redis::setex($timerKey, $ttl, json_encode([
  1088. 'expire_time' => $expireTime,
  1089. 'created_at' => time(),
  1090. 'date' => $today
  1091. ]));
  1092. $timeLeft = 86400;
  1093. }
  1094. }
  1095. $payload = [
  1096. 'status' => $status,
  1097. 'inactive_days' => $inactiveDays,
  1098. // 'total_recharge' => $totalRecharge,
  1099. // 'avg_recharge' => round($avgRecharge, 2),
  1100. 'time_left' => $timeLeft,
  1101. 'expire_at' => $timeLeft > 0 ? (time() + $timeLeft) : null,
  1102. 'message' => $status == 1 ? __('web.gift.vip_inactive_can_recharge') :
  1103. ($status == 2 ? __('web.gift.vip_inactive_claimed_partial') :
  1104. ($status == 3 ? __('web.gift.vip_inactive_claimed_all') :
  1105. __('web.gift.vip_inactive_seven_days_expired')))
  1106. ];
  1107. // status=1 时返回充值档位信息(参考 bankruptcyGift),gift_id 固定 305,加总奖励百分比
  1108. if ($status == 1 && $amount !== null) {
  1109. $sevenPercent = 140 + max(0, $inactiveDays - 3) * 10;
  1110. $sevenPercent = min($sevenPercent, 200);
  1111. $totalRewardPercent = 20 + $sevenPercent; // 120% 立即 + 7日礼包%
  1112. $gear = DB::table('agent.dbo.recharge_gear')
  1113. ->select('money', 'favorable_price', 'gear', 'give')
  1114. ->where('money', $amount)
  1115. ->where('status', 1)
  1116. ->first();
  1117. $favorablePrice = round($amount * 120 / 100, 2); // 305 固定 120% 立即到账
  1118. $give = $favorablePrice - $amount;
  1119. if ($gear) {
  1120. $gear->gift_id = 305;
  1121. $gear->favorable_price = $favorablePrice;
  1122. $gear->give = $give;
  1123. $gear->total_bonus = $totalRewardPercent;
  1124. $gear->bonus = $totalRewardPercent;
  1125. $gear->total_reward_percent = $totalRewardPercent;
  1126. $gear->recommend = 1;
  1127. if (!empty($gear->gear)) {
  1128. $gear->gear = Util::filterGearByDevice($gear->gear,$user);
  1129. }
  1130. $payload['list'] = [$gear];
  1131. } else {
  1132. $payload['list'] = [(object)[
  1133. 'money' => $amount,
  1134. 'favorable_price' => $favorablePrice,
  1135. 'give' => $give,
  1136. 'gear' => null,
  1137. 'gift_id' => 305,
  1138. 'total_bonus' => $totalRewardPercent,
  1139. 'bonus' => $totalRewardPercent,
  1140. 'total_reward_percent' => $totalRewardPercent,
  1141. 'recommend' => 1,
  1142. ]];
  1143. }
  1144. $payload['amount'] = $amount;
  1145. $payload['total_reward_percent'] = $totalRewardPercent;
  1146. $payload['extra_reward'] = round($amount*$totalRewardPercent/100,2);
  1147. $payload['total_reward'] = round($amount*$totalRewardPercent/100+$amount,2);
  1148. } else {
  1149. $payload['amount'] = $amount;
  1150. if($record){
  1151. $payload['total_reward_percent'] = $record->total_percent-100;
  1152. }
  1153. }
  1154. return apiReturnSuc($payload);
  1155. }
  1156. /**
  1157. * 连续未充值 VIP 礼包(gift_id=305)—— 获取 7 日礼包信息
  1158. */
  1159. public function vipInactiveGiftSevenDays(Request $request)
  1160. {
  1161. $user = $request->user();
  1162. $this->setUserLocale($request);
  1163. $userId = $user->UserID;
  1164. // 获取 7 日礼包记录
  1165. $record = DB::table('agent.dbo.inactive_vip_gift_records')
  1166. ->where('user_id', $userId)
  1167. ->where('gift_id', 305)
  1168. ->orderBy('id', 'desc')
  1169. ->first();
  1170. if (!$record) {
  1171. return apiReturnFail(['web.gift.vip_inactive_no_record', __('web.gift.vip_inactive_no_record')]);
  1172. }
  1173. // 计算从充值完成后的第几天(第1天为充值当天)
  1174. // 如果 created_at 是 2024-01-01,今天是 2024-01-01,daysPassed=0,表示可以领取第1天的奖励
  1175. $createdDate = date('Y-m-d', strtotime($record->created_at));
  1176. $today = date('Y-m-d');
  1177. $daysPassed = floor((strtotime($today) - strtotime($createdDate)) / 86400);
  1178. // daysPassed = 0 表示充值当天(第1天),1 表示第2天,以此类推
  1179. // 检查是否已过期(超过7天)
  1180. $expiredAt = strtotime($record->expired_at);
  1181. $isExpired = time() > $expiredAt;
  1182. $perDayAmount = (float)$record->per_day_amount;
  1183. $claimedMask = (int)$record->claimed_days_mask;
  1184. // 构建每一天的状态(第1天为充值当天,对应 daysPassed = 0)
  1185. $days = [];
  1186. for ($day = 1; $day <= 7; $day++) {
  1187. $dayIndex = $day - 1; // 位索引:day1对应bit0
  1188. $isClaimed = ($claimedMask & (1 << $dayIndex)) > 0;
  1189. // 计算这一天对应的日期(充值后第 day-1 天;第1天为充值当天)
  1190. $targetDate = date('Ymd', strtotime($record->created_at . ' +' . ($day - 1) . ' days'));
  1191. // 判断状态
  1192. // 0=不可领取, 1=可领取, 2=已领取, 3=过期
  1193. $dayStatus = 0;
  1194. $betAmount = 0; // 初始化
  1195. // 第4-7天需要查询流水信息(无论状态如何,都要展示进度)
  1196. if ($day >= 4) {
  1197. // var_dump($userId,$day,$targetDate);
  1198. $todayBet = DB::table('QPRecordDB.dbo.RecordUserDataStatisticsNew')
  1199. ->where('UserID', $userId)
  1200. ->where('DateID', $targetDate)
  1201. ->value('TotalBet') ?? 0;
  1202. $betAmount = $todayBet / NumConfig::NUM_VALUE; // 转换为元
  1203. }
  1204. $dayOffset = $day - 1; // 第1天对应 offset=0
  1205. if ($isClaimed) {
  1206. $dayStatus = 2; // 已领取
  1207. } elseif ($daysPassed > $dayOffset) {
  1208. // 已过这一天但未领取:过期
  1209. // 例如:今天是第4天(daysPassed=4),但第3天的奖励还没领取,则第3天过期
  1210. $dayStatus = 3; // 过期
  1211. } elseif ($daysPassed < $dayOffset) {
  1212. // 还没到这一天:第 day 天的奖励需要在充值后的第 day-1 天才能领取
  1213. // 例如:第1天奖励需要 daysPassed >= 0(充值当天)才能领取
  1214. $dayStatus = 0; // 不可领取
  1215. } elseif ($isExpired || $daysPassed >= 7) {
  1216. // 整体过期(超过7天)时,未领取的奖励都过期
  1217. $dayStatus = 3; // 过期
  1218. } else {
  1219. // 到了这一天,判断是否可以领取
  1220. if ($day <= 3) {
  1221. // 前3天:直接领取
  1222. $dayStatus = 1; // 可领取
  1223. } else {
  1224. // 第4-7天:需要当天游戏流水 >= 100(流水信息已在上面查询)
  1225. if ($betAmount >= 100) {
  1226. $dayStatus = 1; // 可领取
  1227. } else {
  1228. $dayStatus = 0; // 不可领取(流水不足)
  1229. }
  1230. }
  1231. }
  1232. // 计算进度条数据(仅第4-7天)
  1233. $betProgress = null;
  1234. if ($day >= 4) {
  1235. $requiredBet = 100;
  1236. $currentBetValue = round($betAmount, 2);
  1237. $progressPercent = $requiredBet > 0 ? min(100, round(($currentBetValue / $requiredBet) * 100, 2)) : 0;
  1238. $betProgress = [
  1239. 'current' => $currentBetValue, // 当前流水
  1240. 'required' => $requiredBet, // 需要流水
  1241. 'progress_percent' => $progressPercent, // 进度百分比(0-100)
  1242. 'is_completed' => $currentBetValue >= $requiredBet // 是否完成
  1243. ];
  1244. }
  1245. $days[] = [
  1246. 'day' => $day,
  1247. 'amount' => $perDayAmount,
  1248. 'status' => $dayStatus,
  1249. 'status_text' => [
  1250. __('web.gift.status_cannot_claim'),
  1251. __('web.gift.status_can_claim'),
  1252. __('web.gift.status_claimed'),
  1253. __('web.gift.status_expired')
  1254. ][$dayStatus] ?? __('web.gift.status_unknown'),
  1255. 'target_date' => $targetDate,
  1256. 'bet_progress' => $betProgress // 第4-7天的流水进度信息
  1257. ];
  1258. }
  1259. // 检查是否有倒计时(未充值时的24小时倒计时)
  1260. $timerKey = "vip_inactive_gift_timer_{$userId}";
  1261. $timerData = Redis::get($timerKey);
  1262. $timeLeft = 0;
  1263. if ($timerData) {
  1264. $timerData = json_decode($timerData, true);
  1265. $expireTime = $timerData['expire_time'] ?? 0;
  1266. $timeLeft = max(0, $expireTime - time());
  1267. }
  1268. return apiReturnSuc([
  1269. 'record' => [
  1270. 'pay_amount' => (float)$record->pay_amount,
  1271. 'total_percent' => (float)$record->total_percent-100,
  1272. 'seven_days_percent' => (float)$record->seven_days_percent,
  1273. 'per_day_amount' => $perDayAmount,
  1274. 'inactive_days' => (int)$record->inactive_days,
  1275. 'created_at' => $record->created_at,
  1276. 'expired_at' => $record->expired_at
  1277. ],
  1278. 'days' => $days,
  1279. 'current_day' => min($daysPassed + 1, 7), // 当前是第几天
  1280. 'is_expired' => $isExpired,
  1281. 'time_left' => $timeLeft, // 未充值时的倒计时(秒)
  1282. 'expire_at' => $expiredAt
  1283. ]);
  1284. }
  1285. /**
  1286. * 连续未充值 VIP 礼包(gift_id=305)—— 领取某日奖励
  1287. */
  1288. public function claimVipInactiveGiftDayReward(Request $request)
  1289. {
  1290. $user = $request->user();
  1291. $this->setUserLocale($request);
  1292. $userId = $user->UserID;
  1293. $day = (int)$request->input('day', 0);
  1294. // if ($day < 1 || $day > 7) {
  1295. // return apiReturnFail(['web.gift.invalid_reward_type', __('web.gift.invalid_reward_type')]);
  1296. // }
  1297. // 获取 7 日礼包记录
  1298. $record = DB::table('agent.dbo.inactive_vip_gift_records')
  1299. ->where('user_id', $userId)
  1300. ->where('gift_id', 305)
  1301. ->orderBy('id', 'desc')
  1302. ->first();
  1303. if (!$record) {
  1304. return apiReturnFail(['web.gift.vip_inactive_no_record', __('web.gift.vip_inactive_no_record')]);
  1305. }
  1306. // 检查是否已过期
  1307. if (strtotime($record->expired_at) < time()) {
  1308. return apiReturnFail(['web.gift.vip_inactive_expired', __('web.gift.vip_inactive_expired')]);
  1309. }
  1310. // 计算从充值完成后的第几天(第1天为充值当天)
  1311. $createdDate = date('Y-m-d', strtotime($record->created_at));
  1312. $today = date('Y-m-d');
  1313. $daysPassed = floor((strtotime($today) - strtotime($createdDate)) / 86400);
  1314. $day = $daysPassed+1;
  1315. // 检查是否已领取
  1316. $claimedMask = (int)$record->claimed_days_mask;
  1317. $dayIndex = $day - 1;
  1318. if ($claimedMask & (1 << $dayIndex)) {
  1319. return apiReturnFail(['web.gift.vip_inactive_day_claimed', str_replace(':day', $day, __('web.gift.vip_inactive_day_claimed'))]);
  1320. }
  1321. // 第 day 天的奖励只能在充值后的第 day-1 天领取(daysPassed == day-1)
  1322. $dayOffset = $day - 1;
  1323. // 检查是否到了这一天
  1324. if ($daysPassed < $dayOffset) {
  1325. return apiReturnFail(['web.gift.vip_inactive_day_not_time', str_replace(':day', $day, __('web.gift.vip_inactive_day_not_time'))]);
  1326. }
  1327. // 检查是否已过期:如果已经过了这一天(daysPassed > day),则不能领取
  1328. if ($daysPassed > $dayOffset) {
  1329. return apiReturnFail(['web.gift.vip_inactive_day_expired', str_replace(':day', $day, __('web.gift.vip_inactive_day_expired'))]);
  1330. }
  1331. // 第4-7天需要检查当天游戏流水 >= 100
  1332. if ($day >= 4) {
  1333. $targetDate = date('Ymd', strtotime($record->created_at . ' +' . $dayOffset . ' days'));
  1334. $todayBet = DB::table('QPRecordDB.dbo.RecordUserDataStatisticsNew')
  1335. ->where('UserID', $userId)
  1336. ->where('DateID', $targetDate)
  1337. ->value('TotalBet') ?? 0;
  1338. $betAmount = $todayBet / NumConfig::NUM_VALUE; // 转换为元
  1339. if ($betAmount < 100) {
  1340. return apiReturnFail(['web.gift.vip_inactive_bet_insufficient', str_replace(':amount', 100, __('web.gift.vip_inactive_bet_insufficient'))]);
  1341. }
  1342. }
  1343. $amount = (float)$record->per_day_amount;
  1344. try {
  1345. // 发放奖励
  1346. OuroGameService::AddScore($userId, $amount * NumConfig::NUM_VALUE, 52, true); // 52=礼包奖励
  1347. $userRecharge = DB::table('QPAccountsDB.dbo.YN_VIPAccount')->lock('with(nolock)')
  1348. ->where('UserID', $userId)
  1349. ->value('Recharge') ?: 0;
  1350. if ($userRecharge > 0) {
  1351. app(PaidRewardStatisticsService::class)
  1352. ->incrementRecordByDateIDAndType(date('Ymd'), 'vip_inactive_claim', $amount * NumConfig::NUM_VALUE);
  1353. }
  1354. // 更新位标记
  1355. $newMask = $claimedMask | (1 << $dayIndex);
  1356. DB::connection('write')->table('agent.dbo.inactive_vip_gift_records')
  1357. ->where('id', $record->id)
  1358. ->update([
  1359. 'claimed_days_mask' => $newMask,
  1360. 'updated_at' => date('Y-m-d H:i:s')
  1361. ]);
  1362. \Log::info('连续未充值VIP礼包奖励领取成功', [
  1363. 'user_id' => $userId,
  1364. 'day' => $day,
  1365. 'amount' => $amount
  1366. ]);
  1367. return apiReturnSuc([
  1368. 'amount' => $amount,
  1369. 'day' => $day,
  1370. 'message' => str_replace(':amount', $amount, __('web.gift.claim_success'))
  1371. ]);
  1372. } catch (\Exception $e) {
  1373. \Log::error('连续未充值VIP礼包奖励领取失败', [
  1374. 'user_id' => $userId,
  1375. 'day' => $day,
  1376. 'error' => $e->getMessage()
  1377. ]);
  1378. return apiReturnFail(['web.gift.claim_failed', str_replace(':error', $e->getMessage(), __('web.gift.claim_failed'))]);
  1379. }
  1380. }
  1381. public function freeBonusGifts(Request $request)
  1382. {
  1383. $user = $request->user();
  1384. $this->setUserLocale($request);
  1385. $gifts = DB::table('agent.dbo.recharge_gift')
  1386. ->where('gift_id', 306)
  1387. ->orderBy('recommend', 'asc')
  1388. ->get();
  1389. $gifts = $gifts->keyBy('recommend');
  1390. $moneyList = [];
  1391. foreach ($gifts as $gift) {
  1392. $money = sprintf('%.2f', $gift->recommend);
  1393. $moneyList[$money] = $gift;
  1394. }
  1395. $result = [];
  1396. $gears = DB::table('agent.dbo.recharge_gear')
  1397. ->select('money', 'favorable_price', 'gear')
  1398. ->whereIn('money', array_keys($moneyList))
  1399. ->where('status', 1)
  1400. ->get();
  1401. foreach ($gears as $gear) {
  1402. if (empty($moneyList[$gear->money])) {
  1403. continue;
  1404. }
  1405. $gear->amount = 0;
  1406. $gear->gift_id = $moneyList[$gear->money]->gift_id;
  1407. $gear->task_bonus = $moneyList[$gear->money]->task_bonus;
  1408. $gear->recommend = sprintf('%.2f', $moneyList[$gear->money]->recommend);
  1409. $gear->gear = Util::filterGearByDevice($gear->gear,GlobalUserInfo::toWebData($user));
  1410. $result[] = $gear;
  1411. }
  1412. return apiReturnSuc([
  1413. 'list' => $result,
  1414. ]);
  1415. }
  1416. }