彭俊 %!s(int64=6) %!d(string=hai) anos
pai
achega
16f7a2cb99

+ 56 - 0
app/Http/Controllers/Api/WriteSportsController.php

@@ -95,6 +95,14 @@ class WriteSportsController extends BaseController
         return $ret;
     }
 
+    //更新投注数据接口
+    public function upOrder(Req $data){
+        $ret = $this->upOrder_v1($data);
+        return $ret;
+
+    }
+
+
     /*
      * 用户 用户 token
      */
@@ -2049,6 +2057,54 @@ class WriteSportsController extends BaseController
         }
     }
 
+    /**
+     * 更新投注数据
+     */
+    public function upOrder_v1($data){
+         //验证token
+         $user = new \App\Models\System_user;
+         if (empty($data->token)) return Response::generate('未获取到token:', Response::TOKEN_ERR);
+         $token = $user::where(['token' => $data->token])->value('token');
+         if (empty($token)) return Response::generate('token验证不通过:', Response::TOKEN_ERR);
+ 
+         try {
+             //开启事务
+             DB::beginTransaction();
+             //获取待更新赛事
+             $obt = $data->data;
+ 
+             //请求 数据 为空
+             if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
+             $data = $this->getAddData($obt);
+             //不是更新投注数据
+             if ($data['title'] != 'up_order_data') throw new \Exception(Response::generate('不是更新投注数据', Response::ABNORMAL));
+             //获取订单类型 1 单式 2串式
+             $order_type = $data['order_type'];
+             //获取订单号
+             $order_id = $data['order_id'];
+             //获取订单下赛事投注数据
+             $order_match = $data['matchData'];
+
+             if(empty($order_type) || empty($order_id) || empty($order_match)) throw new \Exception( Response::generate('',Response::ABNORMAL));
+
+             //更新投注数据
+             $SportsNoteList = new SportsNoteListModel();
+             $SportsNoteList->upOrder($order_type,$order_id,$order_match); 
+            //提交事务
+            DB::commit();
+            //写请求数据 日志记录
+            if ($this->isRecord) commonFunction::SET_SPORTS_RECORD('all', $data, $data['title'], Response::success());
+            return Response::success();
+        } catch (\Exception $e) {
+            //回滚事务
+            DB::rollBack();
+            //写请求数据 日志记录
+            if ($this->isRecord) commonFunction::SET_SPORTS_RECORD('all', $data, $data['title'], $e->getMessage());
+            return $e->getMessage();
+        }
+
+    }
+
     /*
      * 验证所属 联赛 是否存在
      */

+ 1 - 0
app/Http/Middleware/VerifyCsrfToken.php

@@ -27,6 +27,7 @@ class VerifyCsrfToken extends Middleware
         'HandleOrder',
         'HandleMatch',
         'HandleOrderInvalid',
+        'upOrder',
         //'upImg',
         //
     ];

+ 26 - 0
app/Http/Response/Response.php

@@ -82,6 +82,19 @@ class Response
      //===管理员账号或密码错误==
      const USER_ERR = 10051;
 
+     //===订单类型错误===
+     const ORDER_TYPE_ERR =10052;
+     //===订单不存在===
+     const ORDER_NULL = 10053;
+     //===订单数据更新失败===
+     const ORDER_UP_ERR = 10054;
+     //===订单详情数据更新失败===
+     const ORDER_UP_XQ_ERR = 10055;
+     //===订单状态异常===
+     const ORDER_STATUS_ERR = 10056;
+     //===待处理===
+     const WAIT_FOR = 10056;
+
 
 
     private static $errorMsgs = [
@@ -160,6 +173,19 @@ class Response
          //===管理员账号或密码错误===
          self::USER_ERR =>'管理员账号或密码错误',
 
+         //===订单类型错误===
+         self::ORDER_TYPE_ERR =>'订单类型错误',
+         //===订单不存在===
+         self::ORDER_NULL =>'订单不存在',
+         //===订单数据更新失败===
+         self::ORDER_UP_ERR =>'订单数据更新失败',
+         //===订单详情数据更新失败===
+         self::ORDER_UP_XQ_ERR =>'订单详情数据更新失败',
+         //===订单状态异常===
+         self::ORDER_STATUS_ERR =>'订单状态异常',
+         //===待处理===
+         self::WAIT_FOR =>'待处理',
+
     ];
 
     public static function getMsg($code)

+ 66 - 0
app/Models/SportsNoteList.php

@@ -2481,4 +2481,70 @@ class SportsNoteList extends BaseModel
         
           return 1;
     }
+
+    /**
+     * 更新投注数据
+     * $order_type  int订单类型 1单式 2串式
+     * $order_id str 订单id
+     * $order_match arr 投注赛事数据
+     */
+    public function upOrder($order_type='',$order_id='',$order_match=[]){
+        //处理单式注单
+        if($order_type == 1){
+            //球类代码
+            $game_code = $order_match[0]['game_code'];
+            //赛事id
+            $match_id = $order_match[0]['match_id'];
+            //投注玩法代码
+            $odds_code = $order_match[0]['odds_code'];
+            //投注赔率值
+            $odds = $order_match[0]['odds'];
+            //投注条件
+            $condition = $order_match[0]['condition'];
+
+            //拼接 投注 赛事查询条件
+            $where_match = [
+                ['bet_type','=',$order_type],
+                ['order_id','=',$order_id],
+                ['game_code','=',$game_code],
+                ['odds_code','=',$odds_code],
+            ];
+            //订单查询条件
+            $where_order = [
+                ['order_id','=',$order_id],
+            ];
+
+            //获取订单数据
+            $orderData = $this->where($where_order)->first();
+            //订单不存在
+            if(empty($orderData)) throw new \Exception(Response::generate('', Response::ORDER_NULL));
+            //订单不是投注状态
+            if($orderData->status != 1) throw new \Exception(Response::generate('订单状态:$orderData->status;', Response::ORDER_STATUS_ERR));
+            //根据新的赔率计算预期中奖金额
+            $orderData->prize_money = $orderData->money * $odds;
+            $orderData->remark = '模拟第三方投注,修正订单';
+            if(!$orderData->save()) throw new \Exception(Response::generate('', Response::ORDER_UP_ERR));
+
+            //更新投注详情数据
+            $match_up = [
+                'utime'=>date("Y-m-d H:i:s", time()),//更新时间
+                'condition'=>$condition,//投注条件
+                'odds' =>$odds,//投注赔率
+            ];
+            $ret_money_buy_match = \App\Models\MoneyBuyMatch::where('order_id',$order_id)->update($match_up);
+            //订单详情更新失败
+            if($ret_money_buy_match < 1)  throw new \Exception(Response::generate('', Response::ORDER_UP_XQ_ERR));
+        }
+        //处理串式订单
+        else if($order_type == 2){
+            throw new \Exception(Response::generate('串式订单:', Response::WAIT_FOR));
+
+        }
+        //订单类型错误
+        else{
+            throw new \Exception(Response::generate('', Response::ORDER_TYPE_ERR));
+        }
+
+        return 1;
+    }
 }

+ 4 - 0
routes/web.php

@@ -64,6 +64,10 @@ Route::post('/setBroadCast', function () {
 Route::post('/setResultExpress', function () {
     return appExec('api', 'WriteSports', 'setResultExpress');
 });
+//更新订单数据
+Route::post('/upOrder', function () {
+    return appExec('api', 'WriteSports', 'upOrder');
+});
 //写入危险球数据
 Route::post('/setMatchWarn', function () {
     return appExec('api', 'WriteSports', 'setMatchWarn');