From d6dd96af8ced239574f98b3e6e1caf1491642814 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Wed, 18 Sep 2024 18:06:35 +0800 Subject: [PATCH 1/4] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=E5=95=86?= =?UTF-8?q?=E5=93=81=E6=B7=BB=E5=8A=A0=E5=92=8C=E7=BC=96=E8=BE=91=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../logic/store_product/StoreProductLogic.php | 85 ++-- .../logic/CommissionProductLogic copy.php | 375 ++++++++++++++++++ app/common/logic/CommissionnLogic.php | 50 --- 3 files changed, 421 insertions(+), 89 deletions(-) create mode 100644 app/common/logic/CommissionProductLogic copy.php diff --git a/app/admin/logic/store_product/StoreProductLogic.php b/app/admin/logic/store_product/StoreProductLogic.php index fd1bc707d..fddb50f2e 100644 --- a/app/admin/logic/store_product/StoreProductLogic.php +++ b/app/admin/logic/store_product/StoreProductLogic.php @@ -36,15 +36,15 @@ class StoreProductLogic extends BaseLogic */ public static function add(array $params): bool { - $count=count($params['cate_arr']); - $top_cate_id=0; - $two_cate_id=0; - if($count==3){ - $top_cate_id=$params['cate_arr'][0]; - $two_cate_id=$params['cate_arr'][1]; - }elseif($count==2){ - $top_cate_id=$params['cate_arr'][0]; - $two_cate_id=$params['cate_arr'][0]; + $count = count($params['cate_arr']); + $top_cate_id = 0; + $two_cate_id = 0; + if ($count == 3) { + $top_cate_id = $params['cate_arr'][0]; + $two_cate_id = $params['cate_arr'][1]; + } elseif ($count == 2) { + $top_cate_id = $params['cate_arr'][0]; + $two_cate_id = $params['cate_arr'][0]; } Db::startTrans(); try { @@ -62,7 +62,6 @@ class StoreProductLogic extends BaseLogic 'vip_price' => $params['vip_price'], 'cost' => $params['cost'], 'purchase' => $params['purchase'], - 'rose' => $params['rose'], 'is_return' => $params['is_return'], 'manufacturer_information' => $params['manufacturer_information'] ?? '', 'swap' => $params['swap'] ?? 0, @@ -71,12 +70,15 @@ class StoreProductLogic extends BaseLogic 'product_type' => $params['product_type'] ?? 0, 'is_show' => $params['is_show'] ?? 0, ]; - // if ($params['rose'] > 0) { - // $rose_price = bcmul($params['cost'], $params['rose'], 2); - // $data['price'] = bcadd($params['cost'], $rose_price, 2); - // } else { - // $data['price'] = 0; - // } + $rose = 0; + //零售-供货 + $rose_price = bcsub($params['price'], $params['purchase'], 2); + if ($rose_price > 0) { + //利润除于零售 + $price_div = bcdiv($rose_price, $params['price'], 2); + $rose=bcmul($price_div, 100, 2); + } + $data['rose']=$rose; $res = StoreProduct::create($data); StoreProductAttrValue::create([ "bar_code" => $params["bar_code"] ?? '', @@ -91,7 +93,7 @@ class StoreProductLogic extends BaseLogic 'sales' => 0, ]); Db::commit(); - if($data['product_type']==5){ + if ($data['product_type'] == 5) { return true; } if ($params['is_store_all'] == 1) { @@ -117,7 +119,7 @@ class StoreProductLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - throw new BusinessException('添加商品失败'.$e->getMessage()); + throw new BusinessException('添加商品失败' . $e->getMessage()); } } @@ -186,15 +188,15 @@ class StoreProductLogic extends BaseLogic { Db::startTrans(); try { - $count=count($params['cate_arr']); - $top_cate_id=0; - $two_cate_id=0; - if($count==3){ - $top_cate_id=$params['cate_arr'][0]; - $two_cate_id=$params['cate_arr'][1]; - }elseif($count==2){ - $top_cate_id=$params['cate_arr'][0]; - $two_cate_id=$params['cate_arr'][0]; + $count = count($params['cate_arr']); + $top_cate_id = 0; + $two_cate_id = 0; + if ($count == 3) { + $top_cate_id = $params['cate_arr'][0]; + $two_cate_id = $params['cate_arr'][1]; + } elseif ($count == 2) { + $top_cate_id = $params['cate_arr'][0]; + $two_cate_id = $params['cate_arr'][0]; } $data = [ 'store_name' => $params['store_name'], @@ -208,7 +210,6 @@ class StoreProductLogic extends BaseLogic 'stock' => $params['stock'], 'cost' => $params['cost'], 'purchase' => $params['purchase'], - 'rose' => $params['rose'], 'is_return' => $params['is_return'], 'price' => $params['price'], 'vip_price' => $params['vip_price'], @@ -218,12 +219,20 @@ class StoreProductLogic extends BaseLogic 'swap' => $params['swap'] ?? 0, 'is_show' => $params['is_show'] ?? 0, ]; - - StoreProduct::update($data,['id'=>$params['id']]); + $rose = 0; + //零售-供货 + $rose_price = bcsub($params['price'], $params['purchase'], 2); + if ($rose_price > 0) { + //利润除于零售 + $price_div = bcdiv($rose_price, $params['price'], 2); + $rose=bcmul($price_div, 100, 2); + } + $data['rose']=$rose; + StoreProduct::update($data, ['id' => $params['id']]); // $dealCate = self::dealChangeCate($params['cate_id']); //修改 - StoreBranchProduct::where('product_id', $params['id'])->whereNotIn('store_id',[17,18])->update([ + StoreBranchProduct::where('product_id', $params['id'])->whereNotIn('store_id', [17, 18])->update([ 'price' => $params['price'], 'vip_price' => $params['vip_price'], 'cost' => $params['cost'], @@ -238,7 +247,7 @@ class StoreProductLogic extends BaseLogic 'cate_id' => $params['cate_id'], 'bar_code' => $params['bar_code'], 'purchase' => $params['purchase'], - 'rose' => $params['rose'] ?? 0, + 'rose' => $rose, 'status' => $params['is_show'] ?? 0, 'image' => $params['image'], 'store_batch' => $params['store_batch'] ?? 1, @@ -249,8 +258,7 @@ class StoreProductLogic extends BaseLogic return true; } catch (\Throwable $e) { Db::rollback(); - throw new BusinessException('编辑商品失败'.$e->getMessage()); - + throw new BusinessException('编辑商品失败' . $e->getMessage()); } } @@ -309,8 +317,7 @@ class StoreProductLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - throw new BusinessException('删除失败'.$e->getMessage()); - + throw new BusinessException('删除失败' . $e->getMessage()); } } @@ -318,8 +325,8 @@ class StoreProductLogic extends BaseLogic /**普通 */ public static function ordinary($product_arr, $store_id, $admin_id, $find) { - $res=StoreBranchProduct::where('store_id',$store_id)->where('product_id',$find['id'])->find(); - if($res){ + $res = StoreBranchProduct::where('store_id', $store_id)->where('product_id', $find['id'])->find(); + if ($res) { return $res; } $dealCate = self::dealChangeCate($find['cate_id']); @@ -390,7 +397,7 @@ class StoreProductLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - throw new BusinessException('添加兑换商品失败'.$e->getMessage()); + throw new BusinessException('添加兑换商品失败' . $e->getMessage()); } } // else { diff --git a/app/common/logic/CommissionProductLogic copy.php b/app/common/logic/CommissionProductLogic copy.php new file mode 100644 index 000000000..68212629c --- /dev/null +++ b/app/common/logic/CommissionProductLogic copy.php @@ -0,0 +1,375 @@ +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) + { + $total_price = bcmul($product['price'], $find['cart_num'], 2); + $purchase_price = bcmul($product['purchase'], $find['cart_num'], 2); + $price = $product['purchase']; + + $platform_number = 0; //平台 + $attrition_number = 0; //损耗 + $store_number = 0; //门店 + $number1 = 0; //其他 + + + if ($product['rose'] >= 6) { + $platform_number = bcmul($total_price, 0.02, 2); //平台 + } + if ($product['rose'] >= 12) { + $attrition_number = bcmul($total_price, 0.01, 2); //损耗 + } + //零售-供货价 + $number3 = bcsub($total_price, $purchase_price, 2); + //会员 + $uid = 0; + if ($order['spread_uid'] > 0) { + $uid = $order['spread_uid']; + } + if ($order['uid'] > 0) { + $uid = $order['uid']; + } + $user = User::where('id', $uid)->find(); + + if ($user) { + if ($user['user_ship'] == 2) { + $village_number = bcmul($total_price, 0.04, 2); //村长利润 + $data[] = [ + 'nickname' => '零售村长', + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], + 'other_uid' => 0, + 'price' => $price, + 'total_price' => $total_price, + 'cart_num' => 0, + 'rate' => 0.04, + 'number' => $village_number, + 'oid' => $order['id'], + 'type' => 3, + 'status' => 1, + 'is_activity' => 0, + ]; + $number1 = bcadd($number1, $village_number, 2); + } elseif ($user['user_ship'] == 3) { + $brigade_number = bcmul($total_price, 0.04, 2); //队长利润 + $data[] = [ + 'nickname' => '零售队长', + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], + 'other_uid' => 0, + 'price' => $price, + 'total_price' => $total_price, + 'cart_num' => 0, + 'rate' => 0.04, + 'number' => $brigade_number, + 'oid' => $order['id'], + 'type' => 4, + 'status' => 1, + 'is_activity' => 0, + ]; + $number1 = bcadd($number1, $brigade_number, 2); + } elseif ($user['user_ship'] == 1) { + $vip_number = bcmul($total_price, 0.06, 2); //会员利润 + $data[] = [ + 'nickname' => '零售会员', + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], + 'other_uid' => $uid, + 'price' => $price, + 'total_price' => $purchase_price, + 'cart_num' => $find['cart_num'], + 'rate' => 0.06, + 'number' => $vip_number, + 'oid' => $order['id'], + 'type' => 0, + 'status' => 1, + ]; + $number1 = bcadd($number1, $vip_number, 2); + } + } + //门店利润 + if ($number3 <= 0) { + $store_number = 0; + } else { + $number2=bcadd($platform_number, $attrition_number, 2); + $store_number = bcsub($number3, bcadd($number1,$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, + 'number' => $store_number, + 'oid' => $order['id'], + 'type' => 1, + 'status' => 1, + 'is_activity' => 1, + ]; + //平台 + if ($product['rose'] >= 6) { + $data[] = [ + 'nickname' => '零售平台', + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], + 'other_uid' => 0, + 'price' => $price, + 'total_price' => $purchase_price, + 'cart_num' => $find['cart_num'], + 'rate' => 0.02, + 'number' => $platform_number, + 'oid' => $order['id'], + 'type' => 2, + 'status' => 1, + 'is_activity' => 1, + ]; + } + if ($product['rose'] >= 12) { + $data[] = [ + 'nickname' => '零售消耗', + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], + 'other_uid' => 0, + 'price' => $price, + 'total_price' => $purchase_price, + 'cart_num' => $find['cart_num'], + 'rate' => 0.01, + 'number' => $attrition_number, + 'oid' => $order['id'], + 'type' => 6, + 'status' => 1, + ]; + } + + (new StoreFinanceFlowProduct())->saveAll($data); + } + + /** + * 商户价结算 + */ + public function b($find, $order, $product, $user_ship) + { + $total_price = bcmul($product['price'], $find['cart_num'], 2); + $purchase_price = bcmul($product['purchase'], $find['cart_num'], 2); + $price = $product['purchase']; + + $platform_number = 0; + $attrition_number = 0; + if ($product['rose'] >= 6) { + $platform_number = bcmul($total_price, 0.02, 2); //平台 + } + if ($product['rose'] >= 10) { + $attrition_number = bcmul($total_price, 0.02, 2); //损耗 + } + + //零售-供货价 + $number3 = bcsub($total_price, $purchase_price, 2); + + + //门店利润 + if ($number3 <= 0) { + $store_number = 0; + } else { + $store_number = bcsub($number3, bcadd($platform_number, $attrition_number, 2), 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, + 'number' => $store_number, + 'oid' => $order['id'], + 'type' => 1, + 'status' => 1, + 'is_activity' => 1, + ]; + //平台 + if ($product['rose'] >= 6) { + $data[] = [ + 'nickname' => '商户价平台', + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], + 'other_uid' => 0, + 'price' => $price, + 'total_price' => $purchase_price, + 'cart_num' => $find['cart_num'], + 'rate' => 0.02, + 'number' => $platform_number, + 'oid' => $order['id'], + 'type' => 2, + 'status' => 1, + 'is_activity' => 1, + ]; + } + if ($product['rose'] >= 10) { + $data[] = [ + 'nickname' => '商户价消耗', + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], + 'other_uid' => 0, + 'price' => $price, + 'total_price' => $purchase_price, + 'cart_num' => $find['cart_num'], + 'rate' => 0.02, + 'number' => $attrition_number, + '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'], 2); + $purchase_price = bcmul($product['purchase'], $find['cart_num'], 2); + $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); + } +} diff --git a/app/common/logic/CommissionnLogic.php b/app/common/logic/CommissionnLogic.php index d3da5fd75..44b9ae9b1 100644 --- a/app/common/logic/CommissionnLogic.php +++ b/app/common/logic/CommissionnLogic.php @@ -10,56 +10,6 @@ use app\common\model\user\UserAddress; class CommissionnLogic extends BaseLogic { - /** - * 走村长分润 - */ - public static function setVillage($order, $village_uid = 0, $brigade_uid = 0, $transaction_id = 0) - { - self::user($order, 3, $transaction_id, $village_uid, 14); //村长 - self::user($order, 0, $transaction_id, 0, 12); //会员、厨师 - self::user($order, 5, $transaction_id, 0, 20); //个人店铺 - self::user($order, 4, $transaction_id, $brigade_uid, 15); //队长 - - self::platform($order, 2, $transaction_id); //平台 - self::store($order, 1, $transaction_id, 0); //门店 - // $attrition = self::attrition($order, 0.02, $transaction_id, 16); //损耗 - self::suppliter($order, $transaction_id); - } - /** - * 走队长分润 - */ - public static function setBrigade($order, $village_uid = 0, $brigade_uid = 0, $transaction_id = 0) - { - self::user($order, 4, $transaction_id, $brigade_uid, 15); //队长 - self::user($order, 0, $transaction_id, 0, 12); ////会员、厨师 - self::user($order, 5, $transaction_id, 0, 20); ////会员、厨师 - self::user($order, 3, $transaction_id, $village_uid, 14); //村长 - - self::platform($order, 2, $transaction_id); //平台 - self::store($order, 1, $transaction_id, 0); //门店 - // $attrition = self::attrition($order, 0.02, $transaction_id, 16); //损耗 - self::suppliter($order, $transaction_id); - } - /** - * 走厨师分润 - */ - public static function setCook($order, $village_uid = 0, $brigade_uid = 0, $transaction_id = 0) - { - if ($order['spread_uid'] <= 0) { - $uid = $order['uid']; - } else { - $uid = $order['spread_uid']; - } - self::user($order, 0, $transaction_id, $uid, 12); //会员、厨师 - self::user($order, 5, $transaction_id, $uid, 20); //会员、厨师 - self::user($order, 3, $transaction_id, $village_uid, 14); //村长 - self::user($order, 4, $transaction_id, $brigade_uid, 15); //队长 - self::platform($order, 2, $transaction_id); //平台 - self::store($order, 1, $transaction_id, 0); //门店 - // $attrition = self::attrition($order, 0.02, $transaction_id, 16); //损耗 - // $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); - } /** * 零售分润 From 756031dc1ff38a05ef39d8d63b005f7d505f81a9 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Wed, 18 Sep 2024 22:29:24 +0800 Subject: [PATCH 2/4] feat(CommissionProductLogic): deleted file, updated calculation logic for product commission --- ... copy.php => CommissionProductLogic22.php} | 400 +++++++++--------- 1 file changed, 189 insertions(+), 211 deletions(-) rename app/common/logic/{CommissionProductLogic copy.php => CommissionProductLogic22.php} (50%) diff --git a/app/common/logic/CommissionProductLogic copy.php b/app/common/logic/CommissionProductLogic22.php similarity index 50% rename from app/common/logic/CommissionProductLogic copy.php rename to app/common/logic/CommissionProductLogic22.php index 68212629c..f9ae6446e 100644 --- a/app/common/logic/CommissionProductLogic copy.php +++ b/app/common/logic/CommissionProductLogic22.php @@ -15,7 +15,7 @@ use support\Log; * 产品佣金计算 * */ -class CommissionProductLogic extends BaseLogic +class CommissionProductLogic22 extends BaseLogic { /** @@ -27,7 +27,7 @@ class CommissionProductLogic extends BaseLogic if ($product) { //活动商品 if ($product['product_type'] == 4) { - $this->c($find, $order, $village_uid, $brigade_uid, $user_ship, $product); + $this->c($find, $order, $product); return true; } else { //种养殖用户判断 @@ -36,19 +36,22 @@ class CommissionProductLogic extends BaseLogic if ($top_cate_id == 15189) { $this->b($find, $order, $product, $user_ship); return true; + }else{ + $this->a($find, $order, $village_uid, $brigade_uid, $user_ship, $product); + return true; } - } elseif ($user_ship == 0) { - //普通用户判断 + } elseif ($user_ship == 0||$user_ship == 4) { + //普通用户利润全部给门店 $this->b($find, $order, $product, $user_ship); return true; } else { //会员用户入口 $this->a($find, $order, $village_uid, $brigade_uid, $user_ship, $product); + return true; } } - - return true; } + return false; } /** @@ -58,7 +61,7 @@ class CommissionProductLogic extends BaseLogic { $total_price = bcmul($product['price'], $find['cart_num'], 2); $purchase_price = bcmul($product['purchase'], $find['cart_num'], 2); - $price = $product['purchase']; + $price = $product['price']; $platform_number = 0; //平台 $attrition_number = 0; //损耗 @@ -70,7 +73,7 @@ class CommissionProductLogic extends BaseLogic $platform_number = bcmul($total_price, 0.02, 2); //平台 } if ($product['rose'] >= 12) { - $attrition_number = bcmul($total_price, 0.01, 2); //损耗 + $attrition_number = bcmul($total_price, 0.02, 2); //损耗 } //零售-供货价 $number3 = bcsub($total_price, $purchase_price, 2); @@ -87,115 +90,52 @@ class CommissionProductLogic extends BaseLogic if ($user) { if ($user['user_ship'] == 2) { $village_number = bcmul($total_price, 0.04, 2); //村长利润 - $data[] = [ - 'nickname' => '零售村长', - 'store_id' => $order['store_id'], - 'product_id' => $find['product_id'], - 'other_uid' => 0, - 'price' => $price, - 'total_price' => $total_price, - 'cart_num' => 0, - 'rate' => 0.04, - 'number' => $village_number, - 'oid' => $order['id'], - 'type' => 3, - 'status' => 1, - 'is_activity' => 0, - ]; + $data[] =$this->village('零售村长', $order, $find, $village_uid, $price, $total_price, $village_number,0.04); $number1 = bcadd($number1, $village_number, 2); } elseif ($user['user_ship'] == 3) { $brigade_number = bcmul($total_price, 0.04, 2); //队长利润 - $data[] = [ - 'nickname' => '零售队长', - 'store_id' => $order['store_id'], - 'product_id' => $find['product_id'], - 'other_uid' => 0, - 'price' => $price, - 'total_price' => $total_price, - 'cart_num' => 0, - 'rate' => 0.04, - 'number' => $brigade_number, - 'oid' => $order['id'], - 'type' => 4, - 'status' => 1, - 'is_activity' => 0, - ]; + $data[] = $this->brigade('零售队长', $order, $find, $brigade_uid, $price, $total_price, $brigade_number,0.04); $number1 = bcadd($number1, $brigade_number, 2); + if ($product['rose'] >= 13 && $village_uid>0) { + $village_number = bcmul($total_price, 0.01, 2); //村长利润 + $data[] =$this->village('零售村长', $order, $find, $village_uid, $price, $total_price, $village_number,0.01); + $number1 = bcadd($number1, $village_number, 2); + } } elseif ($user['user_ship'] == 1) { $vip_number = bcmul($total_price, 0.06, 2); //会员利润 - $data[] = [ - 'nickname' => '零售会员', - 'store_id' => $order['store_id'], - 'product_id' => $find['product_id'], - 'other_uid' => $uid, - 'price' => $price, - 'total_price' => $purchase_price, - 'cart_num' => $find['cart_num'], - 'rate' => 0.06, - 'number' => $vip_number, - 'oid' => $order['id'], - 'type' => 0, - 'status' => 1, - ]; + $data[] = $this->vip_user('零售会员', $order, $find, $uid, $price, $total_price, $vip_number,0.06); $number1 = bcadd($number1, $vip_number, 2); + if ($product['rose'] >= 13 && $village_uid>0) { + $village_number = bcmul($total_price, 0.01, 2); //村长利润 + $data[] =$this->village('零售村长', $order, $find, $village_uid, $price, $total_price, $village_number,0.01); + $number1 = bcadd($number1, $village_number, 2); + } + if ($product['rose'] >= 14 && $brigade_uid>0) { + $brigade_number = bcmul($total_price, 0.01, 2); //队长利润 + $data[] =$this->village('零售队长', $order, $find, $village_uid, $price, $total_price, $brigade_number,0.01); + $number1 = bcadd($number1, $brigade_number, 2); + } } } //门店利润 if ($number3 <= 0) { $store_number = 0; } else { - $number2=bcadd($platform_number, $attrition_number, 2); - $store_number = bcsub($number3, bcadd($number1,$number2), 2); + $number2 = bcadd($platform_number, $attrition_number, 2); + $store_number = bcsub($number3, bcadd($number1, $number2,2), 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, - 'number' => $store_number, - 'oid' => $order['id'], - 'type' => 1, - 'status' => 1, - 'is_activity' => 1, - ]; + $rate=0; + if($store_number>0){ + $rate=bcdiv($store_number,$total_price,2); + } + $data[] =$this->store('零售门店', $order, $find, $price, $total_price,$store_number,$rate); //平台 if ($product['rose'] >= 6) { - $data[] = [ - 'nickname' => '零售平台', - 'store_id' => $order['store_id'], - 'product_id' => $find['product_id'], - 'other_uid' => 0, - 'price' => $price, - 'total_price' => $purchase_price, - 'cart_num' => $find['cart_num'], - 'rate' => 0.02, - 'number' => $platform_number, - 'oid' => $order['id'], - 'type' => 2, - 'status' => 1, - 'is_activity' => 1, - ]; + $data[] = $this->platform('零售平台', $order, $find, $price, $total_price,$platform_number); } if ($product['rose'] >= 12) { - $data[] = [ - 'nickname' => '零售消耗', - 'store_id' => $order['store_id'], - 'product_id' => $find['product_id'], - 'other_uid' => 0, - 'price' => $price, - 'total_price' => $purchase_price, - 'cart_num' => $find['cart_num'], - 'rate' => 0.01, - 'number' => $attrition_number, - 'oid' => $order['id'], - 'type' => 6, - 'status' => 1, - ]; + $data[] =$this->attrition('零售损耗', $order, $find, $price, $total_price,$attrition_number); } (new StoreFinanceFlowProduct())->saveAll($data); @@ -206,9 +146,9 @@ class CommissionProductLogic extends BaseLogic */ public function b($find, $order, $product, $user_ship) { - $total_price = bcmul($product['price'], $find['cart_num'], 2); + $total_price = bcmul($product['cost'], $find['cart_num'], 2); $purchase_price = bcmul($product['purchase'], $find['cart_num'], 2); - $price = $product['purchase']; + $price = $product['cost']; $platform_number = 0; $attrition_number = 0; @@ -218,7 +158,6 @@ class CommissionProductLogic extends BaseLogic if ($product['rose'] >= 10) { $attrition_number = bcmul($total_price, 0.02, 2); //损耗 } - //零售-供货价 $number3 = bcsub($total_price, $purchase_price, 2); @@ -230,146 +169,185 @@ class CommissionProductLogic extends BaseLogic $store_number = bcsub($number3, bcadd($platform_number, $attrition_number, 2), 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, - 'number' => $store_number, - 'oid' => $order['id'], - 'type' => 1, - 'status' => 1, - 'is_activity' => 1, - ]; + $rate=0; + if($store_number>0){ + $rate=bcdiv($store_number,$total_price,2); + } + $data[] =$this->store('商户价门店',$order,$find,$price,$total_price,$store_number,$rate); //平台 if ($product['rose'] >= 6) { - $data[] = [ - 'nickname' => '商户价平台', - 'store_id' => $order['store_id'], - 'product_id' => $find['product_id'], - 'other_uid' => 0, - 'price' => $price, - 'total_price' => $purchase_price, - 'cart_num' => $find['cart_num'], - 'rate' => 0.02, - 'number' => $platform_number, - 'oid' => $order['id'], - 'type' => 2, - 'status' => 1, - 'is_activity' => 1, - ]; + $data[] =$this->platform('商户价平台',$order,$find,$price,$total_price,$platform_number); } - if ($product['rose'] >= 10) { - $data[] = [ - 'nickname' => '商户价消耗', - 'store_id' => $order['store_id'], - 'product_id' => $find['product_id'], - 'other_uid' => 0, - 'price' => $price, - 'total_price' => $purchase_price, - 'cart_num' => $find['cart_num'], - 'rate' => 0.02, - 'number' => $attrition_number, - 'oid' => $order['id'], - 'type' => 6, - 'status' => 1, - ]; + if ($product['rose'] >= 12) { + $data[] = $this->attrition('商户价损耗',$order,$find,$price,$total_price,$attrition_number); } (new StoreFinanceFlowProduct())->saveAll($data); } //活动商品结算 - public function c($find, $order, $village_uid, $brigade_uid, $user_ship, $product) + public function c($find, $order,$product) { - // $rose = bcdiv($product['rose'], 100, 2); $total_price = bcmul($product['price'], $find['cart_num'], 2); $purchase_price = bcmul($product['purchase'], $find['cart_num'], 2); - $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); + $price = $product['purchase']; + $platform_number = 0; + $attrition_number = 0; + if ($product['rose'] >= 6) { + $platform_number = bcmul($total_price, 0.02, 2); //平台 + } //零售-供货价 $number3 = bcsub($total_price, $purchase_price, 2); + //门店利润 if ($number3 <= 0) { $store_number = 0; } else { - $store_number = bcsub($number3, $number2, 2); + $store_number = bcsub($number3, bcadd($platform_number, $attrition_number, 2), 2); } + //门店 + $rate=0; + if($store_number>0){ + $rate=bcdiv($store_number,$total_price,2); + } + $data[] =$this->store('商户价门店',$order,$find,$price,$total_price,$store_number,$rate,1); + //平台 + if ($product['rose'] >= 6) { + $data[] =$this->platform('商户价平台',$order,$find,$price,$total_price,$platform_number,1); + } + (new StoreFinanceFlowProduct())->saveAll($data); + } - //队长 - $data[] = [ - 'nickname' => '活动队长', + /** + * 村长 + */ + public function village($name, $order, $find, $other_uid, $price, $total_price, $number, $rate = 0.01, $is_activity = 0) + { + $data = [ + 'nickname' => $name, 'store_id' => $order['store_id'], 'product_id' => $find['product_id'], - 'other_uid' => $brigade_uid, + 'other_uid' => $other_uid, + 'price' => $price, + 'total_price' => $total_price, + 'cart_num' => 0, + 'rate' => $rate, + 'number' => $number, + 'oid' => $order['id'], + 'type' => 3, + 'status' => 1, + 'is_activity' => $is_activity, + ]; + return $data; + } + /** + * 队长 + */ + public function brigade($name, $order, $find, $other_uid, $price, $total_price, $number, $rate = 0.01, $is_activity = 0) + { + $data = [ + 'nickname' => $name, + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], + 'other_uid' => $other_uid, + 'price' => $price, + 'total_price' => $total_price, + 'cart_num' => $find['cart_num'], + 'rate' => $rate, + 'number' => $number, + 'oid' => $order['id'], + 'type' => 4, + 'status' => 1, + 'is_activity' => $is_activity, + ]; + return $data; + } + /** + * 平台 + */ + public function platform($name, $order, $find, $price, $total_price, $number, $is_activity = 0) + { + $data = [ + 'nickname' => $name, + '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' => $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, + 'number' => $number, 'oid' => $order['id'], 'type' => 2, 'status' => 1, - 'is_activity' => 1, + 'is_activity' => $is_activity, ]; - (new StoreFinanceFlowProduct())->saveAll($data); + return $data; + } + /** + * 门店 + */ + public function store($name, $order, $find, $price, $total_price, $number,$rate = 0.05, $is_activity = 0) + { + $data = [ + 'nickname' => $name, + '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' => $rate, + 'number' => $number, + 'oid' => $order['id'], + 'type' => 1, + 'status' => 1, + 'is_activity' => $is_activity, + ]; + return $data; + } + /** + * 损耗 + */ + public function attrition($name, $order, $find, $price, $total_price, $number, $is_activity = 0) + { + $data = [ + 'nickname' => $name, + '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' => $number, + 'oid' => $order['id'], + 'type' => 6, + 'status' => 1, + 'is_activity' => $is_activity, + ]; + return $data; + } + + /** + * 会员 + */ + public function vip_user($name, $order, $find, $other_uid,$price, $total_price, $number,$rate = 0.06, $is_activity = 0){ + $data = [ + 'nickname' => $name, + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], + 'other_uid' => $other_uid, + 'price' => $price, + 'total_price' => $total_price, + 'cart_num' => $find['cart_num'], + 'rate' => $rate, + 'number' => $number, + 'oid' => $order['id'], + 'type' => 0, + 'status' => $is_activity, + ]; + return $data; } } From 3e794f47a24e787256980831ae83a2871dc51a47 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Thu, 19 Sep 2024 09:42:11 +0800 Subject: [PATCH 3/4] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E8=B5=84?= =?UTF-8?q?=E9=87=91=E6=B5=81=E5=90=91=E6=A8=A1=E5=9E=8B=E8=BD=AF=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/model/finance/CapitalFlow.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/common/model/finance/CapitalFlow.php b/app/common/model/finance/CapitalFlow.php index 08d68441c..c21929d67 100644 --- a/app/common/model/finance/CapitalFlow.php +++ b/app/common/model/finance/CapitalFlow.php @@ -3,8 +3,11 @@ namespace app\common\model\finance; use app\common\model\BaseModel; +use think\model\concern\SoftDelete; class CapitalFlow extends BaseModel { + use SoftDelete; + protected $deleteTime = 'delete_time'; } From 88c9fd557cb1dd3d6a3a5dbdd80012d966f54e18 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Thu, 19 Sep 2024 11:17:27 +0800 Subject: [PATCH 4/4] =?UTF-8?q?feat:=20=E8=B0=83=E6=95=B4=E4=BA=86?= =?UTF-8?q?=E5=95=86=E5=93=81=E4=BD=A3=E9=87=91=E8=AE=A1=E7=AE=97=E9=80=BB?= =?UTF-8?q?=E8=BE=91=EF=BC=8C=E5=A2=9E=E5=8A=A0=E4=BA=86=E6=8D=9F=E8=80=97?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=EF=BC=8C=E5=B9=B6=E6=9B=B4=E6=96=B0=E4=BA=86?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E6=95=B0=E6=8D=AE=E5=BA=93=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/logic/CommissionProductLogic22.php | 22 ++++++++++++------- .../StoreCashFinanceFlowLists.php | 2 +- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/app/common/logic/CommissionProductLogic22.php b/app/common/logic/CommissionProductLogic22.php index f9ae6446e..46a95dca2 100644 --- a/app/common/logic/CommissionProductLogic22.php +++ b/app/common/logic/CommissionProductLogic22.php @@ -72,9 +72,6 @@ class CommissionProductLogic22 extends BaseLogic if ($product['rose'] >= 6) { $platform_number = bcmul($total_price, 0.02, 2); //平台 } - if ($product['rose'] >= 12) { - $attrition_number = bcmul($total_price, 0.02, 2); //损耗 - } //零售-供货价 $number3 = bcsub($total_price, $purchase_price, 2); //会员 @@ -92,20 +89,28 @@ class CommissionProductLogic22 extends BaseLogic $village_number = bcmul($total_price, 0.04, 2); //村长利润 $data[] =$this->village('零售村长', $order, $find, $village_uid, $price, $total_price, $village_number,0.04); $number1 = bcadd($number1, $village_number, 2); + if ($product['rose'] >= 12) { + $attrition_number = bcmul($total_price, 0.02, 2); //损耗 + $data[] =$this->attrition('零售损耗', $order, $find, $price, $total_price,$attrition_number); + } } elseif ($user['user_ship'] == 3) { $brigade_number = bcmul($total_price, 0.04, 2); //队长利润 $data[] = $this->brigade('零售队长', $order, $find, $brigade_uid, $price, $total_price, $brigade_number,0.04); $number1 = bcadd($number1, $brigade_number, 2); - if ($product['rose'] >= 13 && $village_uid>0) { + if ($product['rose'] >= 12 && $village_uid>0) { $village_number = bcmul($total_price, 0.01, 2); //村长利润 $data[] =$this->village('零售村长', $order, $find, $village_uid, $price, $total_price, $village_number,0.01); $number1 = bcadd($number1, $village_number, 2); } + if ($product['rose'] >= 15) { + $attrition_number = bcmul($total_price, 0.02, 2); //损耗 + $data[] =$this->attrition('零售损耗', $order, $find, $price, $total_price,$attrition_number); + } } elseif ($user['user_ship'] == 1) { $vip_number = bcmul($total_price, 0.06, 2); //会员利润 $data[] = $this->vip_user('零售会员', $order, $find, $uid, $price, $total_price, $vip_number,0.06); $number1 = bcadd($number1, $vip_number, 2); - if ($product['rose'] >= 13 && $village_uid>0) { + if ($product['rose'] >= 12 && $village_uid>0) { $village_number = bcmul($total_price, 0.01, 2); //村长利润 $data[] =$this->village('零售村长', $order, $find, $village_uid, $price, $total_price, $village_number,0.01); $number1 = bcadd($number1, $village_number, 2); @@ -115,6 +120,10 @@ class CommissionProductLogic22 extends BaseLogic $data[] =$this->village('零售队长', $order, $find, $village_uid, $price, $total_price, $brigade_number,0.01); $number1 = bcadd($number1, $brigade_number, 2); } + if ($product['rose'] >= 15) { + $attrition_number = bcmul($total_price, 0.02, 2); //损耗 + $data[] =$this->attrition('零售损耗', $order, $find, $price, $total_price,$attrition_number); + } } } //门店利润 @@ -134,9 +143,6 @@ class CommissionProductLogic22 extends BaseLogic if ($product['rose'] >= 6) { $data[] = $this->platform('零售平台', $order, $find, $price, $total_price,$platform_number); } - if ($product['rose'] >= 12) { - $data[] =$this->attrition('零售损耗', $order, $find, $price, $total_price,$attrition_number); - } (new StoreFinanceFlowProduct())->saveAll($data); } diff --git a/app/store/lists/store_cash_finance_flow/StoreCashFinanceFlowLists.php b/app/store/lists/store_cash_finance_flow/StoreCashFinanceFlowLists.php index a1d1ff1a5..9681a66a6 100644 --- a/app/store/lists/store_cash_finance_flow/StoreCashFinanceFlowLists.php +++ b/app/store/lists/store_cash_finance_flow/StoreCashFinanceFlowLists.php @@ -45,7 +45,7 @@ class StoreCashFinanceFlowLists extends BaseAdminDataLists implements ListsSearc { $this->searchWhere[]=['store_id','=',$this->adminInfo['store_id']]; return StoreCashFinanceFlow::where($this->searchWhere) - ->field(['id', 'store_id', 'cash_price', 'receivable', 'receipts', 'admin_id', 'file', 'remark', 'status']) + ->field(['id', 'store_id', 'cash_price', 'receivable', 'receipts', 'admin_id', 'file','create_time', 'remark', 'status']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->select()->each(function ($item) {