2
0

RechargeController.php 59 KB

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