CheckOrderController.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. $post = Yii::$app->request->post();
  48. $post['sjId'] = $this->sjId;
  49. $post['shopId'] = $this->shopId;
  50. $post['adminId'] = $this->adminId;
  51. //盘点是否有未处理的草稿,有的话先处理之前的草稿??
  52. //todo ??
  53. $this->saveOrder($post,true,false);
  54. }
  55. //编辑草稿 ,继续保存草稿
  56. public function actionUpdateDraft()
  57. {
  58. $post = Yii::$app->request->post();
  59. $post['sjId'] = $this->sjId;
  60. $post['shopId'] = $this->shopId;
  61. $post['adminId'] = $this->adminId;
  62. $orderSn = $post['orderSn']??'';
  63. $orderData = CheckOrderClass::orderExist($orderSn,$this->shopId);
  64. if($orderData['status'] != CheckOrderClass::STATUS_DRAFT){
  65. util::fail("订单不存在");
  66. }
  67. $this->saveOrder($post,true,true);
  68. }
  69. //编辑草稿, 确认
  70. public function actionUpdateOrder()
  71. {
  72. $post = Yii::$app->request->post();
  73. $post['sjId'] = $this->sjId;
  74. $post['shopId'] = $this->shopId;
  75. $post['adminId'] = $this->adminId;
  76. $orderSn = $post['orderSn']??'';
  77. $orderData = CheckOrderClass::orderExist($orderSn,$this->shopId);
  78. if($orderData['status'] != CheckOrderClass::STATUS_DRAFT){
  79. util::fail("订单不存在");
  80. }
  81. $this->saveOrder($post,false,true);
  82. }
  83. protected function saveOrder($post,$draft=false,$update=false)
  84. {
  85. $ghsItemInfo = $post['itemInfo']??'';
  86. if(empty($ghsItemInfo)){
  87. util::fail('请选择花材');
  88. }
  89. $ghsItemInfo = json_decode($ghsItemInfo,true); // [{productId:0,bigNum:1,smallNum:0}]
  90. if(!is_array($ghsItemInfo)){
  91. util::fail('花材格式不正确');
  92. }
  93. //判断花材格式,是否属于当前门店
  94. ProductClass::valid($ghsItemInfo,$this->shopId);
  95. $post['itemInfo'] = $ghsItemInfo;
  96. if($update===true){
  97. //编辑
  98. $order = CheckOrderClass::opOrder($post,$draft,$update);
  99. }else{
  100. $order = CheckOrderClass::opOrder($post,$draft,$update);
  101. }
  102. if($order){
  103. util::success($order);
  104. }else{
  105. util::fail();
  106. }
  107. }
  108. }