CheckOrderController.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. namespace hd\controllers;
  3. use bizGhs\order\classes\CheckOrderClass;
  4. use bizGhs\product\classes\ProductClass;
  5. use Yii;
  6. use common\components\util;
  7. class CheckOrderController extends BaseController
  8. {
  9. //订单列表 ssh 2021.1.14
  10. public function actionList()
  11. {
  12. $get = Yii::$app->request->get();
  13. $orderStatus = isset($get['status']) ? $get['status'] : '';
  14. $where = [];
  15. $where['shopId'] = $this->shopId;
  16. if (!empty($orderStatus)) {
  17. $where['status'] = $orderStatus;
  18. }
  19. $list = CheckOrderClass::getOrderList($where);
  20. util::success($list);
  21. }
  22. //订单详情 2021.1.22 lqh
  23. public function actionDetail()
  24. {
  25. $orderSn = Yii::$app->request->get('orderSn', '');
  26. $orderData = CheckOrderClass::getOrderDetail($orderSn, $this->shopId);
  27. util::success($orderData);
  28. }
  29. //盘点确认 lqh 2021.1.22
  30. public function actionCreateOrder()
  31. {
  32. $post = Yii::$app->request->post();
  33. $post['sjId'] = $this->sjId;
  34. $post['shopId'] = $this->shopId;
  35. $post['adminId'] = $this->adminId;
  36. $this->saveOrder($post, false, false);
  37. }
  38. //盘点存草稿 lqh 2021.1.22
  39. public function actionCreateDraft()
  40. {
  41. $post = Yii::$app->request->post();
  42. $post['sjId'] = $this->sjId;
  43. $post['shopId'] = $this->shopId;
  44. $post['adminId'] = $this->adminId;
  45. $this->saveOrder($post, true, false);
  46. }
  47. //编辑草稿 ,继续保存草稿
  48. public function actionUpdateDraft()
  49. {
  50. $post = Yii::$app->request->post();
  51. $post['sjId'] = $this->sjId;
  52. $post['shopId'] = $this->shopId;
  53. $post['adminId'] = $this->adminId;
  54. $orderSn = $post['orderSn'] ?? '';
  55. $orderData = CheckOrderClass::orderExist($orderSn, $this->shopId);
  56. if ($orderData['status'] != CheckOrderClass::STATUS_DRAFT) {
  57. util::fail("订单不存在");
  58. }
  59. $this->saveOrder($post, true, true);
  60. }
  61. //编辑草稿, 确认
  62. public function actionUpdateOrder()
  63. {
  64. $post = Yii::$app->request->post();
  65. $post['sjId'] = $this->sjId;
  66. $post['shopId'] = $this->shopId;
  67. $post['adminId'] = $this->adminId;
  68. $orderSn = $post['orderSn'] ?? '';
  69. $orderData = CheckOrderClass::orderExist($orderSn, $this->shopId);
  70. if ($orderData['status'] != CheckOrderClass::STATUS_DRAFT) {
  71. util::fail("订单不存在");
  72. }
  73. $this->saveOrder($post, false, true);
  74. }
  75. protected function saveOrder($post, $draft = false, $update = false)
  76. {
  77. $ghsItemInfo = $post['itemInfo'] ?? '';
  78. if (empty($ghsItemInfo)) {
  79. util::fail('请选择花材');
  80. }
  81. $ghsItemInfo = json_decode($ghsItemInfo, true);
  82. if (!is_array($ghsItemInfo)) {
  83. util::fail('花材格式不正确');
  84. }
  85. //判断花材格式,是否属于当前门店
  86. ProductClass::valid($ghsItemInfo, $this->mainId);
  87. foreach ($ghsItemInfo as $key => $item) {
  88. //如果盘点数是99999则转为0
  89. if (isset($item['bigNum']) && $item['bigNum'] == 99999) {
  90. $ghsItemInfo[$key]['bigNum'] = 0;
  91. }
  92. }
  93. $post['itemInfo'] = $ghsItemInfo;
  94. if ($update === true) {
  95. //编辑
  96. $order = CheckOrderClass::opOrder($post, $draft, $update);
  97. } else {
  98. $order = CheckOrderClass::opOrder($post, $draft, $update);
  99. }
  100. if ($order) {
  101. util::success($order);
  102. } else {
  103. util::fail();
  104. }
  105. }
  106. }