diff --git a/app/common/logic/CommissionProductLogic.php b/app/common/logic/CommissionProductLogic.php index f49a95963..49a855793 100644 --- a/app/common/logic/CommissionProductLogic.php +++ b/app/common/logic/CommissionProductLogic.php @@ -21,120 +21,134 @@ class CommissionProductLogic extends BaseLogic { $product = StoreBranchProduct::where('store_id', $order['store_id'])->where('product_id', $find['product_id'])->find(); if ($product && $product['rose'] > 0) { + if(in_array($user_ship,[4, 6, 7])){ + $this->b($find, $order,$product); + return true; + } if ($product['rose'] >= 0 && $product['rose'] < 8) { - $rose = bcdiv($product['rose'], 100, 2); - $total_price = bcmul($product['purchase'], $find['cart_num']); - $commission = bcmul($total_price, $rose, 2); - - //供货价 - $total_cost = bcmul($product['cost'], $find['cart_num']); - $total = bcsub($total_cost, $total_price, 2); - $number = bcsub($total, $commission, 2); - if ($product['rose'] <= 4) { - //门店 - $data = [ - 'store_id' => $order['store_id'], - 'product_id' => $find['product_id'], - 'number' => $total, - 'oid' => $order['id'], - 'type' => 1, - 'status' => 1, - ]; - StoreFinanceFlowProduct::create($data); - } else { - //门店 - $data[] = [ - 'store_id' => $order['store_id'], - 'product_id' => $find['product_id'], - 'number' => $number, - 'oid' => $order['id'], - 'type' => 1, - 'status' => 1, - ]; - //平台 - $data[] = [ - 'store_id' => $order['store_id'], - 'product_id' => $find['product_id'], - 'number' => $commission, - 'oid' => $order['id'], - 'type' => 2, - 'status' => 1, - ]; - (new StoreFinanceFlowProduct())->saveAll($data); - } + $this->b($find, $order,$product); } elseif ($product['rose'] >= 8) { - $rose = bcdiv($product['rose'], 100, 2); - $total_price = bcmul($product['purchase'], $find['cart_num']); - $Distribution = Distribution::where('rate', $rose)->find(); - //门店 - $data[] = [ - 'store_id' => $order['store_id'], - 'product_id' => $find['product_id'], - 'number' => bcmul($total_price, $Distribution['store'], 2), - 'oid' => $order['id'], - 'type' => 1, - 'status' => 1, - ]; - //平台 - $data[] = [ - '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' => $order['store_id'], - 'product_id' => $find['product_id'], - 'other_uid' => $village_uid, - 'number' => bcmul($total_price, $Distribution['village'], 2), - 'oid' => $order['id'], - 'type' => 3, - 'status' => 1, - ]; - //队长 - $data[] = [ - 'store_id' => $order['store_id'], - 'product_id' => $find['product_id'], - 'other_uid' => $brigade_uid, - 'number' => bcmul($total_price, $Distribution['brigade'], 2), - 'oid' => $order['id'], - 'type' => 4, - 'status' => 1, - ]; - //会员 - if ($user_ship == 1) { - $uid = $order['spread_uid']; - } else { - $uid = 0; - } - $data[] = [ - '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' => $order['spread_uid'], - 'number' => bcmul($total_price, $Distribution['person_store'], 2), - 'oid' => $order['id'], - 'type' => 5, - 'status' => 1, - ]; - } - - (new StoreFinanceFlowProduct())->saveAll($data); + $this->a($find, $order, $village_uid, $brigade_uid, $user_ship, $product); } } } + + public function a($find, $order, $village_uid = 0, $brigade_uid = 0, $user_ship = 0, $product) + { + $rose = bcdiv($product['rose'], 100, 2); + $total_price = bcmul($product['purchase'], $find['cart_num']); + $Distribution = Distribution::where('rate', $rose)->find(); + //门店 + $data[] = [ + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], + 'number' => bcmul($total_price, $Distribution['store'], 2), + 'oid' => $order['id'], + 'type' => 1, + 'status' => 1, + ]; + //平台 + $data[] = [ + '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' => $order['store_id'], + 'product_id' => $find['product_id'], + 'other_uid' => $village_uid, + 'number' => bcmul($total_price, $Distribution['village'], 2), + 'oid' => $order['id'], + 'type' => 3, + 'status' => 1, + ]; + //队长 + $data[] = [ + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], + 'other_uid' => $brigade_uid, + 'number' => bcmul($total_price, $Distribution['brigade'], 2), + 'oid' => $order['id'], + 'type' => 4, + 'status' => 1, + ]; + //会员 + if ($user_ship == 1) { + $uid = $order['spread_uid']; + } else { + $uid = 0; + } + $data[] = [ + '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' => $order['spread_uid'], + 'number' => bcmul($total_price, $Distribution['person_store'], 2), + 'oid' => $order['id'], + 'type' => 5, + 'status' => 1, + ]; + } + + (new StoreFinanceFlowProduct())->saveAll($data); + } + + public function b($find, $order, $product) + { + $rose = bcdiv($product['rose'], 100, 2); + $total_price = bcmul($product['purchase'], $find['cart_num']); + $commission = bcmul($total_price, $rose, 2); + + //供货价 + $total_cost = bcmul($product['cost'], $find['cart_num']); + $total = bcsub($total_cost, $total_price, 2); + $number = bcsub($total, $commission, 2); + if ($product['rose'] <= 4) { + //门店 + $data = [ + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], + 'number' => $total, + 'oid' => $order['id'], + 'type' => 1, + 'status' => 1, + ]; + StoreFinanceFlowProduct::create($data); + } else { + //门店 + $data[] = [ + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], + 'number' => $number, + 'oid' => $order['id'], + 'type' => 1, + 'status' => 1, + ]; + //平台 + $data[] = [ + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], + 'number' => $commission, + 'oid' => $order['id'], + 'type' => 2, + 'status' => 1, + ]; + (new StoreFinanceFlowProduct())->saveAll($data); + } + } }