BookItemCustomController.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <?php
  2. namespace ghs\controllers;
  3. use bizGhs\book\classes\BookItemClass;
  4. use bizGhs\book\classes\BookItemCustomClass;
  5. use bizGhs\order\classes\OrderClass;
  6. use bizGhs\product\classes\ProductClass;
  7. use common\components\util;
  8. use Yii;
  9. class BookItemCustomController extends BaseController
  10. {
  11. //获取对象资源 ssh 20240829
  12. public function actionGetInfo()
  13. {
  14. $get = Yii::$app->request->get();
  15. $orderId = $get['orderId'] ?? 0;
  16. $productId = $get['productId'] ?? 0;
  17. $shop = $this->shop;
  18. $order = OrderClass::getById($orderId, true);
  19. if (empty($order)) {
  20. util::fail('没有找到订单');
  21. }
  22. $bookSn = $shop->bookSn ?? 0;
  23. if (empty($bookSn)) {
  24. util::fail('当前不是在预订活动中');
  25. }
  26. $customId = $order->customId ?? 0;
  27. $res = BookItemCustomClass::getByCondition(['bookSn' => $bookSn, 'customId' => $customId, 'itemId' => $productId], true);
  28. if (empty($res)) {
  29. util::fail('数据有问题');
  30. }
  31. util::success(['res' => $res]);
  32. }
  33. //下架 ssh 20240721
  34. public function actionGoOff()
  35. {
  36. $staff = $this->shopAdmin;
  37. if (isset($staff->identity) && $staff->identity == 2) {
  38. util::fail('不能操作');
  39. }
  40. $get = Yii::$app->request->get();
  41. $id = $get['id'] ?? 0;
  42. $num = $get['num'] ?? 0;
  43. if (empty($num)) {
  44. util::fail('请填写下架数量');
  45. }
  46. $shop = $this->shop;
  47. $bookSn = $shop->bookSn ?? 0;
  48. if (empty($bookSn)) {
  49. util::fail('预订没有开户');
  50. }
  51. $book = BookItemCustomClass::getById($id, true);
  52. if (empty($book) || $book->bookSn != $bookSn) {
  53. util::fail('当前无法操作');
  54. }
  55. $staff = $this->shopAdmin;
  56. $staffId = $staff->id ?? 0;
  57. $staffName = $staff->name ?? '';
  58. $params = ['staffId' => $staffId, 'staffName' => $staffName, 'staff' => $staff];
  59. BookItemCustomClass::goOff($book, $shop, $params, $num);
  60. util::complete('操作成功');
  61. }
  62. //标记装箱 ssh 20240721
  63. public function actionToBox()
  64. {
  65. $get = Yii::$app->request->get();
  66. $id = $get['id'] ?? 0;
  67. $shop = $this->shop;
  68. $bookSn = $shop->bookSn ?? 0;
  69. if (empty($bookSn)) {
  70. util::fail('预订没有开户');
  71. }
  72. $book = BookItemCustomClass::getById($id, true);
  73. if (empty($book) || $book->bookSn != $bookSn) {
  74. util::fail('当前无法操作');
  75. }
  76. BookItemCustomClass::toBox($book);
  77. util::complete('操作成功');
  78. }
  79. //取消装箱 ssh 20240721
  80. public function actionCancelBox()
  81. {
  82. $get = Yii::$app->request->get();
  83. $id = $get['id'] ?? 0;
  84. $shop = $this->shop;
  85. $bookSn = $shop->bookSn ?? 0;
  86. if (empty($bookSn)) {
  87. util::fail('预订没有开户');
  88. }
  89. $book = BookItemCustomClass::getById($id, true);
  90. if (empty($book) || $book->bookSn != $bookSn) {
  91. util::fail('当前无法操作');
  92. }
  93. BookItemCustomClass::cancelBox($book);
  94. util::complete('操作成功');
  95. }
  96. //仓库有货上架和上齐 ssh 20240721
  97. public function actionGoOn()
  98. {
  99. $staff = $this->shopAdmin;
  100. if (isset($staff->identity) && $staff->identity == 2) {
  101. util::fail('不能操作');
  102. }
  103. $get = Yii::$app->request->get();
  104. $id = $get['id'] ?? 0;
  105. $num = $get['num'] ?? 0;
  106. $shop = $this->shop;
  107. $bookSn = $shop->bookSn ?? 0;
  108. if (empty($bookSn)) {
  109. util::fail('预订没有开启');
  110. }
  111. $book = BookItemCustomClass::getById($id, true);
  112. if (empty($book) || $book->bookSn != $bookSn) {
  113. util::fail('当前无法操作');
  114. }
  115. $staff = $this->shopAdmin;
  116. $staffId = $staff->id ?? 0;
  117. $staffName = $staff->name ?? '';
  118. $params = ['staffId' => $staffId, 'staffName' => $staffName, 'staff' => $staff];
  119. BookItemCustomClass::goOn($book, $shop, $params, $num);
  120. util::complete('操作成功');
  121. }
  122. //批量上齐 ssh 20240812
  123. public function actionBatchGoOn()
  124. {
  125. $post = Yii::$app->request->post();
  126. $ids = $post['ids'] ?? '';
  127. $staff = $this->shopAdmin;
  128. if (isset($staff->identity) && $staff->identity == 2) {
  129. util::fail('不能操作');
  130. }
  131. $shop = $this->shop;
  132. $bookSn = $shop->bookSn ?? 0;
  133. if (empty($bookSn)) {
  134. util::fail('预订没有开启');
  135. }
  136. if (empty($ids)) {
  137. util::fail('请选择要上齐的项');
  138. }
  139. $arr = json_decode($ids, true);
  140. if (empty($arr)) {
  141. util::fail('请选择项');
  142. }
  143. $staff = $this->shopAdmin;
  144. $staffId = $staff->id ?? 0;
  145. $staffName = $staff->name ?? '';
  146. $params = ['staffId' => $staffId, 'staffName' => $staffName, 'staff' => $staff];
  147. $connection = Yii::$app->db;
  148. $transaction = $connection->beginTransaction();
  149. try {
  150. foreach ($arr as $id) {
  151. $num = 0;
  152. $book = BookItemCustomClass::getById($id, true);
  153. if (empty($book)) {
  154. util::fail('有选择项没有找到');
  155. }
  156. if ($book->bookSn != $bookSn) {
  157. util::fail('有选择的项不是当前预订活动');
  158. }
  159. BookItemCustomClass::goOn($book, $shop, $params, $num);
  160. }
  161. $transaction->commit();
  162. util::complete();
  163. } catch (\Exception $e) {
  164. Yii::info("操作失败原因:" . $e->getMessage());
  165. $transaction->rollBack();
  166. util::fail('操作失败');
  167. }
  168. }
  169. //预订客户列表 ssh 20240616
  170. public function actionList()
  171. {
  172. $get = Yii::$app->request->get();
  173. $where = [];
  174. $where['mainId'] = $this->mainId;
  175. $bookSn = $get['bookSn'] ?? '';
  176. if (empty($bookSn)) {
  177. $shop = $this->shop;
  178. $bookSn = $shop->bookSn ?? 0;
  179. if (empty($bookSn)) {
  180. util::success(['list' => [], 'hint' => 'no bookSn']);
  181. }
  182. }
  183. $where['bookSn'] = $bookSn;
  184. $customId = $get['customId'] ?? 0;
  185. if (!empty($customId)) {
  186. $where['customId'] = $customId;
  187. }
  188. $itemId = $get['itemId'] ?? 0;
  189. $remainNum = 0;
  190. $remainName = '';
  191. if (!empty($itemId)) {
  192. $where['itemId'] = $itemId;
  193. //显示剩余数量
  194. $product = ProductClass::getById($itemId, true);
  195. $booItem = BookItemClass::getByCondition(['bookSn' => $bookSn, 'itemId' => $itemId], true);
  196. if (!empty($booItem)) {
  197. $stock = $product->stock ?? 0;
  198. $onNum = $booItem->onNum ?? 0;
  199. $remainNum = bcsub($stock, $onNum);
  200. $remainName = $product->name ?? '';
  201. }
  202. }
  203. $list = BookItemCustomClass::getAllByCondition($where, '(bookNum-onNum) DESC', '*');
  204. util::success(['list' => $list, 'remainNum' => $remainNum, 'remainName' => $remainName]);
  205. }
  206. }