RechargeController.php 67 KB

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