浏览代码

Merge branch 'master' of http://47.76.126.2:3000/seven/bot-28

Ken 1 周之前
父节点
当前提交
4502f46554
共有 5 个文件被更改,包括 93 次插入1 次删除
  1. 14 0
      app/Http/Controllers/admin/Issue.php
  2. 2 0
      app/Models/Issue.php
  3. 31 0
      app/Services/BetService.php
  4. 45 1
      app/Services/IssueService.php
  5. 1 0
      routes/admin.php

+ 14 - 0
app/Http/Controllers/admin/Issue.php

@@ -92,6 +92,20 @@ class Issue extends Controller
 
     }
 
+    // 开奖失败
+    public function failure()
+    {
+        $id = request()->input('id');
+        if (!$id) {
+            return $this->error(HttpStatus::VALIDATION_FAILED, '参数错误');
+        }
+        $ret = IssueService::lotteryDrawFail($id);
+        if ($ret['code'] == IssueService::NOT) {
+            return $this->error($ret['code'], $ret['msg']);
+        }
+        return $this->success([], $ret['msg']);
+    }
+
     /**
      * @description: 开始
      * @return {*}

+ 2 - 0
app/Models/Issue.php

@@ -56,12 +56,14 @@ class Issue extends Authenticatable
     const STATUS_BETTING = 1;
     const STATUS_CLOSE = 2;
     const STATUS_DRAW = 3;
+    const STATUS_FAIL = 4;
 
     public static $STATUS = [
         0 => '草稿',
         1 => '投注中',
         2 => '封盘',
         3 => '开奖',
+        4 => '失败',
     ];
 
 

+ 31 - 0
app/Services/BetService.php

@@ -604,6 +604,37 @@ class BetService extends BaseService
         return $msg;
     }
 
+
+    /**
+     * @description: 开奖失败退回投注的
+     * @param {*} $issue_no
+     * @return {*}
+     */    
+    public static function betFail($issue_no)
+    {
+        $list = self::findAll(['issue_no' => $issue_no, 'status' => self::model()::STATUS_STAY]);
+        foreach ($list->toArray() as $k => $v) {
+            $profit = $v['amount'];
+            WalletService::updateBalance($v['member_id'], $profit);
+
+            $walletInfo = WalletService::findOne(['member_id' => $v['member_id']]);
+            $balance = $walletInfo['available_balance'];
+
+            BalanceLogService::addLog($v['member_id'], $profit, $balance, ($balance + $profit), '中奖', $v['id'], '');
+
+            $text = $issue_no . "期开奖失败 \n";
+            $text .= "投注类型:{$v['keywords']} \n";
+            $text .= "投注金额:{$v['amount']} \n";
+            $text .= "投注的资金已退回您的钱包 \n";
+
+            self::asyncSendMessage($v['member_id'],$text);
+            $item = [];
+            $iem['status'] = self::model()::STATUS_SETTLED;
+            self::model()::where('id', $v['id'])->update($item);
+        }
+
+    }
+
     /**
      * @description: 中奖结算
      * @param {*} $issue_no

+ 45 - 1
app/Services/IssueService.php

@@ -238,6 +238,50 @@ class IssueService extends BaseService
         return ['code' => self::YES, 'msg' => '封盘成功'];
     }
 
+    /**
+     * @description: 开奖失败
+     * @param {*} $id
+     * @return {*}
+     */    
+    public static function lotteryDrawFail($id)
+    {
+
+        $result = false;
+        $msg['code'] = self::NOT;
+        $msg['msg'] = '';
+        DB::beginTransaction();
+        try {
+
+            // 更新
+            $info = self::findOne(['id' => $id]);
+            if (!$info) {
+                $msg['msg'] = '期号不存在!';
+            } else {
+                $params['status'] = self::model()::STATUS_FAIL;
+                $result = $info->update($params);
+
+                BetService::betFail($info->issue_no);
+            }
+
+            DB::commit();
+            return ['code' => self::YES, 'msg' => '投注已退回'];
+        } catch (\Exception $e) {
+            DB::rollBack();
+            return ['code' => self::NOT, 'msg' => '投注退回失败'];
+        }
+        
+
+
+        if ($result) {
+            $msg['code'] = self::YES;
+            $msg['msg'] = '设置成功';
+        } else {
+            $msg['msg'] = empty($msg['msg']) ? '操作失败' : $msg['msg'];
+        }
+
+        return $msg;
+    }
+
     /**
      * @description: 开奖
      * @param {*} $id
@@ -253,7 +297,7 @@ class IssueService extends BaseService
             return ['code' => self::NOT, 'msg' => '期号不存在'];
         }
 
-        if ($info->status != self::model()::STATUS_CLOSE) {
+        if ($info->status == self::model()::STATUS_DRAW) {
             return ['code' => self::NOT, 'msg' => '期号状态不正确'];
         }
 

+ 1 - 0
routes/admin.php

@@ -80,6 +80,7 @@ Route::middleware(['admin.jwt'])->group(function () {
             Route::post('/submit', [Issue::class, 'store']);
             Route::post('/betting', [Issue::class, 'betting']);
             Route::post('/close', [Issue::class, 'close']);
+            Route::post('/failure', [Issue::class, 'failure']); 
             Route::post('/lotteryDraw', [Issue::class, 'lotteryDraw']); // 开奖
             Route::post('/delete', [Issue::class, 'destroy']); // 删除
         });