BookItemCustomController.php 4.4 KB

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