订单支持商户余额支付
This commit is contained in:
parent
1200f624d7
commit
e833b21b46
@ -86,7 +86,7 @@ class StoreOrderRepository extends BaseRepository
|
||||
/**
|
||||
* 支付类型
|
||||
*/
|
||||
const PAY_TYPE = ['balance', 'weixin', 'routine', 'h5', 'alipay', 'alipayQr', 'weixinQr', 'scrcu', 'creditBuy'];
|
||||
const PAY_TYPE = ['balance', 'weixin', 'routine', 'h5', 'alipay', 'alipayQr', 'weixinQr', 'scrcu', 'creditBuy', 'merBalance'];
|
||||
|
||||
const TYPE_SN_ORDER = 'wxo';
|
||||
const TYPE_SN_PRESELL = 'wxp';
|
||||
@ -118,6 +118,9 @@ class StoreOrderRepository extends BaseRepository
|
||||
if ($type === 'balance') {
|
||||
return $this->payBalance($user, $groupOrder);
|
||||
}
|
||||
if ($type === 'merBalance') {
|
||||
return $this->payMerBalance($user, $groupOrder);
|
||||
}
|
||||
|
||||
if (in_array($type, ['weixin', 'alipay'], true) && $isApp) {
|
||||
$type .= 'App';
|
||||
@ -173,6 +176,44 @@ class StoreOrderRepository extends BaseRepository
|
||||
return app('json')->status('success', '余额支付成功', ['order_id' => $groupOrder['group_order_id']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @param StoreGroupOrder $groupOrder
|
||||
* @return mixed
|
||||
* @author xaboy
|
||||
* @day 2020/6/9
|
||||
*/
|
||||
public function payMerBalance(User $user, StoreGroupOrder $groupOrder)
|
||||
{
|
||||
if (!systemConfig('yue_pay_status'))
|
||||
throw new ValidateException('未开启余额支付');
|
||||
$merchant = Merchant::where('uid', $user['uid'])->find();
|
||||
if (empty($merchant['mer_money']) || $merchant['mer_money'] < $groupOrder['pay_price'])
|
||||
throw new ValidateException('余额不足,请更换支付方式');
|
||||
Db::startTrans();
|
||||
try {
|
||||
$merchant->mer_money = bcsub($merchant->mer_money, $groupOrder['pay_price'], 2);
|
||||
$merchant->save();
|
||||
$userBillRepository = app()->make(UserBillRepository::class);
|
||||
$userBillRepository->decBill($merchant['uid'], 'mer_money', 'pay_product', [
|
||||
'link_id' => $groupOrder['group_order_id'],
|
||||
'status' => 1,
|
||||
'title' => '购买商品',
|
||||
'number' => $groupOrder['pay_price'],
|
||||
'mark' => '商户余额支付支付' . floatval($groupOrder['pay_price']) . '元购买商品',
|
||||
'balance' => $merchant->mer_money
|
||||
]);
|
||||
$this->paySuccess($groupOrder);
|
||||
Db::commit();
|
||||
} catch (Exception $e) {
|
||||
Db::rollback();
|
||||
Log::error('余额支付失败'.$e->getMessage().'。line:'.$e->getLine().'。file:'.$e->getFile());
|
||||
throw new ValidateException('余额支付失败'.$e->getMessage());
|
||||
}
|
||||
|
||||
return app('json')->status('success', '余额支付成功', ['order_id' => $groupOrder['group_order_id']]);
|
||||
}
|
||||
|
||||
public function changePayType(StoreGroupOrder $groupOrder, int $pay_type)
|
||||
{
|
||||
Db::transaction(function () use ($groupOrder, $pay_type) {
|
||||
|
@ -1284,7 +1284,7 @@ class StoreOtherOrderRepository extends BaseRepository
|
||||
}else{
|
||||
$merchant = Db::name('merchant')->where('uid',$item['uid'])->where('status',1)->field('mer_id,mer_name,is_trader,financial_bank,auto_margin_rate,commission_rate')->find();
|
||||
}
|
||||
$merchant['financial_bank'] = json_decode($merchant['financial_bank'], true);
|
||||
$merchant['financial_bank'] = !empty($merchant['financial_bank']) ? json_decode($merchant['financial_bank'], true) : [];
|
||||
$item['merchant'] = $merchant;
|
||||
});
|
||||
return compact('count', 'list');
|
||||
|
Loading…
x
Reference in New Issue
Block a user