浏览代码

制作单变成工单

shish 4 年之前
父节点
当前提交
656ac8158f

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

@@ -15,15 +15,14 @@ class WastageController extends BaseController
     //新增损耗
     public function actionCreateOrder()
     {
-
         $shopAdmin = $this->shopAdmin;
         if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
             util::fail('超管才能报损');
         }
-
         $post = Yii::$app->request->post();
         $post['shopId'] = $this->shopId;
         $post['sjId'] = $this->sjId;
+        $post['mainId'] = $this->mainId;
         $post['shopAdminId'] = $this->shopAdminId;
         $shopAdmin = $this->shopAdmin;
         $adminName = $shopAdmin['name'] ?? '';

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

@@ -4,6 +4,7 @@ namespace hd\controllers;
 
 use bizGhs\order\classes\StockWastageOrderClass;
 use bizGhs\product\classes\ProductClass;
+use common\components\dict;
 use common\components\util;
 use Yii;
 
@@ -41,7 +42,21 @@ class WastageController extends BaseController
         //有unitType数据,说明是收银台传过来的数据,转换成和手机端结构一致
         $hasUnitType = array_column($productList, 'unitType');
         if (!empty($hasUnitType)) {
-
+            $newProductList = [];
+            foreach ($productList as $key => $val) {
+                $unitType = $val['unitType'] ?? 0;
+                $bigNum = 0;
+                $smallNum = 0;
+                $num = $val['num'] ?? 0;
+                $id = $val['productId'] ?? 0;
+                if ($unitType == dict::getDict('unitType', 'big')) {
+                    $bigNum = $num;
+                } else {
+                    $smallNum = $num;
+                }
+                $newProductList[] = ['productId' => $id, 'bigNum' => $bigNum, 'smallNum' => $smallNum, 'classId' => 0, 'itemId' => 0];
+            }
+            $productList = $newProductList;
         }
 
         foreach ($productList as $v) {

+ 38 - 42
biz-ghs/order/classes/StockWastageOrderClass.php

@@ -37,6 +37,7 @@ class StockWastageOrderClass extends BaseClass
 
     public static function addOrder($post)
     {
+        $mainId = $post['mainId'] ?? 0;
         $data = [];
         $data['status'] = self::STATUS_COMPLETE;
         $orderSn = orderSn::getGhsStockWastageSn();
@@ -53,48 +54,45 @@ class StockWastageOrderClass extends BaseClass
         $data['bigNum'] = $sumNum['bigNum'];
         $data['smallNum'] = $sumNum['smallNum'];
         $data['remark'] = $post['remark'] ?? '';
-        $data['mainId'] = $post['mainId'] ?? 0;
-
-        try {
-            //写入订单表
-            $order = self::add($data);
-            foreach ($ghsItemInfo as $k => $v) {
-                $stockInfo = ProductClass::decreaseStock($v['productId'], $v['bigNum'], $v['smallNum'], true);
-                $ghsItemInfo[$k]['oldStock'] = $stockInfo['oldStock'];
-                $ghsItemInfo[$k]['newStock'] = $stockInfo['newStock'];
-            }
-            //写入详情表
-            $batchData = self::groupOrderItem($ghsItemInfo, $orderSn);
-            StockWastageOrderItemClass::batchAddOrderItem($batchData);
-            $orderData = self::getOrderDetail($orderSn, $data['shopId']);
-            $orderData['shopId'] = $data['shopId'];
-            //写流水
-            StockRecordClass::addRecordByOrder($orderData, StockRecordClass::STOCK_RECORD_TYPE_WASTAGE);
-
-            $shop = ShopClass::getLockById($data['shopId']);
-            if (empty($shop)) {
-                util::fail('没有找到门店');
-            }
+        $data['mainId'] = $mainId;
+
+        //写入订单表
+        $order = self::add($data);
+        foreach ($ghsItemInfo as $k => $v) {
+            $stockInfo = ProductClass::decreaseStock($v['productId'], $v['bigNum'], $v['smallNum'], true);
+            $ghsItemInfo[$k]['oldStock'] = $stockInfo['oldStock'];
+            $ghsItemInfo[$k]['newStock'] = $stockInfo['newStock'];
+        }
+        //写入详情表
+        $batchData = self::groupOrderItem($ghsItemInfo, $orderSn);
+        StockWastageOrderItemClass::batchAddOrderItem($batchData);
+        $orderData = self::getOrderDetail($orderSn, $mainId);
+        $orderData['shopId'] = $data['shopId'];
+        //写流水
+        StockRecordClass::addRecordByOrder($orderData, StockRecordClass::STOCK_RECORD_TYPE_WASTAGE);
+
+        $shop = ShopClass::getLockById($data['shopId']);
+        if (empty($shop)) {
+            util::fail('没有找到门店');
+        }
 
-            //计算成本价
-            $wastage = 0;
-            foreach ($batchData as $v) {
-                $num = $v['itemNum'] ?? 0;
-                $cost = $v['itemCost'] ?? 0;
-                $wastage = bcadd($wastage, bcmul($num, $cost, 2), 2);
-            }
-            $currentTotalExpend = bcadd($shop->totalExpend, $wastage, 2);
-            $shop->totalExpend = $currentTotalExpend;
-            $currentWast = bcadd($shop->totalWast, $wastage, 2);
-            $shop->totalWast = $currentWast;
-            $shop->save();
+        //计算成本价
+        $wastage = 0;
+        foreach ($batchData as $v) {
+            $num = $v['itemNum'] ?? 0;
+            $cost = $v['itemCost'] ?? 0;
+            $wastage = bcadd($wastage, bcmul($num, $cost, 2), 2);
+        }
+        $currentTotalExpend = bcadd($shop->totalExpend, $wastage, 2);
+        $shop->totalExpend = $currentTotalExpend;
+        $currentWast = bcadd($shop->totalWast, $wastage, 2);
+        $shop->totalWast = $currentWast;
+        $shop->save();
 
-            StatWastClass::replace($shop, $wastage);
+        StatWastClass::replace($shop, $wastage);
+
+        return $order;
 
-            return $order;
-        } catch (\Exception $exception) {
-            util::fail("入库失败" . $exception->getMessage());
-        }
     }
 
     //2021.1.23 linqh 订单详情
@@ -117,8 +115,6 @@ class StockWastageOrderClass extends BaseClass
                 $itemData[] = $tmp;
             }
         }
-        //下面注释放开前,员工id要用shopAdminId
-        //$orderData = self::groupAdmin($orderData);
         $orderData['itemInfo'] = $itemData;
         return $orderData;
     }
@@ -128,7 +124,7 @@ class StockWastageOrderClass extends BaseClass
     {
         $orderData = self::getByCondition($where);
         if (!$orderData) {
-            util::fail('订单不存在或不能取消');
+            util::fail('订单不存在');
         }
         return $orderData;
     }

+ 10 - 10
sql.txt

@@ -58,10 +58,10 @@ ALTER TABLE xhGhsItem ADD smallRatio SMALLINT(6) NOT NULL DEFAULT '1' COMMENT '
 ALTER TABLE xhCategory ADD property TINYINT NOT NULL DEFAULT 0 COMMENT '属性 0鲜花类 1盆栽绿植花瓶类' AFTER `sjId`;
 ALTER TABLE xhGoods ADD property TINYINT NOT NULL DEFAULT 0 COMMENT '属性 0鲜花类 1盆栽绿植花瓶类' AFTER `sjId`;
 
-DROP TABLE IF EXISTS `xhMake`;
-CREATE TABLE IF NOT EXISTS `xhMake`(
+DROP TABLE IF EXISTS `xhWork`;
+CREATE TABLE IF NOT EXISTS `xhWork`(
 id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
-`makeSn` CHAR(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '制作单编号',
+`makeSn` CHAR(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '单编号',
 `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 '数量',
@@ -72,15 +72,15 @@ id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
 `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 '修改时间'
-)COMMENT='制作单';
-DROP TABLE IF EXISTS `xhMakeItem`;
-CREATE TABLE IF NOT EXISTS `xhMakeItem`(
+)COMMENT='单';
+DROP TABLE IF EXISTS `xhWorkItem`;
+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 '花材封面',
-`makeSn` CHAR(20) NOT NULL DEFAULT '' COMMENT '制作单编号',
-`itemId` INT(11) NOT NULL DEFAULT '0' COMMENT '商家花材id',
-`ptItemId` INT(11) NOT NULL DEFAULT '0' COMMENT '商家花材id',
+`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',
@@ -90,7 +90,7 @@ id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
 `smallPrice` DECIMAL(9,2) NOT NULL DEFAULT '0.00' COMMENT '小单位价格',
 `addTime` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '添加时间',
 `updateTime` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间'
-)COMMENT='制作单花材明细';
+)COMMENT='单花材明细';
 
 
 ALTER TABLE xhGoodsItem DROP COLUMN `productId`;