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 = $product['top_cate_id']; if ($top_cate_id == 15189) { $this->b($find, $order, $product,$user_ship); return true; } } 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; } } /** * 零售价结算 */ 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']); $price=$product['cost']; }else{ $total_price = bcmul($product['price'], $find['cart_num']); $price=$product['price']; } // $Distribution = Distribution::where('rate', $rose)->find(); //门店 $data[] = [ 'nickname' => '门店', 'store_id' => $order['store_id'], 'product_id' => $find['product_id'], 'other_uid' => 0, 'price' => $price, 'total_price' => $total_price, 'cart_num' => $find['cart_num'], 'rate' => 0.05, 'number' => bcmul($total_price, 0.05, 2), 'oid' => $order['id'], 'type' => 1, 'status' => 1, ]; //平台 $data[] = [ 'nickname' => '平台', 'store_id' => $order['store_id'], 'product_id' => $find['product_id'], 'other_uid' => 0, 'price' => $price, 'total_price' => $total_price, 'cart_num' => $find['cart_num'], 'rate' => 0.02, 'number' => bcmul($total_price, 0.02, 2), 'oid' => $order['id'], 'type' => 2, 'status' => 1, ]; //村长 $data[] = [ 'nickname' => '村长', 'store_id' => $order['store_id'], 'product_id' => $find['product_id'], 'price' => $price, 'other_uid' => $village_uid, 'total_price' => $total_price, 'cart_num' => $find['cart_num'], 'rate' => 0.01, 'number' => bcmul($total_price, 0.01, 2), 'oid' => $order['id'], 'type' => 3, 'status' => 1, ]; //队长 $data[] = [ 'nickname' => '队长', 'store_id' => $order['store_id'], 'product_id' => $find['product_id'], 'price' => $price, 'other_uid' => $brigade_uid, 'total_price' => $total_price, 'cart_num' => $find['cart_num'], 'rate' => 0.01, 'number' => bcmul($total_price, 0.01, 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 ||$user_ship>0) { if (in_array($user_ship, [2, 3])) { $data[] = [ 'nickname' => '会员', 'store_id' => $order['store_id'], 'product_id' => $find['product_id'], 'price' => $price, 'other_uid' => $order['spread_uid'], 'total_price' => $total_price, 'cart_num' => $find['cart_num'], 'rate' => 0.05, 'number' => bcmul($total_price, 0.05, 2), 'oid' => $order['id'], 'type' => 0, 'status' => 1, ]; } else { $data[] = [ 'nickname' => '会员', 'store_id' => $order['store_id'], 'product_id' => $find['product_id'], 'other_uid' => $order['spread_uid'], 'price' => $price, 'total_price' => $total_price, 'cart_num' => $find['cart_num'], 'rate' => 0.07, 'number' => bcmul($total_price, 0.07, 2), 'oid' => $order['id'], 'type' => 0, 'status' => 1, ]; } } $data[] = [ 'nickname' => '消耗', 'store_id' => $order['store_id'], 'product_id' => $find['product_id'], 'other_uid' => 0, 'price' => $price, 'total_price' => $total_price, 'cart_num' => $find['cart_num'], 'rate' => 0.01, 'number' => bcmul($total_price, 0.01, 2), 'oid' => $order['id'], 'type' => 6, 'status' => 1, ]; (new StoreFinanceFlowProduct())->saveAll($data); } /** * 商户价结算 */ public function b($find, $order, $product,$user_ship) { // $rose = bcdiv($product['rose'], 100, 2); $total_price = bcmul($product['cost'], $find['cart_num']); $price = $product['cost']; //门店 $data[] = [ 'nickname' => '门店', 'store_id' => $order['store_id'], 'product_id' => $find['product_id'], 'other_uid' => 0, 'price' => $price, 'total_price' => $total_price, 'cart_num' => $find['cart_num'], 'rate' => 0.05, 'number' => bcmul($total_price, 0.05, 2), 'oid' => $order['id'], 'type' => 1, 'status' => 1, ]; //平台 $data[] = [ 'nickname' => '平台', 'store_id' => $order['store_id'], 'product_id' => $find['product_id'], 'other_uid' => 0, 'price' => $price, 'total_price' => $total_price, 'cart_num' => $find['cart_num'], 'rate' => 0.02, 'number' => bcmul($total_price, 0.02, 2), 'oid' => $order['id'], 'type' => 2, 'status' => 1, ]; $data[] = [ 'nickname' => '消耗', 'store_id' => $order['store_id'], 'product_id' => $find['product_id'], 'other_uid' => 0, 'price' => $price, 'total_price' => $total_price, 'cart_num' => $find['cart_num'], 'rate' => 0.01, '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']); $price=$product['price']; $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); //门店利润 if($number3<=0){ $store_number = 0; }else{ $store_number = bcsub($number3, $number2, 2); } //队长 $data[] = [ 'nickname' => '活动队长', 'store_id' => $order['store_id'], 'product_id' => $find['product_id'], 'other_uid' => $brigade_uid, 'price' => $price, 'total_price' => $total_price, 'cart_num' => $find['cart_num'], 'rate' => 0.02, 'number' => $brigade_number, 'oid' => $order['id'], 'type' => 4, 'status' => 1, 'is_activity' => 1, ]; //村长 $data[] = [ 'nickname' => '活动村长', 'store_id' => $order['store_id'], 'product_id' => $find['product_id'], 'other_uid' => $village_uid, 'price' => $price, 'total_price' => $brigade_number, 'cart_num' => 0, 'rate' => 0.01, 'number' => $village_number, 'oid' => $order['id'], 'type' => 3, 'status' => 1, 'is_activity' => 1, ]; //门店 $data[] = [ 'nickname' => '活动门店', 'store_id' => $order['store_id'], 'product_id' => $find['product_id'], 'other_uid' => 0, 'price' => $price, 'total_price' => $store_number, 'cart_num' => $find['cart_num'], 'rate' => 0, 'number' => $store_number, 'oid' => $order['id'], 'type' => 1, 'status' => 1, 'is_activity' => 1, ]; //平台 $data[] = [ 'nickname' => '活动平台', 'store_id' => $order['store_id'], 'product_id' => $find['product_id'], 'other_uid' => 0, 'price' => $price, 'total_price' => $platform_number, 'cart_num' => $find['cart_num'], 'rate' => 0.02, 'number' => $platform_number, 'oid' => $order['id'], 'type' => 2, 'status' => 1, 'is_activity' => 1, ]; (new StoreFinanceFlowProduct())->saveAll($data); } }