OrderServices.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. <?php
  2. namespace App\Services;
  3. use App\dao\Estatisticas\RechargeWithDraw;
  4. use App\Facade\TableName;
  5. use App\Game\GlobalUserInfo;
  6. use App\Game\Services\AgentService;
  7. use App\Http\Controllers\Api\AgentController;
  8. use App\Http\helper\Helper;
  9. use App\Http\helper\HttpCurl;
  10. use App\Http\helper\NumConfig;
  11. use App\Jobs\AfEvent;
  12. use App\Models\AgentUser;
  13. use App\Models\RecordScoreInfo;
  14. use App\Models\RecordUserDataStatistics;
  15. use App\Services\HolidayWheelService;
  16. use App\Util;
  17. use Illuminate\Support\Facades\DB;
  18. use Illuminate\Support\Facades\Log;
  19. use Illuminate\Support\Facades\Redis;
  20. class OrderServices
  21. {
  22. public $FirstCharge = 30;
  23. public $FirstChargeGive = 20;
  24. public $FirstGiftID = 301;
  25. private $first_pay = null;
  26. public function __construct()
  27. {
  28. }
  29. /**
  30. * 获取支付金额
  31. * @param int $GiftsID 礼包ID
  32. * @param int $user_id 用户ID
  33. * @param int $payAmt 支付金额(元)
  34. * @return array|void [$give, $favorable_price, $Recharge, $czReason, $cjReason] 赠送金额,赠送金额+充值金额,充值金额,充值原因,彩金原因
  35. */
  36. public function getPayInfo($GiftsID, $user_id, $payAmt)
  37. {
  38. $give = $czReason = $cjReason = $Recharge = $favorable_price = $second_give = 0;
  39. $shouldCreateGiftRecord = false; // 是否需要创建首充礼包记录
  40. // 判断是不是首冲礼包
  41. if (!empty($GiftsID)) {
  42. if ($GiftsID == 301) { // 礼包--首冲
  43. // 检查用户是否已购买过首充礼包
  44. $hasPurchased = DB::connection('write')->table('agent.dbo.first_pay_gift_records')
  45. ->where('user_id', $user_id)
  46. ->exists();
  47. if ($hasPurchased) {
  48. // 已购买首充礼包,走普通充值逻辑(只加本金)
  49. $Recharge = $payAmt;
  50. $give = 0;
  51. $favorable_price = $Recharge + $give;
  52. $czReason = 1;
  53. $cjReason = 45;
  54. } else {
  55. // 首次购买首充礼包,走赠送逻辑(立即获得bonus_instantly%)
  56. $Gifts = DB::connection('write')->table('agent.dbo.recharge_gift')->where('gift_id', $GiftsID)->first();
  57. $favorable_price = round($Gifts->bonus_instantly*$payAmt/100,2);
  58. $give = $favorable_price-$payAmt;
  59. $Recharge = $payAmt;
  60. $czReason = 50;
  61. $cjReason = 51;
  62. // 创建首充礼包记录
  63. try {
  64. $this->createFirstPayGiftRecord($user_id, $GiftsID, $payAmt);
  65. } catch (\Exception $e) {
  66. \Log::error('首充礼包记录创建失败', [
  67. 'user_id' => $user_id,
  68. 'gift_id' => $GiftsID,
  69. 'error' => $e->getMessage()
  70. ]);
  71. }
  72. }
  73. }if ($GiftsID == 302) { // 破产礼包
  74. // 首次购买首充礼包,走赠送逻辑(立即获得bonus_instantly%)
  75. $Gifts = DB::connection('write')->table('agent.dbo.recharge_gift')->where('gift_id', $GiftsID)->where('recommend', $payAmt)->first();
  76. if($Gifts){
  77. $favorable_price = round($Gifts->bonus_instantly*$payAmt/100,2);
  78. $give = $favorable_price-$payAmt;
  79. $Recharge = $payAmt;
  80. $czReason = 50;
  81. $cjReason = 51;
  82. }else{
  83. $Recharge = $payAmt;
  84. $give = 0;
  85. $favorable_price = $Recharge + $give;
  86. $czReason = 1;
  87. $cjReason = 45;
  88. }
  89. }else if ($GiftsID == 303) { // 每日首充礼包
  90. // 检查用户今日是否已充值过每日首充礼包
  91. $todayStart = date('Y-m-d') . ' 00:00:00';
  92. $todayEnd = date('Y-m-d') . ' 23:59:59';
  93. $todayRecharge = DB::connection('write')->table('agent.dbo.order')
  94. ->where('user_id', $user_id)
  95. ->where('GiftsID', 303)
  96. ->where('pay_status', 1)
  97. ->where('pay_at', '>=', $todayStart)
  98. ->where('pay_at', '<=', $todayEnd)
  99. ->first();
  100. if ($todayRecharge) {
  101. // 今日已充值过,只发放本金(不发放奖励)
  102. $Recharge = $payAmt;
  103. $give = 0;
  104. $favorable_price = $Recharge + $give;
  105. $czReason = 1;
  106. $cjReason = 45;
  107. } else {
  108. // 今日未充值过,按照礼包配置的比例发放
  109. $Gifts = DB::connection('write')->table('agent.dbo.recharge_gift')
  110. ->where('gift_id', $GiftsID)
  111. ->where('recommend', $payAmt)
  112. ->first();
  113. if($Gifts){
  114. $favorable_price = round($Gifts->bonus_instantly*$payAmt/100,2);
  115. $give = $favorable_price-$payAmt;
  116. $Recharge = $payAmt;
  117. $czReason = 50;
  118. $cjReason = 51;
  119. }else{
  120. // 如果没有找到对应的礼包配置,按照普通充值处理
  121. $Recharge = $payAmt;
  122. $give = 0;
  123. $favorable_price = $Recharge + $give;
  124. $czReason = 1;
  125. $cjReason = 45;
  126. }
  127. }
  128. }else if ($GiftsID == 304) { // 每日礼包(三档充值)
  129. // 检查用户今日是否已充值过该档位的每日礼包
  130. $todayStart = date('Y-m-d') . ' 00:00:00';
  131. $todayEnd = date('Y-m-d') . ' 23:59:59';
  132. $todayRecharge = DB::connection('write')->table('agent.dbo.order')
  133. ->where('user_id', $user_id)
  134. ->where('GiftsID', 304)
  135. ->where('amount', $payAmt) // 检查该档位金额
  136. ->where('pay_status', 1)
  137. ->where('pay_at', '>=', $todayStart)
  138. ->where('pay_at', '<=', $todayEnd)
  139. ->first();
  140. if ($todayRecharge) {
  141. // 今日已充值过该档位,只发放本金(不发放奖励)
  142. $Recharge = $payAmt;
  143. $give = 0;
  144. $favorable_price = $Recharge + $give;
  145. $czReason = 1;
  146. $cjReason = 45;
  147. } else {
  148. // 今日未充值过该档位,按照礼包配置的比例发放
  149. $Gifts = DB::connection('write')->table('agent.dbo.recharge_gift')
  150. ->where('gift_id', $GiftsID)
  151. ->where('recommend', $payAmt)
  152. ->first();
  153. if($Gifts){
  154. $favorable_price = round($Gifts->bonus_instantly*$payAmt/100,2);
  155. $give = $favorable_price-$payAmt;
  156. $Recharge = $payAmt;
  157. $czReason = 50;
  158. $cjReason = 51;
  159. }else{
  160. // 如果没有找到对应的礼包配置,按照普通充值处理
  161. $Recharge = $payAmt;
  162. $give = 0;
  163. $favorable_price = $Recharge + $give;
  164. $czReason = 1;
  165. $cjReason = 45;
  166. }
  167. }
  168. }else if ($GiftsID > 400) {
  169. $Status = 1;
  170. $recharge_gear = DB::connection('write')->table('agent.dbo.recharge_gear')->where('status', $Status)->where('money', $payAmt)->select('favorable_price', 'give')->first();
  171. if(!$recharge_gear){
  172. $Recharge=$payAmt;
  173. $give=0;
  174. }else{
  175. $Recharge = $recharge_gear->favorable_price;
  176. $give = $recharge_gear->give;
  177. }
  178. $favorable_price = $Recharge + $give;
  179. $czReason = 1;
  180. $cjReason = 45;
  181. }
  182. } else { // 普通订单
  183. $Status = 1;
  184. $recharge_gear = DB::connection('write')->table('agent.dbo.recharge_gear')->where('status', $Status)->where('money', $payAmt)->select('favorable_price', 'give')->first();
  185. if(!$recharge_gear){
  186. $Recharge=$payAmt;
  187. $give=0;
  188. }else{
  189. $Recharge = $recharge_gear->favorable_price;
  190. $give = $recharge_gear->give;
  191. }
  192. $favorable_price = $Recharge + $give;
  193. $czReason = 1;
  194. $cjReason = 45;
  195. }
  196. return [$give, $favorable_price, $Recharge, $czReason, $cjReason, $second_give];
  197. }
  198. /**
  199. * 添加玩家充值记录
  200. * @param $user_id
  201. * @param $payAmt
  202. * @param $favorable_price
  203. * @param $order_sn
  204. * @param $GiftsID
  205. * @param $Recharge
  206. * @param $czReason
  207. * @param $give
  208. * @param $cjReason
  209. * @param $AdId
  210. * @param $eventType
  211. */
  212. public function addRecord($user_id, $payAmt, $favorable_price, $order_sn, $GiftsID, $Recharge, $czReason, $give, $cjReason, $AdId, $eventType)
  213. {
  214. if ($payAmt > 0) {
  215. // 增加玩家充值金额
  216. $query = DB::connection('write')->table('QPAccountsDB.dbo.YN_VIPAccount')
  217. ->where('UserID', $user_id)
  218. ->value('Recharge');
  219. if ($query) {
  220. DB::connection('write')->table('QPAccountsDB.dbo.YN_VIPAccount')
  221. ->where('UserID', $user_id)
  222. ->increment('Recharge', $payAmt);
  223. } else {
  224. DB::connection('write')->table('QPAccountsDB.dbo.YN_VIPAccount')
  225. ->where('UserID', $user_id)
  226. ->insert(['Recharge' => $payAmt, 'UserID' => $user_id]);
  227. // 首次充值:金币银币切换 + 数据清理
  228. /*
  229. * 金币银币切换 GameScoreInfo 将score的数据复制到 InsureScore 把Score 字段置0 把 ScoreChange字段设置成1
  230. * 清理用户的数据
  231. * GameScoreInfo的MaxScore MaxWinscore清0
  232. * RecordUserTotalStatistics 表 数据清0
  233. * RecordUserDataStatisticsNew 表数据 清0
  234. * RecordUserGameCount 关于用户的数据删除
  235. *
  236. */
  237. try {
  238. $this->switchToInsureScoreAndCleanData($user_id);
  239. } catch (\Exception $e) {
  240. \Log::error('首次充值-金币银币切换失败', [
  241. 'user_id' => $user_id,
  242. 'error' => $e->getMessage()
  243. ]);
  244. }
  245. }
  246. //在这里更新 RecordUserTotalStatistics 数据 将LastRechargeValue字段更新为payAmt 如果不存在则插入
  247. DB::connection('write')->table('QPRecordDB.dbo.RecordUserTotalStatistics')
  248. ->updateOrInsert(['UserID' => $user_id], ['LastRechargeValue' => $payAmt]);
  249. // 节假日大转盘:根据充值金额增加转盘次数(首充礼包/破产礼包不计入)
  250. try {
  251. (new HolidayWheelService())->grantTimesOnRecharge($user_id, $payAmt, (int)$GiftsID);
  252. } catch (\Throwable $e) {
  253. \Log::error('holiday wheel grant times failed', [
  254. 'user_id' => $user_id,
  255. 'payAmt' => $payAmt,
  256. 'GiftsID' => $GiftsID,
  257. 'error' => $e->getMessage(),
  258. ]);
  259. }
  260. // 圣诞大转盘:根据充值金额增加转盘次数(首充礼包/破产礼包不计入)
  261. try {
  262. (new \App\Services\ChristmasWheelService())->grantTimesOnRecharge($user_id, $payAmt, (int)$GiftsID);
  263. } catch (\Throwable $e) {
  264. \Log::error('christmas wheel grant times failed', [
  265. 'user_id' => $user_id,
  266. 'payAmt' => $payAmt,
  267. 'GiftsID' => $GiftsID,
  268. 'error' => $e->getMessage(),
  269. ]);
  270. }
  271. }
  272. if ($Recharge > 0) {
  273. // 添加日志记录表
  274. StoredProcedure::addPlatformData($user_id, 3, $Recharge * NumConfig::NUM_VALUE);
  275. // 增加用户金币变化记录
  276. $AfterScore = RecordScoreInfo::addScore($user_id, ($Recharge * NumConfig::NUM_VALUE), $czReason); #充值
  277. if ($AfterScore) {
  278. RecordScoreInfo::addScore($user_id, ($give * NumConfig::NUM_VALUE), $cjReason, $AfterScore); #赠送彩金
  279. }
  280. }
  281. $favorable_price = (int) round($favorable_price * NumConfig::NUM_VALUE);
  282. $firstScore = DB::connection('write')->table('QPTreasureDB.dbo.GameScoreInfo')->where('UserID', $user_id)->value('Score');
  283. $Score = $favorable_price + $firstScore;
  284. if ($payAmt > 0) {
  285. // 记录订单变化后金币
  286. DB::connection('write')->table('agent.dbo.order')
  287. ->where('order_sn', $order_sn)
  288. ->update(['after_amount' => $Score]);
  289. // 增加用户充值变化值
  290. RecordUserDataStatistics::updateOrAdd($user_id, 0, $payAmt);
  291. }
  292. // 不是周卡的时候执行
  293. if ($GiftsID < 100 || $GiftsID >= 200) {
  294. // 增加用户金币
  295. DB::connection('write')->table('QPTreasureDB.dbo.GameScoreInfo')->where('UserID', $user_id)->increment('Score', $favorable_price);
  296. }
  297. // 充值推广佣金
  298. // (new AgentUser())->reward($user_id, $payAmt, $order_sn);
  299. //
  300. // 周卡 -- 执行存储过程
  301. // if (isset($GiftsID) && $GiftsID > 100 && $GiftsID < 200) {
  302. // $CardID = (int)$GiftsID - 100;
  303. // StoredProcedure::BuyMonthCard($user_id, $CardID, $order_sn);
  304. // // 开始执行时间
  305. // $startTime = Helper::millisecond();
  306. // Log::info('GSP_GP_BuyMonthCard 执行时间:' . ((Helper::millisecond() - $startTime) / 1000));
  307. // }
  308. //设置第二天要领取
  309. // if (isset($GiftsID) && $GiftsID >= 200 && $GiftsID < 300 ) {
  310. // $first = DB::table('agent.dbo.recharge_gear')->where('gift_id', $GiftsID)->select('gift_id', 'money', 'give', 'favorable_price', 'second_give')->first();
  311. // if ($first && $first->second_give > 0) {
  312. // $fpkey = 'Firstpay_' . $user_id;
  313. // $data = (array)$first;
  314. // $data['buytime'] = time();
  315. // $data['czReason'] = $czReason;
  316. // $data['cjReason'] = $cjReason;
  317. // Redis::set($fpkey, json_encode($data));
  318. // DB::table(TableName::agent() . 'guide_payment')->updateOrInsert([
  319. // 'UserID' => $user_id,
  320. // 'GiftID' => $GiftsID,
  321. // 'CreateTime' => now()
  322. // ], ['UserID' => $user_id]);
  323. // }
  324. // }
  325. //设置第二天要领取
  326. // if (!empty($GiftsID) && $GiftsID >= 300 && $GiftsID < 400 ) {
  327. // Redis::del('repay_temp_'.$user_id);
  328. // }
  329. // 数据统计后台 -- 充值记录添加
  330. (new RechargeWithDraw())->recharge($user_id, $payAmt);
  331. // (new RechargeWithDraw())->recharge($user_id, $Recharge);
  332. if ($AdId && $payAmt) AfEvent::dispatch([$user_id, $payAmt, $AdId, $eventType]);
  333. try {
  334. //新邀请
  335. //(new AgentController())->processDeposit($user_id, $payAmt,$order_sn);
  336. AgentService::recordPerformance($user_id, $payAmt * NumConfig::NUM_VALUE);
  337. } catch (\Exception $exception) {
  338. Util::WriteLog("AgentService", $exception->getTraceAsString());
  339. }
  340. return [$Score];
  341. }
  342. /**
  343. * 执行存储过程
  344. * @param $user_id
  345. * @param $payAmt
  346. * @param $favorable_price
  347. * @param $Score
  348. * @param $GiftsID
  349. */
  350. public function storedProcedure($user_id, $payAmt, $favorable_price, $Score, $GiftsID)
  351. {
  352. // 开始执行时间
  353. $startTime = Helper::millisecond();
  354. // 执行存储过程 -- 防刷机制
  355. StoredProcedure::SetUserTabType($user_id);
  356. Log::info('GSP_GP_SetUserTabType12 执行时间:' . ((Helper::millisecond() - $startTime) / 1000));
  357. # 单控标签 -- 执行存储过程
  358. StoredProcedure::user_label($user_id, 1, $payAmt);
  359. Log::info('CheckAccountsLabel 执行时间:' . ((Helper::millisecond() - $startTime) / 1000));
  360. // 服务器通知
  361. // $url = config('transfer.stock')['url'] . 'notifyPay';
  362. // Log::info('中转服参数 ' . json_encode([
  363. // 'userid' => $user_id, 'getScore' => $favorable_price, 'score' => $Score,
  364. // 'giftsid' => empty($GiftsID) ? 0 : $GiftsID,
  365. // 'url' => $url
  366. // ]));
  367. // $res = (new HttpCurl())->service($url, ['userid' => $user_id, 'getScore' => $favorable_price, 'score' => $Score, 'giftsid' => empty($GiftsID) ? 0 : $GiftsID]);
  368. //
  369. // Log::info('中转服 执行时间:' . ((Helper::millisecond() - $startTime) / 1000), [
  370. // 'res' => $res,
  371. // ]);
  372. // AF 事件
  373. // (new AppflyerEvent())->event($user_id, '', 'af_purchase_new', $payAmt);
  374. // Log::info('AF 执行时间:' . ((Helper::millisecond() - $startTime) / 1000));
  375. }
  376. /**
  377. * 首次充值:金币银币切换 + 数据清理
  378. * @param int $user_id 用户ID
  379. */
  380. private function switchToInsureScoreAndCleanData($user_id)
  381. {
  382. \Log::info('开始执行金币银币切换', ['user_id' => $user_id]);
  383. try {
  384. // 1. GameScoreInfo: 将Score的数据复制到InsureScore,把Score字段置0,把ScoreChange字段设置成1
  385. $scoreInfo = DB::connection('write')->table('QPTreasureDB.dbo.GameScoreInfo')
  386. ->where('UserID', $user_id)
  387. ->first();
  388. if ($scoreInfo) {
  389. DB::connection('write')->table('QPTreasureDB.dbo.GameScoreInfo')
  390. ->where('UserID', $user_id)
  391. ->update([
  392. 'InsureScore' => max($scoreInfo->Score,4000), // 将Score复制到InsureScore
  393. 'Score' => 0, // Score置0
  394. 'ScoreChange' => 1, // ScoreChange设置成1
  395. 'MaxScore' => 0, // MaxScore清0
  396. 'MaxWinScore' => 0 // MaxWinScore清0
  397. ]);
  398. \Log::info('GameScoreInfo切换成功', [
  399. 'user_id' => $user_id,
  400. 'original_score' => $scoreInfo->Score,
  401. 'insure_score' => $scoreInfo->Score
  402. ]);
  403. }
  404. // 2. RecordUserTotalStatistics 表数据清0
  405. $totalStats = DB::connection('write')->table('QPRecordDB.dbo.RecordUserTotalStatistics')
  406. ->where('UserID', $user_id)
  407. ->first();
  408. if ($totalStats) {
  409. DB::connection('write')->table('QPRecordDB.dbo.RecordUserTotalStatistics')
  410. ->where('UserID', $user_id)
  411. ->update([
  412. 'WinInning' => 0,
  413. 'LostInning' => 0,
  414. 'Revenue' => 0,
  415. 'WinScore' => 0,
  416. 'LostScore' => 0,
  417. 'Handsel' => 0,
  418. 'DrawBase' => 0,
  419. 'TotalBet' => 0,
  420. // 'TotalScore' => 0,
  421. 'MaxDrawBase' => 0,
  422. 'MaxScore' => 0,
  423. 'MaxWinScore' => 0,
  424. 'Rounds' => 0,
  425. 'ProtectedRounds' => 0
  426. ]);
  427. \Log::info('RecordUserTotalStatistics清0成功', ['user_id' => $user_id]);
  428. }
  429. // 3. RecordUserDataStatisticsNew 表数据清0
  430. DB::connection('write')->table('QPRecordDB.dbo.RecordUserDataStatisticsNew')
  431. ->where('UserID', $user_id)
  432. ->delete();
  433. \Log::info('RecordUserDataStatisticsNew清0成功', ['user_id' => $user_id]);
  434. // 4. RecordUserGameCount 关于用户的数据删除
  435. DB::connection('write')->table('QPRecordDB.dbo.RecordUserGameCount')
  436. ->where('UserID', $user_id)
  437. ->delete();
  438. \Log::info('RecordUserGameCount清除成功', ['user_id' => $user_id]);
  439. \Log::info('金币银币切换完成', [
  440. 'user_id' => $user_id,
  441. 'insure_score' => $scoreInfo->Score ?? 0
  442. ]);
  443. } catch (\Exception $e) {
  444. \Log::error('金币银币切换异常', [
  445. 'user_id' => $user_id,
  446. 'error' => $e->getMessage(),
  447. 'trace' => $e->getTraceAsString()
  448. ]);
  449. throw $e;
  450. }
  451. }
  452. /**
  453. * 创建首充礼包记录
  454. */
  455. public function createFirstPayGiftRecord($user_id, $gift_id, $payAmt)
  456. {
  457. // 检查是否已有记录
  458. $existing = DB::connection('write')->table('agent.dbo.first_pay_gift_records')
  459. ->where('user_id', $user_id)
  460. ->first();
  461. if ($existing) {
  462. \Log::info('首充礼包记录已存在', ['user_id' => $user_id]);
  463. return;
  464. }
  465. // 获取礼包配置
  466. $giftConfig = DB::connection('write')->table('agent.dbo.recharge_gift')
  467. ->where('gift_id', $gift_id)
  468. ->first();
  469. if (!$giftConfig) {
  470. \Log::error('首充礼包配置不存在', ['gift_id' => $gift_id]);
  471. return;
  472. }
  473. // 计算金额
  474. $totalBonusAmount = round($giftConfig->total_bonus * $payAmt / 100, 2);
  475. $bonusInstantlyAmount = round($giftConfig->bonus_instantly * $payAmt / 100, 2);
  476. // 解析JSON数据
  477. $dayRewards = $giftConfig->day_rewards ? json_decode($giftConfig->day_rewards, true) : null;
  478. $bettingBonus = $giftConfig->betting_bonus ? json_decode($giftConfig->betting_bonus, true) : null;
  479. $bettingTask = $giftConfig->betting_task ? json_decode($giftConfig->betting_task, true) : null;
  480. // 计算各部分金额
  481. $dayRewardsTotal = $dayRewards ? round($dayRewards['total_bonus'] * $payAmt / 100, 2) : 0;
  482. $bettingBonusTotal = $bettingBonus ? round($bettingBonus['total_bonus'] * $payAmt / 100, 2) : 0;
  483. $bettingTaskTotal = $bettingTask ? round($bettingTask['total_bonus'] * $payAmt / 100, 2) : 0;
  484. // 创建记录
  485. $data = [
  486. 'user_id' => $user_id,
  487. 'gift_id' => $gift_id,
  488. 'pay_amount' => $payAmt,
  489. 'total_bonus' => $totalBonusAmount,
  490. 'bonus_instantly' => $bonusInstantlyAmount,
  491. 'gift_name' => $giftConfig->gift_name,
  492. // 每日奖励
  493. 'day_rewards_total' => $dayRewardsTotal,
  494. 'day_rewards_claimed' => 0,
  495. 'day_rewards_data' => $giftConfig->day_rewards,
  496. 'day_last_claim_date' => null,
  497. // 下注奖励
  498. 'betting_bonus_total' => $bettingBonusTotal,
  499. 'betting_bonus_claimed' => 0,
  500. 'betting_bonus_data' => $giftConfig->betting_bonus,
  501. 'betting_current_bet' => 0,
  502. // 下注任务
  503. 'betting_task_total' => $bettingTaskTotal,
  504. 'betting_task_claimed' => 0,
  505. 'betting_task_data' => $giftConfig->betting_task,
  506. 'created_at' => date('Y-m-d H:i:s'),
  507. 'updated_at' => date('Y-m-d H:i:s')
  508. ];
  509. DB::connection('write')->table('agent.dbo.first_pay_gift_records')->insert($data);
  510. $dayRewardsTotal = $dayRewards ? round($dayRewards['total_bonus'] * $payAmt / 100, 2) : 0;
  511. $bettingBonusTotal = $bettingBonus ? round($bettingBonus['total_bonus'] * $payAmt / 100, 2) : 0;
  512. $bettingTaskTotal = $bettingTask ? round($bettingTask['total_bonus'] * $payAmt / 100, 2) : 0;
  513. \Log::info('首充礼包记录创建成功', [
  514. 'user_id' => $user_id,
  515. 'gift_id' => $gift_id,
  516. 'pay_amount' => $payAmt,
  517. 'total_bonus' => $totalBonusAmount,
  518. 'rw' => [
  519. $dayRewardsTotal,
  520. $bettingBonusTotal,
  521. $bettingTaskTotal,
  522. round($dayRewards['total_bonus'] * $payAmt / 100, 2),
  523. round($bettingBonus['total_bonus'] * $payAmt / 100, 2),
  524. round($bettingTask['total_bonus'] * $payAmt / 100, 2)
  525. ]
  526. ]);
  527. }
  528. }