2
0

RechargeController.php 61 KB

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