添加自动扣除保证金
This commit is contained in:
parent
52690a7a82
commit
b25a86d056
@ -20,6 +20,13 @@ use app\common\model\system\merchant\FinancialRecord;
|
||||
class FinancialRecordDao extends BaseDao
|
||||
{
|
||||
|
||||
const Outlay = 0; //支出
|
||||
const Income = 1; //收入
|
||||
|
||||
const TypeMerchant = 0; //商户
|
||||
const TypeCommon = 1; //公共
|
||||
const TypePlatform = 2; //平台
|
||||
|
||||
protected function getModel(): string
|
||||
{
|
||||
return FinancialRecord::class;
|
||||
|
@ -12,8 +12,10 @@
|
||||
namespace app\common\repositories\store\order;
|
||||
|
||||
use app\common\dao\store\order\StoreOrderDao;
|
||||
use app\common\dao\system\merchant\FinancialRecordDao;
|
||||
use app\common\model\store\order\StoreGroupOrder;
|
||||
use app\common\model\store\order\StoreOrder;
|
||||
use app\common\model\system\merchant\Merchant;
|
||||
use app\common\model\user\User;
|
||||
use app\common\repositories\BaseRepository;
|
||||
use app\common\repositories\delivery\DeliveryOrderRepository;
|
||||
@ -374,6 +376,10 @@ class StoreOrderRepository extends BaseRepository
|
||||
$_payPrice = bcadd($_payPrice, $order->platform_coupon_price, 2);
|
||||
}
|
||||
|
||||
if ($_payPrice > 0) {
|
||||
$this->autoMargin($_payPrice, $order, $finance, $financeSn, $i);
|
||||
}
|
||||
|
||||
if (!$is_combine) {
|
||||
app()->make(MerchantRepository::class)->addLockMoney($order->mer_id, 'order', $order->order_id, $_payPrice);
|
||||
}
|
||||
@ -450,6 +456,39 @@ class StoreOrderRepository extends BaseRepository
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 自动扣除保证金
|
||||
* @param $income
|
||||
* @param $order
|
||||
* @param $finance
|
||||
* @param $financeSn
|
||||
* @param $index
|
||||
* @return void
|
||||
*/
|
||||
public function autoMargin(&$income, $order, &$finance, $financeSn, $index = 0)
|
||||
{
|
||||
$merchant = Merchant::find($order->mer_id);
|
||||
//商户保证金未完全缴纳且设置了自动扣除比例
|
||||
if ($merchant['margin'] > $merchant['paid_margin'] && $merchant['auto_margin_rate'] > 0 && $merchant['auto_margin_rate'] <= 100) {
|
||||
$margin = bcmul($income, $merchant['auto_margin_rate'] / 100, 2);
|
||||
$margin = min(bcsub($merchant['margin'], $merchant['paid_margin'], 2), $margin);
|
||||
$income = max(bcsub($income, $margin, 2), 0);
|
||||
$finance[] = [
|
||||
'order_id' => $order->order_id,
|
||||
'order_sn' => $order->order_sn,
|
||||
'user_info' => $order->user->nickname,
|
||||
'user_id' => $order->uid,
|
||||
'financial_type' => 'auto_margin',
|
||||
'financial_pm' => FinancialRecordDao::Outlay,
|
||||
'type' => FinancialRecordDao::TypePlatform,
|
||||
'number' => $margin,
|
||||
'mer_id' => $order->mer_id,
|
||||
'financial_record_sn' => $financeSn . $index
|
||||
];
|
||||
$merchant->save(['paid_margin' => bcadd($merchant['paid_margin'], $margin, 2)]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 自动打印
|
||||
* @Author:Qinii
|
||||
|
Loading…
x
Reference in New Issue
Block a user