|
@@ -1183,237 +1183,189 @@ class MemberService extends BaseService
|
|
|
{
|
|
{
|
|
|
$money = isset($params['money'])? floatval($params['money']) : 0;
|
|
$money = isset($params['money'])? floatval($params['money']) : 0;
|
|
|
$payPassword = isset($params['pay_password'])? trim($params['pay_password']) : '';
|
|
$payPassword = isset($params['pay_password'])? trim($params['pay_password']) : '';
|
|
|
- $payType = isset($params['pay_type']) && $params['pay_type']? intval($params['pay_type']) : 10;
|
|
|
|
|
- $bankId = isset($params['bank_id']) && $params['bank_id']? intval($params['bank_id']) : 0;
|
|
|
|
|
- $type = isset($params['type']) && $params['type']? intval($params['type']) : 1;
|
|
|
|
|
|
|
+ $userType = isset($params['user_type']) && $params['user_type']? intval($params['user_type']) : 1;
|
|
|
if($money<=0){
|
|
if($money<=0){
|
|
|
- $this->error = 2031;
|
|
|
|
|
|
|
+ $this->error = 2401;
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if(!in_array($payType, [10,20,50])){
|
|
|
|
|
- $this->error = 2425;
|
|
|
|
|
|
|
+ if(!in_array($userType,[1,2])){
|
|
|
|
|
+ $this->error = 2404;
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$userInfo = $this->model->with(['merchant'])
|
|
$userInfo = $this->model->with(['merchant'])
|
|
|
->where(['id'=> $userId,'mark'=>1])
|
|
->where(['id'=> $userId,'mark'=>1])
|
|
|
- ->select(['id','nickname','balance','pay_password','wxpay_qrcode','alipay_qrcode','status'])
|
|
|
|
|
|
|
+ ->select(['id','nickname','usdt','pay_password','status'])
|
|
|
->first();
|
|
->first();
|
|
|
$status = isset($userInfo['status'])? $userInfo['status'] : 0;
|
|
$status = isset($userInfo['status'])? $userInfo['status'] : 0;
|
|
|
- $balance = isset($userInfo['balance'])? $userInfo['balance'] : 0;
|
|
|
|
|
|
|
+ $userUsdt = isset($userInfo['usdt'])? $userInfo['usdt'] : 0;
|
|
|
$userPayPassword = isset($userInfo['pay_password'])? $userInfo['pay_password'] : '';
|
|
$userPayPassword = isset($userInfo['pay_password'])? $userInfo['pay_password'] : '';
|
|
|
$merchant = isset($userInfo['merchant'])? $userInfo['merchant'] : [];
|
|
$merchant = isset($userInfo['merchant'])? $userInfo['merchant'] : [];
|
|
|
- $merchBalance = isset($merchant['balance'])? $merchant['balance'] : 0;
|
|
|
|
|
- $merchPayPassword = isset($merchant['pay_password'])? $merchant['pay_password'] : '';
|
|
|
|
|
|
|
+ $merchantUsdt = isset($merchant['usdt'])? $merchant['usdt'] : 0;
|
|
|
|
|
+ $merchantId = isset($merchant['id'])? $merchant['id'] : 0;
|
|
|
|
|
+ $merchantTradeStatus = isset($merchant['trade_status'])? $merchant['trade_status'] : 0;
|
|
|
if(empty($userInfo) || $status != 1){
|
|
if(empty($userInfo) || $status != 1){
|
|
|
$this->error = 2024;
|
|
$this->error = 2024;
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 验证提现类型金额
|
|
|
|
|
- $qrcode = '';
|
|
|
|
|
- $account = '';
|
|
|
|
|
- if($type == 2){
|
|
|
|
|
- // 支付密码验证
|
|
|
|
|
- if(empty($merchPayPassword)){
|
|
|
|
|
- $this->error ='1042';
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
- $payPassword = get_password($payPassword);
|
|
|
|
|
- if($payPassword != $merchPayPassword){
|
|
|
|
|
- $this->error ='1043';
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if(empty($merchant)){
|
|
|
|
|
- $this->error = 2646;
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if($money>$merchBalance){
|
|
|
|
|
- $this->error = 2647;
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- $wxpayQrcode = isset($merchant['wxpay_qrcode'])? $merchant['wxpay_qrcode'] : '';
|
|
|
|
|
- $alipayQrcode = isset($merchant['alipay_qrcode'])? $merchant['alipay_qrcode'] : '';
|
|
|
|
|
- if($payType == 10){
|
|
|
|
|
- $qrcode = $wxpayQrcode;
|
|
|
|
|
- if(empty($wxpayQrcode)){
|
|
|
|
|
- $this->error = 2649;
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if($payType == 20){
|
|
|
|
|
- $qrcode = $alipayQrcode;
|
|
|
|
|
- if(empty($alipayQrcode)) {
|
|
|
|
|
- $this->error = 2649;
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- }else{
|
|
|
|
|
- // 支付密码验证
|
|
|
|
|
- if(empty($userPayPassword)){
|
|
|
|
|
- $this->error ='1039';
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
- $payPassword = get_password($payPassword);
|
|
|
|
|
- if($payPassword != $userPayPassword){
|
|
|
|
|
- $this->error ='1038';
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if($money>$balance){
|
|
|
|
|
- $this->error = 2648;
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- $wxpayQrcode = isset($userInfo['wxpay_qrcode'])? $userInfo['wxpay_qrcode'] : '';
|
|
|
|
|
- $alipayQrcode = isset($userInfo['alipay_qrcode'])? $userInfo['alipay_qrcode'] : '';
|
|
|
|
|
- if($payType == 10){
|
|
|
|
|
- $qrcode = $wxpayQrcode;
|
|
|
|
|
- if(empty($wxpayQrcode)) {
|
|
|
|
|
- $this->error = 2420;
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if($userType == 2 && (empty($merchant) || !in_array($merchantTradeStatus,[1,2]))){
|
|
|
|
|
+ $this->error = 2024;
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- if($payType == 20){
|
|
|
|
|
- $qrcode = $alipayQrcode;
|
|
|
|
|
- if(empty($alipayQrcode)){
|
|
|
|
|
- $this->error = 2421;
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // 提现金额验证
|
|
|
|
|
+ $accountUsdt = $userType==1? $userUsdt : $merchantUsdt;
|
|
|
|
|
+ if ($money > $accountUsdt) {
|
|
|
|
|
+ $this->error = web_lang(2402, ['money' => $accountUsdt]);
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- if($payType == 50){
|
|
|
|
|
- $bankInfo = MemberBankModel::where(['id'=> $bankId,'mark'=>1])
|
|
|
|
|
- ->select(['realname','bank_name','bank_card'])
|
|
|
|
|
- ->first();
|
|
|
|
|
- $bankInfo = $bankInfo? $bankInfo->toArray() : [];
|
|
|
|
|
- $bankInfo = array_values($bankInfo);
|
|
|
|
|
- if(empty($bankInfo)){
|
|
|
|
|
- $this->error = 2422;
|
|
|
|
|
- return false;
|
|
|
|
|
- }else {
|
|
|
|
|
- $account = $bankInfo? implode(' ', $bankInfo) : '';
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // 提现账户
|
|
|
|
|
+ $trcUrl = isset($userInfo['trc_url']) ? $userInfo['trc_url'] : '';
|
|
|
|
|
+ if (empty($trcUrl)) {
|
|
|
|
|
+ $this->error = 2403;
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ if($userPayPassword != get_password($payPassword)){
|
|
|
|
|
+ $this->error = 2038;
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ $cacheKey = "caches:member:withdraw:lock_{$userId}";
|
|
|
|
|
+ if(RedisService::get($cacheKey)){
|
|
|
|
|
+ $this->error = 1034;
|
|
|
|
|
+ return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 提现订单
|
|
|
|
|
|
|
+ DB::beginTransaction();
|
|
|
|
|
+ RedisService::set($cacheKey, $userInfo, rand(2,3));
|
|
|
|
|
+
|
|
|
|
|
+ // 提现记录
|
|
|
$orderNo = get_order_num('DW');
|
|
$orderNo = get_order_num('DW');
|
|
|
$data = [
|
|
$data = [
|
|
|
'order_no'=> $orderNo,
|
|
'order_no'=> $orderNo,
|
|
|
- 'user_id'=> $userId,
|
|
|
|
|
|
|
+ 'user_id'=> $userType==1? $userId : $merchantId,
|
|
|
'type'=> 2,
|
|
'type'=> 2,
|
|
|
- 'user_type'=> $type,
|
|
|
|
|
|
|
+ 'user_type'=> $userType,
|
|
|
|
|
+ 'coin_type'=> 1,
|
|
|
'money'=> $money,
|
|
'money'=> $money,
|
|
|
- 'actual_money'=> 0,
|
|
|
|
|
- 'qrcode'=> $qrcode,
|
|
|
|
|
- 'account'=> $account,
|
|
|
|
|
- 'pay_type'=> $payType,
|
|
|
|
|
|
|
+ 'actual_money'=> $money,
|
|
|
|
|
+ 'trc_url'=> $trcUrl,
|
|
|
|
|
+ 'pay_type'=> 20,
|
|
|
|
|
+ 'date'=> date('Y-m-d'),
|
|
|
'create_time'=> time(),
|
|
'create_time'=> time(),
|
|
|
'update_time'=> time(),
|
|
'update_time'=> time(),
|
|
|
'status'=> 1,
|
|
'status'=> 1,
|
|
|
'mark'=> 1,
|
|
'mark'=> 1,
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
- // 提现记录
|
|
|
|
|
- DB::beginTransaction();
|
|
|
|
|
if(!$id = BalanceLogModel::insertGetId($data)){
|
|
if(!$id = BalanceLogModel::insertGetId($data)){
|
|
|
DB::rollBack();
|
|
DB::rollBack();
|
|
|
- $this->error = 2033;
|
|
|
|
|
|
|
+ $this->error = 2405;
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 商户扣款
|
|
// 商户扣款
|
|
|
- if($type == 2){
|
|
|
|
|
- $updateData = ['balance'=>DB::raw("balance - {$money}"),'update_time'=> time()];
|
|
|
|
|
|
|
+ if($userType == 2){
|
|
|
|
|
+ $updateData = ['usdt'=>DB::raw("usdt - {$money}"),'update_time'=> time()];
|
|
|
if(!MerchantModel::where(['user_id'=> $userId,'mark'=>1])->update($updateData)){
|
|
if(!MerchantModel::where(['user_id'=> $userId,'mark'=>1])->update($updateData)){
|
|
|
DB::rollBack();
|
|
DB::rollBack();
|
|
|
- $this->error = 2423;
|
|
|
|
|
|
|
+ $this->error = 2406;
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /*$log = [
|
|
|
|
|
- 'user_id' => 0,
|
|
|
|
|
- 'merch_id' => $merchant['id'],
|
|
|
|
|
|
|
+ // 明细
|
|
|
|
|
+ $log = [
|
|
|
|
|
+ 'user_id' => $merchantId,
|
|
|
'source_uid' => $userId,
|
|
'source_uid' => $userId,
|
|
|
'source_order_no' => $orderNo,
|
|
'source_order_no' => $orderNo,
|
|
|
- 'type' => 12,
|
|
|
|
|
- 'coin_type' => 4,
|
|
|
|
|
|
|
+ 'type' => 5,
|
|
|
|
|
+ 'coin_type' => 1,
|
|
|
'user_type'=> 2,
|
|
'user_type'=> 2,
|
|
|
'money' => -$money,
|
|
'money' => -$money,
|
|
|
- 'balance' => $merchBalance,
|
|
|
|
|
|
|
+ 'actual_money' => -$money,
|
|
|
|
|
+ 'balance' => $merchantUsdt,
|
|
|
'create_time' => time(),
|
|
'create_time' => time(),
|
|
|
'update_time' => time(),
|
|
'update_time' => time(),
|
|
|
- 'remark' => "商户余额提现",
|
|
|
|
|
|
|
+ 'remark' => "商户账户余额提现",
|
|
|
'status' => 1,
|
|
'status' => 1,
|
|
|
'mark' => 1,
|
|
'mark' => 1,
|
|
|
- ];*/
|
|
|
|
|
|
|
+ ];
|
|
|
|
|
+
|
|
|
|
|
+ if (!AccountLogModel::insertGetId($log)) {
|
|
|
|
|
+ $this->error = 2407;
|
|
|
|
|
+ DB::rollBack();
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
// 用户扣款
|
|
// 用户扣款
|
|
|
else{
|
|
else{
|
|
|
- $updateData = ['balance'=>DB::raw("balance - {$money}"),'update_time'=> time()];
|
|
|
|
|
|
|
+ $updateData = ['usdt'=>DB::raw("usdt - {$money}"),'update_time'=> time()];
|
|
|
if(!MemberModel::where(['id'=> $userId,'mark'=>1])->update($updateData)){
|
|
if(!MemberModel::where(['id'=> $userId,'mark'=>1])->update($updateData)){
|
|
|
DB::rollBack();
|
|
DB::rollBack();
|
|
|
- $this->error = 2423;
|
|
|
|
|
|
|
+ $this->error = 2406;
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /*$log = [
|
|
|
|
|
|
|
+ // 明细
|
|
|
|
|
+ $log = [
|
|
|
'user_id' => $userId,
|
|
'user_id' => $userId,
|
|
|
- 'merch_id' => 0,
|
|
|
|
|
'source_uid' => 0,
|
|
'source_uid' => 0,
|
|
|
'source_order_no' => $orderNo,
|
|
'source_order_no' => $orderNo,
|
|
|
- 'type' => 11,
|
|
|
|
|
- 'coin_type' => 4,
|
|
|
|
|
|
|
+ 'type' => 5,
|
|
|
|
|
+ 'coin_type' => 1,
|
|
|
'user_type'=> 1,
|
|
'user_type'=> 1,
|
|
|
'money' => -$money,
|
|
'money' => -$money,
|
|
|
- 'balance' => $balance,
|
|
|
|
|
|
|
+ 'actual_money' => -$money,
|
|
|
|
|
+ 'balance' => $userUsdt,
|
|
|
'create_time' => time(),
|
|
'create_time' => time(),
|
|
|
'update_time' => time(),
|
|
'update_time' => time(),
|
|
|
- 'remark' => "账户余额提现",
|
|
|
|
|
|
|
+ 'remark' => "USDT余额提现",
|
|
|
'status' => 1,
|
|
'status' => 1,
|
|
|
'mark' => 1,
|
|
'mark' => 1,
|
|
|
- ];*/
|
|
|
|
|
|
|
+ ];
|
|
|
|
|
+
|
|
|
|
|
+ if (!AccountLogModel::insertGetId($log)) {
|
|
|
|
|
+ $this->error = 2407;
|
|
|
|
|
+ DB::rollBack();
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 推送消息
|
|
|
|
|
- $pushData = [
|
|
|
|
|
- 'title' => '提现申请提交成功',
|
|
|
|
|
- 'body' => "您的提现申请已提交请耐心等候审核",
|
|
|
|
|
- 'type' => 3, // 1-公告通知,2-订单通知,3-交易通知,4-其他
|
|
|
|
|
- 'content' => [
|
|
|
|
|
- 'order_no' => ['name' => '订单号', 'text' => $orderNo],
|
|
|
|
|
- 'pay_time' => ['name' => '申请时间', 'text' => date('Y-m-d H:i:s')],
|
|
|
|
|
- 'pay_type' => ['name' => '付款方式', 'text' => $payType==10?'微信支付':($payType==20?'支付宝':'银行卡')],
|
|
|
|
|
- 'money' => ['name' => '提现金额', 'text' => $money],
|
|
|
|
|
- 'status' => ['name' => '状态', 'text' => '待审核'],
|
|
|
|
|
- ],
|
|
|
|
|
- 'click_type' => 'payload',
|
|
|
|
|
- 'url' => '',
|
|
|
|
|
- ];
|
|
|
|
|
|
|
+ DB::commit();
|
|
|
|
|
|
|
|
- $merchId = isset($merchant['id'])? $merchant['id'] : 0;
|
|
|
|
|
- if($type == 2 && $merchId){
|
|
|
|
|
- PushService::make()->pushMessageByUser($merchId, $pushData, 2);
|
|
|
|
|
- }else{
|
|
|
|
|
- PushService::make()->pushMessageByUser($userId, $pushData);
|
|
|
|
|
|
|
+ // 站内消息
|
|
|
|
|
+ $dateTime = date('Y-m-d H:i:s');
|
|
|
|
|
+ $title = $userType == 1 ? 'USDT余额提现申请成功' : '商户余额提现申请成功';
|
|
|
|
|
+ $message = $userType == 1 ? "您在{$dateTime}(UTC+8)申请提现{$money}USDT余额成功,请耐心等候审核!!!" : "您在{$dateTime}(UTC+8)申请提现{$money}USDT商户余额成功,请耐心等候审核!!!";
|
|
|
|
|
+ MessageService::make()->pushMessage($userId, $title, $message);
|
|
|
|
|
+
|
|
|
|
|
+ // 提现自动审核,低于该金额自动审核
|
|
|
|
|
+ $autoCheckUsdt = ConfigService::make()->getConfigByCode('withdraw_auto_money', 300);
|
|
|
|
|
+ $autoCheckUsdt = $autoCheckUsdt > 0 ? $autoCheckUsdt : 0;
|
|
|
|
|
+ if ($money <= $autoCheckUsdt) {
|
|
|
|
|
+ // 打款处理
|
|
|
|
|
+ $result = WalletService::make()->usdtTrcTransfer($trcUrl, $money);
|
|
|
|
|
+ $txID = isset($result['txId']) ? $result['txId'] : '';
|
|
|
|
|
+ $payAddress = isset($result['address']) ? $result['address'] : '';
|
|
|
|
|
+ if ($txID && $payAddress) {
|
|
|
|
|
+ $updateData = ['hash'=> $txID,'wallet_url'=> $payAddress,'audit_remark'=>'自动审核打款','status'=>2,'update_time'=>time()];
|
|
|
|
|
+ if($this->model->where(['order_no'=> $orderNo,'user_type'=> $userType])->update($updateData)){
|
|
|
|
|
+ $title = $userType == 1 ? 'USDT余额提现审核成功' : '商户余额提现审核成功';
|
|
|
|
|
+ $message = $userType == 1 ? "您在{$dateTime}(UTC+8)申请提现{$money}USDT余额审核成功,请耐心等候打款到账!!!" : "您在{$dateTime}(UTC+8)申请提现{$money}USDT商户余额审核成功,请耐心等候打款到账!!!";
|
|
|
|
|
+ MessageService::make()->pushMessage($userId, $title, $message);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- DB::commit();
|
|
|
|
|
- $this->error = 2424;
|
|
|
|
|
|
|
+ $this->error = $title;
|
|
|
return [
|
|
return [
|
|
|
'id'=> $id,
|
|
'id'=> $id,
|
|
|
'money'=> $money,
|
|
'money'=> $money,
|
|
|
- 'pay_type'=> $payType,
|
|
|
|
|
|
|
+ 'user_type'=> $userType,
|
|
|
];
|
|
];
|
|
|
}
|
|
}
|
|
|
|
|
|