|
|
@@ -974,5 +974,122 @@ class Betorder extends BaseController{
|
|
|
];
|
|
|
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()->toArray();
|
|
|
+
|
|
|
+ //订单不存在
|
|
|
+ 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()
|
|
|
+ ->toArray();
|
|
|
+
|
|
|
+ if(empty($odds_money_data)) throw new \Exception(Render([], '10026', lang('Tips','Sports')->get('order_money_err')));
|
|
|
+ //获取订单投注金额
|
|
|
+ $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();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|