Bladeren bron

Merge branch 'linqh-dev'

林琦海 5 jaren geleden
bovenliggende
commit
9e299fb510

+ 23 - 4
app/ghs/controllers/ItemClassController.php

@@ -7,7 +7,8 @@
 namespace ghs\controllers;
 
 
-use bizGhs\itemClass\services\ItemClassService;
+use bizGhs\item\classes\ItemClassClass;
+use bizGhs\item\services\ItemClassService;
 use common\components\util;
 use Yii;
 class ItemClassController extends BaseController
@@ -16,14 +17,32 @@ class ItemClassController extends BaseController
     public function actionList()
     {
         $where = ['ghsId' => $this->ghsId];
-        $list = ItemClassService::getGhsItemClassList($where);
+        $list = ItemClassClass::getGhsItemClassList($where);
         util::success($list);
     }
 
     public function actionAdd()
     {
-        $get = Yii::$app->request->get();
-        $res = ItemClassService::addGhsItemClass($this->ghsId,$get);
+        $post = Yii::$app->request->post();
+        $post['adminId'] = $this->adminId;
+        $res = ItemClassClass::addGhsItemClass($this->ghsId,$post);
         util::complete('添加成功');
     }
+
+    public function actionUpdate()
+    {
+        $data = Yii::$app->request->post();
+
+        $data['adminId'] = $this->adminId;
+        $data['ghsId'] = $this->ghsId;
+        ItemClassClass::updateGhsItemClass($data);
+        util::complete('修改成功');
+    }
+
+    public function actionDelete()
+    {
+        $id = Yii::$app->request->get('id',0);
+        ItemClassService::deleteGhsItemClass($id);
+        util::complete('操作成功');
+    }
 }

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

@@ -0,0 +1,48 @@
+<?php
+namespace ghs\controllers;
+
+
+use bizGhs\item\classes\ItemClass;
+use bizGhs\item\services\ItemService;
+use common\components\util;
+use Yii;
+class ItemController extends BaseController
+{
+
+    public function actionList()
+    {
+        //classId
+        $classId = Yii::$app->request->get('classId',0);
+        $where['ghsId'] =  $this->ghsId;
+        $where['classId'] =  $classId;
+        $list = ItemClass::getGhsItemList($where);
+        util::success($list);
+    }
+
+    public function actionAdd()
+    {
+        $post = Yii::$app->request->post();
+        $post['adminId'] = $this->adminId;
+        $post['shopId'] = $this->shopId;
+        $post['ghsId'] = $this->ghsId;
+        ItemService::addGhsItem($post);
+        util::complete('添加成功');
+    }
+
+    public function actionUpdate()
+    {
+        $data = Yii::$app->request->post();
+        $data['adminId'] = $this->adminId;
+        $data['ghsId'] = $this->ghsId;
+        ItemService::updateGshItem($data);
+        util::complete('修改成功');
+    }
+
+    public function actionDelete()
+    {
+        $get = Yii::$app->request->get();
+        $id = isset($get['id']) ? $get['id'] : 0;
+        ItemService::deleteGhsItem($id,$this->shopId,$this->adminId);
+        util::complete('操作成功');
+    }
+}

+ 13 - 0
biz-ghs/demo/classes/DemoClass.php

@@ -0,0 +1,13 @@
+<?php
+namespace bizGhs\demo\classes;
+
+
+use bizGhs\base\classes\BaseClass;
+
+class DemoClass extends BaseClass
+{
+
+    public static $baseFile = '\bizGhs\demo\models\Demo';
+
+
+}

+ 10 - 0
biz-ghs/demo/models/Demo.php

@@ -0,0 +1,10 @@
+<?php
+namespace bizGhs\demo\models;
+use bizGhs\base\models\Base;
+class Demo extends Base
+{
+    public static function tableName()
+    {
+        return 'xhGhsItem';
+    }
+}

+ 13 - 0
biz-ghs/demo/services/DemoService.php

@@ -0,0 +1,13 @@
+<?php
+namespace bizGhs\demo\services;
+
+
+use bizGhs\base\services\BaseService;
+
+class DemoService extends BaseService
+{
+
+
+
+
+}

+ 45 - 1
biz-ghs/item/classes/ItemClass.php

@@ -8,11 +8,55 @@ namespace bizGhs\item\classes;
 
 
 use bizGhs\base\classes\BaseClass;
-
+use bizGhs\item\models\ItemInfo;
+use common\components\util;
+use Yii;
 class ItemClass extends BaseClass
 {
 
     public static $baseFile = '\bizGhs\item\models\Item';
 
 
+    //列表数据
+    public static function getGhsItemList($where)
+    {
+        $data = ItemClass::getList('*', $where, 'addTime DESC');
+        $list = isset($data['list']) && !empty($data['list']) ? $data['list'] : [];
+        if (empty($list)) {
+            return $data;
+        }
+        $data['list'] = $list;
+        return $data;
+    }
+
+
+
+    //批量新增花材(初始化使用)
+    public static function batchAddGhsItem($data)
+    {
+
+        return true;
+    }
+
+    //修改花材的信息(库存预警、每扎加价、每扎重量)
+    public static function updateGshItem($id,$stockWarning,$unitAddPrice,$unitWeight)
+    {
+        $model = ItemClass::getById($id);
+        if(!$model){
+            util::fail("该花材不存在");
+        }
+        $data['stockWarning'] = $stockWarning;
+        $data['unitAddPrice'] = $unitAddPrice;
+        $data['unitWeight'] = $unitWeight;
+        ItemClass::updateById($id,$data);
+        return true;
+
+    }
+
+    //删除花材
+    public static function deleteGhsItem($id)
+    {
+        ItemClass::deleteById($id);
+        return true;
+    }
 }

+ 33 - 24
biz-ghs/itemClass/services/ItemClassService.php → biz-ghs/item/classes/ItemClassClass.php

@@ -1,18 +1,22 @@
 <?php
 /**
  * User: admin
- * Date Time: 2021/1/13 17:16
+ * Date Time: 2021/1/13 17:12
  */
 
-namespace bizGhs\itemClass\services;
+namespace bizGhs\item\classes;
 
 
-use bizGhs\base\services\BaseService;
-use bizGhs\itemClass\classes\ItemClassClass;
+use bizGhs\base\classes\BaseClass;
 use common\components\util;
-class ItemClassService extends BaseService
+
+//use biz\base\classes\BaseClass;
+class ItemClassClass extends BaseClass
 {
 
+    public static $baseFile = '\bizGhs\item\models\ItemClass';
+
+
 
     public static function getGhsItemClassList($where)
     {
@@ -26,50 +30,55 @@ class ItemClassService extends BaseService
     }
 
     //新增花材分类
-    public static function addGhsItemClass($gshId,$data)
+    public static function addGhsItemClass($ghsId,$data)
     {
-
-        if(!$gshId){
+        if(!$ghsId){
             util::fail("请选择供应商");
         }
-        $data['ghsId'] = $gshId;
+        $data['ghsId'] = $ghsId;
         $name = $data['name']??'';
         if(!$name){
             util::fail("请输入花材分类");
         }
+
+        //判断花材名称是否存在(当前ghsId下)
+        $exist = ItemClassClass::exists(['ghsId'=>$ghsId,'name'=>$name]);
+        if($exist){
+            util::fail("花材分类名称已存在");
+        }
+
         $res = ItemClassClass::add($data);
         return $res;
     }
 
     //批量新增花材分类
-    public static function batchAddGhsItemClass(array $data)
+    public static function batchAddGhsItemClass($data)
     {
         ItemClassClass::batchAdd($data);
         return true;
     }
 
     //修改
-    public static function updateGhsItemClass($id,$name,$inTurn,$adminId=0)
+    public static function updateGhsItemClass($data)
     {
+        $id = $data['id']??0;
+        $ghsId = $data['ghsId']??0;
+        $name = $data['name']??'';
+        if(!$ghsId){
+            util::fail("请选择供应商");
+        }
+        if(!$name){
+            util::fail("花材分类名称不能为空");
+        }
         $model = ItemClassClass::getById($id);
         if(!$model){
             util::fail("该花材分类不存在");
         }
-        $data['name'] = $name;
-        $data['inTurn'] = $inTurn;
-        $data['adminId'] = $adminId;
+
         ItemClassClass::updateById($id,$data);
         return true;
     }
 
-    //删除
-    public static function deleteGhsItemClass($id)
-    {
-        $model = ItemClassClass::getById($id);
-        if(!$model){
-            util::fail("该花材分类不存在");
-        }
-        ItemClassClass::deleteById($id);
-        return true;
-    }
+
+
 }

+ 3 - 3
biz-ghs/itemInfo/classes/ItemInfoClass.php → biz-ghs/item/classes/ItemInfoClass.php

@@ -4,7 +4,7 @@
  * Date Time: 2021/1/13 17:12
  */
 
-namespace bizGhs\itemInfo\classes;
+namespace bizGhs\item\classes;
 
 
 use bizGhs\base\classes\BaseClass;
@@ -12,7 +12,7 @@ use bizGhs\base\classes\BaseClass;
 class ItemInfoClass extends BaseClass
 {
 
-    public static $baseFile = '\bizGhs\itemInfo\models\ItemInfo';
-
+    public static $baseFile = '\bizGhs\item\models\ItemInfo';
 
+    //
 }

+ 1 - 1
biz-ghs/itemClass/models/ItemClass.php → biz-ghs/item/models/ItemClass.php

@@ -3,7 +3,7 @@
  * User: admin
  * Date Time: 2021/1/13 14:13
  */
-namespace bizGhs\itemClass\models;
+namespace bizGhs\item\models;
 use bizGhs\base\models\Base;
 class ItemClass extends Base
 {

+ 1 - 1
biz-ghs/itemInfo/models/ItemInfo.php → biz-ghs/item/models/ItemInfo.php

@@ -3,7 +3,7 @@
  * User: admin
  * Date Time: 2021/1/13 14:13
  */
-namespace bizGhs\itemInfo\models;
+namespace bizGhs\item\models;
 use bizGhs\base\models\Base;
 class ItemInfo extends Base
 {

+ 35 - 0
biz-ghs/item/services/ItemClassService.php

@@ -0,0 +1,35 @@
+<?php
+/**
+ * User: admin
+ * Date Time: 2021/1/13 17:16
+ */
+
+namespace bizGhs\item\services;
+
+
+use bizGhs\base\services\BaseService;
+use bizGhs\item\classes\ItemClass;
+use bizGhs\item\classes\ItemClassClass;
+use common\components\util;
+
+class ItemClassService extends BaseService
+{
+
+
+    //删除花材分类. 有花材不让删除
+    public static function deleteGhsItemClass($id)
+    {
+        //判断是否存在
+        $model = ItemClassClass::getById($id);
+        if(!$model){
+            util::fail("该花材分类不存在");
+        }
+        $exist = ItemClass::exists(['classId'=>$id,'ghsId'=>$model['ghsId']]);
+        if($exist){
+            util::fail("该花材分类还有花材,不能删除");
+        }
+        ItemClassClass::deleteById($id);
+
+    }
+
+}

+ 1 - 1
biz-ghs/itemInfo/services/ItemInfoService.php → biz-ghs/item/services/ItemInfoService.php

@@ -4,7 +4,7 @@
  * Date Time: 2021/1/13 17:16
  */
 
-namespace bizGhs\itemInfo\services;
+namespace bizGhs\item\services;
 
 
 use bizGhs\base\services\BaseService;

+ 71 - 27
biz-ghs/item/services/ItemService.php

@@ -6,10 +6,13 @@
 
 namespace bizGhs\item\services;
 
-
 use bizGhs\base\services\BaseService;
 use bizGhs\item\classes\ItemClass;
+use bizGhs\item\classes\ItemClassClass;
+use bizGhs\item\classes\ItemInfoClass;
+use Yii;
 use common\components\util;
+use yii\db\Exception;
 
 
 class ItemService extends BaseService
@@ -21,9 +24,9 @@ class ItemService extends BaseService
         $ghsId = $data['ghsId']??0;
         $classId = $data['classId']??0;
         $itemId = $data['itemId']??0;
-
-        if(!$ghsId){
-            util::fail("请选择供应商");
+        $shopId = $data['shopId']??0;
+        if(!$ghsId || !$shopId){
+            util::fail("请选择供应商/门店");
         }
         if(!$classId){
             util::fail("请选择分类");
@@ -33,43 +36,84 @@ class ItemService extends BaseService
         }
         //判断花材是否存在 调用平台花材的方法
         //todo
-        $res = ItemClass::add($data);
-        return $res;
+
+        $existItemClass = ItemClassClass::exists(['id'=>$classId,'ghsId'=>$ghsId]);
+        if(!$existItemClass){
+            util::fail("花材分类不存在");
+        }
+        $existItem = ItemClass::exists(['itemId'=>$itemId,'ghsId'=>$ghsId]);
+        if($existItem){
+            util::fail("花材已存在");
+        }
+        $connection = Yii::$app->db;
+        $transaction = $connection->beginTransaction();
+        try{
+            //写入一条item,同时写入一条itemInfo(初始化库存)
+            ItemClass::add($data);
+            ItemInfoClass::add($data);
+            $transaction->commit();
+        }catch (Exception $exception){
+            $transaction->rollBack();
+            util::fail("新增失败");
+        }
+
     }
 
-    //批量新增花材(初始化使用)
-    public static function batchAddGhsItem($data)
+    //初始化花材
+    public static function initGhsItem($data)
     {
-        ItemClass::batchAdd($data);
-        return true;
+        $connection = Yii::$app->db;
+        $transaction = $connection->beginTransaction();
+        try{
+            ItemClass::batchAdd($data);
+            ItemInfoClass::batchAdd($data);
+            $transaction->commit();
+        }catch (\Exception $exception){
+            $transaction->rollBack();
+            util::fail("初始化失败");
+        }
     }
 
-    //修改花材的信息(库存预警、每扎加价、每扎重量)
-    public static function updateGshItem($id,$stockWarning,$unitAddPrice,$unitWeight)
+    //修改花材信息
+    public static function updateGshItem($data)
     {
-        $model = ItemClass::getById($id);
-        if(!$model){
-            util::fail("该花材不存在");
+        $id = $data['id']??0;
+        $stockWarning = $data['stockWarning']??0;
+        $unitAddPrice = $data['unitAddPrice']??0;
+        $unitWeight = $data['unitWeight']??0;
+        if($stockWarning < 0 ){
+            util::fail("库存预警不能小于0");
         }
-        $data['stockWarning'] = $stockWarning;
-        $data['unitAddPrice'] = $unitAddPrice;
-        $data['unitWeight'] = $unitWeight;
-        ItemClass::updateById($id,$data);
-        return true;
-
+        if($unitAddPrice < 0 ){
+            util::fail("每扎加价不能小于0");
+        }
+        if($unitWeight < 0 ){
+            util::fail("每扎重量不能小于0");
+        }
+        ItemClass::updateGshItem($id,$stockWarning,$unitAddPrice,$unitWeight);
     }
 
-    //删除花材
-    public static function deleteGhsItem($id)
+    //删除花材,同时修改itemInfo 的状态值 delStatus = 1
+    public static function deleteGhsItem($id,$shopId,$adminId)
     {
         $model = ItemClass::getById($id);
         if(!$model){
             util::fail("该花材不存在");
         }
-        //todo 要修改相应得花材详情表
 
-        ItemClass::deleteById($id);
-        return true;
+        $connection = Yii::$app->db;
+        $transaction = $connection->beginTransaction();
+        try{
+            ItemClass::deleteGhsItem($id);
+            $condition = [
+                'itemId'=>$model['itemId'],
+                'shopId'=>$shopId,
+            ];
+            ItemInfoClass::updateByCondition($condition,['delStatus'=>1,'adminId'=>$adminId]);
+            $transaction->commit();
+        }catch (\Exception $exception){
+            $transaction->rollBack();
+            util::fail("操作失败");
+        }
     }
-
 }

+ 0 - 22
biz-ghs/itemClass/classes/ItemClassClass.php

@@ -1,22 +0,0 @@
-<?php
-/**
- * User: admin
- * Date Time: 2021/1/13 17:12
- */
-
-namespace bizGhs\itemClass\classes;
-
-
-use bizGhs\base\classes\BaseClass;
-//use biz\base\classes\BaseClass;
-class ItemClassClass extends BaseClass
-{
-
-    public static $baseFile = '\bizGhs\itemClass\models\ItemClass';
-
-
-
-
-
-
-}