RechargeController.php 69 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656
  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' => [
  371. 1 => 'cashapp',
  372. 2 => 'paypal',
  373. 4 => 'applepay',
  374. 8 => 'googlepay',
  375. 16 => 'btcpay',
  376. 32 => 'eth',
  377. 1024 => 'usdt',
  378. 2048 => 'usdc',
  379. ]
  380. ]);
  381. }
  382. }
  383. //充值排行榜,每日&累计
  384. public function rechargeRank1(Request $request)
  385. {
  386. $excel = $request->get('excel');
  387. $end_time = $request->input('end_time');
  388. $start_time = $request->input('start_time');
  389. $sort = $request->get('sort');
  390. $todayPayAmount = $request->get('todayPayAmount');
  391. $chargeMin = $request->chargeMin ?: '';
  392. $chargeMax = $request->chargeMax ?: '';
  393. $last_login_start_time = $request->last_login_start_time ?: '';
  394. $last_login_end_time = $request->last_login_end_time ?: '';
  395. $page = $_SERVER['QUERY_STRING'] ? urlencode($_SERVER['QUERY_STRING']) : 'page=1';
  396. $where = [];
  397. $where[] = ['Recharge', '>', 0];
  398. !empty($start_time) && $where[] = ['o.pay_at', '>=', $start_time];
  399. !empty($end_time) ? $where[] = ['o.pay_at', '<=', date('Y-m-d', strtotime("$end_time+1day"))] : '';
  400. !empty($chargeMin) && $where[] = ['Recharge', '>=', $chargeMin];
  401. !empty($chargeMax) && $where[] = ['Recharge', '<=', $chargeMax];
  402. !empty($last_login_start_time) && $where[] = ['LastLogonDate', '>=', $last_login_start_time];
  403. !empty($last_login_end_time) && $where[] = ['LastLogonDate', '<=', $last_login_end_time];
  404. if (empty($start_time)) {
  405. $pay_at_start_time = date('Y-m-d');
  406. } else {
  407. $pay_at_start_time = $start_time;
  408. }
  409. if (empty($end_time)) {
  410. $pay_at_end_time = date('Y-m-d');
  411. } else {
  412. $pay_at_end_time = $end_time;
  413. }
  414. switch ($sort) {
  415. case '1':
  416. $order_sql = 'a.Experience DESC';
  417. break;
  418. case '2':
  419. $order_sql = 'DATEDIFF(DAY,a.LastLogonDate,GETDATE()) DESC';
  420. break;
  421. default:
  422. $order_sql = 'Recharge DESC';
  423. break;
  424. }
  425. if ($excel) {
  426. // $cellData = DB::connection('write')->table('agent.dbo.order as o')
  427. // ->leftjoin('QPAccountsDB.dbo.AccountsInfo as a', 'o.user_id', '=', 'a.UserID')
  428. // ->leftjoin('QPAccountsDB.dbo.AccountPhone as i', 'o.user_id', '=', 'i.UserID')
  429. // ->leftjoin('agent.dbo.agent as ag', 'o.user_id', '=', 'ag.UserID')
  430. // ->join('QPAccountsDB.dbo.YN_VIPAccount as vip', 'o.user_id', '=', 'vip.UserID')
  431. // ->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')
  432. // ->whereNotNull('pay_at')
  433. // ->where($where)
  434. // ->groupBy('o.user_id', 'Recharge', 'a.GameID', 'a.NickName', 'a.LastLogonDate', 'a.RegisterDate', 'a.Experience', 'i.PhoneNum', 'ag.id', 'a.Channel')
  435. // ->orderByRaw($order_sql)
  436. // ->get();
  437. $cellData = DB::table(DB::raw(TableName::QPRecordDB() . 'RecordUserDataStatisticsNew as ds WITH (NOLOCK)'))
  438. ->where('Recharge', '>', 0)
  439. ->join(DB::raw(TableName::QPAccountsDB() . 'AccountsInfo as ai WITH (NOLOCK)'), 'ds.UserID', 'ai.UserID')
  440. ->leftjoin(DB::raw('QPAccountsDB.dbo.AccountPhone as ap WITH (NOLOCK)'), 'ds.UserID', 'ap.UserID')
  441. ->select('ai.UserID', 'ai.GameID', 'ai.NickName', 'ai.Channel', 'ap.PhoneNum', 'ds.Recharge', 'ai.PlayTimeCount', 'ai.LastLogonDate', 'ai.RegisterDate')
  442. ->orderByDesc('Recharge')
  443. ->get();
  444. $pyq = DB::connection('write')->table(DB::raw('QPAccountsDB.dbo.PyqInfo WITH (NOLOCK)'))->select('UserID')->get();
  445. $pyq_list = [];
  446. foreach ($pyq as $k => $v) {
  447. $pyq_list[$v->UserID] = 1;
  448. }
  449. foreach ($cellData as $key => &$value) {
  450. $second = $value->Experience;
  451. $day = floor($second / (3600 * 24));
  452. $second = $second % (3600 * 24);//除去整天之后剩余的时间
  453. $hour = floor($second / 3600);
  454. $second = $second % 3600;//除去整小时之后剩余的时间
  455. $minute = floor($second / 60);
  456. //返回字符串
  457. $value->Experience = $day . '天' . $hour . '小时' . $minute . '分';
  458. $value->type = '玩家';
  459. $value->time = !empty($value->time) ? $value->time . '天' : '';
  460. unset($value->id);
  461. $value->rank = $key + 1;
  462. }
  463. $title = ['排名', '用户ID', '游戏ID', '游戏昵称', '玩家状态', '手机号', '充值总额', '游戏时长', '最后登录时间', '注册时间', '距上次登录时间', '玩家渠道'];
  464. $cellData = json_decode(json_encode($cellData), true);
  465. downloadExcel($cellData, $title, '充值排行榜');
  466. } else {
  467. $sql = DB::connection('write')->table(DB::raw('agent.dbo.[order] as o WITH (NOLOCK)'))
  468. ->leftjoin(DB::raw('QPAccountsDB.dbo.AccountsInfo as a WITH (NOLOCK)'), 'o.user_id', '=', 'a.UserID')
  469. ->leftjoin(DB::raw('QPAccountsDB.dbo.AccountPhone as i WITH (NOLOCK)'), 'o.user_id', '=', 'i.UserID')
  470. ->leftjoin(DB::raw('QPAccountsDB.dbo.YN_VIPAccount as vip WITH (NOLOCK)'), 'o.user_id', '=', 'vip.UserID')
  471. ->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');
  472. if (!empty($todayPayAmount)) {
  473. $list = $sql
  474. ->where('pay_at', '>=', $pay_at_start_time . ' 00:00:00')
  475. ->where('pay_at', '<=', $pay_at_end_time . ' 23:59:59')
  476. ->orderByRaw("sum(amount) $todayPayAmount");
  477. } else {
  478. $list = $sql
  479. ->where('pay_at', '>=', $pay_at_start_time . ' 00:00:00')
  480. ->where('pay_at', '<=', $pay_at_end_time . ' 23:59:59')
  481. ->orderByRaw($order_sql);
  482. }
  483. $list = $list->where($where)
  484. ->groupBy('o.user_id', 'a.GameID', 'a.NickName', 'a.LastLogonDate', 'a.RegisterDate', 'a.Experience', 'i.PhoneNum', 'a.Channel', 'Recharge')
  485. ->paginate(10);
  486. $UserIDs = [];
  487. foreach ($list as $value) {
  488. $UserIDs[] = $value->user_id;
  489. }
  490. $todayPay = DB::connection('write')->table(DB::raw('agent.dbo.[order] WITH (NOLOCK)'))
  491. ->whereIn('user_id', $UserIDs)
  492. ->where('pay_at', '>=', $pay_at_start_time . ' 00:00:00')
  493. ->where('pay_at', '<=', $pay_at_end_time . ' 23:59:59')
  494. ->selectRaw('IsNull(sum(amount),0) amount,user_id')
  495. ->groupBy('user_id')
  496. ->pluck('amount', 'user_id')->toArray();
  497. foreach ($list as $key => &$value) {
  498. $second = $value->Experience;
  499. $day = floor($second / (3600 * 24));
  500. $second = $second % (3600 * 24);//除去整天之后剩余的时间
  501. $hour = floor($second / 3600);
  502. $second = $second % 3600;//除去整小时之后剩余的时间
  503. $minute = floor($second / 60);
  504. //返回字符串
  505. $value->Experience = $day . '天' . $hour . '小时' . $minute . '分';
  506. $value->type = '玩家';
  507. $value->rank = $key + 1;
  508. $value->money = number_float($value->money);
  509. $value->todayPayAmount = isset($todayPay[$value->user_id]) ? number_float($todayPay[$value->user_id] / NumConfig::NUM_VALUE) : 0;
  510. }
  511. $chargeMin = $request->chargeMin ?: '';
  512. $chargeMax = $request->chargeMax ?: '';
  513. $last_login_start_time = $request->last_login_start_time ?: '';
  514. $last_login_end_time = $request->last_login_end_time ?: '';
  515. $sort_list = [0 => '充值金额', 1 => '游戏时长', 2 => '距上次登录时间'];
  516. return view('admin.recharge.rank', [
  517. 'list' => $list,
  518. 'end_time' => $end_time,
  519. 'start_time' => $start_time,
  520. 'sort' => $sort,
  521. 'sort_list' => $sort_list,
  522. 'page' => '/admin/recharge/rank?' . $page,
  523. 'todayPayAmount' => $todayPayAmount,
  524. 'chargeMin' => $chargeMin,
  525. 'chargeMax' => $chargeMax,
  526. 'last_login_start_time' => $last_login_start_time,
  527. 'last_login_end_time' => $last_login_end_time,
  528. 'pay_at_start_time' => $pay_at_start_time,
  529. 'pay_at_end_time' => $pay_at_end_time,
  530. ]);
  531. }
  532. }
  533. public function rechargeRank(Request $request)
  534. {
  535. $excel = $request->get('excel');
  536. $date = Carbon::now();
  537. $start_time = $request->input('start_time', $date->format('Y-m-d'));
  538. $end_time = $request->input('end_time', $date->format('Y-m-d'));
  539. $sort = $request->get('sort');
  540. $Channel = $request->get('Channel');
  541. $chargeMin = $request->chargeMin ?: '';
  542. $chargeMax = $request->chargeMax ?: '';
  543. $adminChannels = session('admin_channels');
  544. $Channels = session('all_channels');
  545. $admin = session('admin');
  546. $where = [];
  547. !empty($start_time) && $where[] = ['DateID', '>=', Carbon::parse($start_time)->format('Ymd')];
  548. !empty($end_time) && $where[] = ['DateID', '<', Carbon::parse($end_time)->addDay(1)->format('Ymd')];
  549. !empty($chargeMin) && $where[] = ['Recharge', '>=', $chargeMin];
  550. !empty($chargeMax) && $where[] = ['Recharge', '<=', $chargeMax];
  551. $where2=$where;
  552. $channelWhere=[];
  553. if(!empty($Channel) || $Channel === '0') {
  554. $where2[] = ['ai.Channel', $Channel];
  555. $channelWhere[] = ['ai.Channel', $Channel];
  556. }else if(count($adminChannels)<5){
  557. $where2[] = [function ($where) use ($adminChannels) {
  558. $where->whereIn('ai.Channel', $adminChannels);
  559. }];
  560. $channelWhere[] = [function ($where) use ($adminChannels) {
  561. $where->whereIn('ai.Channel', $adminChannels);
  562. }];
  563. }
  564. switch ($sort) {
  565. case '1':
  566. $order_sql = 'ai.PlayTimeCount DESC';
  567. break;
  568. case '2':
  569. $order_sql = 'DATEDIFF(DAY,a.LastLogonDate,GETDATE()) DESC';
  570. break;
  571. default:
  572. $order_sql = 'sum(ds.Recharge) DESC';
  573. break;
  574. }
  575. if ($excel && false) {
  576. $cellData = DB::table(DB::raw(TableName::QPRecordDB() . 'RecordUserDataStatisticsNew as ds WITH (NOLOCK)'))
  577. ->where('Recharge', '>', 0)
  578. ->where($where2)
  579. ->join(DB::raw(TableName::QPAccountsDB() . 'AccountsInfo as ai WITH (NOLOCK)'), 'ds.UserID', 'ai.UserID')
  580. ->leftjoin(DB::raw('QPAccountsDB.dbo.AccountPhone as ap WITH (NOLOCK)'), 'ds.UserID', 'ap.UserID')
  581. ->select('ai.UserID','ai.GameID', 'ai.NickName', 'ai.Channel', 'ap.PhoneNum', 'ai.PlayTimeCount', 'ai.LastLogonDate', 'ai.RegisterDate')
  582. ->orderByRaw($order_sql)
  583. ->get();
  584. $rechargeSum = DB::table(DB::raw(TableName::QPRecordDB() . 'RecordUserDataStatisticsNew as ds WITH (NOLOCK)'))
  585. ->where('Recharge', '>', 0)
  586. ->where($where)
  587. ->selectRaw('sum(ds.Recharge) Recharge,UserID')
  588. ->groupBy('UserID')
  589. ->pluck('Recharge', 'UserID')->toArray();
  590. $UserIDs = [];
  591. foreach ($cellData as $value) {
  592. $UserIDs[] = $value->UserID;
  593. }
  594. foreach ($cellData as $key => &$value) {
  595. $second = $value->PlayTimeCount;
  596. $day = floor($second / (3600 * 24));
  597. $second = $second % (3600 * 24);//除去整天之后剩余的时间
  598. $hour = floor($second / 3600);
  599. $second = $second % 3600;//除去整小时之后剩余的时间
  600. $minute = floor($second / 60);
  601. //返回字符串
  602. $value->PlayTimeCount = $day . '天' . $hour . '小时' . $minute . '分';
  603. $value->type = '玩家';
  604. $value->money = $rechargeSum[$value->UserID] ?? 0;
  605. $value->time = Carbon::parse(now())->diffInDays($value->LastLogonDate, true);
  606. }
  607. $title = [ '用户ID', '游戏ID', '游戏昵称', '渠道号', '手机号','游戏时长', '最后登录时间', '注册时间','类型','充值金额', '距上次登录时间'];
  608. $cellData = json_decode(json_encode($cellData), true);
  609. downloadExcel($cellData, $title, '充值排行榜');
  610. } else {
  611. $channelUsers=DB::table(DB::raw(TableName::QPAccountsDB() . 'AccountsInfo as ai WITH (NOLOCK)'))->where($channelWhere)->select('UserID');
  612. $rechargeSum = DB::table(DB::raw(TableName::QPRecordDB() . 'RecordUserDataStatisticsNew as ds WITH (NOLOCK)'))
  613. ->where('Recharge', '>', 0)
  614. ->where($where)
  615. ->whereIn('UserID',$channelUsers)
  616. ->selectRaw('sum(ds.Recharge) RechargeAll,UserID')
  617. ->groupBy('UserID')
  618. ->orderByRaw($order_sql)
  619. ->paginate(10);
  620. $UserIDs = [];
  621. $ReSort=[];
  622. foreach ($rechargeSum as &$value) {
  623. $UserIDs[] = $value->UserID;
  624. $ReSort[$value->UserID]=$value;
  625. }
  626. $list = DB::table(DB::raw(TableName::QPAccountsDB() . 'AccountsInfo as ai WITH (NOLOCK)'))
  627. ->leftjoin(DB::raw('QPAccountsDB.dbo.AccountPhone as ap WITH (NOLOCK)'), 'ai.UserID', 'ap.UserID')
  628. ->select('ai.UserID', 'ai.GameID', 'ai.NickName', 'ai.Channel', 'ap.PhoneNum', 'ai.PlayTimeCount', 'ai.LastLogonDate', 'ai.RegisterDate')
  629. ->whereIn('ai.UserID',$UserIDs)
  630. ->get();
  631. foreach ($list as $key => &$value) {
  632. $second = $value->PlayTimeCount;
  633. $day = floor($second / (3600 * 24));
  634. $second = $second % (3600 * 24);//除去整天之后剩余的时间
  635. $hour = floor($second / 3600);
  636. $second = $second % 3600;//除去整小时之后剩余的时间
  637. $minute = floor($second / 60);
  638. $value2=$ReSort[$value->UserID];
  639. $value2->GameID=$value->GameID;
  640. $value2->NickName=$value->NickName;
  641. $value2->Channel=$value->Channel;
  642. $value2->PhoneNum=$value->PhoneNum;
  643. $value2->PlayTimeCount=$value->PlayTimeCount;
  644. $value2->LastLogonDate=$value->LastLogonDate;
  645. $value2->RegisterDate=$value->RegisterDate;
  646. //返回字符串
  647. $value2->Experience = $day . '天' . $hour . '小时' . $minute . '分';
  648. $value2->type = '玩家';
  649. $value2->rank = $key + 1;
  650. $value2->money = $value2->RechargeAll;//$rechargeSum[$value->UserID] ?? 0;
  651. $value2->time = Carbon::parse(now())->diffInDays($value->LastLogonDate, true);
  652. }
  653. $chargeMin = $request->chargeMin ?: '';
  654. $chargeMax = $request->chargeMax ?: '';
  655. $sort_list = [0 => '充值金额', 1 => '游戏时长', 2 => '距上次登录时间'];
  656. $channels=$adminChannels;
  657. return view('admin.recharge.rank', [
  658. 'list' => $rechargeSum,
  659. 'end_time' => $end_time,
  660. 'start_time' => $start_time,
  661. 'sort' => $sort,
  662. 'sort_list' => $sort_list,
  663. 'chargeMin' => $chargeMin,
  664. 'chargeMax' => $chargeMax,
  665. 'Channel'=>$Channel,
  666. 'channels' => $channels
  667. ]);
  668. }
  669. }
  670. // 补单
  671. public function supplement(Request $request, $id)
  672. {
  673. try {
  674. if ($request->method() == 'POST') {
  675. $admin_id = $request->session()->get('admin')->id;
  676. $order = DB::table('agent.dbo.order')->where('id', $id)->first();
  677. if (!$order) {
  678. return apiReturnFail('订单不存在!');
  679. }
  680. if ((int)$order->pay_status === 1) {
  681. return apiReturnFail('订单已完成!');
  682. }
  683. // 退款订单禁止补单
  684. if ((int)$order->pay_status === 9) {
  685. return apiReturnFail('退款订单不可补单');
  686. }
  687. $payAmt = $order->amount / NumConfig::NUM_VALUE;
  688. $order_sn = $order->order_sn;
  689. Log::info('补单单号:' . $order_sn);
  690. // 成功处理回调
  691. $GiftsID = $order->GiftsID ?: '';
  692. $userID = $order->user_id ?: '';
  693. //$res = (new OrderService())->paySuccess($GiftsID, $userID, $payAmt, $order_sn);
  694. // 获取金额
  695. $service = new OrderServices();
  696. $recharge_gear = DB::connection('write')->table('agent.dbo.recharge_gear')->where('first_pay', 0)->where('money', $payAmt)->select('favorable_price', 'give')->first();
  697. if($recharge_gear || $GiftsID){
  698. [$give, $favorable_price, $Recharge, $czReason, $cjReason] = $service->getPayInfo($GiftsID, $userID, $payAmt);
  699. }else{
  700. $Recharge = $payAmt;
  701. $give = 0;
  702. $favorable_price = $Recharge + $give;
  703. $czReason = 1;
  704. $cjReason = 45;
  705. }
  706. // [$give, $favorable_price, $Recharge, $czReason, $cjReason] = $service->getPayInfo($GiftsID, $userID, $payAmt);
  707. // 增加充值记录
  708. [$Score] = $service->addRecord($userID, $payAmt, $favorable_price, $order_sn, $GiftsID, $Recharge, $czReason, $give, $cjReason, $order->AdId, $order->eventType);
  709. // 成功处理回调
  710. \App\Jobs\Order::dispatch([$userID, $payAmt, $Score, $favorable_price, $GiftsID, $order_sn]);
  711. // 修改订单状态
  712. $data = [
  713. 'pay_status' => 1,
  714. 'finished_at' => date('Y-m-d H:i:s'),
  715. 'updated_at' => date('Y-m-d H:i:s'),
  716. 'pay_at' => date('Y-m-d H:i:s')
  717. ];
  718. $order_up = DB::table('agent.dbo.order')->where('id', $id)->update($data);
  719. // 添加操作记录
  720. (new AccountsRecordLogic())->create_record($id, $order->pay_status, 1, '', $admin_id, 2);
  721. if ($order_up === false) {
  722. return apiReturnFail('补单失败');
  723. }
  724. return apiReturnSuc();
  725. }
  726. } catch (\Exception $exception) {
  727. return apiReturnFail($exception->getMessage());
  728. }
  729. }
  730. // 标记订单为退款状态
  731. public function refund(Request $request, $id)
  732. {
  733. try {
  734. $admin = $request->session()->get('admin');
  735. $roleId = $admin->roles[0]->id ?? 0;
  736. // 仅管理员角色允许操作(与补单权限保持一致)
  737. if (!in_array($roleId, [1, 12])) {
  738. return apiReturnFail('无权限执行该操作');
  739. }
  740. $order = DB::connection('write')->table('agent.dbo.order')->where('id', $id)->lockForUpdate()->first();
  741. if (!$order) {
  742. return apiReturnFail('订单不存在!');
  743. }
  744. if ($order->pay_status == 9) {
  745. return apiReturnFail('订单已为退款状态');
  746. }
  747. if ($order->pay_status != 1) {
  748. return apiReturnFail('仅已到账订单可设置为退款状态');
  749. }
  750. $now = date('Y-m-d H:i:s');
  751. $updated = DB::connection('write')->table('agent.dbo.order')
  752. ->where('id', $id)
  753. ->update([
  754. 'pay_status' => 9,
  755. 'refund_fee' => ($order->payment_code=='AiNewPay' && $order->order_title==2)?800:3000,
  756. 'updated_at' => $now,
  757. ]);
  758. if ($updated === false) {
  759. return apiReturnFail('设置退款状态失败');
  760. }
  761. $fee = ($order->payment_code=='AiNewPay' && $order->order_title==2)?800:3000;
  762. (new RechargeWithDraw())->refund($order->user_id, $order->amount, $fee);
  763. $admin_id = $admin->id;
  764. (new AccountsRecordLogic())->create_record($id, $order->pay_status, 9, '', $admin_id, 2);
  765. return apiReturnSuc();
  766. } catch (\Exception $exception) {
  767. return apiReturnFail($exception->getMessage());
  768. }
  769. }
  770. /**
  771. * 模拟上报 FB 支付事件(仅管理员可用)
  772. */
  773. public function fbReportMock(Request $request, $id)
  774. {
  775. try {
  776. $admin = $request->session()->get('admin');
  777. $roleId = $admin->roles[0]->id ?? 0;
  778. if (!in_array($roleId, [1, 12])) {
  779. return apiReturnFail('无权限执行该操作');
  780. }
  781. $order = DB::connection('write')->table('agent.dbo.order')->where('id', $id)->first();
  782. if (!$order) {
  783. return apiReturnFail('订单不存在!');
  784. }
  785. // 退款订单不允许模拟上报
  786. if ((int)$order->pay_status === 9) {
  787. return apiReturnFail('退款订单不可模拟上报');
  788. }
  789. // 只允许对未成功的订单做模拟上报(已到账的默认认为已正常上报)
  790. if ((int)$order->pay_status === 1) {
  791. return apiReturnFail('仅对未成功订单开放模拟上报');
  792. }
  793. $userId = $order->user_id;
  794. $payAmt = $order->amount; // 内部金额单位,保持与原上报一致
  795. // 构造模拟上报的 params
  796. $item = [
  797. 'regtime' => time(), // 当前时间
  798. 'isd0' => 1, // 固定为首日
  799. 'first' => 1, // 固定视为首充
  800. 'golds' => $payAmt, // 金额
  801. 'udis' => $userId, // 注意:按需求使用 udis 字段
  802. 'order_sn'=> $order->order_sn,
  803. ];
  804. // 通过 OuroGameService 模拟一次 pay_finish 上报
  805. OuroGameService::notifyWebHall(
  806. $userId,
  807. '',
  808. 'pay_finish',
  809. [
  810. 'Golds' => $payAmt,
  811. 'PayNum'=> $payAmt,
  812. 'event' => 'pay',
  813. 'params'=> $item,
  814. ]
  815. );
  816. return apiReturnSuc();
  817. } catch (\Exception $exception) {
  818. Log::error('模拟 FB 上报失败:' . $exception->getMessage(), [
  819. 'order_id' => $id,
  820. ]);
  821. return apiReturnFail('上报失败,请稍后重试');
  822. }
  823. }
  824. public function search($orderId)
  825. {
  826. $order = DB::table('agent.dbo.order')->where('id', $orderId)->first();
  827. if (!$order) {
  828. return apiReturnFail('未查询到订单信息');
  829. }
  830. $agent = $order->payment_code;
  831. $service = PayMentService::pay_logic($agent);
  832. $res = $service->pay_search($order->order_sn);
  833. if($res){
  834. return apiReturnSuc([],'','订单支付成功');
  835. }else{
  836. return apiReturnFail('订单未成功');
  837. }
  838. }
  839. // 充值渠道修改
  840. public function config($method, Request $request)
  841. {
  842. if ($request->method() == 'GET') {
  843. $res = (new RechargeLogic())->config($method);
  844. return view('admin.recharge.config', $res);
  845. }
  846. $validator = Validator::make($request->all(), [
  847. 'config.*.sort' => 'required|int',
  848. 'config.*.status' => 'required|in:1,-1',
  849. 'config.*.weight.1' => 'nullable|int|min:0|max:100000',
  850. 'config.*.weight.2' => 'nullable|int|min:0|max:100000',
  851. 'config.*.weight.4' => 'nullable|int|min:0|max:100000',
  852. 'config.*.weight.8' => 'nullable|int|min:0|max:100000',
  853. ]);
  854. if ($validator->fails()) {
  855. return apiReturnFail($validator->errors()->first());
  856. }
  857. $config = $request->input('config');
  858. $opened = array_filter($config, function ($item) {
  859. return $item['status'] == 1;
  860. });
  861. if (array_sum(array_column($opened, 'sort')) != 100) {
  862. return apiReturnFail('权重值分配不正确');
  863. }
  864. foreach ($config as $id => $v) {
  865. $weightInput = $v['weight'] ?? null;
  866. // 防御性处理:避免后续误把 weight 数组直接参与 update
  867. unset($v['weight']);
  868. $remarksRaw = DB::table('agent.dbo.admin_configs')->where('id', $id)->value('remarks');
  869. $remarks = [];
  870. if (!empty($remarksRaw)) {
  871. $decoded = \GuzzleHttp\json_decode($remarksRaw, true);
  872. if (is_array($decoded)) {
  873. $remarks = $decoded;
  874. }
  875. }
  876. if (is_array($weightInput)) {
  877. $existingWeights = $remarks['weight'] ?? ($remarks['weights'] ?? []);
  878. if (!is_array($existingWeights)) {
  879. $existingWeights = [];
  880. }
  881. $methodWeights = $existingWeights;
  882. foreach ([1, 2, 4, 8] as $methodKey) {
  883. if (array_key_exists($methodKey, $weightInput)) {
  884. $weightKey = 'type_' . $methodKey;
  885. if ($weightInput[$methodKey] === '' || $weightInput[$methodKey] === null) {
  886. $methodWeights[$weightKey] = 0;
  887. } else {
  888. $methodWeights[$weightKey] = (int)$weightInput[$methodKey];
  889. }
  890. }
  891. }
  892. $remarks['weight'] = $methodWeights;
  893. }
  894. $updateData = [
  895. 'sort' => (int)$v['sort'],
  896. 'status' => (int)$v['status'],
  897. 'admin_id' => session('admin')['id'],
  898. 'updated_at' => date('Y-m-d H:i:s'),
  899. 'remarks' => \GuzzleHttp\json_encode($remarks, JSON_UNESCAPED_UNICODE),
  900. ];
  901. if ((int)$v['status'] === -1) {
  902. $updateData['sort'] = 0;
  903. }
  904. DB::table('agent.dbo.admin_configs')->where('id', $id)->update($updateData);
  905. if ((int)$v['status'] === -1) {
  906. DB::table('QPPlatformDB.dbo.ChannelOpenRecharge')->where('ConfigID', $id)
  907. ->update([
  908. 'sort' => 0,
  909. 'status' => 2
  910. ]);
  911. }
  912. }
  913. return apiReturnSuc();
  914. }
  915. public function methods()
  916. {
  917. $methods = DB::table(DB::raw('agent.dbo.admin_configs WITH (NOLOCK)'))
  918. ->leftJoin(DB::raw('agent.dbo.admin_users as u WITH (NOLOCK)'), 'admin_configs.admin_id', '=', 'u.id')
  919. ->select('admin_configs.*', 'u.account')
  920. ->where('admin_configs.type', 'pay_method')
  921. ->get();
  922. return view('admin.recharge.methods', [
  923. 'methods' => $methods,
  924. ]);
  925. }
  926. // 充值渠道修改 开关
  927. public function switch_control(Request $request, $id)
  928. {
  929. $type = $request->type;
  930. $admin_id = $request->session()->get('admin')->id;
  931. $logic = new RechargeLogic();
  932. $res = $logic->switch_control($id, $type, $admin_id);
  933. if ($res === false) {
  934. return apiReturnFail($logic->getError());
  935. }
  936. ClearCache::dispatch();
  937. return apiReturnSuc();
  938. }
  939. // 充值档位修改
  940. public function gear_list()
  941. {
  942. $res = (new RechargeLogic())->gear_list();
  943. // dd($res);
  944. return view('admin.recharge.gear_list', $res);
  945. }
  946. public function channel_switch(Request $request, $id)
  947. {
  948. $type = $request->type;
  949. $logic = new RechargeLogic();
  950. $res = $logic->channel_switch($id, $type);
  951. if ($res === false) {
  952. return apiReturnFail($logic->getError());
  953. }
  954. return apiReturnSuc();
  955. }
  956. // 添加
  957. public function add(Request $request)
  958. {
  959. $list = DB::table('agent.dbo.admin_configs')->where('type', 'pay')->pluck('name', 'id');
  960. if ($request->method() == 'POST') {
  961. $money = (float)$request->money ?: '';
  962. $status = $request->status;
  963. // $config_ids = $request->config_ids;
  964. $favorable_price = (float)$request->favorable_price;
  965. $give = (float)$request->give;
  966. $pay_methods = (int)$request->pay_methods ?: 0; // 支付方式位掩码
  967. $in_shop = (int)$request->input('in_shop', 1); // 是否在商城展示
  968. $logic = new RechargeLogic();
  969. $res = $logic->add($money, $status, '', $favorable_price, $give, $pay_methods, $in_shop);
  970. return apiReturnSuc();
  971. }
  972. return view('admin.recharge.add', ['list' => $list]);
  973. }
  974. public function update_config(Request $request, $id)
  975. {
  976. if ($request->isMethod('post')) {
  977. $money = (float)($request->money ?: '');
  978. $favorable_price = (float)($request->favorable_price ?: 0);
  979. $give = (float)($request->give ?: 0);
  980. $second_give = (int)($request->second_give ?: 0);
  981. $pay_methods = (int)($request->pay_methods ?: 0); // 支付方式位掩码
  982. $in_shop = (int)$request->input('in_shop', 1); // 是否在商城展示
  983. // 构建支付方式数组
  984. $gearData = [];
  985. $payMethodsMap = [
  986. 1 => 'cashapp',
  987. 2 => 'paypal',
  988. 4 => 'applepay',
  989. 8 => 'googlepay',
  990. 16 => 'btcpay',
  991. 32 => 'eth',
  992. 64 => 'usdt-trc20',
  993. 128 => 'usdt-erc20',
  994. 256 => 'usdc-trc20',
  995. 512 => 'usdc-erc20',
  996. 1024 => 'usdt',
  997. 2048 => 'usdc',
  998. ];
  999. foreach ($payMethodsMap as $value => $name) {
  1000. if ($pay_methods & $value) {
  1001. $gearData[] = [
  1002. 'name' => $name,
  1003. 'value' => $value,
  1004. 'status' => 1
  1005. ];
  1006. }
  1007. }
  1008. $data = [
  1009. 'money' => $money,
  1010. 'favorable_price' => $favorable_price,
  1011. 'second_give' => $second_give,
  1012. 'give' => $give,
  1013. 'in_shop' => $in_shop,
  1014. 'gear' => \GuzzleHttp\json_encode($gearData) // 存储到gear字段
  1015. ];
  1016. DB::table('agent.dbo.recharge_gear')->where('id', $id)->update($data);
  1017. return apiReturnSuc();
  1018. } else {
  1019. $info = DB::table('agent.dbo.recharge_gear')->where('id', $id)->first();
  1020. // 解析gear字段,计算pay_methods用于回显
  1021. $pay_methods = 0;
  1022. if (!empty($info->gear)) {
  1023. $gear = \GuzzleHttp\json_decode($info->gear, true);
  1024. if (is_array($gear)) {
  1025. foreach ($gear as $item) {
  1026. if (isset($item['value']) && ($item['status'] ?? 0) == 1) {
  1027. $pay_methods += $item['value'];
  1028. }
  1029. }
  1030. }
  1031. }
  1032. $info->pay_methods = $pay_methods;
  1033. return view('admin.recharge.update_config', ['info' => $info]);
  1034. }
  1035. }
  1036. // 加载修改页面
  1037. public function update(Request $request, $id)
  1038. {
  1039. $info = (new RechargeLogic())->update($id);
  1040. return view('admin.recharge.update', $info);
  1041. }
  1042. // 修改里面的开关
  1043. public function gear_switch(Request $request, $id)
  1044. {
  1045. $config_id = $request->config_id ?: '';
  1046. $type = $request->type ?: '';
  1047. $logic = new RechargeLogic();
  1048. $res = $logic->gear_switch($id, $config_id, $type);
  1049. if ($res === false) {
  1050. return apiReturnFail($logic->getError());
  1051. }
  1052. ClearCache::dispatch();
  1053. return apiReturnSuc();
  1054. }
  1055. // 修改排序
  1056. public function update_sort(Request $request, $id)
  1057. {
  1058. $sort = $request->sort ?: 0;
  1059. DB::connection('write')->table('agent.dbo.admin_configs')
  1060. ->where('id', $id)
  1061. ->update(['sort' => $sort]);
  1062. ClearCache::dispatch();
  1063. return apiReturnSuc();
  1064. }
  1065. // 添加备注
  1066. public function remarks(Request $request, $id)
  1067. {
  1068. $remarks = $request->remark ?: '';
  1069. DB::connection('write')->table('agent.dbo.admin_configs')
  1070. ->where('id', $id)
  1071. ->update(['remarks' => $remarks]);
  1072. return apiReturnSuc();
  1073. }
  1074. // 首冲10元礼包--修改渠道
  1075. public function firstCharge(Request $request)
  1076. {
  1077. $StatusValue = $request->StatusValue ?: '';
  1078. DB::connection('write')->table('QPAccountsDB.dbo.SystemStatusInfo')
  1079. ->where('StatusName', 'FirstChargeGiftBag')
  1080. ->update(['StatusValue' => $StatusValue]);
  1081. return apiReturnSuc();
  1082. }
  1083. // 首冲10元礼包 -- 修改状态
  1084. public function firstChargeStatus(Request $request)
  1085. {
  1086. $StatusValue = $request->StatusValue ?: '';
  1087. DB::connection('write')->table('QPAccountsDB.dbo.SystemStatusInfo')
  1088. ->where('StatusName', 'FirstChargeGiftBagStatus')
  1089. ->update(['StatusValue' => $StatusValue]);
  1090. return apiReturnSuc();
  1091. }
  1092. // IP回调白名单
  1093. public function ip_white(Request $request)
  1094. {
  1095. $list = DB::connection('write')->table(DB::raw('agent.dbo.admin_configs as ac WITH (NOLOCK)'))
  1096. ->leftJoin(DB::raw('agent.dbo.recharge_ip as ri WITH (NOLOCK)'), 'ac.id', '=', 'ri.config_id')
  1097. ->leftJoin(DB::raw('agent.dbo.admin_users as au WITH (NOLOCK)'), 'ri.admin_id', 'au.id')
  1098. ->where('ac.status', 1)
  1099. ->select('ac.id', 'ac.name', 'ac.config_value', 'ip', 'account', 'last_time', 'ac.status', 'ri.remarks')
  1100. ->paginate(5);
  1101. return view('admin.recharge.ip_white', compact('list'));
  1102. }
  1103. public function ip_white_update(Request $request, $id)
  1104. {
  1105. if ($request->isMethod('post')) {
  1106. $post = $request->post();
  1107. if (empty($post['ip'])) {
  1108. return apiReturnFail('IP白名单不能为空');
  1109. }
  1110. $ip = explode(',', $post['ip']);
  1111. foreach ($ip as $val) {
  1112. if (!filter_var($val, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
  1113. return apiReturnFail('ip不合法');
  1114. }
  1115. }
  1116. $post['last_time'] = date('Y-m-d H:i:s');
  1117. $post['admin_id'] = session('admin')->id;
  1118. DB::connection('write')->table('agent.dbo.recharge_ip')
  1119. ->updateOrInsert(['config_id' => $id], $post);
  1120. return apiReturnSuc();
  1121. }
  1122. $info = DB::connection('write')->table('agent.dbo.admin_configs as ac')
  1123. ->leftJoin('agent.dbo.recharge_ip as ri', 'ac.id', '=', 'ri.config_id')
  1124. ->where('ac.id', $id)
  1125. ->select('ac.id', 'ac.name', 'ac.config_value', 'ip', 'ri.remarks')
  1126. ->first();
  1127. return view('admin.recharge.ip_white_update', compact('info'));
  1128. }
  1129. // 充值推荐档位
  1130. public function recomendar_recharge(Request $request)
  1131. {
  1132. $StatusValue = $request->StatusValue ?: '';
  1133. DB::connection('write')->table('QPAccountsDB.dbo.SystemStatusInfo')
  1134. ->where('StatusName', 'RecomendarRecharge')
  1135. ->update(['StatusValue' => $StatusValue]);
  1136. return apiReturnSuc();
  1137. }
  1138. // 修改图片地址
  1139. public function updatePic(Request $request, $id)
  1140. {
  1141. $picList = config('games.recharge_pic_config');
  1142. if ($request->isMethod('post')) {
  1143. $pic_number = $request->post('pic_number');
  1144. if ($pic_number < 0) {
  1145. return apiReturnFail('请选择图片!');
  1146. }
  1147. $pic_url = config('games.recharge_pic.recharge_pic_url');
  1148. $recharge_pic_url = str_replace('{num}', $picList[$pic_number], $pic_url);
  1149. DB::table(TableName::agent() . 'admin_configs')
  1150. ->where('id', $id)
  1151. ->update(['config_value' => $recharge_pic_url, 'pic_num' => $pic_number]);
  1152. return apiReturnSuc();
  1153. }
  1154. return view('admin.recharge.update_pic', compact('id', 'picList'));
  1155. }
  1156. // 轮询开关
  1157. public function poll(Request $request)
  1158. {
  1159. $StatusValue = $request->StatusValue ?: '';
  1160. DB::connection('write')->table('QPAccountsDB.dbo.SystemStatusInfo')
  1161. ->where('StatusName', 'PollSwitch')
  1162. ->update(['StatusValue' => $StatusValue]);
  1163. return apiReturnSuc();
  1164. }
  1165. // 充值礼包
  1166. public function gift()
  1167. {
  1168. $res = (new RechargeLogic())->gift();
  1169. return view('admin.recharge.gift', $res);
  1170. }
  1171. public function clearCache()
  1172. {
  1173. ClearCache::dispatch();
  1174. return apiReturnSuc();
  1175. }
  1176. public function monthCardEdit($id, Request $request) {
  1177. $monthCard = MonthCard::findOrFail($id);
  1178. if ($request->method() == 'GET') {
  1179. return view('admin.recharge.month_card_edit', [
  1180. 'monthCard' => $monthCard,
  1181. ]);
  1182. }
  1183. $validator = Validator::make($request->all(), [
  1184. 'Price' => 'required|min:1',
  1185. 'FirstReward' => 'required|int|min:1',
  1186. 'DayReward' => 'required|int|min:1',
  1187. ]);
  1188. if ($validator->fails()) {
  1189. return apiReturnFail($validator->errors()->first());
  1190. }
  1191. $monthCard->Price = $request->input('Price');
  1192. $monthCard->FirstReward = $request->input('FirstReward')*100;
  1193. $monthCard->DayReward = $request->input('DayReward')*100;
  1194. $monthCard->save();
  1195. return apiReturnSuc();
  1196. }
  1197. public function monthCardChannelEdit($id, Request $request)
  1198. {
  1199. $monthCard = MonthCard::findOrFail($id);
  1200. $gears = $monthCard->gear;
  1201. $channels = AdminConfig::where(['type' => 'pay'])->pluck('name', 'id');
  1202. $monthCardChannels = [];
  1203. foreach ($channels as $id => $name) {
  1204. $status = 0;
  1205. foreach ($gears as $v1) {
  1206. if ($v1['id'] == $id) {
  1207. $status = $v1['status'];
  1208. break;
  1209. }
  1210. }
  1211. $monthCardChannels[] = [
  1212. 'id' => $id,
  1213. 'name' => $name,
  1214. 'status' => $status
  1215. ];
  1216. }
  1217. return view('/admin/recharge/month_card_channel_edit', [
  1218. 'monthCard' => $monthCard,
  1219. 'monthCardChannels' => $monthCardChannels
  1220. ]);
  1221. }
  1222. public function monthCardSwitch($CardID)
  1223. {
  1224. $monthCard = MonthCard::findOrFail($CardID);
  1225. $monthCard->CardState = $monthCard->CardState ? 0 : 1;
  1226. $monthCard->save();
  1227. return apiReturnSuc();
  1228. }
  1229. public function monthCardChannelSwitch($CardID, $channel)
  1230. {
  1231. $monthCard = MonthCard::findOrFail($CardID);
  1232. $gears = $monthCard->gear;
  1233. if (in_array($channel, array_column($gears, 'id'))) {
  1234. $status = 0;
  1235. foreach ($gears as $k => $v) {
  1236. if ($v['id'] == $channel) {
  1237. $status = $v['status'] ? 0 : 1;
  1238. $v['status'] = $status;
  1239. $gears[$k] = $v;
  1240. break;
  1241. }
  1242. }
  1243. } else {
  1244. $status = 1;
  1245. $gears[] = [
  1246. 'id' => $channel,
  1247. 'status' => 1
  1248. ];
  1249. }
  1250. $monthCard->gear = json_encode($gears);
  1251. $monthCard->save();
  1252. return apiReturnSuc();
  1253. }
  1254. // 充值礼包配置列表
  1255. public function gift_list(Request $request)
  1256. {
  1257. try {
  1258. $list = DB::connection('write')->table(DB::raw('agent.dbo.recharge_gift WITH (NOLOCK)'))
  1259. ->orderBy('id', 'desc')
  1260. ->paginate(10);
  1261. foreach ($list as &$item) {
  1262. $item->day_rewards = $item->day_rewards ? json_decode($item->day_rewards, true) : null;
  1263. $item->betting_bonus = $item->betting_bonus ? json_decode($item->betting_bonus, true) : null;
  1264. $item->betting_task = $item->betting_task ? json_decode($item->betting_task, true) : null;
  1265. // task_bonus 是数字字段,保留两位小数
  1266. $item->task_bonus = $item->task_bonus !== null ? round((float)$item->task_bonus, 2) : null;
  1267. }
  1268. return view('admin.recharge.gift_list', compact('list'));
  1269. } catch (\Exception $e) {
  1270. \Log::error('充值礼包列表错误:' . $e->getMessage());
  1271. return apiReturnFail('数据库错误:' . $e->getMessage());
  1272. }
  1273. }
  1274. // 添加充值礼包
  1275. public function gift_add(Request $request)
  1276. {
  1277. \Log::info('gift_add method called', ['method' => $request->method()]);
  1278. if ($request->isMethod('post')) {
  1279. try {
  1280. // 获取最大ID
  1281. $maxId = DB::connection('write')->table('agent.dbo.recharge_gift')->max('id') ?: 0;
  1282. $data = [
  1283. 'id' => $maxId + 1,
  1284. 'bonus_instantly' => (int)$request->bonus_instantly ?: 0,
  1285. 'total_bonus' => (int)$request->total_bonus ?: 0,
  1286. 'first_pay' => (int)$request->first_pay ?: 0,
  1287. 'is_vip' => (int)$request->is_vip ?: 0,
  1288. 'valid_h' => (int)$request->valid_h ?: 0,
  1289. 'valid_h_2' => (int)$request->valid_h_2 ?: 0,
  1290. 'gift_id' => (int)$request->gift_id ?: 0,
  1291. 'gift_name' => $request->gift_name ?: '',
  1292. 'recommend' => round((float)$request->recommend ?: 0, 2),
  1293. ];
  1294. // 处理每日奖励
  1295. if ($request->has('day_rewards_enable') && $request->day_rewards_enable) {
  1296. $day_rewards = [
  1297. 'total_bonus' => (float)$request->day_rewards_total_bonus ?: 0,
  1298. 'bonus_day' => (int)$request->day_rewards_bonus_day ?: 0,
  1299. 'start_day' => (int)$request->day_rewards_start_day ?: 0,
  1300. 'bonus' => array_map('floatval', explode(',', $request->day_rewards_bonus ?: ''))
  1301. ];
  1302. $data['day_rewards'] = json_encode($day_rewards);
  1303. } else {
  1304. $data['day_rewards'] = '';
  1305. }
  1306. // 处理下注奖励
  1307. if ($request->has('betting_bonus_enable') && $request->betting_bonus_enable) {
  1308. $betting_bonus = [
  1309. 'total_bonus' => (float)$request->betting_bonus_total_bonus ?: 0,
  1310. 'per_bet' => (int)$request->betting_bonus_per_bet ?: 0,
  1311. 'per_bet_bonus' => (float)$request->betting_bonus_per_bet_bonus ?: 0
  1312. ];
  1313. $data['betting_bonus'] = json_encode($betting_bonus);
  1314. } else {
  1315. $data['betting_bonus'] = '';
  1316. }
  1317. // 处理下注任务
  1318. if ($request->has('betting_task_enable') && $request->betting_task_enable) {
  1319. $betting_task = [
  1320. 'total_bonus' => (float)$request->betting_task_total_bonus ?: 0,
  1321. 'bet_pay_times' => (int)$request->betting_task_bet_pay_times ?: 0
  1322. ];
  1323. $data['betting_task'] = json_encode($betting_task);
  1324. } else {
  1325. $data['betting_task'] = '';
  1326. }
  1327. // 处理每日任务奖励(数字字段,保留两位小数)
  1328. if ($request->has('task_bonus')) {
  1329. $data['task_bonus'] = round((float)$request->task_bonus ?: 0, 2);
  1330. } else {
  1331. $data['task_bonus'] = null;
  1332. }
  1333. DB::connection('write')->table('agent.dbo.recharge_gift')->insert($data);
  1334. return apiReturnSuc();
  1335. } catch (\Exception $e) {
  1336. \Log::error('添加充值礼包错误:' . $e->getMessage());
  1337. return apiReturnFail('添加失败:' . $e->getMessage());
  1338. }
  1339. }
  1340. \Log::info('Rendering gift_add view');
  1341. try {
  1342. // 测试简单视图
  1343. // return view('admin.recharge.gift_add_simple_test');
  1344. return view('admin.recharge.gift_add');
  1345. } catch (\Exception $e) {
  1346. \Log::error('gift_add view error: ' . $e->getMessage());
  1347. return response('View error: ' . $e->getMessage() . '<br><pre>' . $e->getTraceAsString() . '</pre>', 500);
  1348. }
  1349. }
  1350. // 修改充值礼包
  1351. public function gift_update(Request $request, $id)
  1352. {
  1353. if ($request->isMethod('post')) {
  1354. $data = [
  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')->where('id', $id)->update($data);
  1405. return apiReturnSuc();
  1406. }
  1407. $info = DB::connection('write')->table('agent.dbo.recharge_gift')->where('id', $id)->first();
  1408. $info->day_rewards = $info->day_rewards ? json_decode($info->day_rewards, true) : null;
  1409. $info->betting_bonus = $info->betting_bonus ? json_decode($info->betting_bonus, true) : null;
  1410. $info->betting_task = $info->betting_task ? json_decode($info->betting_task, true) : null;
  1411. // task_bonus 是数字字段,保留两位小数
  1412. $info->task_bonus = $info->task_bonus !== null ? round((float)$info->task_bonus, 2) : null;
  1413. return view('admin.recharge.gift_update', compact('info'));
  1414. }
  1415. // 删除充值礼包
  1416. public function gift_delete($id)
  1417. {
  1418. DB::connection('write')->table('agent.dbo.recharge_gift')->where('id', $id)->delete();
  1419. return apiReturnSuc();
  1420. }
  1421. }