| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274 |
- <?php
- namespace bizHd\work\classes;
- use biz\stock\classes\StockClass;
- use bizGhs\order\classes\StockWastageOrderClass;
- use bizGhs\product\classes\ProductClass;
- use bizHd\order\classes\OrderGoodsClass;
- use bizHd\shop\classes\ShopClass;
- use bizHd\stat\classes\StatWorkCatItemClass;
- use common\components\arrayUtil;
- use common\components\dict;
- use common\components\imgUtil;
- use common\components\orderSn;
- use common\components\util;
- use Yii;
- use bizHd\base\classes\BaseClass;
- class WorkItemClass extends BaseClass
- {
- public static $baseFile = '\bizHd\work\models\WorkItem';
- public static function valid($item, $mainId)
- {
- if (empty($item)) {
- util::fail('没有找到数据');
- }
- if (isset($item->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('请选择花材哦');
- }
- $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;
- }
- }
|