shish 4 роки тому
батько
коміт
1a8ea245e1

+ 1 - 1
app-ghs/controllers/CategoryController.php

@@ -21,7 +21,7 @@ class CategoryController extends BaseController
     {
         $get = Yii::$app->request->get();
         $property = $get['property'] ?? '';
-        $list = CategoryService::getCategoryList($this->sjId, $property);
+        $list = CategoryService::getCategoryList($this->mainId, $property);
         util::success($list);
     }
 

+ 2 - 1
app-ghs/controllers/GoodsController.php

@@ -71,6 +71,7 @@ class GoodsController extends BaseController
         $info = GoodsService::getById($id);
         GoodsService::valid($info, $this->sjId);
         $data['sjId'] = $this->sjId;
+        $data['mainId'] = $this->mainId;
         GoodsService::updateGoods($id, $data);
         util::complete();
     }
@@ -91,7 +92,7 @@ class GoodsController extends BaseController
             GoodsCategoryService::updateByCondition(['cId' => $cId, 'gId' => $id], ['inTurn' => $inTurn]);
         } else {
             GoodsService::updateById($id, ['inTurn' => $inTurn]);
-	        GoodsCategoryService::updateByCondition(['gId' => $id], ['inTurn' => $inTurn]);
+            GoodsCategoryService::updateByCondition(['gId' => $id], ['inTurn' => $inTurn]);
         }
         util::complete('操作成功');
     }

+ 1 - 1
app-ghs/controllers/PicController.php

@@ -59,7 +59,7 @@ class PicController extends BaseController
         if (empty($categoryIdList)) {
             util::fail('请选择分类');
         }
-        $merchantHas = CategoryClass::getCategoryIds($this->sjId);
+        $merchantHas = CategoryClass::getCategoryIds($this->mainId);
         $diff = array_diff($categoryIdList, $merchantHas);
         if (!empty($diff)) {
             util::fail('只能选择自己的分类');

+ 1 - 1
app-hd/controllers/CategoryController.php

@@ -84,7 +84,7 @@ class CategoryController extends BaseController
         $categoryId = Yii::$app->request->get('categoryId', 0);
         //没有分类默认取商家第一个分类
         if (empty($categoryId)) {
-            $categoryId = CategoryService::getTopCategoryId($this->sjId);
+            $categoryId = CategoryService::getTopCategoryId($this->mainId);
         }
         if (empty($categoryId)) {
             util::fail('没有找商品分类');

+ 4 - 13
app-hd/controllers/GoodsController.php

@@ -44,16 +44,6 @@ class GoodsController extends BaseController
         util::success($data);
     }
 
-    //添加商品 ssh 2019.12.7
-    public function actionAdd()
-    {
-        $data = Yii::$app->request->post();
-        $data['sjId'] = $this->sjId;
-        $return = GoodsService::addGoods($data);
-        $id = $return['id'];
-        $info = GoodsService::getById($id);
-        util::success($info);
-    }
 
     //获取商品详情 ssh 2019.12.7
     public function actionDetail()
@@ -72,6 +62,7 @@ class GoodsController extends BaseController
         $info = GoodsService::getById($id);
         GoodsService::valid($info, $this->sjId);
         $data['sjId'] = $this->sjId;
+        $data['mainId'] = $this->mainId;
         GoodsService::updateGoods($id, $data);
         util::complete();
     }
@@ -178,15 +169,15 @@ class GoodsController extends BaseController
 
     public function actionIndex()
     {
-        $classIds = CategoryService::getCategoryClassAll($this->sjId);
+        $classIds = CategoryService::getCategoryClassAll($this->mainId);
         $where['sjId'] = $this->sjId;
         $where['delStatus'] = 0;
         $goodsData = GoodsCategoryService::getGoodsAll($where);
 
         //常用的GoodsId
-        $oftenIds = GoodsCategoryService::getOftenIds($this->sjId);
+        $oftenIds = GoodsCategoryService::getOftenIds($this->mainId);
 
-        $goodsCateData = GoodsCategoryService::getEnableGoodsCategory($this->sjId);
+        $goodsCateData = GoodsCategoryService::getEnableGoodsCategory($this->mainId);
 
         //组装数据: [{classId:'','className:'',child:[{itemInfoData}]}]
         $data = GoodsCategoryService::assembleData($classIds, $goodsCateData, $goodsData, $oftenIds);

+ 1 - 1
app-hd/controllers/PicController.php

@@ -59,7 +59,7 @@ class PicController extends BaseController
         if (empty($categoryIdList)) {
             util::fail('请选择分类');
         }
-        $merchantHas = CategoryClass::getCategoryIds($this->sjId);
+        $merchantHas = CategoryClass::getCategoryIds($this->mainId);
         $diff = array_diff($categoryIdList, $merchantHas);
         if (!empty($diff)) {
             util::fail('只能选择自己的分类');

+ 1 - 2
app-hd/controllers/WastageController.php

@@ -8,7 +8,6 @@ use common\components\dict;
 use common\components\util;
 use Yii;
 
-//已中央化 ssh 20220319
 class WastageController extends BaseController
 {
 
@@ -66,7 +65,7 @@ class WastageController extends BaseController
                 util::fail('花材数量不能为0');
             }
         }
-        $connection = Yii::$app->db;//事务处理
+        $connection = Yii::$app->db;
         $transaction = $connection->beginTransaction();
         try {
             ProductClass::valid($productList, $this->mainId);

+ 123 - 3
app-hd/controllers/WorkController.php

@@ -3,6 +3,8 @@
 namespace hd\controllers;
 
 use bizHd\work\classes\WorkClass;
+use bizHd\work\classes\WorkItemClass;
+use bizHd\work\services\WorkService;
 use common\components\orderSn;
 use common\components\util;
 use Yii;
@@ -26,6 +28,17 @@ class WorkController extends BaseController
         util::success(['list' => $list]);
     }
 
+    //锁定用材 ssh 20220320
+    public function actionLock()
+    {
+        $get = Yii::$app->request->get();
+        $id = $get['id'] ?? 0;
+        $work = WorkClass::getById($id, true);
+        WorkClass::valid($work, $this->mainId);
+        WorkItemClass::lock($work);
+        util::complete();
+    }
+
     //新建工单 shish 20220319
     public function actionCreate()
     {
@@ -34,9 +47,116 @@ class WorkController extends BaseController
         $post['sjId'] = $this->sjId ?? 0;
         $post['shopId'] = $this->shopId ?? 0;
         $orderSn = orderSn::getWorkSn();
-        $post['orderSn'] = $orderSn;
-        $work = WorkClass::add($post, true);
-        util::success(['info' => $work]);
+        $post['workSn'] = $orderSn;
+
+        $connection = Yii::$app->db;
+        $transaction = $connection->beginTransaction();
+        try {
+            $product = $post['product'] ?? '';
+            $post['product'] = [];
+            if (!empty($product)) {
+                $arr = json_decode($product, true);
+                if (!empty($arr)) {
+                    $post['product'] = $arr;
+                }
+            }
+            WorkService::createFinish($post);
+            $transaction->commit();
+            util::complete();
+        } catch (\Exception $e) {
+            $transaction->rollBack();
+            Yii::error("失败原因:" . $e->getMessage());
+            util::fail('操作失败');
+        }
+    }
+
+    //成品新建制作 ssh 20220320
+    public function actionGoodsCreate()
+    {
+        $post = Yii::$app->request->post();
+        $post['mainId'] = $this->mainId ?? 0;
+        $post['sjId'] = $this->sjId ?? 0;
+        $post['shopId'] = $this->shopId ?? 0;
+
+        $connection = Yii::$app->db;
+        $transaction = $connection->beginTransaction();
+        try {
+            WorkService::GoodsCreateFinish($post);
+            $transaction->commit();
+            util::complete();
+        } catch (\Exception $e) {
+            $transaction->rollBack();
+            Yii::error("失败原因:" . $e->getMessage());
+            util::fail('操作失败');
+        }
+    }
+
+    //包括工单和用材信息 shish 20220319
+    public function actionFullInfo()
+    {
+        $get = Yii::$app->request->get();
+        $id = $get['id'] ?? 0;
+        $work = WorkClass::getById($id, true);
+        WorkClass::valid($work, $this->mainId);
+        $workItem = WorkItemClass::getWorkAllItem($work);
+        util::success(['info' => $work, 'item' => $workItem]);
+    }
+
+    //取消 ssh 20220320
+    public function actionCancel()
+    {
+        $get = Yii::$app->request->get();
+        $id = $get['id'] ?? 0;
+        $work = WorkClass::getById($id, true);
+        WorkClass::valid($work, $this->mainId);
+        WorkClass::cancel($work);
+        util::complete();
+    }
+
+    //完成工单 shish 20220319
+    public function actionFinish()
+    {
+        $post = Yii::$app->request->post();
+        $workId = $post['id'] ?? 0;
+        $wastage = $post['wastage'] ?? '';
+        $connection = Yii::$app->db;//事务处理
+        $transaction = $connection->beginTransaction();
+        try {
+            $work = WorkClass::getById($workId, true);
+            WorkClass::valid($work, $this->mainId);
+            if ($work->status == 1) {
+                util::fail('工单已完成');
+            }
+            if ($work->status == 2) {
+                util::fail('工单已取消');
+            }
+            //花材未锁定,需要锁定并扣库存
+            if ($work->hasLock == 0) {
+                WorkItemClass::lock($work);
+                $work->hasLock = 1;
+                $work->save();
+            }
+            //有报损,库存也需要扣除
+            if (!empty($wastage)) {
+                $wastage = json_decode($wastage, true);
+                if (!empty($wastage)) {
+
+                }
+            }
+            WorkClass::finish($work);
+            $transaction->commit();
+            util::complete();
+        } catch (\Exception $e) {
+            $transaction->rollBack();
+            Yii::error("失败原因:" . $e->getMessage());
+            util::fail('操作失败');
+        }
+    }
+
+    //打印
+    public function actionPrint()
+    {
+        util::complete();
     }
 
 }

+ 57 - 0
app-hd/controllers/WorkItemController.php

@@ -0,0 +1,57 @@
+<?php
+
+namespace hd\controllers;
+
+use bizGhs\product\classes\ProductClass;
+use bizHd\work\classes\WorkClass;
+use bizHd\work\classes\WorkItemClass;
+use common\components\dict;
+use common\components\util;
+use Yii;
+
+class WorkItemController extends BaseController
+{
+
+    public $guestAccess = [];
+
+    //修改用材信息
+    public function actionModifyItem()
+    {
+        $post = Yii::$app->request->post();
+        $workId = $post['id'] ?? 0;
+        $product = $post['product'] ?? '';
+        if (empty($product)) {
+            util::fail('请选择花材');
+        }
+        $product = json_decode($product, true);
+        if (empty($product)) {
+            util::fail('请选择花材哈');
+        }
+        $work = WorkClass::getById($workId, true);
+        WorkClass::valid($work, $this->mainId);
+        if ($work->hasLock == 1) {
+            util::fail('用材不可修改');
+        }
+        if ($work->status == 1) {
+            util::fail('工单已完成');
+        }
+        if ($work->status == 2) {
+            util::fail('工单已取消');
+        }
+
+
+        $connection = Yii::$app->db;//事务处理
+        $transaction = $connection->beginTransaction();
+        try {
+
+            WorkItemClass::modifyItem($work, $product);
+            $transaction->commit();
+            util::complete();
+        } catch (\Exception $e) {
+            $transaction->rollBack();
+            Yii::error("修改用材失败原因:" . $e->getMessage());
+            util::fail('修改失败');
+        }
+    }
+
+}

+ 4 - 4
biz-hd/goods/classes/CategoryClass.php

@@ -16,16 +16,16 @@ class CategoryClass extends BaseClass
     //可以使用的分类:花束 花盒 蝴蝶兰 花篮 植物 永生花 散花 充值卡 花艺课 花礼 瓶器
 
     //取出商家所有的分类 ssh 2019.12.7
-    public static function getCategoryIds($sjId)
+    public static function getCategoryIds($mainId)
     {
-        $category = self::getCategory($sjId);
+        $category = self::getCategory($mainId);
         return empty($category) ? [] : array_keys($category);
     }
 
     //获取商家分类,id作为键名 shish 2021.5.4
-    public static function getCategory($sjId)
+    public static function getCategory($mainId)
     {
-        return $category = self::getAllByCondition(['sjId' => $sjId, 'delStatus' => 0], null, '*', 'id');
+        return $category = self::getAllByCondition(['mainId' => $mainId, 'delStatus' => 0], null, '*', 'id');
     }
 
     //获取详情 ssh 2019.12.8

+ 31 - 95
biz-hd/goods/classes/GoodsClass.php

@@ -18,6 +18,7 @@ class GoodsClass extends BaseClass
     public static $baseFile = '\bizHd\goods\models\Goods';
 
     const LOCK_STOCK_GOODS = 'lock_stock_goods_';//修改库存锁
+
     //获取商品完整详情,包括商品的分类 ssh 2019.12.3
     public static function getGoodsInfo($id)
     {
@@ -39,9 +40,10 @@ class GoodsClass extends BaseClass
 
         $currentData = current($list);
         $sjId = $currentData['sjId'];
-        $rise = GoodsSettingClass::getRise($sjId);
+        $mainId = $currentData['mainId'] ?? 0;
+        $rise = GoodsSettingClass::getRise($mainId);
 
-        $sjHasCategory = CategoryClass::getCategory($sjId);
+        $sjHasCategory = CategoryClass::getCategory($mainId);
 
         foreach ($list as $key => $val) {
             $id = $val['id'];
@@ -81,76 +83,26 @@ class GoodsClass extends BaseClass
 
     public static function addGoods($data)
     {
-        $categoryIdList = isset($data['categoryIdList']) && !empty($data['categoryIdList']) ? $data['categoryIdList'] : [];
-        unset($data['categoryIdList']);
-        if (empty($categoryIdList)) {
-            util::fail('没有选择分类');
-        }
-        $goodsStyleList = isset($data['goodsStyleList']) && !empty($data['goodsStyleList']) ? $data['goodsStyleList'] : [];
-
-        if (isset($data['goodsStyle']) && $data['goodsStyle'] == 1) {
-            if (empty($goodsStyleList)) {
-                util::fail('请填写款式');
-            }
-            foreach ($goodsStyleList as $goodsStyle) {
-                if (empty($goodsStyle['styleName'])) {
-                    util::fail('请填写款式名称');
-                }
-                if (isset($goodsStyle['price']) == false || is_numeric($goodsStyle['price']) == false) {
-                    util::fail('请填写款式价格');
-                }
-                if (empty($goodsStyle['picture'])) {
-                    util::fail('请上传款式图片');
-                }
-            }
-        } else {
-            if (isset($data['price']) == false || is_numeric($data['price']) == false) {
-                util::fail('请填写商品价格');
-            }
-        }
-
-        //用商户id生成商品的编号
-        $sjId = $data['sjId'];
         $data['createTime'] = date("Y-m-d H:i:s");
-        $data['shopImg'] = json_encode($data['shopImg']);
-        $data['briefContent'] = isset($data['briefContent']) ? $data['briefContent'] : '';
-        $data['content'] = isset($data['content']) ? $data['content'] : '';
-        $data['stock'] = isset($data['stock']) && is_numeric($data['stock']) && $data['stock'] >= 0 ? $data['stock'] : Goods::FULL_STOCK;
-        $data['sold'] = isset($data['sold']) && is_numeric($data['sold']) && $data['sold'] >= 0 ? $data['sold'] : 0;
+        if (isset($data['shopImg']) && !empty($data['shopImg'])) {
+            $data['shopImg'] = json_encode($data['shopImg']);
+        }
         $data['py'] = stringUtil::py($data['name']);
-        $goodsInfo = self::add($data);
-        $id = $goodsInfo['id'];
-        $name = $goodsInfo['name'];
+        $info = self::add($data, true);
+        $id = $info->id;
+        $name = $info->name;
         $py = $data['py'] ?? '';
-
-        //处理分类
-        $categoryData = CategoryClass::getCategory($sjId);
-        $hasCategoryIds = array_keys($categoryData);
-        $diff = array_diff($categoryIdList, $hasCategoryIds);
-        if (!empty($diff)) {
-            util::fail('不能使用别人的分类');
-        }
-        $addCategory = [];
-        foreach ($categoryIdList as $categoryId) {
-            $cName = $categoryData[$categoryId]['categoryName'];
-            $addCategory[] = ['gId' => $id, 'name' => $name, 'cId' => $categoryId, 'cName' => $cName, 'sjId' => $data['sjId'], 'py' => $py];
-        }
-        GoodsCategoryClass::batchAdd($addCategory);
-        // 分类商品数+1
-        CategoryClass::counters([
-            'goodsNum' => 1
-        ], [
-            'id' => $categoryIdList
-        ]);
-        //处理款式
-        if (!empty($goodsStyleList) && $data['goodsStyle'] == 1) {
-            $addStyle = [];
-            foreach ($goodsStyleList as $goodsStyle) {
-                $addStyle[] = ['styleName' => $goodsStyle['styleName'], 'goodsId' => $id, 'picture' => $goodsStyle['picture'], 'price' => $goodsStyle['price']];
-            }
-            GoodsStyleClass::batchAdd($addStyle);
+        $sjId = $data['sjId'] ?? 0;
+        $mainId = $data['mainId'] ?? 0;
+        $categoryData = CategoryClass::getCategory($mainId);
+        $catIds = $data['catIds'] ?? [];
+        foreach ($catIds as $catId) {
+            $cName = $categoryData[$catId]['categoryName'];
+            $addCategory = ['gId' => $id, 'name' => $name, 'cId' => $catId, 'cName' => $cName, 'sjId' => $sjId, 'py' => $py, 'mainId' => $mainId];
+            GoodsCategoryClass::add($addCategory);
+            CategoryClass::counters(['goodsNum' => 1], ['id' => $catId]);
         }
-        return $goodsInfo;
+        return $info;
     }
 
     //更新商品 ssh 2019.12.7
@@ -161,12 +113,10 @@ class GoodsClass extends BaseClass
         if (empty($categoryIdList)) {
             util::fail('没有选择分类');
         }
-        $goodsStyleList = isset($data['goodsStyleList']) && !empty($data['goodsStyleList']) ? $data['goodsStyleList'] : [];
-        unset($data['goodsStyleList']);
         $py = stringUtil::py($data['name']);
-        //处理分类
-        $sjId = $data['sjId'];
-        $categoryData = CategoryClass::getCategory($sjId);
+
+        $mainId = $data['mainId'] ?? 0;
+        $categoryData = CategoryClass::getCategory($mainId);
         $hasCategoryIds = array_keys($categoryData);
         $diff = array_diff($categoryIdList, $hasCategoryIds);
         if (!empty($diff)) {
@@ -176,11 +126,7 @@ class GoodsClass extends BaseClass
         // 当前商品的分类
         $goodsHasCategoryIds = GoodsCategoryService::getGoodsHasCategoryIds($id);
         // 分类商品数-1
-        CategoryClass::counters([
-            'goodsNum' => -1
-        ], [
-            'id' => $goodsHasCategoryIds
-        ]);
+        CategoryClass::counters(['goodsNum' => -1], ['id' => $goodsHasCategoryIds]);
         GoodsCategoryClass::delGoodsCategory($id);
         $addCategory = [];
         foreach ($categoryIdList as $categoryId) {
@@ -189,17 +135,7 @@ class GoodsClass extends BaseClass
         }
         GoodsCategoryClass::batchAdd($addCategory);
         // 分类商品数+1
-        CategoryClass::counters([
-            'goodsNum' => 1
-        ], [
-            'id' => $categoryIdList
-        ]);
-
-        //处理款式
-        if (!empty($goodsStyleList) && $data['goodsStyle'] == 1) {
-            GoodsStyleClass::updateGoodsStyle($goodsStyleList, $id);
-        }
-
+        CategoryClass::counters(['goodsNum' => 1], ['id' => $categoryIdList]);
         $data['shopImg'] = json_encode($data['shopImg']);
         $data['py'] = $py;
         if (isset($data['stock']) && $data['stock'] === '') {
@@ -246,7 +182,7 @@ class GoodsClass extends BaseClass
 
     //库存变动入口
     //加库存
-    public static function addStock($goodsId,$mainId,$num)
+    public static function addStock($goodsId, $mainId, $num)
     {
         $key = self::LOCK_STOCK_GOODS . '_' . $goodsId;
         $lock = util::lock($key);
@@ -259,7 +195,7 @@ class GoodsClass extends BaseClass
             util::fail("成品不存在");
         }
         $goodsMainId = $goodsData['mainId'];
-        if($mainId !== $goodsMainId){
+        if ($mainId != $goodsMainId) {
             util::unlock($key);
             util::fail("非法参数");
         }
@@ -267,13 +203,13 @@ class GoodsClass extends BaseClass
         //改库存
         $newStock = $goodsData['stock'] + $num;
         $data['stock'] = $newStock;
-        self::updateById($goodsId,$data);
+        self::updateById($goodsId, $data);
         util::unlock($key);
         return ['oldStock' => $goodsData['stock'], 'newStock' => $newStock];
     }
 
     //减库存
-    public static function decreaseStock($goodsId,$mainId,$num)
+    public static function decreaseStock($goodsId, $mainId, $num)
     {
         $key = self::LOCK_STOCK_GOODS . '_' . $goodsId;
         $lock = util::lock($key);
@@ -286,7 +222,7 @@ class GoodsClass extends BaseClass
             util::fail("成品不存在");
         }
         $goodsMainId = $goodsData['mainId'];
-        if($mainId !== $goodsMainId){
+        if ($mainId != $goodsMainId) {
             util::unlock($key);
             util::fail("非法参数");
         }
@@ -294,7 +230,7 @@ class GoodsClass extends BaseClass
         //改库存
         $newStock = $goodsData['stock'] - $num;
         $data['stock'] = $newStock;
-        self::updateById($goodsId,$data);
+        self::updateById($goodsId, $data);
         util::unlock($key);
         return ['oldStock' => $goodsData['stock'], 'newStock' => $newStock];
     }

+ 3 - 3
biz-hd/goods/classes/GoodsSettingClass.php

@@ -18,9 +18,9 @@ class GoodsSettingClass extends BaseClass
     public static $baseFile = '\bizHd\goods\models\GoodsSetting';
 
     //获取商品涨价比例或金额 ssh 2020.5.20
-    public static function getRise($sjId)
+    public static function getRise($mainId)
     {
-        $festRise = FestRiseClass::getAllByCondition(['sjId' => $sjId], null, 'festId', 'festId');
+        $festRise = FestRiseClass::getAllByCondition(['mainId' => $mainId], null, 'festId', 'festId');
         if (empty($festRise)) {
             return [];
         }
@@ -36,7 +36,7 @@ class GoodsSettingClass extends BaseClass
         if (in_array($today, $arr) == false) {
             return [];
         }
-        $set = self::getByCondition(['sjId' => $sjId]);
+        $set = self::getByCondition(['mainId' => $mainId]);
         if (empty($set)) {
             util::fail('没有找到涨价需求');
         }

+ 5 - 8
biz-hd/goods/services/GoodsCategoryService.php

@@ -107,21 +107,18 @@ class GoodsCategoryService extends BaseService
     }
 
     //获取商家下 所有启用的商品分类
-    public static function getEnableGoodsCategory($sjId)
+    public static function getEnableGoodsCategory($mainId)
     {
-        $cat = CategoryService::getEnableList($sjId);
-        $where = [
-            'sjId' => $sjId,
-            'cId' => ['in', array_column($cat, 'id')],
-        ];
+        $cat = CategoryService::getEnableList($mainId);
+        $where = ['mainId' => $mainId,'cId' => ['in', array_column($cat, 'id')]];
         $data = self::getAllList('cId as classId,gId', $where);
         return $data;
     }
 
 	//获取常用分类的 goods id  linqh 2021.04.09
-    public static function getOftenIds($sjId)
+    public static function getOftenIds($mainId)
     {
-        $data = GoodsClass::getLimitList("id", ['sjId' => $sjId], 10,'actualSold desc');
+        $data = GoodsClass::getLimitList("id", ['mainId' => $mainId], 10,'actualSold desc');
         if ($data) {
             $data = array_column($data, 'id');
         }

+ 0 - 6
biz-hd/goods/services/GoodsService.php

@@ -52,12 +52,6 @@ class GoodsService extends BaseService
         GoodsClass::deleteGoods($goods['id']);
     }
 
-    //添加商品 ssh 2019.12.7
-    public static function addGoods($data)
-    {
-        return GoodsClass::addGoods($data);
-    }
-
     //更新商品 ssh 2019.12.7
     public static function updateGoods($id, $data)
     {

+ 3 - 1
biz-hd/order/classes/OrderGoodsClass.php

@@ -103,7 +103,7 @@ class OrderGoodsClass extends BaseClass
     public static function addGoodsStockByMakeGoods($orderSn,$sjId,$shopId,$mainId,$goodsId,$goodsNum)
     {
         //加成品库存
-        GoodsClass::addStock($goodsId,$mainId,$goodsNum);
+        $respond = GoodsClass::addStock($goodsId,$mainId,$goodsNum);
         //成品流水记录
         $data = [];
         $data['sjId'] = $sjId;
@@ -112,6 +112,8 @@ class OrderGoodsClass extends BaseClass
         $data['orderSn'] = $orderSn;
         $data['goodsId'] = $goodsId;
         $data['goodsNum'] = $goodsNum;
+        $data['oldStock'] = $respond['oldStock'] ?? 0;
+        $data['newStock'] = $respond['newStock'] ?? 0;
         GoodsStockRecordClass::addMakeGoods($data);
         return true;
     }

+ 72 - 1
biz-hd/work/classes/WorkClass.php

@@ -2,8 +2,10 @@
 
 namespace bizHd\work\classes;
 
+use bizHd\goods\classes\GoodsClass;
+use bizHd\order\classes\OrderGoodsClass;
 use common\components\imgUtil;
-use Yii;
+use common\components\util;
 use bizHd\base\classes\BaseClass;
 
 class WorkClass extends BaseClass
@@ -11,6 +13,75 @@ class WorkClass extends BaseClass
 
     public static $baseFile = '\bizHd\work\models\Work';
 
+    const STATUS_UN_COMPLETE = 0;
+    const STATUS_COMPLETE = 1;
+    const STATUS_CANCEL = 2;
+
+    public static function cancel($work)
+    {
+        if ($work->status == self::STATUS_COMPLETE) {
+            util::fail('订单已完成');
+        }
+        if ($work->status == self::STATUS_CANCEL) {
+            util::fail('订单已取消');
+        }
+        if (isset($work->orderSn) && !empty($work->orderSn)) {
+            util::fail('此工单有订单,请通过订单取消');
+        }
+        //取消锁定,释放库存
+        WorkItemClass::cancelLock($work);
+        $work->status = self::STATUS_CANCEL;
+        $work->save();
+
+    }
+
+    //完成工单 ssh 20220320
+    public static function finish($work)
+    {
+        $work->status = self::STATUS_COMPLETE;
+        $work->save();
+
+        $num = $work->num ?? 0;
+        $mainId = $work->mainId ?? 0;
+        $workSn = $work->workSn ?? '';
+        $sjId = $work->sjId ?? 0;
+        $shopId = $work->shopId ?? 0;
+        $goodsId = $work->goodsId ?? 0;
+        //没有商品生成商品
+        if (empty($goodsId)) {
+            $name = $work->name ?? '';
+            $catId = $work->catId ?? 0;
+            $date = date("Y-m-d H:i:s");
+            $goodsData = [
+                'mainId' => $mainId,
+                'name' => $name,
+                'content' => '',
+                'createTime' => $date,
+                'sjId' => $sjId,
+                'mainId' => $mainId,
+            ];
+            if (!empty($catId)) {
+                $goodsData['catIds'] = [$catId];
+            }
+            $goods = GoodsClass::addGoods($goodsData);
+            $goodsId = $goods->id ?? 0;
+        }
+        //库存增加
+        OrderGoodsClass::addGoodsStockByMakeGoods($workSn, $sjId, $shopId, $mainId, $goodsId, $num);
+    }
+
+    //验证工单 shish 20220319
+    public static function valid($work, $mainId)
+    {
+        if (empty($work)) {
+            util::fail('没有找到工单');
+        }
+        if (isset($work->mainId) == false || $work->mainId != $mainId) {
+            util::fail('没有权限');
+        }
+        return true;
+    }
+
     public static function getWorkList($where)
     {
         $data = self::getList('*', $where);

+ 134 - 0
biz-hd/work/classes/WorkItemClass.php

@@ -0,0 +1,134 @@
+<?php
+
+namespace bizHd\work\classes;
+
+use bizGhs\product\classes\ProductClass;
+use common\components\dict;
+use common\components\imgUtil;
+use common\components\util;
+use Yii;
+use bizHd\base\classes\BaseClass;
+
+class WorkItemClass extends BaseClass
+{
+
+    public static $baseFile = '\bizHd\work\models\WorkItem';
+
+    //取消锁定,释放库存 ssh 20220320
+    public static function cancelLock($work)
+    {
+        //没有锁定,直接返回
+        if ($work->hasLock == 0) {
+            return true;
+        }
+        $workSn = $work->workSn ?? '';
+        $itemList = self::getAllByCondition(['workSn' => $workSn], null, '*', null, true);
+        if (!empty($itemList)) {
+            foreach ($itemList as $key => $item) {
+
+            }
+        }
+        $work->hasLock = 0;
+        $work->save();
+    }
+
+    //修改用材 ssh 20220320
+    public static function modifyItem($work, $product)
+    {
+        $ids = array_column($product, 'productId');
+        if (empty($ids)) {
+            util::fail('请选择花材哦');
+        }
+        $info = ProductClass::getByIds($ids, null, 'id');
+        $sjId = $work->sjId ?? 0;
+        $shopId = $work->shopId ?? 0;
+        $mainId = $work->mainId ?? 0;
+        $workSn = $work->workSn ?? '';
+
+        WorkItemClass::deleteByCondition(['workSn' => $workSn]);
+
+        foreach ($product as $key => $val) {
+            $id = $val['productId'] ?? 0;
+            $num = $val['num'] ?? 0;
+            $unitType = $val['unitType'] ?? 0;
+            $name = $info[$id]['name'] ?? '';
+            $cover = $info[$id]['cover'] ?? '';
+            $ptItemId = $info[$id]['itemId'] ?? 0;
+            $unitCost = $info[$id]['cost'] ?? 0;
+            $ratio = $info[$id]['ratio'] ?? 0;
+            $bigName = $info[$id]['bigUnit'] ?? '';
+            $smallName = $info[$id]['smallUnit'] ?? '';
+            if ($unitType == dict::getDict('unitType', 'big')) {
+                $count = $num;
+                $cost = bcmul($unitCost, $num, 2);
+                $unitName = $bigName;
+            } else {
+                $count = bcdiv($num, $ratio, 2);
+                $cost = bcmul($unitCost, $count, 2);
+                $unitName = $smallName;
+            }
+            $workData = [
+                'name' => $name,
+                'cover' => $cover,
+                'workSn' => $workSn,
+                'itemId' => $id,
+                'ptItemId' => $ptItemId,
+                'sjId' => $sjId,
+                'shopId' => $shopId,
+                'mainId' => $mainId,
+                'num' => $num,
+                'unitType' => $unitType,
+                'unitName' => $unitName,
+                'count' => $count,
+                'unitCost' => $unitCost,
+                'cost' => $cost,
+                'ratio' => $ratio,
+                'bigName' => $bigName,
+                'smallName' => $smallName,
+            ];
+            WorkItemClass::add($workData);
+        }
+    }
+
+    //锁定用材 ssh 20220320
+    public static function lock($work)
+    {
+        if ($work->hasLock == 1) {
+            return false;
+        }
+        //todo 库存需要扣除
+    }
+
+    //获取工单的所有花材信息 ssh 20220320
+    public static function getWorkAllItem($work)
+    {
+        $workSn = $work->workSn ?? '';
+        $list = self::getAllByCondition(['workSn' => $workSn], null, '*');
+        if (empty($list)) {
+            return $list;
+        }
+        return self::groupInfo($list);
+    }
+
+    //组合信息
+    public static function groupInfo($list)
+    {
+        if (empty($list)) {
+            return $list;
+        }
+        foreach ($list as $key => $val) {
+            $shortCover = $val['cover'] ?? '';
+            $cover = imgUtil::groupImg('');
+            $bigCover = imgUtil::groupImg('');
+            if (!empty($shortCover)) {
+                $cover = self::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_110,w_110";
+                $bigCover = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
+            }
+            $list[$key]['cover'] = $cover;
+            $list[$key]['bigCover'] = $bigCover;
+            $list[$key]['shortCover'] = $shortCover;
+        }
+        return $list;
+    }
+
+}

+ 13 - 0
biz-hd/work/models/WorkItem.php

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

+ 13 - 0
biz-hd/work/services/WorkItemService.php

@@ -0,0 +1,13 @@
+<?php
+
+namespace bizHd\work\services;
+
+use bizHd\base\services\BaseService;
+use Yii;
+
+class WorkItemService extends BaseService
+{
+
+    public static $baseFile = '\bizHd\work\classes\WorkItemClass';
+
+}

+ 74 - 0
biz-hd/work/services/WorkService.php

@@ -3,6 +3,13 @@
 namespace bizHd\work\services;
 
 use bizHd\base\services\BaseService;
+use bizHd\goods\classes\CategoryClass;
+use bizHd\goods\classes\GoodsCategoryClass;
+use bizHd\goods\classes\GoodsClass;
+use bizHd\goods\classes\GoodsItemClass;
+use bizHd\work\classes\WorkClass;
+use bizHd\work\classes\WorkItemClass;
+use common\components\util;
 use Yii;
 
 class WorkService extends BaseService
@@ -10,4 +17,71 @@ class WorkService extends BaseService
 
     public static $baseFile = '\bizHd\work\classes\WorkClass';
 
+    public static function GoodsCreateFinish($data)
+    {
+        $goods = $data['goods'] ?? '';
+        $goods = json_decode($goods, true);
+        if (empty($goods)) {
+            util::fail('没有找到成品');
+        }
+        $remark = $data['remark'] ?? '';
+        $ids = array_column($goods, 'productId');
+        $info = GoodsClass::getByIds($ids, null, 'id');
+        foreach ($goods as $key => $val) {
+            $goodsId = $goods['productId'] ?? 0;
+            $name = $info[$goodsId]['name'] ?? '';
+            $num = $val['num'] ?? 0;
+            $cover = $info[$goodsId]['cover'] ?? '';
+
+            $product = [];
+            $goodsItem = GoodsItemClass::getAllByCondition(['goodsId' => $goodsId], null, '*');
+            if (!empty($goodsItem)) {
+                foreach ($goodsItem as $one) {
+                    $itemId = $one['itemId'] ?? 0;
+                    $unitType = $one['unitType'] ?? 0;
+                    $num = $one['num'] ?? 0;
+                    $product[] = [
+                        'productId' => $itemId,
+                        'num' => $num,
+                        'unitType' => $unitType,
+                    ];
+                }
+            }
+            $goodsCat = GoodsCategoryClass::getByCondition(['gId' => $goodsId], true);
+            $catId = $goodsCat->cId ?? 0;
+            $catName = '';
+            if (!empty($catId)) {
+                $cat = CategoryClass::getById($catId, true);
+                $catName = $cat->categoryName ?? '';
+            }
+            $current = [
+                'name' => $name,
+                'num' => $num,
+                'cover' => $cover,
+                'remark' => $remark,
+                'catId' => $catId,
+                'catName' => $catName,
+                'product' => $product,
+                'goodsId' => $goodsId,
+            ];
+            self::createFinish($current);
+        }
+    }
+
+    public static function createFinish($data)
+    {
+        $work = WorkClass::add($data, true);
+        $product = $data['product'] ?? [];
+        //有花材传入,花艺师制作直接完成
+        if (!empty($product)) {
+            //修改用材
+            WorkItemClass::modifyItem($work, $product);
+            //锁定并扣库存
+            WorkItemClass::lock($work);
+            //完成
+            WorkClass::finish($work);
+        }
+        return $work;
+    }
+
 }

+ 6 - 4
biz-mall/goods/classes/GoodsClass.php

@@ -36,8 +36,8 @@ class GoodsClass extends BaseClass
 
         //注意这里涉及商家节日涨价的问题,不要去取不同商家的商品,确有必要另外起方法!!!!!!
 
-		$currentData = current($list);
-		$sjId = $currentData['sjId'];
+        $currentData = current($list);
+        $sjId = $currentData['sjId'];
         $rise = GoodsSettingClass::getRise($sjId);
 
         foreach ($list as $key => $val) {
@@ -115,7 +115,8 @@ class GoodsClass extends BaseClass
         $name = $goodsInfo['name'];
 
         //处理分类
-        $hasCategoryIdList = CategoryClass::getCategoryIds($sjId);
+        $mainId = $data['mainId'] ?? 0;
+        $hasCategoryIdList = CategoryClass::getCategoryIds($mainId);
         $diff = array_diff($categoryIdList, $hasCategoryIdList);
         if (!empty($diff)) {
             util::fail('您使用了别人的分类');
@@ -149,7 +150,8 @@ class GoodsClass extends BaseClass
 
         //处理分类
         $sjId = $data['sjId'];
-        $merchantHasCategoryIdList = CategoryClass::getCategoryIds($sjId);
+        $mainId = $data['mainId'] ?? 0;
+        $merchantHasCategoryIdList = CategoryClass::getCategoryIds($mainId);
         $diff = array_diff($categoryIdList, $merchantHasCategoryIdList);
         if (!empty($diff)) {
             util::fail('您使用了别人的分类');

+ 2 - 2
biz-mall/goods/services/CategoryService.php

@@ -52,9 +52,9 @@ class CategoryService extends BaseService
     }
 
     //取出商家所有的分类ID ssh 2019.12.7
-    public static function getCategoryIdList($sjId)
+    public static function getCategoryIdList($mainId)
     {
-        return CategoryClass::getCategoryIds($sjId);
+        return CategoryClass::getCategoryIds($mainId);
     }
 
 

+ 12 - 3
console/controllers/InitController.php

@@ -28,6 +28,8 @@ use bizGhs\stat\classes\StatYjMonthClass;
 use bizHd\goods\classes\CategoryClass;
 use bizHd\goods\classes\GoodsCategoryClass;
 use bizHd\goods\classes\GoodsClass;
+use bizHd\goods\classes\GoodsSettingClass;
+use bizHd\saas\classes\FestRiseClass;
 use bizHd\stat\classes\StatOrderClass;
 use bizHd\stat\classes\StatOrderMonthClass;
 use bizHd\stat\classes\StatUserClass;
@@ -116,7 +118,7 @@ class InitController extends Controller
             }
 
 
-            //花材中央化
+            //花材
             ItemClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
             //花材分类
             ItemClassClass::updateByCondition(['sjId' => $shop->sjId], ['mainId' => $mainId]);
@@ -147,16 +149,23 @@ class InitController extends Controller
 
             $sjId = $shop->sjId ?? 0;
             $shopId = $shop->id ?? 0;
+            //商品
             GoodsClass::updateByCondition(['sjId' => $sjId], ['mainId' => $mainId]);
             GoodsCategoryClass::updateByCondition(['sjId' => $sjId], ['mainId' => $mainId]);
 
+            //商品分类
             CategoryClass::updateByCondition(['sjId' => $sjId], ['mainId' => $mainId]);
 
+            GoodsSettingClass::updateByCondition(['sjId' => $sjId], ['mainId' => $mainId]);
+
+            FestRiseClass::updateByCondition(['sjId' => $sjId], ['mainId' => $mainId]);
+
             /********琦海 start ************/
 
-            //花材中央化
+            //花材
             ItemClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
-
+            //花材分类
+            ItemClassClass::updateByCondition(['sjId' => $shop->sjId], ['mainId' => $mainId]);
 
             /********琦海 end ************/
 

+ 46 - 12
sql.txt

@@ -70,13 +70,14 @@ id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
 `orderSn` CHAR(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '关联订单编号',
 `orderId` INT NOT NULL DEFAULT 0 COMMENT '关联订单id',
 `num` SMALLINT NOT NULL DEFAULT 0 COMMENT '数量',
-`categoryId` INT NOT NULL DEFAULT 0 COMMENT '分类id',
+`catId` INT NOT NULL DEFAULT 0 COMMENT '分类id',
+`catName` varchar(50) not null default '' comment '分类名称',
 `goodsId` INT NOT NULL DEFAULT 0 COMMENT '商品id',
 `from` TINYINT NOT NULL DEFAULT 0 COMMENT '来源 0门店下单 1小程序下单...',
 `remark` VARCHAR(1000) NOT NULL DEFAULT '' COMMENT '备注',
 `staffId` int not null default 0 comment '负责人',
 `staffName` varchar(100) not null default '' comment '负责人名称',
-`confirm` tinyint not null default 0 comment '确认花材 0未确认 1已确认',
+`hasLock` tinyint not null default 0 comment '0未锁定,可以修改花材 1锁定了,不可修改',
 `status` TINYINT NOT NULL DEFAULT 0 COMMENT '状态 0待完成 1已完成 2已取消',
 `addTime` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '添加时间',
 `updateTime` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间'
@@ -86,25 +87,50 @@ CREATE TABLE IF NOT EXISTS `xhWorkItem`(
 id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
 `name` VARCHAR(100) NOT NULL DEFAULT '' COMMENT '花材名称',
 `cover` VARCHAR(500) NOT NULL DEFAULT '' COMMENT '花材封面',
+`price` DECIMAL(9,2) NOT NULL DEFAULT '0.00' COMMENT '售价',
 `workSn` CHAR(20) NOT NULL DEFAULT '' COMMENT '工单编号',
 `itemId` INT(11) NOT NULL DEFAULT '0' COMMENT '花材id',
 `ptItemId` INT(11) NOT NULL DEFAULT '0' COMMENT '平台花材id',
 `sjId` INT(11) NOT NULL DEFAULT '0' COMMENT '商家id',
 `shopId` INT(11) NOT NULL DEFAULT '0' COMMENT '门店id',
 `mainId` INT(11) NOT NULL DEFAULT '0' COMMENT '中央id',
-`num` DECIMAL(10,2) NOT NULL DEFAULT '0.00' COMMENT '数量,包括大小单位总合',
-`cost` DECIMAL(9,2) NOT NULL DEFAULT '0.00' COMMENT '花材单位成本',
-`bigPrice` DECIMAL(9,2) NOT NULL DEFAULT '0.00' COMMENT '大单位价格',
-`smallPrice` DECIMAL(9,2) NOT NULL DEFAULT '0.00' COMMENT '小单位价格',
+`num` INT NOT NULL DEFAULT 0 COMMENT '数量',
+`count` DECIMAL(10,2) NOT NULL DEFAULT '0.00' COMMENT '带小数点的数量',
+`ratio` SMALLINT NOT NULL DEFAULT 0 COMMENT '比例',
+`bigName` CHAR(10) NOT NULL DEFAULT '' COMMENT '大单位名称',
+`smallName` CHAR(10) NOT NULL DEFAULT '' COMMENT '小单位名称',
+`unitType` TINYINT NOT NULL DEFAULT 0 COMMENT '当前单位类型 0大单位 1小单位',
+`unitName` CHAR(10) NOT NULL DEFAULT '' COMMENT '当前单位名称',
+`unitCost` DECIMAL(9,2) NOT NULL DEFAULT '0.00' COMMENT '单位成本',
+`cost` DECIMAL(9,2) NOT NULL DEFAULT '0.00' COMMENT '总成本',
+`wastNum` INT NOT NULL DEFAULT 0 COMMENT '报损数量',
+`wastUnitType` TINYINT NOT NULL DEFAULT 0 COMMENT '报损单位类型 0大单位 1小单位',
+`wastUnitId` INT NOT NULL DEFAULT 0 COMMENT '报损单位id',
+`wastUnitName` CHAR(10) NOT NULL DEFAULT '' COMMENT '报损单位名称',
 `addTime` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '添加时间',
 `updateTime` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间'
 )COMMENT='工单花材明细';
 
-
-ALTER TABLE xhGoodsItem DROP COLUMN `productId`;
-ALTER TABLE xhGoodsItem DROP COLUMN `itemId`;
-ALTER TABLE xhGoodsItem ADD itemId INT NOT NULL DEFAULT 0 COMMENT '花材id' AFTER `goodsId`;
-ALTER TABLE xhGoodsItem ADD ptItemId INT NOT NULL DEFAULT 0 COMMENT '平台花材id' AFTER `itemId`;
+DROP TABLE IF EXISTS `xhGoodsItem`;
+CREATE TABLE `xhGoodsItem` (
+`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
+`sjId` INT(11) NOT NULL DEFAULT '0' COMMENT '商户id',
+`shopId` INT NOT NULL DEFAULT 0 COMMENT '门店id',
+`mainId` INT NOT NULL DEFAULT 0 COMMENT '中央id',
+`goodsId` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '成品ID',
+`itemId` INT(11) NOT NULL DEFAULT '0' COMMENT '花材id',
+`ptItemId` INT(11) NOT NULL DEFAULT '0' COMMENT '平台花材id',
+`num` INT NOT NULL DEFAULT 0 COMMENT '数量',
+`count` DECIMAL(10,2) NOT NULL DEFAULT '0.00' COMMENT '带小数点的数量',
+`ratio` SMALLINT NOT NULL DEFAULT 0 COMMENT '比例',
+`bigName` CHAR(10) NOT NULL DEFAULT '' COMMENT '大单位名称',
+`smallName` CHAR(10) NOT NULL DEFAULT '' COMMENT '小单位名称',
+`unitType` TINYINT NOT NULL DEFAULT 0 COMMENT '当前单位类型 0大单位 1小单位',
+`unitName` CHAR(10) NOT NULL DEFAULT '' COMMENT '当前单位名称',
+`addTime` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '添加时间',
+`updateTime` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
+PRIMARY KEY (`id`)
+) COMMENT='成品的花材';
 
 DROP TABLE IF EXISTS `xhHdRefund`;
 CREATE TABLE IF NOT EXISTS `xhHdRefund` (
@@ -488,4 +514,12 @@ CREATE TABLE `xhWorkSn` (
   PRIMARY KEY (`id`)
 ) AUTO_INCREMENT=126520 COMMENT='工单号';
 
-====商品分类中央化 shish 20220319
+====商品分类中央化 shish 20220319
+
+ALTER TABLE xhWorkItem ADD INDEX `workSn`(`workSn`);
+ALTER TABLE xhGoodsSetting ADD mainId INT NOT NULL DEFAULT 0 COMMENT '中央id' AFTER `id`;
+ALTER TABLE xhGoodsCategory DROP INDEX `merchantId`;
+ALTER TABLE xhGoodsCategory ADD INDEX `mainId`(`mainId`,`cId`);
+ALTER TABLE xhGoods MODIFY `stock` INT(11) NOT NULL DEFAULT 0 COMMENT '库存';
+UPDATE xhGoods SET stock=0;
+ALTER TABLE xhFestRise ADD mainId INT NOT NULL DEFAULT 0 COMMENT '中央id' AFTER id;