StockInController.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. namespace ghs\controllers;
  3. use bizGhs\order\classes\StockInOrderClass;
  4. use bizGhs\order\classes\StockInOrderItemClass;
  5. use bizGhs\stock\classes\StockInDayClass;
  6. use common\components\dateUtil;
  7. use common\components\util;
  8. use Yii;
  9. //入库 lqh 2021.1.25
  10. class StockInController extends BaseController
  11. {
  12. //入库单盘点,生成需要盘点的花材 ssh 20221208
  13. public function actionCreatePdItem()
  14. {
  15. $post = Yii::$app->request->post();
  16. $ids = $post['ids'] ?? '';
  17. $arr = json_decode($ids, true);
  18. if (is_array($arr) == false) {
  19. util::fail('没有盘点单');
  20. }
  21. $idData = array_column($arr, 'id');
  22. if (empty($idData) || is_array($idData) == false) {
  23. util::fail('没有盘点单哦');
  24. }
  25. $idData = array_filter(array_unique($idData));
  26. $list = StockInOrderClass::getByIds($idData);
  27. if (empty($list)) {
  28. util::fail('没有找到盘点单');
  29. }
  30. $use = [];
  31. $inMainId = 0;
  32. foreach ($list as $item) {
  33. $inMainId = $item['inMainId'] ?? 0;
  34. if ($inMainId != $this->mainId) {
  35. util::fail('入库单有问题');
  36. }
  37. $orderSn = $item['orderSn'] ?? '';
  38. $itemList = StockInOrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*');
  39. if (!empty($itemList)) {
  40. foreach ($itemList as $it) {
  41. $itemId = $it['productId'] ?? 0;
  42. $ptItemId = $it['itemId'] ?? 0;
  43. $use[$itemId] = [
  44. 'mainId' => $inMainId,
  45. 'itemId' => $itemId,
  46. 'ptItemId' => $ptItemId,
  47. ];
  48. }
  49. }
  50. }
  51. if (empty($use)) {
  52. util::fail('没有找到需要盘点的花材');
  53. }
  54. StockInDayClass::deleteByCondition(['mainId' => $inMainId]);
  55. foreach ($use as $info) {
  56. StockInDayClass::add($info);
  57. }
  58. util::complete();
  59. }
  60. //入库列表 lqh 2021.1.25
  61. public function actionList()
  62. {
  63. $get = Yii::$app->request->get();
  64. $orderStatus = isset($get['status']) ? $get['status'] : '';
  65. $where = [];
  66. $where['inShopId'] = $this->shopId;
  67. if (!empty($orderStatus)) {
  68. $where['status'] = $orderStatus;
  69. }
  70. $searchTime = $get['searchTime'] ?? '';
  71. if (!empty($searchTime)) {
  72. $startTime = $get['startTime'] ?? '';
  73. $endTime = $get['endTime'] ?? '';
  74. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  75. $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
  76. }
  77. $list = StockInOrderClass::getOrderList($where);
  78. util::success($list);
  79. }
  80. //入库详情 lqh 2021.1.25
  81. public function actionDetail()
  82. {
  83. $orderSn = Yii::$app->request->get('orderSn', '');
  84. $orderData = StockInOrderClass::getOrderDetail($orderSn, $this->shopId);
  85. util::success($orderData);
  86. }
  87. //确认入库 lqh 2021.1.24
  88. public function actionConfirmOrder()
  89. {
  90. $get = Yii::$app->request->get();
  91. $orderSn = $get['orderSn'];
  92. $connection = Yii::$app->db;
  93. $transaction = $connection->beginTransaction();
  94. try {
  95. StockInOrderClass::confirmOrder($orderSn, $this->shop, $this->adminId);
  96. $transaction->commit();
  97. util::complete("入库成功");
  98. } catch (\Exception $exception) {
  99. Yii::info("确认入库报错:" . $exception->getMessage());
  100. $transaction->rollBack();
  101. util::fail();
  102. }
  103. }
  104. //取消入库 lqh 2021.1.24
  105. public function actionCancelOrder()
  106. {
  107. $get = Yii::$app->request->get();
  108. $orderSn = $get['orderSn'] ?? '';
  109. $order = StockInOrderClass::getByCondition(['orderSn' => $orderSn], true);
  110. if (empty($order)) {
  111. util::fail('订单不存在');
  112. }
  113. if (isset($order->inShopId) == false || $order->inShopId != $this->shopId) {
  114. util::fail('没有权限');
  115. }
  116. $id = $order->id ?? 0;
  117. $info = StockInOrderClass::getLockById($id);
  118. StockInOrderClass::cancelOrder($info, $this->adminId);
  119. util::complete("取消成功");
  120. }
  121. }