RechargeController.php 55 KB

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