multi-store/app/common/logic/CommissionProductLogic.php

109 lines
4.2 KiB
PHP

<?php
namespace app\common\logic;
use app\common\model\distribution\Distribution;
use app\common\model\store_branch_product\StoreBranchProduct;
use app\common\model\store_finance_flow_product\StoreFinanceFlowProduct;
use app\common\model\store_order_cart_info\StoreOrderCartInfo;
/**
* 产品佣金计算
*
*/
class CommissionProductLogic extends BaseLogic
{
/**
* 根据毛利率计算
*/
function calculate_product_flow($oid, $store_id, $product_id, $village_uid = 0, $brigade_uid = 0,$uid=0,$spread_uid=0)
{
$find = StoreOrderCartInfo::where($oid, $product_id)->field('price,cart_num,rose')->find();
if ($find && $find['rose'] > 0) {
$product = StoreBranchProduct::where('store_id', $store_id)->where('product_id', $product_id)->find();
if ($product) {
if ($product['rose'] >= 4 && $product['rose'] < 8) {
$rose = bcdiv($find['rose'], 100, 2);
$commission = bcmul($product['purchase'], $rose, 4);
StoreFinanceFlowProduct::create([
'store_id' => $store_id,
'product_id' => $product_id,
'number' => $commission,
'oid' => $oid,
'type' => 2,
'status' => 1,
]);
} elseif ($product['rose'] >= 8) {
$rose = bcdiv($find['rose'], 100, 2);
$Distribution = Distribution::where('rate', $rose)->find();
//门店
$data[] = [
'store_id' => $store_id,
'product_id' => $product_id,
'number' => bcmul($product['price'], $Distribution['store'], 4),
'oid' => $oid,
'type' => 1,
'status' => 1,
];
//平台
$data[] = [
'store_id' => $store_id,
'product_id' => $product_id,
'number' => bcmul($product['price'], $Distribution['platform'], 4),
'oid' => $oid,
'type' => 2,
'status' => 1,
];
//村长
$data[] = [
'store_id' => $store_id,
'product_id' => $product_id,
'other_uid' => $village_uid,
'number' => bcmul($product['price'], $Distribution['village'], 4),
'oid' => $oid,
'type' => 0,
'status' => 1,
];
//队长
$data[] = [
'store_id' => $store_id,
'product_id' => $product_id,
'other_uid' => $brigade_uid,
'number' => bcmul($product['price'], $Distribution['brigade'], 4),
'oid' => $oid,
'type' => 0,
'status' => 1,
];
//会员
$data[] = [
'store_id' => $store_id,
'product_id' => $product_id,
'other_uid' => $uid,
'number' => bcmul($product['price'], $Distribution['user'], 4),
'oid' => $oid,
'type' => 0,
'status' => 1,
];
//个人店铺
if($spread_uid>0){
$data[] = [
'store_id' => $store_id,
'product_id' => $product_id,
'other_uid' => $uid,
'number' => bcmul($product['price'], $Distribution['person_store'], 4),
'oid' => $oid,
'type' => 0,
'status' => 1,
];
}
(new StoreFinanceFlowProduct())->saveAll($data);
}
}
}
}
}