diff --git a/app/common/logic/CommissionProductLogic.php b/app/common/logic/CommissionProductLogic.php index f6e1688f8..ea3f3ab53 100644 --- a/app/common/logic/CommissionProductLogic.php +++ b/app/common/logic/CommissionProductLogic.php @@ -193,27 +193,31 @@ class CommissionProductLogic extends BaseLogic */ 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']; - //门店 + $total_price = bcmul($product['price'], $find['cart_num']); + $purchase_price = bcmul($product['purchase'], $find['cart_num']); + $price=$product['purchase']; + + $brigade_number = bcmul($purchase_price, 0.02, 2);//队长 + $village_number = bcmul($brigade_number, 0.1, 2);//村长 + $platform_number = bcmul($purchase_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' => 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' => '平台', + 'nickname' => '商户价队长预留', 'store_id' => $order['store_id'], 'product_id' => $find['product_id'], 'other_uid' => 0, @@ -221,11 +225,61 @@ class CommissionProductLogic extends BaseLogic 'total_price' => $total_price, 'cart_num' => $find['cart_num'], 'rate' => 0.02, - 'number' => bcmul($total_price, 0.02, 2), + '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' => 0, + '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, ]; + $data[] = [ 'nickname' => '消耗', 'store_id' => $order['store_id'], diff --git a/app/common/logic/store_order/StoreOrderLogic.php b/app/common/logic/store_order/StoreOrderLogic.php index b3f84aaf8..1141ae14d 100644 --- a/app/common/logic/store_order/StoreOrderLogic.php +++ b/app/common/logic/store_order/StoreOrderLogic.php @@ -48,7 +48,6 @@ class StoreOrderLogic extends BaseLogic $cart_select = Cart::whereIn('id', $cartId)->where($where)->field('id,product_id,cart_num')->select()->toArray(); if (empty($cart_select)) { throw new BusinessException('购物车为空'); - return false; } try { self::$total_price = 0; @@ -238,7 +237,7 @@ class StoreOrderLogic extends BaseLogic $query->field(['id', 'oid', 'product_id', 'cart_info']); }])->where($params)->find(); if (empty($order)) { - throw new \Exception('订单不存在'); + throw new BusinessException('订单不存在'); } $order['pay_time'] = $order['pay_time'] > 0 ? date('Y-m-d H:i:s', $order['pay_time']) : ''; $order['status_name'] = OrderEnum::getOrderType($order['status']) ?? ''; @@ -372,7 +371,7 @@ class StoreOrderLogic extends BaseLogic return false; } catch (Exception $e) { \support\Log::info($e->extra['message'] ?? $e->getMessage()); - throw new \Exception($e->extra['message'] ?? $e->getMessage()); + throw new BusinessException($e->getMessage()); } } @@ -383,7 +382,7 @@ class StoreOrderLogic extends BaseLogic $code = generateRandomCode(); $phone = User::where('id',$param['uid'])->value('mobile'); if(empty($phone)){ - throw new \Exception('用户未设置手机号'); + throw new BusinessException('用户未设置手机号'); } $template = getenv('SMS_TEMPLATE'); $check =(new SmsService())->client($phone,$template,$code);