|
|
@@ -10,6 +10,7 @@ namespace App\Models;
|
|
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
use App\Models\MoneyBuyMatch;
|
|
|
+use App\Http\Response\Response;
|
|
|
|
|
|
class SportsNoteList extends BaseModel
|
|
|
{
|
|
|
@@ -944,4 +945,131 @@ class SportsNoteList extends BaseModel
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * 滚球投注 危险球自动审核
|
|
|
+ * $match_id int 赛事id
|
|
|
+ * $warn_data arr 危险球数据
|
|
|
+ */
|
|
|
+ public static function WarnHandle($match_id=0,$warn_data=[]){
|
|
|
+
|
|
|
+ if(!empty($match_id) and !empty($warn_data)){
|
|
|
+ $db = new \App\Models\Setinfo();
|
|
|
+ //获取设定需审核时间 秒
|
|
|
+ $handle_time = $db->getInfo(1003)['infocontent']?:90;
|
|
|
+ //获取赛事下 待审核 滚球投注
|
|
|
+ $where = [
|
|
|
+ ['match_id','=',$match_id],
|
|
|
+ ['roll_ratify','=',2]
|
|
|
+ ];
|
|
|
+ $order_data = self::where($where)->SELECT('id','account_name','account_identity','order_id','money_time','roll_ratify','money','gain_money')->get()->toArray();
|
|
|
+ if(!empty($order_data)){
|
|
|
+ //获取审核不通过订单 订单号
|
|
|
+ $order_ids_n = [];
|
|
|
+ //获取审核不通过订单
|
|
|
+ $order_data_n = [];
|
|
|
+ //获取审核通过订单 订单号
|
|
|
+ $order_ids_y = [];
|
|
|
+ //获取审核未通过订单 投注人
|
|
|
+ $account_identitys = [];
|
|
|
+ foreach($order_data as $k=>$v){
|
|
|
+ //投注时间 时间戳
|
|
|
+ $order_time = strtotime($v['money_time']);
|
|
|
+ foreach($warn_data as $kk=>$vv){
|
|
|
+ //危险球时间 时间戳
|
|
|
+ $warn_time = strtotime($vv['find_time']);
|
|
|
+ if($order_time < $warn_time and ($order_time+$handle_time) > $warn_time){
|
|
|
+ $order_ids_n[] = $v['order_id'];
|
|
|
+ $account_identitys[] = $v['account_identity'];
|
|
|
+ $order_data_n[] = $v;
|
|
|
+ unset($order_data[$k]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!empty($order_data)){
|
|
|
+ foreach($order_data as $k=>$v){
|
|
|
+ $order_ids_y[] = $v['order_id'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!empty($order_ids_n)){
|
|
|
+ //在审核时间内订单 审核不通过
|
|
|
+ self::HandleMoney($account_identitys,$order_ids_n,$order_data_n);
|
|
|
+ }
|
|
|
+ if(!empty($order_ids_y)){
|
|
|
+ //在审核时间外订单 审核通过
|
|
|
+ $ret_y = self::whereIn('order_id', $order_ids_y)->update(['roll_ratify' => 1,'use_mark'=>'滚球投注自动审核(危险球)通过']);
|
|
|
+ //如果更新数量小于订单数量 则返回异常
|
|
|
+ if($ret_y < count($order_ids_y)) throw new \Exception( Response::generate('',Response::HANDLE_ORDER_Y_ERR));
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 滚球自动审核 账户资金处理
|
|
|
+ */
|
|
|
+
|
|
|
+ public static function HandleMoney($account_identitys=[],$order_ids=[],$orders=[]){
|
|
|
+ //用戶账户金额
|
|
|
+ $account_money = \App\Models\Account_detailed::whereIn('account_identity',$account_identitys)->get()->toArray();
|
|
|
+ //反水
|
|
|
+ $water_return_money = \App\Models\Money_details::whereIn('trade_id',$order_ids)->where('trade_type', '7')->get()->toArray();
|
|
|
+
|
|
|
+ if(!empty($orders)){
|
|
|
+ for($i=0;$i<count($orders);$i++){
|
|
|
+ for($a=0;$a<count($account_money);$a++){
|
|
|
+ if($orders[$i]['account_identity'] == $account_money[$a]['account_identity']){
|
|
|
+ $available_cash = $account_money[$a]['available_cash'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for($b=0;$b<count($water_return_money);$b++){
|
|
|
+ if($orders[$i]['order_id'] == $water_return_money[$b]['trade_id']){
|
|
|
+ $water_return = $water_return_money[$b]['money'];
|
|
|
+ } else {
|
|
|
+ $water_return = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //需退回金额 = 投注金额-反水金额
|
|
|
+ $money = abs($orders[$i]['money'] - $water_return);
|
|
|
+ //用户剩余金额
|
|
|
+ $new_available_cash = $available_cash + $money;
|
|
|
+
|
|
|
+ $models = new \App\Models\Money_details();
|
|
|
+ $models->info_identity = UUID();
|
|
|
+ $models->trade_id = $orders[$i]['order_id'];
|
|
|
+ $models->account_name = $orders[$i]['account_name'];
|
|
|
+ $models->account_identity = $orders[$i]['account_identity'];
|
|
|
+ $models->money = $money;
|
|
|
+ $models->money_time = date("Y-m-d H:i:s", time());
|
|
|
+ if ($new_available_cash > $available_cash) {
|
|
|
+ $models->money_type = '1';
|
|
|
+ } else {
|
|
|
+ $models->money_type = '2';
|
|
|
+ }
|
|
|
+ $models->money_cash = $new_available_cash;
|
|
|
+ $models->trade_type = '25';
|
|
|
+ $models->trade_desc = '滚球投注自动审核(危险球)不通过,退回投注资金:¥'.$money.';订单号:'.$orders[$i]['order_id'].'';
|
|
|
+ $models->status = '1';
|
|
|
+
|
|
|
+ //更新订单数据
|
|
|
+ $ret_order = self::where('id', $orders[$i]['id'])->update(['roll_ratify' => '-1','status' => '2','use_mark'=>'滚球投注自动审核(危险球)不通过']);
|
|
|
+ if($ret_order < 1) throw new \Exception( Response::generate('',Response::UP_ORDER_ERR));
|
|
|
+
|
|
|
+ //更新用户数据
|
|
|
+ $ret_user = \App\Models\Account_detailed::where('account_identity', $orders[$i]['account_identity'])->update(['available_cash' => $new_available_cash, 'cash' => $new_available_cash]);
|
|
|
+ if($ret_user < 1) throw new \Exception( Response::generate('',Response::UP_USER_ERR));
|
|
|
+
|
|
|
+ //更新用户资金数据
|
|
|
+ if(!$models->save()) throw new \Exception( Response::generate('',Response::UP_MONEY_ERR));
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|