RechargeController.php 61 KB

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