RechargeController.php 72 KB

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