|
|
@@ -2111,7 +2111,7 @@ class SportsNoteList extends BaseModel
|
|
|
return $sim;
|
|
|
}
|
|
|
|
|
|
- //取消结算
|
|
|
+ //取消结算 扣除中奖金额
|
|
|
public function no_cancel_end($order_id){
|
|
|
//获取注单数据
|
|
|
$orderData = $this->where('order_id',$order_id)->first();
|
|
|
@@ -2184,8 +2184,107 @@ class SportsNoteList extends BaseModel
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
- //取消作废
|
|
|
+ //取消作废 扣除投注金额 追加反水金额
|
|
|
public function no_cancel_invalid($order_id){
|
|
|
- dd($order_id);
|
|
|
+ //获取注单数据
|
|
|
+ $orderData = $this->where('order_id',$order_id)->first();
|
|
|
+ if(empty($orderData)) throw new \Exception('未找到该注单');
|
|
|
+ //投注用户
|
|
|
+ $account_name = $orderData->account_name;
|
|
|
+ //用户uuid =
|
|
|
+ $account_identity = $orderData->account_identity;
|
|
|
+
|
|
|
+ //获取注单状态
|
|
|
+ $status = $orderData->status;
|
|
|
+ //获取投注金额
|
|
|
+ $order_money = $orderData->money;
|
|
|
+
|
|
|
+ //如果注单状态不是作废
|
|
|
+ if($status < 2) throw new \Exception('注单状态错误');
|
|
|
+
|
|
|
+ //获取用户账户余额
|
|
|
+ $account_money = \App\Models\Account_detailed::where('account_identity',$account_identity)->SELECT('account_identity','available_cash')->first()->available_cash;
|
|
|
+
|
|
|
+ //===处理用户资金相关===
|
|
|
+ //===扣除投注金额===
|
|
|
+ //需扣除金额 = 投注金额
|
|
|
+ $money = $order_money;
|
|
|
+ //用户剩余金额
|
|
|
+ $new_available_cash = $account_money - $money;
|
|
|
+ $models = new \App\Models\Money_details();
|
|
|
+ $models->info_identity = UUID();
|
|
|
+ $models->trade_id = $order_id;//交易id
|
|
|
+ $models->account_name = $account_name;//用户名
|
|
|
+ $models->account_identity = $account_identity;//用户uuid
|
|
|
+ $models->money = $money;//变动金额
|
|
|
+ $models->money_time = date("Y-m-d H:i:s", time());//资金发生时间
|
|
|
+ $models->money_type = '2';//1.增加 2.减少
|
|
|
+
|
|
|
+ $models->money_cash = $new_available_cash;//剩余金额
|
|
|
+ $models->trade_type = '1';//交易类型 1 已作废改为未结算,扣除投注金额
|
|
|
+ $models->trade_desc = '已作废改为未结算,扣除投注金额:¥'.$money.';订单号:'.$order_id.'';//交易描述
|
|
|
+ $models->status = '1';//1成功 2失败
|
|
|
+
|
|
|
+ //新增资金流水
|
|
|
+ if(!$models->save()) throw new \Exception('新增资金流水失败');
|
|
|
+
|
|
|
+ //更新用户资金
|
|
|
+ $ret_user = \App\Models\Account_detailed::where('account_identity',$account_identity)->update(['available_cash' => $new_available_cash, 'cash' => $new_available_cash]);
|
|
|
+ if($ret_user < 1) throw new \Exception('更新用户资金失败');
|
|
|
+
|
|
|
+ //更新订单数据
|
|
|
+ $order_up = [
|
|
|
+ 'status'=>1,//已作废改为投注
|
|
|
+ 'gain_money' =>0,//中奖金额 0
|
|
|
+ 'settle_status' =>1,//结算状态 未结算
|
|
|
+ 'game_status' =>0,//开奖状态 未开奖
|
|
|
+ 'remark' =>'已作废注单改为未结算',//处理备注
|
|
|
+ ];
|
|
|
+ $ret_order = self::where('order_id',$order_id)->update($order_up);//将注单已作废改为未结算
|
|
|
+ if($ret_order < 1) throw new \Exception('注单数据更新失败');
|
|
|
+
|
|
|
+ //更新投注详情数据
|
|
|
+ $match_up = [
|
|
|
+ 'status'=>0,//结算状态 0 未结算
|
|
|
+ 'result'=>0,//结果状态 0 未处理
|
|
|
+ 'utime'=>date("Y-m-d H:i:s", time()),//更新时间
|
|
|
+ 'matchresult'=>'',//结算结果 默认空
|
|
|
+ ];
|
|
|
+ $ret_money_buy_match = \App\Models\MoneyBuyMatch::where('order_id',$order_id)->update($match_up);
|
|
|
+ if($ret_money_buy_match < 1) throw new \Exception('注单详情投注数据更新失败');
|
|
|
+ //===end===
|
|
|
+
|
|
|
+ //追加用户投注反水
|
|
|
+ //获取反水比例
|
|
|
+ $water_return = \App\Models\Setinfo::where('infotype',1001)->first()->infocontent;
|
|
|
+ //反水金额 = 投注金额*反水比例
|
|
|
+ $water_return_money = $water_return*$order_money;
|
|
|
+
|
|
|
+ //需追加金额 = 反水金额
|
|
|
+ $money = $water_return_money;
|
|
|
+ //用户剩余金额
|
|
|
+ $new_available_cash = $new_available_cash + $money;
|
|
|
+ $models = new \App\Models\Money_details();
|
|
|
+ $models->info_identity = UUID();
|
|
|
+ $models->trade_id = $order_id;//交易id
|
|
|
+ $models->account_name = $account_name;//用户名
|
|
|
+ $models->account_identity = $account_identity;//用户uuid
|
|
|
+ $models->money = $money;//变动金额
|
|
|
+ $models->money_time = date("Y-m-d H:i:s", time());//资金发生时间
|
|
|
+ $models->money_type = '1';//1.增加 2.减少
|
|
|
+
|
|
|
+ $models->money_cash = $new_available_cash;//剩余金额
|
|
|
+ $models->trade_type = '1';//交易类型 1 已作废改为未结算,扣除投注金额
|
|
|
+ $models->trade_desc = '已作废改为未结算,追加反水金额:¥'.$money.';订单号:'.$order_id.'';//交易描述
|
|
|
+ $models->status = '1';//1成功 2失败
|
|
|
+
|
|
|
+ //新增资金流水
|
|
|
+ if(!$models->save()) throw new \Exception('新增资金流水失败');
|
|
|
+
|
|
|
+ //更新用户资金
|
|
|
+ $ret_user = \App\Models\Account_detailed::where('account_identity',$account_identity)->update(['available_cash' => $new_available_cash, 'cash' => $new_available_cash]);
|
|
|
+ if($ret_user < 1) throw new \Exception('更新用户资金失败');
|
|
|
+
|
|
|
+ return 1;
|
|
|
}
|
|
|
}
|