RechargeController.php 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use App\AdminConfig;
  4. use App\dao\Estatisticas\RechargeWithDraw;
  5. use App\Facade\TableName;
  6. use App\Http\Controllers\Controller;
  7. use App\Http\helper\NumConfig;
  8. use App\Http\logic\admin\AccountsRecordLogic;
  9. use App\Http\logic\admin\RechargeLogic;
  10. use App\Jobs\ClearCache;
  11. use App\Models\Order;
  12. use App\Models\Platform\MonthCard;
  13. use App\Services\OrderServices;
  14. use App\Services\PayMentService;
  15. use App\Game\Services\OuroGameService;
  16. use Carbon\Carbon;
  17. use Illuminate\Http\Request;
  18. use Illuminate\Support\Facades\DB;
  19. use Illuminate\Support\Facades\Log;
  20. use Illuminate\Support\Facades\Validator;
  21. use Illuminate\Support\Facades\Cache;
  22. class RechargeController extends Controller
  23. {
  24. //充值查询
  25. public function rechargeList(Request $request, $history = false)
  26. {
  27. $excel = $request->get('excel');
  28. $start_time = $request->input('start_time');
  29. $end_time = $request->input('end_time');
  30. $create_start_time = $request->input('create_start_time');
  31. $create_end_time = $request->input('create_end_time');
  32. $updated_start_time = $request->input('updated_start_time');
  33. $updated_end_time = $request->input('updated_end_time');
  34. $register_start_time = $request->input('register_start_time');
  35. $register_end_time = $request->input('register_end_time');
  36. $order = $request->post('order');
  37. $type = $request->post('type', '');
  38. $order_sn = $request->post('order_sn') ?? "";
  39. $userid = (int)$request->UserID ?: "";
  40. $recharge_type = (int)$request->recharge_type ?: "";
  41. $date = $request->date ?: '';
  42. $Channel = $request->Channel;
  43. $isEmpty = $request->isEmpty ?: 0;
  44. $source = $request->source;
  45. $chargeMoney = $request->chargeMoney ?: '';
  46. $payMethod = (int)$request->input('payMethod', 0);
  47. $amountSort = $request->amountSort ?: '';
  48. // 操作人筛选:空=全部,0=无操作人,正整数=指定管理员 id
  49. $operator_admin_id = $request->input('operator_admin_id', '');
  50. $type_list = DB::table('agent.dbo.admin_configs')->where('type', 'pay')
  51. ->pluck('name');
  52. // $type_list[] = 'TestPay';
  53. $table = 'order as o';
  54. if ($history) {
  55. $table = 'order_back as o';
  56. }
  57. $build_sql = DB::connection('write')->table($table)
  58. ->leftjoin('order_goods as og', 'og.order_id', '=', 'o.id')
  59. ->leftjoin('goods as g', 'og.goods_id', '=', 'g.id')
  60. ->leftJoin('QPAccountsDB.dbo.AccountsInfo as ai', 'o.user_id', '=', 'ai.UserID')
  61. ->leftJoin('QPTreasureDB.dbo.GameScoreInfo as ascore', 'o.user_id', '=', 'ascore.UserID')
  62. ->leftJoin('QPAccountsDB.dbo.AccountPhone as aphone', 'o.user_id', '=', 'aphone.UserID')
  63. ->leftJoin('QPAccountsDB.dbo.AccountsRecord as ar', function ($join) {
  64. $join->on('o.id', '=', 'ar.RecordID');
  65. $join->where('ar.type', 2);
  66. })
  67. ->leftJoin('agent.dbo.admin_users as au', 'ar.admin_id', '=', 'au.id');
  68. $where = [];
  69. $adminChannels=session('admin_channels');
  70. $onlyOrderSnSearch = !empty($order_sn);
  71. // 只查询订单号时,其他筛选条件都不参与
  72. if ($onlyOrderSnSearch) {
  73. $where[] = ['o.order_sn', $order_sn];
  74. } else {
  75. !empty($userid) && $where[] = ['ai.GameID', '=', $userid];
  76. !empty($type) && $where[] = ['o.payment_code', $type];
  77. !empty($payMethod) && $where[] = ['o.order_title', '=', $payMethod];
  78. if(!empty($Channel) || $Channel === '0') {
  79. $where[] = ['ai.Channel', $Channel];
  80. }else if(count($adminChannels)<5){
  81. $where[] = [function ($where) use ($adminChannels) {
  82. $where->whereIn('ai.Channel', $adminChannels);
  83. }];
  84. }
  85. // 充值来源
  86. if (!empty($source)) {
  87. if ($source == -1) {
  88. $where[] = ['o.GiftsID', '=', 0];
  89. } else {
  90. $where[] = ['o.GiftsID', '=', $source];
  91. }
  92. }
  93. // 充值档位筛选
  94. !empty($chargeMoney) && $where[] = ['amount', '=', ($chargeMoney * NumConfig::NUM_VALUE)];
  95. // 支付状态
  96. switch ($recharge_type) {
  97. // 已到账
  98. case 1:
  99. $where[] = ['o.pay_status', '=', 1];
  100. break;
  101. // 咖啡失败(排除退款等特殊状态)
  102. case 2:
  103. $where[] = ['o.pay_status', '>=', 2];
  104. $where[] = ['o.pay_status', '<>', 9];
  105. break;
  106. // 未支付
  107. case 3:
  108. $where[] = ['o.pay_status', '=', 0];
  109. break;
  110. // 退款
  111. case 9:
  112. $where[] = ['o.pay_status', '=', 9];
  113. break;
  114. }
  115. }
  116. // 日期筛选
  117. if (!empty($date)) {
  118. switch ($date) {
  119. case 2:
  120. $create_start_time = date('Y-m-d 00:00:00');
  121. $create_end_time = date('Y-m-d 23:59:59');
  122. break;
  123. case 3:
  124. $create_start_time = date("Y-m-d 00:00:00", strtotime("-1 day"));
  125. $create_end_time = date("Y-m-d 23:59:59", strtotime("-1 day"));
  126. break;
  127. case 4:
  128. //当前日期
  129. $sdefaultDate = date("Y-m-d 00:00:00");
  130. //$first =1 表示每周星期一为开始日期 0表示每周日为开始日期
  131. $first = 1;
  132. //获取当前周的第几天 周日是 0 周一到周六是 1 - 6
  133. $w = date('w', strtotime($sdefaultDate));
  134. $create_start_time = date('Y-m-d 00:00:00', strtotime("$sdefaultDate -" . ($w ? $w - $first : 6) . ' days'));
  135. $create_end_time = date('Y-m-d 23:59:59', strtotime("$start_time +6 days"));
  136. break;
  137. case 5:
  138. $create_start_time = date("Y-m-01 00:00:00");
  139. $create_end_time = date("Y-m-t 23:59:59");
  140. break;
  141. }
  142. }
  143. if (!$onlyOrderSnSearch && $isEmpty == 0) {
  144. empty($create_start_time) && $create_start_time = date('Y-m-d 00:00:00');
  145. empty($create_end_time) && $create_end_time = date('Y-m-d 23:59:59');
  146. } elseif (!$onlyOrderSnSearch && $isEmpty == 2) {
  147. empty($start_time) && $start_time = date('Y-m-d 00:00:00');
  148. empty($end_time) && $end_time = date('Y-m-d 23:59:59');
  149. }
  150. if (!$onlyOrderSnSearch) {
  151. !empty($start_time) && $where[] = ['o.pay_at', '>=', date('Y-m-d H:i:s', strtotime($start_time))];
  152. !empty($end_time) && $where[] = ['o.pay_at', '<=', date('Y-m-d H:i:s', strtotime($end_time))];
  153. !empty($create_start_time) && $where[] = ['o.created_at', '>=', date('Y-m-d H:i:s', strtotime($create_start_time))];
  154. !empty($create_end_time) && $where[] = ['o.created_at', '<=', date('Y-m-d H:i:s', strtotime($create_end_time))];
  155. !empty($updated_start_time) && $where[] = ['o.updated_at', '>=', date('Y-m-d H:i:s', strtotime($updated_start_time))];
  156. !empty($updated_end_time) && $where[] = ['o.updated_at', '<=', date('Y-m-d H:i:s', strtotime($updated_end_time))];
  157. !empty($register_start_time) && $where[] = ['ai.RegisterDate', '>=', date('Y-m-d H:i:s', strtotime($register_start_time))];
  158. !empty($register_end_time) && $where[] = ['ai.RegisterDate', '<=', date('Y-m-d H:i:s', strtotime($register_end_time))];
  159. }
  160. // 操作人(补单等)筛选:与列表相同的 AccountsRecord 关联
  161. if ($operator_admin_id !== '' && $operator_admin_id !== null) {
  162. if ((string)$operator_admin_id === '0') {
  163. $where[] = [function ($q) {
  164. $q->whereNull('ar.admin_id');
  165. }];
  166. } elseif (ctype_digit((string)$operator_admin_id) && (int)$operator_admin_id > 0) {
  167. $where[] = ['ar.admin_id', '=', (int)$operator_admin_id];
  168. }
  169. }
  170. $order ? $orderby = 'g.price desc' : $orderby = 'sum(o.amount) desc';
  171. $operatorFilterActive = $operator_admin_id !== '' && $operator_admin_id !== null
  172. && ((string)$operator_admin_id === '0'
  173. || (ctype_digit((string)$operator_admin_id) && (int)$operator_admin_id > 0));
  174. $aggregateBase = function () use ($table, $operatorFilterActive) {
  175. $q = DB::connection('write')->table($table)
  176. ->leftJoin('QPAccountsDB.dbo.AccountsInfo as ai', 'o.user_id', '=', 'ai.UserID')
  177. ->lock('with(nolock)');
  178. if ($operatorFilterActive) {
  179. $q->leftJoin('QPAccountsDB.dbo.AccountsRecord as ar', function ($join) {
  180. $join->on('o.id', '=', 'ar.RecordID');
  181. $join->where('ar.type', 2);
  182. });
  183. }
  184. return $q;
  185. };
  186. // 充值总金额、手续费汇总(管理员可见);有操作人筛选时 join ar,汇总用 distinct 避免重复行
  187. $payTotalMoney = $aggregateBase()
  188. ->where($where)
  189. ->selectRaw(
  190. $operatorFilterActive
  191. ? 'sum(o.amount) as amount,sum(ISNULL(o.payment_fee,0)) as total_payment_fee,count(distinct o.user_id) count_u,count(distinct o.id) count_id'
  192. : 'sum(amount) as amount,sum(ISNULL(payment_fee,0)) as total_payment_fee,count(distinct(user_id)) count_u,count(id) count_id'
  193. )
  194. ->first();
  195. $totalMoney = isset($payTotalMoney->amount) ? number_float($payTotalMoney->amount / NumConfig::NUM_VALUE) : 0;
  196. $totalPaymentFee = isset($payTotalMoney->total_payment_fee) ? number_float($payTotalMoney->total_payment_fee / NumConfig::NUM_VALUE) : 0;
  197. // 已到账
  198. if ($recharge_type == 1) {
  199. $payOverMoney = $aggregateBase()
  200. ->where($where)
  201. ->selectRaw(
  202. $operatorFilterActive
  203. ? 'sum(o.amount) as amount,count(distinct o.user_id) count_u,count(distinct o.id) count_id'
  204. : 'sum(amount) as amount,count(distinct(user_id)) count_u,count(id) count_id'
  205. )
  206. ->first();
  207. } elseif (empty($recharge_type)) {
  208. $payOverMoney = $aggregateBase()
  209. ->where($where)
  210. ->where('pay_status', 1)
  211. ->selectRaw(
  212. $operatorFilterActive
  213. ? 'sum(o.amount) as amount,count(distinct o.user_id) count_u,count(distinct o.id) count_id'
  214. : 'sum(amount) as amount,count(distinct(user_id)) count_u,count(id) count_id'
  215. )->first();
  216. }
  217. $overMoney = isset($payOverMoney->amount) ? number_float($payOverMoney->amount / NumConfig::NUM_VALUE) : 0;
  218. $refundSummary = $aggregateBase()
  219. ->where($where)
  220. ->where('o.pay_status', 9)
  221. ->selectRaw(
  222. $operatorFilterActive
  223. ? 'sum(o.amount) as refund_amount,sum(ISNULL(o.refund_fee,0)) as refund_fee,count(distinct o.id) as count_id'
  224. : 'sum(amount) as refund_amount,sum(ISNULL(refund_fee,0)) as refund_fee,count(id) as count_id'
  225. )
  226. ->first();
  227. $refundMoney = isset($refundSummary->refund_amount) ? number_float($refundSummary->refund_amount / NumConfig::NUM_VALUE) : 0;
  228. $refundFee = isset($refundSummary->refund_fee) ? number_float($refundSummary->refund_fee / NumConfig::NUM_VALUE) : 0;
  229. $successUserRate = 0;
  230. $successOrderRate = 0;
  231. if (!empty($payTotalMoney->count_u)) {
  232. $successUserRate = round((($payOverMoney->count_u ?? 0) / $payTotalMoney->count_u) * 100, 2);
  233. }
  234. if (!empty($payTotalMoney->count_id)) {
  235. $successOrderRate = round((($payOverMoney->count_id ?? 0) / $payTotalMoney->count_id) * 100, 2);
  236. }
  237. if ($excel) {
  238. $cellData = $build_sql
  239. ->selectRaw('o.order_sn,ai.GameID,o.payment_code,o.pay_status,o.amount,pay_at,o.created_at,o.after_amount,au.account,ai.Channel,ascore.Score as score,ascore.MaxScore as MaxScore,ascore.MaxWinScore as MaxWinScore')
  240. ->orderByDesc('o.id')
  241. ->where($where)
  242. ->lock('with(nolock)')
  243. ->get();
  244. foreach ($cellData as &$val) {
  245. if ($val->pay_status == 1) {
  246. $val->pay_status = '已到账';
  247. } elseif ($val->pay_status == 0) {
  248. $val->pay_status = '未支付';
  249. } elseif ($val->pay_status == 9) {
  250. $val->pay_status = '退款';
  251. } else {
  252. $val->pay_status = '充值出错';
  253. }
  254. $val->amount = number_float($val->amount / NumConfig::NUM_VALUE);
  255. $val->score = number_float($val->score / NumConfig::NUM_VALUE);
  256. $val->created_at_date = date('Y-m-d', strtotime($val->created_at));
  257. $val->created_at_hours = date('H:i:s', strtotime($val->created_at));
  258. $val->finished_at_date = !empty($val->pay_at) ? date('Y-m-d', strtotime($val->pay_at)) : '';
  259. $val->finished_at_hours = !empty($val->pay_at) ? date('H:i:s', strtotime($val->pay_at)) : '';
  260. unset($val->created_at);
  261. unset($val->pay_at);
  262. }
  263. $title = ['订单号', '充值玩家ID', '充值来源', '状态', '充值金额', '操作人', '玩家渠道', '订单创建日期', '订单创建时间', '订单完成日期', '订单完成日期'];
  264. $cellData = json_decode(json_encode($cellData), true);
  265. downloadExcel($cellData, $title, '充值查询');
  266. } else {
  267. $build_sql = $build_sql
  268. ->selectRaw('o.*,og.goods_id,og.price as og_price,og.quantity as og_quantity,ai.GameID as ai_GameID,au.account,ar.RecordID,ar.remarks ar_remarks,ascore.Score as score,aphone.PhoneNum as Phone,ascore.MaxScore as MaxScore,ascore.MaxWinScore as MaxWinScore')
  269. ->lock('with(nolock)')
  270. ->where($where);
  271. if (!empty($amountSort)) {
  272. $build_sql->orderBy('amount', $amountSort);
  273. } else {
  274. $build_sql->orderByDesc('o.id');
  275. }
  276. $list = $build_sql->paginate(10);
  277. foreach ($list as &$val) {
  278. $val->amount = number_float($val->amount / NumConfig::NUM_VALUE);
  279. $val->after_amount = number_float($val->after_amount / NumConfig::NUM_VALUE);
  280. $val->score = number_float($val->score / NumConfig::NUM_VALUE);
  281. $val->payment_fee = number_float(($val->payment_fee ?? 0) / NumConfig::NUM_VALUE);
  282. $val->MaxScore = number_float($val->MaxScore / NumConfig::NUM_VALUE);
  283. $val->MaxWinScore = number_float($val->MaxWinScore / NumConfig::NUM_VALUE);
  284. $val->created_at_date = date('Y-m-d', strtotime($val->created_at));
  285. $val->created_at_hours = date('H:i:s', strtotime($val->created_at));
  286. $val->finished_at_date = !empty($val->pay_at) ? date('Y-m-d', strtotime($val->pay_at)) : '';
  287. $val->finished_at_hours = !empty($val->pay_at) ? date('H:i:s', strtotime($val->pay_at)) : '';
  288. $val->GiftsName = Order::GiftsName($val->GiftsID);
  289. }
  290. $dates = [2 => '今日', 3 => '昨日', 4 => '本周', 5 => '本月'];
  291. // $allChannel = DB::connection('read')->table('QPAccountsDB.dbo.AccountsInfo')->where('IsAndroid', 0)->groupBy('Channel')->pluck('Channel');
  292. $allChannel=$adminChannels;
  293. // 充值来源青铜月卡,白银月卡,黄金月卡,首充礼包,周卡,商城(充值)
  294. //后续还要加个10卢比破冰首充礼包
  295. $sourceList = [
  296. '-1' => '商城',
  297. '301' => '首充',
  298. '302' => '破产礼包',
  299. '303' => '每日首充礼包',
  300. '304' => '每日礼包',
  301. '305' => '召回礼包',
  302. '306' => 'freeBonus礼包',
  303. '401' => '转盘活动充值',
  304. '402' => '圣诞活动',
  305. ];
  306. // 充值档位金额从充值档位配置中动态获取,并加缓存(直接使用档位原始金额)
  307. $chargeMoneyList = Cache::remember('recharge_charge_money_list1', 600, function () {
  308. return DB::connection('write')
  309. ->table('agent.dbo.recharge_gear')
  310. ->where('status', 1)
  311. ->where('first_pay', 0)
  312. ->groupBy('money')
  313. ->orderBy('money')
  314. ->pluck('money')
  315. ->toArray();
  316. });
  317. $admin = session('admin');
  318. $viewAll=1;
  319. if(!in_array($admin->roles[0]->id,[1,12,2010,2011])){
  320. $viewAll=0;
  321. }
  322. $operatorOptions = DB::connection('write')
  323. ->table('QPAccountsDB.dbo.AccountsRecord as ar')
  324. ->join('agent.dbo.admin_users as au', 'ar.admin_id', '=', 'au.id')
  325. ->where('ar.type', 2)
  326. ->whereNotNull('ar.admin_id')
  327. ->select('au.id', 'au.account')
  328. ->distinct()
  329. ->orderBy('au.account')
  330. ->get();
  331. return view('admin.recharge.list', [
  332. 'viewAll' => $viewAll,
  333. 'operator_admin_id' => $operator_admin_id,
  334. 'operatorOptions' => $operatorOptions,
  335. 'list' => $list,
  336. 'UserID' => $userid,
  337. 'order_sn' => $order_sn,
  338. 'end_time' => empty($end_time) ? '' : date('Y-m-d', strtotime($end_time)) . 'T' . date('H:i:s', strtotime($end_time)),
  339. 'start_time' => empty($start_time) ? '' : date('Y-m-d', strtotime($start_time)) . 'T' . date('H:i:s', strtotime($start_time)),
  340. 'create_start_time' => empty($create_start_time) ? '' : date('Y-m-d', strtotime($create_start_time)) . 'T' . date('H:i:s', strtotime($create_start_time)),
  341. 'create_end_time' => empty($create_end_time) ? '' : date('Y-m-d', strtotime($create_end_time)) . 'T' . date('H:i:s', strtotime($create_end_time)),
  342. 'updated_start_time' => empty($updated_start_time) ? '' : date('Y-m-d', strtotime($updated_start_time)) . 'T' . date('H:i:s', strtotime($updated_start_time)),
  343. 'updated_end_time' => empty($updated_end_time) ? '' : date('Y-m-d', strtotime($updated_end_time)) . 'T' . date('H:i:s', strtotime($updated_end_time)),
  344. 'order' => $order,
  345. 'type' => $type,
  346. 'type_list' => $type_list,
  347. 'recharge_type' => $recharge_type,
  348. 'totalMoney' => $totalMoney,
  349. 'totalPaymentFee' => $totalPaymentFee,
  350. 'overMoney' => $overMoney,
  351. 'payOverMoney' => $payOverMoney ?? 0,
  352. 'payTotalMoney' => $payTotalMoney,
  353. 'refundMoney' => $refundMoney,
  354. 'refundFee' => $refundFee,
  355. 'refundSummary' => $refundSummary,
  356. 'successUserRate' => $successUserRate,
  357. 'successOrderRate' => $successOrderRate,
  358. 'date' => $date,
  359. 'dates' => $dates,
  360. 'allChannel' => $allChannel,
  361. 'Channel' => $Channel,
  362. 'isEmpty' => $isEmpty,
  363. 'register_start_time' => $register_start_time,
  364. 'register_end_time' => $register_end_time,
  365. 'sourceList' => $sourceList,
  366. 'source' => $source,
  367. 'chargeMoneyList' => $chargeMoneyList,
  368. 'chargeMoney' => $chargeMoney,
  369. 'amountSort' => $amountSort,
  370. 'request' => $request,
  371. 'payMethod' => $payMethod,
  372. 'payMethods' => [
  373. 1 => 'cashapp',
  374. 2 => 'paypal',
  375. 4 => 'applepay',
  376. 8 => 'googlepay'
  377. ]
  378. ]);
  379. }
  380. }
  381. //充值排行榜,每日&累计
  382. public function rechargeRank1(Request $request)
  383. {
  384. $excel = $request->get('excel');
  385. $end_time = $request->input('end_time');
  386. $start_time = $request->input('start_time');
  387. $sort = $request->get('sort');
  388. $todayPayAmount = $request->get('todayPayAmount');
  389. $chargeMin = $request->chargeMin ?: '';
  390. $chargeMax = $request->chargeMax ?: '';
  391. $last_login_start_time = $request->last_login_start_time ?: '';
  392. $last_login_end_time = $request->last_login_end_time ?: '';
  393. $page = $_SERVER['QUERY_STRING'] ? urlencode($_SERVER['QUERY_STRING']) : 'page=1';
  394. $where = [];
  395. $where[] = ['Recharge', '>', 0];
  396. !empty($start_time) && $where[] = ['o.pay_at', '>=', $start_time];
  397. !empty($end_time) ? $where[] = ['o.pay_at', '<=', date('Y-m-d', strtotime("$end_time+1day"))] : '';
  398. !empty($chargeMin) && $where[] = ['Recharge', '>=', $chargeMin];
  399. !empty($chargeMax) && $where[] = ['Recharge', '<=', $chargeMax];
  400. !empty($last_login_start_time) && $where[] = ['LastLogonDate', '>=', $last_login_start_time];
  401. !empty($last_login_end_time) && $where[] = ['LastLogonDate', '<=', $last_login_end_time];
  402. if (empty($start_time)) {
  403. $pay_at_start_time = date('Y-m-d');
  404. } else {
  405. $pay_at_start_time = $start_time;
  406. }
  407. if (empty($end_time)) {
  408. $pay_at_end_time = date('Y-m-d');
  409. } else {
  410. $pay_at_end_time = $end_time;
  411. }
  412. switch ($sort) {
  413. case '1':
  414. $order_sql = 'a.Experience DESC';
  415. break;
  416. case '2':
  417. $order_sql = 'DATEDIFF(DAY,a.LastLogonDate,GETDATE()) DESC';
  418. break;
  419. default:
  420. $order_sql = 'Recharge DESC';
  421. break;
  422. }
  423. if ($excel) {
  424. // $cellData = DB::connection('write')->table('agent.dbo.order as o')
  425. // ->leftjoin('QPAccountsDB.dbo.AccountsInfo as a', 'o.user_id', '=', 'a.UserID')
  426. // ->leftjoin('QPAccountsDB.dbo.AccountPhone as i', 'o.user_id', '=', 'i.UserID')
  427. // ->leftjoin('agent.dbo.agent as ag', 'o.user_id', '=', 'ag.UserID')
  428. // ->join('QPAccountsDB.dbo.YN_VIPAccount as vip', 'o.user_id', '=', 'vip.UserID')
  429. // ->select(DB::raw('null as rank'), 'o.user_id', 'a.GameID', 'a.NickName', DB::raw('null as type'), 'i.PhoneNum', 'Recharge as money', DB::raw('a.Experience,a.LastLogonDate,a.RegisterDate,DATEDIFF(DAY,a.LastLogonDate,GETDATE()) as time'), 'ag.id', 'a.Channel')
  430. // ->whereNotNull('pay_at')
  431. // ->where($where)
  432. // ->groupBy('o.user_id', 'Recharge', 'a.GameID', 'a.NickName', 'a.LastLogonDate', 'a.RegisterDate', 'a.Experience', 'i.PhoneNum', 'ag.id', 'a.Channel')
  433. // ->orderByRaw($order_sql)
  434. // ->get();
  435. $cellData = DB::table(TableName::QPRecordDB() . 'RecordUserDataStatisticsNew as ds')
  436. ->where('Recharge', '>', 0)
  437. ->join(TableName::QPAccountsDB() . 'AccountsInfo as ai', 'ds.UserID', 'ai.UserID')
  438. ->leftjoin('QPAccountsDB.dbo.AccountPhone as ap', 'ds.UserID', 'ap.UserID')
  439. ->select('ai.UserID', 'ai.GameID', 'ai.NickName', 'ai.Channel', 'ap.PhoneNum', 'ds.Recharge', 'ai.PlayTimeCount', 'ai.LastLogonDate', 'ai.RegisterDate')
  440. ->orderByDesc('Recharge')
  441. ->get();
  442. $pyq = DB::connection('write')->table('QPAccountsDB.dbo.PyqInfo')->select('UserID')->get();
  443. $pyq_list = [];
  444. foreach ($pyq as $k => $v) {
  445. $pyq_list[$v->UserID] = 1;
  446. }
  447. foreach ($cellData as $key => &$value) {
  448. $second = $value->Experience;
  449. $day = floor($second / (3600 * 24));
  450. $second = $second % (3600 * 24);//除去整天之后剩余的时间
  451. $hour = floor($second / 3600);
  452. $second = $second % 3600;//除去整小时之后剩余的时间
  453. $minute = floor($second / 60);
  454. //返回字符串
  455. $value->Experience = $day . '天' . $hour . '小时' . $minute . '分';
  456. $value->type = '玩家';
  457. $value->time = !empty($value->time) ? $value->time . '天' : '';
  458. unset($value->id);
  459. $value->rank = $key + 1;
  460. }
  461. $title = ['排名', '用户ID', '游戏ID', '游戏昵称', '玩家状态', '手机号', '充值总额', '游戏时长', '最后登录时间', '注册时间', '距上次登录时间', '玩家渠道'];
  462. $cellData = json_decode(json_encode($cellData), true);
  463. downloadExcel($cellData, $title, '充值排行榜');
  464. } else {
  465. $sql = DB::connection('write')->table('agent.dbo.order as o')
  466. ->leftjoin('QPAccountsDB.dbo.AccountsInfo as a', 'o.user_id', '=', 'a.UserID')
  467. ->leftjoin('QPAccountsDB.dbo.AccountPhone as i', 'o.user_id', '=', 'i.UserID')
  468. ->leftjoin('QPAccountsDB.dbo.YN_VIPAccount as vip', 'o.user_id', '=', 'vip.UserID')
  469. ->select(DB::raw('null as rank'), 'i.PhoneNum', 'o.user_id', 'a.GameID', 'a.NickName', 'Recharge as money', DB::raw('a.Experience,a.LastLogonDate,a.RegisterDate,DATEDIFF(DAY,a.LastLogonDate,GETDATE()) as time'), 'a.Channel');
  470. if (!empty($todayPayAmount)) {
  471. $list = $sql
  472. ->where('pay_at', '>=', $pay_at_start_time . ' 00:00:00')
  473. ->where('pay_at', '<=', $pay_at_end_time . ' 23:59:59')
  474. ->orderByRaw("sum(amount) $todayPayAmount");
  475. } else {
  476. $list = $sql
  477. ->where('pay_at', '>=', $pay_at_start_time . ' 00:00:00')
  478. ->where('pay_at', '<=', $pay_at_end_time . ' 23:59:59')
  479. ->orderByRaw($order_sql);
  480. }
  481. $list = $list->where($where)
  482. ->groupBy('o.user_id', 'a.GameID', 'a.NickName', 'a.LastLogonDate', 'a.RegisterDate', 'a.Experience', 'i.PhoneNum', 'a.Channel', 'Recharge')
  483. ->paginate(10);
  484. $UserIDs = [];
  485. foreach ($list as $value) {
  486. $UserIDs[] = $value->user_id;
  487. }
  488. $todayPay = DB::connection('write')->table('agent.dbo.order')
  489. ->whereIn('user_id', $UserIDs)
  490. ->where('pay_at', '>=', $pay_at_start_time . ' 00:00:00')
  491. ->where('pay_at', '<=', $pay_at_end_time . ' 23:59:59')
  492. ->selectRaw('IsNull(sum(amount),0) amount,user_id')
  493. ->groupBy('user_id')
  494. ->pluck('amount', 'user_id')->toArray();
  495. foreach ($list as $key => &$value) {
  496. $second = $value->Experience;
  497. $day = floor($second / (3600 * 24));
  498. $second = $second % (3600 * 24);//除去整天之后剩余的时间
  499. $hour = floor($second / 3600);
  500. $second = $second % 3600;//除去整小时之后剩余的时间
  501. $minute = floor($second / 60);
  502. //返回字符串
  503. $value->Experience = $day . '天' . $hour . '小时' . $minute . '分';
  504. $value->type = '玩家';
  505. $value->rank = $key + 1;
  506. $value->money = number_float($value->money);
  507. $value->todayPayAmount = isset($todayPay[$value->user_id]) ? number_float($todayPay[$value->user_id] / NumConfig::NUM_VALUE) : 0;
  508. }
  509. $chargeMin = $request->chargeMin ?: '';
  510. $chargeMax = $request->chargeMax ?: '';
  511. $last_login_start_time = $request->last_login_start_time ?: '';
  512. $last_login_end_time = $request->last_login_end_time ?: '';
  513. $sort_list = [0 => '充值金额', 1 => '游戏时长', 2 => '距上次登录时间'];
  514. return view('admin.recharge.rank', [
  515. 'list' => $list,
  516. 'end_time' => $end_time,
  517. 'start_time' => $start_time,
  518. 'sort' => $sort,
  519. 'sort_list' => $sort_list,
  520. 'page' => '/admin/recharge/rank?' . $page,
  521. 'todayPayAmount' => $todayPayAmount,
  522. 'chargeMin' => $chargeMin,
  523. 'chargeMax' => $chargeMax,
  524. 'last_login_start_time' => $last_login_start_time,
  525. 'last_login_end_time' => $last_login_end_time,
  526. 'pay_at_start_time' => $pay_at_start_time,
  527. 'pay_at_end_time' => $pay_at_end_time,
  528. ]);
  529. }
  530. }
  531. public function rechargeRank(Request $request)
  532. {
  533. $excel = $request->get('excel');
  534. $date = Carbon::now();
  535. $start_time = $request->input('start_time', $date->format('Y-m-d'));
  536. $end_time = $request->input('end_time', $date->format('Y-m-d'));
  537. $sort = $request->get('sort');
  538. $Channel = $request->get('Channel');
  539. $chargeMin = $request->chargeMin ?: '';
  540. $chargeMax = $request->chargeMax ?: '';
  541. $adminChannels = session('admin_channels');
  542. $Channels = session('all_channels');
  543. $admin = session('admin');
  544. $where = [];
  545. !empty($start_time) && $where[] = ['DateID', '>=', Carbon::parse($start_time)->format('Ymd')];
  546. !empty($end_time) && $where[] = ['DateID', '<', Carbon::parse($end_time)->addDay(1)->format('Ymd')];
  547. !empty($chargeMin) && $where[] = ['Recharge', '>=', $chargeMin];
  548. !empty($chargeMax) && $where[] = ['Recharge', '<=', $chargeMax];
  549. $where2=$where;
  550. $channelWhere=[];
  551. if(!empty($Channel) || $Channel === '0') {
  552. $where2[] = ['ai.Channel', $Channel];
  553. $channelWhere[] = ['ai.Channel', $Channel];
  554. }else if(count($adminChannels)<5){
  555. $where2[] = [function ($where) use ($adminChannels) {
  556. $where->whereIn('ai.Channel', $adminChannels);
  557. }];
  558. $channelWhere[] = [function ($where) use ($adminChannels) {
  559. $where->whereIn('ai.Channel', $adminChannels);
  560. }];
  561. }
  562. switch ($sort) {
  563. case '1':
  564. $order_sql = 'ai.PlayTimeCount DESC';
  565. break;
  566. case '2':
  567. $order_sql = 'DATEDIFF(DAY,a.LastLogonDate,GETDATE()) DESC';
  568. break;
  569. default:
  570. $order_sql = 'sum(ds.Recharge) DESC';
  571. break;
  572. }
  573. if ($excel && false) {
  574. $cellData = DB::table(TableName::QPRecordDB() . 'RecordUserDataStatisticsNew as ds')
  575. ->where('Recharge', '>', 0)
  576. ->where($where2)
  577. ->join(TableName::QPAccountsDB() . 'AccountsInfo as ai', 'ds.UserID', 'ai.UserID')
  578. ->leftjoin('QPAccountsDB.dbo.AccountPhone as ap', 'ds.UserID', 'ap.UserID')
  579. ->select('ai.UserID','ai.GameID', 'ai.NickName', 'ai.Channel', 'ap.PhoneNum', 'ai.PlayTimeCount', 'ai.LastLogonDate', 'ai.RegisterDate')
  580. ->lock('with(nolock)')
  581. ->orderByRaw($order_sql)
  582. ->get();
  583. $rechargeSum = DB::table(TableName::QPRecordDB() . 'RecordUserDataStatisticsNew as ds')
  584. ->where('Recharge', '>', 0)
  585. ->where($where)
  586. ->selectRaw('sum(ds.Recharge) Recharge,UserID')
  587. ->lock('with(nolock)')
  588. ->groupBy('UserID')
  589. ->pluck('Recharge', 'UserID')->toArray();
  590. $UserIDs = [];
  591. foreach ($cellData as $value) {
  592. $UserIDs[] = $value->UserID;
  593. }
  594. foreach ($cellData as $key => &$value) {
  595. $second = $value->PlayTimeCount;
  596. $day = floor($second / (3600 * 24));
  597. $second = $second % (3600 * 24);//除去整天之后剩余的时间
  598. $hour = floor($second / 3600);
  599. $second = $second % 3600;//除去整小时之后剩余的时间
  600. $minute = floor($second / 60);
  601. //返回字符串
  602. $value->PlayTimeCount = $day . '天' . $hour . '小时' . $minute . '分';
  603. $value->type = '玩家';
  604. $value->money = $rechargeSum[$value->UserID] ?? 0;
  605. $value->time = Carbon::parse(now())->diffInDays($value->LastLogonDate, true);
  606. }
  607. $title = [ '用户ID', '游戏ID', '游戏昵称', '渠道号', '手机号','游戏时长', '最后登录时间', '注册时间','类型','充值金额', '距上次登录时间'];
  608. $cellData = json_decode(json_encode($cellData), true);
  609. downloadExcel($cellData, $title, '充值排行榜');
  610. } else {
  611. $channelUsers=DB::table(TableName::QPAccountsDB() . 'AccountsInfo as ai')->where($channelWhere)->select('UserID');
  612. $rechargeSum = DB::table(TableName::QPRecordDB() . 'RecordUserDataStatisticsNew as ds')
  613. ->where('Recharge', '>', 0)
  614. ->where($where)
  615. ->whereIn('UserID',$channelUsers)
  616. ->selectRaw('sum(ds.Recharge) RechargeAll,UserID')
  617. ->groupBy('UserID')
  618. ->lock('with(nolock)')
  619. ->orderByRaw($order_sql)
  620. ->paginate(10);
  621. $UserIDs = [];
  622. $ReSort=[];
  623. foreach ($rechargeSum as &$value) {
  624. $UserIDs[] = $value->UserID;
  625. $ReSort[$value->UserID]=$value;
  626. }
  627. $list = DB::table(TableName::QPAccountsDB() . 'AccountsInfo as ai')
  628. ->leftjoin('QPAccountsDB.dbo.AccountPhone as ap', 'ai.UserID', 'ap.UserID')
  629. ->select('ai.UserID', 'ai.GameID', 'ai.NickName', 'ai.Channel', 'ap.PhoneNum', 'ai.PlayTimeCount', 'ai.LastLogonDate', 'ai.RegisterDate')
  630. ->whereIn('ai.UserID',$UserIDs)
  631. ->lock('with(nolock)')
  632. ->get();
  633. foreach ($list as $key => &$value) {
  634. $second = $value->PlayTimeCount;
  635. $day = floor($second / (3600 * 24));
  636. $second = $second % (3600 * 24);//除去整天之后剩余的时间
  637. $hour = floor($second / 3600);
  638. $second = $second % 3600;//除去整小时之后剩余的时间
  639. $minute = floor($second / 60);
  640. $value2=$ReSort[$value->UserID];
  641. $value2->GameID=$value->GameID;
  642. $value2->NickName=$value->NickName;
  643. $value2->Channel=$value->Channel;
  644. $value2->PhoneNum=$value->PhoneNum;
  645. $value2->PlayTimeCount=$value->PlayTimeCount;
  646. $value2->LastLogonDate=$value->LastLogonDate;
  647. $value2->RegisterDate=$value->RegisterDate;
  648. //返回字符串
  649. $value2->Experience = $day . '天' . $hour . '小时' . $minute . '分';
  650. $value2->type = '玩家';
  651. $value2->rank = $key + 1;
  652. $value2->money = $value2->RechargeAll;//$rechargeSum[$value->UserID] ?? 0;
  653. $value2->time = Carbon::parse(now())->diffInDays($value->LastLogonDate, true);
  654. }
  655. $chargeMin = $request->chargeMin ?: '';
  656. $chargeMax = $request->chargeMax ?: '';
  657. $sort_list = [0 => '充值金额', 1 => '游戏时长', 2 => '距上次登录时间'];
  658. $channels=$adminChannels;
  659. return view('admin.recharge.rank', [
  660. 'list' => $rechargeSum,
  661. 'end_time' => $end_time,
  662. 'start_time' => $start_time,
  663. 'sort' => $sort,
  664. 'sort_list' => $sort_list,
  665. 'chargeMin' => $chargeMin,
  666. 'chargeMax' => $chargeMax,
  667. 'Channel'=>$Channel,
  668. 'channels' => $channels
  669. ]);
  670. }
  671. }
  672. // 补单
  673. public function supplement(Request $request, $id)
  674. {
  675. try {
  676. if ($request->method() == 'POST') {
  677. $admin_id = $request->session()->get('admin')->id;
  678. $order = DB::table('agent.dbo.order')->where('id', $id)->first();
  679. if (!$order) {
  680. return apiReturnFail('订单不存在!');
  681. }
  682. if ((int)$order->pay_status === 1) {
  683. return apiReturnFail('订单已完成!');
  684. }
  685. // 退款订单禁止补单
  686. if ((int)$order->pay_status === 9) {
  687. return apiReturnFail('退款订单不可补单');
  688. }
  689. $payAmt = $order->amount / NumConfig::NUM_VALUE;
  690. $order_sn = $order->order_sn;
  691. Log::info('补单单号:' . $order_sn);
  692. // 成功处理回调
  693. $GiftsID = $order->GiftsID ?: '';
  694. $userID = $order->user_id ?: '';
  695. //$res = (new OrderService())->paySuccess($GiftsID, $userID, $payAmt, $order_sn);
  696. // 获取金额
  697. $service = new OrderServices();
  698. $recharge_gear = DB::connection('write')->table('agent.dbo.recharge_gear')->where('first_pay', 0)->where('money', $payAmt)->select('favorable_price', 'give')->first();
  699. if($recharge_gear || $GiftsID){
  700. [$give, $favorable_price, $Recharge, $czReason, $cjReason] = $service->getPayInfo($GiftsID, $userID, $payAmt);
  701. }else{
  702. $Recharge = $payAmt;
  703. $give = 0;
  704. $favorable_price = $Recharge + $give;
  705. $czReason = 1;
  706. $cjReason = 45;
  707. }
  708. // [$give, $favorable_price, $Recharge, $czReason, $cjReason] = $service->getPayInfo($GiftsID, $userID, $payAmt);
  709. // 增加充值记录
  710. [$Score] = $service->addRecord($userID, $payAmt, $favorable_price, $order_sn, $GiftsID, $Recharge, $czReason, $give, $cjReason, $order->AdId, $order->eventType);
  711. // 成功处理回调
  712. \App\Jobs\Order::dispatch([$userID, $payAmt, $Score, $favorable_price, $GiftsID, $order_sn]);
  713. // 修改订单状态
  714. $data = [
  715. 'pay_status' => 1,
  716. 'finished_at' => date('Y-m-d H:i:s'),
  717. 'updated_at' => date('Y-m-d H:i:s'),
  718. 'pay_at' => date('Y-m-d H:i:s')
  719. ];
  720. $order_up = DB::table('agent.dbo.order')->where('id', $id)->update($data);
  721. // 添加操作记录
  722. (new AccountsRecordLogic())->create_record($id, $order->pay_status, 1, '', $admin_id, 2);
  723. if ($order_up === false) {
  724. return apiReturnFail('补单失败');
  725. }
  726. return apiReturnSuc();
  727. }
  728. } catch (\Exception $exception) {
  729. return apiReturnFail($exception->getMessage());
  730. }
  731. }
  732. // 标记订单为退款状态
  733. public function refund(Request $request, $id)
  734. {
  735. try {
  736. $admin = $request->session()->get('admin');
  737. $roleId = $admin->roles[0]->id ?? 0;
  738. // 仅管理员角色允许操作(与补单权限保持一致)
  739. if (!in_array($roleId, [1, 12])) {
  740. return apiReturnFail('无权限执行该操作');
  741. }
  742. $order = DB::connection('write')->table('agent.dbo.order')->where('id', $id)->lockForUpdate()->first();
  743. if (!$order) {
  744. return apiReturnFail('订单不存在!');
  745. }
  746. if ($order->pay_status == 9) {
  747. return apiReturnFail('订单已为退款状态');
  748. }
  749. if ($order->pay_status != 1) {
  750. return apiReturnFail('仅已到账订单可设置为退款状态');
  751. }
  752. $now = date('Y-m-d H:i:s');
  753. $updated = DB::connection('write')->table('agent.dbo.order')
  754. ->where('id', $id)
  755. ->update([
  756. 'pay_status' => 9,
  757. 'refund_fee' => ($order->payment_code=='AiNewPay' && $order->order_title==2)?800:3000,
  758. 'updated_at' => $now,
  759. ]);
  760. if ($updated === false) {
  761. return apiReturnFail('设置退款状态失败');
  762. }
  763. $fee = ($order->payment_code=='AiNewPay' && $order->order_title==2)?800:3000;
  764. (new RechargeWithDraw())->refund($order->user_id, $order->amount, $fee);
  765. $admin_id = $admin->id;
  766. (new AccountsRecordLogic())->create_record($id, $order->pay_status, 9, '', $admin_id, 2);
  767. return apiReturnSuc();
  768. } catch (\Exception $exception) {
  769. return apiReturnFail($exception->getMessage());
  770. }
  771. }
  772. /**
  773. * 模拟上报 FB 支付事件(仅管理员可用)
  774. */
  775. public function fbReportMock(Request $request, $id)
  776. {
  777. try {
  778. $admin = $request->session()->get('admin');
  779. $roleId = $admin->roles[0]->id ?? 0;
  780. if (!in_array($roleId, [1, 12])) {
  781. return apiReturnFail('无权限执行该操作');
  782. }
  783. $order = DB::connection('write')->table('agent.dbo.order')->where('id', $id)->first();
  784. if (!$order) {
  785. return apiReturnFail('订单不存在!');
  786. }
  787. // 退款订单不允许模拟上报
  788. if ((int)$order->pay_status === 9) {
  789. return apiReturnFail('退款订单不可模拟上报');
  790. }
  791. // 只允许对未成功的订单做模拟上报(已到账的默认认为已正常上报)
  792. if ((int)$order->pay_status === 1) {
  793. return apiReturnFail('仅对未成功订单开放模拟上报');
  794. }
  795. $userId = $order->user_id;
  796. $payAmt = $order->amount; // 内部金额单位,保持与原上报一致
  797. // 构造模拟上报的 params
  798. $item = [
  799. 'regtime' => time(), // 当前时间
  800. 'isd0' => 1, // 固定为首日
  801. 'first' => 1, // 固定视为首充
  802. 'golds' => $payAmt, // 金额
  803. 'udis' => $userId, // 注意:按需求使用 udis 字段
  804. 'order_sn'=> $order->order_sn,
  805. ];
  806. // 通过 OuroGameService 模拟一次 pay_finish 上报
  807. OuroGameService::notifyWebHall(
  808. $userId,
  809. '',
  810. 'pay_finish',
  811. [
  812. 'Golds' => $payAmt,
  813. 'PayNum'=> $payAmt,
  814. 'event' => 'pay',
  815. 'params'=> $item,
  816. ]
  817. );
  818. return apiReturnSuc();
  819. } catch (\Exception $exception) {
  820. Log::error('模拟 FB 上报失败:' . $exception->getMessage(), [
  821. 'order_id' => $id,
  822. ]);
  823. return apiReturnFail('上报失败,请稍后重试');
  824. }
  825. }
  826. public function search($orderId)
  827. {
  828. $order = DB::table('agent.dbo.order')->where('id', $orderId)->first();
  829. if (!$order) {
  830. return apiReturnFail('未查询到订单信息');
  831. }
  832. $agent = $order->payment_code;
  833. $service = PayMentService::pay_logic($agent);
  834. $res = $service->pay_search($order->order_sn);
  835. if($res){
  836. return apiReturnSuc([],'','订单支付成功');
  837. }else{
  838. return apiReturnFail('订单未成功');
  839. }
  840. }
  841. // 充值渠道修改
  842. public function config($method, Request $request)
  843. {
  844. if ($request->method() == 'GET') {
  845. $res = (new RechargeLogic())->config($method);
  846. return view('admin.recharge.config', $res);
  847. }
  848. $validator = Validator::make($request->all(), [
  849. 'config.*.sort' => 'required|int',
  850. 'config.*.status' => 'required|in:1,-1',
  851. 'config.*.weight.1' => 'nullable|int|min:0|max:100000',
  852. 'config.*.weight.2' => 'nullable|int|min:0|max:100000',
  853. 'config.*.weight.4' => 'nullable|int|min:0|max:100000',
  854. 'config.*.weight.8' => 'nullable|int|min:0|max:100000',
  855. ]);
  856. if ($validator->fails()) {
  857. return apiReturnFail($validator->errors()->first());
  858. }
  859. $config = $request->input('config');
  860. $opened = array_filter($config, function ($item) {
  861. return $item['status'] == 1;
  862. });
  863. if (array_sum(array_column($opened, 'sort')) != 100) {
  864. return apiReturnFail('权重值分配不正确');
  865. }
  866. foreach ($config as $id => $v) {
  867. $weightInput = $v['weight'] ?? null;
  868. // 防御性处理:避免后续误把 weight 数组直接参与 update
  869. unset($v['weight']);
  870. $remarksRaw = DB::table('agent.dbo.admin_configs')->where('id', $id)->value('remarks');
  871. $remarks = [];
  872. if (!empty($remarksRaw)) {
  873. $decoded = \GuzzleHttp\json_decode($remarksRaw, true);
  874. if (is_array($decoded)) {
  875. $remarks = $decoded;
  876. }
  877. }
  878. if (is_array($weightInput)) {
  879. $existingWeights = $remarks['weight'] ?? ($remarks['weights'] ?? []);
  880. if (!is_array($existingWeights)) {
  881. $existingWeights = [];
  882. }
  883. $methodWeights = $existingWeights;
  884. foreach ([1, 2, 4, 8] as $methodKey) {
  885. if (array_key_exists($methodKey, $weightInput)) {
  886. $weightKey = 'type_' . $methodKey;
  887. if ($weightInput[$methodKey] === '' || $weightInput[$methodKey] === null) {
  888. $methodWeights[$weightKey] = 0;
  889. } else {
  890. $methodWeights[$weightKey] = (int)$weightInput[$methodKey];
  891. }
  892. }
  893. }
  894. $remarks['weight'] = $methodWeights;
  895. }
  896. $updateData = [
  897. 'sort' => (int)$v['sort'],
  898. 'status' => (int)$v['status'],
  899. 'admin_id' => session('admin')['id'],
  900. 'updated_at' => date('Y-m-d H:i:s'),
  901. 'remarks' => \GuzzleHttp\json_encode($remarks, JSON_UNESCAPED_UNICODE),
  902. ];
  903. if ((int)$v['status'] === -1) {
  904. $updateData['sort'] = 0;
  905. }
  906. DB::table('agent.dbo.admin_configs')->where('id', $id)->update($updateData);
  907. if ((int)$v['status'] === -1) {
  908. DB::table('QPPlatformDB.dbo.ChannelOpenRecharge')->where('ConfigID', $id)
  909. ->update([
  910. 'sort' => 0,
  911. 'status' => 2
  912. ]);
  913. }
  914. }
  915. return apiReturnSuc();
  916. }
  917. public function methods()
  918. {
  919. $methods = DB::table('agent.dbo.admin_configs')
  920. ->leftJoin('agent.dbo.admin_users as u', 'admin_configs.admin_id', '=', 'u.id')
  921. ->select('admin_configs.*', 'u.account')
  922. ->where('admin_configs.type', 'pay_method')
  923. ->get();
  924. return view('admin.recharge.methods', [
  925. 'methods' => $methods,
  926. ]);
  927. }
  928. // 充值渠道修改 开关
  929. public function switch_control(Request $request, $id)
  930. {
  931. $type = $request->type;
  932. $admin_id = $request->session()->get('admin')->id;
  933. $logic = new RechargeLogic();
  934. $res = $logic->switch_control($id, $type, $admin_id);
  935. if ($res === false) {
  936. return apiReturnFail($logic->getError());
  937. }
  938. ClearCache::dispatch();
  939. return apiReturnSuc();
  940. }
  941. // 充值档位修改
  942. public function gear_list()
  943. {
  944. $res = (new RechargeLogic())->gear_list();
  945. // dd($res);
  946. return view('admin.recharge.gear_list', $res);
  947. }
  948. public function channel_switch(Request $request, $id)
  949. {
  950. $type = $request->type;
  951. $logic = new RechargeLogic();
  952. $res = $logic->channel_switch($id, $type);
  953. if ($res === false) {
  954. return apiReturnFail($logic->getError());
  955. }
  956. return apiReturnSuc();
  957. }
  958. // 添加
  959. public function add(Request $request)
  960. {
  961. $list = DB::table('agent.dbo.admin_configs')->where('type', 'pay')->pluck('name', 'id');
  962. if ($request->method() == 'POST') {
  963. $money = (float)$request->money ?: '';
  964. $status = $request->status;
  965. // $config_ids = $request->config_ids;
  966. $favorable_price = (float)$request->favorable_price;
  967. $give = (float)$request->give;
  968. $pay_methods = (int)$request->pay_methods ?: 0; // 支付方式位掩码
  969. $in_shop = (int)$request->input('in_shop', 1); // 是否在商城展示
  970. $logic = new RechargeLogic();
  971. $res = $logic->add($money, $status, '', $favorable_price, $give, $pay_methods, $in_shop);
  972. return apiReturnSuc();
  973. }
  974. return view('admin.recharge.add', ['list' => $list]);
  975. }
  976. public function update_config(Request $request, $id)
  977. {
  978. if ($request->isMethod('post')) {
  979. $money = (float)($request->money ?: '');
  980. $favorable_price = (float)($request->favorable_price ?: 0);
  981. $give = (float)($request->give ?: 0);
  982. $second_give = (int)($request->second_give ?: 0);
  983. $pay_methods = (int)($request->pay_methods ?: 0); // 支付方式位掩码
  984. $in_shop = (int)$request->input('in_shop', 1); // 是否在商城展示
  985. // 构建支付方式数组
  986. $gearData = [];
  987. $payMethodsMap = [
  988. 1 => 'cashapp',
  989. 2 => 'paypal',
  990. 4 => 'applepay',
  991. 8 => 'googlepay',
  992. 64 => 'usdt-trc20',
  993. 128 => 'usdt-erc20',
  994. 256 => 'usdc-trc20',
  995. 512 => 'usdc-erc20'
  996. ];
  997. foreach ($payMethodsMap as $value => $name) {
  998. if ($pay_methods & $value) {
  999. $gearData[] = [
  1000. 'name' => $name,
  1001. 'value' => $value,
  1002. 'status' => 1
  1003. ];
  1004. }
  1005. }
  1006. $data = [
  1007. 'money' => $money,
  1008. 'favorable_price' => $favorable_price,
  1009. 'second_give' => $second_give,
  1010. 'give' => $give,
  1011. 'in_shop' => $in_shop,
  1012. 'gear' => \GuzzleHttp\json_encode($gearData) // 存储到gear字段
  1013. ];
  1014. DB::table('agent.dbo.recharge_gear')->where('id', $id)->update($data);
  1015. return apiReturnSuc();
  1016. } else {
  1017. $info = DB::table('agent.dbo.recharge_gear')->where('id', $id)->first();
  1018. // 解析gear字段,计算pay_methods用于回显
  1019. $pay_methods = 0;
  1020. if (!empty($info->gear)) {
  1021. $gear = \GuzzleHttp\json_decode($info->gear, true);
  1022. if (is_array($gear)) {
  1023. foreach ($gear as $item) {
  1024. if (isset($item['value']) && ($item['status'] ?? 0) == 1) {
  1025. $pay_methods += $item['value'];
  1026. }
  1027. }
  1028. }
  1029. }
  1030. $info->pay_methods = $pay_methods;
  1031. return view('admin.recharge.update_config', ['info' => $info]);
  1032. }
  1033. }
  1034. // 加载修改页面
  1035. public function update(Request $request, $id)
  1036. {
  1037. $info = (new RechargeLogic())->update($id);
  1038. return view('admin.recharge.update', $info);
  1039. }
  1040. // 修改里面的开关
  1041. public function gear_switch(Request $request, $id)
  1042. {
  1043. $config_id = $request->config_id ?: '';
  1044. $type = $request->type ?: '';
  1045. $logic = new RechargeLogic();
  1046. $res = $logic->gear_switch($id, $config_id, $type);
  1047. if ($res === false) {
  1048. return apiReturnFail($logic->getError());
  1049. }
  1050. ClearCache::dispatch();
  1051. return apiReturnSuc();
  1052. }
  1053. // 修改排序
  1054. public function update_sort(Request $request, $id)
  1055. {
  1056. $sort = $request->sort ?: 0;
  1057. DB::connection('write')->table('agent.dbo.admin_configs')
  1058. ->where('id', $id)
  1059. ->update(['sort' => $sort]);
  1060. ClearCache::dispatch();
  1061. return apiReturnSuc();
  1062. }
  1063. // 添加备注
  1064. public function remarks(Request $request, $id)
  1065. {
  1066. $remarks = $request->remark ?: '';
  1067. DB::connection('write')->table('agent.dbo.admin_configs')
  1068. ->where('id', $id)
  1069. ->update(['remarks' => $remarks]);
  1070. return apiReturnSuc();
  1071. }
  1072. // 首冲10元礼包--修改渠道
  1073. public function firstCharge(Request $request)
  1074. {
  1075. $StatusValue = $request->StatusValue ?: '';
  1076. DB::connection('write')->table('QPAccountsDB.dbo.SystemStatusInfo')
  1077. ->where('StatusName', 'FirstChargeGiftBag')
  1078. ->update(['StatusValue' => $StatusValue]);
  1079. return apiReturnSuc();
  1080. }
  1081. // 首冲10元礼包 -- 修改状态
  1082. public function firstChargeStatus(Request $request)
  1083. {
  1084. $StatusValue = $request->StatusValue ?: '';
  1085. DB::connection('write')->table('QPAccountsDB.dbo.SystemStatusInfo')
  1086. ->where('StatusName', 'FirstChargeGiftBagStatus')
  1087. ->update(['StatusValue' => $StatusValue]);
  1088. return apiReturnSuc();
  1089. }
  1090. // IP回调白名单
  1091. public function ip_white(Request $request)
  1092. {
  1093. $list = DB::connection('write')->table('agent.dbo.admin_configs as ac')
  1094. ->leftJoin('agent.dbo.recharge_ip as ri', 'ac.id', '=', 'ri.config_id')
  1095. ->leftJoin('agent.dbo.admin_users as au', 'ri.admin_id', 'au.id')
  1096. ->where('ac.status', 1)
  1097. ->select('ac.id', 'ac.name', 'ac.config_value', 'ip', 'account', 'last_time', 'ac.status', 'ri.remarks')
  1098. ->paginate(5);
  1099. return view('admin.recharge.ip_white', compact('list'));
  1100. }
  1101. public function ip_white_update(Request $request, $id)
  1102. {
  1103. if ($request->isMethod('post')) {
  1104. $post = $request->post();
  1105. if (empty($post['ip'])) {
  1106. return apiReturnFail('IP白名单不能为空');
  1107. }
  1108. $ip = explode(',', $post['ip']);
  1109. foreach ($ip as $val) {
  1110. if (!filter_var($val, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
  1111. return apiReturnFail('ip不合法');
  1112. }
  1113. }
  1114. $post['last_time'] = date('Y-m-d H:i:s');
  1115. $post['admin_id'] = session('admin')->id;
  1116. DB::connection('write')->table('agent.dbo.recharge_ip')
  1117. ->updateOrInsert(['config_id' => $id], $post);
  1118. return apiReturnSuc();
  1119. }
  1120. $info = DB::connection('write')->table('agent.dbo.admin_configs as ac')
  1121. ->leftJoin('agent.dbo.recharge_ip as ri', 'ac.id', '=', 'ri.config_id')
  1122. ->where('ac.id', $id)
  1123. ->select('ac.id', 'ac.name', 'ac.config_value', 'ip', 'ri.remarks')
  1124. ->first();
  1125. return view('admin.recharge.ip_white_update', compact('info'));
  1126. }
  1127. // 充值推荐档位
  1128. public function recomendar_recharge(Request $request)
  1129. {
  1130. $StatusValue = $request->StatusValue ?: '';
  1131. DB::connection('write')->table('QPAccountsDB.dbo.SystemStatusInfo')
  1132. ->where('StatusName', 'RecomendarRecharge')
  1133. ->update(['StatusValue' => $StatusValue]);
  1134. return apiReturnSuc();
  1135. }
  1136. // 修改图片地址
  1137. public function updatePic(Request $request, $id)
  1138. {
  1139. $picList = config('games.recharge_pic_config');
  1140. if ($request->isMethod('post')) {
  1141. $pic_number = $request->post('pic_number');
  1142. if ($pic_number < 0) {
  1143. return apiReturnFail('请选择图片!');
  1144. }
  1145. $pic_url = config('games.recharge_pic.recharge_pic_url');
  1146. $recharge_pic_url = str_replace('{num}', $picList[$pic_number], $pic_url);
  1147. DB::table(TableName::agent() . 'admin_configs')
  1148. ->where('id', $id)
  1149. ->update(['config_value' => $recharge_pic_url, 'pic_num' => $pic_number]);
  1150. return apiReturnSuc();
  1151. }
  1152. return view('admin.recharge.update_pic', compact('id', 'picList'));
  1153. }
  1154. // 轮询开关
  1155. public function poll(Request $request)
  1156. {
  1157. $StatusValue = $request->StatusValue ?: '';
  1158. DB::connection('write')->table('QPAccountsDB.dbo.SystemStatusInfo')
  1159. ->where('StatusName', 'PollSwitch')
  1160. ->update(['StatusValue' => $StatusValue]);
  1161. return apiReturnSuc();
  1162. }
  1163. // 充值礼包
  1164. public function gift()
  1165. {
  1166. $res = (new RechargeLogic())->gift();
  1167. return view('admin.recharge.gift', $res);
  1168. }
  1169. public function clearCache()
  1170. {
  1171. ClearCache::dispatch();
  1172. return apiReturnSuc();
  1173. }
  1174. public function monthCardEdit($id, Request $request) {
  1175. $monthCard = MonthCard::findOrFail($id);
  1176. if ($request->method() == 'GET') {
  1177. return view('admin.recharge.month_card_edit', [
  1178. 'monthCard' => $monthCard,
  1179. ]);
  1180. }
  1181. $validator = Validator::make($request->all(), [
  1182. 'Price' => 'required|min:1',
  1183. 'FirstReward' => 'required|int|min:1',
  1184. 'DayReward' => 'required|int|min:1',
  1185. ]);
  1186. if ($validator->fails()) {
  1187. return apiReturnFail($validator->errors()->first());
  1188. }
  1189. $monthCard->Price = $request->input('Price');
  1190. $monthCard->FirstReward = $request->input('FirstReward')*100;
  1191. $monthCard->DayReward = $request->input('DayReward')*100;
  1192. $monthCard->save();
  1193. return apiReturnSuc();
  1194. }
  1195. public function monthCardChannelEdit($id, Request $request)
  1196. {
  1197. $monthCard = MonthCard::findOrFail($id);
  1198. $gears = $monthCard->gear;
  1199. $channels = AdminConfig::where(['type' => 'pay'])->pluck('name', 'id');
  1200. $monthCardChannels = [];
  1201. foreach ($channels as $id => $name) {
  1202. $status = 0;
  1203. foreach ($gears as $v1) {
  1204. if ($v1['id'] == $id) {
  1205. $status = $v1['status'];
  1206. break;
  1207. }
  1208. }
  1209. $monthCardChannels[] = [
  1210. 'id' => $id,
  1211. 'name' => $name,
  1212. 'status' => $status
  1213. ];
  1214. }
  1215. return view('/admin/recharge/month_card_channel_edit', [
  1216. 'monthCard' => $monthCard,
  1217. 'monthCardChannels' => $monthCardChannels
  1218. ]);
  1219. }
  1220. public function monthCardSwitch($CardID)
  1221. {
  1222. $monthCard = MonthCard::findOrFail($CardID);
  1223. $monthCard->CardState = $monthCard->CardState ? 0 : 1;
  1224. $monthCard->save();
  1225. return apiReturnSuc();
  1226. }
  1227. public function monthCardChannelSwitch($CardID, $channel)
  1228. {
  1229. $monthCard = MonthCard::findOrFail($CardID);
  1230. $gears = $monthCard->gear;
  1231. if (in_array($channel, array_column($gears, 'id'))) {
  1232. $status = 0;
  1233. foreach ($gears as $k => $v) {
  1234. if ($v['id'] == $channel) {
  1235. $status = $v['status'] ? 0 : 1;
  1236. $v['status'] = $status;
  1237. $gears[$k] = $v;
  1238. break;
  1239. }
  1240. }
  1241. } else {
  1242. $status = 1;
  1243. $gears[] = [
  1244. 'id' => $channel,
  1245. 'status' => 1
  1246. ];
  1247. }
  1248. $monthCard->gear = json_encode($gears);
  1249. $monthCard->save();
  1250. return apiReturnSuc();
  1251. }
  1252. // 充值礼包配置列表
  1253. public function gift_list(Request $request)
  1254. {
  1255. try {
  1256. $list = DB::connection('write')->table('agent.dbo.recharge_gift')
  1257. ->orderBy('id', 'desc')
  1258. ->paginate(10);
  1259. foreach ($list as &$item) {
  1260. $item->day_rewards = $item->day_rewards ? json_decode($item->day_rewards, true) : null;
  1261. $item->betting_bonus = $item->betting_bonus ? json_decode($item->betting_bonus, true) : null;
  1262. $item->betting_task = $item->betting_task ? json_decode($item->betting_task, true) : null;
  1263. // task_bonus 是数字字段,保留两位小数
  1264. $item->task_bonus = $item->task_bonus !== null ? round((float)$item->task_bonus, 2) : null;
  1265. }
  1266. return view('admin.recharge.gift_list', compact('list'));
  1267. } catch (\Exception $e) {
  1268. \Log::error('充值礼包列表错误:' . $e->getMessage());
  1269. return apiReturnFail('数据库错误:' . $e->getMessage());
  1270. }
  1271. }
  1272. // 添加充值礼包
  1273. public function gift_add(Request $request)
  1274. {
  1275. \Log::info('gift_add method called', ['method' => $request->method()]);
  1276. if ($request->isMethod('post')) {
  1277. try {
  1278. // 获取最大ID
  1279. $maxId = DB::connection('write')->table('agent.dbo.recharge_gift')->max('id') ?: 0;
  1280. $data = [
  1281. 'id' => $maxId + 1,
  1282. 'bonus_instantly' => (int)$request->bonus_instantly ?: 0,
  1283. 'total_bonus' => (int)$request->total_bonus ?: 0,
  1284. 'first_pay' => (int)$request->first_pay ?: 0,
  1285. 'is_vip' => (int)$request->is_vip ?: 0,
  1286. 'valid_h' => (int)$request->valid_h ?: 0,
  1287. 'valid_h_2' => (int)$request->valid_h_2 ?: 0,
  1288. 'gift_id' => (int)$request->gift_id ?: 0,
  1289. 'gift_name' => $request->gift_name ?: '',
  1290. 'recommend' => round((float)$request->recommend ?: 0, 2),
  1291. ];
  1292. // 处理每日奖励
  1293. if ($request->has('day_rewards_enable') && $request->day_rewards_enable) {
  1294. $day_rewards = [
  1295. 'total_bonus' => (float)$request->day_rewards_total_bonus ?: 0,
  1296. 'bonus_day' => (int)$request->day_rewards_bonus_day ?: 0,
  1297. 'start_day' => (int)$request->day_rewards_start_day ?: 0,
  1298. 'bonus' => array_map('floatval', explode(',', $request->day_rewards_bonus ?: ''))
  1299. ];
  1300. $data['day_rewards'] = json_encode($day_rewards);
  1301. } else {
  1302. $data['day_rewards'] = '';
  1303. }
  1304. // 处理下注奖励
  1305. if ($request->has('betting_bonus_enable') && $request->betting_bonus_enable) {
  1306. $betting_bonus = [
  1307. 'total_bonus' => (float)$request->betting_bonus_total_bonus ?: 0,
  1308. 'per_bet' => (int)$request->betting_bonus_per_bet ?: 0,
  1309. 'per_bet_bonus' => (float)$request->betting_bonus_per_bet_bonus ?: 0
  1310. ];
  1311. $data['betting_bonus'] = json_encode($betting_bonus);
  1312. } else {
  1313. $data['betting_bonus'] = '';
  1314. }
  1315. // 处理下注任务
  1316. if ($request->has('betting_task_enable') && $request->betting_task_enable) {
  1317. $betting_task = [
  1318. 'total_bonus' => (float)$request->betting_task_total_bonus ?: 0,
  1319. 'bet_pay_times' => (int)$request->betting_task_bet_pay_times ?: 0
  1320. ];
  1321. $data['betting_task'] = json_encode($betting_task);
  1322. } else {
  1323. $data['betting_task'] = '';
  1324. }
  1325. // 处理每日任务奖励(数字字段,保留两位小数)
  1326. if ($request->has('task_bonus')) {
  1327. $data['task_bonus'] = round((float)$request->task_bonus ?: 0, 2);
  1328. } else {
  1329. $data['task_bonus'] = null;
  1330. }
  1331. DB::connection('write')->table('agent.dbo.recharge_gift')->insert($data);
  1332. return apiReturnSuc();
  1333. } catch (\Exception $e) {
  1334. \Log::error('添加充值礼包错误:' . $e->getMessage());
  1335. return apiReturnFail('添加失败:' . $e->getMessage());
  1336. }
  1337. }
  1338. \Log::info('Rendering gift_add view');
  1339. try {
  1340. // 测试简单视图
  1341. // return view('admin.recharge.gift_add_simple_test');
  1342. return view('admin.recharge.gift_add');
  1343. } catch (\Exception $e) {
  1344. \Log::error('gift_add view error: ' . $e->getMessage());
  1345. return response('View error: ' . $e->getMessage() . '<br><pre>' . $e->getTraceAsString() . '</pre>', 500);
  1346. }
  1347. }
  1348. // 修改充值礼包
  1349. public function gift_update(Request $request, $id)
  1350. {
  1351. if ($request->isMethod('post')) {
  1352. $data = [
  1353. 'bonus_instantly' => (int)$request->bonus_instantly ?: 0,
  1354. 'total_bonus' => (int)$request->total_bonus ?: 0,
  1355. 'first_pay' => (int)$request->first_pay ?: 0,
  1356. 'is_vip' => (int)$request->is_vip ?: 0,
  1357. 'valid_h' => (int)$request->valid_h ?: 0,
  1358. 'valid_h_2' => (int)$request->valid_h_2 ?: 0,
  1359. 'gift_id' => (int)$request->gift_id ?: 0,
  1360. 'gift_name' => $request->gift_name ?: '',
  1361. 'recommend' => round((float)$request->recommend ?: 0, 2),
  1362. ];
  1363. // 处理每日奖励
  1364. if ($request->has('day_rewards_enable') && $request->day_rewards_enable) {
  1365. $day_rewards = [
  1366. 'total_bonus' => (float)$request->day_rewards_total_bonus ?: 0,
  1367. 'bonus_day' => (int)$request->day_rewards_bonus_day ?: 0,
  1368. 'start_day' => (int)$request->day_rewards_start_day ?: 0,
  1369. 'bonus' => array_map('floatval', explode(',', $request->day_rewards_bonus ?: ''))
  1370. ];
  1371. $data['day_rewards'] = json_encode($day_rewards);
  1372. } else {
  1373. $data['day_rewards'] = '';
  1374. }
  1375. // 处理下注奖励
  1376. if ($request->has('betting_bonus_enable') && $request->betting_bonus_enable) {
  1377. $betting_bonus = [
  1378. 'total_bonus' => (float)$request->betting_bonus_total_bonus ?: 0,
  1379. 'per_bet' => (int)$request->betting_bonus_per_bet ?: 0,
  1380. 'per_bet_bonus' => (float)$request->betting_bonus_per_bet_bonus ?: 0
  1381. ];
  1382. $data['betting_bonus'] = json_encode($betting_bonus);
  1383. } else {
  1384. $data['betting_bonus'] = '';
  1385. }
  1386. // 处理下注任务
  1387. if ($request->has('betting_task_enable') && $request->betting_task_enable) {
  1388. $betting_task = [
  1389. 'total_bonus' => (float)$request->betting_task_total_bonus ?: 0,
  1390. 'bet_pay_times' => (int)$request->betting_task_bet_pay_times ?: 0
  1391. ];
  1392. $data['betting_task'] = json_encode($betting_task);
  1393. } else {
  1394. $data['betting_task'] = '';
  1395. }
  1396. // 处理每日任务奖励(数字字段,保留两位小数)
  1397. if ($request->has('task_bonus')) {
  1398. $data['task_bonus'] = round((float)$request->task_bonus ?: 0, 2);
  1399. } else {
  1400. $data['task_bonus'] = null;
  1401. }
  1402. DB::connection('write')->table('agent.dbo.recharge_gift')->where('id', $id)->update($data);
  1403. return apiReturnSuc();
  1404. }
  1405. $info = DB::connection('write')->table('agent.dbo.recharge_gift')->where('id', $id)->first();
  1406. $info->day_rewards = $info->day_rewards ? json_decode($info->day_rewards, true) : null;
  1407. $info->betting_bonus = $info->betting_bonus ? json_decode($info->betting_bonus, true) : null;
  1408. $info->betting_task = $info->betting_task ? json_decode($info->betting_task, true) : null;
  1409. // task_bonus 是数字字段,保留两位小数
  1410. $info->task_bonus = $info->task_bonus !== null ? round((float)$info->task_bonus, 2) : null;
  1411. return view('admin.recharge.gift_update', compact('info'));
  1412. }
  1413. // 删除充值礼包
  1414. public function gift_delete($id)
  1415. {
  1416. DB::connection('write')->table('agent.dbo.recharge_gift')->where('id', $id)->delete();
  1417. return apiReturnSuc();
  1418. }
  1419. }