RechargeController.php 66 KB

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