feat: 调整佣金计算逻辑以区分门店和平台收入

This commit is contained in:
mkm 2024-07-27 17:06:03 +08:00
parent fcf6efe6ae
commit b5e2707c3c

View File

@ -21,18 +21,47 @@ class CommissionProductLogic extends BaseLogic
{
$product = StoreBranchProduct::where('store_id', $order['store_id'])->where('product_id', $find['product_id'])->find();
if ($product && $product['rose'] > 0) {
if ($product['rose'] >= 4 && $product['rose'] < 8) {
if ($product['rose'] >= 0 && $product['rose'] < 8) {
$rose = bcdiv($product['rose'], 100, 2);
$total_price = bcmul($product['purchase'], $find['cart_num']);
$commission = bcmul($total_price, $rose, 2);
StoreFinanceFlowProduct::create([
'store_id' => $order['store_id'],
'product_id' => $find['product_id'],
'number' => $commission,
'oid' => $order['id'],
'type' => 2,
'status' => 1,
]);
//供货价
$total_cost = bcmul($product['cost'], $find['cart_num']);
$total = bcsub($total_cost, $total_price, 2);
$number = bcsub($total, $commission, 2);
if ($product['rose'] <= 4) {
//门店
$data = [
'store_id' => $order['store_id'],
'product_id' => $find['product_id'],
'number' => $total,
'oid' => $order['id'],
'type' => 1,
'status' => 1,
];
StoreFinanceFlowProduct::create($data);
} else {
//门店
$data[] = [
'store_id' => $order['store_id'],
'product_id' => $find['product_id'],
'number' => $number,
'oid' => $order['id'],
'type' => 1,
'status' => 1,
];
//平台
$data[] = [
'store_id' => $order['store_id'],
'product_id' => $find['product_id'],
'number' => $commission,
'oid' => $order['id'],
'type' => 2,
'status' => 1,
];
(new StoreFinanceFlowProduct())->saveAll($data);
}
} elseif ($product['rose'] >= 8) {
$rose = bcdiv($product['rose'], 100, 2);
$total_price = bcmul($product['purchase'], $find['cart_num']);