RechargeController.php 64 KB

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