RechargeController.php 62 KB

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