FreightController.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <?php
  2. namespace backend\modules\mall\controllers;
  3. use backend\controllers\MallController;
  4. use common\enums\StatusEnum;
  5. use common\models\goods\FreeShippingRules;
  6. use common\models\goods\FreightRules;
  7. use common\models\goods\GoodsCate;
  8. use common\models\goods\GoodsCateRelate;
  9. use Yii;
  10. /**
  11. *
  12. * 货运控制器
  13. * @Author bing
  14. * @DateTime 2021-08-16 13:12:44
  15. * @copyright: Copyright (c) 2020 广东七件事集团
  16. */
  17. class FreightController extends MallController
  18. {
  19. /**
  20. * 货运规则
  21. * @Author bing
  22. * @DateTime 2021-08-26 15:05:10
  23. * @copyright: Copyright (c) 2020 广东七件事集团
  24. * @return void
  25. */
  26. public function actionRules(){
  27. $request = \Yii::$app->request;
  28. if ($request->isAjax) {
  29. if($request->isGet){
  30. $keyword = Yii::$app->request->get('keyword', '');
  31. $where = [['mall_id' => $this->mall['id'], 'mch_id' => $this->admin->mch_id, 'status' => StatusEnum::ENABLED]];
  32. $keyword && $where[] = ['like', 'name', $keyword . '%', false];
  33. $order = 'id desc';
  34. $params = compact('where', 'order');
  35. $page_data = FreightRules::listPage($params);
  36. if($page_data === false) return $this->error(FreightRules::getStaticError());
  37. return $this->success('操作成功',$page_data);
  38. }else{
  39. $form = Yii::$app->request->post();
  40. $rules = [[['id'], 'required'], [['id'], 'integer']];
  41. switch ($form['type']) {
  42. case 'destroy':
  43. $form['status'] = StatusEnum::DELETE;
  44. $rules[] = [['status'], 'required'];
  45. break;
  46. case 'default':
  47. $rules[] = [['is_default'], 'required'];
  48. break;
  49. }
  50. $res = Yii::$app->services->validate->validate($form, $rules);
  51. if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  52. $form['mall_id'] = $this->mall['id'];
  53. $form['mch_id'] = $this->admin->mch_id;
  54. $res = FreightRules::setData($form);
  55. if ($res === false) return $this->error(FreightRules::getStaticError());
  56. return $this->success('操作成功',[]);
  57. }
  58. }
  59. return $this->render($this->action->id);
  60. }
  61. /**
  62. * 货运规则
  63. * @Author bing
  64. * @DateTime 2021-08-26 15:05:10
  65. * @copyright: Copyright (c) 2020 广东七件事集团
  66. * @return void
  67. */
  68. public function actionEdit(){
  69. if (Yii::$app->request->isAjax) {
  70. if (Yii::$app->request->isGet) {
  71. $get = Yii::$app->request->get();
  72. $res = Yii::$app->services->validate->validate($get, [[['id'], 'required'], [['id'], 'integer']]);
  73. if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  74. $detail = FreightRules::getOne([['id' => $get['id'], 'mall_id' => $this->mall_id, 'mch_id' => $this->admin->mch_id]], true);
  75. $detail['rule'] = json_decode($detail['rule'],true);
  76. if (is_array($detail['rule'])) {
  77. foreach ($detail['rule'] as &$ruleItem) {
  78. !isset($ruleItem['is_enable_ladder_condition']) && $ruleItem['is_enable_ladder_condition'] = 0;
  79. !isset($ruleItem['ladder_condition']) && $ruleItem['ladder_condition'] = [];
  80. }
  81. }
  82. return $this->success('操作成功',compact('detail'));
  83. } else {
  84. $form = Yii::$app->request->post('form');
  85. $form = json_decode($form,true);
  86. $id = Yii::$app->request->get('id');
  87. $res = Yii::$app->services->validate->validate($form, [
  88. [['id','select_com','compute_type'], 'integer'],
  89. [['name', 'type', 'rule'], 'safe'],
  90. ]);
  91. if(empty($form['id'])) $form['id'] = $id;
  92. if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  93. $form['mall_id'] = $this->mall['id'];
  94. $form['mch_id'] = $this->admin->mch_id;
  95. $res = FreightRules::setData($form);
  96. if ($res === false) return $this->error(FreightRules::getStaticError());
  97. return $this->success('操作成功');
  98. }
  99. }
  100. return $this->render($this->action->id);
  101. }
  102. /**
  103. * 包邮规则
  104. * @Author bing
  105. * @DateTime 2021-08-26 15:05:10
  106. * @copyright: Copyright (c) 2020 广东七件事集团
  107. * @return void
  108. */
  109. public function actionFreeShippingRules(){
  110. $request = \Yii::$app->request;
  111. if ($request->isAjax) {
  112. if($request->isGet){
  113. $keyword = Yii::$app->request->get('keyword', '');
  114. $where = [['mall_id' => $this->mall['id'], 'mch_id' => $this->admin->mch_id, 'status' => StatusEnum::ENABLED]];
  115. $keyword && $where[] = ['like', 'name', $keyword . '%', false];
  116. $order = 'id desc';
  117. $params = compact('where', 'order');
  118. $page_data = FreeShippingRules::listPage($params);
  119. if($page_data['list']) foreach ($page_data['list'] as $k => $v) $page_data['list'][$k]['rule'] = json_decode($v['rule']);
  120. if($page_data === false) return $this->error(FreeShippingRules::getStaticError());
  121. return $this->success('操作成功',$page_data);
  122. }else{
  123. $form = Yii::$app->request->post();
  124. $rules = [[['id'], 'required'], [['id'], 'integer']];
  125. switch ($form['type']) {
  126. case 'destroy':
  127. $form['status'] = -1;
  128. $rules[] = [['status'], 'required'];
  129. break;
  130. case 'default':
  131. $rules[] = [['is_default'], 'required'];
  132. break;
  133. }
  134. $res = Yii::$app->services->validate->validate($form, $rules);
  135. if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  136. $form['mall_id'] = $this->mall['id'];
  137. $form['mch_id'] = $this->admin->mch_id;
  138. $res = FreeShippingRules::setData($form);
  139. if ($res === false) return $this->error(FreeShippingRules::getStaticError());
  140. return $this->success('操作成功');
  141. }
  142. }
  143. return $this->render($this->action->id);
  144. }
  145. /**
  146. * 编辑包邮规则
  147. * @Author bing
  148. * @DateTime 2021-08-26 15:05:10
  149. * @copyright: Copyright (c) 2020 广东七件事集团
  150. * @return void
  151. */
  152. public function actionFreeShippingEdit(){
  153. if (Yii::$app->request->isAjax) {
  154. if (Yii::$app->request->isGet) {
  155. $get = Yii::$app->request->get();
  156. $res = Yii::$app->services->validate->validate($get, [
  157. [['id'], 'required'],
  158. [['id'], 'compare', 'compareValue' => 0, 'operator' => '>']
  159. ]);
  160. if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  161. $detail = FreeShippingRules::getOne([['id' => $get['id'], 'mall_id' => $this->mall_id, 'mch_id' => $this->admin->mch_id]], true);
  162. $detail['rule'] = json_decode($detail['rule'],true);
  163. return $this->success('操作成功',compact('detail'));
  164. } else {
  165. $form = Yii::$app->request->post('form');
  166. $res = Yii::$app->services->validate->validate($form, [
  167. [['id'], 'integer'],
  168. [['name', 'money', 'rule' ,'select_com', 'rule_type', 'num'], 'safe'],
  169. ]);
  170. if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  171. $form['mall_id'] = $this->mall['id'];
  172. $form['mch_id'] = $this->admin->mch_id;
  173. if (is_array($form['rule'])) $form['rule'] = json_encode($form['rule']);
  174. $res = FreeShippingRules::setData($form);
  175. if ($res === false) return $this->error(FreeShippingRules::getStaticError());
  176. return $this->success('操作成功');
  177. }
  178. }
  179. return $this->render($this->action->id);
  180. }
  181. /**
  182. * @return void
  183. */
  184. public function actionDelRule()
  185. {
  186. $id = Yii::$app->request->post('id');
  187. if (!$id) return $this->error("请选择删除数据");
  188. }
  189. }