RechargeController.php 55 KB

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