RechargeController.php 55 KB

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