feat(commission): 优化商品佣金计算逻辑,根据商品类型和用户等级判断计算方式

This commit is contained in:
mkm 2024-08-26 23:05:01 +08:00
parent 3f00f24334
commit df9ed597fc
2 changed files with 139 additions and 26 deletions

View File

@ -8,6 +8,7 @@ use app\common\model\store_finance_flow_product\StoreFinanceFlowProduct;
use app\common\model\store_order_cart_info\StoreOrderCartInfo;
use app\common\model\store_product\StoreProduct;
use PDO;
use support\Log;
/**
* 产品佣金计算
@ -21,20 +22,30 @@ class CommissionProductLogic extends BaseLogic
*/
function calculate_product_flow($find, $order, $village_uid = 0, $brigade_uid = 0, $user_ship = 0, $spread_user_ship = 0)
{
$product = StoreBranchProduct::where('id', $find['product_id'])->where('store_id', $order['store_id'])->find();
$product = StoreBranchProduct::where('product_id', $find['product_id'])->where('store_id', $order['store_id'])->find();
if (!$product) {
$product = StoreProduct::where('id', $find['product_id'])->find();
}
if ($product) {
if ($product['product_type'] == 4) {
$this->c($find, $order, $village_uid, $brigade_uid, $user_ship, $product);
return true;
} else {
if ($user_ship == 5) {
$top_cate_id = StoreBranchProduct::where('product_id', $find['product_id'])->value('top_cate_id');
if ($top_cate_id == 15189) {
$this->b($find, $order, $product);
$this->b($find, $order, $product,$user_ship);
return true;
}
} else {
} elseif($user_ship==0) {
$this->b($find, $order, $product,$user_ship);
return true;
}else{
$this->a($find, $order, $village_uid, $brigade_uid, $user_ship, $product);
}
}
return true;
}
}
@ -45,7 +56,11 @@ class CommissionProductLogic extends BaseLogic
public function a($find, $order, $village_uid, $brigade_uid, $user_ship, $product)
{
// $rose = bcdiv($product['rose'], 100, 2);
if($user_ship==4){
$total_price = bcmul($product['cost'], $find['cart_num']);
}else{
$total_price = bcmul($product['price'], $find['cart_num']);
}
// $Distribution = Distribution::where('rate', $rose)->find();
//门店
$data[] = [
@ -88,11 +103,11 @@ class CommissionProductLogic extends BaseLogic
'status' => 1,
];
//会员
if ($user_ship == 1) {
$uid = $order['spread_uid'];
} else {
$uid = 0;
}
// if ($user_ship == 1) {
// $uid = $order['spread_uid'];
// } else {
// $uid = 0;
// }
// $data[] = [
// 'store_id' => $order['store_id'],
// 'product_id' => $find['product_id'],
@ -103,18 +118,30 @@ class CommissionProductLogic extends BaseLogic
// 'status' => 1,
// ];
//个人店铺
//会员
if ($order['spread_uid'] > 0) {
if (in_array($user_ship, [2, 3])) {
$data[] = [
'store_id' => $order['store_id'],
'product_id' => $find['product_id'],
'other_uid' => $order['spread_uid'],
'number' => bcmul($total_price, 0.05, 2),
'oid' => $order['id'],
'type' => 0,
'status' => 1,
];
} else {
$data[] = [
'store_id' => $order['store_id'],
'product_id' => $find['product_id'],
'other_uid' => $order['spread_uid'],
'number' => bcmul($total_price, 0.07, 2),
'oid' => $order['id'],
'type' => 5,
'type' => 0,
'status' => 1,
];
}
}
$data[] = [
'store_id' => $order['store_id'],
'product_id' => $find['product_id'],
@ -130,10 +157,10 @@ class CommissionProductLogic extends BaseLogic
/**
* 商户价结算
*/
public function b($find, $order, $product)
public function b($find, $order, $product,$user_ship)
{
// $rose = bcdiv($product['rose'], 100, 2);
$total_price = bcmul($product['purchase'], $find['cart_num']);
$total_price = bcmul($product['cost'], $find['cart_num']);
//门店
$data[] = [
'store_id' => $order['store_id'],
@ -154,6 +181,78 @@ class CommissionProductLogic extends BaseLogic
'type' => 2,
'status' => 1,
];
$data[] = [
'store_id' => $order['store_id'],
'product_id' => $find['product_id'],
'other_uid' => 0,
'number' => bcmul($total_price, 0.01, 2),
'oid' => $order['id'],
'type' => 6,
'status' => 1,
];
(new StoreFinanceFlowProduct())->saveAll($data);
}
//活动商品结算
public function c($find, $order, $village_uid, $brigade_uid, $user_ship, $product)
{
// $rose = bcdiv($product['rose'], 100, 2);
$total_price = bcmul($product['price'], $find['cart_num']);
$purchase_price = bcmul($product['purchase'], $find['cart_num']);
$brigade_number = bcmul($total_price, 0.02, 2);
$village_number = bcmul($brigade_number, 0.1, 2);
$platform_number = bcmul($total_price, 0.02, 2);
$number1 = bcadd($brigade_number, $village_number, 2);
$number2 = bcadd($number1, $platform_number, 2);
//零售-供货价
$number3 = bcsub($total_price, $purchase_price, 2);
//门店利润
$store_number = bcsub($number3, $number2, 2);
//队长
$data[] = [
'store_id' => $order['store_id'],
'product_id' => $find['product_id'],
'other_uid' => $brigade_uid,
'number' => $brigade_number,
'oid' => $order['id'],
'type' => 4,
'status' => 1,
];
//村长
$data[] = [
'store_id' => $order['store_id'],
'product_id' => $find['product_id'],
'other_uid' => $village_uid,
'number' => $village_number,
'oid' => $order['id'],
'type' => 3,
'status' => 1,
];
//门店
$data[] = [
'store_id' => $order['store_id'],
'product_id' => $find['product_id'],
'other_uid' => 0,
'number' => $store_number,
'oid' => $order['id'],
'type' => 1,
'status' => 1,
];
//平台
$data[] = [
'store_id' => $order['store_id'],
'product_id' => $find['product_id'],
'other_uid' => 0,
'number' => $platform_number,
'oid' => $order['id'],
'type' => 2,
'status' => 1,
];
(new StoreFinanceFlowProduct())->saveAll($data);
}
}

View File

@ -675,6 +675,13 @@ class PayNotifyLogic extends BaseLogic
}
}
}
$info = StoreOrderCartInfo::where('oid', $order['id'])->field('store_id,product_id,cart_num')->select();
$comm = new CommissionProductLogic();
foreach ($info as $k => $v) {
$comm->calculate_product_flow($v, $order, $village_uid, $brigade_uid, $user_ship);
}
CommissionnLogic::setStore($order, $village_uid, $brigade_uid, $transaction_id);
return true;
if (isset($user) && $order['store_id'] == getenv('ACTIVITY_STORE_ID') && !in_array($user['user_ship'], [4, 6, 7])) {
try {
$info = StoreOrderCartInfo::where('oid', $order['id'])->field('store_id,product_id,cart_num')->select();
@ -709,6 +716,13 @@ class PayNotifyLogic extends BaseLogic
break;
}
} else {
$info = StoreOrderCartInfo::where('oid', $order['id'])->field('store_id,product_id,cart_num')->select();
$comm = new CommissionProductLogic();
foreach ($info as $k => $v) {
$comm->calculate_product_flow($v, $order, $village_uid, $brigade_uid, $user_ship);
}
CommissionnLogic::setStore($order, $village_uid, $brigade_uid, $transaction_id);
return true;
if (isset($user) && $order['store_id'] == getenv('ACTIVITY_STORE_ID') && !in_array($user['user_ship'], [4, 6, 7])) {
try {
$info = StoreOrderCartInfo::where('oid', $order['id'])->field('store_id,product_id,cart_num')->select();