调试平台手续费分润

This commit is contained in:
luofei 2023-05-25 17:15:48 +08:00
parent 9d88388a08
commit 13a4c40034
2 changed files with 56 additions and 45 deletions

View File

@ -27,7 +27,8 @@ use think\model\Relation;
class StoreCartDao extends BaseDao class StoreCartDao extends BaseDao
{ {
const SOURCE_CLOUD = 101; //店铺云商品 const SOURCE_STORE_CLOUD = 101; //店铺内云商品
const SOURCE_CLOUD = 102; //云仓内店铺商品
protected function getModel(): string protected function getModel(): string
{ {

View File

@ -3,13 +3,13 @@ declare (strict_types=1);
namespace app\listener; namespace app\listener;
use app\common\dao\store\order\StoreCartDao;
use app\common\dao\system\merchant\MerchantDao;
use app\common\model\system\merchant\Merchant; use app\common\model\system\merchant\Merchant;
use app\common\repositories\system\merchant\FinancialRecordRepository; use app\common\repositories\system\merchant\FinancialRecordRepository;
use app\common\repositories\system\merchant\MerchantRepository; use app\common\repositories\system\merchant\MerchantRepository;
use crmeb\jobs\AutoMarginJob;
use think\facade\Db; use think\facade\Db;
use think\facade\Log; use think\facade\Log;
use think\facade\Queue;
class paySuccessOrder class paySuccessOrder
{ {
@ -33,51 +33,61 @@ class paySuccessOrder
return; return;
} }
$this->streetId = $merchant['street_id']; $this->streetId = $merchant['street_id'];
//订单购物详情表是否有云仓数据 //订单购物详情表是否有云仓数据
$store_order_product_price = Db::name('store_order_product')->where('order_id', $event['order']['order_id']) $orderProduct = Db::name('store_order_product')
->where('is_refund', 0)->where('source', 101)->sum('product_price'); ->where('order_id', $event['order']['order_id'])
if ($store_order_product_price <= 0) { ->where('is_refund', 0)
return true; ->whereIn('source', [StoreCartDao::SOURCE_STORE_CLOUD, StoreCartDao::SOURCE_CLOUD])
} ->group('source_id')
$source_id = Db::name('store_order_product')->where('order_id', $event['order']['order_id'])->where('is_refund', 0)->where('source', 101)->value('source_id'); ->column('source,source_id,sum(product_price) total');
$commission_rate = ($event['order']['commission_rate'] / 100); foreach ($orderProduct as $item) {
//该笔订单平台总手续费 $commission_rate = ($event['order']['commission_rate'] / 100);
$this->totalAmount = bcmul((string)$store_order_product_price, (string)$commission_rate, 2); //该笔订单平台总手续费
$this->totalAmount = bcmul((string)$item['total'], (string)$commission_rate, 2);
if ($this->totalAmount <= 0) {
continue;
}
//入口商户佣金 //入口商户佣金
$merchantRate = systemConfig('commission_to_merchant_rate'); $entryMerId = $item['source_id'];
$merchantAmount = bcmul($this->totalAmount, (string)($merchantRate / 100), 2); $entryMerchant = app()->make(MerchantDao::class)->get($entryMerId);
/** @var MerchantRepository $merchantRepo */ if ($entryMerchant == Merchant::TypeStore) {
$merchantRepo = app()->make(MerchantRepository::class); $merchantRate = systemConfig('commission_to_merchant_rate');
$merchantRepo->merId = $source_id; $merchantAmount = bcmul($this->totalAmount, (string)($merchantRate / 100), 2);
$merchantRepo->forceMargin = true; /** @var MerchantRepository $merchantRepo */
[$merchantAmount, $this->finance] = $merchantRepo->autoMargin($merchantAmount, $event['order'], $this->finance, $this->financeSn, $this->index); $merchantRepo = app()->make(MerchantRepository::class);
$this->index++; $merchantRepo->merId = $entryMerId;
if ($merchantAmount > 0) { $merchantRepo->forceMargin = true;
$this->finance[] = [ [$merchantAmount, $this->finance] = $merchantRepo->autoMargin($merchantAmount, $event['order'], $this->finance, $this->financeSn, $this->index);
'order_id' => $this->event['order']['order_id'], $this->index++;
'order_sn' => $this->event['order']['order_sn'], if ($merchantAmount > 0) {
'user_info' => $this->event['order']->user->nickname, $this->finance[] = [
'user_id' => $this->event['order']['uid'], 'order_id' => $this->event['order']['order_id'],
'financial_type' => 'entry_merchant_commission', 'order_sn' => $this->event['order']['order_sn'],
'financial_pm' => 1, 'user_info' => $this->event['order']->user->nickname,
'type' => 1, 'user_id' => $this->event['order']['uid'],
'number' => $merchantAmount, 'financial_type' => 'entry_merchant_commission',
'mer_id' => $this->event['order']['mer_id'], 'financial_pm' => 1,
'financial_record_sn' => $this->financeSn . $this->index 'type' => 1,
]; 'number' => $merchantAmount,
$this->index++; 'mer_id' => $this->event['order']['mer_id'],
app()->make(MerchantRepository::class)->addLockMoney($source_id, 'order', $event['order']['order_id'], (float)$merchantAmount); 'financial_record_sn' => $this->financeSn . $this->index
} ];
$this->index++;
app()->make(MerchantRepository::class)->addLockMoney($entryMerId, 'order', $event['order']['order_id'], (float)$merchantAmount);
}
}
//镇分管人员佣金 //镇团队佣金
$this->calculate(Merchant::TypeTeamServer, 'commission_to_town_manager_rate'); $this->calculate(Merchant::TypeTownServer, 'commission_to_town_rate');
//小组服务团队佣金 //村团队佣金
$this->calculate(Merchant::TypeVillageServer, 'commission_to_town_team_rate'); $this->calculate(Merchant::TypeVillageServer, 'commission_to_village_rate');
//镇级云仓佣金 //小组服务团队佣金
$this->calculate(Merchant::TypeTownServer, 'commission_to_cloud_rate'); $this->calculate(Merchant::TypeTeamServer, 'commission_to_service_team_rate');
//镇级云仓佣金 //云仓佣金
$this->calculate(Merchant::TypeCloudWarehouse, 'commission_to_cloud_rate'); $this->calculate(Merchant::TypeTownServer, 'commission_to_cloud_rate');
}
$financialRecordRepository->insertAll($this->finance); $financialRecordRepository->insertAll($this->finance);
} }