Browse Source

赛事结束追加写入结算通知表

彭俊 6 years ago
parent
commit
e03ed4932a

+ 49 - 1
app/Http/Controllers/Admin/SportsbqController.php

@@ -195,6 +195,21 @@ class SportsbqController extends Controller {
 		return $jieguo;
 	}
 
+    //查询赛事结果
+    function resultLog(Req $req){
+        $match_id = $req->match_id;
+        $list = \App\Models\Stbqresultlog::leftJoin('system_user', 'user_id', '=', 'system_user.id')
+            ->select('st_bq_result_log.*', 'system_user.loginname')->where('match_id', $match_id)->orderBy('id', 'desc')->get();
+        foreach ($list as $key=>$value){
+            $list[$key]['match_score_t'] = json_decode($value['match_score_t'], true);
+        }
+        $result =array(
+            'status' => 200,
+            'list' => $list
+        );
+        echo json_encode($result);die;
+    }
+
 	function onlyresult(Req $req){
 		$match_id = $req->matchid;
 		$newapp = \App\Models\Stbqresult::where('match_id', $match_id)->first();
@@ -250,7 +265,21 @@ class SportsbqController extends Controller {
         );
 
 		\App\Models\Stbqresult::where('match_id', $match_id)->update(["match_score_t"=>json_encode($uscore)]);
-       
+
+		//添加赛事结果记录
+        $lastLog = \App\Models\Stbqresultlog::where([
+            ['match_id', $match_id],
+            ['type', 1]
+        ])->orderBy('id', 'desc')->first();
+        if(empty($lastLog) || $lastLog['match_score_t'] != json_encode($uscore)){
+            \App\Models\Stbqresultlog::insert([
+                'match_id' => $match_id,
+                'match_score_t' => json_encode($uscore),
+                'user_id' => session('adminInfo.admin_id'),
+                'create_at' => now()
+            ]);
+        }
+
         return responseToJson(1);
 	}
 
@@ -277,6 +306,25 @@ class SportsbqController extends Controller {
 		$twoapp->updatestatus('match_id',$match_id,['status'=>2]);//修改赛事状态
 		$newapp->updatestatus('match_id',$match_id,['status'=>2]);//修改结果状态
 
+        //添加赛事结果比较记录
+        $lastLog = \App\Models\Stbqresultlog::where([
+            ['match_id', $match_id],
+            ['type', 2]
+        ])->orderBy('id', 'desc')->first();
+
+        if(empty($lastLog) || !(
+            $lastLog['u_home_score'] == $data['u_home_score']
+            && $lastLog['u_guest_score'] == $data['u_guest_score']
+            && $lastLog['guest_score'] == $data['guest_score']
+            && $lastLog['home_score'] == $data['home_score']
+            )){
+            $logData = $data;
+            $logData['type'] = 2;
+            $logData['match_id'] = $match_id;
+            $logData['user_id'] = session('adminInfo.admin_id');
+            $logData['create_at'] = now();
+            \App\Models\Stbqresultlog::insert($logData);
+        }
 		return responseToJson(1);
 	}
 

+ 34 - 45
app/Http/Controllers/Api/WriteSportsController.php

@@ -1921,6 +1921,8 @@ class WriteSportsController extends BaseController
 
             //获取 球类代码
             $game_code = $data['game_code'];
+            //获取球类 名称
+            $gameName = gameModel::getGameName($game_code);
             //获取 数据源 
             $source = $data['source'];
 
@@ -1937,54 +1939,41 @@ class WriteSportsController extends BaseController
                 ->whereIn('others_match_id', $others_match_ids)
                 ->get()->toArray();
             if (empty($local_match)) throw new \Exception(Response::generate('', Response::MATCHID_NULL));
-            //更新状态字段
-            if($game_code == 'zq'){
-                foreach ($local_match as $k => $v) {
-                    foreach($data['data'] as $kk =>$vv){
-                        if($v['others_match_id'] == $vv['match_id']){
-                            $set_status = [
-                                'status' => $vv['status'],
-                                'is_rollball' => $vv['is_rollball'],
-                                'is_today' => $vv['is_today'],
-                                'is_morningplate' => $vv['is_morningplate'],
-                                'is_stringscene' => $vv['is_stringscene'],
-                                'is_horn' => $vv['is_horn'],
-                                'utime' => date('Y-m-d H:i:s'),
-                            ];
-                            $ret = $model['model_match']::where(['id' => $v['match_id']])
-                                ->update($set_status);
-                            if ($ret < 1) throw new \Exception(Response::generate(gameModel::getGameName($game_code) . '赛事-match_id:' . $v['others_match_id'], Response::UPSTATUS_ERROR));
+
+            //取值 更新字段
+            foreach ($local_match as $k => $v) {
+                foreach($data['data'] as $kk =>$vv){
+                    if($v['others_match_id'] == $vv['match_id']){
                         
-                            //===如果赛事已结束 新增 更新 赛事结果===
-                            if($vv['status'] == 2){
-                                $this->match_result($game_code, $v['match_id']);
-                            }
-                            //===end===
+                        $set_status = [
+                            'status' => $vv['status'],
+                            'is_rollball' => $vv['is_rollball'],
+                            'is_today' => $vv['is_today'],
+                            'is_morningplate' => $vv['is_morningplate'],
+                            'is_stringscene' => $vv['is_stringscene'],
+                            'utime' => date('Y-m-d H:i:s'),
+                        ];
+
+                        //如果是足球 追加角球状态
+                        if($game_code == 'zq'){
+                            $set_status['is_horn'] =  $vv['is_horn'];
                         }
-                    }
-                }
-            }else{
-                foreach ($local_match as $k => $v) {
-                    foreach($data['data'] as $kk =>$vv){
-                        if($v['others_match_id'] == $vv['match_id']){
-                            $set_status = [
-                                'status' => $vv['status'],
-                                'is_rollball' => $vv['is_rollball'],
-                                'is_today' => $vv['is_today'],
-                                'is_morningplate' => $vv['is_morningplate'],
-                                'is_stringscene' => $vv['is_stringscene'],
-                                'utime' => date('Y-m-d H:i:s'),
-                            ];
-                            $ret = $model['model_match']::where(['id' => $v['match_id']])
-                                ->update($set_status);
-                            if ($ret < 1) throw new \Exception(Response::generate(gameModel::getGameName($game_code) . '赛事-match_id:' . $v['others_match_id'], Response::UPSTATUS_ERROR));
-                        
-                            //===如果赛事已结束 新增 更新 赛事结果===
-                            if($vv['status'] == 2){
-                                $this->match_result($game_code, $v['match_id']);
-                            }
-                            //===end===
+                        $ret = $model['model_match']::where(['id' => $v['match_id']])
+                            ->update($set_status);
+                        if ($ret < 1) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $v['others_match_id'], Response::UPSTATUS_ERROR));
+                    
+                        //===如果赛事已结束===
+                        if($vv['status'] == 2){
+                            // 新增 更新 赛事结果
+                            $this->match_result($game_code, $v['match_id']);
+                            //获取赛事开始时间
+                            $game_start_time = $model['model_result']::where(['match_id' => $v['match_id']])->first()->start_time;
+                            // 写入结算通知表 用于自动结算
+                            $Comendnotice = new \App\Models\Comendnotice();
+                            $ret_add = $Comendnotice->addcomendnotice($v['match_id'], $game_code, 0, $game_start_time);
+                            if ($ret_add != 1) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $v['others_match_id'], Response::ADD_NOTICE_ERR));
                         }
+                        //===end===
                     }
                 }
             }

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

@@ -77,6 +77,8 @@ class Response
      const UP_MONEY_ERR = 10048;
      //===订单数据更新失败===
      const UP_ORDER_ERR = 10049;
+     //===赛事结束写入结算通知表失败===
+     const ADD_NOTICE_ERR = 10050;
 
 
 
@@ -150,6 +152,9 @@ class Response
          //===订单数据更新失败===
          self::UP_ORDER_ERR =>'订单数据更新失败',
 
+         //===赛事结束写入结算通知表失败===
+         self::ADD_NOTICE_ERR=>'赛事结束写入结算通知表失败',
+
     ];
 
     public static function getMsg($code)

File diff suppressed because it is too large
+ 8 - 1
resources/views/admin/Sportsbq/outcome.blade.php


Some files were not shown because too many files changed in this diff