feat: 修改分润逻辑以优化计算方式

This commit is contained in:
mkm 2024-07-26 15:06:47 +08:00
parent 5cf7dd76b9
commit 83f81a3974
2 changed files with 111 additions and 127 deletions

View File

@ -3,6 +3,7 @@
namespace app\common\logic; namespace app\common\logic;
use app\common\enum\OrderEnum; use app\common\enum\OrderEnum;
use app\common\model\store_finance_flow_product\StoreFinanceFlowProduct;
use app\common\model\system_store\SystemStore; use app\common\model\system_store\SystemStore;
use app\common\model\user\User; use app\common\model\user\User;
use app\common\model\user\UserAddress; use app\common\model\user\UserAddress;
@ -14,32 +15,32 @@ class CommissionLogic extends BaseLogic
*/ */
public static function setVillage($order, $village_uid = 0, $brigade_uid = 0, $transaction_id = 0) public static function setVillage($order, $village_uid = 0, $brigade_uid = 0, $transaction_id = 0)
{ {
$user_1 = self::user($order, 0.05, $transaction_id, $village_uid, 14); //村长 self::user($order, 3, $transaction_id, $village_uid, 14); //村长
$user_2 = self::user($order, 0.03, $transaction_id, 0, 12); //会员、厨师 self::user($order, 0, $transaction_id, 0, 12); //会员、厨师
$user_3 = self::user($order, 0.01, $transaction_id, $brigade_uid, 15); //队长 self::user($order, 5, $transaction_id, 0, 12); //个人店铺
self::user($order, 4, $transaction_id, $brigade_uid, 15); //队长
$platform = self::platform($order, 0.02, $transaction_id); //平台 self::platform($order, 2, $transaction_id); //平台
$store = self::store($order, 0.05, $transaction_id, 0); //门店 self::store($order, 1, $transaction_id, 0); //门店
$attrition = self::attrition($order, 0.02, $transaction_id, 16); //损耗 // $attrition = self::attrition($order, 0.02, $transaction_id, 16); //损耗
self::suppliter($order, $transaction_id);
$moeny = bcadd(bcadd(bcadd(bcadd($user_1, $user_2, 2), $user_3, 2), $platform, 2), bcadd($store, $attrition, 2), 2);
self::suppliter($order, $moeny, $transaction_id);
} }
/** /**
* 走队长分润 * 走队长分润
*/ */
public static function setBrigade($order, $village_uid = 0, $brigade_uid = 0, $transaction_id = 0) public static function setBrigade($order, $village_uid = 0, $brigade_uid = 0, $transaction_id = 0)
{ {
$user_1 = self::user($order, 0.05, $transaction_id, $brigade_uid, 15); //队长 self::user($order, 4, $transaction_id, $brigade_uid, 15); //队长
$user_2 = self::user($order, 0.03, $transaction_id, 0, 12); ////会员、厨师 self::user($order, 0, $transaction_id, 0, 12); ////会员、厨师
$user_3 = self::user($order, 0.01, $transaction_id, $village_uid, 14); //村长 self::user($order, 5, $transaction_id, 0, 12); ////会员、厨师
self::user($order, 3, $transaction_id, $village_uid, 14); //村长
$platform = self::platform($order, 0.02, $transaction_id); //平台 self::platform($order, 2, $transaction_id); //平台
$store = self::store($order, 0.05, $transaction_id, 0); //门店 self::store($order, 1, $transaction_id, 0); //门店
$attrition = self::attrition($order, 0.02, $transaction_id, 16); //损耗 // $attrition = self::attrition($order, 0.02, $transaction_id, 16); //损耗
self::suppliter($order, $transaction_id);
$moeny = bcadd(bcadd(bcadd(bcadd($user_1, $user_2, 2), $user_3, 2), $platform, 2), bcadd($store, $attrition, 2), 2);
self::suppliter($order, $moeny, $transaction_id);
} }
/** /**
* 走厨师分润 * 走厨师分润
@ -51,14 +52,15 @@ class CommissionLogic extends BaseLogic
}else{ }else{
$uid=$order['spread_uid']; $uid=$order['spread_uid'];
} }
$user_1 = self::user($order, 0.07, $transaction_id, $uid, 12); //会员、厨师 self::user($order, 0, $transaction_id, $uid, 12); //会员、厨师
$user_2 = self::user($order, 0.01, $transaction_id, $village_uid, 14); //村长 self::user($order, 5, $transaction_id, $uid, 12); //会员、厨师
$user_3 = self::user($order, 0.01, $transaction_id, $brigade_uid, 15); //队长 self::user($order, 3, $transaction_id, $village_uid, 14); //村长
$platform = self::platform($order, 0.02, $transaction_id); //平台 self::user($order, 4, $transaction_id, $brigade_uid, 15); //队长
$store = self::store($order, 0.05, $transaction_id, 0); //门店 self::platform($order, 2, $transaction_id); //平台
$attrition = self::attrition($order, 0.02, $transaction_id, 16); //损耗 self::store($order, 1, $transaction_id, 0); //门店
$moeny = bcadd(bcadd(bcadd(bcadd($user_1, $user_2, 2), $user_3, 2), $platform, 2), bcadd($store, $attrition, 2), 2); // $attrition = self::attrition($order, 0.02, $transaction_id, 16); //损耗
self::suppliter($order, $moeny, $transaction_id); // $moeny = bcadd(bcadd(bcadd(bcadd($user_1, $user_2, 2), $user_3, 2), $platform, 2), bcadd($store, 0, 2), 2);
self::suppliter($order, $transaction_id);
} }
/** /**
@ -66,27 +68,23 @@ class CommissionLogic extends BaseLogic
*/ */
public static function setStore($order, $transaction_id = 0) public static function setStore($order, $transaction_id = 0)
{ {
$platform = self::platform($order, 0.02, $transaction_id); //平台 self::platform($order, 2, $transaction_id); //平台
$store = self::store($order, 0.05, $transaction_id, 0); //门店 self::store($order, 1, $transaction_id, 0); //门店
$attrition = self::attrition($order, 0.01, $transaction_id, 16); //损耗 // $attrition = self::attrition($order, 0.01, $transaction_id, 16); //损耗
$moeny = bcadd(bcadd($platform, $store, 2), $attrition, 2); // $moeny = bcadd($platform, $store, 2);
self::suppliter($order, $moeny, $transaction_id); self::suppliter($order, $transaction_id);
} }
/** /**
* 平台分润 * 平台分润
*/ */
public static function platform($order, $platformRate, $transaction_id) public static function platform($order, $type, $transaction_id)
{ {
$financeLogic = new StoreFinanceFlowLogic(); $financeLogic = new StoreFinanceFlowLogic();
$financeLogic->order = $order; $financeLogic->order = $order;
$financeLogic->user['uid'] = $order['uid']; $financeLogic->user['uid'] = $order['uid'];
$pay_price = $order['pay_price']; $fees=StoreFinanceFlowProduct::where('oid',$order['id'])->where('type',$type)->sum('number');
if (isset($order['dealVipAmount']) && $order['dealVipAmount'] > 0) {
$pay_price = bcsub($order['pay_price'], $order['dealVipAmount'], 2);
}
$fees = bcdiv(bcmul($pay_price, $platformRate, 2), 1, 2);
if ($fees > 0) { if ($fees > 0) {
$financeLogic->in($transaction_id, $fees, OrderEnum::ORDER_HANDLING_FEES, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); //平台手续费 $financeLogic->in($transaction_id, $fees, OrderEnum::ORDER_HANDLING_FEES, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); //平台手续费
$financeLogic->out($transaction_id, $fees, OrderEnum::ORDER_HANDLING_FEES, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); //商户平台手续费支出 $financeLogic->out($transaction_id, $fees, OrderEnum::ORDER_HANDLING_FEES, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); //商户平台手续费支出
@ -97,16 +95,14 @@ class CommissionLogic extends BaseLogic
/** /**
* 供应链订单获得 * 供应链订单获得
*/ */
public static function suppliter($order, $platformRate, $transaction_id) public static function suppliter($order, $transaction_id)
{ {
$financeLogic = new StoreFinanceFlowLogic(); $financeLogic = new StoreFinanceFlowLogic();
$financeLogic->order = $order; $financeLogic->order = $order;
$financeLogic->user['uid'] = $order['uid']; $financeLogic->user['uid'] = $order['uid'];
$pay_price = $order['pay_price']; $pay_price = $order['pay_price'];
if (isset($order['dealVipAmount']) && $order['dealVipAmount'] > 0) { $number=StoreFinanceFlowProduct::where('oid',$order['id'])->sum('number');
$pay_price = bcsub($order['pay_price'], $order['dealVipAmount'], 2); $fees = bcsub($pay_price, $number, 2);
}
$fees = bcsub($pay_price, $platformRate, 2);
if ($fees > 0) { if ($fees > 0) {
$financeLogic->in($transaction_id, $fees, OrderEnum::SUPPLIER_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); $financeLogic->in($transaction_id, $fees, OrderEnum::SUPPLIER_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0, $order['pay_type']);
$financeLogic->out($transaction_id, $fees, OrderEnum::SUPPLIER_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); $financeLogic->out($transaction_id, $fees, OrderEnum::SUPPLIER_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0, $order['pay_type']);
@ -116,7 +112,7 @@ class CommissionLogic extends BaseLogic
/** /**
* 门店分润 * 门店分润
*/ */
public static function store($order, $platformRate, $transaction_id, $uid) public static function store($order, $type, $transaction_id, $uid)
{ {
$financeLogic = new StoreFinanceFlowLogic(); $financeLogic = new StoreFinanceFlowLogic();
$financeLogic->user['uid'] = $order['uid']; $financeLogic->user['uid'] = $order['uid'];
@ -127,11 +123,7 @@ class CommissionLogic extends BaseLogic
//缴纳齐全了就加商户没有就加到平台 //缴纳齐全了就加商户没有就加到平台
$money_limt = SystemStore::where('id', $order['store_id'])->field('paid_deposit,security_deposit')->find(); $money_limt = SystemStore::where('id', $order['store_id'])->field('paid_deposit,security_deposit')->find();
$deposit = bcsub($money_limt['security_deposit'], $money_limt['paid_deposit'], 2); //保证金剩余额度 $deposit = bcsub($money_limt['security_deposit'], $money_limt['paid_deposit'], 2); //保证金剩余额度
$pay_price = $order['pay_price']; $store_profit=StoreFinanceFlowProduct::where('oid',$order['id'])->where('type',$type)->sum('number');
if (isset($order['dealVipAmount']) && $order['dealVipAmount'] > 0) {
$pay_price = bcsub($order['pay_price'], $order['dealVipAmount'], 2);
}
$store_profit = bcmul($pay_price, $platformRate, 2);
if ($deposit > 0) { if ($deposit > 0) {
if ($deposit > $store_profit) { if ($deposit > $store_profit) {
if ($store_profit > 0) { if ($store_profit > 0) {
@ -159,14 +151,10 @@ class CommissionLogic extends BaseLogic
/** /**
* 分给用户 * 分给用户
*/ */
public static function user($order, $userRate, $transaction_id, $uid = 0, $enum = 0) public static function user($order, $type, $transaction_id, $uid = 0, $enum = 0)
{ {
$financeLogic = new StoreFinanceFlowLogic(); $financeLogic = new StoreFinanceFlowLogic();
$pay_price = $order['pay_price']; $fees=StoreFinanceFlowProduct::where('oid',$order['id'])->where('type',$type)->sum('number');
if (isset($order['dealVipAmount']) && $order['dealVipAmount'] > 0) {
$pay_price = bcsub($order['pay_price'], $order['dealVipAmount'], 2);
}
$fees = bcmul($pay_price, $userRate, 2);
if ($fees > 0) { if ($fees > 0) {
//记录用户余额收入 //记录用户余额收入
$financeLogic->user['uid'] = $order['uid']; $financeLogic->user['uid'] = $order['uid'];

View File

@ -17,16 +17,13 @@ class CommissionProductLogic extends BaseLogic
/** /**
* 根据毛利率计算 * 根据毛利率计算
*/ */
function calculate_product_flow($oid, $store_id, $product_id, $village_uid = 0, $brigade_uid = 0,$uid=0,$spread_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();
if ($find && $find['rose'] > 0) {
$product = StoreBranchProduct::where('store_id', $store_id)->where('product_id', $product_id)->find(); $product = StoreBranchProduct::where('store_id', $store_id)->where('product_id', $product_id)->find();
if ($product) { if ($product && $product['rose'] > 0) {
if ($product['rose'] >= 4 && $product['rose'] < 8) { if ($product['rose'] >= 4 && $product['rose'] < 8) {
$rose = bcdiv($find['rose'], 100, 2); $rose = bcdiv($product['rose'], 100, 2);
$commission = bcmul($product['purchase'], $rose, 4); $commission = bcmul($product['purchase'], $rose, 2);
StoreFinanceFlowProduct::create([ StoreFinanceFlowProduct::create([
'store_id' => $store_id, 'store_id' => $store_id,
'product_id' => $product_id, 'product_id' => $product_id,
@ -36,14 +33,14 @@ class CommissionProductLogic extends BaseLogic
'status' => 1, 'status' => 1,
]); ]);
} elseif ($product['rose'] >= 8) { } elseif ($product['rose'] >= 8) {
$rose = bcdiv($find['rose'], 100, 2); $rose = bcdiv($product['rose'], 100, 2);
$Distribution = Distribution::where('rate', $rose)->find(); $Distribution = Distribution::where('rate', $rose)->find();
//门店 //门店
$data[] = [ $data[] = [
'store_id' => $store_id, 'store_id' => $store_id,
'product_id' => $product_id, 'product_id' => $product_id,
'number' => bcmul($product['price'], $Distribution['store'], 4), 'number' => bcmul($product['price'], $Distribution['store'], 2),
'oid' => $oid, 'oid' => $oid,
'type' => 1, 'type' => 1,
'status' => 1, 'status' => 1,
@ -52,7 +49,7 @@ class CommissionProductLogic extends BaseLogic
$data[] = [ $data[] = [
'store_id' => $store_id, 'store_id' => $store_id,
'product_id' => $product_id, 'product_id' => $product_id,
'number' => bcmul($product['price'], $Distribution['platform'], 4), 'number' => bcmul($product['price'], $Distribution['platform'],2),
'oid' => $oid, 'oid' => $oid,
'type' => 2, 'type' => 2,
'status' => 1, 'status' => 1,
@ -62,9 +59,9 @@ class CommissionProductLogic extends BaseLogic
'store_id' => $store_id, 'store_id' => $store_id,
'product_id' => $product_id, 'product_id' => $product_id,
'other_uid' => $village_uid, 'other_uid' => $village_uid,
'number' => bcmul($product['price'], $Distribution['village'], 4), 'number' => bcmul($product['price'], $Distribution['village'], 2),
'oid' => $oid, 'oid' => $oid,
'type' => 0, 'type' => 3,
'status' => 1, 'status' => 1,
]; ];
//队长 //队长
@ -72,9 +69,9 @@ class CommissionProductLogic extends BaseLogic
'store_id' => $store_id, 'store_id' => $store_id,
'product_id' => $product_id, 'product_id' => $product_id,
'other_uid' => $brigade_uid, 'other_uid' => $brigade_uid,
'number' => bcmul($product['price'], $Distribution['brigade'], 4), 'number' => bcmul($product['price'], $Distribution['brigade'], 2),
'oid' => $oid, 'oid' => $oid,
'type' => 0, 'type' => 4,
'status' => 1, 'status' => 1,
]; ];
//会员 //会员
@ -82,20 +79,20 @@ class CommissionProductLogic extends BaseLogic
'store_id' => $store_id, 'store_id' => $store_id,
'product_id' => $product_id, 'product_id' => $product_id,
'other_uid' => $uid, 'other_uid' => $uid,
'number' => bcmul($product['price'], $Distribution['user'], 4), 'number' => bcmul($product['price'], $Distribution['user'], 2),
'oid' => $oid, 'oid' => $oid,
'type' => 0, 'type' => 0,
'status' => 1, 'status' => 1,
]; ];
//个人店铺 //个人店铺
if($spread_uid>0){ if ($spread_uid > 0) {
$data[] = [ $data[] = [
'store_id' => $store_id, 'store_id' => $store_id,
'product_id' => $product_id, 'product_id' => $product_id,
'other_uid' => $uid, 'other_uid' => $uid,
'number' => bcmul($product['price'], $Distribution['person_store'], 4), 'number' => bcmul($product['price'], $Distribution['person_store'], 2),
'oid' => $oid, 'oid' => $oid,
'type' => 0, 'type' => 5,
'status' => 1, 'status' => 1,
]; ];
} }
@ -104,5 +101,4 @@ class CommissionProductLogic extends BaseLogic
} }
} }
} }
}
} }