StockInController.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. //惠雅鲜花搜索BUG兼容
  74. if (in_array($this->shopId, [2167, 2164])) {
  75. $searchTime = $get['searchTime'] ?? 'today';
  76. }
  77. if (!empty($searchTime)) {
  78. $startTime = $get['startTime'] ?? '';
  79. $endTime = $get['endTime'] ?? '';
  80. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  81. $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
  82. }
  83. $list = StockInOrderClass::getOrderList($where);
  84. util::success($list);
  85. }
  86. //入库详情 lqh 2021.1.25
  87. public function actionDetail()
  88. {
  89. $orderSn = Yii::$app->request->get('orderSn', '');
  90. $orderData = StockInOrderClass::getOrderDetail($orderSn, $this->shopId);
  91. util::success($orderData);
  92. }
  93. //确认入库 lqh 2021.1.24
  94. public function actionConfirmOrder()
  95. {
  96. $get = Yii::$app->request->get();
  97. $orderSn = $get['orderSn'];
  98. $connection = Yii::$app->db;
  99. $transaction = $connection->beginTransaction();
  100. try {
  101. StockInOrderClass::confirmOrder($orderSn, $this->shop, $this->adminId);
  102. $transaction->commit();
  103. util::complete("入库成功");
  104. } catch (\Exception $exception) {
  105. Yii::info("确认入库报错:" . $exception->getMessage());
  106. $transaction->rollBack();
  107. util::fail();
  108. }
  109. }
  110. //取消入库 lqh 2021.1.24
  111. public function actionCancelOrder()
  112. {
  113. $get = Yii::$app->request->get();
  114. $orderSn = $get['orderSn'] ?? '';
  115. $order = StockInOrderClass::getByCondition(['orderSn' => $orderSn], true);
  116. if (empty($order)) {
  117. util::fail('订单不存在');
  118. }
  119. if (isset($order->inShopId) == false || $order->inShopId != $this->shopId) {
  120. util::fail('没有权限');
  121. }
  122. $id = $order->id ?? 0;
  123. $info = StockInOrderClass::getLockById($id);
  124. StockInOrderClass::cancelOrder($info, $this->adminId);
  125. util::complete("取消成功");
  126. }
  127. }