RechargeController.php 56 KB

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