RechargeController.php 62 KB

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