BookItemCustomController.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. $post = Yii::$app->request->post();
  103. $ids = $post['ids']??'';
  104. $staff = $this->shopAdmin;
  105. if(isset($staff->identity) && $staff->identity == 2){
  106. util::fail('不能操作');
  107. }
  108. $shop = $this->shop;
  109. $bookSn = $shop->bookSn ?? 0;
  110. if (empty($bookSn)) {
  111. util::fail('预订没有开启');
  112. }
  113. if(empty($ids)){
  114. util::fail('请选择要上齐的项');
  115. }
  116. $arr = json_decode($ids,true);
  117. if(empty($arr)){
  118. util::fail('请选择项');
  119. }
  120. $staff = $this->shopAdmin;
  121. $staffId = $staff->id ?? 0;
  122. $staffName = $staff->name ?? '';
  123. $params = ['staffId' => $staffId, 'staffName' => $staffName, 'staff' => $staff];
  124. $connection = Yii::$app->db;
  125. $transaction = $connection->beginTransaction();
  126. try {
  127. foreach($arr as $id){
  128. $num = 0;
  129. $book = BookItemCustomClass::getById($id, true);
  130. if (empty($book)) {
  131. util::fail('有选择项没有找到');
  132. }
  133. if($book->bookSn != $bookSn){
  134. util::fail('有选择的项不是当前预订活动');
  135. }
  136. BookItemCustomClass::goOn($book, $shop, $params, $num);
  137. }
  138. $transaction->commit();
  139. util::complete();
  140. } catch (\Exception $e) {
  141. Yii::info("操作失败原因:" . $e->getMessage());
  142. $transaction->rollBack();
  143. util::fail('操作失败');
  144. }
  145. }
  146. //预订客户列表 ssh 20240616
  147. public function actionList()
  148. {
  149. $get = Yii::$app->request->get();
  150. $where = [];
  151. $where['mainId'] = $this->mainId;
  152. $bookSn = $get['bookSn'] ?? '';
  153. if (empty($bookSn)) {
  154. $shop = $this->shop;
  155. $bookSn = $shop->bookSn ?? 0;
  156. if (empty($bookSn)) {
  157. util::success(['list' => [], 'hint' => 'no bookSn']);
  158. }
  159. }
  160. $where['bookSn'] = $bookSn;
  161. $customId = $get['customId'] ?? 0;
  162. if (!empty($customId)) {
  163. $where['customId'] = $customId;
  164. }
  165. $itemId = $get['itemId'] ?? 0;
  166. $remainNum = 0;
  167. $remainName = '';
  168. if (!empty($itemId)) {
  169. $where['itemId'] = $itemId;
  170. //显示剩余数量
  171. $product = ProductClass::getById($itemId, true);
  172. $booItem = BookItemClass::getByCondition(['bookSn' => $bookSn, 'itemId' => $itemId], true);
  173. if (!empty($booItem)) {
  174. $stock = $product->stock ?? 0;
  175. $onNum = $booItem->onNum ?? 0;
  176. $remainNum = bcsub($stock, $onNum);
  177. $remainName = $product->name ?? '';
  178. }
  179. }
  180. $list = BookItemCustomClass::getAllByCondition($where, '(bookNum-onNum) DESC', '*');
  181. util::success(['list' => $list, 'remainNum' => $remainNum, 'remainName' => $remainName]);
  182. }
  183. }