RechargeController.php 68 KB

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