SettingController.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace addons\RandFee\backend\controllers;
  3. use addons\RandFee\common\enums\Order;
  4. use addons\RandFee\common\service\SettingService;
  5. use Yii;
  6. use common\controllers\AddonsController;
  7. use common\enums\StatusEnum;
  8. use common\models\user\UserLevel;
  9. /**
  10. * 设置控制器
  11. *
  12. * Class SettingController
  13. * @package addons\RandFee\backend\controllers
  14. */
  15. class SettingController extends BaseController
  16. {
  17. public $enableCsrfValidation = false;
  18. /**
  19. * 设置首页
  20. *
  21. * @return void
  22. */
  23. public function actionIndex()
  24. {
  25. if ($this->request->isAjax) {
  26. // 获取设置
  27. $service = new SettingService(['mall_id' => $this->mall_id]);
  28. $conf = $service->getSetting();
  29. // 等级
  30. $level = UserLevel::getUserLevel([
  31. ['=', 'mall_id', $this->mall_id],
  32. ['=', 'status', StatusEnum::ENABLED],
  33. ], [], true, 'level, name', 'level asc');
  34. // 订单
  35. $order = Order::getTypes();
  36. return $this->success('ok', compact('conf', 'level', 'order'));
  37. }
  38. return $this->render('index');
  39. }
  40. /**
  41. * 保存设置
  42. *
  43. * @return void
  44. */
  45. public function actionSubmit()
  46. {
  47. if ($this->request->isPost) {
  48. // 数据提交
  49. $post = $this->request->post();
  50. $service = new SettingService(['mall_id' => $this->mall_id]);
  51. if ($service->saveSetting($post)) {
  52. return $this->success('保存成功');
  53. }
  54. return $this->error('保存失败');
  55. }
  56. }
  57. }