CheckOrderController.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. namespace ghs\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 linqh
  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. //盘点确认 linqh 2021.1.22
  30. public function actionCreateOrder()
  31. {
  32. $shopAdmin = $this->shopAdmin;
  33. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  34. util::fail('超管才能盘点');
  35. }
  36. $post = Yii::$app->request->post();
  37. $post['sjId'] = $this->sjId;
  38. $post['shopId'] = $this->shopId;
  39. $post['adminId'] = $this->adminId;
  40. //盘点是否有未处理的草稿,有的话先处理之前的草稿??
  41. //todo
  42. $this->saveOrder($post,false,false);
  43. }
  44. //盘点存草稿 linqh 2021.1.22
  45. public function actionCreateDraft()
  46. {
  47. $shopAdmin = $this->shopAdmin;
  48. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  49. util::fail('超管才能操作');
  50. }
  51. $post = Yii::$app->request->post();
  52. $post['sjId'] = $this->sjId;
  53. $post['shopId'] = $this->shopId;
  54. $post['adminId'] = $this->adminId;
  55. //盘点是否有未处理的草稿,有的话先处理之前的草稿??
  56. //todo ??
  57. $this->saveOrder($post,true,false);
  58. }
  59. //编辑草稿 ,继续保存草稿
  60. public function actionUpdateDraft()
  61. {
  62. $shopAdmin = $this->shopAdmin;
  63. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  64. util::fail('超管才能操作');
  65. }
  66. $post = Yii::$app->request->post();
  67. $post['sjId'] = $this->sjId;
  68. $post['shopId'] = $this->shopId;
  69. $post['adminId'] = $this->adminId;
  70. $orderSn = $post['orderSn']??'';
  71. $orderData = CheckOrderClass::orderExist($orderSn,$this->shopId);
  72. if($orderData['status'] != CheckOrderClass::STATUS_DRAFT){
  73. util::fail("订单不存在");
  74. }
  75. $this->saveOrder($post,true,true);
  76. }
  77. //编辑草稿, 确认
  78. public function actionUpdateOrder()
  79. {
  80. $shopAdmin = $this->shopAdmin;
  81. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  82. util::fail('超管才能操作');
  83. }
  84. $post = Yii::$app->request->post();
  85. $post['sjId'] = $this->sjId;
  86. $post['shopId'] = $this->shopId;
  87. $post['adminId'] = $this->adminId;
  88. $orderSn = $post['orderSn']??'';
  89. $orderData = CheckOrderClass::orderExist($orderSn,$this->shopId);
  90. if($orderData['status'] != CheckOrderClass::STATUS_DRAFT){
  91. util::fail("订单不存在");
  92. }
  93. $this->saveOrder($post,false,true);
  94. }
  95. protected function saveOrder($post,$draft=false,$update=false)
  96. {
  97. $shopAdmin = $this->shopAdmin;
  98. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  99. util::fail('超管才能操作');
  100. }
  101. $ghsItemInfo = $post['itemInfo']??'';
  102. if(empty($ghsItemInfo)){
  103. util::fail('请选择花材');
  104. }
  105. $ghsItemInfo = json_decode($ghsItemInfo,true); // [{productId:0,bigNum:1,smallNum:0}]
  106. if(!is_array($ghsItemInfo)){
  107. util::fail('花材格式不正确');
  108. }
  109. //判断花材格式,是否属于当前门店
  110. ProductClass::valid($ghsItemInfo,$this->shopId);
  111. $post['itemInfo'] = $ghsItemInfo;
  112. if($update===true){
  113. //编辑
  114. $order = CheckOrderClass::opOrder($post,$draft,$update);
  115. }else{
  116. $order = CheckOrderClass::opOrder($post,$draft,$update);
  117. }
  118. if($order){
  119. util::success($order);
  120. }else{
  121. util::fail();
  122. }
  123. }
  124. }