105 lines
3.8 KiB
PHP
105 lines
3.8 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)
|
|
{
|
|
$product = StoreBranchProduct::where('store_id', $store_id)->where('product_id', $product_id)->find();
|
|
if ($product && $product['rose'] > 0) {
|
|
if ($product['rose'] >= 4 && $product['rose'] < 8) {
|
|
$rose = bcdiv($product['rose'], 100, 2);
|
|
$commission = bcmul($product['purchase'], $rose, 2);
|
|
StoreFinanceFlowProduct::create([
|
|
'store_id' => $store_id,
|
|
'product_id' => $product_id,
|
|
'number' => $commission,
|
|
'oid' => $oid,
|
|
'type' => 2,
|
|
'status' => 1,
|
|
]);
|
|
} elseif ($product['rose'] >= 8) {
|
|
$rose = bcdiv($product['rose'], 100, 2);
|
|
|
|
$Distribution = Distribution::where('rate', $rose)->find();
|
|
//门店
|
|
$data[] = [
|
|
'store_id' => $store_id,
|
|
'product_id' => $product_id,
|
|
'number' => bcmul($product['price'], $Distribution['store'], 2),
|
|
'oid' => $oid,
|
|
'type' => 1,
|
|
'status' => 1,
|
|
];
|
|
//平台
|
|
$data[] = [
|
|
'store_id' => $store_id,
|
|
'product_id' => $product_id,
|
|
'number' => bcmul($product['price'], $Distribution['platform'],2),
|
|
'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'], 2),
|
|
'oid' => $oid,
|
|
'type' => 3,
|
|
'status' => 1,
|
|
];
|
|
//队长
|
|
$data[] = [
|
|
'store_id' => $store_id,
|
|
'product_id' => $product_id,
|
|
'other_uid' => $brigade_uid,
|
|
'number' => bcmul($product['price'], $Distribution['brigade'], 2),
|
|
'oid' => $oid,
|
|
'type' => 4,
|
|
'status' => 1,
|
|
];
|
|
//会员
|
|
$data[] = [
|
|
'store_id' => $store_id,
|
|
'product_id' => $product_id,
|
|
'other_uid' => $uid,
|
|
'number' => bcmul($product['price'], $Distribution['user'], 2),
|
|
'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'], 2),
|
|
'oid' => $oid,
|
|
'type' => 5,
|
|
'status' => 1,
|
|
];
|
|
}
|
|
|
|
(new StoreFinanceFlowProduct())->saveAll($data);
|
|
}
|
|
}
|
|
}
|
|
}
|