2
0

RechargeController.php 56 KB

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