BookItemCustomController.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. namespace ghs\controllers;
  3. use bizGhs\book\classes\BookItemClass;
  4. use bizGhs\book\classes\BookItemCustomClass;
  5. use bizGhs\product\classes\ProductClass;
  6. use common\components\util;
  7. use Yii;
  8. class BookItemCustomController extends BaseController
  9. {
  10. //下架 ssh 20240721
  11. public function actionGoOff()
  12. {
  13. $staff = $this->shopAdmin;
  14. if(isset($staff->identity) && $staff->identity == 2){
  15. util::fail('不能操作');
  16. }
  17. $get = Yii::$app->request->get();
  18. $id = $get['id'] ?? 0;
  19. $num = $get['num'] ?? 0;
  20. if(empty($num)){
  21. util::fail('请填写下架数量');
  22. }
  23. $shop = $this->shop;
  24. $bookSn = $shop->bookSn ?? 0;
  25. if (empty($bookSn)) {
  26. util::fail('预订没有开户');
  27. }
  28. $book = BookItemCustomClass::getById($id, true);
  29. if (empty($book) || $book->bookSn != $bookSn) {
  30. util::fail('当前无法操作');
  31. }
  32. $staff = $this->shopAdmin;
  33. $staffId = $staff->id ?? 0;
  34. $staffName = $staff->name ?? '';
  35. $params = ['staffId' => $staffId, 'staffName' => $staffName, 'staff' => $staff];
  36. BookItemCustomClass::goOff($book, $shop, $params, $num);
  37. util::complete('操作成功');
  38. }
  39. //标记装箱 ssh 20240721
  40. public function actionToBox()
  41. {
  42. $get = Yii::$app->request->get();
  43. $id = $get['id'] ?? 0;
  44. $shop = $this->shop;
  45. $bookSn = $shop->bookSn ?? 0;
  46. if (empty($bookSn)) {
  47. util::fail('预订没有开户');
  48. }
  49. $book = BookItemCustomClass::getById($id, true);
  50. if (empty($book) || $book->bookSn != $bookSn) {
  51. util::fail('当前无法操作');
  52. }
  53. BookItemCustomClass::toBox($book);
  54. util::complete('操作成功');
  55. }
  56. //取消装箱 ssh 20240721
  57. public function actionCancelBox()
  58. {
  59. $get = Yii::$app->request->get();
  60. $id = $get['id'] ?? 0;
  61. $shop = $this->shop;
  62. $bookSn = $shop->bookSn ?? 0;
  63. if (empty($bookSn)) {
  64. util::fail('预订没有开户');
  65. }
  66. $book = BookItemCustomClass::getById($id, true);
  67. if (empty($book) || $book->bookSn != $bookSn) {
  68. util::fail('当前无法操作');
  69. }
  70. BookItemCustomClass::cancelBox($book);
  71. util::complete('操作成功');
  72. }
  73. //仓库有货上架和上齐 ssh 20240721
  74. public function actionGoOn()
  75. {
  76. $staff = $this->shopAdmin;
  77. if(isset($staff->identity) && $staff->identity == 2){
  78. util::fail('不能操作');
  79. }
  80. $get = Yii::$app->request->get();
  81. $id = $get['id'] ?? 0;
  82. $num = $get['num'] ?? 0;
  83. $shop = $this->shop;
  84. $bookSn = $shop->bookSn ?? 0;
  85. if (empty($bookSn)) {
  86. util::fail('预订没有开户');
  87. }
  88. $book = BookItemCustomClass::getById($id, true);
  89. if (empty($book) || $book->bookSn != $bookSn) {
  90. util::fail('当前无法操作');
  91. }
  92. $staff = $this->shopAdmin;
  93. $staffId = $staff->id ?? 0;
  94. $staffName = $staff->name ?? '';
  95. $params = ['staffId' => $staffId, 'staffName' => $staffName, 'staff' => $staff];
  96. BookItemCustomClass::goOn($book, $shop, $params, $num);
  97. util::complete('操作成功');
  98. }
  99. //批量上齐 ssh 20240812
  100. public function actionBatchGoOn()
  101. {
  102. util::complete();
  103. }
  104. //预订客户列表 ssh 20240616
  105. public function actionList()
  106. {
  107. $get = Yii::$app->request->get();
  108. $where = [];
  109. $where['mainId'] = $this->mainId;
  110. $bookSn = $get['bookSn'] ?? '';
  111. if (empty($bookSn)) {
  112. $shop = $this->shop;
  113. $bookSn = $shop->bookSn ?? 0;
  114. if (empty($bookSn)) {
  115. util::success(['list' => [], 'hint' => 'no bookSn']);
  116. }
  117. }
  118. $where['bookSn'] = $bookSn;
  119. $customId = $get['customId'] ?? 0;
  120. if (!empty($customId)) {
  121. $where['customId'] = $customId;
  122. }
  123. $itemId = $get['itemId'] ?? 0;
  124. $remainNum = 0;
  125. $remainName = '';
  126. if (!empty($itemId)) {
  127. $where['itemId'] = $itemId;
  128. //显示剩余数量
  129. $product = ProductClass::getById($itemId, true);
  130. $booItem = BookItemClass::getByCondition(['bookSn' => $bookSn, 'itemId' => $itemId], true);
  131. if (!empty($booItem)) {
  132. $stock = $product->stock ?? 0;
  133. $onNum = $booItem->onNum ?? 0;
  134. $remainNum = bcsub($stock, $onNum);
  135. $remainName = $product->name ?? '';
  136. }
  137. }
  138. $list = BookItemCustomClass::getAllByCondition($where, '(bookNum-onNum) DESC', '*');
  139. util::success(['list' => $list, 'remainNum' => $remainNum, 'remainName' => $remainName]);
  140. }
  141. }