PayRechargeController.php 69 KB

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