BookItemClass.php 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901
  1. <?php
  2. namespace bizGhs\book\classes;
  3. use bizGhs\base\classes\BaseClass;
  4. use bizGhs\custom\classes\CustomClass;
  5. use bizGhs\notify\classes\NotifyClass;
  6. use bizGhs\product\classes\ProductClass;
  7. use bizGhs\shop\classes\ShopClass;
  8. use common\components\dict;
  9. use common\components\noticeUtil;
  10. use common\components\util;
  11. use Yii;
  12. class BookItemClass extends BaseClass
  13. {
  14. public static $baseFile = '\bizGhs\book\models\BookItem';
  15. public static function delBathItem($batchData, $order, $params = [])
  16. {
  17. $orderId = $order->id ?? 0;
  18. $shopId = $order->shopId ?? 0;
  19. $shop = ShopClass::getById($shopId, true);
  20. if (empty($shop)) {
  21. util::fail('没有门店相关信息');
  22. }
  23. $bookSn = $shop->bookSn ?? '';
  24. $pfLevel = $shop->pfLevel ?? 0;
  25. if (empty($bookSn)) {
  26. if ($pfLevel == 1) {
  27. $sjName = $shop->merchantName ?? '';
  28. $shopName = $shop->shopName ?? '';
  29. $currentName = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
  30. noticeUtil::push($currentName . ' 没有开启预订', '15280215347');
  31. util::fail('请先开启预订');
  32. }
  33. }
  34. $mainId = $order->mainId ?? 0;
  35. $customId = $order->customId ?? 0;
  36. $customName = $order->customName ?? '';
  37. $customNamePy = $order->customNamePy ?? '';
  38. $ids = array_column($batchData, 'productId');
  39. $infoList = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id', true);
  40. foreach ($batchData as $data) {
  41. $itemId = $data['productId'] ?? 0;
  42. $product = $infoList[$itemId] ?? null;
  43. if (empty($product)) {
  44. util::fail('没有找到产品,ID:' . $itemId);
  45. }
  46. $ptItemId = $product->itemId ?? 0;
  47. $num = $data['num'] ?? 0;
  48. $name = $product->name ?? '';
  49. $py = $product->py ?? '';
  50. $cgStaffName = $product->cgStaffName ?? '';
  51. $cgStaffId = $product->cgStaffId ?? 0;
  52. if (empty($cgStaffId)) {
  53. if ($pfLevel == 1) {
  54. util::fail($name . '没有设置采购人');
  55. }
  56. }
  57. $cacheKey = 'change_book_item_num_' . $itemId;
  58. $noLock = util::lock($cacheKey);
  59. if (!$noLock) {
  60. util::fail("系统繁忙,1秒后再提交");
  61. }
  62. $lastNum = $data['lastNum'] ?? 0;
  63. $staffName = $params['staffName'] ?? '';
  64. $staffId = $params['staffId'] ?? 0;
  65. $ioData = [
  66. 'mainId' => $mainId,
  67. 'bookSn' => $bookSn,
  68. 'itemId' => $itemId,
  69. 'ptItemId' => $ptItemId,
  70. 'itemName' => $name,
  71. 'io' => 0,
  72. 'changeNum' => $num,
  73. 'num' => $lastNum,
  74. 'staffId' => $staffId,
  75. 'staffName' => $staffName,
  76. 'orderId' => $orderId,
  77. ];
  78. $ioRes = BookIoClass::add($ioData, true);
  79. $params['ioRes'] = $ioRes;
  80. $bookItemCustomRes = BookItemCustomClass::getByCondition(['bookSn' => $bookSn, 'customId' => $customId, 'itemId' => $itemId], true);
  81. if (empty($bookItemCustomRes)) {
  82. $currentData = [
  83. 'name' => $name,
  84. 'py' => $py,
  85. 'mainId' => $mainId,
  86. 'itemId' => $itemId,
  87. 'ptItemId' => $ptItemId,
  88. 'customId' => $customId,
  89. 'customName' => $customName,
  90. 'customNamePy' => $customNamePy,
  91. 'cgStaffId' => $cgStaffId,
  92. 'cgStaffName' => $cgStaffName,
  93. 'bookSn' => $bookSn,
  94. ];
  95. $bookItemCustomRes = BookItemCustomClass::add($currentData, true);
  96. }
  97. $params['cacheKey'] = $cacheKey;
  98. $bookItemCustomRes = BookItemCustomClass::delBookNum($bookItemCustomRes, $num, $order, $shop, $product, $params);
  99. $bookItemRes = self::getByCondition(['bookSn' => $bookSn, 'itemId' => $itemId,], true);
  100. if (empty($bookItemRes)) {
  101. $statData = [
  102. 'mainId' => $mainId,
  103. 'itemId' => $itemId,
  104. 'ptItemId' => $ptItemId,
  105. 'name' => $name,
  106. 'bookSn' => $bookSn,
  107. 'py' => $py,
  108. 'cgStaffId' => $cgStaffId,
  109. 'cgStaffName' => $cgStaffName
  110. ];
  111. $bookItemRes = self::add($statData, true);
  112. }
  113. $bookItemRes = self::delBookNum($bookItemRes, $num, $order, $shop, $product, $params);
  114. $bookCustomRes = BookCustomClass::getByCondition(['bookSn' => $bookSn, 'customId' => $customId], true);
  115. if (empty($bookCustomRes)) {
  116. $currentData = [
  117. 'name' => $customName,
  118. 'py' => $customNamePy,
  119. 'mainId' => $mainId,
  120. 'customId' => $customId,
  121. 'bookSn' => $bookSn,
  122. ];
  123. $bookCustomRes = BookCustomClass::add($currentData, true);
  124. }
  125. $bookCustomRes = BookCustomChangeClass::delBookNum($bookCustomRes, $num, $order, $shop, $product, $params);
  126. //预订变化通知 ssh 20240820
  127. $noticeText = json_encode(['orderId' => $orderId, 'customName' => $customName, 'customId' => $customId, 'itemId' => $itemId, 'itemName' => $name, 'io' => 0, 'num' => $num, 'shopId' => $shopId]);
  128. $noticeKey = "bookChangeNoticeStaff";
  129. Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
  130. $firstRemainSubNum = 0;
  131. if ($bookItemCustomRes->needCgNum >= $num) {
  132. //待采数量足够扣
  133. $firstNeedSubNum = $num;
  134. } else {
  135. $firstNeedSubNum = $bookItemCustomRes->needCgNum;
  136. //待采数量不够扣
  137. $firstRemainSubNum = bcsub($num, $firstNeedSubNum);
  138. }
  139. $bookItemRes = self::delNeedCgNum($bookItemRes, $firstNeedSubNum, $num, $order, $shop, $product, $params);
  140. $bookCustomRes = BookCustomClass::delNeedCgNum($bookCustomRes, $firstNeedSubNum, $num, $order, $shop, $product, $params);
  141. $bookItemCustomRes = BookItemCustomClass::delNeedCgNum($bookItemCustomRes, $firstNeedSubNum, $num, $order, $shop, $product, $params);
  142. if ($firstRemainSubNum <= 0) {
  143. util::unlock($cacheKey);
  144. continue;
  145. }
  146. $secondRemainSubNum = 0;
  147. if ($bookItemCustomRes->roadNum >= $firstRemainSubNum) {
  148. //路上数量足够扣
  149. $secondNeedSubNum = $firstRemainSubNum;
  150. } else {
  151. //路上数量不够扣
  152. $secondNeedSubNum = $bookItemCustomRes->roadNum;
  153. $secondRemainSubNum = bcsub($firstRemainSubNum, $secondNeedSubNum);
  154. }
  155. $bookItemRes = self::delRoadNum($bookItemRes, $secondNeedSubNum, $num, $order, $shop, $product, $params);
  156. $bookItemCustomRes = BookItemCustomClass::delRoadNum($bookItemCustomRes, $secondNeedSubNum, $num, $order, $shop, $product, $params);
  157. $bookCustomRes = BookCustomClass::delRoadNum($bookCustomRes, $secondNeedSubNum, $num, $order, $shop, $product, $params);
  158. //删除供货商的路上数量!!!!
  159. BookItemGhsClass::delRoadNum($bookItemCustomRes, $secondNeedSubNum, $bookSn, $order);
  160. if ($secondRemainSubNum <= 0) {
  161. util::unlock($cacheKey);
  162. continue;
  163. }
  164. $thirdRemainSubNum = 0;
  165. if ($bookItemCustomRes->onNum > $secondRemainSubNum) {
  166. //上架数量够扣
  167. $thirdNeedSubNum = $secondRemainSubNum;
  168. } else {
  169. //上架数量不够扣
  170. $thirdNeedSubNum = $bookItemCustomRes->onNum;
  171. $thirdRemainSubNum = bcsub($secondRemainSubNum, $thirdNeedSubNum);
  172. }
  173. $bookItemRes = self::delOnNum($bookItemRes, $thirdNeedSubNum, $num, $order, $shop, $product, $params);
  174. $bookItemCustomRes = BookItemCustomClass::delOnNum($bookItemCustomRes, $thirdNeedSubNum, $num, $order, $shop, $product, $params);
  175. $bookCustomRes = BookCustomClass::delOnNum($bookCustomRes, $thirdNeedSubNum, $num, $order, $shop, $product, $params);
  176. //预订减少造成下架而产生通知
  177. if($thirdNeedSubNum>0){
  178. NotifyClass::bookReduceOutItem($bookItemCustomRes, $thirdNeedSubNum, $shop);
  179. }
  180. if ($thirdRemainSubNum <= 0) {
  181. util::unlock($cacheKey);
  182. continue;
  183. }
  184. //还有不够扣在库存里,不用任何处理
  185. $bookItemCustomRes->save();
  186. $bookItemRes->save();
  187. $bookCustomRes->save();
  188. util::unlock($cacheKey);
  189. }
  190. }
  191. //批量添加预订花材 ssh 20240711
  192. public static function addBatchItem($batchData, $order, $params = [])
  193. {
  194. $action = $params['action'] ?? 'update';
  195. $orderId = $order->id ?? 0;
  196. $shopId = $order->shopId ?? 0;
  197. $shop = ShopClass::getById($shopId, true);
  198. if (empty($shop)) {
  199. util::fail('没有门店相关信息');
  200. }
  201. $bookSn = $shop->bookSn ?? '';
  202. $pfLevel = $shop->pfLevel ?? 0;
  203. if (empty($bookSn)) {
  204. if ($pfLevel == 1) {
  205. $sjName = $shop->merchantName ?? '';
  206. $shopName = $shop->shopName ?? '';
  207. $currentName = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
  208. noticeUtil::push($currentName . ' 没有开启预订', '15280215347');
  209. util::fail('请开启预订');
  210. }
  211. }
  212. $mainId = $order->mainId ?? 0;
  213. $customId = $order->customId ?? 0;
  214. $customName = $order->customName ?? '';
  215. $customNamePy = $order->customNamePy ?? '';
  216. $custom = CustomClass::getById($customId, true);
  217. if (empty($custom)) {
  218. util::fail('没有找到客户');
  219. }
  220. $seatSn = $custom->seatSn ?? '';
  221. $ids = array_column($batchData, 'productId');
  222. $infoList = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id', true);
  223. foreach ($batchData as $data) {
  224. $itemId = $data['productId'] ?? 0;
  225. $product = $infoList[$itemId] ?? null;
  226. if (empty($product)) {
  227. util::fail('没有找到产品,ID:' . $itemId);
  228. }
  229. $ptItemId = $product->itemId ?? 0;
  230. $num = $data['num'] ?? 0;
  231. $name = $product->name ?? '';
  232. $py = $product->py ?? '';
  233. $cgStaffName = $product->cgStaffName ?? '';
  234. $cgStaffId = $product->cgStaffId ?? 0;
  235. if (empty($cgStaffId)) {
  236. if ($pfLevel == 1) {
  237. util::fail($name . '没有设置采购人');
  238. }
  239. }
  240. $cacheKey = 'change_book_item_num_' . $itemId;
  241. $noLock = util::lock($cacheKey);
  242. if (!$noLock) {
  243. util::fail("系统繁忙,1秒后再提交");
  244. }
  245. $lastNum = $data['lastNum'] ?? 0;
  246. $remark = $data['remark'] ?? '';
  247. $hasRemark = $data['hasRemark'] ?? 0;
  248. $staffName = $params['staffName'] ?? '';
  249. $staffId = $params['staffId'] ?? 0;
  250. $ioData = [
  251. 'mainId' => $mainId,
  252. 'bookSn' => $bookSn,
  253. 'itemId' => $itemId,
  254. 'ptItemId' => $ptItemId,
  255. 'itemName' => $name,
  256. 'io' => 1,
  257. 'changeNum' => $num,
  258. 'num' => $lastNum,
  259. 'staffId' => $staffId,
  260. 'staffName' => $staffName,
  261. 'orderId' => $orderId,
  262. ];
  263. $ioRes = BookIoClass::add($ioData, true);
  264. $params['ioRes'] = $ioRes;
  265. $bookItemRes = self::getByCondition(['mainId' => $mainId, 'bookSn' => $bookSn, 'itemId' => $itemId,], true);
  266. if (empty($bookItemRes)) {
  267. $statData = [
  268. 'mainId' => $mainId,
  269. 'itemId' => $itemId,
  270. 'ptItemId' => $ptItemId,
  271. 'name' => $name,
  272. 'bookSn' => $bookSn,
  273. 'py' => $py,
  274. 'cgStaffId' => $cgStaffId,
  275. 'cgStaffName' => $cgStaffName,
  276. 'hasRemark' => $hasRemark,
  277. ];
  278. $bookItemRes = self::add($statData, true);
  279. }
  280. $currentStock = $product->stock;
  281. $totalHasNum = bcadd($currentStock, $bookItemRes->roadNum);
  282. $overNum = $bookItemRes->bookNum > $totalHasNum ? 0 : bcsub($totalHasNum, $bookItemRes->bookNum);
  283. //新增待采数量 = 预订数量 - 超出库存
  284. $needCgNumValue = bcsub($num, $overNum);
  285. $addNeedCgNum = $needCgNumValue < 0 ? 0 : $needCgNumValue;
  286. $bookItemRes = self::addBookNum($bookItemRes, $num, $order, $shop, $product, $params);
  287. self::addNeedCgNum($bookItemRes, $addNeedCgNum, $num, $order, $shop, $product, $params);
  288. $bookItemCustomRes = BookItemCustomClass::getByCondition(['mainId' => $mainId, 'bookSn' => $bookSn, 'customId' => $customId, 'itemId' => $itemId], true);
  289. if (empty($bookItemCustomRes)) {
  290. $currentData = [
  291. 'name' => $name,
  292. 'py' => $py,
  293. 'mainId' => $mainId,
  294. 'itemId' => $itemId,
  295. 'ptItemId' => $ptItemId,
  296. 'customId' => $customId,
  297. 'customName' => $customName,
  298. 'customNamePy' => $customNamePy,
  299. 'seatSn' => $seatSn,
  300. 'cgStaffId' => $cgStaffId,
  301. 'cgStaffName' => $cgStaffName,
  302. 'bookSn' => $bookSn,
  303. 'hasRemark' => $hasRemark,
  304. 'remark' => $remark,
  305. ];
  306. $bookItemCustomRes = BookItemCustomClass::add($currentData, true);
  307. }
  308. $bookItemCustomRes = BookItemCustomClass::addBookNum($bookItemCustomRes, $num, $order, $shop, $product, $params);
  309. BookItemCustomClass::addNeedCgNum($bookItemCustomRes, $addNeedCgNum, $num, $order, $shop, $product, $params);
  310. $bookCustomRes = BookCustomClass::getByCondition(['mainId' => $mainId, 'bookSn' => $bookSn, 'customId' => $customId], true);
  311. if (empty($bookCustomRes)) {
  312. $currentData = [
  313. 'name' => $customName,
  314. 'py' => $customNamePy,
  315. 'seatSn' => $seatSn,
  316. 'mainId' => $mainId,
  317. 'customId' => $customId,
  318. 'bookSn' => $bookSn,
  319. 'hasRemark' => $hasRemark,
  320. ];
  321. $bookCustomRes = BookCustomClass::add($currentData, true);
  322. }
  323. $bookCustomRes = BookCustomClass::addBookNum($bookCustomRes, $num, $order, $shop, $product, $params);
  324. BookCustomClass::addNeedCgNum($bookCustomRes, $addNeedCgNum, $num, $order, $shop, $product, $params);
  325. util::unlock($cacheKey);
  326. //添加到缓存,所有待入库采购单重新找货位号
  327. $cacheKey = 'assign_seat_main_book_sn_list';
  328. Yii::$app->redis->executeCommand('SADD', [$cacheKey, $bookSn]);
  329. //预订变化通知
  330. if($action == 'update'){
  331. $noticeText = json_encode(['orderId' => $orderId, 'customName' => $customName, 'customId' => $customId, 'itemId' => $itemId, 'itemName' => $name, 'io' => 1, 'num' => $num, 'shopId' => $shopId]);
  332. $noticeKey = "bookChangeNoticeStaff";
  333. Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
  334. }
  335. }
  336. }
  337. public static function addBookNum($bookItemRes, $num, $order, $shop, $product, $params)
  338. {
  339. $currentNum = bcadd($bookItemRes->bookNum, $num);
  340. $bookItemRes->bookNum = $currentNum;
  341. $bookItemRes->save();
  342. $bookItemResId = $bookItemRes->id ?? 0;
  343. $ioRes = $params['ioRes'] ?? null;
  344. $relatedId = $ioRes->id ?? 0;
  345. //预订增加变动记录
  346. $itemId = $product->id ?? 0;
  347. $ptItemId = $product->itemId ?? 0;
  348. $name = $product->name ?? '';
  349. $py = $product->py ?? '';
  350. $bigUnit = $product->bigUnit ?? '扎';
  351. $bookSn = $shop->bookSn ?? '';
  352. $mainId = $order->mainId ?? 0;
  353. $customId = $order->customId ?? 0;
  354. $customName = $order->customName ?? '';
  355. $customNamePy = $order->customNamePy ?? '';
  356. $currentCapitalType = dict::getDict('capitalType', 'addBook');
  357. $staffName = $params['staffName'] ?? '';
  358. $staffId = $params['staffId'] ?? 0;
  359. $event = $customName . '预订' . $name . $num . $bigUnit;
  360. $changeData = [
  361. 'mainId' => $mainId,
  362. 'bookSn' => $bookSn,
  363. 'name' => $name,
  364. 'py' => $py,
  365. 'itemId' => $itemId,
  366. 'ptItemId' => $ptItemId,
  367. 'customId' => $customId,
  368. 'customName' => $customName,
  369. 'customNamePy' => $customNamePy,
  370. 'relateId' => $relatedId,
  371. 'relateSecondId' => $bookItemResId,
  372. 'ptStyle' => 2,
  373. 'capitalType' => $currentCapitalType,
  374. 'io' => 1,
  375. 'changeNum' => $num,
  376. 'num' => $bookItemRes->bookNum,
  377. 'event' => $event,
  378. 'staffId' => $staffId,
  379. 'staffName' => $staffName,
  380. 'remark' => '',
  381. ];
  382. BookChangeGlobalClass::add($changeData, true);
  383. return $bookItemRes;
  384. }
  385. public static function addOnNum($bookItemRes, $addOnNum, $bill, $shop, $product, $params)
  386. {
  387. $bookItemRes->onNum = bcadd($bookItemRes->onNum, $addOnNum);
  388. $bookItemRes->save();
  389. $bookItemResId = $bookItemRes->id ?? 0;
  390. $ioRes = $params['ioRes'] ?? null;
  391. $relatedId = $ioRes->id ?? 0;
  392. //变动记录
  393. $itemId = $product->id ?? 0;
  394. $ptItemId = $product->itemId ?? 0;
  395. $name = $product->name ?? '';
  396. $py = $product->py ?? '';
  397. $bigUnit = $product->bigUnit ?? '扎';
  398. $bookSn = $shop->bookSn ?? '';
  399. $mainId = $shop->mainId ?? 0;
  400. $customId = $bill->customId ?? 0;
  401. $customName = $bill->customName ?? '';
  402. $customNamePy = $bill->customNamePy ?? '';
  403. $currentCapitalType = dict::getDict('capitalType', 'ghsCheckIn');
  404. $staffName = $params['staffName'] ?? '';
  405. $staffId = $params['staffId'] ?? 0;
  406. $orderSn = $bill->orderSn ?? '';
  407. $currentChangeType = $params['currentChangeType'] ?? 'putIn';
  408. if ($currentChangeType == 'stockOn') {
  409. $currentCapitalType = 0;
  410. $event = "{$staffName} 手动上架 {$name} " . $addOnNum . $bigUnit;
  411. } elseif ($currentChangeType == 'putIn') {
  412. $event = "采购单 {$orderSn} 入库,{$name} 上架 " . $addOnNum . $bigUnit;
  413. } else {
  414. $event = '';
  415. util::fail('不存在的动作');
  416. }
  417. $changeData = [
  418. 'mainId' => $mainId,
  419. 'bookSn' => $bookSn,
  420. 'name' => $name,
  421. 'py' => $py,
  422. 'itemId' => $itemId,
  423. 'ptItemId' => $ptItemId,
  424. 'customId' => $customId,
  425. 'customName' => $customName,
  426. 'customNamePy' => $customNamePy,
  427. 'relateId' => $relatedId,
  428. 'relateSecondId' => $bookItemResId,
  429. 'ptStyle' => 2,
  430. 'capitalType' => $currentCapitalType,
  431. 'io' => 1,
  432. 'changeNum' => $addOnNum,
  433. 'num' => $bookItemRes->onNum,
  434. 'event' => $event,
  435. 'staffId' => $staffId,
  436. 'staffName' => $staffName,
  437. 'remark' => '',
  438. ];
  439. BookOnChangeGlobalClass::add($changeData, true);
  440. return $bookItemRes;
  441. }
  442. public static function delOnNum($bookItemRes, $delOnNum, $num, $bill, $shop, $product, $params)
  443. {
  444. $bookItemRes->onNum = bcsub($bookItemRes->onNum, $delOnNum);
  445. $bookItemRes->save();
  446. $bookItemResId = $bookItemRes->id ?? 0;
  447. $ioRes = $params['ioRes'] ?? null;
  448. $relatedId = $ioRes->id ?? 0;
  449. //变动记录
  450. $itemId = $product->id ?? 0;
  451. $ptItemId = $product->itemId ?? 0;
  452. $name = $product->name ?? '';
  453. $py = $product->py ?? '';
  454. $bigUnit = $product->bigUnit ?? '扎';
  455. $bookSn = $shop->bookSn ?? '';
  456. $mainId = $shop->mainId ?? 0;
  457. $staffName = $params['staffName'] ?? '';
  458. $staffId = $params['staffId'] ?? 0;
  459. $currentChangeType = $params['currentChangeType'] ?? 'delBook';
  460. if ($currentChangeType == 'ghsCgRefund') {
  461. //供货商采购单售后
  462. $customId = 0;
  463. $customName = '';
  464. $customNamePy = '';
  465. $orderSn = $bill->orderSn ?? '';
  466. $event = $staffName . ' 售后采购单' . $orderSn . ',下架' . $name . $delOnNum . $bigUnit;
  467. $currentCapitalType = dict::getDict('capitalType', 'ghsCgRefund');
  468. } elseif ($currentChangeType == 'stockOff') {
  469. $customId = 0;
  470. $customName = '';
  471. $customNamePy = '';
  472. $currentCapitalType = 0;
  473. $event = $staffName . '手动下架' . $name . $delOnNum . $bigUnit;
  474. } elseif ($currentChangeType == 'delBook') {
  475. $customId = $bill->customId ?? 0;
  476. $customName = $bill->customName ?? '';
  477. $customNamePy = $bill->customNamePy ?? '';
  478. $currentCapitalType = dict::getDict('capitalType', 'delBook');
  479. $event = $customName . '减少预订' . $name . $num . $bigUnit . ',其中下架' . $delOnNum . $bigUnit;
  480. } else {
  481. $currentCapitalType = dict::getDict('capitalType', 'delBook');
  482. $customId = 0;
  483. $customName = '';
  484. $customNamePy = '';
  485. $event = '';
  486. util::fail('不存在的运作哈。。。');
  487. }
  488. $changeData = [
  489. 'mainId' => $mainId,
  490. 'bookSn' => $bookSn,
  491. 'name' => $name,
  492. 'py' => $py,
  493. 'itemId' => $itemId,
  494. 'ptItemId' => $ptItemId,
  495. 'customId' => $customId,
  496. 'customName' => $customName,
  497. 'customNamePy' => $customNamePy,
  498. 'relateId' => $relatedId,
  499. 'relateSecondId' => $bookItemResId,
  500. 'ptStyle' => 2,
  501. 'capitalType' => $currentCapitalType,
  502. 'io' => 0,
  503. 'changeNum' => $delOnNum,
  504. 'num' => $bookItemRes->onNum,
  505. 'event' => $event,
  506. 'staffId' => $staffId,
  507. 'staffName' => $staffName,
  508. 'remark' => '',
  509. ];
  510. BookOnChangeGlobalClass::add($changeData, true);
  511. return $bookItemRes;
  512. }
  513. public static function addRoadNum($bookItemRes, $addRoadNum, $bill, $shop, $product, $params)
  514. {
  515. $bookItemRes->roadNum = bcadd($bookItemRes->roadNum, $addRoadNum);
  516. $bookItemRes->save();
  517. $bookItemResId = $bookItemRes->id ?? 0;
  518. $ioRes = $params['ioRes'] ?? null;
  519. $relatedId = $ioRes->id ?? 0;
  520. $itemId = $product->id ?? 0;
  521. $ptItemId = $product->itemId ?? 0;
  522. $name = $product->name ?? '';
  523. $py = $product->py ?? '';
  524. $bigUnit = $product->bigUnit ?? '扎';
  525. $bookSn = $shop->bookSn ?? '';
  526. $mainId = $shop->mainId ?? 0;
  527. $staffName = $params['staffName'] ?? '';
  528. $staffId = $params['staffId'] ?? 0;
  529. $currentCapitalType = dict::getDict('capitalType', 'ghsPurchase');
  530. $customId = $params['customId'] ?? 0;
  531. $customName = $params['customName'] ?? '';
  532. $customNamePy = $params['customNamePy'] ?? '';
  533. $orderSn = $bill->orderSn ?? '';
  534. $event = "{$staffName} 新增待入库 {$orderSn}({$customName}),路上增加 {$name}" . $addRoadNum . $bigUnit;
  535. $changeData = [
  536. 'mainId' => $mainId,
  537. 'bookSn' => $bookSn,
  538. 'name' => $name,
  539. 'py' => $py,
  540. 'itemId' => $itemId,
  541. 'ptItemId' => $ptItemId,
  542. 'customId' => $customId,
  543. 'customName' => $customName,
  544. 'customNamePy' => $customNamePy,
  545. 'relateId' => $relatedId,
  546. 'relateSecondId' => $bookItemResId,
  547. 'ptStyle' => 2,
  548. 'capitalType' => $currentCapitalType,
  549. 'io' => 1,
  550. 'changeNum' => $addRoadNum,
  551. 'num' => $bookItemRes->roadNum,
  552. 'event' => $event,
  553. 'staffId' => $staffId,
  554. 'staffName' => $staffName,
  555. 'remark' => '',
  556. ];
  557. BookRoadChangeGlobalClass::add($changeData, true);
  558. return $bookItemRes;
  559. }
  560. public static function delRoadNum($bookItemRes, $delRoadNum, $num, $bill, $shop, $product, $params)
  561. {
  562. $bookItemRes->roadNum = bcsub($bookItemRes->roadNum, $delRoadNum);
  563. $bookItemRes->save();
  564. $bookItemResId = $bookItemRes->id ?? 0;
  565. $ioRes = $params['ioRes'] ?? null;
  566. $relatedId = $ioRes->id ?? 0;
  567. $itemId = $product->id ?? 0;
  568. $ptItemId = $product->itemId ?? 0;
  569. $name = $product->name ?? '';
  570. $py = $product->py ?? '';
  571. $bigUnit = $product->bigUnit ?? '扎';
  572. $bookSn = $shop->bookSn ?? '';
  573. $mainId = $shop->mainId ?? 0;
  574. $currentCapitalType = dict::getDict('capitalType', 'delBook');
  575. $staffName = $params['staffName'] ?? '';
  576. $staffId = $params['staffId'] ?? 0;
  577. $currentChangeType = $params['currentChangeType'] ?? 'delBook';
  578. if ($currentChangeType == 'putIn') {
  579. //入库
  580. $currentCapitalType = dict::getDict('capitalType', 'ghsCheckIn');
  581. $customId = 0;
  582. $customName = '';
  583. $customNamePy = '';
  584. $orderSn = $bill->orderSn ?? '';
  585. $event = "采购单 {$orderSn} 入库上架,{$name} 路上减少" . $delRoadNum . $bigUnit;
  586. } elseif ($currentChangeType == 'delBook') {
  587. //减少预订
  588. $currentCapitalType = dict::getDict('capitalType', 'delBook');
  589. $customId = $bill->customId ?? 0;
  590. $customName = $bill->customName ?? '';
  591. $customNamePy = $bill->customNamePy ?? '';
  592. $event = $customName . '减少预订' . $name . $num . $bigUnit . ',其中减少路上' . $delRoadNum . $bigUnit;
  593. } elseif ($currentChangeType == 'cgCancel') {
  594. $currentCapitalType = dict::getDict('capitalType', 'ghsCgCancel');
  595. $customId = 0;
  596. $customName = '';
  597. $customNamePy = '';
  598. $orderSn = $bill->orderSn ?? '';
  599. $event = "采购单 {$orderSn} 取消,{$name} 路上减少" . $delRoadNum . $bigUnit;
  600. } else {
  601. $event = '';
  602. $customId = 0;
  603. $customName = '';
  604. $customNamePy = '';
  605. util::fail('此变动方式没有找到');
  606. }
  607. $changeData = [
  608. 'mainId' => $mainId,
  609. 'bookSn' => $bookSn,
  610. 'name' => $name,
  611. 'py' => $py,
  612. 'itemId' => $itemId,
  613. 'ptItemId' => $ptItemId,
  614. 'customId' => $customId,
  615. 'customName' => $customName,
  616. 'customNamePy' => $customNamePy,
  617. 'relateId' => $relatedId,
  618. 'relateSecondId' => $bookItemResId,
  619. 'ptStyle' => 2,
  620. 'capitalType' => $currentCapitalType,
  621. 'io' => 0,
  622. 'changeNum' => $delRoadNum,
  623. 'num' => $bookItemRes->roadNum,
  624. 'event' => $event,
  625. 'staffId' => $staffId,
  626. 'staffName' => $staffName,
  627. 'remark' => '',
  628. ];
  629. BookRoadChangeGlobalClass::add($changeData, true);
  630. return $bookItemRes;
  631. }
  632. public static function delNeedCgNum($bookItemRes, $delNeedCgNum, $totalBookNum, $bill, $shop, $product, $params)
  633. {
  634. $bookItemRes->needCgNum = bcsub($bookItemRes->needCgNum, $delNeedCgNum);
  635. $bookItemRes->save();
  636. $bookItemResId = $bookItemRes->id ?? 0;
  637. $ioRes = $params['ioRes'] ?? null;
  638. $relatedId = $ioRes->id ?? 0;
  639. $itemId = $product->id ?? 0;
  640. $ptItemId = $product->itemId ?? 0;
  641. $name = $product->name ?? '';
  642. $py = $product->py ?? '';
  643. $bigUnit = $product->bigUnit ?? '扎';
  644. $bookSn = $shop->bookSn ?? '';
  645. $mainId = $shop->mainId ?? 0;
  646. $currentCapitalType = dict::getDict('capitalType', 'addBook');
  647. $staffName = $params['staffName'] ?? '';
  648. $staffId = $params['staffId'] ?? 0;
  649. $currentChangeType = $params['currentChangeType'] ?? 'delBook';
  650. if ($currentChangeType == 'addCg') {
  651. $currentCapitalType = dict::getDict('capitalType', 'ghsPurchase');
  652. $customId = $params['customId'] ?? 0;
  653. $customName = $params['customName'] ?? '';
  654. $customNamePy = $params['customNamePy'] ?? '';
  655. $orderSn = $bill->orderSn ?? '';
  656. $event = $staffName . "新增加待入库 {$orderSn}({$customName}) 减少待采 {$name} " . $delNeedCgNum . $bigUnit;
  657. } elseif ($currentChangeType == 'pdAddStock') {
  658. $customId = 0;
  659. $customName = '';
  660. $customNamePy = '';
  661. $currentCapitalType = dict::getDict('capitalType', 'pd');
  662. $event = $staffName . '盘点增加库存' . $delNeedCgNum . $bigUnit . ',减少待采' . $delNeedCgNum . $bigUnit;
  663. } elseif ($currentChangeType == 'loanStock') {
  664. $currentCapitalType = dict::getDict('capitalType', 'loanStock');
  665. $outName = $params['outName'] ?? '';
  666. $customId = 0;
  667. $customName = '';
  668. $customNamePy = '';
  669. $event = $staffName . '向' . $outName . '借库存' . $delNeedCgNum . $bigUnit . ',减少待采' . $delNeedCgNum . $bigUnit;
  670. } elseif ($currentChangeType == 'delBook') {
  671. $customId = $bill->customId ?? 0;
  672. $customName = $bill->customName ?? '';
  673. $customNamePy = $bill->customNamePy ?? '';
  674. $event = $customName . '减少预订' . $name . $totalBookNum . $bigUnit . ',其中减少待采' . $delNeedCgNum . $bigUnit;
  675. } else {
  676. $customId = 0;
  677. $customName = '';
  678. $customNamePy = '';
  679. $event = '';
  680. util::fail('没有找到的操作');
  681. }
  682. $changeData = [
  683. 'mainId' => $mainId,
  684. 'bookSn' => $bookSn,
  685. 'name' => $name,
  686. 'py' => $py,
  687. 'itemId' => $itemId,
  688. 'ptItemId' => $ptItemId,
  689. 'customId' => $customId,
  690. 'customName' => $customName,
  691. 'customNamePy' => $customNamePy,
  692. 'relateId' => $relatedId,
  693. 'relateSecondId' => $bookItemResId,
  694. 'ptStyle' => 2,
  695. 'capitalType' => $currentCapitalType,
  696. 'io' => 0,
  697. 'changeNum' => $delNeedCgNum,
  698. 'num' => $bookItemRes->needCgNum,
  699. 'event' => $event,
  700. 'staffId' => $staffId,
  701. 'staffName' => $staffName,
  702. 'remark' => '',
  703. ];
  704. BookCgChangeGlobalClass::add($changeData, true);
  705. return $bookItemRes;
  706. }
  707. public static function addNeedCgNum($bookItemRes, $addNeedCgNum, $totalBookNum, $bill, $shop, $product, $params)
  708. {
  709. $bookItemRes->needCgNum = bcadd($bookItemRes->needCgNum, $addNeedCgNum);
  710. $bookItemRes->save();
  711. $bookItemResId = $bookItemRes->id ?? 0;
  712. $ioRes = $params['ioRes'] ?? null;
  713. $relatedId = $ioRes->id ?? 0;
  714. $itemId = $product->id ?? 0;
  715. $ptItemId = $product->itemId ?? 0;
  716. $name = $product->name ?? '';
  717. $py = $product->py ?? '';
  718. $bigUnit = $product->bigUnit ?? '扎';
  719. $bookSn = $shop->bookSn ?? '';
  720. $mainId = $shop->mainId ?? 0;
  721. $staffName = $params['staffName'] ?? '';
  722. $staffId = $params['staffId'] ?? 0;
  723. $currentChangeType = $params['currentChangeType'] ?? 'addBook';
  724. if ($currentChangeType == 'cgCancel') {
  725. $currentCapitalType = dict::getDict('capitalType', 'ghsCgCancel');
  726. $customId = $bookCustomRes->customId ?? 0;
  727. $customName = $bookCustomRes->name ?? '';
  728. $customNamePy = $bookCustomRes->py ?? '';
  729. $orderSn = $bill->orderSn ?? '';
  730. $event = "采购单 {$orderSn} 取消,{$name} 增加待采" . $addNeedCgNum . $bigUnit;
  731. } elseif ($currentChangeType == 'refund') {
  732. $currentCapitalType = dict::getDict('capitalType', 'ghsCgRefund');
  733. $customId = $bookCustomRes->customId ?? 0;
  734. $customName = $bookCustomRes->name ?? '';
  735. $customNamePy = $bookCustomRes->py ?? '';
  736. $orderSn = $bill->orderSn ?? '';
  737. $event = "采购单 {$orderSn} 售后,{$name} 增加待采" . $addNeedCgNum . $bigUnit;
  738. } elseif ($currentChangeType == 'addBook') {
  739. $currentCapitalType = dict::getDict('capitalType', 'addBook');
  740. $customId = $bill->customId ?? 0;
  741. $customName = $bill->customName ?? '';
  742. $customNamePy = $bill->customNamePy ?? '';
  743. $event = $customName . '预订 ' . $name . $totalBookNum . $bigUnit . ',增加待采' . $addNeedCgNum . $bigUnit;
  744. } else {
  745. $currentCapitalType = dict::getDict('capitalType', 'addBook');
  746. $customId = 0;
  747. $customName = '';
  748. $customNamePy = '';
  749. $event = '';
  750. util::fail('无效动作哈...');
  751. }
  752. $changeData = [
  753. 'mainId' => $mainId,
  754. 'bookSn' => $bookSn,
  755. 'name' => $name,
  756. 'py' => $py,
  757. 'itemId' => $itemId,
  758. 'ptItemId' => $ptItemId,
  759. 'customId' => $customId,
  760. 'customName' => $customName,
  761. 'customNamePy' => $customNamePy,
  762. 'relateId' => $relatedId,
  763. 'relateSecondId' => $bookItemResId,
  764. 'ptStyle' => 2,
  765. 'capitalType' => $currentCapitalType,
  766. 'io' => 1,
  767. 'changeNum' => $addNeedCgNum,
  768. 'num' => $bookItemRes->needCgNum,
  769. 'event' => $event,
  770. 'staffId' => $staffId,
  771. 'staffName' => $staffName,
  772. 'remark' => '',
  773. ];
  774. BookCgChangeGlobalClass::add($changeData, true);
  775. return $bookItemRes;
  776. }
  777. public static function delBookNum($bookItemRes, $num, $order, $shop, $product, $params)
  778. {
  779. $mainId = $order->mainId ?? 0;
  780. $customId = $order->customId ?? 0;
  781. $customName = $order->customName ?? '';
  782. $customNamePy = $order->customNamePy ?? '';
  783. $itemId = $product->id ?? 0;
  784. $ptItemId = $product->itemId ?? 0;
  785. $name = $product->name ?? '';
  786. $py = $product->py ?? '';
  787. $bigUnit = $product->bigUnit ?? '扎';
  788. $bookSn = $shop->bookSn ?? '';
  789. $currentNum = bcsub($bookItemRes->bookNum, $num);
  790. if ($currentNum < 0) {
  791. $cacheKey = $params['cacheKey'] ?? '';
  792. if (!empty($cacheKey)) {
  793. util::unlock($cacheKey);
  794. }
  795. util::fail($customName . '预订的' . $name . '不够减 bookItemCustom');
  796. }
  797. $bookItemRes->bookNum = $currentNum;
  798. $bookItemRes->save();
  799. $bookItemCustomResId = $bookItemRes->id ?? 0;
  800. $ioRes = $params['ioRes'] ?? null;
  801. $relatedId = $ioRes->id ?? 0;
  802. //变动记录
  803. $currentCapitalType = dict::getDict('capitalType', 'delBook');
  804. $staffName = $params['staffName'] ?? '';
  805. $staffId = $params['staffId'] ?? 0;
  806. $event = $customName . '减少预订' . $name . $num . $bigUnit;
  807. $changeData = [
  808. 'mainId' => $mainId,
  809. 'bookSn' => $bookSn,
  810. 'name' => $name,
  811. 'py' => $py,
  812. 'itemId' => $itemId,
  813. 'ptItemId' => $ptItemId,
  814. 'customId' => $customId,
  815. 'customName' => $customName,
  816. 'customNamePy' => $customNamePy,
  817. 'relateId' => $relatedId,
  818. 'relateSecondId' => $bookItemCustomResId,
  819. 'ptStyle' => 2,
  820. 'capitalType' => $currentCapitalType,
  821. 'io' => 0,
  822. 'changeNum' => $num,
  823. 'num' => $bookItemRes->bookNum,
  824. 'event' => $event,
  825. 'staffId' => $staffId,
  826. 'staffName' => $staffName,
  827. 'remark' => '',
  828. ];
  829. BookChangeGlobalClass::add($changeData, true);
  830. return $bookItemRes;
  831. }
  832. }