|
|
@@ -186,6 +186,11 @@ class AdvertOrderService extends BaseService
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ if($tradeType != 2){
|
|
|
+ $this->error = '4003';
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
if ($tradePrice <= 0 && $priceType == 2) {
|
|
|
$this->error = '3002';
|
|
|
return false;
|
|
|
@@ -203,14 +208,27 @@ class AdvertOrderService extends BaseService
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ // 单笔限额
|
|
|
+ if($total< $info['limit_min'] || $total> $info['limit_max']){
|
|
|
+ $this->error = lang('4005',['min'=> $info['limit_min'],'max'=>$info['limit_max']]);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
// 购买用户信息
|
|
|
$userInfo = MemberService::make()->getInfo($userId);
|
|
|
$status = isset($userInfo['status']) ? $userInfo['status'] : 0;
|
|
|
+ $idcardCheck = isset($userInfo['idcard_check']) ? $userInfo['idcard_check'] : 0;
|
|
|
+ $username = isset($userInfo['username']) ? format_account($userInfo['username']) : '';
|
|
|
if (empty($userInfo) || $status != 1) {
|
|
|
$this->error = '2009';
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ if($idcardCheck != 1){
|
|
|
+ $this->error = '2014';
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
// 未处理订单
|
|
|
$noCatchOrder = $this->checkOrderNoCatch($userId, 1);
|
|
|
if ($tradeLimitNum > 0 && $noCatchOrder >= $tradeLimitNum) {
|
|
|
@@ -225,7 +243,6 @@ class AdvertOrderService extends BaseService
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
// 购买者身份信息
|
|
|
$idcardData = [
|
|
|
'idcard' => isset($userInfo['idcard']) ? $userInfo['idcard'] : '',
|
|
|
@@ -243,7 +260,7 @@ class AdvertOrderService extends BaseService
|
|
|
}
|
|
|
|
|
|
$this->model->startTrans();
|
|
|
- $orderNo = get_order_num('OT');
|
|
|
+ $orderNo = get_order_num('TA');
|
|
|
$data = [
|
|
|
'user_id' => $userId,
|
|
|
'business_id' => isset($businessInfo['id']) ? $businessInfo['id'] : 0,
|
|
|
@@ -302,9 +319,9 @@ class AdvertOrderService extends BaseService
|
|
|
$data = [
|
|
|
'from_uid' => $userId,
|
|
|
'to_uid' => $businessInfo['id'],
|
|
|
- 'type' => 2,
|
|
|
+ 'type' => 3,
|
|
|
'order_no' => $orderNo,
|
|
|
- 'chat_key' => ChatMessageService::make()->getChatKey($userId, $businessInfo['id']),
|
|
|
+ 'chat_key' => getChatKey($userId, $businessInfo['id']),
|
|
|
'message' => "来自用户{$username}的购买订单,金额{$total},单号{$orderNo},时间" . date('Y-m-d H:i:s'),
|
|
|
'message_type' => 1,
|
|
|
'create_time' => time(),
|
|
|
@@ -332,7 +349,8 @@ class AdvertOrderService extends BaseService
|
|
|
{
|
|
|
$id = isset($params['id']) ? intval($params['id']) : 0;
|
|
|
$num = isset($params['num']) ? intval($params['num']) : 0;
|
|
|
- if ($id <= 0 || $num<=0) {
|
|
|
+ $paymentId = isset($params['payment_id']) ? intval($params['payment_id']) : 0;
|
|
|
+ if ($id <= 0 || $num<=0 || $paymentId<=0) {
|
|
|
$this->error = '1013';
|
|
|
return false;
|
|
|
}
|
|
|
@@ -340,10 +358,6 @@ class AdvertOrderService extends BaseService
|
|
|
// 验证参数
|
|
|
$config = \App\Services\ConfigService::make()->getConfigOptionByGroup(5);
|
|
|
$tradeOpen = isset($config['trade_usdt_open']) ? $config['trade_usdt_open'] : 0;
|
|
|
- $tradeMinNum = isset($config['trade_min_num']) ? $config['trade_min_num'] : 0;
|
|
|
- $tradeMaxNum = isset($config['trade_max_num']) ? $config['trade_max_num'] : 0;
|
|
|
- $trademinMoney = isset($config['trade_min_money']) ? $config['trade_min_money'] : 0;
|
|
|
- $tradeMaxMoney = isset($config['trade_max_money']) ? $config['trade_max_money'] : 0;
|
|
|
$tradePrice = isset($config['usdt_buy_price']) ? $config['usdt_sell_price'] : 0;
|
|
|
$tradeLimitNum = isset($config['trade_no_catch']) ? $config['trade_no_catch'] : 0;
|
|
|
|
|
|
@@ -363,6 +377,11 @@ class AdvertOrderService extends BaseService
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ if($tradeType != 1){
|
|
|
+ $this->error = '4004';
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
if ($tradePrice <= 0 && $priceType == 2) {
|
|
|
$this->error = '3002';
|
|
|
return false;
|
|
|
@@ -373,7 +392,17 @@ class AdvertOrderService extends BaseService
|
|
|
$price = floatval($tradePrice + $price);
|
|
|
}
|
|
|
|
|
|
+ // 单笔限额
|
|
|
$total = floatval($price * $num);
|
|
|
+ if($total<=0){
|
|
|
+ $this->error = '4002';
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if($total< $info['limit_min'] || $total> $info['limit_max']){
|
|
|
+ $this->error = lang('4005',['min'=> $info['limit_min'],'max'=>$info['limit_max']]);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
// 用户信息
|
|
|
$userInfo = MemberService::make()->getInfo($userId);
|
|
|
@@ -385,6 +414,10 @@ class AdvertOrderService extends BaseService
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ if($idcardCheck != 1){
|
|
|
+ $this->error = '2014';
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
// 未处理订单
|
|
|
$noCatchOrder = $this->checkOrderNoCatch($userId, 2);
|
|
|
@@ -400,7 +433,6 @@ class AdvertOrderService extends BaseService
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
// 购买者身份信息
|
|
|
$idcardData = [
|
|
|
'idcard' => isset($userInfo['idcard']) ? $userInfo['idcard'] : '',
|
|
|
@@ -411,26 +443,38 @@ class AdvertOrderService extends BaseService
|
|
|
];
|
|
|
|
|
|
// 收款方式
|
|
|
- $payment = MemberPaymentService::make()->getPayment($userId);
|
|
|
- if (empty($payment)) {
|
|
|
- $this->error = '3015';
|
|
|
+ $paymentInfo = MemberPaymentService::make()->getInfo($paymentId);
|
|
|
+ if (empty($paymentInfo)) {
|
|
|
+ $this->error = '3010';
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ $paymentData = [
|
|
|
+ 'payment_id' => $paymentInfo['id'],
|
|
|
+ 'type' => $paymentInfo['type'],
|
|
|
+ 'logo' => $paymentInfo['logo'] ? get_image_url($paymentInfo['logo']) : '',
|
|
|
+ 'real_name' => $paymentInfo['real_name'],
|
|
|
+ 'bank_name' => $paymentInfo['bank_name'],
|
|
|
+ 'bank_card' => $paymentInfo['bank_card'],
|
|
|
+ 'branch_name' => $paymentInfo['branch_name'],
|
|
|
+ 'qrcode' => $paymentInfo['qrcode'] ? get_image_url($paymentInfo['qrcode']) : '',
|
|
|
+ 'account' => $paymentInfo['account'],
|
|
|
+ ];
|
|
|
+
|
|
|
$this->model->startTrans();
|
|
|
- $orderNo = get_order_num('OT');
|
|
|
+ $orderNo = get_order_num('TA');
|
|
|
$data = [
|
|
|
'user_id' => $userId,
|
|
|
'business_id' => isset($businessInfo['id']) ? $businessInfo['id'] : 0,
|
|
|
'order_no' => $orderNo,
|
|
|
- 'type' => 1,
|
|
|
+ 'type' => 2,
|
|
|
'pay_type' => isset($params['pay_type']) ? floatval($params['pay_type']) : 1,
|
|
|
'price' => $price,
|
|
|
'num' => $num,
|
|
|
'total' => $total,
|
|
|
- 'payment_id' => isset($payment['id']) ? intval($payment['id']) : 0,
|
|
|
+ 'payment_id' => $paymentId,
|
|
|
'idcard_data' => $idcardData ? json_encode($idcardData, 256) : '',
|
|
|
- 'payment_data' => $payment ? json_encode($payment, 256) : '',
|
|
|
+ 'payment_data' => $paymentData ? json_encode($paymentData, 256) : '',
|
|
|
'create_time' => time(),
|
|
|
'update_time' => time(),
|
|
|
'status' => 1,
|
|
|
@@ -443,8 +487,8 @@ class AdvertOrderService extends BaseService
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- if(!$this->memberModel->where(['id'=> $businessInfo['id']])->decrement('usdt_num', $num)){
|
|
|
+ // 扣除出售用户的USDT
|
|
|
+ if(!$this->memberModel->where(['id'=> $userId])->decrement('usdt_num', $num)){
|
|
|
$this->model->rollBack();
|
|
|
$this->error = '3020';
|
|
|
return false;
|
|
|
@@ -452,19 +496,19 @@ class AdvertOrderService extends BaseService
|
|
|
|
|
|
$data = [
|
|
|
'order_no'=> $orderNo,
|
|
|
- 'user_id'=> $businessInfo['id'],
|
|
|
+ 'user_id'=> $userId,
|
|
|
'type'=> 2,
|
|
|
'pay_type'=> 1,
|
|
|
'trade_type'=> 2,
|
|
|
'change_type'=> 2,
|
|
|
'num'=> $num,
|
|
|
'total'=> $total,
|
|
|
- 'balance'=> floatval($businessInfo['usdt_num']-$num),
|
|
|
+ 'balance'=> floatval($userInfo['usdt_num']-$num),
|
|
|
'create_time'=> time(),
|
|
|
'update_time'=> time(),
|
|
|
'status'=> 1,
|
|
|
'mark'=>1,
|
|
|
- 'remark'=> '交易员卖出',
|
|
|
+ 'remark'=> '客户卖出',
|
|
|
];
|
|
|
|
|
|
if(!$this->capitalModel->edit($data)){
|
|
|
@@ -477,10 +521,10 @@ class AdvertOrderService extends BaseService
|
|
|
$data = [
|
|
|
'from_uid' => $userId,
|
|
|
'to_uid' => $businessInfo['id'],
|
|
|
- 'type' => 2,
|
|
|
+ 'type' => 3,
|
|
|
'order_no' => $orderNo,
|
|
|
- 'chat_key' => ChatMessageService::make()->getChatKey($userId, $businessInfo['id']),
|
|
|
- 'message' => "来自用户{$username}的购买订单,金额{$total},单号{$orderNo},时间" . date('Y-m-d H:i:s'),
|
|
|
+ 'chat_key' => getChatKey($userId, $businessInfo['id']),
|
|
|
+ 'message' => "来自用户{$username}的出售订单,金额{$total},单号{$orderNo},时间" . date('Y-m-d H:i:s'),
|
|
|
'message_type' => 1,
|
|
|
'create_time' => time(),
|
|
|
'update_time' => time(),
|
|
|
@@ -506,7 +550,7 @@ class AdvertOrderService extends BaseService
|
|
|
public function checkOrderNoCatch($userId, $type = 1)
|
|
|
{
|
|
|
return $this->model->where(['user_id' => $userId, 'type' => $type, 'mark' => 1])
|
|
|
- ->whereIn('status', [1, 2, 7])
|
|
|
+ ->whereIn('status', [1, 2, 5, 7])
|
|
|
->count('id');
|
|
|
}
|
|
|
|