| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443 |
- <?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 开赛日期时间 比赛状态(早盘,今日,串场,滚球), 父级玩法, 子级玩法,排序
- $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();
- }
- }
- }
|