调整订单佣金

This commit is contained in:
luofei 2024-02-27 18:05:17 +08:00
parent 30027973a6
commit cde71f49a7
4 changed files with 67 additions and 33 deletions

View File

@ -131,6 +131,28 @@ class FinancialDao extends BaseDao
$this->setData($number, $financialType, 1, 1, $merId);
}
/**
* 商户入账财务流水
* @param $number
* @param $financialType
* @param $merId
*/
public function merchantOut($number, $financialType, $merId = '')
{
$this->setData($number, $financialType, 0, 0, $merId);
}
/**
* 商户入账财务流水
* @param $number
* @param $financialType
* @param $merId
*/
public function merchantIn($number, $financialType, $merId = '')
{
$this->setData($number, $financialType, 1, 0, $merId);
}
public function setData($number, $financialType, $pm, $type = 2, $merId = '')
{
if (empty($this->financeSn)) {

View File

@ -24,6 +24,7 @@ use app\common\model\system\config\SystemConfigValue;
use app\common\model\system\financial\Financial;
use app\common\model\system\GeoStreet;
use app\common\model\system\serve\ServeOrder;
use app\common\model\user\User;
use app\common\repositories\store\StoreActivityRepository;
use think\facade\Db;
@ -316,4 +317,9 @@ class Merchant extends BaseModel
return $this->hasOne(GeoStreet::class, 'street_code', 'street_id');
}
public function promoter()
{
return User::where('uid', $this->uid)->value('spread_uid');
}
}

View File

@ -22,6 +22,7 @@ use app\common\model\store\order\StoreOrder;
use app\common\model\store\order\StoreOrderInterest;
use app\common\model\store\order\StoreRefundOrder;
use app\common\model\store\product\PurchaseRecord;
use app\common\model\system\merchant\FinancialRecord;
use app\common\model\user\User;
use app\common\model\system\merchant\Merchant;
use app\common\repositories\BaseRepository;
@ -288,7 +289,6 @@ class StoreOrderRepository extends BaseRepository
'user_type' => $storeOrderStatusRepository::U_TYPE_USER,
];
//TODO 成为推广员
foreach ($order->orderProduct as $product) {
if ($flag && $product['cart_info']['product']['is_gift_bag']) {
app()->make(UserRepository::class)->promoter($order->uid);
@ -304,36 +304,30 @@ class StoreOrderRepository extends BaseRepository
$financeDao->order = $order;
$financeDao->user = $groupOrder->user;
$financialType = $presell ? 'order_presell' : 'order';
// 平台订单收入流水账单数据
$financeDao->platformIn($order->total_price, $financialType);
// 公共收入流水账单数据
$financeDao->publicIn($order->total_price, $financialType);
if ($order->consumption_money > 0) {
// 平台支出优惠金额
$financeDao->platformOut($order->consumption_money, 'platform_consumption');
}
if ($order->source == 103) {
$_payPrice = $order->procure_price;
//市级供应链
$product_mer_id = Db::name('store_order_product')->where('order_id', $order->order_id)->value('product_mer_id');
// 平台支付市供应链流水账单数据
$financeDao->platformOut($_payPrice, 'supply_chain', $product_mer_id);
if ($product_mer_id) {
//市级供应链押金计算
if ($_payPrice > 0) {
/** @var MerchantRepository $merchantRepo */
$merchantRepo = app()->make(MerchantRepository::class);
$merchantRepo->merId = $product_mer_id;
$merchantRepo->forceMargin = false;
[$_payCityPrice, $financeDao] = $merchantRepo->deductDeposit($_payPrice, $order, $financeDao);
}
if (isset($_payCityPrice)) {
if (!$is_combine) {
app()->make(MerchantRepository::class)->addLockMoney($product_mer_id, 'order', $order->order_id, $_payCityPrice);
}
}
$_payPrice = bcsub($order->pay_price, bcadd($order['extension_one'], $order['extension_two'], 3), 2);
if ($order['commission_rate'] > 0) {
$commission_rate = bcdiv((string)$order['commission_rate'],'100',6);
$platformCommission = bcmul($_payPrice, (string)$commission_rate, 2);
// 平台收入手续费
$financeDao->platformIn($platformCommission, 'platform_commission');
$promoter = $order->merchant->promoter();
if (!empty($promoter)) {
$promoterCommission = bcmul($_payPrice, 0.003, 2);
// 平台支出推广费
$financeDao->platformOut($promoterCommission, 'promoter_commission');
}
} else {
$_payPrice = $order->pay_price;
$_payPrice = bcsub($_payPrice, $platformCommission, 2);
}
// 商户收入金额
$financeDao->merchantIn($_payPrice, 'merchant_order', $order['mer_id']);
if ($is_combine) {
$profitsharing[] = [
@ -357,10 +351,6 @@ class StoreOrderRepository extends BaseRepository
], $order->mer_id);
//自动打印订单
$this->autoPrinter($order->order_id, $order->mer_id);
if ($order['pay_price'] > 0 && $order['source'] == 103) {
// "惠农供销,谱写数字新篇章"活动首单分润,商户和村、小组合伙人
$financeDao = (new CommissionDao())->firstOrderCommission($order, $financeDao);
}
//判断是否是平台购物卡
$merchantCate = $order->orderProduct[0]->product->merCateId;
@ -744,6 +734,22 @@ class StoreOrderRepository extends BaseRepository
// 'number' => $order->extension_two,
// ], $order->mer_id);
}
$promoterCommission = FinancialRecord::where('order_id', $order['id'])
->where('financial_type', 'promoter_commission')
->column('user_id,number');
if (!empty($promoterCommission)) {
$userBillRepository->incBill($promoterCommission['user_id'], 'brokerage', 'order_one', [
'link_id' => $order['order_id'],
'status' => 0,
'title' => '获得推广佣金',
'number' => $promoterCommission['number'],
'mark' => $order->merchant['mer_name'] . '成功销售' . floatval($order['pay_price']) . '元,奖励推广佣金' . floatval($promoterCommission['number']),
'balance' => 0
]);
$userRepository = app()->make(UserRepository::class);
$userRepository->incBrokerage($promoterCommission['user_id'], $promoterCommission['number']);
}
}
/**

View File

@ -35,10 +35,10 @@ class paySuccess
{
try {
$orderList = $event['groupOrder']['orderList'];
if ($event['groupOrder']['source'] == 103) {
$storeConsumptionUserDao = new StoreConsumptionUserDao();
$storeConsumptionUserDao->check($event['groupOrder']['uid'], $event['groupOrder']['group_order_id']);
}
// if ($event['groupOrder']['source'] == 103) {
// $storeConsumptionUserDao = new StoreConsumptionUserDao();
// $storeConsumptionUserDao->check($event['groupOrder']['uid'], $event['groupOrder']['group_order_id']);
// }
foreach ($orderList as $k => $order) {
//
$StoreProcessing->AutomaticallyCreateOrders($order);