PayRechargeController.php 69 KB

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