BookCustomClass.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. <?php
  2. namespace bizGhs\book\classes;
  3. use bizGhs\base\classes\BaseClass;
  4. use common\components\dict;
  5. use common\components\util;
  6. use Yii;
  7. class BookCustomClass extends BaseClass
  8. {
  9. public static $baseFile = '\bizGhs\book\models\BookCustom';
  10. public static function addOnNum($bookCustomRes, $addOnNum, $bill, $shop, $product, $params)
  11. {
  12. $bookCustomRes->onNum = bcadd($bookCustomRes->onNum, $addOnNum);
  13. $bookCustomRes->save();
  14. $bookCustomResId = $bookCustomRes->id ?? 0;
  15. $ioRes = $params['ioRes'] ?? null;
  16. $relatedId = $ioRes->id ?? 0;
  17. //变动记录
  18. $itemId = $product->id ?? 0;
  19. $ptItemId = $product->itemId ?? 0;
  20. $name = $product->name ?? '';
  21. $py = $product->py ?? '';
  22. $bigUnit = $product->bigUnit ?? '扎';
  23. $bookSn = $shop->bookSn ?? '';
  24. $mainId = $shop->mainId ?? 0;
  25. $customId = $bookCustomRes->customId ?? 0;
  26. $customName = $bookCustomRes->name ?? '';
  27. $customNamePy = $bookCustomRes->py ?? '';
  28. $currentCapitalType = dict::getDict('capitalType', 'ghsCheckIn');
  29. $staffName = $params['staffName'] ?? '';
  30. $staffId = $params['staffId'] ?? 0;
  31. $orderSn = $bill->orderSn ?? '';
  32. $currentChangeType = $params['currentChangeType'] ?? 'putIn';
  33. if ($currentChangeType == 'stockOn') {
  34. $currentCapitalType = 0;
  35. $event = "{$staffName} 手动上架 {$name} " . $addOnNum . $bigUnit;
  36. } elseif ($currentChangeType == 'putIn') {
  37. $event = "采购单 {$orderSn} 入库,{$name} 上架 " . $addOnNum . $bigUnit;
  38. } else {
  39. $event = '';
  40. util::fail('无效动作');
  41. }
  42. $changeData = [
  43. 'mainId' => $mainId,
  44. 'bookSn' => $bookSn,
  45. 'name' => $name,
  46. 'py' => $py,
  47. 'itemId' => $itemId,
  48. 'ptItemId' => $ptItemId,
  49. 'customId' => $customId,
  50. 'customName' => $customName,
  51. 'customNamePy' => $customNamePy,
  52. 'relateId' => $relatedId,
  53. 'relateSecondId' => $bookCustomResId,
  54. 'ptStyle' => 2,
  55. 'capitalType' => $currentCapitalType,
  56. 'io' => 1,
  57. 'changeNum' => $addOnNum,
  58. 'num' => $bookCustomRes->onNum,
  59. 'event' => $event,
  60. 'staffId' => $staffId,
  61. 'staffName' => $staffName,
  62. 'remark' => '',
  63. ];
  64. BookCustomOnChangeClass::add($changeData, true);
  65. return $bookCustomRes;
  66. }
  67. public static function delOnNum($bookCustomRes, $delOnNum, $num, $bill, $shop, $product, $params)
  68. {
  69. $bookCustomRes->onNum = bcsub($bookCustomRes->onNum, $delOnNum);
  70. $bookCustomRes->save();
  71. $bookCustomResId = $bookCustomRes->id ?? 0;
  72. $ioRes = $params['ioRes'] ?? null;
  73. $relatedId = $ioRes->id ?? 0;
  74. $itemId = $product->id ?? 0;
  75. $ptItemId = $product->itemId ?? 0;
  76. $name = $product->name ?? '';
  77. $py = $product->py ?? '';
  78. $bigUnit = $product->bigUnit ?? '扎';
  79. $bookSn = $shop->bookSn ?? '';
  80. $mainId = $shop->mainId ?? 0;
  81. $staffName = $params['staffName'] ?? '';
  82. $staffId = $params['staffId'] ?? 0;
  83. $currentChangeType = $params['currentChangeType'] ?? 'delBook';
  84. if ($currentChangeType == 'ghsCgRefund') {
  85. //供货商采购单售后
  86. $customId = $bookCustomRes->customId ?? 0;
  87. $customName = $bookCustomRes->name ?? '';
  88. $customNamePy = $bookCustomRes->py ?? '';
  89. $orderSn = $bill->orderSn ?? '';
  90. $event = $staffName . ' 售后采购单' . $orderSn . ',下架' . $name . $delOnNum . $bigUnit;
  91. $currentCapitalType = dict::getDict('capitalType', 'ghsCgRefund');
  92. } elseif ($currentChangeType == 'stockOff') {
  93. $customId = $bookCustomRes->customId ?? 0;
  94. $customName = $bookCustomRes->name ?? '';
  95. $customNamePy = $bookCustomRes->py ?? '';
  96. $currentCapitalType = 0;
  97. $event = $staffName . '手动下架' . $name . $delOnNum . $bigUnit;
  98. } elseif ($currentChangeType == 'delBook') {
  99. $customId = $bill->customId ?? 0;
  100. $customName = $bill->customName ?? '';
  101. $customNamePy = $bill->customNamePy ?? '';
  102. $currentCapitalType = dict::getDict('capitalType', 'delBook');
  103. $event = $customName . '减少预订' . $name . $num . $bigUnit . ',其中下架' . $delOnNum . $bigUnit;
  104. } else {
  105. $currentCapitalType = dict::getDict('capitalType', 'delBook');
  106. $customId = 0;
  107. $customName = '';
  108. $customNamePy = '';
  109. $event = '';
  110. util::fail('不存在的运作哈。。。');
  111. }
  112. $changeData = [
  113. 'mainId' => $mainId,
  114. 'bookSn' => $bookSn,
  115. 'name' => $name,
  116. 'py' => $py,
  117. 'itemId' => $itemId,
  118. 'ptItemId' => $ptItemId,
  119. 'customId' => $customId,
  120. 'customName' => $customName,
  121. 'customNamePy' => $customNamePy,
  122. 'relateId' => $relatedId,
  123. 'relateSecondId' => $bookCustomResId,
  124. 'ptStyle' => 2,
  125. 'capitalType' => $currentCapitalType,
  126. 'io' => 0,
  127. 'changeNum' => $delOnNum,
  128. 'num' => $bookCustomRes->onNum,
  129. 'event' => $event,
  130. 'staffId' => $staffId,
  131. 'staffName' => $staffName,
  132. 'remark' => '',
  133. ];
  134. BookCustomOnChangeClass::add($changeData, true);
  135. return $bookCustomRes;
  136. }
  137. public static function addRoadNum($bookCustomRes, $addRoadNum, $bill, $shop, $product, $params)
  138. {
  139. $bookCustomRes->roadNum = bcadd($bookCustomRes->roadNum, $addRoadNum);
  140. $bookCustomRes->save();
  141. $bookItemCustomResId = $bookCustomRes->id ?? 0;
  142. $ioRes = $params['ioRes'] ?? null;
  143. $relatedId = $ioRes->id ?? 0;
  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. $currentCapitalType = dict::getDict('capitalType', 'ghsPurchase');
  154. $customId = $bookCustomRes->customId ?? 0;
  155. $customName = $bookCustomRes->name ?? '';
  156. $customNamePy = $bookCustomRes->py ?? '';
  157. $orderSn = $bill->orderSn ?? '';
  158. $event = "{$staffName} 新增待入库 {$orderSn},路上增加 {$name}" . $addRoadNum . $bigUnit;
  159. $changeData = [
  160. 'mainId' => $mainId,
  161. 'bookSn' => $bookSn,
  162. 'name' => $name,
  163. 'py' => $py,
  164. 'itemId' => $itemId,
  165. 'ptItemId' => $ptItemId,
  166. 'customId' => $customId,
  167. 'customName' => $customName,
  168. 'customNamePy' => $customNamePy,
  169. 'relateId' => $relatedId,
  170. 'relateSecondId' => $bookItemCustomResId,
  171. 'ptStyle' => 2,
  172. 'capitalType' => $currentCapitalType,
  173. 'io' => 1,
  174. 'changeNum' => $addRoadNum,
  175. 'num' => $bookCustomRes->roadNum,
  176. 'event' => $event,
  177. 'staffId' => $staffId,
  178. 'staffName' => $staffName,
  179. 'remark' => '',
  180. ];
  181. BookCustomRoadChangeClass::add($changeData, true);
  182. return $bookCustomRes;
  183. }
  184. public static function delRoadNum($bookCustomRes, $delRoadNum, $num, $bill, $shop, $product, $params)
  185. {
  186. $bookCustomRes->roadNum = bcsub($bookCustomRes->roadNum, $delRoadNum);
  187. $bookCustomRes->save();
  188. $bookItemCustomResId = $bookCustomRes->id ?? 0;
  189. $ioRes = $params['ioRes'] ?? null;
  190. $relatedId = $ioRes->id ?? 0;
  191. //路上减少变动记录
  192. $itemId = $product->id ?? 0;
  193. $ptItemId = $product->itemId ?? 0;
  194. $name = $product->name ?? '';
  195. $py = $product->py ?? '';
  196. $bigUnit = $product->bigUnit ?? '扎';
  197. $bookSn = $shop->bookSn ?? '';
  198. $mainId = $shop->mainId ?? 0;
  199. $currentCapitalType = dict::getDict('capitalType', 'delBook');
  200. $staffName = $params['staffName'] ?? '';
  201. $staffId = $params['staffId'] ?? 0;
  202. $currentChangeType = $params['currentChangeType'] ?? 'delBook';
  203. if ($currentChangeType == 'putIn') {
  204. //入库
  205. $currentCapitalType = dict::getDict('capitalType', 'ghsCheckIn');
  206. $customId = $bookCustomRes->customId ?? 0;
  207. $customName = $bookCustomRes->name ?? '';
  208. $customNamePy = $bookCustomRes->py ?? '';
  209. $orderSn = $bill->orderSn ?? '';
  210. $event = "采购单 {$orderSn} 入库上架,{$name} 路上减少" . $delRoadNum . $bigUnit;
  211. } elseif ($currentChangeType == 'delBook') {
  212. //减少预订
  213. $currentCapitalType = dict::getDict('capitalType', 'delBook');
  214. $customId = $bill->customId ?? 0;
  215. $customName = $bill->customName ?? '';
  216. $customNamePy = $bill->customNamePy ?? '';
  217. $event = $customName . '减少预订' . $name . $num . $bigUnit . ',其中路上减少' . $delRoadNum . $bigUnit;
  218. } elseif ($currentChangeType == 'cgCancel') {
  219. $currentCapitalType = dict::getDict('capitalType', 'ghsCgCancel');
  220. $customId = $bookCustomRes->customId ?? 0;
  221. $customName = $bookCustomRes->customName ?? '';
  222. $customNamePy = $bookCustomRes->customNamePy ?? '';
  223. $orderSn = $bill->orderSn ?? '';
  224. $event = "采购单 {$orderSn} 取消,{$name} 路上减少" . $delRoadNum . $bigUnit;
  225. } else {
  226. $event = '';
  227. $customId = 0;
  228. $customName = '';
  229. $customNamePy = '';
  230. util::fail('此变动方式没有找到');
  231. }
  232. $changeData = [
  233. 'mainId' => $mainId,
  234. 'bookSn' => $bookSn,
  235. 'name' => $name,
  236. 'py' => $py,
  237. 'itemId' => $itemId,
  238. 'ptItemId' => $ptItemId,
  239. 'customId' => $customId,
  240. 'customName' => $customName,
  241. 'customNamePy' => $customNamePy,
  242. 'relateId' => $relatedId,
  243. 'relateSecondId' => $bookItemCustomResId,
  244. 'ptStyle' => 2,
  245. 'capitalType' => $currentCapitalType,
  246. 'io' => 0,
  247. 'changeNum' => $delRoadNum,
  248. 'num' => $bookCustomRes->roadNum,
  249. 'event' => $event,
  250. 'staffId' => $staffId,
  251. 'staffName' => $staffName,
  252. 'remark' => '',
  253. ];
  254. BookCustomRoadChangeClass::add($changeData, true);
  255. return $bookCustomRes;
  256. }
  257. public static function delNeedCgNum($bookCustomRes, $delNeedCgNum, $totalBookNum, $bill, $shop, $product, $params)
  258. {
  259. $bookCustomRes->needCgNum = bcsub($bookCustomRes->needCgNum, $delNeedCgNum);
  260. $bookCustomRes->save();
  261. $bookItemCustomResId = $bookCustomRes->id ?? 0;
  262. $ioRes = $params['ioRes'] ?? null;
  263. $relatedId = $ioRes->id ?? 0;
  264. $itemId = $product->id ?? 0;
  265. $ptItemId = $product->itemId ?? 0;
  266. $name = $product->name ?? '';
  267. $py = $product->py ?? '';
  268. $bigUnit = $product->bigUnit ?? '扎';
  269. $bookSn = $shop->bookSn ?? '';
  270. $mainId = $shop->mainId ?? 0;
  271. $currentCapitalType = dict::getDict('capitalType', 'delBook');
  272. $staffName = $params['staffName'] ?? '';
  273. $staffId = $params['staffId'] ?? 0;
  274. $currentChangeType = $params['currentChangeType'] ?? 'delBook';
  275. if ($currentChangeType == 'addCg') {
  276. $currentCapitalType = dict::getDict('capitalType', 'ghsPurchase');
  277. $customId = $bookCustomRes->customId ?? 0;
  278. $customName = $bookCustomRes->name ?? '';
  279. $customNamePy = $bookCustomRes->py ?? '';
  280. $orderSn = $bill->orderSn ?? '';
  281. $event = $staffName . "增加待入库单 {$orderSn} 减少待采 {$name} " . $delNeedCgNum . $bigUnit;
  282. } elseif ($currentChangeType == 'pdAddStock') {
  283. $customId = 0;
  284. $customName = '';
  285. $customNamePy = '';
  286. $currentCapitalType = dict::getDict('capitalType', 'pd');
  287. $event = $staffName . '盘点增加库存' . $delNeedCgNum . $bigUnit . ',减少待采' . $delNeedCgNum . $bigUnit;
  288. } elseif ($currentChangeType == 'loanStock') {
  289. $currentCapitalType = dict::getDict('capitalType', 'loanStock');
  290. $customId = $bookCustomRes->customId ?? 0;
  291. $customName = $bookCustomRes->name ?? '';
  292. $customNamePy = $bookCustomRes->py ?? '';
  293. $outName = $params['outName'] ?? '';
  294. $event = $staffName . '向' . $outName . '借库存' . $delNeedCgNum . $bigUnit . ',减少待采' . $delNeedCgNum . $bigUnit;
  295. } elseif ($currentChangeType == 'delBook') {
  296. $currentCapitalType = dict::getDict('capitalType', 'delBook');
  297. $customId = $bill->customId ?? 0;
  298. $customName = $bill->customName ?? '';
  299. $customNamePy = $bill->customNamePy ?? '';
  300. $event = $customName . '减少预订' . $name . $totalBookNum . $bigUnit . ',其中减少待采' . $delNeedCgNum . $bigUnit;
  301. } else {
  302. $customId = 0;
  303. $customName = '';
  304. $customNamePy = '';
  305. $event = '';
  306. util::fail('没有找到的操作');
  307. }
  308. $changeData = [
  309. 'mainId' => $mainId,
  310. 'bookSn' => $bookSn,
  311. 'name' => $name,
  312. 'py' => $py,
  313. 'itemId' => $itemId,
  314. 'ptItemId' => $ptItemId,
  315. 'customId' => $customId,
  316. 'customName' => $customName,
  317. 'customNamePy' => $customNamePy,
  318. 'relateId' => $relatedId,
  319. 'relateSecondId' => $bookItemCustomResId,
  320. 'ptStyle' => 2,
  321. 'capitalType' => $currentCapitalType,
  322. 'io' => 0,
  323. 'changeNum' => $delNeedCgNum,
  324. 'num' => $bookCustomRes->needCgNum,
  325. 'event' => $event,
  326. 'staffId' => $staffId,
  327. 'staffName' => $staffName,
  328. 'remark' => '',
  329. ];
  330. BookCustomCgChangeClass::add($changeData, true);
  331. return $bookCustomRes;
  332. }
  333. public static function addBookNum($bookCustomRes, $num, $order, $shop, $product, $params)
  334. {
  335. $currentNum = bcadd($bookCustomRes->bookNum, $num);
  336. $bookCustomRes->bookNum = $currentNum;
  337. $bookCustomRes->box = 0;
  338. $bookCustomRes->save();
  339. $bookItemCustomResId = $bookCustomRes->id ?? 0;
  340. $ioRes = $params['ioRes'] ?? 0;
  341. $relatedId = $ioRes->id ?? 0;
  342. //预订增加变动记录
  343. $itemId = $product->id ?? 0;
  344. $ptItemId = $product->itemId ?? 0;
  345. $name = $product->name ?? '';
  346. $py = $product->py ?? '';
  347. $bigUnit = $product->bigUnit ?? '扎';
  348. $bookSn = $shop->bookSn ?? '';
  349. $mainId = $order->mainId ?? 0;
  350. $customId = $order->customId ?? 0;
  351. $customName = $order->customName ?? '';
  352. $customNamePy = $order->customNamePy ?? '';
  353. $currentCapitalType = dict::getDict('capitalType', 'addBook');
  354. $staffName = $params['staffName'] ?? '';
  355. $staffId = $params['staffId'] ?? 0;
  356. $event = $customName . '预订' . $name . $num . $bigUnit;
  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' => $bookItemCustomResId,
  369. 'ptStyle' => 2,
  370. 'capitalType' => $currentCapitalType,
  371. 'io' => 1,
  372. 'changeNum' => $num,
  373. 'num' => $bookCustomRes->bookNum,
  374. 'event' => $event,
  375. 'staffId' => $staffId,
  376. 'staffName' => $staffName,
  377. 'remark' => '',
  378. ];
  379. BookCustomChangeClass::add($changeData, true);
  380. return $bookCustomRes;
  381. }
  382. public static function addNeedCgNum($bookCustomRes, $addNeedCgNum, $num, $bill, $shop, $product, $params)
  383. {
  384. $bookCustomRes->needCgNum = bcadd($bookCustomRes->needCgNum, $addNeedCgNum);
  385. $bookCustomRes->save();
  386. $bookCustomResId = $bookCustomRes->id ?? 0;
  387. $ioRes = $params['ioRes'] ?? 0;
  388. $relatedId = $ioRes->id ?? 0;
  389. //待采增加变动记录
  390. $itemId = $product->id ?? 0;
  391. $ptItemId = $product->itemId ?? 0;
  392. $name = $product->name ?? '';
  393. $py = $product->py ?? '';
  394. $bigUnit = $product->bigUnit ?? '扎';
  395. $bookSn = $shop->bookSn ?? '';
  396. $mainId = $shop->mainId ?? 0;
  397. $staffName = $params['staffName'] ?? '';
  398. $staffId = $params['staffId'] ?? 0;
  399. $currentChangeType = $params['currentChangeType'] ?? 'addBook';
  400. if ($currentChangeType == 'cgCancel') {
  401. $currentCapitalType = dict::getDict('capitalType', 'ghsCgCancel');
  402. $customId = $bookCustomRes->customId ?? 0;
  403. $customName = $bookCustomRes->name ?? '';
  404. $customNamePy = $bookCustomRes->py ?? '';
  405. $orderSn = $bill->orderSn ?? '';
  406. $event = "采购单 {$orderSn} 取消,{$name} 增加待采" . $addNeedCgNum . $bigUnit;
  407. } elseif ($currentChangeType == 'addBook') {
  408. $currentCapitalType = dict::getDict('capitalType', 'addBook');
  409. $customId = $bill->customId ?? 0;
  410. $customName = $bill->customName ?? '';
  411. $customNamePy = $bill->customNamePy ?? '';
  412. $event = $customName . '预订 ' . $name . $num . $bigUnit . ',增加待采' . $addNeedCgNum . $bigUnit;
  413. } else {
  414. $currentCapitalType = dict::getDict('capitalType', 'addBook');
  415. $customId = 0;
  416. $customName = '';
  417. $customNamePy = '';
  418. $event = '';
  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' => $bookCustomResId,
  433. 'ptStyle' => 2,
  434. 'capitalType' => $currentCapitalType,
  435. 'io' => 1,
  436. 'changeNum' => $addNeedCgNum,
  437. 'num' => $bookCustomRes->needCgNum,
  438. 'event' => $event,
  439. 'staffId' => $staffId,
  440. 'staffName' => $staffName,
  441. 'remark' => '',
  442. ];
  443. BookCustomCgChangeClass::add($changeData, true);
  444. return $bookCustomRes;
  445. }
  446. }