PdGoodsController.php 3.1 KB

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