RechargeController.php 61 KB

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