BookItemCustomClass.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  1. <?php
  2. namespace bizGhs\book\classes;
  3. use bizGhs\base\classes\BaseClass;
  4. use bizGhs\product\classes\ProductClass;
  5. use common\components\dict;
  6. use common\components\util;
  7. use Yii;
  8. class BookItemCustomClass extends BaseClass
  9. {
  10. public static $baseFile = '\bizGhs\book\models\BookItemCustom';
  11. //下架
  12. public static function goOff($bookItemCustomRes, $shop, $params, $num)
  13. {
  14. $itemId = $bookItemCustomRes->itemId ?? 0;
  15. $product = ProductClass::getById($itemId, true);
  16. if (empty($product)) {
  17. util::fail('没有找到花材');
  18. }
  19. $bookSn = $shop->bookSn ?? 0;
  20. $bookItemRes = BookItemClass::getByCondition(['bookSn' => $bookSn, 'itemId' => $itemId], true);
  21. if (empty($bookItemRes)) {
  22. util::fail('预订信息缺失');
  23. }
  24. $onNum = $bookItemCustomRes->onNum ?? 0;
  25. if ($num > $onNum) {
  26. util::fail('下架数量超过已上架数');
  27. }
  28. $needOffNum = $num;
  29. $params['currentChangeType'] = 'stockOff';
  30. $bookItemRes = BookItemClass::delOnNum($bookItemRes, $needOffNum, 0, null, $shop, $product, $params);
  31. $bookItemCustomRes = self::delOnNum($bookItemCustomRes, $needOffNum, 0, null, $shop, $product, $params);
  32. $customId = $bookItemCustomRes->customId ?? 0;
  33. $bookCustomRes = BookCustomClass::getByCondition(['bookSn' => $bookSn, 'customId' => $customId], true);
  34. if (empty($bookCustomRes)) {
  35. util::fail('上架库存没有bookCustom...');
  36. }
  37. $bookCustomRes = BookCustomClass::delOnNum($bookCustomRes, $needOffNum, 0, null, $shop, $product, $params);
  38. }
  39. //上架 $onSkip true 表示上齐的直接跳过
  40. public static function goOn($bookItemCustomRes, $shop, $params, $num, $onSkip=false)
  41. {
  42. $itemId = $bookItemCustomRes->itemId ?? 0;
  43. $product = ProductClass::getById($itemId, true);
  44. if (empty($product)) {
  45. util::fail('没有找到花材');
  46. }
  47. $bookNum = $bookItemCustomRes->bookNum ?? 0;
  48. $onNum = $bookItemCustomRes->onNum ?? 0;
  49. $itemName =$bookItemCustomRes->name ?? '';
  50. $customName = $bookItemCustomRes->customName??'';
  51. if ($onNum >= $bookNum) {
  52. if($onSkip){
  53. return true;
  54. }else{
  55. util::fail('已经上齐');
  56. }
  57. }
  58. $bookSn = $shop->bookSn ?? 0;
  59. $bookItemRes = BookItemClass::getByCondition(['bookSn' => $bookSn, 'itemId' => $itemId], true);
  60. if (empty($bookItemRes)) {
  61. util::fail('预订信息缺失');
  62. }
  63. $hasOnNum = $bookItemRes->onNum;
  64. $stock = $product->stock ?? 0;
  65. $couldOnNum = bcsub($stock, $hasOnNum);
  66. if ($couldOnNum < 0) {
  67. util::fail('上架数量超过库存数量 bookItem');
  68. }
  69. if ($num > 0) {
  70. //上指定数量
  71. $needOnNum = $num;
  72. $maxNum = bcsub($bookNum, $onNum);
  73. if ($needOnNum > $maxNum) {
  74. util::fail("只需要上" . $maxNum . '份');
  75. }
  76. } else {
  77. //上齐
  78. $needOnNum = bcsub($bookNum, $onNum);
  79. }
  80. if ($needOnNum > $couldOnNum) {
  81. util::fail($customName.'的'.$itemName.' 可上' . $couldOnNum . '份,需上'.$needOnNum.'份');
  82. }
  83. $params['currentChangeType'] = 'stockOn';
  84. $bookItemRes = BookItemClass::addOnNum($bookItemRes, $needOnNum, null, $shop, $product, $params);
  85. $bookItemCustomRes = self::addOnNum($bookItemCustomRes, $needOnNum, null, $shop, $product, $params);
  86. $customId = $bookItemCustomRes->customId ?? 0;
  87. $bookCustomRes = BookCustomClass::getByCondition(['bookSn' => $bookSn, 'customId' => $customId], true);
  88. if (empty($bookCustomRes)) {
  89. util::fail('上架库存没有bookCustom...');
  90. }
  91. $bookCustomRes = BookCustomClass::addOnNum($bookCustomRes, $needOnNum, null, $shop, $product, $params);
  92. }
  93. public static function cancelBox($bookItemCustomRes)
  94. {
  95. $bookItemCustomRes->box = 0;
  96. $bookItemCustomRes->save();
  97. $bookSn = $bookItemCustomRes->bookSn ?? 0;
  98. $customId = $bookItemCustomRes->customId ?? 0;
  99. $bookCustomRes = BookCustomClass::getByCondition(['bookSn' => $bookSn, 'customId' => $customId], true);
  100. if (!empty($bookCustomRes)) {
  101. $bookCustomRes->box = 0;
  102. $bookCustomRes->save();
  103. }
  104. return $bookItemCustomRes;
  105. }
  106. public static function toBox($bookItemCustomRes)
  107. {
  108. if ($bookItemCustomRes->box == 1) {
  109. util::fail('已装过箱了');
  110. }
  111. if ($bookItemCustomRes->bookNum != $bookItemCustomRes->onNum) {
  112. util::fail('上架数量不等于预订数量');
  113. }
  114. $bookItemCustomRes->box = 1;
  115. $bookItemCustomRes->save();
  116. $bookSn = $bookItemCustomRes->bookSn ?? 0;
  117. $customId = $bookItemCustomRes->customId ?? 0;
  118. $list = BookItemCustomClass::getAllByCondition(['bookSn' => $bookSn, 'customId' => $customId,], null, '*', null, true);
  119. $allHasBox = 1;
  120. if (!empty($list)) {
  121. foreach ($list as $info) {
  122. if ($info->box == 0) {
  123. $allHasBox = 0;
  124. }
  125. }
  126. }
  127. if ($allHasBox == 1) {
  128. $bookCustomRes = BookCustomClass::getByCondition(['bookSn' => $bookSn, 'customId' => $customId], true);
  129. if (!empty($bookCustomRes)) {
  130. $bookCustomRes->box = 1;
  131. $bookCustomRes->save();
  132. }
  133. }
  134. return $bookItemCustomRes;
  135. }
  136. public static function delOnNum($bookItemCustomRes, $delOnNum, $num, $bill, $shop, $product, $params)
  137. {
  138. $bookItemCustomRes->onNum = bcsub($bookItemCustomRes->onNum, $delOnNum);
  139. $bookItemCustomRes->save();
  140. $bookItemResId = $bookItemCustomRes->id ?? 0;
  141. $ioRes = $params['ioRes'] ?? null;
  142. $relatedId = $ioRes->id ?? 0;
  143. //变动记录
  144. $itemId = $product->id ?? 0;
  145. $ptItemId = $product->itemId ?? 0;
  146. $name = $product->name ?? '';
  147. $py = $product->py ?? '';
  148. $bigUnit = $product->bigUnit ?? '扎';
  149. $bookSn = $shop->bookSn ?? '';
  150. $mainId = $shop->mainId ?? 0;
  151. $staffName = $params['staffName'] ?? '';
  152. $staffId = $params['staffId'] ?? 0;
  153. $currentChangeType = $params['currentChangeType'] ?? 'delBook';
  154. if ($currentChangeType == 'ghsCgRefund') {
  155. //供货商采购单售后
  156. $customId = $bookItemCustomRes->customId ?? 0;
  157. $customName = $bookItemCustomRes->customName ?? '';
  158. $customNamePy = $bookItemCustomRes->customNamePy ?? '';
  159. $orderSn = $bill->orderSn ?? '';
  160. $event = $staffName . ' 售后采购单' . $orderSn . ',下架' . $name . $delOnNum . $bigUnit;
  161. $currentCapitalType = dict::getDict('capitalType', 'ghsCgRefund');
  162. } elseif ($currentChangeType == 'stockOff') {
  163. $customId = $bookItemCustomRes->customId ?? 0;
  164. $customName = $bookItemCustomRes->customName ?? '';
  165. $customNamePy = $bookItemCustomRes->customNamePy ?? '';
  166. $currentCapitalType = 0;
  167. $event = $staffName . '手动下架' . $name . $delOnNum . $bigUnit;
  168. } elseif ($currentChangeType == 'delBook') {
  169. $customId = $bill->customId ?? 0;
  170. $customName = $bill->customName ?? '';
  171. $customNamePy = $bill->customNamePy ?? '';
  172. $event = $customName . '减少预订' . $name . $num . $bigUnit . ',其中下架' . $delOnNum . $bigUnit;
  173. $currentCapitalType = dict::getDict('capitalType', 'delBook');
  174. } else {
  175. $currentCapitalType = dict::getDict('capitalType', 'delBook');
  176. $customId = 0;
  177. $customName = '';
  178. $customNamePy = '';
  179. $event = '';
  180. util::fail('不存在的运作哦!!!');
  181. }
  182. $changeData = [
  183. 'mainId' => $mainId,
  184. 'bookSn' => $bookSn,
  185. 'name' => $name,
  186. 'py' => $py,
  187. 'itemId' => $itemId,
  188. 'ptItemId' => $ptItemId,
  189. 'customId' => $customId,
  190. 'customName' => $customName,
  191. 'customNamePy' => $customNamePy,
  192. 'relateId' => $relatedId,
  193. 'relateSecondId' => $bookItemResId,
  194. 'ptStyle' => 2,
  195. 'capitalType' => $currentCapitalType,
  196. 'io' => 0,
  197. 'changeNum' => $delOnNum,
  198. 'num' => $bookItemCustomRes->onNum,
  199. 'event' => $event,
  200. 'staffId' => $staffId,
  201. 'staffName' => $staffName,
  202. 'remark' => '',
  203. ];
  204. BookOnChangeClass::add($changeData, true);
  205. return $bookItemCustomRes;
  206. }
  207. public static function addOnNum($bookItemCustomRes, $addOnNum, $bill, $shop, $product, $params)
  208. {
  209. $bookItemCustomRes->onNum = bcadd($bookItemCustomRes->onNum, $addOnNum);
  210. $bookItemCustomRes->save();
  211. $bookItemResId = $bookItemCustomRes->id ?? 0;
  212. $ioRes = $params['ioRes'] ?? null;
  213. $relatedId = $ioRes->id ?? 0;
  214. $itemId = $product->id ?? 0;
  215. $ptItemId = $product->itemId ?? 0;
  216. $name = $product->name ?? '';
  217. $py = $product->py ?? '';
  218. $bigUnit = $product->bigUnit ?? '扎';
  219. $bookSn = $shop->bookSn ?? '';
  220. $mainId = $shop->mainId ?? 0;
  221. $customId = $bookItemCustomRes->customId ?? 0;
  222. $customName = $bookItemCustomRes->customName ?? '';
  223. $customNamePy = $bookItemCustomRes->customNamePy ?? '';
  224. $currentCapitalType = dict::getDict('capitalType', 'ghsCheckIn');
  225. $staffName = $params['staffName'] ?? '';
  226. $staffId = $params['staffId'] ?? 0;
  227. $currentChangeType = $params['currentChangeType'] ?? 'putIn';
  228. if ($currentChangeType == 'stockOn') {
  229. $currentCapitalType = 0;
  230. $event = "{$staffName} 手动上架 {$name} " . $addOnNum . $bigUnit;
  231. } elseif ($currentChangeType == 'putIn') {
  232. $orderSn = $bill->orderSn ?? '';
  233. $event = "采购单 {$orderSn} 入库,{$name} 上架 " . $addOnNum . $bigUnit;
  234. } else {
  235. $event = '';
  236. util::fail('无效动作');
  237. }
  238. $changeData = [
  239. 'mainId' => $mainId,
  240. 'bookSn' => $bookSn,
  241. 'name' => $name,
  242. 'py' => $py,
  243. 'itemId' => $itemId,
  244. 'ptItemId' => $ptItemId,
  245. 'customId' => $customId,
  246. 'customName' => $customName,
  247. 'customNamePy' => $customNamePy,
  248. 'relateId' => $relatedId,
  249. 'relateSecondId' => $bookItemResId,
  250. 'ptStyle' => 2,
  251. 'capitalType' => $currentCapitalType,
  252. 'io' => 1,
  253. 'changeNum' => $addOnNum,
  254. 'num' => $bookItemCustomRes->onNum,
  255. 'event' => $event,
  256. 'staffId' => $staffId,
  257. 'staffName' => $staffName,
  258. 'remark' => '',
  259. ];
  260. BookOnChangeClass::add($changeData, true);
  261. return $bookItemCustomRes;
  262. }
  263. public static function addRoadNum($bookItemCustomRes, $addRoadNum, $bill, $shop, $product, $params)
  264. {
  265. $bookItemCustomRes->roadNum = bcadd($bookItemCustomRes->roadNum, $addRoadNum);
  266. $bookItemCustomRes->save();
  267. $bookItemResId = $bookItemCustomRes->id ?? 0;
  268. $ioRes = $params['ioRes'] ?? null;
  269. $relatedId = $ioRes->id ?? 0;
  270. $bigUnit = $product->bigUnit ?? '扎';
  271. $itemId = $product->id ?? 0;
  272. $ptItemId = $product->itemId ?? 0;
  273. $name = $product->name ?? '';
  274. $py = $product->py ?? '';
  275. $bookSn = $shop->bookSn ?? '';
  276. $mainId = $shop->mainId ?? 0;
  277. $staffName = $params['staffName'] ?? '';
  278. $staffId = $params['staffId'] ?? 0;
  279. $currentCapitalType = dict::getDict('capitalType', 'ghsPurchase');
  280. $customId = $bookItemCustomRes->customId ?? 0;
  281. $customName = $bookItemCustomRes->customName ?? '';
  282. $customNamePy = $bookItemCustomRes->customNamePy ?? '';
  283. $orderSn = $bill->orderSn ?? '';
  284. $event = "{$staffName} 新增待入库 {$orderSn},路上增加 {$name}" . $addRoadNum . $bigUnit;
  285. $changeData = [
  286. 'mainId' => $mainId,
  287. 'bookSn' => $bookSn,
  288. 'name' => $name,
  289. 'py' => $py,
  290. 'itemId' => $itemId,
  291. 'ptItemId' => $ptItemId,
  292. 'customId' => $customId,
  293. 'customName' => $customName,
  294. 'customNamePy' => $customNamePy,
  295. 'relateId' => $relatedId,
  296. 'relateSecondId' => $bookItemResId,
  297. 'ptStyle' => 2,
  298. 'capitalType' => $currentCapitalType,
  299. 'io' => 1,
  300. 'changeNum' => $addRoadNum,
  301. 'num' => $bookItemCustomRes->roadNum,
  302. 'event' => $event,
  303. 'staffId' => $staffId,
  304. 'staffName' => $staffName,
  305. 'remark' => '',
  306. ];
  307. BookRoadChangeClass::add($changeData, true);
  308. return $bookItemCustomRes;
  309. }
  310. public static function delRoadNum($bookItemCustomRes, $delRoadNum, $num, $bill, $shop, $product, $params)
  311. {
  312. $bookItemCustomRes->roadNum = bcsub($bookItemCustomRes->roadNum, $delRoadNum);
  313. $bookItemCustomRes->save();
  314. $bookItemResId = $bookItemCustomRes->id ?? 0;
  315. $ioRes = $params['ioRes'] ?? null;
  316. $relatedId = $ioRes->id ?? 0;
  317. $bigUnit = $product->bigUnit ?? '扎';
  318. $currentChangeType = $params['currentChangeType'] ?? 'delBook';
  319. $itemId = $product->id ?? 0;
  320. $ptItemId = $product->itemId ?? 0;
  321. $name = $product->name ?? '';
  322. $py = $product->py ?? '';
  323. $bookSn = $shop->bookSn ?? '';
  324. $mainId = $shop->mainId ?? 0;
  325. $currentCapitalType = dict::getDict('capitalType', 'delBook');
  326. $staffName = $params['staffName'] ?? '';
  327. $staffId = $params['staffId'] ?? 0;
  328. if ($currentChangeType == 'putIn') {
  329. //入库
  330. $currentCapitalType = dict::getDict('capitalType', 'ghsCheckIn');
  331. $customId = $bookItemCustomRes->customId ?? 0;
  332. $customName = $bookItemCustomRes->customName ?? '';
  333. $customNamePy = $bookItemCustomRes->customNamePy ?? '';
  334. $orderSn = $bill->orderSn ?? '';
  335. $event = "采购单 {$orderSn} 入库上架,{$name} 路上减少" . $delRoadNum . $bigUnit;
  336. } elseif ($currentChangeType == 'cgCancel') {
  337. $currentCapitalType = dict::getDict('capitalType', 'ghsCgCancel');
  338. $customId = $bookItemCustomRes->customId ?? 0;
  339. $customName = $bookItemCustomRes->customName ?? '';
  340. $customNamePy = $bookItemCustomRes->customNamePy ?? '';
  341. $orderSn = $bill->orderSn ?? '';
  342. $event = "采购单 {$orderSn} 取消,{$name} 路上减少" . $delRoadNum . $bigUnit;
  343. } elseif ($currentChangeType == 'delBook') {
  344. //减少预订
  345. $currentCapitalType = dict::getDict('capitalType', 'delBook');
  346. $customId = $bill->customId ?? 0;
  347. $customName = $bill->customName ?? '';
  348. $customNamePy = $bill->customNamePy ?? '';
  349. $event = $customName . '减少预订' . $name . $num . $bigUnit . ',其中减少路上' . $delRoadNum . $bigUnit;
  350. } else {
  351. $event = '';
  352. $customId = 0;
  353. $customName = '';
  354. $customNamePy = '';
  355. util::fail('此变动方式没有找到');
  356. }
  357. $changeData = [
  358. 'mainId' => $mainId,
  359. 'bookSn' => $bookSn,
  360. 'name' => $name,
  361. 'py' => $py,
  362. 'itemId' => $itemId,
  363. 'ptItemId' => $ptItemId,
  364. 'customId' => $customId,
  365. 'customName' => $customName,
  366. 'customNamePy' => $customNamePy,
  367. 'relateId' => $relatedId,
  368. 'relateSecondId' => $bookItemResId,
  369. 'ptStyle' => 2,
  370. 'capitalType' => $currentCapitalType,
  371. 'io' => 0,
  372. 'changeNum' => $delRoadNum,
  373. 'num' => $bookItemCustomRes->roadNum,
  374. 'event' => $event,
  375. 'staffId' => $staffId,
  376. 'staffName' => $staffName,
  377. 'remark' => '',
  378. ];
  379. BookRoadChangeClass::add($changeData, true);
  380. return $bookItemCustomRes;
  381. }
  382. public static function delNeedCgNum($bookItemCustomRes, $delNeedCgNum, $totalBookNum, $bill, $shop, $product, $params)
  383. {
  384. $bookItemCustomRes->needCgNum = bcsub($bookItemCustomRes->needCgNum, $delNeedCgNum);
  385. $bookItemCustomRes->save();
  386. $bookItemCustomResId = $bookItemCustomRes->id ?? 0;
  387. $ioRes = $params['ioRes'] ?? null;
  388. $relatedId = $ioRes->id ?? 0;
  389. $itemId = $product->id ?? 0;
  390. $ptItemId = $product->itemId ?? 0;
  391. $name = $product->name ?? '';
  392. $py = $product->py ?? '';
  393. $bigUnit = $product->bigUnit ?? '扎';
  394. $bookSn = $shop->bookSn ?? '';
  395. $mainId = $shop->mainId ?? 0;
  396. $currentCapitalType = dict::getDict('capitalType', 'delBook');
  397. $staffName = $params['staffName'] ?? '';
  398. $staffId = $params['staffId'] ?? 0;
  399. $customId = $bookItemCustomRes->customId ?? 0;
  400. $customName = $bookItemCustomRes->customName ?? '';
  401. $customNamePy = $bookItemCustomRes->customNamePy ?? '';
  402. $currentChangeType = $params['currentChangeType'] ?? 'delBook';
  403. $event = '';
  404. if ($currentChangeType == 'addCg') {
  405. $currentCapitalType = dict::getDict('capitalType', 'ghsPurchase');
  406. $orderSn = $bill->orderSn ?? '';
  407. $event = $staffName . "新增待入库 {$orderSn} 减少待采 {$name} " . $delNeedCgNum . $bigUnit;
  408. } elseif ($currentChangeType == 'pdAddStock') {
  409. $currentCapitalType = dict::getDict('capitalType', 'pd');
  410. $event = $staffName . '盘点增加库存' . $delNeedCgNum . $bigUnit . ',减少待采' . $delNeedCgNum . $bigUnit;
  411. } elseif ($currentChangeType == 'loanStock') {
  412. $currentCapitalType = dict::getDict('capitalType', 'loanStock');
  413. $outName = $params['outName'] ?? '';
  414. $event = $staffName . '向' . $outName . '借库存' . $delNeedCgNum . $bigUnit . ',减少待采' . $delNeedCgNum . $bigUnit;
  415. } elseif ($currentChangeType == 'delBook') {
  416. $currentCapitalType = dict::getDict('capitalType', 'delBook');
  417. $event = $customName . '减少预订' . $name . $totalBookNum . $bigUnit . ',其中减少待采' . $delNeedCgNum . $bigUnit;
  418. } else {
  419. util::fail('没有找到的操作');
  420. }
  421. $changeData = [
  422. 'mainId' => $mainId,
  423. 'bookSn' => $bookSn,
  424. 'name' => $name,
  425. 'py' => $py,
  426. 'itemId' => $itemId,
  427. 'ptItemId' => $ptItemId,
  428. 'customId' => $customId,
  429. 'customName' => $customName,
  430. 'customNamePy' => $customNamePy,
  431. 'relateId' => $relatedId,
  432. 'relateSecondId' => $bookItemCustomResId,
  433. 'ptStyle' => 2,
  434. 'capitalType' => $currentCapitalType,
  435. 'io' => 0,
  436. 'changeNum' => $delNeedCgNum,
  437. 'num' => $bookItemCustomRes->needCgNum,
  438. 'event' => $event,
  439. 'staffId' => $staffId,
  440. 'staffName' => $staffName,
  441. 'remark' => '',
  442. ];
  443. BookCgChangeClass::add($changeData, true);
  444. return $bookItemCustomRes;
  445. }
  446. //预订增加待采数量 ssh 20240712
  447. public static function addNeedCgNum($bookItemCustomRes, $addNeedCgNum, $totalBookNum, $bill, $shop, $product, $params)
  448. {
  449. $bookItemCustomRes->needCgNum = bcadd($bookItemCustomRes->needCgNum, $addNeedCgNum);
  450. $bookItemCustomRes->save();
  451. $bookItemCustomResId = $bookItemCustomRes->id ?? 0;
  452. $ioRes = $params['ioRes'] ?? 0;
  453. $relatedId = $ioRes->id ?? 0;
  454. //待采增加变动记录
  455. $itemId = $product->id ?? 0;
  456. $ptItemId = $product->itemId ?? 0;
  457. $name = $product->name ?? '';
  458. $py = $product->py ?? '';
  459. $bigUnit = $product->bigUnit ?? '扎';
  460. $bookSn = $shop->bookSn ?? '';
  461. $mainId = $shop->mainId ?? 0;
  462. $staffName = $params['staffName'] ?? '';
  463. $staffId = $params['staffId'] ?? 0;
  464. $currentChangeType = $params['currentChangeType'] ?? 'delBook';
  465. if ($currentChangeType == 'cgCancel') {
  466. $currentCapitalType = dict::getDict('capitalType', 'ghsCgCancel');
  467. $customId = $bookItemCustomRes->customId ?? 0;
  468. $customName = $bookItemCustomRes->customName ?? '';
  469. $customNamePy = $bookItemCustomRes->customNamePy ?? '';
  470. $orderSn = $bill->orderSn ?? '';
  471. $event = "采购单 {$orderSn} 取消,{$name} 增加待采" . $addNeedCgNum . $bigUnit;
  472. } elseif ($currentChangeType == 'delBook') {
  473. $currentCapitalType = dict::getDict('capitalType', 'addBook');
  474. $customId = $bill->customId ?? 0;
  475. $customName = $bill->customName ?? '';
  476. $customNamePy = $bill->customNamePy ?? '';
  477. $event = $customName . '预订 ' . $name . $totalBookNum . $bigUnit . ',增加待采' . $addNeedCgNum . $bigUnit;
  478. } else {
  479. $customId = 0;
  480. $customName = '';
  481. $customNamePy = '';
  482. $currentCapitalType = dict::getDict('capitalType', 'addBook');
  483. util::fail('没有');
  484. }
  485. $changeData = [
  486. 'mainId' => $mainId,
  487. 'bookSn' => $bookSn,
  488. 'name' => $name,
  489. 'py' => $py,
  490. 'itemId' => $itemId,
  491. 'ptItemId' => $ptItemId,
  492. 'customId' => $customId,
  493. 'customName' => $customName,
  494. 'customNamePy' => $customNamePy,
  495. 'relateId' => $relatedId,
  496. 'relateSecondId' => $bookItemCustomResId,
  497. 'ptStyle' => 2,
  498. 'capitalType' => $currentCapitalType,
  499. 'io' => 1,
  500. 'changeNum' => $addNeedCgNum,
  501. 'num' => $bookItemCustomRes->needCgNum,
  502. 'event' => $event,
  503. 'staffId' => $staffId,
  504. 'staffName' => $staffName,
  505. 'remark' => '',
  506. ];
  507. BookCgChangeClass::add($changeData, true);
  508. return $bookItemCustomRes;
  509. }
  510. public static function addBookNum($bookItemCustomRes, $num, $order, $shop, $product, $params)
  511. {
  512. $currentNum = bcadd($bookItemCustomRes->bookNum, $num);
  513. $bookItemCustomRes->bookNum = $currentNum;
  514. $bookItemCustomRes->box = 0;
  515. $bookItemCustomRes->save();
  516. $bookItemCustomResId = $bookItemCustomRes->id ?? 0;
  517. $ioRes = $params['ioRes'] ?? 0;
  518. $relatedId = $ioRes->id ?? 0;
  519. //预订增加变动记录
  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 = $order->mainId ?? 0;
  527. $customId = $order->customId ?? 0;
  528. $customName = $order->customName ?? '';
  529. $customNamePy = $order->customNamePy ?? '';
  530. $currentCapitalType = dict::getDict('capitalType', 'addBook');
  531. $staffName = $params['staffName'] ?? '';
  532. $staffId = $params['staffId'] ?? 0;
  533. $event = $customName . '预订' . $name . $num . $bigUnit;
  534. $changeData = [
  535. 'mainId' => $mainId,
  536. 'bookSn' => $bookSn,
  537. 'name' => $name,
  538. 'py' => $py,
  539. 'itemId' => $itemId,
  540. 'ptItemId' => $ptItemId,
  541. 'customId' => $customId,
  542. 'customName' => $customName,
  543. 'customNamePy' => $customNamePy,
  544. 'relateId' => $relatedId,
  545. 'relateSecondId' => $bookItemCustomResId,
  546. 'ptStyle' => 2,
  547. 'capitalType' => $currentCapitalType,
  548. 'io' => 1,
  549. 'changeNum' => $num,
  550. 'num' => $bookItemCustomRes->bookNum,
  551. 'event' => $event,
  552. 'staffId' => $staffId,
  553. 'staffName' => $staffName,
  554. 'remark' => '',
  555. ];
  556. BookChangeClass::add($changeData, true);
  557. return $bookItemCustomRes;
  558. }
  559. public static function delBookNum($bookItemCustomRes, $num, $order, $shop, $product, $params)
  560. {
  561. $mainId = $order->mainId ?? 0;
  562. $customId = $order->customId ?? 0;
  563. $customName = $order->customName ?? '';
  564. $customNamePy = $order->customNamePy ?? '';
  565. $itemId = $product->id ?? 0;
  566. $ptItemId = $product->itemId ?? 0;
  567. $name = $product->name ?? '';
  568. $py = $product->py ?? '';
  569. $bigUnit = $product->bigUnit ?? '扎';
  570. $bookSn = $shop->bookSn ?? '';
  571. $currentNum = bcsub($bookItemCustomRes->bookNum, $num);
  572. if ($currentNum < 0) {
  573. $cacheKey = $params['cacheKey'] ?? '';
  574. if (!empty($cacheKey)) {
  575. util::unlock($cacheKey);
  576. }
  577. util::fail($customName . '预订的' . $name . '不够减 bookItemCustom');
  578. }
  579. $bookItemCustomRes->bookNum = $currentNum;
  580. $bookItemCustomRes->save();
  581. $bookItemCustomResId = $bookItemCustomRes->id ?? 0;
  582. $ioRes = $params['ioRes'] ?? null;
  583. $relatedId = $ioRes->id ?? 0;
  584. //变动记录
  585. $currentCapitalType = dict::getDict('capitalType', 'delBook');
  586. $staffName = $params['staffName'] ?? '';
  587. $staffId = $params['staffId'] ?? 0;
  588. $event = $customName . '减少预订' . $name . $num . $bigUnit;
  589. $changeData = [
  590. 'mainId' => $mainId,
  591. 'bookSn' => $bookSn,
  592. 'name' => $name,
  593. 'py' => $py,
  594. 'itemId' => $itemId,
  595. 'ptItemId' => $ptItemId,
  596. 'customId' => $customId,
  597. 'customName' => $customName,
  598. 'customNamePy' => $customNamePy,
  599. 'relateId' => $relatedId,
  600. 'relateSecondId' => $bookItemCustomResId,
  601. 'ptStyle' => 2,
  602. 'capitalType' => $currentCapitalType,
  603. 'io' => 0,
  604. 'changeNum' => $num,
  605. 'num' => $bookItemCustomRes->bookNum,
  606. 'event' => $event,
  607. 'staffId' => $staffId,
  608. 'staffName' => $staffName,
  609. 'remark' => '',
  610. ];
  611. BookChangeClass::add($changeData, true);
  612. return $bookItemCustomRes;
  613. }
  614. }