Browse Source

修改单位和重量

shish 1 year ago
parent
commit
5b90465bed

+ 163 - 0
app-ghs/controllers/ItemController.php

@@ -3,6 +3,7 @@
 namespace ghs\controllers;
 
 use biz\item\classes\PtItemClass;
+use biz\item\classes\UnitClass;
 use biz\shop\classes\ShopExtClass;
 use bizGhs\book\classes\BookItemClass;
 use bizGhs\custom\classes\CustomClass;
@@ -21,6 +22,168 @@ use Yii;
 class ItemController extends BaseController
 {
 
+    public function actionModifyWeight()
+    {
+        $get = Yii::$app->request->get();
+        $id = $get['id'] ?? '';
+        $weight = $get['weight'] ?? 1;
+        if ($weight <= 0) {
+            util::fail('重量不能小于0');
+        }
+        $item = ItemClass::getById($id, true);
+        if (empty($item)) {
+            util::fail('没有找到花材');
+        }
+        if ($item->mainId != $this->mainId) {
+            util::fail('不是你的花材');
+        }
+        $adminId = $this->adminId;
+        $ptItemId = $item->itemId ?? 0;
+        $hasRightChange = ShopAdminClass::changeWeightRight($adminId, $ptItemId);
+        if ($hasRightChange == 0) {
+            util::fail('不能修改');
+        }
+        $ptItem = PtItemClass::getById($ptItemId, true);
+        if (empty($ptItem)) {
+            util::fail('花材信息缺失');
+        }
+        $connection = Yii::$app->db;
+        $transaction = $connection->beginTransaction();
+        try {
+            $ptItem->weight = $weight;
+            $ptItem->save();
+            ItemClass::updateByCondition(['itemId' => $ptItemId], ['weight' => $weight]);
+            $transaction->commit();
+        } catch (\Exception $e) {
+            $transaction->rollBack();
+            Yii::info("修改失败原因:" . $e->getMessage());
+            util::fail('修改失败');
+        }
+    }
+
+    public function actionModifyRatio()
+    {
+        $get = Yii::$app->request->get();
+        $id = $get['id'] ?? '';
+        $ratio = $get['ratio'] ?? 20;
+        if ($ratio < 1) {
+            util::fail('单位比不能小于1');
+        }
+        $item = ItemClass::getById($id, true);
+        if (empty($item)) {
+            util::fail('没有找到花材');
+        }
+        if ($item->mainId != $this->mainId) {
+            util::fail('不是你的花材');
+        }
+        $adminId = $this->adminId;
+        $ptItemId = $item->itemId ?? 0;
+        $hasRightChange = ShopAdminClass::changeWeightRight($adminId, $ptItemId);
+        if ($hasRightChange == 0) {
+            util::fail('不能修改');
+        }
+        $ptItem = PtItemClass::getById($ptItemId, true);
+        if (empty($ptItem)) {
+            util::fail('花材信息缺失');
+        }
+        $connection = Yii::$app->db;
+        $transaction = $connection->beginTransaction();
+        try {
+            $ptItem->ratio = $ratio;
+            $ptItem->save();
+            ItemClass::updateByCondition(['itemId' => $ptItemId], ['ratio' => $ratio]);
+            $transaction->commit();
+        } catch (\Exception $e) {
+            $transaction->rollBack();
+            Yii::info("修改失败原因:" . $e->getMessage());
+            util::fail('修改失败');
+        }
+    }
+
+    public function actionModifyBigUnit()
+    {
+        $get = Yii::$app->request->get();
+        $id = $get['id'] ?? '';
+        $unitId = $get['unitId'] ?? 1;
+        $unit = UnitClass::getById($unitId, true);
+        if (empty($unit)) {
+            util::fail('没有找到单位');
+        }
+        $unitName = $unit->name;
+        $item = ItemClass::getById($id, true);
+        if (empty($item)) {
+            util::fail('没有找到花材');
+        }
+        if ($item->mainId != $this->mainId) {
+            util::fail('不是你的花材');
+        }
+        $adminId = $this->adminId;
+        $ptItemId = $item->itemId ?? 0;
+        $hasRightChange = ShopAdminClass::changeWeightRight($adminId, $ptItemId);
+        if ($hasRightChange == 0) {
+            util::fail('不能修改');
+        }
+        $ptItem = PtItemClass::getById($ptItemId, true);
+        if (empty($ptItem)) {
+            util::fail('花材信息缺失');
+        }
+        $connection = Yii::$app->db;
+        $transaction = $connection->beginTransaction();
+        try {
+            $ptItem->bigUnit = $unitName;
+            $ptItem->bigUnitId = $unitId;
+            $ptItem->save();
+            ItemClass::updateByCondition(['itemId' => $ptItemId], ['bigUnit' => $unitName, 'bigUnitId' => $unitId]);
+            $transaction->commit();
+        } catch (\Exception $e) {
+            $transaction->rollBack();
+            Yii::info("修改失败原因:" . $e->getMessage());
+            util::fail('修改失败');
+        }
+    }
+
+    public function actionModifySmallUnit()
+    {
+        $get = Yii::$app->request->get();
+        $id = $get['id'] ?? '';
+        $unitId = $get['unitId'] ?? 1;
+        $unit = UnitClass::getById($unitId, true);
+        if (empty($unit)) {
+            util::fail('没有找到单位');
+        }
+        $unitName = $unit->name;
+        $item = ItemClass::getById($id, true);
+        if (empty($item)) {
+            util::fail('没有找到花材');
+        }
+        if ($item->mainId != $this->mainId) {
+            util::fail('不是你的花材');
+        }
+        $adminId = $this->adminId;
+        $ptItemId = $item->itemId ?? 0;
+        $hasRightChange = ShopAdminClass::changeWeightRight($adminId, $ptItemId);
+        if ($hasRightChange == 0) {
+            util::fail('不能修改');
+        }
+        $ptItem = PtItemClass::getById($ptItemId, true);
+        if (empty($ptItem)) {
+            util::fail('花材信息缺失');
+        }
+        $connection = Yii::$app->db;
+        $transaction = $connection->beginTransaction();
+        try {
+            $ptItem->smallUnit = $unitName;
+            $ptItem->smallUnitId = $unitId;
+            $ptItem->save();
+            ItemClass::updateByCondition(['itemId' => $ptItemId], ['smallUnit' => $unitName, 'smallUnitId' => $smallUnitId]);
+            $transaction->commit();
+        } catch (\Exception $e) {
+            $transaction->rollBack();
+            Yii::info("修改失败原因:" . $e->getMessage());
+            util::fail('修改失败');
+        }
+    }
+
     //挪到处理区 ssh 20250418
     public function actionMoveToLosing()
     {

+ 1 - 14
app-ghs/controllers/ProductController.php

@@ -1259,20 +1259,7 @@ class ProductController extends BaseController
         //判断这个花材能否被修改单位比和重量,同步参考ShopController actionMyShop方法,关键词has_right_shop_list
         //判断当前登录的人,在自己有财务权限的main里面,是否包括了这个花材所属的平台id,在这个平台id下所有花材的main
         $adminId = $this->adminId;
-        $staffList = ShopAdminClass::getAllByCondition(['adminId' => $adminId], null, '*', null, true);
-        $hasMainList = [];
-        if (!empty($staffList)) {
-            foreach ($staffList as $staff) {
-                if($staff->super == 1){
-                    $hasMainList[] = $staff->mainId;
-                }
-            }
-        }
-        $sameList = ProductClass::getAllByCondition(['itemId' => $ptItemId], null, 'id,itemId,mainId');
-        $sameMainList = array_column($sameList, 'mainId');
-        $hasNot = array_diff($sameMainList, $hasMainList);
-        $hasRightChange = empty($hasNot) ? 1 : 0;
-        //是否允许修改花材单位比、单位和重量等
+        $hasRightChange = ShopAdminClass::changeWeightRight($adminId, $ptItemId);
         $respond['hasRightChange'] = $hasRightChange;
 
         $respond['cpInfo'] = $cpInfo;

+ 23 - 0
biz-ghs/shop/classes/ShopAdminClass.php

@@ -5,6 +5,7 @@ namespace bizGhs\shop\classes;
 
 use biz\admin\classes\AdminClass;
 use bizGhs\admin\classes\AdminRoleClass;
+use bizGhs\product\classes\ProductClass;
 use common\components\dict;
 use common\components\sms;
 use common\components\util;
@@ -16,6 +17,28 @@ class ShopAdminClass extends BaseClass
 
     public static $baseFile = '\bizGhs\shop\models\ShopAdmin';
 
+
+    public static function changeWeightRight($adminId,$ptItemId)
+    {
+        //判断这个花材能否被修改单位比和重量,同步参考ShopController actionMyShop方法,关键词has_right_shop_list
+        //判断当前登录的人,在自己有财务权限的main里面,是否包括了这个花材所属的平台id,在这个平台id下所有花材的main
+        $staffList = ShopAdminClass::getAllByCondition(['adminId' => $adminId], null, '*', null, true);
+        $hasMainList = [];
+        if (!empty($staffList)) {
+            foreach ($staffList as $staff) {
+                if($staff->super == 1){
+                    $hasMainList[] = $staff->mainId;
+                }
+            }
+        }
+        $sameList = ProductClass::getAllByCondition(['itemId' => $ptItemId], null, 'id,itemId,mainId');
+        $sameMainList = array_column($sameList, 'mainId');
+        $hasNot = array_diff($sameMainList, $hasMainList);
+        $hasRightChange = empty($hasNot) ? 1 : 0;
+        //是否允许修改花材单位比、单位和重量等
+        return $hasRightChange;
+    }
+
     const GENERATE_ADMIN_DATA = 'generate_ghs_admin_data_';//创建管理员需要的数据
 
     //查看财务权限 ssh 20230620