StockInController.php 3.9 KB

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