RechargeController.php 69 KB

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