| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447 |
- <?php
- namespace App\Api\Controller;
- use Biz\Money\Moneycopy;
- use Biz\Money\Money;
- use Biz\Account\AccountManager;
- use App\Api\Model\St_odds_code as odds_codeModel;
- use App\Api\Model\Dc_user_grade;
- use Biz\Db\Redis\Cache as Redis;
- use Illuminate\Support\Testing\Fakes\QueueFake;
- // use Illuminate\Contracts\Queue\Queue;
- /*
- * Class Register
- * @package App\Api\Controller
- * User: junghwi
- * Date: 2019/3/21
- */
- class Betorder extends BaseController{
- private $simplex_money = 0; //单式投注总额
- public function init() {
- $this->time = date('Y-m-d H:i:s',time());
- $this->MC = new Moneycopy();
- $this->M = new Money();
- $this->accountManager = new AccountManager();
- $this->commonFunction = C()->get('commonFunction');
- }
- /**
- * 测试写队列 任务
- */
- public function dd(){
- //laterOn
- //实例化 队列
- $Queue = new QueueFake();
- //新建队列 任务
- $Queue ->push('a','c','123');
- /*
- $redis = new Redis();
- $redis->set('name','pengjun');
- $name = $redis->get('name');
- dd($name);
- */
- }
- /**
- * 单式串式分类
- * @param [array] $res 投注数据
- * @return [array] $data
- *
- */
- public function Classify(array $res){
- if(empty($res)){
- Render($res, '7003',lang('Errors','Api')->get('error-7003'));
- }
- $data['single'] = [];//单式
- $data['bunch'] = [];//串式
- $last[] = $res[count($res)-1];
- unset($res[count($res)-1]);
- foreach ($last as $k =>$v){
- foreach ($v as $kk =>$vv){
- /*
- $num = $kk+1;
- //验证球类代码是否有效
- $this->verify_gameType($vv['ballId'],$num);
- //验证联赛是否存在
- $this->verify_league($vv['ballId'],(int)$vv['lg_id'],$num);
- //验证赛事/赔率代码是否存在,如果match_id = 0 则为冠军联赛赔率,无需验证
- if($vv['match_id'] > 0 and $vv['is_champion'] == 0){
- $this->verify_match($vv['ballId'],$vv['match_id'],$num);
- //验证赛事下赔率玩法是否有效
- $this->verify_odds($vv['ballId'],$vv['odds_only'],$vv['odds'],$vv['condition'],$vv['odds_code'],$num);
- }
- */
- }
- }
- foreach($res as $k => $v){
- //根据类型分组
- if($v['type'] == '1'){
- $data['single'][$k] = array_merge($last[0][$v['index']],$v);
- }else{
- $data['bunch'][$k] = $v;
- }
- }
- if(!empty($data['bunch'])){
- $data['bunch'] = array_merge_recursive($data['bunch'],$last);
- }
- return $data;
- }
- /**
- * 根据赛事ID分组
- * @param [array] $data 球类数据
- * @return [array] $data
- */
- public function Group_ball($data = []){
- if(empty($data)){
- return $data;
- }
-
- foreach($data as $k => $v){
- //普通赛事
- if($v['match_id'] > 0){
- if(!isset($data[$v['match_id']])){
- $data[$v['match_id']][] = $v;
- unset($data[$k]);
- }else{
- $data[$v['match_id']][] = $v;
- unset($data[$k]);
- }
- }
- //冠军联赛
- if($v['match_id'] == 0){
- if(!isset($data[$v['lg_id']])){
- $data[$v['lg_id']][] = $v;
- unset($data[$k]);
- }else{
- $data[$v['lg_id']][] = $v;
- unset($data[$k]);
- }
- }
-
- }
- return $data;
- }
- /**
- * 单式投注数据处理
- * @param [array] $res 单式投注数据
- * @return [int] 1 成功 其他失败
- * @param [int] $batch_id 批量ID
- * 弃用
- */
- public function Simplex_bet(array $res,array $userInfo,$batch_id){
- if(empty($res)||empty($userInfo)||empty($batch_id)){
- Render('', '7003',lang('Errors','Api')->get('error-7003'));
- }
- //验证与判断投注了几种
- foreach($res as $k => $v){
- $num = $k + 1;
- if(empty($v['bet_amount'])){
- $msg = '第'.$num.'条'.lang('Errors','Api')->get('error-5105');
- Render([], '5105',$msg);
- }
- //根据类型分组
- if(!isset($res[$v['ballId']])){
- $res[$v['ballId']][] = $v;
- unset($res[$k]);
- }else{
- $res[$v['ballId']][] = $v;
- unset($res[$k]);
- }
- }
- //球类联赛分类并且插入数据库
- foreach($res as $k => $v){
- $this->Simplex_bet_insert($v,$userInfo,$k,$batch_id);
- /*
- $gamedate = $this->Group_ball($res[$k]);
- $this->Simplex_bet_insert($gamedate,$userInfo,$k,$batch_id);
- */
- }
- return $odds_ids;
- }
- //弃用 备份
- public function Simplex_bet___(array $res,array $userInfo,$batch_id){
- if(empty($res)||empty($userInfo)||empty($batch_id)){
- Render('', '7003',lang('Errors','Api')->get('error-7003'));
- }
- //验证与判断投注了几种
- foreach($res as $k => $v){
- $num = $k + 1;
- if(empty($v['bet_amount'])){
- $msg = '第'.$num.'条'.lang('Errors','Api')->get('error-5105');
- Render([], '5105',$msg);
- }
- //根据类型分组
- if(!isset($res[$v['ballId']])){
- $res[$v['ballId']][] = $v;
- unset($res[$k]);
- }else{
- $res[$v['ballId']][] = $v;
- unset($res[$k]);
- }
- }
- //球类联赛分类并且插入数据库
- foreach($res as $k => $v){
- $gamedate = $this->Group_ball($res[$k]);
- $this->Simplex_bet_insert($gamedate,$userInfo,$k,$batch_id);
- }
- return $odds_ids;
- }
- /**
- * 单式投注单个球类数据插入
- * @param [array] $data 单式投注数据
- * @param [array] $userInfo 用户信息
- * @param [type] $game_code 球类代码
- * @param [int] $batch_id 批量ID
- * @return [int] 1 成功 其他失败
- */
- public function Simplex_bet_insert__($data,$userInfo,$game_code,$batch_id){
- if(empty($data)||empty($userInfo)||empty($game_code)){
- Render('', '7003',lang('Errors','Api')->get('error-7003'));
- }
- foreach($data as $k => $v){
- $OrderID = OrderID('S');//生成订单ID
- $UUID = UUID(); //生成信息ID
- $bet_money = 0; //赛事总投注额
- $prize_money = 0; //可赢额
- //获取投注单中是否有冠军联赛数据
- $championData = [];
- foreach($v as $kk => $vv){
- $bet_money += $vv['bet_amount'];
- //计算每个投注玩法下的可赢金额
- // $prize_money += $this->commonFunction->getEarnMoney($game_code,$vv['p_code'],$vv['odds'],$vv['bet_amount'],1);
- $prize_money += $vv['odds']* $vv['bet_amount'];
- //是否是滚球投注
- $is_rolling = 0;
- if($vv['oddsType']=='StRollBall'){
- $is_rolling = 1;
- }
- $matchData =[
- 'odds_id' =>$vv['id'],
- 'home_team' => $vv['home_team'],
- 'guest_team' => $vv['guest_team'],
- 'condition' => $vv['condition'],
- 'odds' => $vv['odds'],
- 'odds_code' => $vv['odds_code'],
- 'p_code' => $vv['p_code'],
- 'odds_only' => $vv['odds_only'],
- 'match_id' => $vv['match_id'],
- 'game_code' => $game_code,
- 'lg_id' => $vv['lg_id'],
- 'batch_id' => $batch_id,
- 'bet_type' => 1,
- 'bet_money' => $vv['bet_amount'],
- 'ctime' => $this->time,
- 'utime' => $this->time,
- 'is_rolling' =>$is_rolling,
- ];
- //插入数据源
- $moneyBuyMatch = lm('MoneyBuyMatch','Api')->insert($matchData);
- if(!$moneyBuyMatch){
- Render('','3205',lang('errors','Api')->get('error-3205'));
- }
- }
- $order =[
- 'info_identity' => $UUID,
- 'account_name' => $userInfo['account'],
- 'account_identity' => $userInfo['account_identity'],
- 'order_id' => OrderID('S'),//$OrderID,
- 'game_code' => $game_code,
- 'batch_id' => $batch_id,
- 'match_id' => $k,
- 'game_no' => "",
- 'prize_money'=> $prize_money,
- 'money' => $bet_money, //投注金额
- 'money_time' => $this->time
- ];
- $insert = lm("MoneyBuySimplex",'Api')->insert($order);
- if(!$insert){
- Render('','3205',lang('errors','Api')->get('error-3205'));
- }
- $insertMoney = $this->M->insertMoney($userInfo['account_identity'],$bet_money,$OrderID,1,"",$UUID,$userInfo);
-
- if($insertMoney!=1){
- Render('', $insertMoney,lang('Errors','Api')->get('error'.$insertMoney));
- }
- $this->M->fanshui($userInfo['account_identity'],$userInfo['account'],$bet_money,$OrderID);//反水
- }
- }
- //按赛事分组 一个赛事一个注单
- public function Simplex_bet_insert_v1($data,$userInfo,$game_code,$batch_id){
- if(empty($data)||empty($userInfo)||empty($game_code)){
- Render('', '7003',lang('Errors','Api')->get('error-7003'));
- }
- foreach($data as $k => $v){
- $OrderID = OrderID('S');//生成订单ID
- $UUID = UUID(); //生成信息ID
- $bet_money = 0; //赛事总投注额
- $prize_money = 0; //可赢额
- foreach($v as $kk => $vv){
- //是否是冠军投注,如果==0 则为冠军投注
- $is_champion = 0;
- if($vv['match_id'] == 0){
- $is_champion = 1;
- }
- //获取联赛id lg_id
- $lg_id = $vv['lg_id'];
- $bet_money += $vv['bet_amount'];
- //计算每个投注玩法下的可赢金额
- // $prize_money += $this->commonFunction->getEarnMoney($game_code,$vv['p_code'],$vv['odds'],$vv['bet_amount'],1);
- $prize_money += $vv['odds']* $vv['bet_amount'];
- //是否是滚球投注
- $is_rolling = 0;
- if($vv['oddsType']=='StRollBall'){
- $is_rolling = 1;
- }
- $matchData =[
- 'odds_id' =>$vv['id'],
- 'home_team' => $vv['home_team'],
- 'guest_team' => $vv['guest_team'],
- 'condition' => $vv['condition'],
- 'odds' => $vv['odds'],
- 'odds_code' => $vv['odds_code'],
- 'p_code' => $vv['p_code'],
- 'odds_only' => $vv['odds_only'],
- 'match_id' => $vv['match_id'],
- 'game_code' => $game_code,
- 'lg_id' => $vv['lg_id'],
- 'batch_id' => $batch_id,
- 'bet_type' => 1,
- 'bet_money' => $vv['bet_amount'],
- 'ctime' => $this->time,
- 'utime' => $this->time,
- 'is_rolling' =>$is_rolling,
- 'is_champion' => $is_champion?:0,//1 冠军投注 0普通赛事投注
- 'order_id'=>$OrderID,//追加所属订单id
- ];
- //插入数据源
- $moneyBuyMatch = lm('MoneyBuyMatch','Api')->insert($matchData);
- if(!$moneyBuyMatch){
- Render('','3205',lang('errors','Api')->get('error-3205'));
- }
- }
- $order = [];
- $order =[
- 'info_identity' => $UUID,
- 'account_name' => $userInfo['account'],
- 'account_identity' => $userInfo['account_identity'],
- 'order_id' => $OrderID,//$OrderID,
- 'game_code' => $game_code,
- 'batch_id' => $batch_id,
- 'match_id' => $k,
- 'lg_id' => $lg_id,
- 'game_no' => "",
- 'prize_money'=> $prize_money,
- 'money' => $bet_money, //投注金额
- 'money_time' => $this->time,
- 'is_champion' => $is_champion?:0,//1 冠军投注 0普通赛事投注
- ];
- //如果是冠军投注,追加字段
- if($is_champion == 1){
- $json_single_result = [
- 'lg_id'=> '',
- 'game_name' => '',
- 'result' => '',
- 'updatetime' => '',
- ];
- $order['single_result'] = json_encode($json_single_result);
- }
- //如果是滚球投注,追加字段
- if($is_rolling == 1 and $game_code == 'zq'){
- $order['roll_ratify'] = 2;//未审核滚球投注
- }
- $insert = lm("MoneyBuySimplex",'Api')->insert($order);
- if(!$insert){
- Render('','3205',lang('errors','Api')->get('error-3205'));
- }
- $insertMoney = $this->M->insertMoney($userInfo['account_identity'],$bet_money,$OrderID,1,"",$UUID,$userInfo);
-
- if($insertMoney!=1){
- Render('', $insertMoney,lang('Errors','Api')->get('error'.$insertMoney));
- }
- $this->M->fanshui($userInfo['account_identity'],$userInfo['account'],$bet_money,$OrderID);//反水
- }
- }
- //无需按赛事分组
- public function Simplex_bet_insert($data,$userInfo,$game_code,$batch_id){
- if(empty($data)||empty($userInfo)||empty($game_code)){
- Render('', '7003',lang('Errors','Api')->get('error-7003'));
- }
- foreach($data as $k => $v){
- $OrderID = OrderID('S');//生成订单ID
- $UUID = UUID(); //生成信息ID
- $bet_money = 0; //赛事总投注额
- $prize_money = 0; //可赢额
- //====处理 投注数据
- //是否是冠军投注,如果==0 则为冠军投注
- $is_champion = 0;
- if($v['match_id'] == 0){
- $is_champion = 1;
- }
- //获取联赛id lg_id
- $lg_id = $v['lg_id'];
- $bet_money = $v['bet_amount'];
- //计算每个投注玩法下的可赢金额
- $prize_money = $v['odds']* $v['bet_amount'];
- //是否是滚球投注
- $is_rolling = 0;
- //追加滚球投注时 赛事进行时间
- $roll_time = 0;
- //主队得分
- $home_score = 0;
- //客队得分
- $guest_score = 0;
- if($v['oddsType']=='StRollBall'){
- $is_rolling = 1;
- $roll_time=$v['roll_time']?:'';
- $home_score = $v['home_score']?:0;
- $guest_score = $v['guest_score']?:0;
- }
- //===追加各球类其他状态码===
- //即将
- if($v['oddsType']=='StSoon'){
- $is_rolling = 2;
- }
- //今日
- if($v['oddsType']=='StToday'){
- $is_rolling = 3;
- }
- //早盘
- if($v['oddsType']=='StMorningPlate'){
- $is_rolling = 4;
- }
- //串场
- if($v['oddsType']=='StStringScene'){
- $is_rolling = 5;
- }
- //冠军
- if($v['oddsType']=='StChampion'){
- $is_rolling = 6;
- }
- //首页
- if($v['oddsType']=='home'){
- $is_rolling = 7;
- }
- //===end===
- $matchData =[
- 'odds_id' =>$v['id'],
- 'home_team' => $v['home_team'],
- 'guest_team' => $v['guest_team'],
- 'condition' => $v['condition'],
- 'odds' => $v['odds'],
- 'odds_code' => $v['odds_code'],
- 'p_code' => $v['p_code'],
- 'odds_only' => $v['odds_only'],
- 'match_id' => $v['match_id'],
- 'game_code' => $game_code,
- 'lg_id' => $lg_id,
- 'batch_id' => $batch_id,
- 'bet_type' => 1,
- 'bet_money' => $bet_money,
- 'ctime' => $this->time,
- 'utime' => $this->time,
- 'is_rolling' =>$is_rolling,
- 'is_champion' => $is_champion?:0,//1 冠军投注 0普通赛事投注
- 'order_id'=>$OrderID,//追加所属订单id
- 'roll_time'=>$roll_time,//追加滚球投注时 赛事进行时间
- 'home_score'=>$home_score,//主队得分
- 'guest_score'=>$guest_score,//客队得分
- ];
- //插入数据源
- $moneyBuyMatch = lm('MoneyBuyMatch','Api')->insert($matchData);
- if(!$moneyBuyMatch){
- Render('','3205',lang('errors','Api')->get('error-3205'));
- }
- //===end===
- $order = [];
- $order =[
- 'info_identity' => $UUID,
- 'account_name' => $userInfo['account'],
- 'account_identity' => $userInfo['account_identity'],
- 'order_id' => $OrderID,//$OrderID,
- 'game_code' => $game_code,
- 'batch_id' => $batch_id,
- 'match_id' => $v['match_id'],
- 'lg_id' => $lg_id,
- 'game_no' => "",
- 'prize_money'=> $prize_money,
- 'money' => $bet_money, //投注金额
- 'money_time' => $this->time,
- 'is_champion' => $is_champion?:0,//1 冠军投注 0普通赛事投注
- ];
- //如果是冠军投注,追加字段
- if($is_champion == 1){
- $json_single_result = [
- 'lg_id'=> '',
- 'game_name' => '',
- 'result' => '',
- 'updatetime' => '',
- ];
- $order['single_result'] = json_encode($json_single_result);
- }
- //如果是滚球投注,追加字段
- if($is_rolling == 1 and $game_code == 'zq'){
- $order['roll_ratify'] = 2;//未审核滚球投注
- }
- $insert = lm("MoneyBuySimplex",'Api')->insert($order);
- if(!$insert){
- Render('','3205',lang('errors','Api')->get('error-3205'));
- }
- $insertMoney = $this->M->insertMoney($userInfo['account_identity'],$bet_money,$OrderID,1,"",$UUID,$userInfo);
-
- if($insertMoney!=1){
- Render('', $insertMoney,lang('Errors','Api')->get('error'.$insertMoney));
- }
- $this->M->fanshui($userInfo['account_identity'],$userInfo['account'],$bet_money,$OrderID);//反水
- //===追加写处理队列===
- //订单号 比赛id188 开赛日期时间 比赛状态(早盘,今日,串场,滚球), 父级玩法, 子级玩法,排序
- //获取开赛时间
- //根据球类代码 获取相关model
- $models = $this->commonFunction->getModels($v['ballId']);
- $model_match = $models['model_match'];
- $info = lm($model_match,'Sports')
- ->select('match_date','match_time','match_identity')
- ->where('id',$v['match_id'])
- ->first();
- $match_time = $info->match_date.' '.$info->match_time;
- $orderData = [
- 'order_type'=>1,//订单类型 1单式 2串式
- 'order_id'=>$OrderID,//订单ID
- 'matchData'=>[
- [
- 'game_code'=>$v['ballId'],//球类代码
- 'other_match_id'=>$v['others_match_id'],//第三方赛事id 188
- 'match_id'=>$v['match_id'],//本地赛事id
- 'match_uuid'=> $info->match_identity,//赛事uuid
- 'odds_code'=>$v['odds_code'],//子玩法代码
- 'p_code'=>$v['p_code'],//父玩法代码
- 'match_time'=>$match_time,//开赛时间
- 'match_type'=>$is_rolling,//比赛盘口
- 'sort'=>$v['sort'],//排序
- ]
- ],
- ];
- $this->commonFunction->setOrderQueue($orderData);
- }
- }
- public function Bet(){
-
- /*
- // 模拟单式数据
- $get_data = [
- 'data'=>[
- [
- 'type'=>1,
- 'index'=>0,
- 'bet_amount'=>100,
- ],
- [
- 'type'=>1,
- 'index'=>1,
- 'bet_amount'=>100,
- ],
- [
- [
- 'id'=>10350565,
- 'home_team'=>'什鲁斯伯里',
- 'guest_team'=>'彼德堡',
- 'name'=>'大',
- 'odds'=>1.09,
- 'match_id'=>1463,
- 'condition'=>'2.5/3',
- 'ballId'=>'zq',
- 'odds_code'=>'gsb',
- 'p_code'=>'GS',
- 'play_name'=>'进球大小',
- 'score'=>0,
- 'bettingTime'=>date('Y-m-d H:i:s',time()),
- 'odds_only'=>'6a003dec710a42849a82dd1ea978f572',
- 'lg_id'=>17,
- 'match_type'=>'',//滚球投注
- 'odds_id'=>10350565,
- 'repeat'=>'true',
- 'is_champion'=>0,//是否是冠军联赛
- ],
- [
- 'id'=>10781633,
- 'home_team'=>'什鲁斯伯里',
- 'guest_team'=>'彼德堡',
- 'name'=>'彼德堡',
- 'odds'=>1,
- 'match_id'=>1463,
- 'condition'=>'-0/0.5',
- 'ballId'=>'zq',
- 'odds_code'=>'cog',
- 'p_code'=>'CO',
- 'play_name'=>'让球',
- 'score'=>0,
- 'bettingTime'=>date('Y-m-d H:i:s',time()),
- 'odds_only'=>'390e2b68992587438c0020179abc94f5',
- 'lg_id'=>17,
- 'match_type'=>'',//滚球投注
- 'odds_id'=>10781633,
- 'repeat'=>'true',
- 'is_champion'=>0,//是否是冠军联赛
- ]
- ]
- ],
-
- 'token'=>'Zj2aXC15738846155dcf92c78385c',
- 'bet_money'=>200,
- ];
- */
- /*
- // 模拟串式数据
- $get_data = [
- 'data'=>[
- [
- 'type'=>1,
- 'index'=>0,
- 'bet_amount'=>1,
- ],
- [
- 'type'=>'3串1',
- 'bet_amount' =>1,
- ],
- [
- [
- 'id'=>229351,
- 'home_team'=>'布琳狮子U20',
- 'guest_team'=>'圣奥尔本斯U20',
- 'name'=>'圣奥尔本斯U20',
- 'odds'=>1.01,
- 'match_id'=>0,
- 'condition'=>'4/4.5',
- 'ballId'=>'zq',
- 'odds_code'=>'goal_size_big',
- 'p_code'=>'goal_size',
- 'play_name'=>'大小',
- 'score'=>0,
- 'bettingTime'=>date('Y-m-d H:i:s',time()),
- 'odds_only'=>'908f8bae2233a0384c96c7b1f42e9ea7',
- 'lg_id'=>153,
- 'repeat'=>'false',
- 'match_type'=>'StRollBall',//滚球投注
- ],
- [
- 'id'=>238940,
- 'home_team'=>'格罗兹尼艾哈迈德U20',
- 'guest_team'=>'奥伦堡U20',
- 'name'=>'格罗兹尼艾哈迈德U20',
- 'odds'=>0.94,
- 'match_id'=>1247,
- 'condition'=>'1/1.5',
- 'ballId'=>'zq',
- 'odds_code'=>'concede_home',
- 'p_code'=>'concede',
- 'play_name'=>'让球',
- 'score'=>0,
- 'bettingTime'=>date('Y-m-d H:i:s',time()),
- 'odds_only'=>'9125bf40d6649fcdb663c43d8f55bebd',
- 'lg_id'=>20,
- 'repeat'=>'false',
- 'match_type'=>'StRollBall',//滚球投注
- ],
- [
- 'id'=>238958,
- 'home_team'=>'巴扬卡拉',
- 'guest_team'=>'马都拉联',
- 'name'=>'巴扬卡拉',
- 'odds'=>1.13,
- 'match_id'=>1254,
- 'condition'=>'0.5',
- 'ballId'=>'zq',
- 'odds_code'=>'concede_home',
- 'p_code'=>'concede',
- 'play_name'=>'让球',
- 'score'=>0,
- 'bettingTime'=>date('Y-m-d H:i:s',time()),
- 'odds_only'=>'3cf81ac0b9765218845fe8bc4de0ad99',
- 'lg_id'=>61,
- 'repeat'=>'false',
- 'match_type'=>'StRollBall',//滚球投注
- ],
- ]
- ],
-
- 'token'=>'ppWGRW15682541865d79a8eacb0b1',
- 'bet_money'=>2
- ];
- */
- //如果获取不到data,则为游戏端提交,需转成数组
- if(!empty($_POST['game_data'])){
- //获取参数转成数组
- $get_data = json_decode($_POST['game_data'],true);
- $token = $get_data['token'];
- $bet_money = $get_data['bet_money'];
- $data = $get_data['data'];
- // $bet_money_arr = $get_data['bet_money_arr'];
- }else{
- $data = $_REQUEST['data'];
- $bet_money = $_REQUEST['bet_money'];
- $token = $_REQUEST['token'];
- // $bet_money_arr = $_REQUEST['bet_money_arr'];
- }
- /*
- $data = $get_data['data'];
- $bet_money = $get_data['bet_money'];
- $token = $get_data['token'];
- */
- //验证用户token
- $userInfo = $this->getAgent($token);
- if(empty($data)||empty($bet_money)){
- Render('', '51029',lang('Errors','Api')->get('error-51029'));
- }
- //获取用户金额信息
- if(!$this->M->verifyMoney($bet_money,$userInfo['cash'])){
- Render('', '4204',lang('Errors','Api')->get('error-4204'));
- }
- //追加验证用户投注金额限额
- $this->bet_money_limit($data,$userInfo);
- //获取订单批次号
- $batch_id = OrderID();///strtotime(date('Y-m-d H:i:s',time())).mt_rand('1','99');//批量ID
- //执行数据插入
- try {
- _beginTransaction();//开启事务
- $data = $this->Classify($data);
- if(!empty($data['single'])){
- $this->Simplex_bet($data['single'],$userInfo,$batch_id);//单式数据处理
- }
- if(!empty($data['bunch'])){
- $data_all = $data['bunch'][count($data['bunch'])-1];//获取最后一个数组
- unset($data['bunch'][count($data['bunch'])-1]);//删除最后一个元素
- $this->stringBet($data['bunch'],$data_all,$userInfo,$batch_id);
- }
- _commit();//提交
- Render('', '1',lang('Errors','Api')->get('error-1'));
- } catch (Exception $e) {
- _rollBack();//回滚
- print $e->getMessage();
- }
- }
- /**
- * token获取用户详情
- */
- public function getAgent($token = '') {
- $checkToken = $this->accountManager->checkEffectiveTime($token);
- if ($checkToken['status'] != 1) {
- Render($checkToken['data'], $checkToken['status'], lang('commons')->get('user does login'));
- };
- $result = $this->accountManager->refreshToken($token);
- return $result['data'];
- }
- //验证联赛是否存在
- public function verify_league($game_code,$lg_id,$num = 1){
- if(empty($lg_id)){
- $msg = '第'.$num.'条'.lang('Errors','Api')->get('error-5112');
- Render([], '5112',$msg);
- }
- //根据球类代码 获取相关model
- $model = $this->commonFunction->getModels($game_code);
- $model_league = $model['model_league'];
- $info = lm($model_league,'Sports')
- ->select('id')
- ->where('id',$lg_id)
- ->first();
- if(empty($info)){
- $msg = '第'.$num.'条'.lang('Errors','Api')->get('error-5113');
- Render([], '5113',$msg);
- }
- }
- /**
- * 赛事是否存在或结束
- * @param [type] $game_code 球类代码
- * @param [type] $match_id 赔率ID
- * @param [type] $num 循环键值
- * $@param [type]type_str 串式
- *
- */
- public function verify_match($game_code,$match_id,$num = 1){
- if(empty($match_id)){
- $msg = '第'.$num.'条'.lang('Errors','Api')->get('error-5109');
- Render([], '5109',$msg);
- }
- //根据球类代码 获取相关model
- $models = $this->commonFunction->getModels($game_code);
- $model_match = $models['model_match'];
- $info = lm($model_match,'Sports')
- ->select('status')
- ->where('status', '<', '2')
- // ->where('us_time','>',qgmdate('Y-m-d H:i:s','', -4))
- // ->where('source','hg3535')
- ->where('id',$match_id)
- ->first();
- if(empty($info)){
- $msg = '第'.$num.'条'.lang('Errors','Api')->get('error-5103');
- Render([], '5103',$msg);
- }
- $info = $info->toarray();
- if($info['status'] == 2){
- $msg = '第'.$num.'条'.lang('Errors','Api')->get('error-5108');
- Render([], '5108',$msg);
- }
- return $info;
- }
- /**
- * 验证球类是否存在
- * @param [type] $game_code 球类代码
- * @param [type] $num 第几条
- */
- public function verify_gameType($game_code,$num){
- if(empty($game_code)){
- $msg = '第'.$num.'条数据'.lang('Errors','Api')->get('error-5102');
- Render([], '5102', $msg);
- }
- $info = lm('GameType','Sports')->where('game_code',$game_code)->first();
- if(empty($info)){
- $msg = '第' . $num . '条数据' . lang('Errors', 'Api')->get('error-5102');
- Render([], '5102', $msg);
- }
- return $info;
- }
- /**
- * 验证赔率是否存在
- * @param [type] $game_code 球类代码
- * @param [type] $odds_id 赔率IDkk
- *
- */
- public function verify_odds($game_code,$odds_only,$odds,$condition,$odds_code,$num = 1){
- if (empty($odds_only)){
- $msg = '第'.$num.'条数据'.lang('Errors','Api')->get('error-5111');
- Render([], '5111', $msg);
- }
- if(empty($odds_code)){
- $msg = '第'.$num.'条数据'.lang('Errors','Api')->get('error-7052');
- Render([], '7052', $msg);
- }
- if(empty($odds)){
- $msg = '第'.$num.'条数据'.lang('Errors','Api')->get('error-7029');
- Render([], '7029', $msg);
- }
- $odds_codeNum = odds_codeModel::getOddsCode($odds_code,$game_code);
- if($odds_codeNum < 1){
- $msg = '第'.$num.'条数据'.lang('Errors','Api')->get('error-7053');
- Render([], '7053', $msg);
- }
- //根据球类代码 获取相关model
- $models = $this->commonFunction->getModels($game_code);
- $model_odds = $models['model_odds'];
- $model_odds_record = $models['model_odds_record'];
- //匹配赔率是否过期
- $odds_info = lm($model_odds,'Sports')
- ->join($model_odds_record,$model_odds_record.'.odds_only',$model_odds.'.odds_only')
- ->select($model_odds_record.'.odds',$model_odds_record.'.condition')
- ->where($model_odds.'.odds_only',$odds_only)
- ->first();
- if(empty($odds_info)){
- $msg = '第'.$num.'条数据'.lang('Errors','Api')->get('error-7051');
- Render([], '7051', $msg);
- }
- $odds_info = $odds_info->toarray();
- if($condition != $odds_info['condition']){
- $msg = '第'.$num.'条数据'.lang('Errors','Api')->get('error-7047');
- Render([], '7047', $msg);
- }
- if($odds != $odds_info['odds']){
- $msg = '第'.$num.'条数据'.lang('Errors','Api')->get('error-7049');
- Render([], '7049', $msg);
- }
- return $odds_info;
- }
- /**
- * 处理串式投注
- * $data_str 各串式 数据
- * $data_all 所有赛事 数据
- * $userInfo 用户数据
- * $batch_id 批次号
- */
- public function stringBet__($data_str=[],$data_all=[],$userInfo=[],$batch_id=0){
- //验证串式投注是否合法
- $this->verify_stringType($data_all);
- //获取串式 总赛事数量
- $groupNum = count($data_all);//总数量
- $orderData = [];
- foreach ($data_str as $k=>$v){
- //字符串替换
- $str = str_ireplace("串","_",$v['type']);
- //获取type 3_12
- $after = substr($str,strpos($str,"_")+1);
- //当前串式 值
- $sonNum = substr($str,0,strrpos($str,"_"));
- //获取倍数
- if((int)$after == 1){
- $multiple = $this->getMultiple($groupNum,(int)$sonNum);
- }else{
- $multiple =(int)$after;
- }
- //获取当前串式投注金额及可赢金额
- if($after == 1){
- $money_all = $this->getmakeMoney((int)$sonNum,$v['bet_amount'],$multiple,$data_all,$after);
- }else{
- $money_all = $this->getStrAllMoney((int)$sonNum,$v['bet_amount'],$multiple,$data_all,$after);
- }
- //投注金额
- $moneyData = $money_all['moneyData'];
- //可赢金额
- $prize_money = $money_all['prize_money'];
- $uuid = UUID();
- $orderID = OrderID('T');
- $orderData[$k]['info_identity'] = $uuid;
- $orderData[$k]['account_name'] = $userInfo['account'];
- $orderData[$k]['account_identity'] = $userInfo['account_identity'];
- $orderData[$k]['order_id'] = $orderID;
- $orderData[$k]['game_no'] = "";
- $orderData[$k]['money'] = $moneyData;//$pay_money//总投注金额
- $orderData[$k]['money_time'] = $this->time;//下注时间
- $orderData[$k]['prize_money'] = $prize_money;//$expect_money ;//预期总可赢金额
- $orderData[$k]['str_type'] = $v['type'];//串式类型
- $orderData[$k]['batch_id'] = $batch_id;//批次号
- $orderData[$k]['wait_match_num'] = count($data_all);//批次号
- //写资金变动表
- $insertMoney = $this->M->insertMoney($userInfo['account_identity'],$moneyData,$orderID,1,"",$uuid,$userInfo);
- if($insertMoney!=1){
- Render('', $insertMoney,lang('Errors','Api')->get('error'.$insertMoney));
- }
- $this->M->fanshui($userInfo['account_identity'],$userInfo['account'],$moneyData,$orderID);//反水
- }
- //写注单 表
- $moneyBuy = lm('MoneyBuyStr','Api')->insert($orderData);
- if(!$moneyBuy){
- Render('','3205',lang('errors','Api')->get('error-3205'));
- }
- foreach ($data_all as $kk=>$vv){
- $getModels = $this->commonFunction->getModels($vv['ballId']);
- $model_match = $getModels['model_match'];
- //获取是否是滚球投注
- $is_rolling = 0;
- if($vv['match_type'] == 'StRollBall'){
- $is_rolling = 1;
- }
- $matchData[] = [
- 'batch_id'=>$batch_id,
- 'odds_id'=>$vv['id'],
- 'home_team'=>$vv['home_team'],
- 'guest_team'=>$vv['guest_team'],
- 'condition'=>$vv['condition'],
- 'odds'=>$vv['odds'],
- 'odds_code'=>$vv['odds_code'],
- 'p_code'=>$vv['p_code'],
- 'odds_only'=>$vv['odds_only'],
- 'status'=>0,
- 'match_id'=>$vv['match_id'],
- 'game_code'=>$vv['ballId'],
- 'lg_id'=> $vv['lg_id'],
- 'ctime'=>$this->time,//写入时间
- 'utime' => $this->time,
- 'bet_type'=>2,
- 'is_rolling'=>$is_rolling,
- 'order_id'=> $orderID,
- ];
- }
- //写赔率数据表
- $moneyBuyMatch = lm('MoneyBuyMatch','Api')->insert($matchData);
- if(!$moneyBuyMatch){
- Render('','3205',lang('errors','Api')->get('error-3205'));
- }
- return true;
- }
- public function stringBet($data_str=[],$data_all=[],$userInfo=[],$batch_id=0){
- //验证串式投注是否合法
- $this->verify_stringType($data_all);
- //获取串式 总赛事数量
- $groupNum = count($data_all);//总数量
- $orderData = [];
- foreach ($data_str as $k=>$v){
- //字符串替换
- $str = str_ireplace("串","_",$v['type']);
- //获取type 3_12
- $after = substr($str,strpos($str,"_")+1);
- //当前串式 值
- $sonNum = substr($str,0,strrpos($str,"_"));
- //获取倍数
- if((int)$after == 1){
- $multiple = $this->getMultiple($groupNum,(int)$sonNum);
- }else{
- $multiple =(int)$after;
- }
- //获取当前串式投注金额及可赢金额
- if($after == 1){
- $money_all = $this->getmakeMoney((int)$sonNum,$v['bet_amount'],$multiple,$data_all,$after);
- }else{
- $money_all = $this->getStrAllMoney((int)$sonNum,$v['bet_amount'],$multiple,$data_all,$after);
- }
- //投注金额
- $moneyData = $money_all['moneyData'];
- //可赢金额
- $prize_money = $money_all['prize_money'];
- $uuid = UUID();
- $orderID = OrderID('T');
- $orderData[$k]['info_identity'] = $uuid;
- $orderData[$k]['account_name'] = $userInfo['account'];
- $orderData[$k]['account_identity'] = $userInfo['account_identity'];
- $orderData[$k]['order_id'] = $orderID;
- $orderData[$k]['game_no'] = "";
- $orderData[$k]['money'] = $moneyData;//$pay_money//总投注金额
- $orderData[$k]['money_time'] = $this->time;//下注时间
- $orderData[$k]['prize_money'] = $prize_money;//$expect_money ;//预期总可赢金额
- $orderData[$k]['str_type'] = $v['type'];//串式类型
- $orderData[$k]['batch_id'] = $batch_id;//批次号
- $orderData[$k]['wait_match_num'] = count($data_all);//批次号
- //写资金变动表
- $insertMoney = $this->M->insertMoney($userInfo['account_identity'],$moneyData,$orderID,1,"",$uuid,$userInfo);
- if($insertMoney!=1){
- Render('', $insertMoney,lang('Errors','Api')->get('error'.$insertMoney));
- }
- $this->M->fanshui($userInfo['account_identity'],$userInfo['account'],$moneyData,$orderID);//反水
- //===处理赛事数据===
- foreach ($data_all as $kk=>$vv){
- $getModels = $this->commonFunction->getModels($vv['ballId']);
- $model_match = $getModels['model_match'];
-
- //获取是否是滚球投注
- $is_rolling = 0;
-
- if($vv['match_type'] == 'StRollBall'){
- $is_rolling = 1;
- }
- $matchData[] = [
- 'batch_id'=>$batch_id,
- 'odds_id'=>$vv['id'],
- 'home_team'=>$vv['home_team'],
- 'guest_team'=>$vv['guest_team'],
- 'condition'=>$vv['condition'],
- 'odds'=>$vv['odds'],
- 'odds_code'=>$vv['odds_code'],
- 'p_code'=>$vv['p_code'],
- 'odds_only'=>$vv['odds_only'],
- 'status'=>0,
- 'match_id'=>$vv['match_id'],
- 'game_code'=>$vv['ballId'],
- 'lg_id'=> $vv['lg_id'],
- 'ctime'=>$this->time,//写入时间
- 'utime' => $this->time,
- 'bet_type'=>2,
- 'is_rolling'=>$is_rolling,
- 'order_id'=> $orderID,
- ];
- //=====拼接赛事数据===
- //获取开赛时间
- //根据球类代码 获取相关model
- $models = $this->commonFunction->getModels($vv['ballId']);
- $model_match = $models['model_match'];
- $info = lm($model_match,'Sports')
- ->select('match_date','match_time','match_identity')
- ->where('id',$vv['match_id'])
- ->first();
- $match_time = $info->match_date.' '.$info->match_time;
- $match_data_order[] = [
- 'game_code'=>$vv['ballId'],//球类代码
- 'other_match_id'=>$vv['others_match_id'],//第三方赛事id 188
- 'match_id'=>$vv['match_id'],//本地赛事id
- 'match_uuid'=> $info->match_identity,//赛事uuid
- 'odds_code'=>$vv['odds_code'],//子玩法代码
- 'p_code'=>$vv['p_code'],//父玩法代码
- 'match_time'=>$match_time,//开赛时间
- 'match_type'=>$is_rolling,//比赛盘口
- 'sort'=>$vv['sort'],//排序
- ];
- //===end===
- }
- //===追加写处理队列===
- //订单号 比赛id188 开赛日期时间 比赛状态(早盘,今日,串场,滚球), 父级玩法, 子级玩法,排序
- //赛事去重
- $match_data_order = $this->commonFunction->array_unset_tt($match_data_order,'match_id');
- sort($match_data_order);
-
- $orderData_queue[] = [
- 'order_type'=>2,//订单类型 1单式 2串式
- 'order_id'=>$orderID,//订单ID
- 'matchData'=>$match_data_order
- ];
- }
- //写赔率数据表
- $moneyBuyMatch = lm('MoneyBuyMatch','Api')->insert($matchData);
- if(!$moneyBuyMatch){
- Render('','3205',lang('errors','Api')->get('error-3205'));
- }
- //===end===
- //写注单 表
- $moneyBuy = lm('MoneyBuyStr','Api')->insert($orderData);
- if(!$moneyBuy){
- Render('','3205',lang('errors','Api')->get('error-3205'));
- }
- //写队列
- foreach($orderData_queue as $k=>$v){
- $this->commonFunction->setOrderQueue($v);
- }
- return true;
- }
- /**
- * 计算串式投注 倍率
- * $groupNum 总赛事 数量
- * $sonNum 当前串式 数量
- */
- public function getMultiple($groupNum = 0,$sonNum = 0){
- if($groupNum and $sonNum){
- $group =1;
- for($i = $groupNum ; $i >($groupNum - $sonNum);$i--) {
- $group = $group * $i;
- }
- $son =1;
- for($i = $sonNum ; $i >0;$i--) {
- $son = $son * $i;
- }
- }
- return $group/$son;
- }
- /**
- * @param int $sonNum 当前串式数量
- * @param int $bet_amount 当前串式投注额
- * @param int $multiple 当前串式倍数
- * @param array $data_all 当前注单 所有投注数据
- * @return mixed
- * 计算当前串式投注总额、可赢总额
- */
- public function getmakeMoney($sonNum=0,$bet_amount=0,$multiple=0,$data_all=[],$after = 0){
- $allNum = count($data_all);//所有数量
- $odds_all = [];//所有投注项数据
- foreach ($data_all as $k=>$v){
- $odds_all[] = $v['odds']+1;
- }
- //投注总额
- $data['moneyData'] = (double)$bet_amount*(double)$multiple;
- if($sonNum == $allNum and (int)$after ==1){//N场赛事 N串一
- //获取所有赛事赔率乘积
- $odds = array_product($odds_all) - 1;
- //获取可赢金额
- $data['prize_money'] = sprintf("%.2f",substr(sprintf("%.3f", $bet_amount*$odds), 0, -1));//floor($bet_amount*$odds*100)/100;//保留两位小数
- }
- if($sonNum < $allNum and (int)$after ==1){//例:N场赛事 <N串一
- //计算 组合赔率
- $group = $this->commonFunction->combination($odds_all, $sonNum);
- foreach ($group as $k=>$v){
- $odds[] = array_product($v);
- }
- $odds = (array_sum($odds))-(count($odds));
- //获取可赢金额
- $data['prize_money'] = sprintf("%.2f",substr(sprintf("%.3f", $bet_amount*$odds), 0, -1));//floor($bet_amount*$odds*100)/100;
- }
- return $data;
- }
- /**
- * 获取所有可用串式 N场赛事 2串1,3串1...N串1,N<11
- * 并计算 其投注可赢金额
- */
- public function getStrAllMoney($sonNum=0,$bet_amount=0,$multiple=0,$data_all=[],$after = 0){
- $d = [];
- for ($i=2;$i<($sonNum+1);$i++){
- $d[] = $i;
- }
- foreach ($d as $k=>$v){
- $multiple = $this->getMultiple($sonNum,$v);
- $money[] = $this->getmakeMoney($v,$bet_amount,$multiple,$data_all,1);
- }
- $data=array();
- foreach($money as $k=>$v){
- $data['moneyData']+=$v['moneyData'];
- $data['prize_money']+=$v['prize_money'];
- }
- return $data;
- }
- /**
- * 验证串式投注 是否合法
- * $data 串式 所有赛事
- */
- public function verify_stringType($data=[]){
- if($data){
- foreach($data as $k=>$v){
- if($v['match_id']==$v['match_id'] ){
- $r[$v['match_id']][] = $v;
- }
- }
- }
- if($r){
- foreach ($r as $k=>$v){
- if(count($v) > 1){
- $msg = lang('Errors','Api')->get('error-50038');
- Render([], '50038',$msg);
- }else if( $k == 0){
- $msg = lang('Errors','Api')->get('error-50043');
- Render([], '50043',$msg);
- }
- }
- }
- }
- /**
- * 更新投注项相关数据
- */
- public function getBetData(){
- $data = $_REQUEST;
- // $data = [['game_code'=>'zq','match_id'=>3095448,'odds_id'=>623078],['game_code'=>'zq','match_id'=>3095448,'odds_id'=>623078]];
- foreach ($data as $k=>$v){
- $getModels = $this->commonFunction->getModels($v['game_code']);
- $model_match = $getModels['model_match'];
- $model_odds = $getModels['model_odds'];
- $oddsData = lm($model_match,"Sports")
- ->join($model_odds,$model_odds.'.match_id',$model_match.'.id')
- ->select($model_match.'.id as match_id',$model_match.'.match_date',$model_match.'.home_team',$model_match.'.guest_team',$model_odds.'.id as odds_id',$model_odds.'.p_code',$model_odds.'.odds_code',$model_odds.'.condition',$model_odds.'.odds',$model_odds.'.odds_only',$model_odds.'.status',$model_odds.'.sort')
- // ->where($model_match.'.source',$this->source)
- ->where($model_match.'.id',$v['match_id'])
- ->where($model_odds.'.id',$v['odds_id'])
- //->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
- ->first();
- $oddsData->game_code = $v['game_code'];
- $betData[] = $oddsData;
- }
- Render($betData, '1', lang('Tips','Sports')->get('success'));
- }
- //用户投注限额验证
- public function bet_money_limit($bet_money_arr=[],$userInfo=[]){
- if(!empty($bet_money_arr)){
- foreach($bet_money_arr as $k=>$v){
- if($k == (count($bet_money_arr)-1)){
- unset($bet_money_arr[$k]);
- }
- }
- }
- //===追加验证用户投注金额限额===
- if(empty($bet_money_arr)) Render('', '3605',lang('Errors','Api')->get('error-3605'));
- //获取当前用户分组名称
- $substr = substr($userInfo['group_name'],strpos($userInfo['group_name'],'|')+1);
- $role_name = substr($substr, 0, -1);
- //获取用户分组的投注限额
- $bet_money_limit = Dc_user_grade::get_bet_money_limit($role_name);
- foreach($bet_money_arr as $k=>$v){
- if($v['bet_amount'] < $bet_money_limit->lower_limit) Render(['bet_amount'=>$v['bet_amount'],'lower_limit'=>$bet_money_limit->lower_limit], '3406','第'.($k+1).'条'.lang('Errors','Api')->get('error-3406'));
- if($v['bet_amount'] > $bet_money_limit->upper_limit) Render(['bet_amount'=>$v['bet_amount'],'upper_limit'=>$bet_money_limit->upper_limit], '3401','第'.($k+1).'条'.lang('Errors','Api')->get('error-3401'));
- }
- //===end==
- }
- //根据token获取用户投注限额
- public function getBetMoneyLimit(){
- //验证用户token
- $token = $_REQUEST['token'];
- $userInfo = $this->getAgent($token);
- //获取当前用户分组名称
- $substr = substr($userInfo['group_name'],strpos($userInfo['group_name'],'|')+1);
- $role_name = substr($substr, 0, -1);
- //获取用户分组的投注限额
- $bet_money_limit = Dc_user_grade::get_bet_money_limit($role_name);
- $data['bet_money_limit']=[
- 'lower_limit'=>$bet_money_limit->lower_limit,
- 'upper_limit'=>$bet_money_limit->upper_limit,
- ];
- Render($data, '1', lang('Tips','Sports')->get('success'));
- }
- /**
- * 用户撤单操作 接口
- * 单订单操作
- */
- public function reOrder(){
- //获取球类代码
- $order_id = $_REQUEST['order_id'];
- $token = $_REQUEST['token'];
-
- try {
-
- if(empty($order_id)){
- throw new \Exception(Render([], '10001', lang('Tips','Sports')->get('PARAM_ERROR')));
- }
-
- _beginTransaction();//开启事务
- // 单式 S 串式 T
- if(substr($order_id,0,1) == 'S'){
- //单式订单 model
- $order_model = 'money_buy_simplex';
- }else{
- //串式订单 model
- $order_model = 'money_buy_str';
- }
- //查询订单信息
- $order_data = lm($order_model,"Commons")
- ->where('order_id',$order_id)
- ->first();
- //订单不存在
- if(empty($order_data)) throw new \Exception(Render([], '10030', lang('Tips','Sports')->get('order_null')));
- //订单非投注状态 不可撤单
- if($order_data->status != 1) throw new \Exception(Render([], '10031', lang('Tips','Sports')->get('order_type_err')));
- //获取用户数据
- $userInfo = $this->getAgent($token);
- //验证订单是否属于该用户
- if($order_data->account_identity != $userInfo['account_identity']) throw new \Exception(Render([], '10025', lang('Tips','Sports')->get('auth_error').':不是该用户的订单'));
- //获取用户账户余额
- $cash = $userInfo['cash'];
- //获取订单涉及金额
- $where = [
- ['trade_id','=',$order_id],
- ['status','=',1]
- ];
- $odds_money_data = lm('money_details',"Commons")
- ->select('info_identity','trade_id','account_name','account_identity','money','money_type','money_cash','trade_type','status')
- ->where($where)
- ->get();
-
- if(empty($odds_money_data)) throw new \Exception(Render([], '10026', lang('Tips','Sports')->get('order_money_err')));
- $odds_money_data = $odds_money_data -> toArray();
- //获取订单投注金额
- $odds_money_bet = 0;
- //获取订单反水金额
- $odds_money_fs = 0;
-
- foreach($odds_money_data as $k=>$v){
- if($v['trade_type'] == 1){
- $odds_money_bet = $v['money'];
- }
- if($v['trade_type'] == 7){
- $odds_money_fs = $v['money'];
- }
- }
- //更新订单状态为已取消
- $up_order = lm($order_model,"Commons")
- ->where('order_id',$order_id)
- ->update(['status'=>3,'use_mark'=>'用户撤单']);
-
- if($up_order < 1) throw new \Exception(Render([], '10027', lang('Tips','Sports')->get('order_status_up_err')));
- //===退款===
- //需退回金额 = 投注金额-反水金额
- $money = abs($odds_money_bet - $odds_money_fs);
- //用户剩余金额
- $new_available_cash = $cash + $money;
- //组装新增数据
- $set_money_data = [
- 'info_identity' => UUID(),
- 'trade_id' => $order_id,
- 'account_name' => $userInfo['account'],
- 'account_identity' => $userInfo['account_identity'],
- 'money' => $money,
- 'money_time' => date("Y-m-d H:i:s", time()),
- 'money_type' => 1,
- 'money_cash' => $new_available_cash,
- 'trade_type' => 3,
- 'trade_desc' => '用户撤单,退回投注资金:¥'.$money.';订单号:'.$order_id.'',
- 'status' => 1,
- ];
- //更新用户数据
- $ret_user = lm('account_detailed',"Commons")
- ->where('account_identity', $v['account_identity'])
- ->update(['available_cash' => $new_available_cash, 'cash' => $new_available_cash]);
- if($ret_user < 1) throw new \Exception(Render([], '10028', lang('Tips','Sports')->get('up_user_err')));
- //更新用户资金数据
- $set_money = lm('money_details',"Commons")->insert($set_money_data);
- if($set_money != true) throw new \Exception(Render([], '10029', lang('Tips','Sports')->get('add_money_err')));
- //===end===
- _commit();//提交
- Render('', '1', lang('Tips','Sports')->get('success'));
- } catch (\Exception $e) {
- echo $e->getMessage();
- }
- }
- }
|