mainId) == false || $item->mainId != $mainId) { util::fail('没有权限'); } } //损耗处理 ssh 20220425 public static function wastage($work) { $workSn = $work->workSn ?? ''; $mainId = $work->mainId ?? 0; $sjId = $work->sjId ?? 0; $shopId = $work->shopId ?? 0; $staffId = $work->staffId ?? 0; $staffName = $work->staffName ?? ''; $itemList = self::getAllByCondition(['workSn' => $workSn], null, '*', null, true); $product = []; if (!empty($itemList)) { foreach ($itemList as $key => $item) { $wastNum = $item->wastNum ?? 0; $wastUnitType = $item->wastUnitType ?? 0; $mainId = $item->mainId ?? 0; if ($wastNum > 0) { $ptItemId = $item->ptItemId ?? 0; $productId = $item->itemId ?? 0; $bigNum = $wastUnitType == 0 ? $wastNum : 0; $smallNum = $wastUnitType == 0 ? 0 : $wastNum; $product[] = [ 'productId' => $productId, 'bigNum' => $bigNum, 'smallNum' => $smallNum, 'classId' => -1, 'itemId' => $ptItemId, ]; } } } if (empty($product)) { return true; } $data = []; $data['product'] = $product; $data['status'] = StockWastageOrderClass::STATUS_COMPLETE; $orderSn = orderSn::getGhsStockWastageSn(); $data['orderSn'] = $orderSn; $data['sjId'] = $sjId; $data['shopId'] = $shopId; $data['shopAdminId'] = $staffId; $data['shopAdminName'] = $staffName; $data['bigNum'] = 0; $data['smallNum'] = 0; $data['remark'] = '制作单报损'; $data['mainId'] = $mainId; $data['type'] = StockWastageOrderClass::WASTAGE_TYPE_WORK; $data['targetId'] = $work->id ?? 0; $data['ptStyle'] = dict::getDict('ptStyle', 'hd'); StockWastageOrderClass::addOrder($data); } //取消锁定,释放库存 ssh 20220320 public static function cancelLock($work) { //没有锁定,直接返回 if ($work->stockLock == 0) { return true; } $workSn = $work->workSn ?? ''; $sjId = $work->sjId ?? 0; $shopId = $work->shopId ?? 0; $num = $work->num ?? 0; $itemList = self::getAllByCondition(['workSn' => $workSn], null, '*', null, true); if (!empty($itemList)) { foreach ($itemList as $key => $item) { //库存回滚 $unitType = $item->unitType ?? 0; $itemId = $item->itemId ?? 0; $itemNum = $item->num ?? 0; $currentNum = bcmul($itemNum, $num); if ($currentNum > 0) { OrderGoodsClass::consumeItemByMakeGoodsCancel($workSn, $sjId, $shopId, $itemId, $currentNum, $unitType); } } } $work->stockLock = 0; $work->save(); } //修改用材 ssh 20220320 public static function modifyItem($work, $product) { $ids = array_column($product, 'productId'); if (empty($ids)) { util::fail('请选择花材哦16'); } $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; $unitPrice = $val['unitPrice'] ?? 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, 'unitPrice' => $unitPrice, ]; WorkItemClass::add($workData); } } //锁定用材 ssh 20220320 public static function lock($work) { $workSn = $work->workSn ?? ''; $sjId = $work->sjId ?? 0; $shopId = $work->shopId ?? 0; $shop = ShopClass::getById($shopId, true); if (empty($shop)) { util::fail('没有找到门店51'); } $stockModel = $shop->stockModel ?? 0; $catId = $work->catId ?? 0; $catName = $work->catName ?? ''; if (empty($catId)) { util::fail('没有分类'); } $stockLock = $work->stockLock ?? 0; if ($stockLock == 1) { util::fail('库存已锁定了'); } $list = self::getAllByCondition(['workSn' => $workSn], null, '*', null, true); if (empty($list)) { util::fail('没有花材'); } $bigNum = 0; $smallNum = 0; $workNum = $work->num; foreach ($list as $key => $item) { $unitType = $item->unitType ?? 0; $num = $item->num ?? 0; $itemId = $item->itemId ?? 0; //管到扎,不需要根据制作单上要求的作品数X花材数 if ($stockModel == 0) { $totalNum = $num; } else { $totalNum = bcmul($workNum, $num); } OrderGoodsClass::consumeItemByMakeGoods($workSn, $sjId, $shopId, $itemId, $totalNum, $unitType); $ptItemId = $item->ptItemId ?? 0; $ratio = $item->ratio ?? 0; $bigUnit = $item->bigName ?? '扎'; $smallUnit = $item->smallName ?? '支'; $itemName = $item->name ?? ''; $cover = $item->cover ?? ''; $itemData = [ 'itemId' => $itemId, 'ptItemId' => $ptItemId, 'ratio' => $ratio, 'bigUnit' => $bigUnit, 'smallUnit' => $smallUnit, 'itemName' => $itemName, 'itemCover' => $cover, ]; StatWorkCatItemClass::replace($shop, $catId, $catName, $itemData, $totalNum); } $work->bigNum = $bigNum; $work->smallNum = $smallNum; $work->stockLock = 1; $work->save(); } //获取制作单的所有花材信息 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; } }