StockInController.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. $id = $item['id'] ?? 0;
  51. StockInOrderClass::updateById($id, ['check' => 1]);
  52. }
  53. if (empty($use)) {
  54. util::fail('没有找到需要盘点的花材');
  55. }
  56. StockInDayClass::deleteByCondition(['mainId' => $inMainId]);
  57. foreach ($use as $info) {
  58. StockInDayClass::add($info);
  59. }
  60. util::complete();
  61. }
  62. //入库列表 lqh 2021.1.25
  63. public function actionList()
  64. {
  65. $get = Yii::$app->request->get();
  66. $orderStatus = isset($get['status']) ? $get['status'] : '';
  67. $where = [];
  68. $where['inShopId'] = $this->shopId;
  69. if (!empty($orderStatus)) {
  70. $where['status'] = $orderStatus;
  71. }
  72. $searchTime = $get['searchTime'] ?? '';
  73. if (!empty($searchTime)) {
  74. $startTime = $get['startTime'] ?? '';
  75. $endTime = $get['endTime'] ?? '';
  76. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  77. $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
  78. }
  79. $list = StockInOrderClass::getOrderList($where);
  80. util::success($list);
  81. }
  82. //入库详情 lqh 2021.1.25
  83. public function actionDetail()
  84. {
  85. $orderSn = Yii::$app->request->get('orderSn', '');
  86. $orderData = StockInOrderClass::getOrderDetail($orderSn, $this->shopId);
  87. util::success($orderData);
  88. }
  89. //确认入库 lqh 2021.1.24
  90. public function actionConfirmOrder()
  91. {
  92. $get = Yii::$app->request->get();
  93. $orderSn = $get['orderSn'];
  94. $connection = Yii::$app->db;
  95. $transaction = $connection->beginTransaction();
  96. try {
  97. StockInOrderClass::confirmOrder($orderSn, $this->shop, $this->adminId);
  98. $transaction->commit();
  99. util::complete("入库成功");
  100. } catch (\Exception $exception) {
  101. Yii::info("确认入库报错:" . $exception->getMessage());
  102. $transaction->rollBack();
  103. util::fail();
  104. }
  105. }
  106. //取消入库 lqh 2021.1.24
  107. public function actionCancelOrder()
  108. {
  109. $get = Yii::$app->request->get();
  110. $orderSn = $get['orderSn'] ?? '';
  111. $order = StockInOrderClass::getByCondition(['orderSn' => $orderSn], true);
  112. if (empty($order)) {
  113. util::fail('订单不存在');
  114. }
  115. if (isset($order->inShopId) == false || $order->inShopId != $this->shopId) {
  116. util::fail('没有权限');
  117. }
  118. $id = $order->id ?? 0;
  119. $info = StockInOrderClass::getLockById($id);
  120. StockInOrderClass::cancelOrder($info, $this->adminId);
  121. util::complete("取消成功");
  122. }
  123. }