保证金 修正
This commit is contained in:
parent
8f325973bf
commit
7bf188ada3
@ -317,6 +317,7 @@ class StoreOrderRepository extends BaseRepository
|
||||
|
||||
$_order_rate = 0;
|
||||
|
||||
//平台手续费
|
||||
if ($order['commission_rate'] > 0) {
|
||||
|
||||
$commission_rate = ($order['commission_rate'] / 100);
|
||||
@ -324,7 +325,8 @@ class StoreOrderRepository extends BaseRepository
|
||||
$_order_rate = bcmul($_payPrice, $commission_rate, 2);
|
||||
|
||||
$_payPrice = bcsub($_payPrice, $_order_rate, 2);
|
||||
event('order.paySuccessOrder', compact('order','_order_rate'));
|
||||
// 结算各镇 小组佣金
|
||||
// event('order.paySuccessOrder', compact('order','_order_rate'));
|
||||
|
||||
}
|
||||
|
||||
@ -373,6 +375,7 @@ class StoreOrderRepository extends BaseRepository
|
||||
'financial_record_sn' => $financeSn . ($i++)
|
||||
];
|
||||
}
|
||||
//保证金计算
|
||||
if ($_payPrice > 0) {
|
||||
/** @var MerchantRepository $merchantRepo */
|
||||
$merchantRepo = app()->make(MerchantRepository::class);
|
||||
@ -435,10 +438,11 @@ class StoreOrderRepository extends BaseRepository
|
||||
//自动打印订单
|
||||
$this->autoPrinter($order->order_id, $order->mer_id);
|
||||
}
|
||||
if ($groupOrder->user->spread_uid) {
|
||||
Queue::push(UserBrokerageLevelJob::class, ['uid' => $groupOrder->user->spread_uid, 'type' => 'spread_pay_num', 'inc' => 1]);
|
||||
Queue::push(UserBrokerageLevelJob::class, ['uid' => $groupOrder->user->spread_uid, 'type' => 'spread_money', 'inc' => $groupOrder->pay_price]);
|
||||
}
|
||||
//分销判断
|
||||
// if ($groupOrder->user->spread_uid) {
|
||||
// Queue::push(UserBrokerageLevelJob::class, ['uid' => $groupOrder->user->spread_uid, 'type' => 'spread_pay_num', 'inc' => 1]);
|
||||
// Queue::push(UserBrokerageLevelJob::class, ['uid' => $groupOrder->user->spread_uid, 'type' => 'spread_money', 'inc' => $groupOrder->pay_price]);
|
||||
// }
|
||||
app()->make(UserRepository::class)->update($groupOrder->uid, [
|
||||
'pay_count' => Db::raw('pay_count+' . count($groupOrder->orderList)),
|
||||
'pay_price' => Db::raw('pay_price+' . $groupOrder->pay_price),
|
||||
@ -467,7 +471,7 @@ class StoreOrderRepository extends BaseRepository
|
||||
Queue::push(UserBrokerageLevelJob::class, ['uid' => $groupOrder->uid, 'type' => 'pay_money', 'inc' => $groupOrder->pay_price]);
|
||||
Queue::push(UserBrokerageLevelJob::class, ['uid' => $groupOrder->uid, 'type' => 'pay_num', 'inc' => 1]);
|
||||
app()->make(UserBrokerageRepository::class)->incMemberValue($groupOrder->uid, 'member_pay_num', $groupOrder->group_order_id);
|
||||
event('order.paySuccess', compact('groupOrder'));
|
||||
// event('order.paySuccess', compact('groupOrder'));
|
||||
//店内扫码支付
|
||||
if (isset($groupOrder['micro_pay']) && $groupOrder['micro_pay'] == 1) {
|
||||
$order = $this->dao->search(['uid' => $groupOrder->uid])->where('group_order_id', $groupOrder->group_order_id)->find();
|
||||
|
@ -51,6 +51,7 @@ use think\db\exception\ModelNotFoundException;
|
||||
use think\Exception;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Db;
|
||||
use think\facade\Log;
|
||||
use think\facade\Queue;
|
||||
use think\facade\Route;
|
||||
use think\Model;
|
||||
@ -688,18 +689,19 @@ class MerchantRepository extends BaseRepository
|
||||
public function autoMargin($income, $order, $finance, $financeSn, $index = 0)
|
||||
{
|
||||
$merchant = Merchant::find($this->merId);
|
||||
//商户保证金未完全缴纳且设置了自动扣除比例
|
||||
if ($merchant['margin'] <= $merchant['paid_margin'] || ($this->forceMargin === false && $merchant['auto_margin_rate'] <= 0 && $merchant['auto_margin_rate'] > 100)) {
|
||||
$margin = Db::name('MerchantType')->where('mer_type_id', $merchant['type_id'])->value('margin');
|
||||
//商户保证金大于支付保证金 或者forceMargin==false 直接返回 不计算保证金
|
||||
if ($merchant['paid_margin']>= $margin|| ($this->forceMargin === false && $merchant['auto_margin_rate'] == 0)) {
|
||||
return [$income, $finance, false];
|
||||
}
|
||||
$rate = $this->forceMargin ? 100 : $merchant['auto_margin_rate'];
|
||||
//商户保证金未完全缴纳且设置了自动扣除比例
|
||||
$margin = bcmul($income, $rate / 100, 2);
|
||||
$margin = min(bcsub($merchant['margin'], $merchant['paid_margin'], 2), $margin);
|
||||
$income = max(bcsub($income, $margin, 2), 0);
|
||||
if ($margin <= 0) {
|
||||
return [$income, $finance, false];
|
||||
}
|
||||
// //商户保证金未完全缴纳且设置了自动扣除比例
|
||||
$margin = bcmul($income, bcdiv($rate, 100,2), 2);
|
||||
// $margin = min(bcsub($margin, $merchant['paid_margin'], 2), $margin);
|
||||
// $income = max(bcsub($income, $margin, 2), 0);
|
||||
// if ($margin <= 0) {
|
||||
// return [$income, $finance, false];
|
||||
// }
|
||||
$finance[] = [
|
||||
'order_id' => $order->order_id,
|
||||
'order_sn' => $order->order_sn,
|
||||
@ -741,7 +743,7 @@ class MerchantRepository extends BaseRepository
|
||||
throw new \Exception('merchant 保存出错', 500);
|
||||
}
|
||||
|
||||
return [$income, $finance, true];
|
||||
return [bcsub($income,$margin), $finance, true];
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ class paySuccessMargin
|
||||
//已支付的保证金
|
||||
$paidMarginAmount = bcadd($merchantInfo['paid_margin'], $marginInfo['total_price'], 2);
|
||||
Db::name('merchant')->where('mer_id', $marginInfo['mer_id'])->where('uid', $marginInfo['uid'])->update([
|
||||
'paid_margin' => $paidMarginAmount
|
||||
'paid_margin' => $paidMarginAmount,'ot_margin'=>$paidMarginAmount
|
||||
]);
|
||||
Db::name('merchant')->where('mer_id', $marginInfo['mer_id'])->where('uid', $marginInfo['uid'])->update([
|
||||
'margin' => 0
|
||||
|
Loading…
x
Reference in New Issue
Block a user