Kaynağa Gözat

异常处理

彭俊 6 yıl önce
ebeveyn
işleme
fe116b3d05

+ 784 - 0
app/Http/Controllers/Admin/CheckRollingController.php

@@ -0,0 +1,784 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Jonlin
+ * Date: 2019/4/9
+ * Time: 9:11
+ */
+
+namespace App\Http\Controllers\Admin;
+
+use App\Http\Controllers\Controller;
+use Illuminate\Http\Request as Req;
+use Illuminate\Support\Facades\DB;
+Use App\Lib\Settlement\SettlementOrder;
+Use App\Lib\Settlement\SettlementWinFail;
+use App\Models;
+use Request;
+
+/**
+ *
+ */
+class CheckRollingController extends Controller
+{
+
+    public function notelist(Req $req)
+    {
+        $request['name_chinese'] = isset($req->name_chinese) ? trim($req->name_chinese) : null;
+        $request['sureblurs'] = isset($req->sureblurs) ? $req->sureblurs : 'on';
+        $request['account'] = isset($req->account) ? trim($req->account) : null;
+        $request['star_time'] = isset($req->star_time) ? trim($req->star_time) : null;
+        $request['end_time'] = isset($req->end_time) ? trim($req->end_time) : null;
+        $request['order_id'] = isset($req->order_id) ? trim($req->order_id) : null;
+        $request['match_id'] = isset($req->match_id) ? trim($req->match_id) : null;
+        $request['status'] = isset($req->status) ? trim($req->status) : '-1';
+        $request['order_status'] = isset($req->order_status) ? trim($req->order_status) : '-1';
+        $request['type'] = isset($req->type) ? trim($req->type) : 'zq';
+        $dt = \App\Lib\DataTable\DataTable::init();
+        $dt->setDataSource('/admin/CheckRolling/getinfo');
+        $dt->setLang('sportsnotelist');
+        //$dt->addColsFields('id', array('templet' => '#userdetail', 'sort' => true, 'width' => 80));
+        $dt->addColsFields('match_id_order', array('sort' => true, 'width' => 200));
+        $dt->addColsFields('league', array('templet' => '#userdetail', 'sort' => false, 'width' => 100));
+        $dt->addColsFields('home_guest', array('templet' => '#userdetail', 'sort' => false, 'width' => 80));
+        $dt->addColsFields('content', array('templet' => '#userdetail', 'sort' => false, 'width' => 250));
+        $dt->addColsFields('money', array('templet' => '#userdetail', 'sort' => false, 'width' => 80));
+        $dt->addColsFields('water_return', array('templet' => '#userdetail', 'sort' => false, 'width' => 70));
+        $dt->addColsFields('prize_money', array('templet' => '#userdetail', 'sort' => false, 'width' => 80));
+        $dt->addColsFields('result', array('templet' => '#userdetail', 'sort' => false, 'width' => 70));
+        $dt->addColsFields('money_match_time', array('templet' => '#userdetail', 'sort' => false, 'width' => 200));
+        $dt->addColsFields('order_status', array('sort' => false, 'width' => 80));
+        $dt->addColsFields('account_money', array('templet' => '#userdetail', 'sort' => false, 'width' => 110));
+        $dt->addColsFields('game_status', array('templet' => '#game_status', 'sort' => false, 'width' => 90));
+        //$arr[] = 'view';
+//        if (checkRriv('/admin/CheckRolling/edit')) {
+//            $arr[] = 'edit';
+//        }
+//        $dt->setToolBar($arr, array('width' => 70));
+        $dt->enableCheckBox();//var_dump($request['type']);
+        return view('sports/sports_notelist', $dt->render($request));
+    }
+
+    //修改冠军单订单结果
+    function orderupgj(Req $req)
+    {
+        $id = $req->id;//37
+        $orderid = $req->order;//S20190916094723915270970
+        if (intval($id) < 1) {
+            return -1;
+        }
+
+        $data = \App\Models\SoccerLeague::where('id', $id)->first();
+
+        $odds_code = \App\Models\SoccerOdds::where('lg_id', $id)->where('type', 1)->where('odds_code', '!=', '')->select('odds_code')->distinct()->get()->toArray();//赔率表
+
+        for ($i = 0; $i < count($odds_code); $i++) {
+            $allteam[] = \App\Models\SoccerOdds::where('odds_code', $odds_code[$i]['odds_code'])->where('lg_id', $id)->where('type', 1)->select('team')->distinct()->get()->toArray();
+        }
+
+        $data = $data->toArray();
+        $isdisplay = \App\Models\Stwqleagueresult::where(['lg_id' => $id, 'status' => 1])->select("game_name")->distinct()->get()->toArray();
+        $idisplay = array_column($isdisplay, 'game_name');
+        $displays = implode(",", $idisplay);//转换成字符串
+
+        //新增纪录
+        foreach ($odds_code as $k => $v) {
+            foreach ($allteam[$k] as $kk => $vv) {
+                $name = $v['odds_code'];
+                $isteam = $allteam[$k][$kk]['team'];
+                $res = \App\Models\Stwqleagueresult::where(['lg_id' => $id, 'game_name' => $name, 'result' => $isteam])->first();
+
+                $addresult = [
+                    'lg_id' => $id,
+                    'game_name' => $name,
+                    'result' => $isteam,
+                    'ctime' => date('Y-m-d H:i:s', time()),
+                    'status' => 0,
+                    'updated_at' => date('Y-m-d H:i:s', time()),
+                ];
+
+                if (empty($res)) {
+                    \App\Models\Stwqleagueresult::insert($addresult);
+                }
+
+            }
+        }
+        $orderjg = \App\Models\SportsNoteList::where(['order_id' => $orderid])->select("single_result")->first();
+        $orderjg = json_decode($orderjg['single_result'], true);
+
+        $data['allteam'] = $allteam;
+        $data['odds_code'] = $odds_code;
+        $data['displays'] = $displays;
+        $data['isdisplay'] = $isdisplay;
+        $data['orderjg'] = $orderjg;
+        $data['orderid'] = $orderid;
+        $data['lg_id'] = $id;
+
+        return view('sports/orderupgj', $data);
+    }
+
+    //修改冠军单订单结果提交
+    function ajaxtj(Req $req)
+    {
+        $isstatus = $req->isstatus;//更新
+        $order = $req->order;
+
+        if ($isstatus) {
+            $gjresult = array(
+                'lg_id' => $req->lg_id ? $req->lg_id : '',
+                'game_name' => $req->odds_code ? $req->odds_code : '',
+                'result' => $req->team ? $req->team : '',
+                'updatetime' => date("Y-m-d H:i:s", time()),
+            );
+        } else {
+            $gjresult = array(
+                'lg_id' => '',
+                'game_name' => '',
+                'result' => '',
+            );
+        }
+
+        \App\Models\SportsNoteList::where(['order_id' => $order])->update(['single_result' => json_encode($gjresult, JSON_UNESCAPED_UNICODE)]);
+
+        return responseToJson(1);
+    }
+
+    function info()
+    {
+        $page = Request::has('page') ? Request::get('page') : '';
+        $list = Request::has('limit') ? Request::get('limit') : 10;
+        $account = Request::get('account') ? Request::get('account') : '';
+        $star_time = Request::get('star_time') ? Request::get('star_time') . ' 00:00:00' : '';
+        $end_time = Request::get('end_time') ? Request::get('end_time') . ' 23:59:59' : '';
+        $order_id = Request::get('order_id') ? Request::get('order_id') : '';
+        $match_id = Request::get('match_id') ? Request::get('match_id') : '';
+        $status = Request::has('status') ? Request::get('status') : '';
+        $order_status = Request::has('order_status') ? Request::get('order_status') : '';
+        $sureblur = Request::has('sureblurs') ? Request::get('sureblurs') : 'off';
+        $type = Request::has('type') ? Request::get('type') : 'zq';
+        $where = array();
+        //$where[] = array('money_buy_match.is_rolling', '=', 1);
+        $where[] = array('money_buy_simplex.roll_ratify', '=', 2);
+        if (!empty($account)) {
+            if (empty($sureblur) || $sureblur == 'off') {
+                $where[] = array('money_buy_simplex.account_name', 'like', '%' . $account . '%');
+            } else {
+                $where[] = array('money_buy_simplex.account_name', '=', $account);
+            }
+        }
+        if (!empty($star_time)) {
+            if (!empty($end_time)) {
+                $where[] = array('money_buy_simplex.money_time', '>', $star_time);
+                $where[] = array('money_buy_simplex.money_time', '<', $end_time);
+            } else {
+                $where[] = array('money_buy_simplex.money_time', '>', $star_time);
+            }
+        } else if (empty($star_time)) {
+            if (!empty($end_time)) {
+
+                $where[] = array('money_buy_simplex.money_time', '<', $end_time);
+            }
+        }
+        if (!empty($order_id)) {
+            $where[] = array('money_buy_simplex.order_id', $order_id);
+        }
+        if (!empty($match_id)) {
+            $where[] = array('money_buy_simplex.match_id', $match_id);
+        }
+        if ($status != -1) {
+            $where[] = array('money_buy_simplex.settle_status', '=', $status);
+        }
+        if ($order_status != -1) {
+            $where[] = array('money_buy_simplex.status', '=', $order_status);
+        }
+        $where[] = array('money_buy_simplex.game_code', $type);
+        $newapp = new \App\Models\SportsNoteList();
+        $data = $newapp->checkinfo($list, $page, $where, $type);
+        //$alldata = $newapp->join('money_buy_match','money_buy_match.order_id','=','money_buy_simplex.order_id')->where('money_buy_match.bet_type',1)->where('money_buy_match.is_rolling',1)->where('money_buy_match.game_code',$type)->distinct('money_buy_match.order_id')->count('money_buy_match.order_id');
+
+        return \App\Lib\DataTable\DataTable::init()->toJson($data['data'], $data['total'], 0, $where);
+        //return \App\Lib\DataTable\DataTable::init()->toJson($data['data'], $alldata, 0, $where);
+    }
+
+    public function search(Req $req)
+    {
+        $request['name_chinese'] = isset($req->name_chinese) ? trim($req->name_chinese) : null;
+        $request['sureblurs'] = isset($req->sureblurs) ? $req->sureblurs : 'on';
+        $request['account'] = isset($req->account) ? trim($req->account) : null;
+        $request['star_time'] = isset($req->star_time) ? trim($req->star_time) : null;
+        $request['end_time'] = isset($req->end_time) ? trim($req->end_time) : null;
+        $request['order_id'] = isset($req->order_id) ? trim($req->order_id) : null;
+        $request['match_id'] = isset($req->match_id) ? trim($req->match_id) : null;
+        $request['status'] = isset($req->status) ? trim($req->status) : '-1';
+        $request['order_status'] = isset($req->order_status) ? trim($req->order_status) : '-1';
+        $request['type'] = isset($req->type) ? trim($req->type) : 'zq';
+        $dt = \App\Lib\DataTable\DataTable::init();
+        $dt->setDataSource('/admin/CheckRolling/info');
+        $dt->setLang('sportsnotelist');
+        //$dt->addColsFields('id', array('templet' => '#userdetail', 'sort' => true, 'width' => 80));
+        $dt->addColsFields('match_id_order', array('sort' => true, 'width' => 200));
+        $dt->addColsFields('league', array('templet' => '#userdetail', 'sort' => false, 'width' => 100));
+        $dt->addColsFields('home_guest', array('templet' => '#userdetail', 'sort' => false, 'width' => 80));
+        $dt->addColsFields('content', array('templet' => '#userdetail', 'sort' => false, 'width' => 250));
+        $dt->addColsFields('money', array('templet' => '#userdetail', 'sort' => false, 'width' => 80));
+        $dt->addColsFields('water_return', array('templet' => '#userdetail', 'sort' => false, 'width' => 70));
+        $dt->addColsFields('prize_money', array('templet' => '#userdetail', 'sort' => false, 'width' => 80));
+        $dt->addColsFields('result', array('templet' => '#userdetail', 'sort' => false, 'width' => 70));
+        $dt->addColsFields('money_match_time', array('templet' => '#userdetail', 'sort' => false, 'width' => 200));
+        $dt->addColsFields('order_status', array('sort' => false, 'width' => 80));
+        $dt->addColsFields('account_money', array('templet' => '#userdetail', 'sort' => false, 'width' => 110));
+        $dt->addColsFields('roll_ratify', array('sort' => false, 'width' => 90));
+        //$arr[] = 'view';
+//        if (checkRriv('/admin/CheckRolling/edit')) {
+//            $arr[] = 'edit';
+//        }
+//        $dt->setToolBar($arr, array('width' => 70));
+        $dt->enableCheckBox();
+        return view('sports/sports_search', $dt->render($request));
+    }
+
+    //查询赛事结果
+    // function Sairesult(Req $req){
+    // $did = $req->did;
+    // $qlgame = $req->qlgame?$req->qlgame:'zq';
+    // $newapp = \App\Models\SportsNoteList::where('id', $did)->first();
+
+    // if($qlgame=='zq'){
+    //     if($newapp['match_id']){
+    //         $newre = new \App\Models\Stzqresult();
+    //         $teamname = $newre->matchjg($newapp['match_id']);
+    //     }else{
+    //         $teamname ='';
+    //     }
+    // }elseif($qlgame=='lq'){
+    //     if($newapp['match_id']){
+    //         $newre = new \App\Models\Stlqresult();
+    //         $teamname = $newre->matchjg($newapp['match_id']);
+    //     }else{
+    //         $teamname ='';
+    //     }
+    // }elseif($qlgame=='bq'){
+    //     if($newapp['match_id']){
+    //         $newre = new \App\Models\Stbqresult();
+    //         $teamname = $newre->matchjg($newapp['match_id']);
+    //     }else{
+    //         $teamname ='';
+    //     }
+    // }elseif($qlgame=='wq'){
+    //     if($newapp['match_id']){
+    //         $newre = new \App\Models\Stwqresult();
+    //         $teamname = $newre->matchjg($newapp['match_id']);
+    //     }else{
+    //         $teamname ='';
+    //     }
+    // }else{
+    //     $data = "参数错误";
+    // }
+
+    // $data =array(
+    //     'singleresult' => json_decode($newapp['single_result'],true),
+    //     'teamname' => $teamname,
+    // );
+    // return $data;
+    // }
+    // function Sairesult(Req $req){
+    //     $did = $req->did;
+    //     $model = \App\Models\SportsNoteList::where('id', $did)->first();
+    //     $pid = $model['match_id'];
+    //     $saisjg = \App\Models\Stzqresult::where('match_id',$pid)->first()->toArray();//赛事结果
+    //     $saisjg['corner_ball'] = json_decode($saisjg['corner_ball'],true);
+    //     $saisjg['first_score'] = json_decode($saisjg['first_score'],true);
+    //     $saisjg['penalty_card'] = json_decode($saisjg['penalty_card'],true);
+    //     $saisjg['warn_more'] = json_decode($saisjg['warn_more'],true);
+
+    // }
+
+    //结果添加
+    function addend(Req $req)
+    {
+        $did = $req->did;//59;//
+        $qlgame = $req->qlgame;//1;
+        $model = \App\Models\SportsNoteList::where('id', $did)->first();
+        $pid = $model['match_id'];
+
+        if ($qlgame == 1) {
+            if ($model['result_flag'] != 1) {
+                $saisjg = \App\Models\Stzqresult::where('match_id', $pid)->first()->toArray();//赛事结果
+                $saisjg['corner_ball'] = json_decode($saisjg['corner_ball'], true);
+                $saisjg['first_score'] = json_decode($saisjg['first_score'], true);
+                $saisjg['penalty_card'] = json_decode($saisjg['penalty_card'], true);
+                $saisjg['warn_more'] = json_decode($saisjg['warn_more'], true);
+
+                $model->single_result = json_encode([$saisjg], JSON_UNESCAPED_UNICODE);
+                $model->save();
+            }
+            $newm = \App\Models\SportsNoteList::where('id', $did)->first();
+            return $newm['single_result'];
+        } else {
+            $new = \App\Models\SportsNoteList::where('id', $did)->first();
+            $newa = json_decode($new['single_result'], true);
+            $newa[0]['home_score'] = $req->home_score;//主队进球
+            $newa[0]['guest_score'] = $req->guest_score;//客队进球
+            $newa[0]['all_goal'] = intval($req->guest_score) + intval($req->home_score);//总进球
+            $newa[0]['last_score'] = $req->lastscore ? $req->lastscore : '';//最后进球球队
+            $newa[0]['match_winer'] = $req->matchwiner ? $req->matchwiner : '';//赢球球队
+            $newa[0]['update_time'] = time();//更新时间
+            $newa[0]['u_guest_score'] = $req->u_guest_score;//上半场-主队进球数
+            $newa[0]['u_home_score'] = $req->u_home_score;//上半场-客队进球数
+            $newa[0]['penalty_card'] = array(
+                'home' => $req->homeallcard,
+                'guest' => $req->guestallcard,
+                'home_half' => $req->homehalfcard,
+                'guest_half' => $req->guesthalfcard,
+            );
+            $newa[0]['corner_ball'] = array(
+                'home' => $req->homeallcorner,
+                'guest' => $req->guestallcorner,
+                'home_half' => $req->homehalfcorner,
+                'guest_half' => $req->guesthalfcorner,
+            );
+            //最新进球
+            $newa[0]['first_score'] = array(
+                'teamscore' => $req->firstscore ? $req->firstscore : 0,//最先进球球队
+                'scoretime' => $req->onescoretime ? $req->onescoretime : '',//进球时间
+                'scoretype' => $req->firststye ? $req->firststye : '',//进球方式
+            );
+
+            $model->single_result = json_encode($newa, JSON_UNESCAPED_UNICODE);
+            $model->result_flag = 1;
+
+            $model->save();
+            return responseToJson(1);
+        }
+    }
+
+    function getinfo()
+    {
+        $page = Request::has('page') ? Request::get('page') : '';
+        $list = Request::has('limit') ? Request::get('limit') : 10;
+        $account = Request::get('account') ? Request::get('account') : '';
+        $star_time = Request::get('star_time') ? Request::get('star_time') . ' 00:00:00' : '';
+        $end_time = Request::get('end_time') ? Request::get('end_time') . ' 23:59:59' : '';
+        $order_id = Request::get('order_id') ? Request::get('order_id') : '';
+        $match_id = Request::get('match_id') ? Request::get('match_id') : '';
+        $status = Request::has('status') ? Request::get('status') : '-1';
+        $order_status = Request::has('order_status') ? Request::get('order_status') : '';
+        $sureblur = Request::has('sureblurs') ? Request::get('sureblurs') : 'off';
+        $type = Request::has('type') ? Request::get('type') : 'zq';
+        $where = array();
+        if (!empty($account)) {
+            if (empty($sureblur) || $sureblur == 'off') {
+                $where[] = array('money_buy_simplex.account_name', 'like', '%' . $account . '%');
+            } else {
+                $where[] = array('money_buy_simplex.account_name', '=', $account);
+            }
+        }
+        if (!empty($star_time)) {
+            if (!empty($end_time)) {
+                $where[] = array('money_buy_simplex.money_time', '>', $star_time);
+                $where[] = array('money_buy_simplex.money_time', '<', $end_time);
+            } else {
+                $where[] = array('money_buy_simplex.money_time', '>', $star_time);
+            }
+        } else if (empty($star_time)) {
+            if (!empty($end_time)) {
+
+                $where[] = array('money_buy_simplex.money_time', '<', $end_time);
+            }
+        }
+        if (!empty($order_id)) {
+            $where[] = array('money_buy_simplex.order_id', $order_id);
+        }
+        if (!empty($match_id)) {
+            $where[] = array('money_buy_simplex.match_id', $match_id);
+        }
+        if ($status != -1) {
+            $where[] = array('money_buy_simplex.settle_status', '=', $status);
+        }
+        if ($order_status != -1) {
+            $where[] = array('money_buy_simplex.status', '=', $order_status);
+        }
+        $where[] = array('money_buy_simplex.game_code', $type);
+        $newapp = new \App\Models\SportsNoteList();
+        $data = $newapp->info($list, $page, $where, $type);
+
+        return \App\Lib\DataTable\DataTable::init()->toJson($data['data'], $data['total'], 0, $where);
+    }
+
+    /**
+     *单式注单通过审核
+     */
+    public function check(Req $req)
+    {
+        $id = $req->id;
+        if (intval($id) < 1) {
+            return -1;
+        }
+        \App\Models\SportsNoteList::where('id', $id)->update(['roll_ratify' => '1']);
+        return 1;
+    }
+
+    /**
+     *单式注单拒绝审核
+     */
+    public function nocheck(Req $req)
+    {
+        $id = $req->id;
+        if (intval($id) < 1) {
+            return -1;
+        }
+        $order = \App\Models\SportsNoteList::where('id', $id)->first();
+        //用戶账户金额
+        $account_money = \App\Models\Account_detailed::where('account_identity', $order->account_identity)->first();
+        //反水
+        $water_return_money = \App\Models\Money_details::where('trade_id', $order->order_id)->where('trade_type', '7')->first();
+        if (!empty($water_return_money)) {
+            $water_return = $water_return_money->money;
+        } else {
+            $water_return = 0;
+        }
+        //审核不通过用户账户金额
+        $available_cash = $account_money->available_cash;
+        $new_available_cash = $available_cash + $order->money - $order->gain_money - $water_return;
+
+        $model = new \App\Models\Money_details();
+        $model->info_identity = UUID();
+        $model->trade_id = $order->order_id;
+        $model->account_name = $order->account_name;
+        $model->account_identity = $order->account_identity;
+        $model->money = abs($order->money - $order->gain_money - $water_return);
+        $model->money_time = date("Y-m-d H:i:s", time());
+        if ($new_available_cash > $available_cash) {
+            $model->money_type = '1';
+        } else {
+            $model->money_type = '2';
+        }
+        $model->money_cash = $new_available_cash;
+        $model->trade_type = '25';
+        $model->trade_desc = '单式注单审核不通过回款';
+        $model->status = '1';
+        try {
+            DB::beginTransaction();//开启事务
+            \App\Models\SportsNoteList::where('id', $id)->update(['roll_ratify' => '-1']);
+            \App\Models\Account_detailed::where('account_identity', $order->account_identity)->update(['available_cash' => $new_available_cash, 'cash' => $new_available_cash]);
+            $model->save();
+
+            DB::commit();//提交
+            return 1;
+        } catch (Exception $e) {
+            DB::rollback();//回滚
+            return -1;
+        }
+    }
+
+    /**
+     *单式注单作废
+     */
+    public function invalid(Req $req)
+    {
+        $id = $req->id;
+        if (intval($id) < 1) {
+            return -1;
+        }
+        $order = \App\Models\SportsNoteList::where('id', $id)->first();
+        //用戶账户金额
+        $account_money = \App\Models\Account_detailed::where('account_identity', $order->account_identity)->first();
+        //反水
+        $water_return_money = \App\Models\Money_details::where('trade_id', $order->order_id)->where('trade_type', '7')->first();
+        if (!empty($water_return_money)) {
+            $water_return = $water_return_money->money;
+        } else {
+            $water_return = 0;
+        }
+        //撤单后用户账户金额
+        $available_cash = $account_money->available_cash;
+        $new_available_cash = $available_cash + $order->money - $order->gain_money - $water_return;
+
+        $model = new \App\Models\Money_details();
+        $model->info_identity = UUID();
+        $model->trade_id = $order->order_id;
+        $model->account_name = $order->account_name;
+        $model->account_identity = $order->account_identity;
+        $model->money = abs($order->money - $order->gain_money - $water_return);
+        $model->money_time = date("Y-m-d H:i:s", time());
+        if ($new_available_cash > $available_cash) {
+            $model->money_type = '1';
+        } else {
+            $model->money_type = '2';
+        }
+        $model->money_cash = $new_available_cash;
+        $model->trade_type = '3';
+        $model->trade_desc = '管理员作废单式注单';
+        $model->status = '1';
+        try {
+            DB::beginTransaction();//开启事务
+            \App\Models\SportsNoteList::where('id', $id)->update(['status' => '2'], ['gain_money' => '0']);
+            \App\Models\Account_detailed::where('account_identity', $order->account_identity)->update(['available_cash' => $new_available_cash, 'cash' => $new_available_cash]);
+            $model->save();
+
+            DB::commit();//提交
+            return 1;
+        } catch (Exception $e) {
+            DB::rollback();//回滚
+            return -1;
+        }
+    }
+
+    /**
+     *单式注单首次结算
+     */
+    public function settlement(Req $req)
+    {
+        $id = $req->id;
+        if (intval($id) < 1) {
+            return -1;
+        }
+        $order = \App\Models\SportsNoteList::where('id', $id)->first();
+        $order_id = $order->order_id;
+        $order_ids = array($order->order_id);
+        $match_id = $order->match_id;
+        $game_code = $order->game_code;
+        $bet_type = 1;//单式注单
+        //return $match_id;
+        //判断输赢
+        $settlementWinFail = new SettlementWinFail();
+        $res = $settlementWinFail->ProcWinInfoByOneOrder($match_id, $order_id, $bet_type);
+        //结算
+        $SettlementOrder = new SettlementOrder();
+        $settype = 1; //首次结算
+        $data = $SettlementOrder->reSettlement($order_ids, $bet_type, $settype, $game_code, $match_id, $match_status = 0);
+        return $data;
+    }
+
+
+    /**
+     *单式注单重新结算
+     */
+    // public function resettlement(Req $req) {
+    //     $id = $req->id;
+    //     if (intval($id) < 1) {
+    //         return -1;
+    //     }
+    //     $order = \App\Models\SportsNoteList::where('id',$id)->first();
+    //     $match_id = $order->match_id;
+    //     $game_code = $order->game_code;
+    //     $order_id = $order->order_id;
+    //     $order_ids = array($order->order_id);
+    //     //return $match_id;
+    //     $bet_type = 1;//单式注单
+    //     //重新判断输赢
+    //     $settlementWinFail = new SettlementWinFail();
+    //     $res = $settlementWinFail->ProcWinInfoByOneOrder($match_id, $order_id, $bet_type);
+    //     //结算
+    //     $SettlementOrder = new SettlementOrder();
+    //     $settype = 2; //重新结算
+    //     $data = $SettlementOrder->reSettlement($order_ids,$bet_type,$settype,$game_code,$match_id,$match_status=0);
+    //     return $data;
+    // }
+    public function resettlement(Req $req)
+    {
+        $order_id = $req->order_id;
+        $type = $req->type;
+        $match_id = $req->match_id;
+        $jsurl = config('sconstant.url');//结算请求域名地址
+        $token = session('adminInfo.token');
+        //查询是否有订单
+        $newapp = new \App\Models\SportsNoteList();
+        $simplexnum = $newapp->onlyorder($order_id);
+        if ($simplexnum == 1) {
+            $requet = file_get_contents($jsurl . "/DoWinFailOneOrder?order_id=" . $order_id . "&token=" . $token);
+            if (json_decode($requet, true)['status'] == 1) {
+                $napp = new \App\Models\Stzqresult();
+                $simplex = array(
+                    'token' => $token,
+                    'order_ids' => $order_id, //订单id字符串,用半角都好分隔
+                    'bettype' => 1, //结算类型  1单式  2串式
+                    'settype' => 2, //结算次数  1首次  2非首冷饮
+                    'game_code' => $type, //赛事类型  zq lq wq bq
+                    'match_id' => $match_id, // 赛事ID
+                    'change_status' => 0   //是否改状态
+                );
+                $url = $jsurl . '/Settelement';
+                $simplex_res = $napp->post_curls($url, $simplex);//返回json
+                $huawei_res = json_decode($simplex_res, true);
+                if ($huawei_res['status'] == 1) {
+                    return json_encode(['status' => 1, 'msg' => '结算成功']);
+                } else {
+                    return json_encode(['status' => 4, 'msg' => '结算失败']);
+                }
+            } else {
+                return json_encode(['status' => 3, 'msg' => '输赢判断错误']);
+            }
+        } else {
+            return json_encode(['status' => 2, 'msg' => '订单不存在']);
+        }
+    }
+
+    /**
+     *单式注单批量结算
+     */
+    public function batchsettlement()
+    {
+        $orders = \App\Models\SportsNoteList::where('settle_status', '1')->get();
+        $order_ids = array();
+        for ($i = 0; $i < count($orders); $i++) {
+            $result = \App\Models\MoneyBuyMatch::where('batch_id', $orders[$i]->batch_id)->where('match_id', $orders[$i]->match_id)->get();
+            $res = array();
+            for ($j = 0; $j < count($result); $j++) {
+                $res[] = $result[$j]->result;
+            }
+            if (!in_array(0, $res)) {
+                $order_ids[] = $orders[$i]->order_id;
+            }
+        }
+        $SettlementOrder = new SettlementOrder();
+        $bet_type = 1;//单式注单
+        $data = $SettlementOrder->reSettlement($order_ids, $bet_type);
+        return $data;
+    }
+
+    /**
+     *删除订单
+     */
+    public function delete(Req $req)
+    {
+        $id = $req->input('id');
+        if (empty($id)) {
+            return responseToJson(-2001); //id
+        }
+        $ids = explode(',', $id);
+        if (!is_array($ids) && intval($ids) < 0) {
+            return responseToJson(-2002); //id
+        }
+        if (is_array($ids) && count($ids) > 0) {
+            foreach ($ids as $k => $v) {
+                if (intval($v) < 1) {
+                    unset($ids[$k]);
+                }
+            }
+        }
+
+        $rows = \App\Models\SportsNoteList::whereIn('id', $ids)->delete();
+        if (!$rows) {
+            return responseToJson(-2003); //id
+        }
+        return responseToJson(1, trans('menu.delete_success')); //id
+
+    }
+
+    /**
+     * 投注金额统计
+     */
+    function moneycount()
+    {
+        $where = Request::has('where') ? Request::get('where') : '';
+        $type = Request::has('type') ? Request::get('type') : 'zq';
+        $db = new \App\Models\SportsNoteList;
+
+        $data = $db->MoneyCount($where, $type);
+        return responseToJson($data);
+    }
+
+    //单式订单数据
+    public function manualmatchget(Req $req)
+    {
+        $order_id = isset($req->order_id) ? $req->order_id : 0;
+        $model = new  \App\Models\SportsNoteList();
+        $ret = $model->getorder($order_id);
+        if ($ret) {
+            $ret = $ret->toArray();
+            return responseToJson(1, '成功', $ret);
+        } else {
+            return responseToJson(-1, 'false', $ret);
+        }
+
+    }
+
+    //单式订直接手动更改输赢结果并结算
+    public function manualmatchpdate(Req $req)
+    {
+        $order_id = isset($req->order_id) ? $req->order_id : 0;
+        $datas = isset($req->matchdata) ? $req->matchdata : [];
+        $datas = json_decode($datas, true);
+        if (empty($order_id) || empty($datas)) {
+            return responseToJson(-1, '参数不能为空!');
+        }
+
+        $model = new  \App\Models\SportsNoteList();
+        $modeldata = $model->getorder($order_id);
+        if (empty($modeldata)) {
+            return responseToJson(-1, 'false');
+        }
+
+        $sdataArr = [];
+        foreach ($datas as $val) {
+            $tmp_id = $val['id'];
+            $tmp_result = intval($val['result']);
+            $tmp_matchword = trim($val['matchresult']);
+            if (!in_array($tmp_result, [-1, 1, 2, 3, 4])) {
+                continue;
+            }
+            $sdataArr[$tmp_id] = ['result' => $tmp_result, 'matchresult' => $tmp_matchword];
+        }
+        if (empty($sdataArr)) {
+            return responseToJson(-2, '没有要更新的数据');
+        }
+
+        $chageNum = 0;
+        foreach ($modeldata->matchdatas as $key => $val) {
+            $id = $val->id;
+            if (isset($sdataArr[$id])) {
+                if ($val->result != $sdataArr[$id]['result'] || $val->matchwork != $sdataArr[$id]['matchresult']) {
+                    $val->result = $sdataArr[$id]['result'];
+                    $val->matchresult = $sdataArr[$id]['matchresult'];
+                    $val->save();
+                    $chageNum++;
+                }
+            }
+        }
+        if ($chageNum) {
+            $modeldata->is_manual = 1;
+            $modeldata->save();
+        } else {
+            return responseToJson(1, '没有更新操作数据!');
+        }
+
+        $data = [
+            'token' => 'oclatv15689731035d84a12f550df',    //外网
+            'order_ids' => $modeldata->order_id,
+            'bettype' => 1,
+            'settype' => 2,
+            'game_code' => $modeldata->game_code,
+            'match_id' => $modeldata->match_id,
+            'change_status' => 0,
+            'is_manual' => 1,
+        ];
+        $ret = $this->request_post('http://stadmin.bocai108.com:9094/Settelement', $data);
+
+        return responseToJson(1, '更新成功');
+
+    }
+
+
+    private function request_post($url = '', $param = '')
+    {
+        if (empty($url) || empty($param)) {
+            return false;
+        }
+
+        $postUrl = $url;
+        $curlPost = $param;
+        $ch = curl_init();//初始化curl
+        curl_setopt($ch, CURLOPT_URL, $postUrl);//抓取指定网页
+        curl_setopt($ch, CURLOPT_HEADER, 0);//设置header
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
+        curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
+        curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
+        $data = curl_exec($ch);//运行curl
+        curl_close($ch);
+
+        return $data;
+    }
+
+
+}

+ 9 - 2
app/Http/Controllers/Admin/SoccerNoteListController.php

@@ -157,7 +157,6 @@ class SoccerNoteListController extends Controller
         $sureblur = Request::has('sureblurs') ? Request::get('sureblurs') : 'off';
         $type = Request::has('type') ? Request::get('type') : 'zq';
         $where = array();
-        // $where[] = array('money_buy_simplex.is_champion', '=', 0);
         if (!empty($account)) {
             if (empty($sureblur) || $sureblur == 'off') {
                 $where[] = array('money_buy_simplex.account_name', 'like', '%' . $account . '%');
@@ -398,7 +397,7 @@ class SoccerNoteListController extends Controller
         $where[] = array('money_buy_simplex.game_code', $type);
         $newapp = new \App\Models\SportsNoteList();
         $data = $newapp->info($list, $page, $where, $type);
-
+        //$alldata = Models\MoneyBuyMatch::where('bet_type',1)->where('is_rolling',1)->distinct('order_id')->count('order_id');
         return \App\Lib\DataTable\DataTable::init()->toJson($data['data'], $data['total'], 0, $where);
     }
 
@@ -617,7 +616,15 @@ class SoccerNoteListController extends Controller
         $model = new  \App\Models\SportsNoteList();
         $ret = $model->getorder($order_id);
         if ($ret) {
+            $modelcode = new  \App\Models\StoddsCode();
+            $opcode_nameArr = $modelcode->getTypeDatas($ret->game_code);
             $ret = $ret->toArray();
+            foreach ($ret['matchdatas'] as $key => $val) {
+                $tmp_pcode = $val['p_code'];
+                $tmp_code = $val['odds_code'];
+                $ret['matchdatas'][$key]['odds_name'] = isset($opcode_nameArr[$tmp_pcode][$tmp_code]['odds_name']) ? $opcode_nameArr[$tmp_pcode][$tmp_code]['odds_name'] : '';
+            }
+
             return responseToJson(1, '成功', $ret);
         } else {
             return responseToJson(-1, 'false', $ret);

+ 8 - 0
app/Http/Controllers/Api/SettlementController.php

@@ -36,6 +36,14 @@ class SettlementController extends Controller
     public function debug(Req $req)
     {
 
+        /*
+        $model = new  \App\Models\StoddsCode();
+        $aa =$model->getTypeDatas('zq');
+        print_r($aa);
+        return ;
+         */
+
+
         $order_id = isset($req->order_id) ? $req->order_id : 0;
         $model  = new  \App\Models\SportsNoteList();
         $ret = $model->getorder($order_id);

+ 4 - 4
app/Http/Controllers/Api/WriteSportsController.php

@@ -2272,10 +2272,10 @@ class WriteSportsController extends BaseController
     public function match_result($game_code = '')
     {
         $model = commonFunction::getModels($game_code, 1);
-        if ($game_code == 'zq') ZqResultModel::ZQresult($model);
-        if ($game_code == 'lq') LqResultModel::LQresult($model);
-        if ($game_code == 'wq') WqResultModel::WQresult($model);
-        if ($game_code == 'bq') BqResultModel::BQresult($model);
+        if ($game_code == 'zq') ZqResultModel::ZQresult_v2($model);
+        if ($game_code == 'lq') LqResultModel::LQresult_v2($model);
+        if ($game_code == 'wq') WqResultModel::WQresult_v2($model);
+        if ($game_code == 'bq') BqResultModel::BQresult_v2($model);
     }
 
     /*

+ 145 - 1
app/Http/Model/StBqResult.php

@@ -92,7 +92,7 @@ class StBqResult extends Model
         }
     }
 
-    public static function BQresult($model){
+    public static function BQresult_v1($model){
         //获取赛事表7天内所有赛事
         $matchData = $model['model_match']::select('id','home_team','guest_team','lg_id','status','tag','match_date','match_time')
             ->where([['match_date','>',date('Y-m-d',strtotime("-2 day"))],['status','=',2]])
@@ -261,6 +261,150 @@ class StBqResult extends Model
 
         return 1;
 
+    }
+    /**
+     * 获取自动赛事结果
+     * 只更新已结束+未手动修改的赛事结果
+     */
+    public static function BQresult_v2($model){
+         //获取两天内的结束赛事
+         $matchData = $model['model_match']
+         ->join('st_bq_result','st_bq_result.match_id','=','st_bq_competition.id')
+         ->select('st_bq_competition.id','is_correct')
+         ->where([['st_bq_competition.match_date','>',date('Y-m-d', strtotime("-2 day"))],['st_bq_competition.status','=',2]])
+         ->get()
+         ->toArray();
+
+
+        //没有数据,无需操作
+        if(empty($matchData)) return Response::success();
+        //获取需更新结果的赛事ID
+        $match_ids = [];
+        foreach($matchData as $k =>$v){
+            //未手动修改比分
+            if($v['is_correct'] == 0){
+                $match_ids[] = $v['id'];
+            }
+        }
+
+        $match_ids_str = implode(",", $match_ids);
+         // 组装sql
+         $sql_result = "select a.match_id,a.home_team,a.guest_team,a.home_score,a.guest_score,a.match_time as a_time,a.match_process,a.all_inning,a.first_score,a.last_score,a.match_score,a.match_winer,a.home_rate,a.guest_rate,a.result_mark from st_bq_result_record a,
+         (select match_id,max(id) id from st_bq_result_record where match_id IN ($match_ids_str) group by match_id)b
+         where a.match_id = b.match_id and a.id = b.id ";
+
+        //赛事最终结果
+        $match_result = DB::select($sql_result);
+
+        if(!empty($match_result)){
+            foreach($match_result as $k=>$v){
+                //获取赛事每节的赛果
+                $resultData = commonFunction::filter_by_value($match_result,'match_id',$v->match_id);
+            
+                if(!empty($resultData)){
+                    //获取赛果json
+                    $result_mark = json_decode($resultData['result_mark'],true);
+
+                    //获取进程
+                    $match_process = $resultData['match_process'];
+
+                    //获胜球员
+                    $match_winer = '';
+                    if($result_mark['game_num_H'] > $result_mark['game_num_C']){
+                        $match_winer = $v->home_team;
+                    }else{
+                        $match_winer = $v->guest_team;
+                    }
+
+                    //组装输赢结果json
+                    $inning = [
+                        1=>[
+                            "home"=>$result_mark['sc_1th_H'],
+                            "guest"=>$result_mark['sc_1th_C'],
+                        ],
+                        2=>[
+                            "home"=>$result_mark['sc_2th_H'],
+                            "guest"=>$result_mark['sc_2th_C'],
+                        ],
+                        3=>[
+                            "home"=>$result_mark['sc_3th_H'],
+                            "guest"=>$result_mark['sc_3th_C'],
+                        ],
+                        4=>[
+                            "home"=>$result_mark['sc_4th_H'],
+                            "guest"=>$result_mark['sc_4th_C'],
+                        ],
+                        5=>[
+                            "home"=>$result_mark['sc_5th_H'],
+                            "guest"=>$result_mark['sc_5th_C'],
+                        ],
+                        6=>[
+                            "home"=>$result_mark['sc_6th_H'],
+                            "guest"=>$result_mark['sc_6th_C'],
+                        ],
+                        7=>[
+                            "home"=>$result_mark['sc_7th_H'],
+                            "guest"=>$result_mark['sc_7th_C'],
+                        ],
+                        8=>[
+                            "home"=>$result_mark['sc_8th_H'],
+                            "guest"=>$result_mark['sc_8th_C'],
+                        ],
+                        9=>[
+                            "home"=>$result_mark['sc_9th_H'],
+                            "guest"=>$result_mark['sc_9th_C'],
+                        ],
+                        "other"=>[//加时
+                            "home"=>$result_mark['OT_H'],
+                            "guest"=>$result_mark['OT_C'],
+                        ]
+                    
+                    ];
+
+                    //上半场主队进球
+                    $u_home_score = $result_mark['sc_1th_H']+$result_mark['sc_2th_H']+$result_mark['sc_3th_H']+$result_mark['sc_4th_H']+$result_mark['sc_5th_H'];
+
+                    //上半场客队进球
+                    $u_guest_score = $result_mark['sc_1th_C']+$result_mark['sc_2th_C']+$result_mark['sc_3th_C']+$result_mark['sc_4th_C']+$result_mark['sc_5th_C'];
+
+                    //赛事比分
+                    $match_score = $result_mark['game_num_H'].':'.$result_mark['game_num_C'];
+
+                    //总进球数
+                    $all_goal = $result_mark['game_num_H'] + $result_mark['game_num_C'];
+                   
+                    //赛事待写入赛果数据
+                    $set_match_r = [
+                        "match_id"=> $v->match_id,
+                        "status"=>2,
+                        "update_time"=>date('Y-m-d H:i:s'),
+
+                        "home_rate"=> $resultData['home_rate']?:0, //主队让球
+                        "guest_rate"=> $resultData['guest_rate']?:0, //客队让球
+                        "home_score"=> $result_mark['game_num_H']?:0, //主队进球
+                        "guest_score"=> $result_mark['game_num_C']?:0, //客队进球
+                        "all_goal"=> $all_goal?:0, //总局数
+                        // "first_score"=> $resultData['first_score']?:'', //最先得分
+                        // "last_score"=> $resultData['last_score']?:'', //最后得分
+                        "match_score"=> $match_score?:'',//赛事比分
+                        "match_winer"=>  $match_winer?:'',//获胜队员
+                        "match_process"=> $match_process?:'',//比赛进程
+                        "u_home_score"=> $u_home_score,//上半场主队进球
+                        "u_guest_score"=> $u_guest_score ,//上半场客队进球
+                        "match_score_t"=> json_encode($inning)?:'',//每局输赢结果
+                        "is_correct"=> -1,//自动比分
+                    ];    
+
+                    $ret = $model['model_result']::where(['match_id' => $v->match_id])
+                    ->update($set_match_r);
+  
+                    if($ret < 1) throw new \Exception( Response::generate('',Response::ADD_MATCH_R_ERROR));  
+                }
+            }
+        }
+
+        return 1;
+
     }
 
     //计算滚球 赛事进行时间

+ 96 - 1
app/Http/Model/StLqResult.php

@@ -110,7 +110,7 @@ class StLqResult extends Model
     /*
      * 写赛事结果
      */
-    public static function LQresult($model){
+    public static function LQresult_v1($model){
         //获取当天开始并且已结束的所有赛事
         $matchData = $model['model_match']::select('id','home_team','guest_team','lg_id','status','tag','match_date','match_time')
             ->where([['match_date','>',date('Y-m-d',strtotime("-2 day"))],['status','=',2]])
@@ -262,6 +262,101 @@ class StLqResult extends Model
         return 1;
     }
 
+    /**
+     * 获取自动赛事结果
+     * 只更新已结束+未手动修改的赛事结果
+     */
+    public static function LQresult_v2($model){
+         //获取两天内的结束赛事
+         $matchData = $model['model_match']
+            ->join('st_lq_result','st_lq_result.match_id','=','st_lq_competition.id')
+            ->select('st_lq_competition.id','is_correct')
+            ->where([['st_lq_competition.match_date','>',date('Y-m-d', strtotime("-2 day"))],['st_lq_competition.status','=',2]])
+            ->get()
+            ->toArray();
+
+     
+        //没有数据,无需操作
+        if(empty($matchData)) return Response::success();
+        //获取需更新结果的赛事ID
+        $match_ids = [];
+        foreach($matchData as $k =>$v){
+            //未手动修改比分
+            if($v['is_correct'] == 0){
+                $match_ids[] = $v['id'];
+            }
+        }
+
+        $match_ids_str = implode(",", $match_ids);
+
+        //拼接sql
+        $sql_result = "select a.match_id,a.home_team,a.guest_team,a.home_score,a.guest_score,a.match_time as a_time,a.home_rate,a.guest_rate,a.match_process,a.first_score,a.last_score,a.match_score,a.match_winer,a.result_mark from st_lq_result_record a,
+        (select match_id,max(id) id from st_lq_result_record where  match_id IN ($match_ids_str) group by match_id)b
+        where a.match_id = b.match_id and a.id = b.id ";
+
+        //第一节最终结果
+        $match_result = DB::select($sql_result);
+
+        if(!empty($match_result)){
+            foreach($match_result as $k=>$v){
+                //获取结果json
+                $mark_result = json_decode($v->result_mark,true);
+                //获取总进球数
+                $all_goal = $mark_result['whole_H']+$mark_result['whole_C'];
+                //获取比分
+                $match_score = $mark_result['whole_H'].':'.$mark_result['whole_C'];
+                //获取获胜球队
+                if(($mark_result['whole_H']) > ($mark_result['whole_C'])){
+                    $match_winer = $v->home_team;
+                }else{
+                    $match_winer = $v->guest_team;
+                }
+                //拼接赛事主队比分  {"1":0,"2":0,"3":0,"4":0}
+                $home_score = [
+                    '1'=>$mark_result['sc_1th_H'],
+                    '2'=>$mark_result['sc_2th_H'],
+                    '3'=>$mark_result['sc_3th_H'],
+                    '4'=>$mark_result['sc_4th_H'],
+                ];
+                //拼接赛事客队比分
+                $guest_score = [
+                    '1'=>$mark_result['sc_1th_C'],
+                    '2'=>$mark_result['sc_2th_C'],
+                    '3'=>$mark_result['sc_3th_C'],
+                    '4'=>$mark_result['sc_4th_C'],
+                ];
+                //赛事待写入赛果数据
+                $set_match_r = [
+                    "match_id"=> $v->match_id,
+                    "status"=>2,
+                    "update_time"=>date('Y-m-d H:i:s'),
+
+                    "home_rate"=> $v->home_rate?:0, //主队让球
+                    "guest_rate"=> $v->guest_rate?:0, //客队让球
+                    "home_score"=> json_encode($home_score)?:'', //主队进球数
+                    "guest_score"=> json_encode($guest_score)?:'', //客队进球数
+                    "all_goal"=> $all_goal?:0, //总进球数
+                    // "first_score"=> $result_4['first_score']?:'', //最先进球球队
+                    // "last_score"=> $result_4['last_score']?:'', //最后进球球队
+                    "match_score"=> $match_score?:0, //赛事比分
+                    "match_winer"=>  $match_winer?:'',//获胜球队
+                    "match_process"=> $mark_result['schedule']?:'',//比赛进程
+                    "u_home_score"=> $mark_result['half_H']?:0,//上半场主队进球数
+                    "u_guest_score"=> $mark_result['half_C']?:0,//上半场客队进球数
+                    "is_correct"=> -1,//自动比分
+
+                ];  
+
+                $ret = $model['model_result']::where(['match_id' => $v->match_id])
+                    ->update($set_match_r);
+  
+                if($ret < 1) throw new \Exception( Response::generate('',Response::ADD_MATCH_R_ERROR));               
+            }
+        }
+
+        return 1;
+    }
+
     //计算滚球 赛事进行时间
     public static function secTime($sec=0){
         $min = floor($sec/60);

+ 129 - 1
app/Http/Model/StWqResult.php

@@ -91,7 +91,7 @@ class StWqResult extends Model
             }
         }
     }
-    public static function WQresult($model){
+    public static function WQresult_v1($model){
 
         //获取赛事表7天内所有赛事
         $matchData = $model['model_match']::select('id','home_team','guest_team','lg_id','status','tag','match_date','match_time')
@@ -276,6 +276,134 @@ class StWqResult extends Model
 
     }
 
+   /**
+     * 获取自动赛事结果
+     * 只更新已结束+未手动修改的赛事结果
+     */
+    public static function WQresult_v2($model){
+
+        //获取两天内的结束赛事
+        $matchData = $model['model_match']
+            ->join('st_wq_result','st_wq_result.match_id','=','st_wq_competition.id')
+            ->select('st_wq_competition.id','is_correct')
+            ->where([['st_wq_competition.match_date','>',date('Y-m-d', strtotime("-2 day"))],['st_wq_competition.status','=',2]])
+            ->get()
+            ->toArray();
+
+ 
+        //没有数据,无需操作
+        if(empty($matchData)) return Response::success();
+        //获取需更新结果的赛事ID
+        $match_ids = [];
+        foreach($matchData as $k =>$v){
+            //未手动修改比分
+            if($v['is_correct'] == 0){
+                $match_ids[] = $v['id'];
+            }
+        }
+
+        $match_ids_str = implode(",", $match_ids);
+
+        //组装sql 
+        //获取赛事最终赛果
+        $sql_result = "select a.match_id,a.home_player_name,a.guest_player_name,a.home_player_score,a.guest_player_score,a.match_time as a_time,a.home_player_let_plate,a.guest_player_let_plate,a.home_player_let_inning,a.guest_player_let_inning,a.all_inning,a.match_process,a.first_score_player,a.last_score_player,a.first_inning_score,a.second_inning_score,a.third_inning_score,a.match_winer_player,a.result_mark from st_wq_result_record a,
+        (select match_id,max(id) id from st_wq_result_record where match_id IN ($match_ids_str) group by match_id)b
+        where a.match_id = b.match_id and a.id = b.id ";
+
+        //赛事最终结果
+        $match_result = DB::select($sql_result);
+
+        if(!empty($match_result)){
+            foreach($match_result as $k=>$v){
+                //获取赛事每节的赛果
+                $resultData = commonFunction::filter_by_value($match_result,'match_id',$v->match_id);
+            
+                //如果有获取到结果,并且进程不为空,则写入赛事结果数据
+                if(!empty($resultData) and $resultData['match_process'] != ''){
+                    //获取赛果json
+                    $result_mark = json_decode($resultData['result_mark'],true);
+
+                    //获取进程
+                    $match_process = '';
+                    if($result_mark['schedule']){
+                        $match_process = $result_mark['schedule'];
+                    }
+
+                    //获胜球员
+                    $match_winer = '';
+                    if($result_mark['game_num_H'] > $result_mark['game_num_C']){
+                        $match_winer = $resultData['home_player_name'];
+                    }else{
+                        $match_winer = $resultData['guest_player_name'];
+                    }
+
+                    //组装输赢结果json
+                    $inning = [
+                        1=>[
+                            "home"=>$result_mark['sc_1th_H'],
+                            "guest"=>$result_mark['sc_1th_C'],
+                        ],
+                        2=>[
+                            "home"=>$result_mark['sc_2th_H'],
+                            "guest"=>$result_mark['sc_2th_C'],
+                        ],
+                        3=>[
+                            "home"=>$result_mark['sc_3th_H'],
+                            "guest"=>$result_mark['sc_3th_C'],
+                        ],
+                        4=>[
+                            "home"=>$result_mark['sc_4th_H'],
+                            "guest"=>$result_mark['sc_4th_C'],
+                        ],
+                        5=>[
+                            "home"=>$result_mark['sc_5th_H'],
+                            "guest"=>$result_mark['sc_5th_C'],
+                        ],
+                    
+                    ];
+
+                    //赛事比分
+                    $match_score = $result_mark['game_num_H'].':'.$result_mark['game_num_C'];
+                   
+                    //赛事待写入赛果数据
+                   
+                    $set_match_r = [
+                        "match_id"=> $v->match_id,
+                        "status"=>2,
+                        "update_time"=>date('Y-m-d H:i:s'),
+
+                        "home_player_let_plate"=> $resultData['home_player_let_plate']?:0, //主队让盘
+                        "guest_player_let_plate"=> $resultData['guest_player_let_plate']?:0, //客队让盘
+                        "home_player_let_inning"=> $resultData['home_player_let_inning']?:0, //主队让局
+                        "guest_player_let_inning"=> $resultData['guest_player_let_inning']?:0, //客队让局
+                        "home_player_score"=> $result_mark['game_num_H']?:0, //主队得分
+                        "guest_player_score"=> $result_mark['game_num_C']?:0, //客队得分
+                        "all_inning"=> $resultData['all_inning']?:0, //总局数
+                        // "first_score_player"=> $resultData['first_score']?:'', //最先得分
+                        // "last_score_player"=> $resultData['last_score']?:'', //最后得分
+                        "first_inning_score"=> $resultData['first_inning_score']?:'', //第一局比分
+                        "second_inning_score"=> $resultData['second_inning_score']?:'',//第二局比分
+                        "third_inning_score"=> $resultData['third_inning_score']?:'',//第三局比分
+                        "match_score"=> $match_score?:'',//赛事比分
+                        "match_winer_player"=>  $match_winer?:'',//获胜队员
+                        "match_process"=> $match_process?:'',//比赛进程
+                        "inning"=> json_encode($inning)?:'',//每局输赢结果
+                        "is_correct"=> -1,//自动比分
+
+                    ]; 
+
+                    $ret = $model['model_result']::where(['match_id' => $v->match_id])
+                    ->update($set_match_r);
+  
+                    if($ret < 1) throw new \Exception( Response::generate('',Response::ADD_MATCH_R_ERROR));  
+
+                }
+            }
+        }
+
+        return 1;
+    }
+
     //计算滚球 赛事进行时间
     public static function secTime($sec=0){
         $min = floor($sec/60);

+ 49 - 80
app/Http/Model/StZqResult.php

@@ -192,7 +192,7 @@ class StZqResult extends Model
     /*
      * 写赛事结果
      */
-    public static function ZQresult($model){
+    public static function ZQresult_v1($model){
         //获取当天开始并且已结束的所有赛事
         $matchData = $model['model_match']::select('id','home_team','guest_team','lg_id','status','tag','match_date','match_time')
             ->where([['match_date','>',date('Y-m-d', strtotime("-2 day"))],['status','=',2]])
@@ -331,56 +331,38 @@ class StZqResult extends Model
     }
 
     /**
-     * 测试新结果写入
+     * 获取自动赛事结果
+     * 只更新已结束+未手动修改的赛事结果
      */
-    public static function ZQresult_xxx($model){
-        //获取当天开始并且已结束的所有赛事
-        $matchData = $model['model_match']::select('id','home_team','guest_team','lg_id','status','tag','match_date','match_time')
-            ->where([['match_date','>',date('Y-m-d', strtotime("-2 day"))],['status','=',2]])
-            ->get()
-            ->toArray();
-
-        //获取赛事结果表 一天内
-        $matchData_r = $model['model_result']::select('match_id','is_correct')
-            ->where([['start_time','>',date('Y-m-d H:i:s', strtotime("-2 day"))],['status','=',2]])
+    public static function ZQresult_v2($model){
+        //获取两天内的结束赛事
+        $matchData = $model['model_match']
+            ->join('st_zq_result','st_zq_result.match_id','=','st_zq_competition.id')
+            ->select('st_zq_competition.id','is_correct')
+            ->where([['st_zq_competition.match_date','>',date('Y-m-d', strtotime("-2 day"))],['st_zq_competition.status','=',2]])
             ->get()
             ->toArray();
-            dd($matchData_r);
-
-        if(!empty($matchData_r)){
-            //如果结果表有数据,则获取结果表没有的赛事
-            foreach ($matchData as $k => $v) {
-                foreach ($matchData_r as $kk => $vv) {
-                    if ($v['id'] == $vv['match_id']) {
-                        unset($matchData[$k]);
-                    }
-                }
-            }
-
-        }
-
+        
         //没有数据,无需操作
         if(empty($matchData)) return Response::success();
-
-        //获取赛事id 用于获取赛事对应结果比分
+        //获取需更新结果的赛事ID
         $match_ids = [];
         foreach($matchData as $k =>$v){
-            //只获取赛事已结束的
-            if($v['status'] == 2){
+            //未手动修改比分
+            if($v['is_correct'] == 0){
                 $match_ids[] = $v['id'];
             }
         }
 
-
         $match_ids_str = implode(",", $match_ids);
         
         //上半场
-        $sql_h = "select a.match_id,a.home_score,a.guest_score,a.match_time as a_time,a.match_process,a.all_goal,a.first_score,a.last_score,a.match_score,a.match_winer from st_zq_result_record a,
+        $sql_h = "select a.match_id,a.home_team,a.guest_team,a.home_score,a.guest_score,a.match_time as a_time,a.match_process,a.all_goal,a.first_score,a.last_score,a.match_score,a.match_winer from st_zq_result_record a,
         (select match_id,max(id) id from st_zq_result_record where match_process = '半场' and match_id IN ($match_ids_str) group by match_id)b
         where a.match_id = b.match_id and a.id = b.id ";
 
         //全场
-        $sql_f = "select a.match_id,a.home_score,a.guest_score,a.match_time as a_time,a.match_process,a.all_goal,a.first_score,a.last_score,a.match_score,a.match_winer,a.home_rate,a.guest_rate from st_zq_result_record a,
+        $sql_f = "select a.match_id,a.home_team,a.guest_team,a.home_score,a.guest_score,a.match_time as a_time,a.match_process,a.all_goal,a.first_score,a.last_score,a.match_score,a.match_winer,a.home_rate,a.guest_rate from st_zq_result_record a,
         (select match_id,max(id) id from st_zq_result_record where match_id IN ($match_ids_str) group by match_id)b
         where a.match_id = b.match_id and a.id = b.id ";
 
@@ -399,6 +381,8 @@ class StZqResult extends Model
                     if($v->match_id == $vv->match_id){
                         $match_result_record[$k] = [
                             "match_id"=>$v->match_id,
+                            "home_team"=>$v->home_team,
+                            "guest_team"=>$v->guest_team,
                             "home_score"=> $vv->home_score,
                             "guest_score"=> $vv->guest_score,
                             "a_time"=> $vv->a_time,
@@ -417,58 +401,43 @@ class StZqResult extends Model
                 }
             }
         }
-        
 
-        //组装赛果数据
         if(!empty($match_result_record)){
-            foreach ($matchData as $k=>$v){
-                $start_time = ($v['match_date'].' '.$v['match_time']);
-                $time = time()-strtotime($v['match_time']);
-                $match_time = self::secTime($time);
-                foreach($match_result_record as $kk =>$vv){        
-                    if($v['id'] == $vv['match_id']){
-                        //获取获胜球队
-                        if(($vv['home_score']) > ($vv['guest_score'])){
-                            $match_winer = $v['home_team'];
-                        }else{
-                            $match_winer = $v['guest_team'];
-                        }
-                        $set_match_r[] = [
-                            "match_id"=> $v['id'],
-                            "home_team"=>$v['home_team'],
-                            "guest_team"=>$v['guest_team'],
-                            "lg_id"=>$v['lg_id'],
-                            "status"=>$v['status'],
-                            "tag"=> $v['tag'],
-                            'match_time'=>$vv['a_time']?:0,//比赛进行时间
-                            "ctime"=>date('Y-m-d H:i:s'),
-                            "update_time"=>date('Y-m-d H:i:s'),
-                            "start_time"=>date('Y-m-d H:i:s',strtotime($start_time)),
-
-                            "home_rate"=> $vv['home_rate']?:0, //主队让球
-                            "guest_rate"=> $vv['guest_rate']?:0, //客队让球
-                            "home_score"=> $vv['home_score']?:0, //主队进球数
-                            "guest_score"=> $vv['guest_score']?:0, //客队进球数
-                            "all_goal"=> $vv['all_goal']?:0, //总进球数
-                            // "first_score"=> $vv['first_score']?:'', //最先进球球队
-                            // "last_score"=> $vv['last_score']?:'', //最后进球球队
-                            "match_score"=> $vv['match_score']?:0, //赛事比分
-                            "match_winer"=>  $match_winer?:'',//获胜球队
-                            "match_process"=> $vv['match_process']?:'',//比赛进程
-                            "u_home_score"=> $vv['u_home_score']?:0,//上半场主队进球数
-                            "u_guest_score"=> $vv['u_guest_score']?:0,//上半场客队进球数
-                        ];                        
-                    }                   
+            foreach($match_result_record as $k=>$v){
+                //获取获胜球队
+                if(($v['home_score']) > ($v['guest_score'])){
+                    $match_winer = $v['home_team'];
+                }else{
+                    $match_winer = $v['guest_team'];
+                
                 }
-            }
-        }
 
-        //写入赛果
-        if(!empty($set_match_r)){
-            $ret = $model['model_result']::insert($set_match_r);
-            if($ret != true) throw new \Exception( Response::generate('',Response::ADD_MATCH_R_ERROR));
+                $set_match_r = [
+                    "match_id"=> $v['match_id'],
+                    "update_time"=>date('Y-m-d H:i:s'),
+                    "status"=>2,//已结束
+                    "home_rate"=> $v['home_rate']?:0, //主队让球
+                    "guest_rate"=> $v['guest_rate']?:0, //客队让球
+                    "home_score"=> $v['home_score']?:0, //主队进球数
+                    "guest_score"=> $v['guest_score']?:0, //客队进球数
+                    "all_goal"=> $v['all_goal']?:0, //总进球数
+                    // "first_score"=> $vv['first_score']?:'', //最先进球球队
+                    // "last_score"=> $vv['last_score']?:'', //最后进球球队
+                    "match_score"=> $v['match_score']?:0, //赛事比分
+                    "match_winer"=>  $match_winer?:'',//获胜球队
+                    "match_process"=> $v['match_process']?:'',//比赛进程
+                    "u_home_score"=> $v['u_home_score']?:0,//上半场主队进球数
+                    "u_guest_score"=> $v['u_guest_score']?:0,//上半场客队进球数
+                    "is_correct"=> -1,//自动比分
+                ];     
+                
+                $ret = $model['model_result']::where(['match_id' => $v['match_id']])
+                    ->update($set_match_r);
+      
+                if($ret < 1) throw new \Exception( Response::generate('',Response::ADD_MATCH_R_ERROR));
+            }
         }
-
+        
         return 1;
     }
 

+ 271 - 7
app/Models/SportsNoteList.php

@@ -27,10 +27,12 @@ class SportsNoteList extends BaseModel
         $data = $this
             ->join('money_details', 'money_details.info_identity', '=', 'money_buy_simplex.info_identity')
             ->join('st_' . $type . '_competition', 'st_' . $type . '_competition.id', '=', 'money_buy_simplex.match_id')
-            // ->join('st_'.$type.'_league','st_'.$type.'_competition.lg_id','=','st_'.$type.'_league.id')
+            //->join('money_buy_match','money_buy_match.order_id','=','money_buy_simplex.order_id')
             ->join('st_' . $type . '_league', 'money_buy_simplex.lg_id', '=', 'st_' . $type . '_league.id')
             ->select('money_buy_simplex.id', 'money_buy_simplex.account_name', 'money_buy_simplex.is_champion', 'money_buy_simplex.account_identity', 'money_buy_simplex.order_id', 'money_buy_simplex.money', 'money_buy_simplex.prize_money', 'money_buy_simplex.status', 'money_buy_simplex.money_time', 'money_buy_simplex.settle_status', 'money_buy_simplex.gain_money', 'money_buy_simplex.game_code', 'money_buy_simplex.match_id', 'money_buy_simplex.game_status', 'st_' . $type . '_competition.home_team', 'st_' . $type . '_competition.guest_team', 'st_' . $type . '_competition.match_date', 'st_' . $type . '_competition.match_time', 'st_' . $type . '_competition.lg_id', 'st_' . $type . '_competition.status as match_status', 'money_details.money_cash', 'money_buy_simplex.batch_id', 'st_' . $type . '_league.name_chinese', 'st_' . $type . '_league.last_time')
+            ->whereIn('money_buy_simplex.roll_ratify',array(0,1))
             ->where($where)
+            //->distinct('money_buy_match.order_id')
             ->orderby('money_buy_simplex.money_time', 'desc')
             ->paginate($list);
         if (!$data < 0) {
@@ -286,15 +288,15 @@ class SportsNoteList extends BaseModel
         $data['all_money'] = 0;
         $data['all_prize_money'] = 0;
         $data['alraedy_prize_money'] = 0;
-        $all_money = $this->join('money_details', 'money_details.info_identity', '=', 'money_buy_simplex.info_identity')->join('st_' . $type . '_competition', 'st_' . $type . '_competition.id', '=', 'money_buy_simplex.match_id')->join('st_' . $type . '_league', 'st_' . $type . '_competition.lg_id', '=', 'st_' . $type . '_league.id')->select('money_buy_simplex.money', 'money_buy_simplex.prize_money', 'money_buy_simplex.gain_money')->where('money_buy_simplex.status', '1')->get();
+        $all_money = $this->join('money_details', 'money_details.info_identity', '=', 'money_buy_simplex.info_identity')->join('st_' . $type . '_competition', 'st_' . $type . '_competition.id', '=', 'money_buy_simplex.match_id')->join('st_' . $type . '_league', 'st_' . $type . '_competition.lg_id', '=', 'st_' . $type . '_league.id')->select('money_buy_simplex.money', 'money_buy_simplex.prize_money', 'money_buy_simplex.gain_money')->whereIn('money_buy_simplex.roll_ratify',array(0,1))->where('money_buy_simplex.status', '1')->get();
         for ($a = 0; $a < count($all_money); $a++) {
             $data['all_money'] = $data['all_money'] + $all_money[$a]->money;
         }
-        $all_prize_money = $this->join('money_details', 'money_details.info_identity', '=', 'money_buy_simplex.info_identity')->join('st_' . $type . '_competition', 'st_' . $type . '_competition.id', '=', 'money_buy_simplex.match_id')->join('st_' . $type . '_league', 'st_' . $type . '_competition.lg_id', '=', 'st_' . $type . '_league.id')->select('money_buy_simplex.money', 'money_buy_simplex.prize_money', 'money_buy_simplex.gain_money')->where('money_buy_simplex.status', '1')->get();
+        $all_prize_money = $this->join('money_details', 'money_details.info_identity', '=', 'money_buy_simplex.info_identity')->join('st_' . $type . '_competition', 'st_' . $type . '_competition.id', '=', 'money_buy_simplex.match_id')->join('st_' . $type . '_league', 'st_' . $type . '_competition.lg_id', '=', 'st_' . $type . '_league.id')->select('money_buy_simplex.money', 'money_buy_simplex.prize_money', 'money_buy_simplex.gain_money')->whereIn('money_buy_simplex.roll_ratify',array(0,1))->where('money_buy_simplex.status', '1')->get();
         for ($a = 0; $a < count($all_prize_money); $a++) {
             $data['all_prize_money'] = $data['all_money'] + $all_prize_money[$a]->prize_money;
         }
-        $alraedy_prize_money = $this->join('money_details', 'money_details.info_identity', '=', 'money_buy_simplex.info_identity')->join('st_' . $type . '_competition', 'st_' . $type . '_competition.id', '=', 'money_buy_simplex.match_id')->join('st_' . $type . '_league', 'st_' . $type . '_competition.lg_id', '=', 'st_' . $type . '_league.id')->select('money_buy_simplex.money', 'money_buy_simplex.prize_money', 'money_buy_simplex.gain_money')->where('money_buy_simplex.settle_status', '2')->where('money_buy_simplex.status', '1')->get();
+        $alraedy_prize_money = $this->join('money_details', 'money_details.info_identity', '=', 'money_buy_simplex.info_identity')->join('st_' . $type . '_competition', 'st_' . $type . '_competition.id', '=', 'money_buy_simplex.match_id')->join('st_' . $type . '_league', 'st_' . $type . '_competition.lg_id', '=', 'st_' . $type . '_league.id')->select('money_buy_simplex.money', 'money_buy_simplex.prize_money', 'money_buy_simplex.gain_money')->where('money_buy_simplex.settle_status', '2')->whereIn('money_buy_simplex.roll_ratify',array(0,1))->where('money_buy_simplex.status', '1')->get();
         for ($a = 0; $a < count($alraedy_prize_money); $a++) {
             $data['alraedy_prize_money'] = $data['all_money'] + $alraedy_prize_money[$a]->gain_money;
         }
@@ -306,15 +308,15 @@ class SportsNoteList extends BaseModel
             //$data['all_money'] = $this->where($where)->sum('money');
 //            $data['all_prize_money'] = $this->where($where)->sum('prize_money');
 //            $data['alraedy_prize_money'] = $this->where($where)->where('settle_status','2')->sum('gain_money');
-            $all_money = $this->join('money_details', 'money_details.info_identity', '=', 'money_buy_simplex.info_identity')->join('st_zq_competition', 'st_zq_competition.id', '=', 'money_buy_simplex.match_id')->join('st_zq_league', 'st_zq_competition.lg_id', '=', 'st_zq_league.id')->select('money_buy_simplex.money', 'money_buy_simplex.prize_money', 'money_buy_simplex.gain_money')->where($where)->where('money_buy_simplex.status', '1')->get();
+            $all_money = $this->join('money_details', 'money_details.info_identity', '=', 'money_buy_simplex.info_identity')->join('st_zq_competition', 'st_zq_competition.id', '=', 'money_buy_simplex.match_id')->join('st_zq_league', 'st_zq_competition.lg_id', '=', 'st_zq_league.id')->select('money_buy_simplex.money', 'money_buy_simplex.prize_money', 'money_buy_simplex.gain_money')->whereIn('money_buy_simplex.roll_ratify',array(0,1))->where($where)->where('money_buy_simplex.status', '1')->get();
             for ($a = 0; $a < count($all_money); $a++) {
                 $data['all_money'] = $data['all_money'] + $all_money[$a]->money;
             }
-            $all_prize_money = $this->join('money_details', 'money_details.info_identity', '=', 'money_buy_simplex.info_identity')->join('st_' . $type . '_competition', 'st_' . $type . '_competition.id', '=', 'money_buy_simplex.match_id')->join('st_' . $type . '_league', 'st_' . $type . '_competition.lg_id', '=', 'st_' . $type . '_league.id')->select('money_buy_simplex.money', 'money_buy_simplex.prize_money', 'money_buy_simplex.gain_money')->where($where)->where('money_buy_simplex.status', '1')->get();
+            $all_prize_money = $this->join('money_details', 'money_details.info_identity', '=', 'money_buy_simplex.info_identity')->join('st_' . $type . '_competition', 'st_' . $type . '_competition.id', '=', 'money_buy_simplex.match_id')->join('st_' . $type . '_league', 'st_' . $type . '_competition.lg_id', '=', 'st_' . $type . '_league.id')->select('money_buy_simplex.money', 'money_buy_simplex.prize_money', 'money_buy_simplex.gain_money')->whereIn('money_buy_simplex.roll_ratify',array(0,1))->where($where)->where('money_buy_simplex.status', '1')->get();
             for ($a = 0; $a < count($all_prize_money); $a++) {
                 $data['all_prize_money'] = $data['all_prize_money'] + $all_prize_money[$a]->prize_money;
             }
-            $alraedy_prize_money = $this->join('money_details', 'money_details.info_identity', '=', 'money_buy_simplex.info_identity')->join('st_' . $type . '_competition', 'st_' . $type . '_competition.id', '=', 'money_buy_simplex.match_id')->join('st_' . $type . '_league', 'st_' . $type . '_competition.lg_id', '=', 'st_' . $type . '_league.id')->select('money_buy_simplex.money', 'money_buy_simplex.prize_money', 'money_buy_simplex.gain_money')->where('money_buy_simplex.settle_status', '2')->where($where)->where('money_buy_simplex.status', '1')->get();
+            $alraedy_prize_money = $this->join('money_details', 'money_details.info_identity', '=', 'money_buy_simplex.info_identity')->join('st_' . $type . '_competition', 'st_' . $type . '_competition.id', '=', 'money_buy_simplex.match_id')->join('st_' . $type . '_league', 'st_' . $type . '_competition.lg_id', '=', 'st_' . $type . '_league.id')->select('money_buy_simplex.money', 'money_buy_simplex.prize_money', 'money_buy_simplex.gain_money')->whereIn('money_buy_simplex.roll_ratify',array(0,1))->where('money_buy_simplex.settle_status', '2')->where($where)->where('money_buy_simplex.status', '1')->get();
             for ($a = 0; $a < count($alraedy_prize_money); $a++) {
                 $data['alraedy_prize_money'] = $data['alraedy_prize_money'] + $alraedy_prize_money[$a]->gain_money;
             }
@@ -355,6 +357,7 @@ class SportsNoteList extends BaseModel
             // ->join('st_'.$type.'_league','st_'.$type.'_competition.lg_id','=','st_'.$type.'_league.id')
             ->join('st_' . $type . '_league', 'money_buy_simplex.lg_id', '=', 'st_' . $type . '_league.id')
             ->select('money_buy_simplex.id', 'money_buy_simplex.account_name', 'money_buy_simplex.is_champion', 'money_buy_simplex.account_identity', 'money_buy_simplex.order_id', 'money_buy_simplex.money', 'money_buy_simplex.prize_money', 'money_buy_simplex.status', 'money_buy_simplex.money_time', 'money_buy_simplex.settle_status', 'money_buy_simplex.gain_money', 'money_buy_simplex.game_code', 'money_buy_simplex.match_id', 'money_buy_simplex.game_status', 'st_' . $type . '_competition.home_team', 'st_' . $type . '_competition.guest_team', 'st_' . $type . '_competition.match_date', 'st_' . $type . '_competition.match_time', 'st_' . $type . '_competition.lg_id', 'st_' . $type . '_competition.status as match_status', 'money_details.money_cash', 'money_buy_simplex.batch_id', 'st_' . $type . '_league.name_chinese', 'st_' . $type . '_league.last_time')
+            ->whereIn('money_buy_simplex.roll_ratify',array(0,1))
             ->where($where)
             ->orderby('money_buy_simplex.money_time', 'desc')
             ->paginate($list);
@@ -601,4 +604,265 @@ class SportsNoteList extends BaseModel
     }
 
 
+    function checkinfo($list = 10, $page, $where = '', $type)
+    {
+        $data = $this
+            ->join('money_details', 'money_details.info_identity', '=', 'money_buy_simplex.info_identity')
+            ->join('st_' . $type . '_competition', 'st_' . $type . '_competition.id', '=', 'money_buy_simplex.match_id')
+            //->join('money_buy_match','money_buy_match.order_id','=','money_buy_simplex.order_id')
+            ->join('st_' . $type . '_league', 'money_buy_simplex.lg_id', '=', 'st_' . $type . '_league.id')
+            ->select('money_buy_simplex.id', 'money_buy_simplex.account_name', 'money_buy_simplex.is_champion', 'money_buy_simplex.account_identity', 'money_buy_simplex.order_id', 'money_buy_simplex.money', 'money_buy_simplex.prize_money', 'money_buy_simplex.status', 'money_buy_simplex.money_time', 'money_buy_simplex.settle_status', 'money_buy_simplex.gain_money', 'money_buy_simplex.game_code', 'money_buy_simplex.match_id', 'money_buy_simplex.game_status', 'money_buy_simplex.roll_ratify', 'st_' . $type . '_competition.home_team', 'st_' . $type . '_competition.guest_team', 'st_' . $type . '_competition.match_date', 'st_' . $type . '_competition.match_time', 'st_' . $type . '_competition.lg_id', 'st_' . $type . '_competition.status as match_status', 'money_details.money_cash', 'money_buy_simplex.batch_id', 'st_' . $type . '_league.name_chinese', 'st_' . $type . '_league.last_time')
+            ->where($where)
+            //->distinct('money_buy_match.order_id')
+            ->orderby('money_buy_simplex.money_time', 'desc')
+            ->paginate($list);
+        if (!$data < 0) {
+            return -2021052003; //
+        }
+        //反水
+        $water_return_money = \App\Models\Money_details::where('trade_type', '7')->get();
+
+        //注单作废
+        $invalid_money = \App\Models\Money_details::where('trade_type', '3')->get();
+
+        //订单投注的玩法
+        $content = \App\Models\MoneyBuyMatch::where('bet_type', '1')->get();
+        for ($d = 0; $d < count($content); $d++) {
+            if ($content[$d]->result == 0) {
+                $content[$d]->result = '未处理';
+            }
+            if ($content[$d]->result == 1) {
+                $content[$d]->result = '赢';
+            }
+            if ($content[$d]->result == -1) {
+                $content[$d]->result = '输';
+            }
+            if ($content[$d]->result == 2) {
+                $content[$d]->result = '平';
+            }
+            if ($content[$d]->result == 3) {
+                $content[$d]->result = '赢半平半';
+            }
+            if ($content[$d]->result == 4) {
+                $content[$d]->result = '输半平半';
+            }
+        }
+
+        //玩法
+        $result = \App\Models\Matchcode::where('game_code', $type)->get();
+        //$result = \App\Model\Matchcode::get();
+
+
+        for ($i = 0; $i < count($data); $i++) {
+            // if($data[$i]->status==1 && $data[$i]->game_status==0){
+            // $data[$i]->order_status = '投注'.'<br>;<a class="layui-btn layui-btn-sm invalid" lay-event="detail" pid="id" uri="/admin/SoccerNoteList/invalid/?id=" href="javascript:invalid(\'/admin/SoccerNoteList/invalid/?id='.$data[$i]->id.'\');"> 作废 </a>';
+            // }else
+            if ($data[$i]->status == 1 && $data[$i]->game_status == 0) {
+                $data[$i]->order_status = '投注';
+            } else if ($data[$i]->status == 2) {
+                $data[$i]->order_status = '作废';//.'<br><a class="layui-btn layui-btn-sm audit" lay-event="detail" pid="id" uri="" href="javascript:void(0)" style="background-color: grey;"> 已作废 </a>';
+            } else if ($data[$i]->status == 3) {
+                $data[$i]->order_status = '撤单';//.'<br><a class="layui-btn layui-btn-sm audit" lay-event="detail" pid="id" uri="" href="javascript:void(0)" style="background-color: grey;"> 已撤单 </a>';
+            }
+            if ($data[$i]->settle_status == 1) {
+                $data[$i]->settle_status = '未结算';
+            } else if ($data[$i]->settle_status == 2) {
+                $data[$i]->settle_status = '已结算';
+            }
+            if ($data[$i]->game_status == 0) {
+                $data[$i]->game_status = '未处理';
+            } else {
+                $data[$i]->game_status = '已处理';
+            }
+
+            if ($data[$i]->roll_ratify == 2) {
+                $data[$i]->roll_ratify = '<a class="layui-btn layui-btn-sm lay-btn-diy" lay-event="detail" pid="id" uri="/admin/CheckRolling/check/?id=" href="javascript:check(\'/admin/CheckRolling/check/?id=' . $data[$i]->id . '\');"> 通过 </a><br><a class="layui-btn layui-btn-sm invalid" lay-event="detail" pid="id" style="margin-top:5px;" uri="/admin/CheckRolling/nocheck/?id=" href="javascript:nocheck(\'/admin/CheckRolling/nocheck/?id=' . $data[$i]->id . '\');"> 拒绝 </a>';
+            }
+
+
+            if ($data[$i]->game_code == 'zq') {
+                $data[$i]->match_id_order = '<a href="/admin/sportsfoot/outcome?home_team=' . $data[$i]->match_id . '">' . $data[$i]->match_id . '</a> (<span>' . $data[$i]->account_name . '</span>)<br>' . $data[$i]->order_id;
+            }
+            if ($data[$i]->game_code == 'lq') {
+                $data[$i]->match_id_order = '<a href="/admin/Sportsbk/outcome?home_team=' . $data[$i]->match_id . '">' . $data[$i]->match_id . '</a> (<span>' . $data[$i]->account_name . '</span>)<br>' . $data[$i]->order_id;
+            }
+            if ($data[$i]->game_code == 'wq') {
+                $data[$i]->match_id_order = '<a href="/admin/Sportswq/outcome?home_team=' . $data[$i]->match_id . '">' . $data[$i]->match_id . '</a> (<span>' . $data[$i]->account_name . '</span>)<br>' . $data[$i]->order_id;
+            }
+            if ($data[$i]->game_code == 'bq') {
+                $data[$i]->match_id_order = '<a href="/admin/Sportsbq/outcome?home_team=' . $data[$i]->match_id . '">' . $data[$i]->match_id . '</a> (<span>' . $data[$i]->account_name . '</span>)<br>' . $data[$i]->order_id;
+            }
+
+            $data[$i]->league = $data[$i]->name_chinese;
+
+
+            if ($data[$i]->is_champion == 0) {
+                $data[$i]->home_guest = $data[$i]->home_team . ' VS ' . $data[$i]->guest_team;
+                $data[$i]->time = '开赛:' . $data[$i]->match_date . ' ' . $data[$i]->match_time;
+            } else {
+                $data[$i]->home_guest = '冠军联赛投注';
+                $data[$i]->time = '结束:' . $data[$i]->last_time;
+
+            }
+            $data[$i]->money_match_time = '下注:' . $data[$i]->money_time . $data[$i]->time;
+
+            //反水
+            $data[$i]->water_return = -1;
+            for ($a = 0; $a < count($water_return_money); $a++) {
+                if ($data[$i]->order_id == $water_return_money[$a]->trade_id) {
+                    if ($data[$i]->status == 2 || $data[$i]->status == 3) {
+                        $data[$i]->water_return = 0;
+                    } else {
+                        $data[$i]->water_return = $water_return_money[$a]->money;
+                    }
+                    //用户投注后账户金额
+                    $data[$i]->frozen_cash = $water_return_money[$a]->money_cash;
+                }
+            }
+            if ($data[$i]->water_return == -1) {
+                $data[$i]->water_return = 0;
+                //用户投注后账户金额
+                $data[$i]->frozen_cash = $data[$i]->money_cash;
+            }
+            //此时结果金额
+            $data[$i]->result = $data[$i]->water_return + $data[$i]->gain_money;
+            //用户投注前账户金额
+            $data[$i]->available_cash = $data[$i]->money_cash + $data[$i]->money;
+            //投注前后账户金额
+            $data[$i]->account_money = $data[$i]->available_cash . '<br><span>' . $data[$i]->money . '</span><br>' . $data[$i]->frozen_cash;
+            if ($data[$i]->status == 2 || $data[$i]->status == 3) {
+                for ($b = 0; $b < count($invalid_money); $b++) {
+                    if ($data[$i]->order_id == $invalid_money[$b]->trade_id) {
+                        $data[$i]->available_cash = $invalid_money[$b]->money_cash;
+                        $data[$i]->account_money = $data[$i]->available_cash;
+                    }
+                }
+            }
+            $data[$i]->str = 0;
+            for ($b = 0; $b < count($content); $b++) {
+                $data[$i]->str1 = 0;
+                $data[$i]->team = '';
+                if (!empty($content[$b]->odds_code)) {
+                    if (!empty(stristr($content[$b]->odds_code, 'home'))) {
+                        $data[$i]->team = $data[$i]->home_team;
+                    }
+                    if (!empty(stristr($content[$b]->odds_code, 'guest'))) {
+                        $data[$i]->team = $data[$i]->guest_team;
+                    }
+
+                    if ($content[$b]->p_code == 'half_full') {
+                        $string = str_replace('home', $data[$i]->home_team, $content[$b]->odds_code);
+                        $string = str_replace('guest', $data[$i]->guest_team, $string);
+                        $string = str_replace('dogfall', '和局', $string);
+                        $string = explode('_', $string);
+                        $data[$i]->team = $string['2'] . '/' . $string['3'];
+                    }
+                }
+
+                //处理普通赛事玩法详情
+                if ($data[$i]->match_id == $content[$b]->match_id && $data[$i]->batch_id == $content[$b]->batch_id && $data[$i]->is_champion == 0) {
+
+                    if ($content[$b]->p_code == 'first_last_ball' || $content[$b]->p_code == 'half_full' || $content[$b]->p_code == 'capot' || $content[$b]->p_code == 'two_sides' || $content[$b]->p_code == 'total_goal') {
+                        $content[$b]->condition = '';
+                    }
+
+                    $data[$i]->game_status = $data[$i]->game_status;
+
+                    //投注详情
+                    if (!empty($data[$i]->match_time)) {
+                        $data[$i]->content1 = '[' . $data[$i]->match_time . ']';
+                        //$data[$i]->match_time = $data[$i]->match_time;
+                    } else {
+                        if (!empty($data[$i]->last_time)) {
+                            $datetime = explode(' ', $data[$i]->last_time);
+                            //$data[$i]->match_time = $datetime[1];
+                            $data[$i]->content1 = '[' . $datetime[1] . ']';
+                        }
+                    }
+                    for ($c = 0; $c < count($result); $c++) {
+                        if ($content[$b]->odds_code == $result[$c]->odds_code) {
+                            $data[$i]->str1 = 1;
+                            if ($content[$b]->result == '未处理') {
+                                $data[$i]->content = $data[$i]->content . $result[$c]->odds_name . '<br>' . $content[$b]->condition . ' ' . $data[$i]->team . '@' . $content[$b]->odds . ' ¥' . $content[$b]->bet_money . '<br>';
+                            } else {
+                                $data[$i]->content = $data[$i]->content . $result[$c]->odds_name . '<br>' . $content[$b]->condition . ' ' . $data[$i]->team . '@' . $content[$b]->odds . ' ¥' . $content[$b]->bet_money . '<br><span>' . $content[$b]->result . '</span>(' . $content[$b]->matchresult . ')<br>';
+                            }
+                        }
+                    }
+                    if ($data[$i]->str1 == 0) {
+                        if ($content[$b]->result == '未处理') {
+                            $data[$i]->content = $data[$i]->content . $content[$b]->odds_code . '<br>' . $content[$b]->condition . ' ' . $data[$i]->team . '@' . $content[$b]->odds . ' ¥' . $content[$b]->bet_money . '<br>';
+                        } else {
+                            $data[$i]->content = $data[$i]->content . $content[$b]->odds_code . '<br>' . $content[$b]->condition . ' ' . $data[$i]->team . '@' . $content[$b]->odds . ' ¥' . $content[$b]->bet_money . '<br><span>' . $content[$b]->result . '</span>(' . $content[$b]->matchresult . ')<br>';
+                        }
+                    }
+                }
+                //处理冠军联赛玩法详情
+                if ($data[$i]->match_id == $content[$b]->lg_id && $data[$i]->batch_id == $content[$b]->batch_id && $data[$i]->is_champion == 1) {
+                    $content[$b]->condition = '';
+
+                    if ($content[$b]->p_code == 'first_last_ball' || $content[$b]->p_code == 'half_full' || $content[$b]->p_code == 'capot' || $content[$b]->p_code == 'two_sides' || $content[$b]->p_code == 'total_goal') {
+                        $content[$b]->condition = '';
+                    }
+
+                    $data[$i]->game_status = $data[$i]->game_status;
+
+                    /*
+                    //投注详情
+                    if(!empty($data[$i]->match_time)){
+                        $data[$i]->content1 = '['.$data[$i]->match_time.']';
+                        //$data[$i]->match_time = $data[$i]->match_time;
+                    }
+                    else{
+                        if(!empty($data[$i]->last_time)){
+                            $datetime = explode(' ',$data[$i]->last_time);
+                            //$data[$i]->match_time = $datetime[1];
+                            $data[$i]->content1 = '['.$datetime[1].']';
+                        }
+                    }
+                    */
+                    /*
+                    for($c=0;$c<count($result);$c++){
+                        if($content[$b]->odds_code == $result[$c]->odds_code){
+                            $data[$i]->str1 = 1;
+                            if($content[$b]->result=='未处理'){
+                                $data[$i]->content = $content[$b]->home_team.'<br>'.$data[$i]->content.$result[$c]->odds_name.'<br>'.$content[$b]->condition.' '.$data[$i]->team.'@'.$content[$b]->odds.' ¥'.$content[$b]->bet_money.'<br>';
+                            }else{
+                                $data[$i]->content = $content[$b]->home_team.'<br>'.$data[$i]->content.$result[$c]->odds_name.'<br>'.$content[$b]->condition.' '.$data[$i]->team.'@'.$content[$b]->odds.' ¥'.$content[$b]->bet_money.'<br><span>'.$content[$b]->result.'</span>('.$content[$b]->matchresult.')<br>';
+                            }
+                        }
+                    }
+                    */
+                    if ($data[$i]->str1 == 0) {
+                        if ($content[$b]->result == '未处理') {
+                            $data[$i]->content = $content[$b]->home_team . '<br>' . $data[$i]->content . $content[$b]->odds_code . '<br>' . $content[$b]->condition . ' ' . $data[$i]->team . '@' . $content[$b]->odds . ' ¥' . $content[$b]->bet_money . '<br>';
+                        } else {
+                            $data[$i]->content = $content[$b]->home_team . '<br>' . $data[$i]->content . $content[$b]->odds_code . '<br>' . $content[$b]->condition . ' ' . $data[$i]->team . '@' . $content[$b]->odds . ' ¥' . $content[$b]->bet_money . '<br><span>' . $content[$b]->result . '</span>(' . $content[$b]->matchresult . ')<br>';
+                        }
+                    }
+                }
+            }
+            // if($data[$i]->status == 1){
+            // if($data[$i]->match_status == 0 || $data[$i]->match_status == 1){
+            //     $data[$i]->game_status = $data[$i]->settle_status.'<br><a class="layui-btn layui-btn-sm audit" lay-event="detail" pid="id" uri="" href="javascript:void(0)" style="background-color: grey;"> 结算 </a>';
+            // }
+            //     if($data[$i]->match_status == 2 || $data[$i]->match_status == 3 || $data[$i]->match_status == 5){
+            //         if($data[$i]->settle_status == '已结算'){
+            //             $data[$i]->game_status = $data[$i]->settle_status.'<br><a class="layui-btn layui-btn-sm resettlement" lay-event="detail" pid="id" uri="/admin/SoccerNoteList/resettlement/?id=" href="javascript:resettlement(\'/admin/SoccerNoteList/resettlement/?id='.$data[$i]->id.'\');"> 重新结算 </a>';
+            //         }else{
+            //             $data[$i]->game_status = $data[$i]->settle_status.'<br><a class="layui-btn layui-btn-sm settlement" lay-event="detail" pid="id" uri="/admin/SoccerNoteList/settlement/?id=" href="javascript:settlement(\'/admin/SoccerNoteList/settlement/?id='.$data[$i]->id.'\');"> 结算 </a>';
+            //         }
+            //     }
+            // }else{
+            //     $data[$i]->game_status = $data[$i]->settle_status.'<br><a class="layui-btn layui-btn-sm audit" lay-event="detail" pid="id" uri="" href="javascript:void(0)" style="background-color: grey;"> 结2算 </a>';
+            // }
+
+            $data[$i]->content = $data[$i]->content1 . $data[$i]->content;
+
+        }
+        return $data->toArray();
+
+    }
+
+
 }

+ 44 - 0
app/Models/StoddsCode.php

@@ -0,0 +1,44 @@
+<?php
+
+namespace App\Models;
+/**
+ *
+ */
+class StoddsCode extends BaseModel
+{
+    protected $table = 'st_odds_code';
+    public $timestamps = false;
+
+    public function getTypeDatas($ret_game_code = '')
+    {
+        $all = self::all()->toArray();
+        if (empty($all)) {
+            return [];
+        }
+
+        $allIDKey = [];
+        foreach ($all as $val) {
+            $id = $val['id'];
+            $allIDKey[$id] = $val;
+        }
+
+        $retall = [];
+        foreach ($allIDKey as $id => $val) {
+            if ($val['p_id'] != 0) {
+                $game_code = $val['game_code'];
+                $pid = $val['p_id'];
+                $pidcode = $allIDKey[$pid]['odds_code'];
+                $nowcode = $val['odds_code'];
+                $retall[$game_code][$pidcode][$nowcode] = $val;
+            }
+        }
+        if (empty($ret_game_code)) {
+            return $retall;
+        } else {
+            return $retall[$ret_game_code];
+        }
+    }
+
+}
+
+?>

+ 1 - 0
resources/lang/zh-cn/sportsnotelist.php

@@ -32,6 +32,7 @@ return array(
     'edit' => '修改',
     'ifsettlement' => '结算状态',
     'order_status' => '注单状态',
+    'roll_ratify' => '审核',
 
     'str_type' => '模式',
     'detail_content' => '结算详细信息',

+ 2 - 2
resources/views/sports/sports_notelist.blade.php

@@ -28,7 +28,7 @@
         @{{#if(d.status==2 || d.status==3 || d.status==5){ }}
             <button onclick="resettlement('@{{d.order_id}}','{{$type}}','@{{d.match_id}}')" class="layui-btn layui-btn-sm settlement">再1结算</button>
         @{{#} }}
-            <button onclick="setScore('@{{d.order_id}}','@{{d.match_id}}')" class="layui-btn layui-btn-sm settlement">设置比分</button>
+        <button style="margin-left: 0;" onclick="setScore('@{{d.order_id}}','@{{d.match_id}}')" class="layui-btn layui-btn-sm settlement">设置比分</button>
 
     </script>
 
@@ -411,7 +411,7 @@
               // 拼接玩法数据
               for (let o in getData) {
                 id = getData[o].id;
-                teamName = getData[o].home_team + ' VS ' + getData[o].guest_team + ' - ' + getData[o].guest_team;
+                teamName = getData[o].home_team + ' VS ' + getData[o].guest_team + ' - ' + getData[o].odds_name;
                 content +=
                     '        <div style="margin-top: 10px; margin-bottom: 10px;">' +
                     '            <div style="color: #5f5f5f; margin-left: 10px; margin-bottom: 10px;">' + teamName + '</div>' +

+ 46 - 1
resources/views/sports/sports_search.blade.php

@@ -362,7 +362,10 @@
     for(var i in data){
     data[i]=parseFloat(data[i]);
     }
-    str+='<p class="bottom-txt">总投注金额:<span class="blue">'+data.all_money+'</span> , 总可赢金额:<span class="red">'+data.all_prize_money+'</span> , 已赢金额:<span class="green">'+data.alraedy_prize_money+'</span></p>'
+    if(data.all_money != 0){
+        str+='<p class="bottom-txt">总投注金额:<span class="blue">'+data.all_money+'</span> , 总可赢金额:<span class="red">'+data.all_prize_money+'</span> , 已赢金额:<span class="green">'+data.alraedy_prize_money+'</span></p>';
+    }
+
     {{--str+='<p class="bottom-txt">总金额:<span class="blue">'+data.all_money+'</span> , 成功:<span class="green">'+data.success_money+'</span> , 手续费:<span class="red">'+data.service_money+'</span> , 处理中:<span class="yellow">'+data.handing+'</span></p>'--}}
     $('#statistics').html(str);
     var height1=$('.layui-table-view').height();
@@ -452,6 +455,48 @@
             });
 
         }
+
+
+
+        //单式注单通过审核
+        function check(url,ids) {
+            layer.confirm('确认通过审核?', {
+                btn: ['确认', '取消'] //按钮
+            }, function() {
+                $.getJSON(url, function(data, textStatus) {
+                    //console.log(data);
+                    if (data == '1') {
+                        reloadDataTable();
+                        layer.msg('成功');
+                    } else {
+                        layer.msg(data.msg);
+                    }
+                });
+            }, function() {
+
+            });
+
+        }
+
+        //单式注单拒绝审核
+        function nocheck(url,ids) {
+            layer.confirm('确认拒绝审核?', {
+                btn: ['确认', '取消'] //按钮
+            }, function() {
+                $.getJSON(url, function(data, textStatus) {
+                    //console.log(data);
+                    if (data == '1') {
+                        reloadDataTable();
+                        layer.msg('成功');
+                    } else {
+                        layer.msg(data.msg);
+                    }
+                });
+            }, function() {
+
+            });
+
+        }
     </script>
 
     @include('vip.datatable')