|
|
@@ -2,10 +2,13 @@
|
|
|
|
|
|
namespace bizHd\work\classes;
|
|
|
|
|
|
+use biz\stock\classes\StockClass;
|
|
|
+use bizGhs\order\classes\StockWastageOrderClass;
|
|
|
use bizGhs\product\classes\ProductClass;
|
|
|
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;
|
|
|
@@ -15,31 +18,67 @@ class WorkItemClass extends BaseClass
|
|
|
|
|
|
public static $baseFile = '\bizHd\work\models\WorkItem';
|
|
|
|
|
|
- public static function waste($work, $wastage)
|
|
|
+ public static function valid($item, $mainId)
|
|
|
{
|
|
|
- //[{"productId":"12253","num":1,"unitType":0}]
|
|
|
- $wast = arrayUtil::arraySort($wastage, 'productId');
|
|
|
+ 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) {
|
|
|
- $itemId = $item->itemId ?? 0;
|
|
|
- $wastNum = $wast[$itemId]['num'];
|
|
|
- $wastUnitType = $wast[$itemId]['unitType'];
|
|
|
- $bigName = $item->bigName ?? '';
|
|
|
- $smallName = $item->smallName ?? '';
|
|
|
- $wastUnitName = $wastUnitType == dict::getDict('unitType', 'big') ? $bigName : $smallName;
|
|
|
-
|
|
|
- $item->wastNum = $wastNum;
|
|
|
- $item->wastUnitType = $wastUnitType;
|
|
|
- $item->wastUnitName = $wastUnitName;
|
|
|
- $item->save();
|
|
|
-
|
|
|
- //todo 相应库存扣除
|
|
|
-
|
|
|
+ $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;
|
|
|
+ StockWastageOrderClass::addOrder($data);
|
|
|
}
|
|
|
|
|
|
//取消锁定,释放库存 ssh 20220320
|