RechargeController.php 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737
  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') . '(今日-' . $i . '天)';
  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. // 从 admin_configs 取所有支付渠道(type=pay),config_key 即为 payment_code
  704. $paymentCodes = DB::connection('write')
  705. ->table(DB::raw('agent.dbo.admin_configs WITH (NOLOCK)'))
  706. ->where('type', 'pay')
  707. ->where('config_key', '<>', '')
  708. ->pluck('config_key')
  709. ->unique()
  710. ->values()
  711. ->toArray();
  712. // 将订单数据按 [payment_code][order_title] 索引
  713. $dataIndex = [];
  714. foreach ($rows as $row) {
  715. $code = $row->payment_code;
  716. $title = (int)$row->order_title;
  717. $dataIndex[$code][$title] = $row;
  718. }
  719. $list = [];
  720. foreach ($paymentCodes as $code) {
  721. foreach ($payMethodsMap as $title => $name) {
  722. $row = $dataIndex[$code][$title] ?? null;
  723. $channelName = $code . ' ' . $name;
  724. $days = [];
  725. for ($i = 0; $i < 4; $i++) {
  726. if ($row) {
  727. $total = (int)$row->{'d' . $i . '_total'};
  728. $success = (int)$row->{'d' . $i . '_success'};
  729. } else {
  730. $total = 0;
  731. $success = 0;
  732. }
  733. $rate = $total > 0 ? round($success / $total * 100, 1) : 0;
  734. $days[] = [
  735. 'total' => $total,
  736. 'success' => $success,
  737. 'rate' => $rate,
  738. ];
  739. }
  740. $list[] = [
  741. 'payment_code' => $code,
  742. 'order_title' => $title,
  743. 'channel_name' => $channelName,
  744. 'days' => $days,
  745. ];
  746. }
  747. }
  748. return view('admin.recharge.pay_channel_rate', [
  749. 'list' => $list,
  750. 'dateLabels' => $dateLabels,
  751. 'dates' => $dates,
  752. ]);
  753. }
  754. // 补单
  755. public function supplement(Request $request, $id)
  756. {
  757. try {
  758. if ($request->method() == 'POST') {
  759. $admin_id = $request->session()->get('admin')->id;
  760. $order = DB::table('agent.dbo.order')->where('id', $id)->first();
  761. if (!$order) {
  762. return apiReturnFail('订单不存在!');
  763. }
  764. if ((int)$order->pay_status === 1) {
  765. return apiReturnFail('订单已完成!');
  766. }
  767. // 退款订单禁止补单
  768. if ((int)$order->pay_status === 9) {
  769. return apiReturnFail('退款订单不可补单');
  770. }
  771. $payAmt = $order->amount / NumConfig::NUM_VALUE;
  772. $order_sn = $order->order_sn;
  773. Log::info('补单单号:' . $order_sn);
  774. // 成功处理回调
  775. $GiftsID = $order->GiftsID ?: '';
  776. $userID = $order->user_id ?: '';
  777. //$res = (new OrderService())->paySuccess($GiftsID, $userID, $payAmt, $order_sn);
  778. // 获取金额
  779. $service = new OrderServices();
  780. $recharge_gear = DB::connection('write')->table('agent.dbo.recharge_gear')->where('first_pay', 0)->where('money', $payAmt)->select('favorable_price', 'give')->first();
  781. if($recharge_gear || $GiftsID){
  782. [$give, $favorable_price, $Recharge, $czReason, $cjReason] = $service->getPayInfo($GiftsID, $userID, $payAmt);
  783. }else{
  784. $Recharge = $payAmt;
  785. $give = 0;
  786. $favorable_price = $Recharge + $give;
  787. $czReason = 1;
  788. $cjReason = 45;
  789. }
  790. // [$give, $favorable_price, $Recharge, $czReason, $cjReason] = $service->getPayInfo($GiftsID, $userID, $payAmt);
  791. // 增加充值记录
  792. [$Score] = $service->addRecord($userID, $payAmt, $favorable_price, $order_sn, $GiftsID, $Recharge, $czReason, $give, $cjReason, $order->AdId, $order->eventType);
  793. // 成功处理回调
  794. \App\Jobs\Order::dispatch([$userID, $payAmt, $Score, $favorable_price, $GiftsID, $order_sn]);
  795. // 修改订单状态
  796. $data = [
  797. 'pay_status' => 1,
  798. 'finished_at' => date('Y-m-d H:i:s'),
  799. 'updated_at' => date('Y-m-d H:i:s'),
  800. 'pay_at' => date('Y-m-d H:i:s')
  801. ];
  802. $order_up = DB::table('agent.dbo.order')->where('id', $id)->update($data);
  803. // 添加操作记录
  804. (new AccountsRecordLogic())->create_record($id, $order->pay_status, 1, '', $admin_id, 2);
  805. if ($order_up === false) {
  806. return apiReturnFail('补单失败');
  807. }
  808. return apiReturnSuc();
  809. }
  810. } catch (\Exception $exception) {
  811. return apiReturnFail($exception->getMessage());
  812. }
  813. }
  814. // 标记订单为退款状态
  815. public function refund(Request $request, $id)
  816. {
  817. try {
  818. $admin = $request->session()->get('admin');
  819. $roleId = $admin->roles[0]->id ?? 0;
  820. // 仅管理员角色允许操作(与补单权限保持一致)
  821. if (!in_array($roleId, [1, 12])) {
  822. return apiReturnFail('无权限执行该操作');
  823. }
  824. $order = DB::connection('write')->table('agent.dbo.order')->where('id', $id)->lockForUpdate()->first();
  825. if (!$order) {
  826. return apiReturnFail('订单不存在!');
  827. }
  828. if ($order->pay_status == 9) {
  829. return apiReturnFail('订单已为退款状态');
  830. }
  831. if ($order->pay_status != 1) {
  832. return apiReturnFail('仅已到账订单可设置为退款状态');
  833. }
  834. $now = date('Y-m-d H:i:s');
  835. $updated = DB::connection('write')->table('agent.dbo.order')
  836. ->where('id', $id)
  837. ->update([
  838. 'pay_status' => 9,
  839. 'refund_fee' => ($order->payment_code=='AiNewPay' && $order->order_title==2)?800:3000,
  840. 'updated_at' => $now,
  841. ]);
  842. if ($updated === false) {
  843. return apiReturnFail('设置退款状态失败');
  844. }
  845. $fee = ($order->payment_code=='AiNewPay' && $order->order_title==2)?800:3000;
  846. (new RechargeWithDraw())->refund($order->user_id, $order->amount, $fee);
  847. $admin_id = $admin->id;
  848. (new AccountsRecordLogic())->create_record($id, $order->pay_status, 9, '', $admin_id, 2);
  849. return apiReturnSuc();
  850. } catch (\Exception $exception) {
  851. return apiReturnFail($exception->getMessage());
  852. }
  853. }
  854. /**
  855. * 模拟上报 FB 支付事件(仅管理员可用)
  856. */
  857. public function fbReportMock(Request $request, $id)
  858. {
  859. try {
  860. $admin = $request->session()->get('admin');
  861. $roleId = $admin->roles[0]->id ?? 0;
  862. if (!in_array($roleId, [1, 12])) {
  863. return apiReturnFail('无权限执行该操作');
  864. }
  865. $order = DB::connection('write')->table('agent.dbo.order')->where('id', $id)->first();
  866. if (!$order) {
  867. return apiReturnFail('订单不存在!');
  868. }
  869. // 退款订单不允许模拟上报
  870. if ((int)$order->pay_status === 9) {
  871. return apiReturnFail('退款订单不可模拟上报');
  872. }
  873. // 只允许对未成功的订单做模拟上报(已到账的默认认为已正常上报)
  874. if ((int)$order->pay_status === 1) {
  875. return apiReturnFail('仅对未成功订单开放模拟上报');
  876. }
  877. $userId = $order->user_id;
  878. $payAmt = $order->amount; // 内部金额单位,保持与原上报一致
  879. // 构造模拟上报的 params
  880. $item = [
  881. 'regtime' => time(), // 当前时间
  882. 'isd0' => 1, // 固定为首日
  883. 'first' => 1, // 固定视为首充
  884. 'golds' => $payAmt, // 金额
  885. 'udis' => $userId, // 注意:按需求使用 udis 字段
  886. 'order_sn'=> $order->order_sn,
  887. ];
  888. // 通过 OuroGameService 模拟一次 pay_finish 上报
  889. OuroGameService::notifyWebHall(
  890. $userId,
  891. '',
  892. 'pay_finish',
  893. [
  894. 'Golds' => $payAmt,
  895. 'PayNum'=> $payAmt,
  896. 'event' => 'pay',
  897. 'params'=> $item,
  898. ]
  899. );
  900. return apiReturnSuc();
  901. } catch (\Exception $exception) {
  902. Log::error('模拟 FB 上报失败:' . $exception->getMessage(), [
  903. 'order_id' => $id,
  904. ]);
  905. return apiReturnFail('上报失败,请稍后重试');
  906. }
  907. }
  908. public function search($orderId)
  909. {
  910. $order = DB::table('agent.dbo.order')->where('id', $orderId)->first();
  911. if (!$order) {
  912. return apiReturnFail('未查询到订单信息');
  913. }
  914. $agent = $order->payment_code;
  915. $service = PayMentService::pay_logic($agent);
  916. $res = $service->pay_search($order->order_sn);
  917. if($res){
  918. return apiReturnSuc([],'','订单支付成功');
  919. }else{
  920. return apiReturnFail('订单未成功');
  921. }
  922. }
  923. // 充值渠道修改
  924. public function config($method, Request $request)
  925. {
  926. if ($request->method() == 'GET') {
  927. $res = (new RechargeLogic())->config($method);
  928. return view('admin.recharge.config', $res);
  929. }
  930. $validator = Validator::make($request->all(), [
  931. 'config.*.sort' => 'required|int',
  932. 'config.*.status' => 'required|in:1,-1',
  933. 'config.*.weight.1' => 'nullable|int|min:0|max:100000',
  934. 'config.*.weight.2' => 'nullable|int|min:0|max:100000',
  935. 'config.*.weight.4' => 'nullable|int|min:0|max:100000',
  936. 'config.*.weight.8' => 'nullable|int|min:0|max:100000',
  937. ]);
  938. if ($validator->fails()) {
  939. return apiReturnFail($validator->errors()->first());
  940. }
  941. $config = $request->input('config');
  942. $opened = array_filter($config, function ($item) {
  943. return $item['status'] == 1;
  944. });
  945. if (array_sum(array_column($opened, 'sort')) != 100) {
  946. return apiReturnFail('权重值分配不正确');
  947. }
  948. foreach ($config as $id => $v) {
  949. $weightInput = $v['weight'] ?? null;
  950. // 防御性处理:避免后续误把 weight 数组直接参与 update
  951. unset($v['weight']);
  952. $remarksRaw = DB::table('agent.dbo.admin_configs')->where('id', $id)->value('remarks');
  953. $remarks = [];
  954. if (!empty($remarksRaw)) {
  955. $decoded = \GuzzleHttp\json_decode($remarksRaw, true);
  956. if (is_array($decoded)) {
  957. $remarks = $decoded;
  958. }
  959. }
  960. if (is_array($weightInput)) {
  961. $existingWeights = $remarks['weight'] ?? ($remarks['weights'] ?? []);
  962. if (!is_array($existingWeights)) {
  963. $existingWeights = [];
  964. }
  965. $methodWeights = $existingWeights;
  966. foreach ([1, 2, 4, 8] as $methodKey) {
  967. if (array_key_exists($methodKey, $weightInput)) {
  968. $weightKey = 'type_' . $methodKey;
  969. if ($weightInput[$methodKey] === '' || $weightInput[$methodKey] === null) {
  970. $methodWeights[$weightKey] = 0;
  971. } else {
  972. $methodWeights[$weightKey] = (int)$weightInput[$methodKey];
  973. }
  974. }
  975. }
  976. $remarks['weight'] = $methodWeights;
  977. }
  978. $updateData = [
  979. 'sort' => (int)$v['sort'],
  980. 'status' => (int)$v['status'],
  981. 'admin_id' => session('admin')['id'],
  982. 'updated_at' => date('Y-m-d H:i:s'),
  983. 'remarks' => \GuzzleHttp\json_encode($remarks, JSON_UNESCAPED_UNICODE),
  984. ];
  985. if ((int)$v['status'] === -1) {
  986. $updateData['sort'] = 0;
  987. }
  988. DB::table('agent.dbo.admin_configs')->where('id', $id)->update($updateData);
  989. if ((int)$v['status'] === -1) {
  990. DB::table('QPPlatformDB.dbo.ChannelOpenRecharge')->where('ConfigID', $id)
  991. ->update([
  992. 'sort' => 0,
  993. 'status' => 2
  994. ]);
  995. }
  996. }
  997. return apiReturnSuc();
  998. }
  999. public function methods()
  1000. {
  1001. $methods = DB::table(DB::raw('agent.dbo.admin_configs WITH (NOLOCK)'))
  1002. ->leftJoin(DB::raw('agent.dbo.admin_users as u WITH (NOLOCK)'), 'admin_configs.admin_id', '=', 'u.id')
  1003. ->select('admin_configs.*', 'u.account')
  1004. ->where('admin_configs.type', 'pay_method')
  1005. ->get();
  1006. return view('admin.recharge.methods', [
  1007. 'methods' => $methods,
  1008. ]);
  1009. }
  1010. // 充值渠道修改 开关
  1011. public function switch_control(Request $request, $id)
  1012. {
  1013. $type = $request->type;
  1014. $admin_id = $request->session()->get('admin')->id;
  1015. $logic = new RechargeLogic();
  1016. $res = $logic->switch_control($id, $type, $admin_id);
  1017. if ($res === false) {
  1018. return apiReturnFail($logic->getError());
  1019. }
  1020. ClearCache::dispatch();
  1021. return apiReturnSuc();
  1022. }
  1023. // 充值档位修改
  1024. public function gear_list()
  1025. {
  1026. $res = (new RechargeLogic())->gear_list();
  1027. // dd($res);
  1028. return view('admin.recharge.gear_list', $res);
  1029. }
  1030. public function channel_switch(Request $request, $id)
  1031. {
  1032. $type = $request->type;
  1033. $logic = new RechargeLogic();
  1034. $res = $logic->channel_switch($id, $type);
  1035. if ($res === false) {
  1036. return apiReturnFail($logic->getError());
  1037. }
  1038. return apiReturnSuc();
  1039. }
  1040. // 添加
  1041. public function add(Request $request)
  1042. {
  1043. $list = DB::table('agent.dbo.admin_configs')->where('type', 'pay')->pluck('name', 'id');
  1044. if ($request->method() == 'POST') {
  1045. $money = (float)$request->money ?: '';
  1046. $status = $request->status;
  1047. // $config_ids = $request->config_ids;
  1048. $favorable_price = (float)$request->favorable_price;
  1049. $give = (float)$request->give;
  1050. $pay_methods = (int)$request->pay_methods ?: 0; // 支付方式位掩码
  1051. $in_shop = (int)$request->input('in_shop', 1); // 是否在商城展示
  1052. $logic = new RechargeLogic();
  1053. $res = $logic->add($money, $status, '', $favorable_price, $give, $pay_methods, $in_shop);
  1054. return apiReturnSuc();
  1055. }
  1056. return view('admin.recharge.add', ['list' => $list]);
  1057. }
  1058. public function update_config(Request $request, $id)
  1059. {
  1060. if ($request->isMethod('post')) {
  1061. $money = (float)($request->money ?: '');
  1062. $favorable_price = (float)($request->favorable_price ?: 0);
  1063. $give = (float)($request->give ?: 0);
  1064. $second_give = (int)($request->second_give ?: 0);
  1065. $pay_methods = (int)($request->pay_methods ?: 0); // 支付方式位掩码
  1066. $in_shop = (int)$request->input('in_shop', 1); // 是否在商城展示
  1067. // 构建支付方式数组
  1068. $gearData = [];
  1069. $payMethodsMap = config('payment.methods');
  1070. foreach ($payMethodsMap as $value => $item) {
  1071. if ($pay_methods & $value) {
  1072. $gearData[] = [
  1073. 'name' => $item['key'],
  1074. 'value' => $value,
  1075. 'status' => 1
  1076. ];
  1077. }
  1078. }
  1079. $data = [
  1080. 'money' => $money,
  1081. 'favorable_price' => $favorable_price,
  1082. 'second_give' => $second_give,
  1083. 'give' => $give,
  1084. 'in_shop' => $in_shop,
  1085. 'gear' => \GuzzleHttp\json_encode($gearData) // 存储到gear字段
  1086. ];
  1087. DB::table('agent.dbo.recharge_gear')->where('id', $id)->update($data);
  1088. return apiReturnSuc();
  1089. } else {
  1090. $info = DB::table('agent.dbo.recharge_gear')->where('id', $id)->first();
  1091. // 解析gear字段,计算pay_methods用于回显
  1092. $pay_methods = 0;
  1093. if (!empty($info->gear)) {
  1094. $gear = \GuzzleHttp\json_decode($info->gear, true);
  1095. if (is_array($gear)) {
  1096. foreach ($gear as $item) {
  1097. if (isset($item['value']) && ($item['status'] ?? 0) == 1) {
  1098. $pay_methods += $item['value'];
  1099. }
  1100. }
  1101. }
  1102. }
  1103. $info->pay_methods = $pay_methods;
  1104. return view('admin.recharge.update_config', ['info' => $info]);
  1105. }
  1106. }
  1107. // 加载修改页面
  1108. public function update(Request $request, $id)
  1109. {
  1110. $info = (new RechargeLogic())->update($id);
  1111. return view('admin.recharge.update', $info);
  1112. }
  1113. // 修改里面的开关
  1114. public function gear_switch(Request $request, $id)
  1115. {
  1116. $config_id = $request->config_id ?: '';
  1117. $type = $request->type ?: '';
  1118. $logic = new RechargeLogic();
  1119. $res = $logic->gear_switch($id, $config_id, $type);
  1120. if ($res === false) {
  1121. return apiReturnFail($logic->getError());
  1122. }
  1123. ClearCache::dispatch();
  1124. return apiReturnSuc();
  1125. }
  1126. // 修改排序
  1127. public function update_sort(Request $request, $id)
  1128. {
  1129. $sort = $request->sort ?: 0;
  1130. DB::connection('write')->table('agent.dbo.admin_configs')
  1131. ->where('id', $id)
  1132. ->update(['sort' => $sort]);
  1133. ClearCache::dispatch();
  1134. return apiReturnSuc();
  1135. }
  1136. // 添加备注
  1137. public function remarks(Request $request, $id)
  1138. {
  1139. $remarks = $request->remark ?: '';
  1140. DB::connection('write')->table('agent.dbo.admin_configs')
  1141. ->where('id', $id)
  1142. ->update(['remarks' => $remarks]);
  1143. return apiReturnSuc();
  1144. }
  1145. // 首冲10元礼包--修改渠道
  1146. public function firstCharge(Request $request)
  1147. {
  1148. $StatusValue = $request->StatusValue ?: '';
  1149. DB::connection('write')->table('QPAccountsDB.dbo.SystemStatusInfo')
  1150. ->where('StatusName', 'FirstChargeGiftBag')
  1151. ->update(['StatusValue' => $StatusValue]);
  1152. return apiReturnSuc();
  1153. }
  1154. // 首冲10元礼包 -- 修改状态
  1155. public function firstChargeStatus(Request $request)
  1156. {
  1157. $StatusValue = $request->StatusValue ?: '';
  1158. DB::connection('write')->table('QPAccountsDB.dbo.SystemStatusInfo')
  1159. ->where('StatusName', 'FirstChargeGiftBagStatus')
  1160. ->update(['StatusValue' => $StatusValue]);
  1161. return apiReturnSuc();
  1162. }
  1163. // IP回调白名单
  1164. public function ip_white(Request $request)
  1165. {
  1166. $list = DB::connection('write')->table(DB::raw('agent.dbo.admin_configs as ac WITH (NOLOCK)'))
  1167. ->leftJoin(DB::raw('agent.dbo.recharge_ip as ri WITH (NOLOCK)'), 'ac.id', '=', 'ri.config_id')
  1168. ->leftJoin(DB::raw('agent.dbo.admin_users as au WITH (NOLOCK)'), 'ri.admin_id', 'au.id')
  1169. ->where('ac.status', 1)
  1170. ->select('ac.id', 'ac.name', 'ac.config_value', 'ip', 'account', 'last_time', 'ac.status', 'ri.remarks')
  1171. ->paginate(5);
  1172. return view('admin.recharge.ip_white', compact('list'));
  1173. }
  1174. public function ip_white_update(Request $request, $id)
  1175. {
  1176. if ($request->isMethod('post')) {
  1177. $post = $request->post();
  1178. if (empty($post['ip'])) {
  1179. return apiReturnFail('IP白名单不能为空');
  1180. }
  1181. $ip = explode(',', $post['ip']);
  1182. foreach ($ip as $val) {
  1183. if (!filter_var($val, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
  1184. return apiReturnFail('ip不合法');
  1185. }
  1186. }
  1187. $post['last_time'] = date('Y-m-d H:i:s');
  1188. $post['admin_id'] = session('admin')->id;
  1189. DB::connection('write')->table('agent.dbo.recharge_ip')
  1190. ->updateOrInsert(['config_id' => $id], $post);
  1191. return apiReturnSuc();
  1192. }
  1193. $info = DB::connection('write')->table('agent.dbo.admin_configs as ac')
  1194. ->leftJoin('agent.dbo.recharge_ip as ri', 'ac.id', '=', 'ri.config_id')
  1195. ->where('ac.id', $id)
  1196. ->select('ac.id', 'ac.name', 'ac.config_value', 'ip', 'ri.remarks')
  1197. ->first();
  1198. return view('admin.recharge.ip_white_update', compact('info'));
  1199. }
  1200. // 充值推荐档位
  1201. public function recomendar_recharge(Request $request)
  1202. {
  1203. $StatusValue = $request->StatusValue ?: '';
  1204. DB::connection('write')->table('QPAccountsDB.dbo.SystemStatusInfo')
  1205. ->where('StatusName', 'RecomendarRecharge')
  1206. ->update(['StatusValue' => $StatusValue]);
  1207. return apiReturnSuc();
  1208. }
  1209. // 修改图片地址
  1210. public function updatePic(Request $request, $id)
  1211. {
  1212. $picList = config('games.recharge_pic_config');
  1213. if ($request->isMethod('post')) {
  1214. $pic_number = $request->post('pic_number');
  1215. if ($pic_number < 0) {
  1216. return apiReturnFail('请选择图片!');
  1217. }
  1218. $pic_url = config('games.recharge_pic.recharge_pic_url');
  1219. $recharge_pic_url = str_replace('{num}', $picList[$pic_number], $pic_url);
  1220. DB::table(TableName::agent() . 'admin_configs')
  1221. ->where('id', $id)
  1222. ->update(['config_value' => $recharge_pic_url, 'pic_num' => $pic_number]);
  1223. return apiReturnSuc();
  1224. }
  1225. return view('admin.recharge.update_pic', compact('id', 'picList'));
  1226. }
  1227. // 轮询开关
  1228. public function poll(Request $request)
  1229. {
  1230. $StatusValue = $request->StatusValue ?: '';
  1231. DB::connection('write')->table('QPAccountsDB.dbo.SystemStatusInfo')
  1232. ->where('StatusName', 'PollSwitch')
  1233. ->update(['StatusValue' => $StatusValue]);
  1234. return apiReturnSuc();
  1235. }
  1236. // 充值礼包
  1237. public function gift()
  1238. {
  1239. $res = (new RechargeLogic())->gift();
  1240. return view('admin.recharge.gift', $res);
  1241. }
  1242. public function clearCache()
  1243. {
  1244. ClearCache::dispatch();
  1245. return apiReturnSuc();
  1246. }
  1247. public function monthCardEdit($id, Request $request) {
  1248. $monthCard = MonthCard::findOrFail($id);
  1249. if ($request->method() == 'GET') {
  1250. return view('admin.recharge.month_card_edit', [
  1251. 'monthCard' => $monthCard,
  1252. ]);
  1253. }
  1254. $validator = Validator::make($request->all(), [
  1255. 'Price' => 'required|min:1',
  1256. 'FirstReward' => 'required|int|min:1',
  1257. 'DayReward' => 'required|int|min:1',
  1258. ]);
  1259. if ($validator->fails()) {
  1260. return apiReturnFail($validator->errors()->first());
  1261. }
  1262. $monthCard->Price = $request->input('Price');
  1263. $monthCard->FirstReward = $request->input('FirstReward')*100;
  1264. $monthCard->DayReward = $request->input('DayReward')*100;
  1265. $monthCard->save();
  1266. return apiReturnSuc();
  1267. }
  1268. public function monthCardChannelEdit($id, Request $request)
  1269. {
  1270. $monthCard = MonthCard::findOrFail($id);
  1271. $gears = $monthCard->gear;
  1272. $channels = AdminConfig::where(['type' => 'pay'])->pluck('name', 'id');
  1273. $monthCardChannels = [];
  1274. foreach ($channels as $id => $name) {
  1275. $status = 0;
  1276. foreach ($gears as $v1) {
  1277. if ($v1['id'] == $id) {
  1278. $status = $v1['status'];
  1279. break;
  1280. }
  1281. }
  1282. $monthCardChannels[] = [
  1283. 'id' => $id,
  1284. 'name' => $name,
  1285. 'status' => $status
  1286. ];
  1287. }
  1288. return view('/admin/recharge/month_card_channel_edit', [
  1289. 'monthCard' => $monthCard,
  1290. 'monthCardChannels' => $monthCardChannels
  1291. ]);
  1292. }
  1293. public function monthCardSwitch($CardID)
  1294. {
  1295. $monthCard = MonthCard::findOrFail($CardID);
  1296. $monthCard->CardState = $monthCard->CardState ? 0 : 1;
  1297. $monthCard->save();
  1298. return apiReturnSuc();
  1299. }
  1300. public function monthCardChannelSwitch($CardID, $channel)
  1301. {
  1302. $monthCard = MonthCard::findOrFail($CardID);
  1303. $gears = $monthCard->gear;
  1304. if (in_array($channel, array_column($gears, 'id'))) {
  1305. $status = 0;
  1306. foreach ($gears as $k => $v) {
  1307. if ($v['id'] == $channel) {
  1308. $status = $v['status'] ? 0 : 1;
  1309. $v['status'] = $status;
  1310. $gears[$k] = $v;
  1311. break;
  1312. }
  1313. }
  1314. } else {
  1315. $status = 1;
  1316. $gears[] = [
  1317. 'id' => $channel,
  1318. 'status' => 1
  1319. ];
  1320. }
  1321. $monthCard->gear = json_encode($gears);
  1322. $monthCard->save();
  1323. return apiReturnSuc();
  1324. }
  1325. // 充值礼包配置列表
  1326. public function gift_list(Request $request)
  1327. {
  1328. try {
  1329. $list = DB::connection('write')->table(DB::raw('agent.dbo.recharge_gift WITH (NOLOCK)'))
  1330. ->orderBy('id', 'desc')
  1331. ->paginate(10);
  1332. foreach ($list as &$item) {
  1333. $item->day_rewards = $item->day_rewards ? json_decode($item->day_rewards, true) : null;
  1334. $item->betting_bonus = $item->betting_bonus ? json_decode($item->betting_bonus, true) : null;
  1335. $item->betting_task = $item->betting_task ? json_decode($item->betting_task, true) : null;
  1336. // task_bonus 是数字字段,保留两位小数
  1337. $item->task_bonus = $item->task_bonus !== null ? round((float)$item->task_bonus, 2) : null;
  1338. }
  1339. return view('admin.recharge.gift_list', compact('list'));
  1340. } catch (\Exception $e) {
  1341. \Log::error('充值礼包列表错误:' . $e->getMessage());
  1342. return apiReturnFail('数据库错误:' . $e->getMessage());
  1343. }
  1344. }
  1345. // 添加充值礼包
  1346. public function gift_add(Request $request)
  1347. {
  1348. \Log::info('gift_add method called', ['method' => $request->method()]);
  1349. if ($request->isMethod('post')) {
  1350. try {
  1351. // 获取最大ID
  1352. $maxId = DB::connection('write')->table('agent.dbo.recharge_gift')->max('id') ?: 0;
  1353. $data = [
  1354. 'id' => $maxId + 1,
  1355. 'bonus_instantly' => (int)$request->bonus_instantly ?: 0,
  1356. 'total_bonus' => (int)$request->total_bonus ?: 0,
  1357. 'first_pay' => (int)$request->first_pay ?: 0,
  1358. 'is_vip' => (int)$request->is_vip ?: 0,
  1359. 'valid_h' => (int)$request->valid_h ?: 0,
  1360. 'valid_h_2' => (int)$request->valid_h_2 ?: 0,
  1361. 'gift_id' => (int)$request->gift_id ?: 0,
  1362. 'gift_name' => $request->gift_name ?: '',
  1363. 'recommend' => round((float)$request->recommend ?: 0, 2),
  1364. ];
  1365. // 处理每日奖励
  1366. if ($request->has('day_rewards_enable') && $request->day_rewards_enable) {
  1367. $day_rewards = [
  1368. 'total_bonus' => (float)$request->day_rewards_total_bonus ?: 0,
  1369. 'bonus_day' => (int)$request->day_rewards_bonus_day ?: 0,
  1370. 'start_day' => (int)$request->day_rewards_start_day ?: 0,
  1371. 'bonus' => array_map('floatval', explode(',', $request->day_rewards_bonus ?: ''))
  1372. ];
  1373. $data['day_rewards'] = json_encode($day_rewards);
  1374. } else {
  1375. $data['day_rewards'] = '';
  1376. }
  1377. // 处理下注奖励
  1378. if ($request->has('betting_bonus_enable') && $request->betting_bonus_enable) {
  1379. $betting_bonus = [
  1380. 'total_bonus' => (float)$request->betting_bonus_total_bonus ?: 0,
  1381. 'per_bet' => (int)$request->betting_bonus_per_bet ?: 0,
  1382. 'per_bet_bonus' => (float)$request->betting_bonus_per_bet_bonus ?: 0
  1383. ];
  1384. $data['betting_bonus'] = json_encode($betting_bonus);
  1385. } else {
  1386. $data['betting_bonus'] = '';
  1387. }
  1388. // 处理下注任务
  1389. if ($request->has('betting_task_enable') && $request->betting_task_enable) {
  1390. $betting_task = [
  1391. 'total_bonus' => (float)$request->betting_task_total_bonus ?: 0,
  1392. 'bet_pay_times' => (int)$request->betting_task_bet_pay_times ?: 0
  1393. ];
  1394. $data['betting_task'] = json_encode($betting_task);
  1395. } else {
  1396. $data['betting_task'] = '';
  1397. }
  1398. // 处理每日任务奖励(数字字段,保留两位小数)
  1399. if ($request->has('task_bonus')) {
  1400. $data['task_bonus'] = round((float)$request->task_bonus ?: 0, 2);
  1401. } else {
  1402. $data['task_bonus'] = null;
  1403. }
  1404. DB::connection('write')->table('agent.dbo.recharge_gift')->insert($data);
  1405. return apiReturnSuc();
  1406. } catch (\Exception $e) {
  1407. \Log::error('添加充值礼包错误:' . $e->getMessage());
  1408. return apiReturnFail('添加失败:' . $e->getMessage());
  1409. }
  1410. }
  1411. \Log::info('Rendering gift_add view');
  1412. try {
  1413. // 测试简单视图
  1414. // return view('admin.recharge.gift_add_simple_test');
  1415. return view('admin.recharge.gift_add');
  1416. } catch (\Exception $e) {
  1417. \Log::error('gift_add view error: ' . $e->getMessage());
  1418. return response('View error: ' . $e->getMessage() . '<br><pre>' . $e->getTraceAsString() . '</pre>', 500);
  1419. }
  1420. }
  1421. // 修改充值礼包
  1422. public function gift_update(Request $request, $id)
  1423. {
  1424. if ($request->isMethod('post')) {
  1425. $data = [
  1426. 'bonus_instantly' => (int)$request->bonus_instantly ?: 0,
  1427. 'total_bonus' => (int)$request->total_bonus ?: 0,
  1428. 'first_pay' => (int)$request->first_pay ?: 0,
  1429. 'is_vip' => (int)$request->is_vip ?: 0,
  1430. 'valid_h' => (int)$request->valid_h ?: 0,
  1431. 'valid_h_2' => (int)$request->valid_h_2 ?: 0,
  1432. 'gift_id' => (int)$request->gift_id ?: 0,
  1433. 'gift_name' => $request->gift_name ?: '',
  1434. 'recommend' => round((float)$request->recommend ?: 0, 2),
  1435. ];
  1436. // 处理每日奖励
  1437. if ($request->has('day_rewards_enable') && $request->day_rewards_enable) {
  1438. $day_rewards = [
  1439. 'total_bonus' => (float)$request->day_rewards_total_bonus ?: 0,
  1440. 'bonus_day' => (int)$request->day_rewards_bonus_day ?: 0,
  1441. 'start_day' => (int)$request->day_rewards_start_day ?: 0,
  1442. 'bonus' => array_map('floatval', explode(',', $request->day_rewards_bonus ?: ''))
  1443. ];
  1444. $data['day_rewards'] = json_encode($day_rewards);
  1445. } else {
  1446. $data['day_rewards'] = '';
  1447. }
  1448. // 处理下注奖励
  1449. if ($request->has('betting_bonus_enable') && $request->betting_bonus_enable) {
  1450. $betting_bonus = [
  1451. 'total_bonus' => (float)$request->betting_bonus_total_bonus ?: 0,
  1452. 'per_bet' => (int)$request->betting_bonus_per_bet ?: 0,
  1453. 'per_bet_bonus' => (float)$request->betting_bonus_per_bet_bonus ?: 0
  1454. ];
  1455. $data['betting_bonus'] = json_encode($betting_bonus);
  1456. } else {
  1457. $data['betting_bonus'] = '';
  1458. }
  1459. // 处理下注任务
  1460. if ($request->has('betting_task_enable') && $request->betting_task_enable) {
  1461. $betting_task = [
  1462. 'total_bonus' => (float)$request->betting_task_total_bonus ?: 0,
  1463. 'bet_pay_times' => (int)$request->betting_task_bet_pay_times ?: 0
  1464. ];
  1465. $data['betting_task'] = json_encode($betting_task);
  1466. } else {
  1467. $data['betting_task'] = '';
  1468. }
  1469. // 处理每日任务奖励(数字字段,保留两位小数)
  1470. if ($request->has('task_bonus')) {
  1471. $data['task_bonus'] = round((float)$request->task_bonus ?: 0, 2);
  1472. } else {
  1473. $data['task_bonus'] = null;
  1474. }
  1475. DB::connection('write')->table('agent.dbo.recharge_gift')->where('id', $id)->update($data);
  1476. return apiReturnSuc();
  1477. }
  1478. $info = DB::connection('write')->table('agent.dbo.recharge_gift')->where('id', $id)->first();
  1479. $info->day_rewards = $info->day_rewards ? json_decode($info->day_rewards, true) : null;
  1480. $info->betting_bonus = $info->betting_bonus ? json_decode($info->betting_bonus, true) : null;
  1481. $info->betting_task = $info->betting_task ? json_decode($info->betting_task, true) : null;
  1482. // task_bonus 是数字字段,保留两位小数
  1483. $info->task_bonus = $info->task_bonus !== null ? round((float)$info->task_bonus, 2) : null;
  1484. return view('admin.recharge.gift_update', compact('info'));
  1485. }
  1486. // 删除充值礼包
  1487. public function gift_delete($id)
  1488. {
  1489. DB::connection('write')->table('agent.dbo.recharge_gift')->where('id', $id)->delete();
  1490. return apiReturnSuc();
  1491. }
  1492. }