seven 2 周之前
父节点
当前提交
a032eb3b73
共有 3 个文件被更改,包括 59 次插入1 次删除
  1. 14 0
      app/Http/Controllers/admin/Issue.php
  2. 2 0
      app/Models/Issue.php
  3. 43 1
      app/Services/IssueService.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 => '失败',
     ];
 
 

+ 43 - 1
app/Services/IssueService.php

@@ -238,6 +238,48 @@ 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);
+            }
+
+            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 +295,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' => '期号状态不正确'];
         }