RechargeController.php 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154
  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. return view('admin.recharge.gear_list', $res);
  702. }
  703. public function channel_switch(Request $request, $id)
  704. {
  705. $type = $request->type;
  706. $logic = new RechargeLogic();
  707. $res = $logic->channel_switch($id, $type);
  708. if ($res === false) {
  709. return apiReturnFail($logic->getError());
  710. }
  711. return apiReturnSuc();
  712. }
  713. // 添加
  714. public function add(Request $request)
  715. {
  716. $list = DB::table('agent.dbo.admin_configs')->where('type', 'pay')->pluck('name', 'id');
  717. if ($request->method() == 'POST') {
  718. $money = (int)$request->money ?: '';
  719. $status = $request->status;
  720. $config_ids = $request->config_ids;
  721. $favorable_price = (int)$request->favorable_price;
  722. $give = (int)$request->give;
  723. $logic = new RechargeLogic();
  724. $res = $logic->add($money, $status, $config_ids, $favorable_price, $give);
  725. return apiReturnSuc();
  726. }
  727. return view('admin.recharge.add', ['list' => $list]);
  728. }
  729. public function update_config(Request $request, $id)
  730. {
  731. if ($request->isMethod('post')) {
  732. $money = (int)$request->money ?: '';
  733. $favorable_price = (int)$request->favorable_price;
  734. $give = (int)$request->give;
  735. $second_give = (int)$request->second_give;
  736. $data = [
  737. 'money' => $money,
  738. 'favorable_price' => $favorable_price,
  739. 'second_give' => $second_give,
  740. 'give' => $give
  741. ];
  742. DB::table('agent.dbo.recharge_gear')->where('id', $id)->update($data);
  743. return apiReturnSuc();
  744. } else {
  745. $info = DB::table('agent.dbo.recharge_gear')->where('id', $id)->first();
  746. return view('admin.recharge.update_config', ['info' => $info]);
  747. }
  748. }
  749. // 加载修改页面
  750. public function update(Request $request, $id)
  751. {
  752. $info = (new RechargeLogic())->update($id);
  753. return view('admin.recharge.update', $info);
  754. }
  755. // 修改里面的开关
  756. public function gear_switch(Request $request, $id)
  757. {
  758. $config_id = $request->config_id ?: '';
  759. $type = $request->type ?: '';
  760. $logic = new RechargeLogic();
  761. $res = $logic->gear_switch($id, $config_id, $type);
  762. if ($res === false) {
  763. return apiReturnFail($logic->getError());
  764. }
  765. ClearCache::dispatch();
  766. return apiReturnSuc();
  767. }
  768. // 修改排序
  769. public function update_sort(Request $request, $id)
  770. {
  771. $sort = $request->sort ?: 0;
  772. DB::connection('write')->table('agent.dbo.admin_configs')
  773. ->where('id', $id)
  774. ->update(['sort' => $sort]);
  775. ClearCache::dispatch();
  776. return apiReturnSuc();
  777. }
  778. // 添加备注
  779. public function remarks(Request $request, $id)
  780. {
  781. $remarks = $request->remark ?: '';
  782. DB::connection('write')->table('agent.dbo.admin_configs')
  783. ->where('id', $id)
  784. ->update(['remarks' => $remarks]);
  785. return apiReturnSuc();
  786. }
  787. // 首冲10元礼包--修改渠道
  788. public function firstCharge(Request $request)
  789. {
  790. $StatusValue = $request->StatusValue ?: '';
  791. DB::connection('write')->table('QPAccountsDB.dbo.SystemStatusInfo')
  792. ->where('StatusName', 'FirstChargeGiftBag')
  793. ->update(['StatusValue' => $StatusValue]);
  794. return apiReturnSuc();
  795. }
  796. // 首冲10元礼包 -- 修改状态
  797. public function firstChargeStatus(Request $request)
  798. {
  799. $StatusValue = $request->StatusValue ?: '';
  800. DB::connection('write')->table('QPAccountsDB.dbo.SystemStatusInfo')
  801. ->where('StatusName', 'FirstChargeGiftBagStatus')
  802. ->update(['StatusValue' => $StatusValue]);
  803. return apiReturnSuc();
  804. }
  805. // IP回调白名单
  806. public function ip_white(Request $request)
  807. {
  808. $list = DB::connection('write')->table('agent.dbo.admin_configs as ac')
  809. ->leftJoin('agent.dbo.recharge_ip as ri', 'ac.id', '=', 'ri.config_id')
  810. ->leftJoin('agent.dbo.admin_users as au', 'ri.admin_id', 'au.id')
  811. ->where('ac.status', 1)
  812. ->select('ac.id', 'ac.name', 'ac.config_value', 'ip', 'account', 'last_time', 'ac.status', 'ri.remarks')
  813. ->paginate(5);
  814. return view('admin.recharge.ip_white', compact('list'));
  815. }
  816. public function ip_white_update(Request $request, $id)
  817. {
  818. if ($request->isMethod('post')) {
  819. $post = $request->post();
  820. if (empty($post['ip'])) {
  821. return apiReturnFail('IP白名单不能为空');
  822. }
  823. $ip = explode(',', $post['ip']);
  824. foreach ($ip as $val) {
  825. if (!filter_var($val, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
  826. return apiReturnFail('ip不合法');
  827. }
  828. }
  829. $post['last_time'] = date('Y-m-d H:i:s');
  830. $post['admin_id'] = session('admin')->id;
  831. DB::connection('write')->table('agent.dbo.recharge_ip')
  832. ->updateOrInsert(['config_id' => $id], $post);
  833. return apiReturnSuc();
  834. }
  835. $info = DB::connection('write')->table('agent.dbo.admin_configs as ac')
  836. ->leftJoin('agent.dbo.recharge_ip as ri', 'ac.id', '=', 'ri.config_id')
  837. ->where('ac.id', $id)
  838. ->select('ac.id', 'ac.name', 'ac.config_value', 'ip', 'ri.remarks')
  839. ->first();
  840. return view('admin.recharge.ip_white_update', compact('info'));
  841. }
  842. // 充值推荐档位
  843. public function recomendar_recharge(Request $request)
  844. {
  845. $StatusValue = $request->StatusValue ?: '';
  846. DB::connection('write')->table('QPAccountsDB.dbo.SystemStatusInfo')
  847. ->where('StatusName', 'RecomendarRecharge')
  848. ->update(['StatusValue' => $StatusValue]);
  849. return apiReturnSuc();
  850. }
  851. // 修改图片地址
  852. public function updatePic(Request $request, $id)
  853. {
  854. $picList = config('games.recharge_pic_config');
  855. if ($request->isMethod('post')) {
  856. $pic_number = $request->post('pic_number');
  857. if ($pic_number < 0) {
  858. return apiReturnFail('请选择图片!');
  859. }
  860. $pic_url = config('games.recharge_pic.recharge_pic_url');
  861. $recharge_pic_url = str_replace('{num}', $picList[$pic_number], $pic_url);
  862. DB::table(TableName::agent() . 'admin_configs')
  863. ->where('id', $id)
  864. ->update(['config_value' => $recharge_pic_url, 'pic_num' => $pic_number]);
  865. return apiReturnSuc();
  866. }
  867. return view('admin.recharge.update_pic', compact('id', 'picList'));
  868. }
  869. // 轮询开关
  870. public function poll(Request $request)
  871. {
  872. $StatusValue = $request->StatusValue ?: '';
  873. DB::connection('write')->table('QPAccountsDB.dbo.SystemStatusInfo')
  874. ->where('StatusName', 'PollSwitch')
  875. ->update(['StatusValue' => $StatusValue]);
  876. return apiReturnSuc();
  877. }
  878. // 充值礼包
  879. public function gift()
  880. {
  881. $res = (new RechargeLogic())->gift();
  882. return view('admin.recharge.gift', $res);
  883. }
  884. public function clearCache()
  885. {
  886. ClearCache::dispatch();
  887. return apiReturnSuc();
  888. }
  889. public function monthCardEdit($id, Request $request) {
  890. $monthCard = MonthCard::findOrFail($id);
  891. if ($request->method() == 'GET') {
  892. return view('admin.recharge.month_card_edit', [
  893. 'monthCard' => $monthCard,
  894. ]);
  895. }
  896. $validator = Validator::make($request->all(), [
  897. 'Price' => 'required|min:1',
  898. 'FirstReward' => 'required|int|min:1',
  899. 'DayReward' => 'required|int|min:1',
  900. ]);
  901. if ($validator->fails()) {
  902. return apiReturnFail($validator->errors()->first());
  903. }
  904. $monthCard->Price = $request->input('Price');
  905. $monthCard->FirstReward = $request->input('FirstReward')*100;
  906. $monthCard->DayReward = $request->input('DayReward')*100;
  907. $monthCard->save();
  908. return apiReturnSuc();
  909. }
  910. public function monthCardChannelEdit($id, Request $request)
  911. {
  912. $monthCard = MonthCard::findOrFail($id);
  913. $gears = $monthCard->gear;
  914. $channels = AdminConfig::where(['type' => 'pay'])->pluck('name', 'id');
  915. $monthCardChannels = [];
  916. foreach ($channels as $id => $name) {
  917. $status = 0;
  918. foreach ($gears as $v1) {
  919. if ($v1['id'] == $id) {
  920. $status = $v1['status'];
  921. break;
  922. }
  923. }
  924. $monthCardChannels[] = [
  925. 'id' => $id,
  926. 'name' => $name,
  927. 'status' => $status
  928. ];
  929. }
  930. return view('/admin/recharge/month_card_channel_edit', [
  931. 'monthCard' => $monthCard,
  932. 'monthCardChannels' => $monthCardChannels
  933. ]);
  934. }
  935. public function monthCardSwitch($CardID)
  936. {
  937. $monthCard = MonthCard::findOrFail($CardID);
  938. $monthCard->CardState = $monthCard->CardState ? 0 : 1;
  939. $monthCard->save();
  940. return apiReturnSuc();
  941. }
  942. public function monthCardChannelSwitch($CardID, $channel)
  943. {
  944. $monthCard = MonthCard::findOrFail($CardID);
  945. $gears = $monthCard->gear;
  946. if (in_array($channel, array_column($gears, 'id'))) {
  947. $status = 0;
  948. foreach ($gears as $k => $v) {
  949. if ($v['id'] == $channel) {
  950. $status = $v['status'] ? 0 : 1;
  951. $v['status'] = $status;
  952. $gears[$k] = $v;
  953. break;
  954. }
  955. }
  956. } else {
  957. $status = 1;
  958. $gears[] = [
  959. 'id' => $channel,
  960. 'status' => 1
  961. ];
  962. }
  963. $monthCard->gear = json_encode($gears);
  964. $monthCard->save();
  965. return apiReturnSuc();
  966. }
  967. }