diff --git a/app/common/logic/CommissionProductLogic.php b/app/common/logic/CommissionProductLogic.php index d580dc0a..ab1597fe 100644 --- a/app/common/logic/CommissionProductLogic.php +++ b/app/common/logic/CommissionProductLogic.php @@ -17,82 +17,87 @@ class CommissionProductLogic extends BaseLogic /** * 根据毛利率计算 */ - function calculate_product_flow($find,$oid, $store_id, $product_id, $village_uid = 0, $brigade_uid = 0, $uid = 0, $spread_uid = 0) + function calculate_product_flow($find, $order, $village_uid = 0, $brigade_uid = 0, $user_ship = 0) { - $product = StoreBranchProduct::where('store_id', $store_id)->where('product_id', $product_id)->find(); + $product = StoreBranchProduct::where('store_id', $order['store_id'])->where('product_id', $find['product_id'])->find(); if ($product && $product['rose'] > 0) { + if ($order['spread_uid'] > 0) { + $uid = $order['spread_uid']; + } if ($product['rose'] >= 4 && $product['rose'] < 8) { $rose = bcdiv($product['rose'], 100, 2); - $total_price=bcmul($product['purchase'],$find['cart_num']); + $total_price = bcmul($product['purchase'], $find['cart_num']); $commission = bcmul($total_price, $rose, 2); StoreFinanceFlowProduct::create([ - 'store_id' => $store_id, - 'product_id' => $product_id, + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], 'number' => $commission, - 'oid' => $oid, + 'oid' => $order['id'], 'type' => 2, 'status' => 1, ]); } elseif ($product['rose'] >= 8) { $rose = bcdiv($product['rose'], 100, 2); - $total_price=bcmul($product['purchase'],$find['cart_num']); + $total_price = bcmul($product['purchase'], $find['cart_num']); $Distribution = Distribution::where('rate', $rose)->find(); //门店 $data[] = [ - 'store_id' => $store_id, - 'product_id' => $product_id, + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], 'number' => bcmul($total_price, $Distribution['store'], 2), - 'oid' => $oid, + 'oid' => $order['id'], 'type' => 1, 'status' => 1, ]; //平台 $data[] = [ - 'store_id' => $store_id, - 'product_id' => $product_id, - 'number' => bcmul($total_price, $Distribution['platform'],2), - 'oid' => $oid, + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], + 'number' => bcmul($total_price, $Distribution['platform'], 2), + 'oid' => $order['id'], 'type' => 2, 'status' => 1, ]; //村长 $data[] = [ - 'store_id' => $store_id, - 'product_id' => $product_id, + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], 'other_uid' => $village_uid, 'number' => bcmul($total_price, $Distribution['village'], 2), - 'oid' => $oid, + 'oid' => $order['id'], 'type' => 3, 'status' => 1, ]; //队长 $data[] = [ - 'store_id' => $store_id, - 'product_id' => $product_id, + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], 'other_uid' => $brigade_uid, 'number' => bcmul($total_price, $Distribution['brigade'], 2), - 'oid' => $oid, + 'oid' => $order['id'], 'type' => 4, 'status' => 1, ]; //会员 - $data[] = [ - 'store_id' => $store_id, - 'product_id' => $product_id, - 'other_uid' => $uid, - 'number' => bcmul($total_price, $Distribution['user'], 2), - 'oid' => $oid, - 'type' => 0, - 'status' => 1, - ]; - //个人店铺 - if ($spread_uid > 0) { + if ($user_ship == 1) { $data[] = [ - 'store_id' => $store_id, - 'product_id' => $product_id, + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], + 'other_uid' => $uid, + 'number' => bcmul($total_price, $Distribution['user'], 2), + 'oid' => $order['id'], + 'type' => 0, + 'status' => 1, + ]; + } + //个人店铺 + if ($order['spread_uid'] > 0) { + $data[] = [ + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], 'other_uid' => $uid, 'number' => bcmul($total_price, $Distribution['person_store'], 2), - 'oid' => $oid, + 'oid' => $order['id'], 'type' => 5, 'status' => 1, ]; diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php index eaef64e9..098835c7 100644 --- a/app/common/logic/PayNotifyLogic.php +++ b/app/common/logic/PayNotifyLogic.php @@ -646,7 +646,7 @@ class PayNotifyLogic extends BaseLogic $info = StoreOrderCartInfo::where('oid', $order['id'])->field('store_id,product_id,cart_num')->select(); $comm = new CommissionProductLogic(); foreach ($info as $v) { - $comm->calculate_product_flow($v, $order['id'], $order['store_id'], $v['product_id'], $village_uid, $brigade_uid, $order['uid'], $order['spread_uid']); + $comm->calculate_product_flow($v, $order, $village_uid, $brigade_uid,$user_ship); } CommissionLogic::setStore($order,$village_uid, $brigade_uid, $transaction_id); return true;