From 14dae9023761942bcc2a62dd16aba815ad24bec4 Mon Sep 17 00:00:00 2001 From: lqmac Date: Thu, 29 Feb 2024 00:37:47 +0800 Subject: [PATCH 1/3] 1 --- app/api/controller/Store.php | 51 ++++++++++++-------------- app/common/model/PriceSet.php | 69 +++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+), 27 deletions(-) diff --git a/app/api/controller/Store.php b/app/api/controller/Store.php index 93d22a2e..daa2844d 100644 --- a/app/api/controller/Store.php +++ b/app/api/controller/Store.php @@ -139,20 +139,25 @@ class Store extends Controller PriceSet::where('store_id', $storeid)->where('type', $params['type']??0)->delete(); $inDatas = []; foreach ($params['list'] as $value) { - foreach ($value['price_list'] as $price) { - $temp = [ - 'category' => $value['category'], - 'store_id' => $storeid, - 'type' => $params['type'], - 'min' => $price['min'], - 'max' => $price['max'], - 'add_price_rate' => $price['add_price_rate'], - 'create_time' => time(), - 'update_time' => time(), - ]; - $inDatas[] = $temp; + $categorys = explode(",", $value['category']); + foreach ($categorys as $category) { + foreach ($value['price_list'] as $price) { + $temp = [ + 'category' => $value['category'], + 'code' => $category, + 'store_id' => $storeid, + 'type' => $params['type'], + 'min' => $price['min'], + 'max' => $price['max'], + 'add_price_rate' => $price['add_price_rate'], + 'create_time' => time(), + 'update_time' => time(), + ]; + $inDatas[] = $temp; + } } + } // echo "
";
         // print_r($inDatas);
@@ -165,7 +170,7 @@ class Store extends Controller
     public function getStorePriceInfo(int $type): Json
     {
         $storeid = request()->header()['storeid'];
-        $list = PriceSet::where('store_id',$storeid)->where('type', $params['type'] ?? 0)->field('category,min,max,add_price_rate')->select()->toArray();
+        $list = PriceSet::where('store_id',$storeid)->where('type', $params['type'] ?? 0)->field('category,code,min,max,add_price_rate')->group("category, min")->select()->toArray();
         $data = [];
         $arr = [];
         foreach ($list as $value) {
@@ -185,20 +190,12 @@ class Store extends Controller
     public function test(int $type): Json
     {
         $storeid = request()->header()['storeid'];
-        $list = PriceSet::where('store_id',$storeid)->where('type', $params['type'] ?? 0)->field('category,min,max,add_price_rate')->select()->toArray();
-        $data = [];
-        $arr = [];
-        foreach ($list as $value) {
-            $arr[$value['category']][] = $value;
-        }
-        foreach ($arr as $key => $item) {
-            $data['list'][] = [
-                'category' => $key,
-                'price_list' => $item,
-            ];
-        }
-        $data['type'] = $type;
-        return $this->renderSuccess($data);
+
+        $categoryIds = [1001,1002];
+        $list = PriceSet::distributionPrice(90, 50, $categoryIds);
+        
+        
+        return $this->renderSuccess($list);
     }
 
 
diff --git a/app/common/model/PriceSet.php b/app/common/model/PriceSet.php
index bf2766e4..b833a40c 100644
--- a/app/common/model/PriceSet.php
+++ b/app/common/model/PriceSet.php
@@ -28,4 +28,73 @@ class PriceSet extends BaseModel
     // 定义主键
     protected $pk = 'id';
 
+    /**
+     * 会员价
+     * [membershipPrice description]
+     * @param  [type] $market_price [description]
+     * @param  [type] $cost_price   [description]
+     * @param  [type] $category_ids [description]
+     * @return [type]               [description]
+     */
+    public static function membershipPrice($market_price, $cost_price, $category_ids){
+        $addPriceRate = self::getAddPriceRate(0, $category_ids, $cost_price);
+        $membershipPrice = $cost_price * (1 + $addPriceRate * 0.01);
+        //当加价率生效后,会员价高于市场价
+        if ($membershipPrice > $market_price) {
+            $membershipPrice = ($market_price - $cost_price) * $addPriceRate * 0.01 + $cost_price;
+            
+        }
+        return sprintf("%.2f", $membershipPrice);
+        
+    }
+    /**
+     * 分销价
+     * [distributionPrice description]
+     * @param  [type] $market_price [description]
+     * @param  [type] $cost_price   [description]
+     * @param  [type] $type         [description]
+     * @param  [type] $category_ids [description]
+     * @return [type]               [description]
+     */
+    public static function distributionPrice($market_price, $cost_price, $category_ids){
+        //会员价
+        $membershipPrice = self::membershipPrice($market_price, $cost_price, $category_ids);
+        //分销价
+        $addPriceRate = self::getAddPriceRate(1, $category_ids, $cost_price);
+        $distributionPrice = $cost_price * (1 + $addPriceRate * 0.01);
+        $price = $distributionPrice;
+        //当加价率生效后,分销价高于市场价
+        if ($distributionPrice > $market_price) {
+            $price = ($market_price - $cost_price) * $addPriceRate * 0.01 + $cost_price;
+        }
+        //当加价率生效后,分销价高于会员价
+        if ($distributionPrice > $membershipPrice) {
+            $price = ($membershipPrice - $cost_price) * $addPriceRate * 0.01 + $cost_price;
+        }
+        return sprintf("%.2f", $price);
+    }
+
+
+    /**
+     * 获取商品加价率
+     * [getAddPriceRate description]
+     * @param  [type] $store_id     [description]
+     * @param  [type] $type         [description]
+     * @param  [type] $category_ids [description]
+     * @param  [type] $goods_price  [description]
+     * @return [type]               [description]
+     */
+    public static function getAddPriceRate($type, $category_ids, $cost_price){
+        $info = static::where('type',$type)
+            ->whereIn('code', $category_ids)
+            ->where('min', '<=', $cost_price)
+            ->where('max', '>', $cost_price)
+            ->order('id desc')
+            ->column('add_price_rate');
+        if (!$info) {
+            return 0;
+        }
+        
+        return $info[0];
+    }
 }

From 0d5b8e8631c2342f1b1d7b97ed1c571434626269 Mon Sep 17 00:00:00 2001
From: lqmac 
Date: Thu, 29 Feb 2024 00:44:33 +0800
Subject: [PATCH 2/3] 1

---
 app/api/model/dealer/Order.php | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/app/api/model/dealer/Order.php b/app/api/model/dealer/Order.php
index 1e9a5ca5..43ebd092 100644
--- a/app/api/model/dealer/Order.php
+++ b/app/api/model/dealer/Order.php
@@ -75,9 +75,9 @@ class Order extends DealerOrderModel
                 $item['second_user_id'] => $item['second_money'],
                 $item['third_user_id'] => $item['third_money'],
             ];
-            $item['goods'] = $order_goods['goods'];
+            $item['goods'] = $order_goods['goods'] ?? [];
             $item['address_name'] =$address['name'];
-            $item['order_no'] = $item['order']['order_no'];
+            $item['order_no'] = $item['order']['order_no'] ?? "";
             $item['my_money'] = $money[$userId];
         }
         return $list;

From 0b34ad756e9b895f77ef3bb37aff677ec4c18975 Mon Sep 17 00:00:00 2001
From: ztt <835303992@qq.com>
Date: Thu, 29 Feb 2024 10:11:46 +0800
Subject: [PATCH 3/3] =?UTF-8?q?=E5=9B=9E=E6=94=B6=E8=AE=A2=E5=8D=95?=
 =?UTF-8?q?=E6=94=B9=E7=8A=B6=E6=80=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 app/api/controller/Recovery.php | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/app/api/controller/Recovery.php b/app/api/controller/Recovery.php
index 909b7b2c..b6325d42 100644
--- a/app/api/controller/Recovery.php
+++ b/app/api/controller/Recovery.php
@@ -134,11 +134,17 @@ class Recovery extends Controller
         if (empty($params['order_id']) || empty($params['recovery_id']) || empty($params['status'])) {
             return $this->renderError('缺少必要参数');
         }
-        $model = new RecoveryOrder();
-        $res = $model->save(['order_status' => $params['status']]);
-        if ($res) {
-            return  $this->renderSuccess('更新成功');
+
+        $model = (new RecoveryOrder())::detail($params['order_id']);
+        if ($model) {
+            if($params['status'] == RecoveryStatusEnum::ALREADY || $params['status'] == RecoveryStatusEnum::FINISN) {
+                $res = $model->save(['order_status' => $params['status']]);
+                if ($res) {
+                    return  $this->renderSuccess('更新成功');
+                }
+            }
         }
+
         return $this->renderError('更新失败');
     }