Przeglądaj źródła

Merge branch 'dev'

lip 13 godzin temu
rodzic
commit
076d79d189

+ 2 - 0
app/Http/Controllers/admin/ActivityReward.php

@@ -56,6 +56,8 @@ class ActivityReward extends Controller
                 'end_time' => ['required', 'date', 'after_or_equal:start_time'],
                 'detail_image' => ['required', 'url', 'regex:/\.(jpeg|jpg|png|webp)$/i'],
                 'pc_image' => ['required', 'url', 'regex:/\.(jpeg|jpg|png|webp)$/i'],
+                'detail_banner' => ['required', 'url', 'regex:/\.(jpeg|jpg|png|webp)$/i'],
+                'pc_banner' => ['required', 'url', 'regex:/\.(jpeg|jpg|png|webp)$/i'],
                 'status' => ['required', 'integer', 'min:0', 'max:1'],
                 'type' => ['required'],
                 'lang' => ['required', 'string'],

+ 35 - 30
app/Http/Controllers/admin/PaymentOrder.php

@@ -26,14 +26,14 @@ class PaymentOrder extends Controller
         //人工充值订单
         $data['rgRecharge'] = (int)PaymentOrderModel::whereIn('status', [0,1,5])->where('type', 3)->count();
         //人民币充值订单
-        $data['rgRecharge'] = (int)PaymentOrderModel::whereIn('status', [0,1])->where('type', 1)->count();
+        $data['rmbRecharge'] = (int)PaymentOrderModel::whereIn('status', [0,1])->where('type', 1)->count();
         
         //USDT提现订单
         $data['usdtWithdraw'] = (int)Withdraw::where('status', 0)->count();
         //人工提现订单
         $data['rgWithdraw'] = (int)PaymentOrderModel::where('status', 0)->where('type', 4)->count();
         //人民币提现订单
-        $data['rgWithdraw'] = (int)PaymentOrderModel::where('status', 0)->where('type', 2)->count();
+        $data['rmbWithdraw'] = (int)PaymentOrderModel::where('status', 0)->where('type', 2)->count();
         return $this->success($data);
     }
 
@@ -74,40 +74,44 @@ class PaymentOrder extends Controller
         DB::beginTransaction();
         try {
             $params = request()->validate([
-                'id' => ['required', 'integer'],
+                'id' => ['required'],
                 'status' => ['required', 'integer', 'in:2,3'],
                 'remark' => ['nullable', 'string'],
             ]);
             $remark = $params['remark'] ?? '';
-            $info = PaymentOrderModel::find($params['id']);
-            if (!$info) throw new Exception('数据不存在', HttpStatus::CUSTOM_ERROR);
-            if ($info->status != 5) throw new Exception('用户未提交充值凭证', HttpStatus::CUSTOM_ERROR);
-            if ($info->payment_type == 0) throw new Exception('当前订单非人工充值,无法操作', HttpStatus::CUSTOM_ERROR);
-            if ($params['status'] == 3) {
-                if (empty($remark)) {
-                    throw new Exception('请填写原因', HttpStatus::CUSTOM_ERROR);
+            $ids = is_array($params['id']) ? $params['id'] : [$params['id']];
+            foreach($ids as $id) {
+                $info = PaymentOrderModel::find($id);
+                if (!$info) throw new Exception('数据不存在', HttpStatus::CUSTOM_ERROR);
+                if ($params['status'] == 2 && $info->status != 5) throw new Exception('用户未提交充值凭证', HttpStatus::CUSTOM_ERROR);
+                if ($params['status'] == 3 && !in_array($info->status, [0,1,4,5])) throw new Exception('订单已完成,不可驳回', HttpStatus::CUSTOM_ERROR);
+                if ($params['status'] == 3) {
+                    //驳回
+                    if (empty($remark)) {
+                        throw new Exception('请填写原因', HttpStatus::CUSTOM_ERROR);
+                    }
+                    $info->status = $params['status'];
+                    $info->remark = $remark;
+                    $info->save();
+                } else {
+                    //充值成功
+                    $info->status = $params['status'];
+                    $info->remark = $remark;
+                    $info->state = 1;
+                    $info->save();
+    
+                    $memberId = $info->member_id;
+                    $amount = $info->amount;
+                    $changeType = '人工充值';
+                    $wallet = Wallet::where('member_id', $memberId)->first();
+                    if (!$wallet) throw new Exception('用户不存在', HttpStatus::CUSTOM_ERROR);
+                    $availableBalance = bcadd($wallet->available_balance, $amount, 10);
+                    BalanceLogService::addLog($memberId, $amount, $wallet->available_balance, $availableBalance, $changeType, null, $remark);
+                    $wallet->available_balance = $availableBalance;
+                    $wallet->save();
                 }
-                $info->status = $params['status'];
-                $info->remark = $remark;
-                $info->save();
-            } else {
-                //充值成功
-                $info->status = $params['status'];
-                $info->remark = $remark;
-                $info->state = 1;
-                $info->save();
-
-                $memberId = $info->member_id;
-                $amount = $info->amount;
-                $changeType = '人工充值';
-                $wallet = Wallet::where('member_id', $memberId)->first();
-                if (!$wallet) throw new Exception('用户不存在', HttpStatus::CUSTOM_ERROR);
-                $availableBalance = bcadd($wallet->available_balance, $amount, 10);
-                BalanceLogService::addLog($memberId, $amount, $wallet->available_balance, $availableBalance, $changeType, null, $remark);
-                $wallet->available_balance = $availableBalance;
-                $wallet->save();
-
             }
+            
             DB::commit();
         } catch (ValidationException $e) {
             DB::rollBack();
@@ -124,6 +128,7 @@ class PaymentOrder extends Controller
     {
         DB::beginTransaction();
         try {
+            
             $validate = [
                 'ids' => ['required', 'array', 'min:1', 'max:20'],
                 'ids.*' => ['required', 'integer', 'min:1'],

+ 28 - 1
app/Http/Controllers/admin/SportGame.php

@@ -5,6 +5,7 @@ namespace App\Http\Controllers\admin;
 use App\Http\Controllers\Controller;
 use App\Models\SportGame as SportGameModel;
 use App\Models\SportGameplay;
+use App\Models\SportGameLog;
 use Exception;
 use App\Constants\HttpStatus;
 
@@ -16,7 +17,7 @@ class SportGame extends Controller
     public function list()
     {
         try {
-            $list = SportGameModel::with(['children'])->field('id,name,name_en,end_time,is_locked')->get()->toArray();
+            $list = SportGameModel::with(['children'])->select(['id','name','name_en','end_time','is_locked'])->get()->toArray();
         } catch (Exception $e) {
             return $this->error(HttpStatus::CUSTOM_ERROR,$e->getMessage());
         }
@@ -56,4 +57,30 @@ class SportGame extends Controller
         }
     }
 
+    //开奖
+    public function openCode() { 
+        try {
+            $params = request()->validate([
+                'id' => ['required','integer'],
+            ]);
+            $id = $params['id'];
+            $info = SportGameModel::find($id);
+            if (!$info) {
+                return $this->error(HttpStatus::NOT_FOUND,'数据不存在');
+            }
+            //记录开奖日志
+            $log = new SportGameLog();
+            $log->game_id = $info->game_id;
+            $log->gameplay_id = $info->id;
+            $log->name = $info->name;
+            $log->name_en = $info->name_en;
+            $log->save();
+            
+            //订单结算
+            return $this->success();
+        } catch (Exception $e) {
+            return $this->error(HttpStatus::CUSTOM_ERROR,$e->getMessage());
+        }
+    }
+
 }

+ 2 - 1
app/Http/Controllers/admin/SportGameOrder.php

@@ -114,6 +114,7 @@ class SportGameOrder extends Controller
             DB::beginTransaction();
             $params = request()->validate([
                 'id' => ['required', 'array', 'min:1'],
+                'remark' => ['nullable', 'string'],
             ]);
             $orderList = SportGameOrderModel::whereIn('id', $params['id'])->get();
             foreach ($orderList as $order) {
@@ -121,7 +122,7 @@ class SportGameOrder extends Controller
                     continue;
                 }
                 
-                $order->status = 4;
+                $order->status = 3;
                 $order->updated_at = time();
                 $order->save();
 

+ 11 - 0
app/Http/Controllers/api/Wallet.php

@@ -358,6 +358,17 @@ class Wallet extends BaseController
             ]);
             $member_id = request()->user->member_id;
             $user = User::where('member_id', $member_id)->first();
+
+            //检验是否有待处理的提现订单
+            if ($params['channel'] == 'rgtx') {
+                $count = PaymentOrder::where('type', PaymentOrderService::TYPE_SELF_PAYOUT)
+                            ->where('member_id', $member_id)
+                            ->whereIn('status', [0,1,4,5])
+                            ->count();
+                if ($count > 0) {
+                    throw new Exception(lang("您已有1笔提现订单正常处理中!"));
+                }
+            }
             if (empty($user->payment_password)) {
                 $error_code = 10011;
                 throw new Exception(lang("请先设置资金密码"));

+ 95 - 0
app/Jobs/SportGameOrderJob.php

@@ -0,0 +1,95 @@
+<?php
+
+
+namespace App\Jobs;
+
+use Illuminate\Bus\Queueable;
+use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Foundation\Bus\Dispatchable;
+use Illuminate\Queue\InteractsWithQueue;
+use Illuminate\Queue\SerializesModels;
+use Illuminate\Support\Facades\Log;
+use App\Models\SportGameOrder;
+use App\Models\Wallet;
+use App\Models\FundsRecord;
+use Illuminate\Support\Facades\DB;
+
+class SportGameOrderJob implements ShouldQueue
+{
+    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
+
+    /**
+     * 任务尝试次数
+     */
+    public $tries = 3;
+
+    /**
+     * 任务超时时间(秒)
+     */
+    public $timeout = 30;
+    
+    public $gameplayId = 0;
+
+    /**
+     * Create a new job instance.
+     *
+     * @return void
+     */
+    public function __construct(int $gameplayId)
+    {
+        $this->gameplayId = $gameplayId;
+    }
+
+    /**
+     * Execute the job.
+     *
+     * @return void
+     */
+    public function handle()
+    {
+        Log::error('开始执行足球游戏订单开奖结算任务: ' . now());
+        
+        //先把未中奖的标记为未中奖
+        SportGameOrder::where('gameplay_id', '<>', $this->gameplayId)->where('status', 0)->update(['status' => 1]);
+
+        $list = SportGameOrder::where('gameplay_id', $this->gameplayId)->where('status', 0)->get();
+        foreach ($list as $item) {
+            try {
+                DB::beginTransaction();
+                $item->status = 2;
+                $item->win_amount = bcmul($item->amount, $item->odds, 2);
+                $item->profit_and_loss = $item->win_amount - $item->amount;
+                $item->updated_at = now();
+                $item->save();
+
+                $walletInfo = Wallet::where('member_id', $item->member_id)->first();
+                if (!$walletInfo) continue;
+                
+                $before = $walletInfo->available_balance;
+                $after = bcadd($walletInfo->available_balance, $item->win_amount, 2);
+                $walletInfo->available_balance = $after;
+                $walletInfo->save();
+
+                FundsRecord::addData([
+                    'change_type' => '足球游戏中奖',
+                    'amount' => $item->win_amount,
+                    'before_balance' => $before,
+                    'after_balance' => $after,
+                    'member_id' => $item->member_id,
+                    'related_id' => $item->id,
+                    'remark' => '足球游戏中奖',
+                ]);
+                DB::commit();
+            } catch (\Exception $e) {
+                DB::rollBack();
+                Log::error('足球游戏订单开奖结算任务执行异常: ' . $e->getMessage());
+            }
+        }
+    }
+
+    // 可选:失败处理
+    public function failed(\Throwable $exception)
+    {
+        Log::error('足球游戏订单开奖结算任务执行异常: ' . $exception->getMessage());
+    }
+}

+ 1 - 1
app/Models/ActivityReward.php

@@ -20,7 +20,7 @@ class ActivityReward extends BaseModel
     const STATUS_DOWN = 0;
 
     protected $table = 'activity_rewards';
-    protected $fillable = ['title', 'sub_title', 'detail_image', 'start_time', 'end_time', 'status','type','lang','content', 'params','pc_image'];
+    protected $fillable = ['title', 'sub_title', 'detail_image', 'start_time', 'end_time', 'status','type','lang','content', 'params','pc_image','detail_banner', 'pc_banner'];
 
     public function activityUser(): HasMany
     {

+ 6 - 0
app/Models/SportGame.php

@@ -1,9 +1,15 @@
 <?php
 
 namespace App\Models;
+use App\Models\SportGameplay;
 
 class SportGame extends BaseModel
 {
     protected $table = 'sport_game';
     protected $fillable = [ 'name', 'name_en', 'end_time','is_locked'];
+    
+    public function children()
+    {
+        return $this->hasMany(SportGameplay::class, 'game_id', 'id')->select(['id','game_id','name','name_en','is_locked', 'odds','mininum', 'maxinum']);
+    }
 }

+ 9 - 0
app/Models/SportGameLog.php

@@ -0,0 +1,9 @@
+<?php
+
+namespace App\Models;
+
+class SportGameLog extends BaseModel
+{
+    protected $table = 'sport_game_log';
+    protected $fillable = ['game_id', 'gameplay_id', 'name', 'name_en'];
+}

+ 4 - 1
app/Services/ActivityRewardService.php

@@ -95,7 +95,10 @@ class ActivityRewardService extends BaseService
             $params['detail_image'] = Util::replacePartInUrl($params['detail_image']);
         if (isset($params['pc_image']))
             $params['pc_image'] = Util::replacePartInUrl($params['pc_image']);
-
+        if (isset($params['detail_banner']))
+            $params['detail_banner'] = Util::replacePartInUrl($params['detail_banner']);
+        if (isset($params['pc_banner']))
+            $params['pc_banner'] = Util::replacePartInUrl($params['pc_banner']);
 
         if (!empty($params['id'])) {
             $info = static::findOne(['id' => $params['id']]);

+ 1 - 0
lang/en/messages.php

@@ -465,4 +465,5 @@ return [
     '请选择提现类型' => 'Please Select Withdrawal Type',
     '不支持此充值方式' => 'Not Support This Recharge Type', 
     '不支持此提现方式' =>  'Not Support This Withdrawal Type',
+    '您已有1笔提现订单正常处理中!' => 'You Have 1 Withdrawal Order In Normal Processing!',
 ];

+ 1 - 0
lang/vi/messages.php

@@ -465,4 +465,5 @@ return [
     '请选择提现类型' => 'Vui lòng chọn loại rút tiền',
     '不支持此充值方式' => 'Không hỗ trợ phương thức nạp này',
     '不支持此提现方式' => 'Không hỗ trợ phương thức rút này',
+    '您已有1笔提现订单正常处理中!' => 'Bạn đã có 1 lệnh rút tiền đang được xử lý!',
 ];

+ 1 - 0
lang/zh/messages.php

@@ -465,4 +465,5 @@ return [
     '请选择提现类型' => '请选择提现类型',
     '不支持此充值方式' => '不支持此充值方式',
     '不支持此提现方式' => '不支持此提现方式',
+    '您已有1笔提现订单正常处理中!' => '您已有1笔提现订单正常处理中!',
 ];