From bc881d8e09f7937cbaa826de82a7670ed799aebb Mon Sep 17 00:00:00 2001
From: liu <1873441552@qq.com>
Date: Mon, 17 Jun 2024 15:27:43 +0800
Subject: [PATCH 1/3] =?UTF-8?q?=E5=AD=97=E6=AE=B5=E5=92=8C=E5=BA=97?=
 =?UTF-8?q?=E9=93=BA=E5=95=86=E5=93=81=E7=9A=84=E9=80=BB=E8=BE=91=E4=BF=AE?=
 =?UTF-8?q?=E6=94=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../StoreBranchProductLists.php                   |  2 +-
 app/api/logic/order/OrderLogic.php                | 15 +++++++++------
 app/common/enum/UserShipEnum.php                  | 13 +++++++++----
 app/queue/redis/StoreStorageSend.php              |  4 +++-
 4 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/app/admin/lists/store_branch_product/StoreBranchProductLists.php b/app/admin/lists/store_branch_product/StoreBranchProductLists.php
index a15a4e13a..cce4193a4 100644
--- a/app/admin/lists/store_branch_product/StoreBranchProductLists.php
+++ b/app/admin/lists/store_branch_product/StoreBranchProductLists.php
@@ -58,7 +58,7 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI
             }
         }
         return StoreBranchProduct::where($this->searchWhere)->where($where)
-            ->field(['id','store_id','product_id', 'image', 'store_name', 'cate_id', 'price', 'sales', 'stock', 'unit', 'cost', 'status'])
+            ->field(['id','store_id','product_id', 'image', 'store_name', 'cate_id', 'price', 'sales', 'stock', 'unit', 'cost','purchase', 'status'])
             ->when(!empty($this->adminInfo['store_id']), function ($query) {
                 $query->where('store_id', $this->adminInfo['store_id']);
             })
diff --git a/app/api/logic/order/OrderLogic.php b/app/api/logic/order/OrderLogic.php
index 5896de4e4..d87393fd9 100644
--- a/app/api/logic/order/OrderLogic.php
+++ b/app/api/logic/order/OrderLogic.php
@@ -66,30 +66,33 @@ class OrderLogic extends BaseLogic
         try {
             self::$total_price = 0;
             self::$pay_price = 0;
-            self::$cost = 0; //成本
+            self::$cost = 0; //成本由采购价替代原成本为门店零售价
             self::$profit = 0; //利润
             self::$activity_price = 0; //活动减少
             /** 计算价格 */
             
             foreach ($cart_select as $k => $v) {
-                $find = StoreBranchProduct::where(['product_id' => $v['product_id'], 'store_id' => $params['store_id']])->field('id branch_product_id,store_name,image,unit,price,vip_price,cost,product_id')->withTrashed()->find();
+                $find = StoreBranchProduct::where(['product_id' => $v['product_id'], 'store_id' => $params['store_id']])->field('id branch_product_id,store_name,image,unit,price,vip_price,cost,purchase,product_id')->withTrashed()->find();
                 if (!$find) {
                     continue;
                 }
                 unset($cart_select[$k]['id']);
+                if($user && in_array($user['user_ship'],UserShipEnum::DISCOUNT_ARRAY)){
+                    $find['price'] = $find['cost'];
+                }
 
                 $cart_select[$k]['price'] = $find['price'];
                 $cart_select[$k]['total_price'] = bcmul($v['cart_num'], $find['price'], 2); //订单总价
                 $cart_select[$k]['deduction_price'] =self::$activity_price;//抵扣金额
 
                 if ($user && $user['user_ship'] == 4) {
-                    $deduction_price_count=bcmul(bcsub($find['price'], $find['cost'], 2),$v['cart_num'],2);
+                    $deduction_price_count=bcmul(bcsub($find['price'], $find['purchase'], 2),$v['cart_num'],2);
                     $cart_select[$k]['deduction_price'] =$deduction_price_count;
                     self::$activity_price = bcadd(self::$activity_price, $deduction_price_count, 2);
                 }                
                 //利润
                 // $cart_select[$k]['profit'] = bcmul($v['cart_num'], $onePrice, 2); //利润
-                $cart_select[$k]['cost'] = bcmul($v['cart_num'], $find['cost'], 2) ?? 0; //成本
+                $cart_select[$k]['purchase'] = bcmul($v['cart_num'], $find['purchase'], 2) ?? 0; //成本
                 $cart_select[$k]['pay_price'] = bcmul($v['cart_num'], $find['price'], 2); //订单支付金额
                 $cart_select[$k]['product_id'] = $find['product_id'];
                 $cart_select[$k]['old_cart_id'] = $v['id'];
@@ -110,7 +113,7 @@ class OrderLogic extends BaseLogic
                 $cart_select[$k]['unit_name'] = StoreProductUnit::where(['id' => $find['unit']])->value('name');
                 self::$total_price = bcadd(self::$total_price, $cart_select[$k]['total_price'], 2);
                 self::$pay_price = bcadd(self::$pay_price, $cart_select[$k]['pay_price'], 2);
-                self::$cost = bcadd(self::$cost, $cart_select[$k]['cost'], 2);
+                self::$cost = bcadd(self::$cost, $cart_select[$k]['purchase'], 2);
                 // self::$profit = bcadd(self::$profit, $cart_select[$k]['profit'], 2);
             }
             $pay_price =bcsub(self::$pay_price, self::$activity_price, 2); //减去活动优惠金额
@@ -141,7 +144,7 @@ class OrderLogic extends BaseLogic
             if ($params['store_id']) {
                 $order['default_delivery'] = SystemStore::where('id', $params['store_id'])->value('is_send');
             }
-            if($user['user_ship']>=1 &&$user['user_ship']<=3){
+            if($user && $user['user_ship']>=1 &&$user['user_ship']<=3){
                 $order['is_vip'] = 1;
 
             }
diff --git a/app/common/enum/UserShipEnum.php b/app/common/enum/UserShipEnum.php
index ea4b84ccf..772a54456 100644
--- a/app/common/enum/UserShipEnum.php
+++ b/app/common/enum/UserShipEnum.php
@@ -8,9 +8,14 @@ class UserShipEnum
      * 会员等级
      */
     const VIP1 = 1;
-    const VIP2 = 7;
-    const VIP3 = 8;
-    const VIP4 = 9;
-    const VIP5 = 10;
+    const VIP2 = 2;
+    const VIP3 = 3;
+    const VIP4 = 4;
+    const VIP5 = 5;
+
+    /**
+     * 切换折扣价
+     */
+    const DISCOUNT_ARRAY = [4,5,6];
 
 }
\ No newline at end of file
diff --git a/app/queue/redis/StoreStorageSend.php b/app/queue/redis/StoreStorageSend.php
index f2069763c..3e755bd3c 100644
--- a/app/queue/redis/StoreStorageSend.php
+++ b/app/queue/redis/StoreStorageSend.php
@@ -56,7 +56,8 @@ class StoreStorageSend implements Consumer
                     'cate_id' => $find['cate_id'],
                     'price' => $find['price'],
 //                    'cost' => $find['cost'], //v1.0
-                    'cost' => $find['purchase'],
+                    'cost' => $find['cost'],
+                    'purchase' => $find['purchase'],
                     'vip_price' => $find['vip_price'],
                     'unit' => $find['unit'],
                     'batch' => $find['batch'],
@@ -117,6 +118,7 @@ class StoreStorageSend implements Consumer
                     'cate_id' => $find['cate_id'],
                     'price' => $find['price'],
                     'cost' => $find['cost'],
+                    'purchase' => $find['purchase'],
                     'vip_price' => $find['vip_price'],
                     'unit' => $find['unit'],
                     'store_id' => $store_id,

From 725dc922bf9ffe4ef4c87506bc2eea6c40c94930 Mon Sep 17 00:00:00 2001
From: liu <1873441552@qq.com>
Date: Mon, 17 Jun 2024 15:32:36 +0800
Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=90=88=E5=B9=B6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .gitignore | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.gitignore b/.gitignore
index ee1734d91..a0a855bf2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,4 +5,5 @@
 /tests/tmp
 /tests/.phpunit.result.cache
 public/uploads
+public/image/barcode
 public/image
\ No newline at end of file

From 3ccaee48978507701facd57f8673f1d7883babfb Mon Sep 17 00:00:00 2001
From: liu <1873441552@qq.com>
Date: Mon, 17 Jun 2024 15:50:05 +0800
Subject: [PATCH 3/3] =?UTF-8?q?=E4=B8=B4=E6=97=B6=E5=A4=A7=E5=B1=8F?=
 =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=9F=A5=E8=AF=A2=E6=8E=A5=E5=8F=A3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 app/store/controller/WorkbenchController.php | 11 +++++++++++
 app/store/logic/WorkbenchLogic.php           |  8 ++++++++
 2 files changed, 19 insertions(+)

diff --git a/app/store/controller/WorkbenchController.php b/app/store/controller/WorkbenchController.php
index 3ca20e3cb..6617466ca 100644
--- a/app/store/controller/WorkbenchController.php
+++ b/app/store/controller/WorkbenchController.php
@@ -3,12 +3,14 @@
 namespace app\store\controller;
 
 use app\common\controller\Definitions;
+use app\common\model\dict\DictType;
 use app\store\lists\store_order\StoreOrderLists;
 use app\store\logic\WorkbenchLogic;
 
 // #[ApiDoc\Title('工作台')]
 class WorkbenchController extends BaseAdminController
 {
+    public $notNeedLogin = ['recharge_statistics'];
 
     // #[
     //     ApiDoc\Title('交易统计'),
@@ -159,4 +161,13 @@ class WorkbenchController extends BaseAdminController
         $result = WorkbenchLogic::revenueStatistics($params);
         return $this->data($result);
     }
+
+
+    public function recharge_statistics()
+    {
+        $params['store_id'] = DictType::where('type','store')->value('remark')??5;
+        $result = WorkbenchLogic::rechargeData($params);
+        return $this->data($result);
+        
+    }
 }
diff --git a/app/store/logic/WorkbenchLogic.php b/app/store/logic/WorkbenchLogic.php
index 8f349359c..53aa4eec5 100644
--- a/app/store/logic/WorkbenchLogic.php
+++ b/app/store/logic/WorkbenchLogic.php
@@ -709,6 +709,14 @@ class WorkbenchLogic extends BaseLogic
 
     }
 
+    public static function rechargeData($params)
+    {
+        $data['receipt_amount'] = UserRecharge::where([
+            'store_id'=>$params['store_id'],
+            'paid'=>YesNoEnum::YES
+        ])->sum('price');
+        return $data??[];
+    }