2
0

RechargeController.php 61 KB

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