RechargeController.php 53 KB

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