|
|
@@ -13,6 +13,9 @@ use Illuminate\Support\Facades\Log;
|
|
|
|
|
|
use App\Services\Payment\SanJinService;
|
|
|
|
|
|
+use App\Services\WalletService;
|
|
|
+use App\Services\BalanceLogService;
|
|
|
+
|
|
|
/**
|
|
|
* 投注
|
|
|
*/
|
|
|
@@ -143,6 +146,20 @@ class PaymentOrderService extends BaseService
|
|
|
|
|
|
public static function createPayout($memberId ,$amount ,$channel ,$bank_name ,$account ,$card_no)
|
|
|
{
|
|
|
+
|
|
|
+ $default_amount = $amount;
|
|
|
+ $result = [];
|
|
|
+ $result['chat_id'] = $memberId;
|
|
|
+
|
|
|
+ $wallet = WalletService::findOne(['member_id' => $memberId]);
|
|
|
+ $balance = $wallet->available_balance;
|
|
|
+ if (bccomp($balance, $amount, 2) < 0) {
|
|
|
+ $result['text'] = '您的钱包余额不足!';
|
|
|
+ return $result;
|
|
|
+ }
|
|
|
+
|
|
|
+ $available_balance = bcsub($balance, $amount, 10);
|
|
|
+
|
|
|
$data = [];
|
|
|
$data['type'] = self::TYPE_PAYOUT;
|
|
|
$order_no = self::createOrderNo('sj'.$data['type'].'_',$memberId);
|
|
|
@@ -156,16 +173,53 @@ class PaymentOrderService extends BaseService
|
|
|
$data['card_no'] = $card_no;
|
|
|
$data['callback_url'] = SanJinService::getNotifyUrl();
|
|
|
$data['status'] = self::STATUS_STAY;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
$ret = SanJinService::payout($amount,$order_no,$bank_name,$account,$card_no);
|
|
|
|
|
|
if($ret['code'] == 200){
|
|
|
- $data['status'] = self::STATUS_PROCESS;
|
|
|
+
|
|
|
+ DB::beginTransaction();
|
|
|
+ try {
|
|
|
+ $wallet->available_balance = $available_balance;
|
|
|
+ $wallet->save();
|
|
|
+
|
|
|
+ $data['status'] = self::STATUS_PROCESS;
|
|
|
+ $info = self::model()::create($data);
|
|
|
+ $id = $info->id;
|
|
|
+
|
|
|
+ BalanceLogService::addLog(
|
|
|
+ $memberId,
|
|
|
+ $default_amount,
|
|
|
+ $balance,
|
|
|
+ $available_balance,
|
|
|
+ '三方提现',
|
|
|
+ $id,
|
|
|
+ '钱宝提现'
|
|
|
+ );
|
|
|
+
|
|
|
+ $text = "✅ 提现申请已提交!\n\n";
|
|
|
+ $text .= "钱包余额:{$available_balance} RMB\n";
|
|
|
+ $text .= "提现金额:{$default_amount} RMB\n";
|
|
|
+ $text .= "⌛️请等待系统处理, 到账时间可能需要几分钟!\n";
|
|
|
+
|
|
|
+ $result['text'] = $text;
|
|
|
+ DB::commit();
|
|
|
+ }catch (\Exception $e) {
|
|
|
+ DB::rollBack();
|
|
|
+ $result['text'] = $e->getMessage();
|
|
|
+ return $result;
|
|
|
+ // 记录错误日志或抛出异常
|
|
|
+ }
|
|
|
+
|
|
|
}else{
|
|
|
- $data['status'] = self::STATUS_FAIL;
|
|
|
- $data['remark'] = $ret['msg'];
|
|
|
+ $result['text'] = $ret['msg'];
|
|
|
+ return $result;
|
|
|
+
|
|
|
}
|
|
|
- self::model()::create($data);
|
|
|
- return $ret;
|
|
|
+ return $result;
|
|
|
}
|
|
|
|
|
|
}
|