RechargeController.php 55 KB

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