feat(CommissionProductLogic): 根据毛利率计算分配产品流水

This commit is contained in:
mkm 2024-07-25 17:59:15 +08:00
parent 1ffd1193c1
commit 30230df638
2 changed files with 71 additions and 9 deletions

View File

@ -2,6 +2,7 @@
namespace app\common\logic; namespace app\common\logic;
use app\common\model\distribution\Distribution;
use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\store_branch_product\StoreBranchProduct;
use app\common\model\store_finance_flow_product\StoreFinanceFlowProduct; use app\common\model\store_finance_flow_product\StoreFinanceFlowProduct;
use app\common\model\store_order_cart_info\StoreOrderCartInfo; use app\common\model\store_order_cart_info\StoreOrderCartInfo;
@ -16,7 +17,7 @@ class CommissionProductLogic extends BaseLogic
/** /**
* 根据毛利率计算 * 根据毛利率计算
*/ */
function calculate_product_flow($oid, $store_id, $product_id, $village_uid = 0, $brigade_uid = 0) 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(); $find = StoreOrderCartInfo::where($oid, $product_id)->field('price,cart_num,rose')->find();
@ -35,17 +36,73 @@ class CommissionProductLogic extends BaseLogic
'status' => 1, 'status' => 1,
]); ]);
} elseif ($product['rose'] >= 8) { } 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);
} }
} }
$price = bcmul($find['price'], $find['cart_num'], 2);
// $price=bcsub($price, $price
// )
// bcsub($price, $find['rose'], 2);
// return $price;
} }
} }
} }

View File

@ -645,6 +645,11 @@ class PayNotifyLogic extends BaseLogic
} }
} }
} }
$info = StoreOrderCartInfo::where('oid',$order['id'])->field('store_id,product_id')->select();
$comm=new CommissionProductLogic();
foreach ($info as $v) {
$comm->calculate_product_flow($order['id'],$order['store_id'],$v['product_id'],$village_uid,$brigade_uid,$order['uid'],$order['spread_uid']);
}
switch ($user_ship) { switch ($user_ship) {
case 1: // 厨师 case 1: // 厨师
//case 4: // 商户 //case 4: // 商户