FreeController.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\admin\controllers\setting;
  8. use app\models\District;
  9. use app\models\FreeDeliveryRules;
  10. use app\modules\admin\controllers\BaseController;
  11. use app\modules\admin\models\FreeForm;
  12. class FreeController extends BaseController
  13. {
  14. /**
  15. * 获取运费规则列表
  16. * @return \yii\web\Response
  17. */
  18. public function actionList()
  19. {
  20. return $this->asJson([
  21. 'code' => 0,
  22. 'data' => [
  23. 'list' => FreeDeliveryRules::find()->where([
  24. 'store_id' => get_store_id(),
  25. 'mch_id' => get_mch_id(),
  26. 'is_delete' => 0
  27. ])->select(['id','name','price'])->all()
  28. ]
  29. ]);
  30. }
  31. /**
  32. * 新增、编辑运费规则
  33. */
  34. public function actionEdit($id = null)
  35. {
  36. $model = FreeDeliveryRules::findOne([
  37. 'id' => $id,
  38. 'store_id' => get_store_id(),
  39. 'mch_id' => get_mch_id(),
  40. 'is_delete' => 0,
  41. ]);
  42. return $this->asJson([
  43. 'code' => 0,
  44. 'data' => [
  45. 'model' => $model,
  46. 'district' => District::getAll()
  47. ]
  48. ]);
  49. }
  50. /**
  51. * 保存
  52. */
  53. public function actionSave()
  54. {
  55. $form = new FreeForm();
  56. $form->free = post_params('free');
  57. $form->city_list = post_params('city_list');
  58. $form->store_id = get_store_id();
  59. $form->mch_id = get_mch_id();
  60. return $this->asJson($form->save());
  61. }
  62. /**
  63. * 修改状态
  64. * @return \yii\web\Response
  65. */
  66. public function actionDel()
  67. {
  68. $data = get_params();
  69. $model = FreeDeliveryRules::findOne(['id' => $data['id'], 'store_id' => get_store_id(), 'mch_id' => get_mch_id()]);
  70. if (empty($model)) {
  71. $res = ['code' => 1, 'msg' => '参数错误'];
  72. } else {
  73. $model->is_delete = 1;
  74. $res = $model->save() ? ['code' => 0, 'msg' => '操作成功'] : ['code' => 1, 'msg' => '操作失败'];
  75. }
  76. return $this->asJson($res);
  77. }
  78. }