|
|
@@ -194,7 +194,7 @@ class BookItemClass extends BaseClass
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //数据结构 [['productId' => $productId,'num' => $num]]
|
|
|
+ //批量添加预订花材 ssh 20240711
|
|
|
public static function addBatchItem($batchData, $order)
|
|
|
{
|
|
|
$shopId = $order->shopId ?? 0;
|
|
|
@@ -210,7 +210,7 @@ class BookItemClass extends BaseClass
|
|
|
$shopName = $shop->shopName ?? '';
|
|
|
$currentName = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
|
|
|
noticeUtil::push($currentName . ' 没有开启预订', '15280215347');
|
|
|
- util::fail('请先开启预订');
|
|
|
+ util::fail('请开启预订');
|
|
|
}
|
|
|
}
|
|
|
$mainId = $order->mainId ?? 0;
|
|
|
@@ -242,9 +242,15 @@ class BookItemClass extends BaseClass
|
|
|
util::fail($name . '没有设置采购人');
|
|
|
}
|
|
|
}
|
|
|
- //总花材新增预订
|
|
|
- $stat = self::getByCondition(['mainId' => $mainId, 'bookSn' => $bookSn, 'itemId' => $itemId,], true);
|
|
|
- if (empty($stat)) {
|
|
|
+
|
|
|
+ $cacheKey = 'add_need_cg_num_' . $itemId;
|
|
|
+ $noLock = util::lock($cacheKey);
|
|
|
+ if (!$noLock) {
|
|
|
+ util::fail("系统繁忙,1秒后再提交");
|
|
|
+ }
|
|
|
+
|
|
|
+ $bookItemRes = self::getByCondition(['mainId' => $mainId, 'bookSn' => $bookSn, 'itemId' => $itemId,], true);
|
|
|
+ if (empty($bookItemRes)) {
|
|
|
$statData = [
|
|
|
'mainId' => $mainId,
|
|
|
'itemId' => $itemId,
|
|
|
@@ -255,30 +261,23 @@ class BookItemClass extends BaseClass
|
|
|
'cgStaffId' => $cgStaffId,
|
|
|
'cgStaffName' => $cgStaffName
|
|
|
];
|
|
|
- $stat = self::add($statData, true);
|
|
|
+ $bookItemRes = self::add($statData, true);
|
|
|
}
|
|
|
- $id = $stat->id;
|
|
|
- $unique = self::getLockById($id);
|
|
|
-
|
|
|
+ $bookItemResId = $bookItemRes->id;
|
|
|
+ $bookItemRes = self::getLockById($bookItemResId);
|
|
|
$currentStock = $product->stock;
|
|
|
- $hasNum = bcadd($currentStock, $unique->roadNum);
|
|
|
- $overNum = $unique->bookNum > $hasNum ? 0 : bcsub($hasNum, $unique->bookNum);
|
|
|
+ $totalHasNum = bcadd($currentStock, $bookItemRes->roadNum);
|
|
|
+ $overNum = $bookItemRes->bookNum > $totalHasNum ? 0 : bcsub($totalHasNum, $bookItemRes->bookNum);
|
|
|
//新增待采数量 = 预订数量 - 超出库存
|
|
|
$needCgNumValue = bcsub($num, $overNum);
|
|
|
$addNeedCgNum = $needCgNumValue < 0 ? 0 : $needCgNumValue;
|
|
|
- $key = 'add_need_cg_num_' . $itemId;
|
|
|
- $lock = util::lock($key);
|
|
|
- if (!$lock) {
|
|
|
- util::fail("系统繁忙,请重试");
|
|
|
- }
|
|
|
+ $currentNum = bcadd($bookItemRes->bookNum, $num);
|
|
|
+ $bookItemRes->bookNum = $currentNum;
|
|
|
+ $bookItemRes->needCgNum = bcadd($bookItemRes->needCgNum, $addNeedCgNum);
|
|
|
+ $bookItemRes->save();
|
|
|
|
|
|
- $currentNum = bcadd($unique->bookNum, $num);
|
|
|
- $unique->bookNum = $currentNum;
|
|
|
- $unique->needCgNum = bcadd($unique->needCgNum, $addNeedCgNum);
|
|
|
- $unique->save();
|
|
|
- //客户花材新增预订
|
|
|
- $has = BookItemCustomClass::getByCondition(['mainId' => $mainId, 'bookSn' => $bookSn, 'customId' => $customId, 'itemId' => $itemId], true);
|
|
|
- if (empty($has)) {
|
|
|
+ $bookItemCustomRes = BookItemCustomClass::getByCondition(['mainId' => $mainId, 'bookSn' => $bookSn, 'customId' => $customId, 'itemId' => $itemId], true);
|
|
|
+ if (empty($bookItemCustomRes)) {
|
|
|
$currentData = [
|
|
|
'name' => $name,
|
|
|
'py' => $py,
|
|
|
@@ -293,16 +292,16 @@ class BookItemClass extends BaseClass
|
|
|
'cgStaffName' => $cgStaffName,
|
|
|
'bookSn' => $bookSn,
|
|
|
];
|
|
|
- $has = BookItemCustomClass::add($currentData, true);
|
|
|
+ $bookItemCustomRes = BookItemCustomClass::add($currentData, true);
|
|
|
}
|
|
|
- $hasId = $has->id ?? 0;
|
|
|
- $has = BookItemCustomClass::getLockById($hasId);
|
|
|
- $has->bookNum = bcadd($has->bookNum, $num);
|
|
|
- $has->needCgNum = bcadd($has->needCgNum, $addNeedCgNum);
|
|
|
- $has->save();
|
|
|
- //客户新增预订
|
|
|
- $has = BookCustomClass::getByCondition(['mainId' => $mainId, 'bookSn' => $bookSn, 'customId' => $customId], true);
|
|
|
- if (empty($has)) {
|
|
|
+ $bookItemCustomResId = $bookItemCustomRes->id ?? 0;
|
|
|
+ $bookItemCustomRes = BookItemCustomClass::getLockById($bookItemCustomResId);
|
|
|
+ $bookItemCustomRes->bookNum = bcadd($bookItemCustomRes->bookNum, $num);
|
|
|
+ $bookItemCustomRes->needCgNum = bcadd($bookItemCustomRes->needCgNum, $addNeedCgNum);
|
|
|
+ $bookItemCustomRes->save();
|
|
|
+
|
|
|
+ $bookCustomRes = BookCustomClass::getByCondition(['mainId' => $mainId, 'bookSn' => $bookSn, 'customId' => $customId], true);
|
|
|
+ if (empty($bookCustomRes)) {
|
|
|
$currentData = [
|
|
|
'name' => $customName,
|
|
|
'py' => $customNamePy,
|
|
|
@@ -311,14 +310,14 @@ class BookItemClass extends BaseClass
|
|
|
'customId' => $customId,
|
|
|
'bookSn' => $bookSn,
|
|
|
];
|
|
|
- $has = BookCustomClass::add($currentData, true);
|
|
|
+ $bookCustomRes = BookCustomClass::add($currentData, true);
|
|
|
}
|
|
|
- $hasId = $has->id ?? 0;
|
|
|
- $has = BookCustomClass::getLockById($hasId);
|
|
|
- $has->bookNum = bcadd($has->bookNum, $num);
|
|
|
- $has->needCgNum = bcadd($has->needCgNum, $addNeedCgNum);
|
|
|
- $has->save();
|
|
|
- util::unlock($key);
|
|
|
+ $bookCustomResId = $bookCustomRes->id ?? 0;
|
|
|
+ $bookCustomRes = BookCustomClass::getLockById($bookCustomResId);
|
|
|
+ $bookCustomRes->bookNum = bcadd($bookCustomRes->bookNum, $num);
|
|
|
+ $bookCustomRes->needCgNum = bcadd($bookCustomRes->needCgNum, $addNeedCgNum);
|
|
|
+ $bookCustomRes->save();
|
|
|
+ util::unlock($cacheKey);
|
|
|
}
|
|
|
}
|
|
|
|