PayRechargeController.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. <?php
  2. namespace App\Http\Controllers\Game;
  3. use App\Facade\TableName;
  4. use App\Game\Services\OuroGameService;
  5. use App\Http\Controllers\Controller;
  6. use App\Http\helper\NumConfig;
  7. use App\Models\Order;
  8. use App\Services\OrderServices;
  9. use App\Utility\SetNXLock;
  10. use Illuminate\Http\Request;
  11. use Illuminate\Support\Facades\DB;
  12. use Illuminate\Support\Facades\Redis;
  13. class PayRechargeController extends Controller
  14. {
  15. // 充值记录
  16. public function orderList(Request $request)
  17. {
  18. $user_id = (int)$request->globalUser->UserID;//$request->get('user_id', 1);
  19. $page = $request->get('page', 1);
  20. $pageSize = $request->get('pageSize', 7);
  21. $redisKey = 'PayRecharge_orderList_'.$user_id;
  22. if (!SetNXLock::getExclusiveLock($redisKey)) {
  23. return apiReturnFail(['web.withdraw.try_again_later','Tente novamente mais tarde']);
  24. }
  25. $where[] = ['user_id', $user_id];
  26. $where[] = ['pay_status', 1];
  27. $cacheTime = 60 * rand(1, 2);
  28. // $list = cache()->remember($user_id . '_order_list', $cacheTime, function () use ($where, $pageSize) {
  29. //
  30. // return Order::where($where)
  31. // ->orderBy('finished_at', 'desc')
  32. // ->selectRaw('amount,payment_code,order_sn as payment_sn,finished_at,created_at,pay_status')
  33. // ->paginate(15,['*'],'page',1);
  34. // });
  35. $list = Order::query()->where($where)
  36. ->orderBy('finished_at', 'desc')
  37. ->selectRaw('amount,payment_code,order_sn as payment_sn,finished_at,created_at,pay_status')
  38. ->paginate($pageSize);
  39. // ->paginate(15,['*'],'page',1);
  40. foreach ($list as &$val) {
  41. $val->amount = number_format($val->amount, 2, '.', '');
  42. }
  43. SetNXLock::release($redisKey);
  44. return apiReturnSuc($list);
  45. }
  46. // 首充
  47. public function firstPay(Request $request)
  48. {
  49. $user = $request->user();
  50. $user_recharge = DB::table(TableName::QPAccountsDB() . 'YN_VIPAccount')
  51. ->where('UserID', $user->UserID)
  52. ->value('Recharge') ?: 0;
  53. if($user_recharge)return apiReturnSuc();
  54. $firstPayGift = DB::table('agent.dbo.recharge_gift')
  55. ->where('gift_id', 301)->first();
  56. if(!$firstPayGift) return apiReturnFail();
  57. $names = DB::table('agent.dbo.admin_configs')
  58. ->where([
  59. 'type' => 'pay_method',
  60. 'status' => 1,
  61. ])
  62. ->selectRaw('id, name, status, new_pay_type as type')
  63. ->orderByDesc('sort')->get()->toArray();
  64. $list = DB::table('agent.dbo.recharge_gear')
  65. ->select('id','money','favorable_price','give')
  66. ->orderBy('money', 'asc')->where('status', 1)->get();
  67. $gear=\GuzzleHttp\json_encode($names);
  68. foreach ($list as &$val) {
  69. $val->favorable_price = $val->favorable_price + $val->give;
  70. $val->gear = $gear;
  71. $val->recommend = 0;
  72. if($val->money == $firstPayGift->recommend){
  73. $val->recommend = 1;
  74. }
  75. }
  76. return apiReturnSuc(compact('list', 'firstPayGift'));
  77. }
  78. // 首充礼包(带倒计时逻辑)
  79. public function firstPayGift(Request $request)
  80. {
  81. $user = $request->user();
  82. // 获取礼包配置
  83. $giftConfig = DB::table('agent.dbo.recharge_gift')
  84. ->where('gift_id', 301)
  85. ->first();
  86. if (!$giftConfig) {
  87. return apiReturnFail('礼包配置不存在');
  88. }
  89. // 检查用户是否购买了首充礼包
  90. $giftRecord = DB::table('agent.dbo.first_pay_gift_records')
  91. ->where('user_id', $user->UserID)
  92. ->first();
  93. // ========== 未购买礼包:返回充值列表 + 礼包配置 + 倒计时 ==========
  94. if (!$giftRecord) {
  95. // 获取充值档位列表
  96. $list = DB::table('agent.dbo.recharge_gear')
  97. ->select('money', 'favorable_price', 'give', 'gear')
  98. ->orderBy('money', 'asc')
  99. ->where('status', 1)
  100. ->get();
  101. foreach ($list as &$val) {
  102. $val->favorable_price = $val->favorable_price + $val->give;
  103. $val->recommend = 0;
  104. if ($val->money == $giftConfig->recommend) {
  105. $val->recommend = 1;
  106. }
  107. }
  108. // ========== 处理倒计时逻辑(仅未购买时) ==========
  109. $redisKey = "first_pay_gift_timer_{$user->UserID}";
  110. $currentTime = time();
  111. $timeLeft = 0;
  112. $timerData = Redis::get($redisKey);
  113. if ($timerData) {
  114. $timerData = json_decode($timerData, true);
  115. $firstRequestTime = $timerData['first_request_time'];
  116. $phase = $timerData['phase'];
  117. // 阶段1:valid_h倒计时
  118. if ($phase === 'first') {
  119. $expireTime = $firstRequestTime + ($giftConfig->valid_h * 3600);
  120. if ($currentTime >= $expireTime) {
  121. $expireDate = date('Y-m-d', $expireTime);
  122. $currentDate = date('Y-m-d', $currentTime);
  123. if ($expireDate !== $currentDate) {
  124. // 进入阶段2
  125. $nextDayStart = strtotime($expireDate . ' +1 day 00:00:00');
  126. $newExpireTime = $nextDayStart + ($giftConfig->valid_h_2 * 3600);
  127. $newTimerData = [
  128. 'first_request_time' => $firstRequestTime,
  129. 'phase' => 'daily',
  130. 'current_cycle_start' => $nextDayStart,
  131. 'last_expire_time' => $newExpireTime
  132. ];
  133. Redis::set($redisKey, json_encode($newTimerData));
  134. $timeLeft = max(0, $newExpireTime - $currentTime);
  135. }
  136. } else {
  137. $timeLeft = $expireTime - $currentTime;
  138. }
  139. }
  140. // 阶段2:每日循环
  141. elseif ($phase === 'daily') {
  142. $currentCycleStart = $timerData['current_cycle_start'];
  143. $expireTime = $currentCycleStart + ($giftConfig->valid_h_2 * 3600);
  144. if ($currentTime >= $expireTime) {
  145. $expireDate = date('Y-m-d', $expireTime);
  146. $currentDate = date('Y-m-d', $currentTime);
  147. if ($expireDate !== $currentDate) {
  148. $todayStart = strtotime($currentDate . ' 00:00:00');
  149. $newExpireTime = $todayStart + ($giftConfig->valid_h_2 * 3600);
  150. $newTimerData = [
  151. 'first_request_time' => $firstRequestTime,
  152. 'phase' => 'daily',
  153. 'current_cycle_start' => $todayStart,
  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. } else {
  164. // 首次请求,初始化倒计时
  165. $expireTime = $currentTime + ($giftConfig->valid_h * 3600);
  166. $timerData = [
  167. 'first_request_time' => $currentTime,
  168. 'phase' => 'first',
  169. 'last_expire_time' => $expireTime
  170. ];
  171. Redis::set($redisKey, json_encode($timerData));
  172. $timeLeft = $giftConfig->valid_h * 3600;
  173. }
  174. return apiReturnSuc([
  175. 'has_purchased' => false, // 未购买标记
  176. 'list' => $list, // 充值档位列表
  177. 'gift_info' => [
  178. 'gift_id' => $giftConfig->gift_id,
  179. 'gift_name' => $giftConfig->gift_name,
  180. 'total_bonus' => $giftConfig->total_bonus,
  181. 'bonus_instantly' => $giftConfig->bonus_instantly,
  182. 'day_rewards' => $giftConfig->day_rewards ? json_decode($giftConfig->day_rewards) : null,
  183. 'betting_bonus' => $giftConfig->betting_bonus ? json_decode($giftConfig->betting_bonus) : null,
  184. 'betting_task' => $giftConfig->betting_task ? json_decode($giftConfig->betting_task) : null,
  185. ],
  186. 'time_left' => $timeLeft, // ✅ 倒计时(未购买时展示)
  187. 'expire_at' => time() + $timeLeft // ✅ 过期时间戳
  188. ]);
  189. }
  190. // ========== 已购买礼包:返回任务进度(无倒计时) ==========
  191. // 获取用户当前累计下注(从统计表)
  192. $userStats = DB::table('QPRecordDB.dbo.RecordUserTotalStatistics')
  193. ->where('UserID', $user->UserID)
  194. ->first();
  195. $currentTotalBet = $userStats->AllBet ?? 0;
  196. // 更新下注进度到礼包记录
  197. DB::table('agent.dbo.first_pay_gift_records')
  198. ->where('user_id', $user->UserID)
  199. ->update([
  200. 'betting_current_bet' => $currentTotalBet / NumConfig::NUM_VALUE,
  201. 'updated_at' => date('Y-m-d H:i:s')
  202. ]);
  203. // 重新获取最新记录
  204. $giftRecord = DB::table('agent.dbo.first_pay_gift_records')
  205. ->where('user_id', $user->UserID)
  206. ->first();
  207. // 解析任务数据
  208. $dayRewardsData = $giftRecord->day_rewards_data ? json_decode($giftRecord->day_rewards_data, true) : null;
  209. $bettingBonusData = $giftRecord->betting_bonus_data ? json_decode($giftRecord->betting_bonus_data, true) : null;
  210. $bettingTaskData = $giftRecord->betting_task_data ? json_decode($giftRecord->betting_task_data, true) : null;
  211. // 构建返回数据
  212. $giftInfo = [
  213. 'gift_id' => $giftRecord->gift_id,
  214. 'gift_name' => $giftRecord->gift_name,
  215. 'total_bonus' => (float)$giftRecord->total_bonus,
  216. 'bonus_instantly' => (float)$giftRecord->bonus_instantly,
  217. 'pay_amount' => (float)$giftRecord->pay_amount,
  218. ];
  219. // 每日奖励进度
  220. if ($dayRewardsData) {
  221. $giftInfo['day_rewards'] = [
  222. 'total_bonus' => (float)$giftRecord->day_rewards_total,
  223. 'bonus_day' => $dayRewardsData['bonus_day'] ?? 0,
  224. 'start_day' => $dayRewardsData['start_day'] ?? 1,
  225. 'bonus' => $dayRewardsData['bonus'] ?? [],
  226. 'claimed_days' => $giftRecord->day_rewards_claimed, // 已领取天数
  227. 'progress' => $giftRecord->day_rewards_claimed . '/' . ($dayRewardsData['bonus_day'] ?? 0)
  228. ];
  229. }
  230. // 下注奖励进度
  231. if ($bettingBonusData) {
  232. $perBet = $bettingBonusData['per_bet'] ?? 100; // 每次下注要求
  233. $perBetBonus = $bettingBonusData['per_bet_bonus'] ?? 2; // 每次奖励百分比
  234. $currentBet = $giftRecord->betting_current_bet; // 当前累计下注
  235. $totalBonusLimit = $giftRecord->betting_bonus_total; // 总奖励上限
  236. $claimedAmount = $giftRecord->betting_bonus_claimed; // 已领取金额
  237. $remainingBonus = $totalBonusLimit - $claimedAmount; // 剩余可领取金额
  238. // 每次可领取的金额
  239. $perReward = round($giftRecord->pay_amount * $perBetBonus / 100, 2);
  240. // 根据当前下注计算已达成的次数
  241. $completedTimes = floor($currentBet / $perBet);
  242. // 已领取的次数
  243. $claimedTimes = $claimedAmount > 0 ? floor($claimedAmount / $perReward) : 0;
  244. // 当前可领取次数(但不能超过剩余总额)
  245. $canClaimTimes = $completedTimes - $claimedTimes;
  246. $maxCanClaimTimes = floor($remainingBonus / $perReward); // 剩余总额最多可领次数
  247. $canClaimTimes = min($canClaimTimes, $maxCanClaimTimes);
  248. // 计算下次领取需要的下注金额
  249. $nextClaimBet = 0;
  250. if ($remainingBonus > 0 && $canClaimTimes == 0) {
  251. // 还有剩余奖励但当前不能领取,计算还需下注多少
  252. $nextClaimBet = ($claimedTimes + 1) * $perBet - $currentBet;
  253. }
  254. $giftInfo['betting_bonus'] = [
  255. 'total_bonus' => (float)$totalBonusLimit, // 总奖励上限
  256. 'per_bet' => $perBet, // 每次下注要求
  257. 'per_bet_bonus' => $perBetBonus, // 每次奖励百分比
  258. 'per_reward' => $perReward, // 每次奖励金额
  259. 'current_bet' => (float)$currentBet, // 当前累计下注
  260. 'claimed_amount' => (float)$claimedAmount, // 已领取金额
  261. 'remaining_bonus' => (float)$remainingBonus, // 剩余可领金额
  262. 'can_claim_times' => max(0, $canClaimTimes), // 当前可领取次数
  263. 'next_claim_bet' => max(0, $nextClaimBet), // 下次领取还需下注
  264. 'progress' => round($currentBet, 2) . '/' . round($claimedTimes * $perBet + $perBet, 2) // 当前进度/下次领取目标
  265. ];
  266. }
  267. // 下注任务进度
  268. if ($bettingTaskData) {
  269. $betPayTimes = $bettingTaskData['bet_pay_times'] ?? 60;
  270. $requiredBet = $giftRecord->pay_amount * $betPayTimes;
  271. $currentProgress = $giftRecord->betting_current_bet;
  272. $taskCompleted = $currentProgress >= $requiredBet;
  273. $giftInfo['betting_task'] = [
  274. 'total_bonus' => (float)$giftRecord->betting_task_total,
  275. 'bet_pay_times' => $betPayTimes,
  276. 'required_bet' => $requiredBet, // 需要下注的金额
  277. 'current_bet' => (float)$currentProgress, // 当前累计下注
  278. 'claimed' => $giftRecord->betting_task_claimed == 1, // 是否已领取
  279. 'can_claim' => $taskCompleted && $giftRecord->betting_task_claimed == 0, // 可否领取
  280. 'progress' => round($currentProgress, 2) . '/' . $requiredBet
  281. ];
  282. }
  283. return apiReturnSuc([
  284. 'has_purchased' => true, // 已购买标记
  285. 'gift_info' => $giftInfo
  286. // ✅ 已购买用户不返回倒计时
  287. ]);
  288. }
  289. /**
  290. * 领取首充礼包奖励
  291. */
  292. public function claimFirstPayGiftReward(Request $request)
  293. {
  294. $user = $request->user();
  295. $userId = $user->UserID;
  296. $rewardType = $request->input('reward_type'); // 'day_reward', 'betting_bonus', 'betting_task'
  297. // 获取礼包记录
  298. $giftRecord = DB::table('agent.dbo.first_pay_gift_records')
  299. ->where('user_id', $userId)
  300. ->first();
  301. if (!$giftRecord) {
  302. return apiReturnFail('未购买首充礼包');
  303. }
  304. $rewardAmount = 0;
  305. try {
  306. // 每日奖励领取
  307. if ($rewardType === 'day_reward') {
  308. $dayRewardsData = json_decode($giftRecord->day_rewards_data, true);
  309. if (!$dayRewardsData) {
  310. return apiReturnFail('没有每日奖励配置');
  311. }
  312. $bonusDay = $dayRewardsData['bonus_day'] ?? 0;
  313. $startDay = $dayRewardsData['start_day'] ?? 1;
  314. $bonusArray = $dayRewardsData['bonus'] ?? [];
  315. $claimedDays = $giftRecord->day_rewards_claimed;
  316. // 检查是否还有可领取的天数
  317. if ($claimedDays >= $bonusDay) {
  318. return apiReturnFail('每日奖励已全部领取');
  319. }
  320. // 计算当前是购买后的第几天
  321. $purchaseDate = date('Y-m-d', strtotime($giftRecord->created_at));
  322. $currentDate = date('Y-m-d');
  323. $daysPassed = floor((strtotime($currentDate) - strtotime($purchaseDate)) / 86400);
  324. // 检查是否到了可以领取的天数(从第start_day天开始)
  325. if ($daysPassed < $startDay) {
  326. return apiReturnFail('还未到可领取时间,需要从第' . $startDay . '天开始');
  327. }
  328. // 计算今天应该领取第几天的奖励
  329. // 例如:start_day=2,今天是第3天,应该领取第1个奖励(索引0)
  330. $todayRewardIndex = $daysPassed - $startDay;
  331. // 检查是否超过奖励天数
  332. if ($todayRewardIndex >= $bonusDay) {
  333. return apiReturnFail('每日奖励已过期');
  334. }
  335. // 检查今天是否已领取
  336. $lastClaimDate = $giftRecord->day_last_claim_date;
  337. if ($lastClaimDate && $lastClaimDate === $currentDate) {
  338. return apiReturnFail('今天已经领取过了');
  339. }
  340. // 检查是否跳过了某些天(过期不补领)
  341. // 如果今天应该领第5天的奖励,但用户只领了3天,那就直接领第5天的
  342. if ($todayRewardIndex > $claimedDays) {
  343. // 跳过了一些天,更新已领取天数为今天的索引
  344. $claimedDays = $todayRewardIndex;
  345. }
  346. // 计算今天可领取的奖励(使用todayRewardIndex作为索引)
  347. $todayBonusPercent = $bonusArray[$todayRewardIndex] ?? 0;
  348. $rewardAmount = round($giftRecord->pay_amount * $todayBonusPercent / 100, 2);
  349. // 更新记录
  350. DB::table('agent.dbo.first_pay_gift_records')
  351. ->where('user_id', $userId)
  352. ->update([
  353. 'day_rewards_claimed' => $todayRewardIndex + 1, // 已领取到第几天(索引+1)
  354. 'day_last_claim_date' => $currentDate,
  355. 'updated_at' => date('Y-m-d H:i:s')
  356. ]);
  357. }
  358. // 下注奖励领取
  359. elseif ($rewardType === 'betting_bonus') {
  360. $bettingBonusData = json_decode($giftRecord->betting_bonus_data, true);
  361. if (!$bettingBonusData) {
  362. return apiReturnFail('没有下注奖励配置');
  363. }
  364. $perBet = $bettingBonusData['per_bet'] ?? 100; // 每次下注要求
  365. $perBetBonus = $bettingBonusData['per_bet_bonus'] ?? 2; // 每次奖励百分比
  366. $currentBet = $giftRecord->betting_current_bet; // 当前累计下注
  367. $totalBonusLimit = $giftRecord->betting_bonus_total; // 总奖励上限
  368. $claimedAmount = $giftRecord->betting_bonus_claimed; // 已领取金额
  369. $remainingBonus = $totalBonusLimit - $claimedAmount; // 剩余可领金额
  370. // 检查是否还有剩余奖励
  371. if ($remainingBonus <= 0) {
  372. return apiReturnFail('下注奖励已全部领取');
  373. }
  374. // 每次可领取的金额
  375. $perReward = round($giftRecord->pay_amount * $perBetBonus / 100, 2);
  376. // 根据当前下注计算已达成的次数
  377. $completedTimes = floor($currentBet / $perBet);
  378. // 已领取的次数
  379. $claimedTimes = $claimedAmount > 0 ? floor($claimedAmount / $perReward) : 0;
  380. // 可领取次数(下注达成的次数 - 已领取次数)
  381. $canClaimTimes = $completedTimes - $claimedTimes;
  382. // 检查是否可以领取
  383. if ($canClaimTimes <= 0) {
  384. return apiReturnFail('下注金额不足,还需下注 ' . (($claimedTimes + 1) * $perBet - $currentBet) . ' 才能领取');
  385. }
  386. // ✅ 一次性领取所有已达成的奖励(但不能超过剩余总额)
  387. $totalCanClaimAmount = $canClaimTimes * $perReward; // 理论可领取总额
  388. $rewardAmount = min($totalCanClaimAmount, $remainingBonus); // 实际领取金额(不超过剩余总额)
  389. $actualClaimTimes = floor($rewardAmount / $perReward); // 实际领取次数
  390. // 更新记录
  391. DB::table('agent.dbo.first_pay_gift_records')
  392. ->where('user_id', $userId)
  393. ->update([
  394. 'betting_bonus_claimed' => $giftRecord->betting_bonus_claimed + $rewardAmount,
  395. 'updated_at' => date('Y-m-d H:i:s')
  396. ]);
  397. \Log::info('下注奖励领取', [
  398. 'user_id' => $userId,
  399. 'can_claim_times' => $canClaimTimes,
  400. 'actual_claim_times' => $actualClaimTimes,
  401. 'reward_amount' => $rewardAmount
  402. ]);
  403. }
  404. // 下注任务领取
  405. elseif ($rewardType === 'betting_task') {
  406. if ($giftRecord->betting_task_claimed == 1) {
  407. return apiReturnFail('下注任务奖励已领取');
  408. }
  409. $bettingTaskData = json_decode($giftRecord->betting_task_data, true);
  410. if (!$bettingTaskData) {
  411. return apiReturnFail('没有下注任务配置');
  412. }
  413. $betPayTimes = $bettingTaskData['bet_pay_times'] ?? 60;
  414. $requiredBet = $giftRecord->pay_amount * $betPayTimes;
  415. $currentBet = $giftRecord->betting_current_bet;
  416. if ($currentBet < $requiredBet) {
  417. return apiReturnFail('下注金额不足,需要下注 ' . $requiredBet);
  418. }
  419. $rewardAmount = $giftRecord->betting_task_total;
  420. // 更新记录
  421. DB::table('agent.dbo.first_pay_gift_records')
  422. ->where('user_id', $userId)
  423. ->update([
  424. 'betting_task_claimed' => 1,
  425. 'updated_at' => date('Y-m-d H:i:s')
  426. ]);
  427. }
  428. else {
  429. return apiReturnFail('无效的奖励类型');
  430. }
  431. // 添加奖励到用户账户
  432. if ($rewardAmount > 0) {
  433. OuroGameService::AddScore($userId, $rewardAmount * NumConfig::NUM_VALUE, 52, true); // 52=首充礼包奖励
  434. \Log::info('首充礼包奖励领取', [
  435. 'user_id' => $userId,
  436. 'reward_type' => $rewardType,
  437. 'amount' => $rewardAmount
  438. ]);
  439. }
  440. return apiReturnSuc([
  441. 'amount' => $rewardAmount,
  442. 'message' => '成功领取 ' . $rewardAmount . ' 奖励'
  443. ]);
  444. } catch (\Exception $e) {
  445. \Log::error('首充礼包奖励领取失败', [
  446. 'user_id' => $userId,
  447. 'error' => $e->getMessage()
  448. ]);
  449. return apiReturnFail('领取失败:' . $e->getMessage());
  450. }
  451. }
  452. /**
  453. * 获取首充礼包数据(包含充值档位列表)
  454. * @param $firstPayGift 礼包配置
  455. * @param $timeLeft 剩余秒数(已经是用户实际剩余时间)
  456. */
  457. private function getFirstPayGiftData($firstPayGift, $timeLeft)
  458. {
  459. // 获取支付方式
  460. // $names = DB::table('agent.dbo.admin_configs')
  461. // ->where([
  462. // 'type' => 'pay_method',
  463. // 'status' => 1,
  464. // ])
  465. // ->selectRaw('id, name, status, new_pay_type as type')
  466. // ->orderByDesc('sort')
  467. // ->get()
  468. // ->toArray();
  469. // 获取充值档位
  470. $list = DB::table('agent.dbo.recharge_gear')
  471. ->select('money', 'favorable_price', 'give','gear')
  472. ->orderBy('money', 'asc')
  473. ->where('status', 1)
  474. ->get();
  475. // $gear = \GuzzleHttp\json_encode($names);
  476. foreach ($list as &$val) {
  477. $val->favorable_price = $val->favorable_price + $val->give;
  478. // $val->gear = $gear;
  479. $val->recommend = 0;
  480. if ($val->money == $firstPayGift->recommend) {
  481. $val->recommend = 1;
  482. }
  483. }
  484. return apiReturnSuc([
  485. 'list' => $list,
  486. 'gift_info' => [
  487. 'gift_id' => $firstPayGift->gift_id,
  488. 'gift_name' => $firstPayGift->gift_name,
  489. 'total_bonus' => $firstPayGift->total_bonus,
  490. 'bonus_instantly' => $firstPayGift->bonus_instantly,
  491. 'day_rewards' => $firstPayGift->day_rewards?json_decode($firstPayGift->day_rewards):'',
  492. 'betting_bonus' => $firstPayGift->betting_bonus?json_decode($firstPayGift->betting_bonus):'',
  493. 'betting_task' => $firstPayGift->betting_task?json_decode($firstPayGift->betting_task):'',
  494. ],
  495. 'time_left' => $timeLeft, // 剩余秒数
  496. 'expire_at' => time() + $timeLeft // 过期时间戳
  497. ]);
  498. }
  499. public function firstPayMulti(Request $request)
  500. {
  501. $user = LoginController::checkLogin($request);
  502. if($user){
  503. if(env('CONFIG_24680_NFTD_99',0)==0)if($user->Channel==99)return apiReturnFail();
  504. $fpkey='Firstpay_'.$user->UserID;
  505. if(Redis::exists($fpkey)){
  506. $data=Redis::get($fpkey);
  507. $data=json_decode($data,true);
  508. $data['timeleft']=86400-(time()-$data['buytime']);
  509. return apiReturnSuc(['leftitem'=>$data]);
  510. }
  511. $user_recharge = DB::table(TableName::QPAccountsDB() . 'YN_VIPAccount')
  512. ->where('UserID', $user->UserID)
  513. ->value('Recharge') ?: 0;
  514. if($user_recharge)return apiReturnFail();
  515. }
  516. $items=DB::table('agent.dbo.recharge_gear')
  517. ->where('status',1)
  518. ->where('second_give','>',0)
  519. ->where('first_pay','>=', 1)
  520. ->select('gift_id','money','give','favorable_price','second_give')->get()->each(function($item){
  521. $item->id=28;
  522. })->toArray();
  523. $default=count($items)-1;
  524. return apiReturnSuc(compact('items','default'));
  525. }
  526. public function getSecondGive(Request $request)
  527. {
  528. $user = $request->user();
  529. $fpkey='Firstpay_'.$user->UserID;
  530. if(Redis::exists($fpkey)){
  531. $data=Redis::get($fpkey);
  532. $data=json_decode($data,true);
  533. $data['timeleft']=86400-(time()-$data['buytime']);
  534. if($data['timeleft']<=0) {
  535. Redis::del($fpkey);
  536. //加钱
  537. if($data['second_give']){
  538. $czReason=$data['czReason'];
  539. $cjReason=$data['cjReason'];
  540. [$OrgScore,$NowScore]=OuroGameService::AddScore($user->UserID,$data['second_give']*NumConfig::NUM_VALUE,$cjReason);
  541. //更新二次领钱记录
  542. DB::table(TableName::agent() . 'guide_payment')->where('UserID',$user->UserID)->update([
  543. 'GetSecondTime' => now(),
  544. 'SecondScoreNum'=>$data['second_give']*NumConfig::NUM_VALUE
  545. ]);
  546. return apiReturnSuc(compact('OrgScore','NowScore'));
  547. }
  548. return apiReturnSuc();
  549. }
  550. }
  551. return apiReturnFail(['web.withdraw.try_again_later','Tente novamente mais tarde']);
  552. }
  553. }