浏览代码

修改价格

shish 3 年之前
父节点
当前提交
5b10088b51

+ 0 - 10
app-hd/controllers/ProductController.php

@@ -192,13 +192,11 @@ class ProductController extends BaseController
     public function actionBatchChangePrice()
     {
         $shop = $this->shop ?? [];
-
         $default = $shop->default ?? 0;
         $shopAdmin = $this->shopAdmin;
         if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
             util::fail('超管才能修改');
         }
-
         $data = Yii::$app->request->post('data', '');
         if (empty($data)) {
             util::fail('没有修改');
@@ -207,25 +205,20 @@ class ProductController extends BaseController
         if (empty($arr)) {
             util::fail('没有修改!');
         }
-
         $connection = Yii::$app->db;
         $transaction = $connection->beginTransaction();
         try {
-
             $ids = array_column($arr, 'id');
             $ids = array_unique(array_filter($ids));
             if (empty($ids)) {
                 util::fail('请选择花材');
             }
-
             $sjId = $shop->sjId ?? 0;
             $chainShopList = [];
             if ($default == 1) {
                 $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId, 'join' => 0], null, '*', null, true);
             }
-
             $productList = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id', true);
-
             foreach ($arr as $product) {
                 if (isset($product['price']) == false) {
                     util::fail('没有价格');
@@ -258,16 +251,13 @@ class ProductController extends BaseController
                     }
                 }
             }
-
             $transaction->commit();
             util::complete('修改成功');
-
         } catch (\Exception $e) {
             $transaction->rollBack();
             Yii::info("失败原因:" . $e->getMessage());
             util::fail('修改失败');
         }
-
     }
 
     //从零售端采购入库,查看供货商的某个门店的product

+ 37 - 3
biz-hd/item/classes/ItemClass.php

@@ -156,16 +156,50 @@ class ItemClass extends BaseClass
 
     }
 
-    //单个价格修改 ssh 20220503
-    public static function changeSinglePrice($shop, $ptItemId, $price)
+    //单个价格修改 ssh 20230214
+    public static function changeSinglePrice($shop, $ptItemId, $skPrice, $params = [])
     {
         $mainId = $shop->mainId ?? 0;
         $productInfo = ProductClass::getByCondition(['itemId' => $ptItemId, 'mainId' => $mainId], true);
         if (empty($productInfo)) {
             return false;
         }
-        $productInfo->skPrice = $price;
+        $productInfo->skPrice = $skPrice;
         $productInfo->save();
+        $price = $productInfo->price ?? 0;
+
+        $sjId = $shop->sjId ?? 0;
+        $itemId = $productInfo->id ?? 0;
+        $ptItemId = $productInfo->itemId ?? 0;
+        $name = $productInfo->name ?? '';
+        $cover = $productInfo->cover ?? '';
+        $staffId = $params['staffId'] ?? 0;
+        $staffName = $params['staffName'] ?? '';
+        $changeType = $params['changeType'] ?? 'normal';
+        $targetId = $params['targetId'] ?? 0;
+        $event = '修改';
+        $type = 0;
+        if ($changeType == 'cg') {
+            $event = '采购修改';
+            $type = 1;
+        }
+        $changeData = [
+            'ptStyle' => 1,
+            'sjId' => $sjId,
+            'mainId' => $mainId,
+            'itemId' => $itemId,
+            'ptItemId' => $ptItemId,
+            'price' => $price,
+            'skPrice' => $skPrice,
+            'staffId' => $staffId,
+            'staffName' => $staffName,
+            'name' => $name,
+            'cover' => $cover,
+            'event' => $event,
+            'type' => $type,
+            'targetId' => $targetId,
+        ];
+        PriceChangeClass::addData($changeData);
     }
 
     //新增花材

+ 24 - 0
biz-hd/item/classes/PriceChangeClass.php

@@ -0,0 +1,24 @@
+<?php
+
+namespace bizHd\item\classes;
+
+use bizHd\base\classes\BaseClass;
+
+class PriceChangeClass extends BaseClass
+{
+
+    public static $baseFile = '\bizHd\item\models\PriceChange';
+
+    public static function getChangeList($where)
+    {
+        $data = self::getList('*', $where, 'addTime DESC');
+        return $data;
+    }
+
+    //增加价格变动记录 ssh 20221108
+    public static function addData($data)
+    {
+        return self::add($data, true);
+    }
+
+}

+ 13 - 0
biz-hd/item/models/PriceChange.php

@@ -0,0 +1,13 @@
+<?php
+
+namespace bizHd\item\models;
+use bizHd\base\models\Base;
+class PriceChange extends Base
+{
+
+    public static function tableName()
+    {
+        return 'xhGhsPriceChange';
+    }
+
+}