RechargeController.php 69 KB

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