Forráskód Böngészése

批量修改价格

shish 2 éve
szülő
commit
6d8bcb843d

+ 0 - 1
app-hd/controllers/CgItemController.php

@@ -115,7 +115,6 @@ class CgItemController extends BaseController
                 //修改之前的批发价
                 $beforeModifyPrice = $current['price'] ?? 0;
                 $list[$key]['beforeModifyPrice'] = $beforeModifyPrice;
-
             }
         }
         $shop = $this->shop;

+ 68 - 18
app-hd/controllers/ProductController.php

@@ -9,7 +9,9 @@ use biz\shop\classes\ShopExtClass;
 use bizGhs\item\classes\ItemClassClass;
 use bizGhs\product\classes\ProductClass;
 use bizGhs\product\services\ProductService;
+use bizHd\admin\classes\ShopAdminClass;
 use bizHd\item\classes\ItemClass;
+use bizHd\purchase\classes\PurchaseClass;
 use common\components\printUtil;
 use common\components\stringUtil;
 use common\components\util;
@@ -201,17 +203,21 @@ class ProductController extends BaseController
     {
         $shop = $this->shop ?? [];
         $default = $shop->default ?? 0;
+        $join = $shop->join ?? 0;
         $shopAdmin = $this->shopAdmin;
+        $adminId = $this->adminId ?? 0;
         if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
             util::fail('超管才能修改');
         }
-
-        $pfShopId = $shop->pfShopId ?? 0;
-        if (!empty($pfShopId)) {
-            util::fail('请在批发端操作');
+        if ($join == 0 && $default == 0) {
+            util::fail('当前直营分店,只能回总店修改价格');
         }
-
-        $data = Yii::$app->request->post('data', '');
+        //normal常规改价,cg采购改价
+        $changeType = Yii::$app->request->post('changeType', 'normal');
+        $targetId = Yii::$app->request->post('targetId', 0);
+        $changeParams = ['staffId' => $shopAdmin->id, 'staffName' => $shopAdmin->name, 'changeType' => $changeType, 'targetId' => $targetId];
+        $post = Yii::$app->request->post();
+        $data = $post['data'] ?? '';
         if (empty($data)) {
             util::fail('没有修改');
         }
@@ -222,6 +228,22 @@ class ProductController extends BaseController
         $connection = Yii::$app->db;
         $transaction = $connection->beginTransaction();
         try {
+
+            $cg = PurchaseClass::getLockById($targetId);
+            if (!empty($cg)) {
+                if (isset($cg->mainId) == false || $cg->mainId != $this->mainId) {
+                    util::fail('不是您的采购单');
+                }
+                //没有发货则先发货
+                if ($cg->status == PurchaseClass::STATUS_UN_SEND) {
+                    $cg = PurchaseClass::orderSend($cg, [], true);
+                }
+                //确认收货并入库
+                if ($cg->status == PurchaseClass::STATUS_SENDING) {
+                    PurchaseClass::takeToPutIn($cg);
+                }
+            }
+
             $ids = array_column($arr, 'id');
             $ids = array_unique(array_filter($ids));
             if (empty($ids)) {
@@ -242,32 +264,60 @@ class ProductController extends BaseController
                 }
                 $price = $product['price'];
                 $productId = $product['id'];
-
-                $product = $productList[$productId] ?? [];
-                if (empty($product)) {
+                $productInfo = $productList[$productId] ?? [];
+                if (empty($productInfo)) {
                     util::fail('没有找到花材');
                 }
-                if (isset($product->mainId) == false || $product->mainId != $this->mainId) {
+                $productName = $productInfo->name ?? '';
+                if (isset($product['price']) == false || is_numeric($product['price']) == false || $product['price'] < 0) {
+                    util::fail('请填写' . $productName . '的批发价');
+                }
+                if (isset($product['skPrice']) == false || is_numeric($product['skPrice']) == false || $product['skPrice'] < 0) {
+                    util::fail('请填写' . $productName . '的零售价');
+                }
+                $skPrice = $product['skPrice'];
+                if (isset($product['hjPrice']) == false || is_numeric($product['hjPrice']) == false || $product['hjPrice'] < 0) {
+                    util::fail('请填写' . $productName . '的会员价');
+                }
+                $hjPrice = $product['hjPrice'] ?? 0;
+                if (isset($productInfo->mainId) == false || $productInfo->mainId != $this->mainId) {
                     util::fail('无法访问');
                 }
-                if (empty($price) || is_numeric($price) == false) {
-                    continue;
+                if ($hjPrice > $price) {
+                    util::fail($productName . ' 批发价要大于会员价');
+                }
+                if ($price > $skPrice) {
+                    util::fail($productName . ' 零售价要大于批发价');
                 }
-                $ptItemId = $product->itemId;
-                $staff = $this->shopAdmin;
-                $staffName = $staff->name ?? '';
-                $params = ['staffName' => $staffName];
-                ItemClass::changeSinglePrice($shop, $ptItemId, $price, $params);
+                $ptItemId = $productInfo->itemId;
+                ProductClass::changeSinglePrice($shop, $ptItemId, $price, $skPrice, $hjPrice, $changeParams);
                 //在首店修改需要同步到所有直营店
                 if ($default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
                     foreach ($chainShopList as $chain) {
                         if ($chain->id == $shop->id) {
                             continue;
                         }
-                        ItemClass::changeSinglePrice($chain, $ptItemId, $price, $params);
+                        $chainMainId = $chain->mainId ?? 0;
+                        $staff = ShopAdminClass::getByCondition(['mainId' => $chainMainId, 'adminId' => $adminId], true);
+                        $changeParams2 = ['staffId' => $staff->id, 'staffName' => $staff->name, 'changeType' => $changeType, 'targetId' => $targetId];
+                        ProductClass::changeSinglePrice($chain, $ptItemId, $price, $skPrice, $hjPrice, $changeParams2);
                     }
                 }
             }
+
+            $mainId = $shop->mainId ?? 0;
+            if (!empty($mainId)) {
+                //提醒零售收银台界面要刷新
+                $staffList = ShopAdminClass::getAllByCondition(['mainId' => $mainId], null, '*', null, true);
+                if (!empty($staffList)) {
+                    foreach ($staffList as $staff) {
+                        $staffId = $staff->id ?? 0;
+                        Yii::$app->redis->executeCommand('SET', ['cashier_' . $mainId . '_' . $staffId . '_may_refresh', 'yes']);
+                        Yii::$app->redis->executeCommand('SET', ['ghs_cashier_' . $mainId . '_' . $staffId . '_may_refresh', 'yes']);
+                    }
+                }
+            }
+
             $transaction->commit();
             util::complete('修改成功');
         } catch (\Exception $e) {

+ 51 - 2
biz-hd/purchase/classes/PurchaseClass.php

@@ -66,13 +66,14 @@ class PurchaseClass extends BaseClass
     //订单发货主方法 ssh 20231119
     public static function orderSend($cg, $params, $allowRepeat)
     {
-        self::orderFh($cg, $params, $allowRepeat);
+        $respond = self::orderFh($cg, $params, $allowRepeat);
         $orderId = $cg->saleId ?? 0;
         $orderInfo = OrderClass::getById($orderId, true);
         if (empty($orderInfo)) {
             util::fail('没有找到销售单信息');
         }
         OrderClass::orderFh($orderInfo, $params, $allowRepeat);
+        return $respond;
     }
 
     //订单发货子方法 ssh 20231119
@@ -109,6 +110,7 @@ class PurchaseClass extends BaseClass
         $cg->fhType = $fhType;
         $cg->status = 3;
         $cg->save();
+        return $cg;
     }
 
     //确认收货 ssh 20231119
@@ -116,8 +118,55 @@ class PurchaseClass extends BaseClass
     {
         //订单如果没有发货,则先发货
         if ($cg->status == self::STATUS_UN_SEND) {
-            self::orderSend($cg, [], true);
+            $cg = self::orderSend($cg, [], true);
+        }
+        self::takeToPutIn($cg);
+    }
+
+    //确认收货并入库 ssh 20231119
+    public static function takeToPutIn($cg)
+    {
+        if ($cg->status != 3) {
+            util::fail('订单不是待入库状态');
+        }
+        $saleId = $cg->saleId ?? 0;
+        $Order = OrderClass::getById($saleId, true);
+        if (empty($Order)) {
+            util::fail('没有找到订单');
         }
+        if ($Order->status != 3) {
+            util::fail('订单不是待入库状态哦');
+        }
+        $Order->status == 4;
+        $Order->save();
+
+        //加库存 lqh 2021-05-10
+        $orderSn = $cg->orderSn;
+        $purchaseItem = PurchaseItemClass::getAllByCondition(['orderSn' => $orderSn], null, "*");
+        foreach ($purchaseItem as $v) {
+            //小单位库存不考虑入库 ssh 202310
+            $itemNum = intval($v['itemNum']);
+            if ($itemNum > 0) {
+                $stockInfo = ProductClass::addStockByItemNum($v['productId'], $itemNum);
+                //记录库存流水
+                $recordData = [];
+                $recordData['sjId'] = $cg->sjId;
+                $recordData['shopId'] = $cg->shopId;
+                $recordData['mainId'] = $cg->mainId;
+                $recordData['itemId'] = $v['itemId'] ?? 0;
+                $recordData['itemNum'] = $itemNum;
+                $recordData['oldStock'] = $stockInfo['oldStock'];
+                $recordData['newStock'] = $stockInfo['newStock'];
+                $recordData['productId'] = $v['productId'];
+                $recordData['orderSn'] = $orderSn;
+                $recordData['relateName'] = $cg->ghsName ?? '';
+                StockRecordClass::addPurchaseOrderRecord($recordData);
+            }
+        }
+
+        $cg->status = 4;
+        $cg->stockChange = 1;
+        $cg->save();
     }
 
     public static function notSameCity($shop, $ghsShop)