SettingController.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace addons\Seckill\backend\controllers;
  3. use addons\Seckill\common\enums\SeckillEnum;
  4. use common\enums\StatusEnum;
  5. use common\models\goods\Goods;
  6. use addons\Seckill\common\models\SeckillActivity;
  7. use Yii;
  8. /**
  9. * 系统设置控制器
  10. *
  11. * Class ActivityController
  12. * @package addons\Seckill\backend\controllers
  13. */
  14. class SettingController extends BaseController
  15. {
  16. public $enableCsrfValidation = false;
  17. /**
  18. * 首页
  19. *
  20. * @return string
  21. */
  22. public function actionIndex()
  23. {
  24. if (\Yii::$app->request->isAjax) {
  25. $config = \Yii::$app->services->setting->addons->get($this->mall_id, SeckillEnum::ADDONS_NAME, 'basic');
  26. $this->success('获取成功', $config);
  27. }
  28. return $this->render('index');
  29. }
  30. /**
  31. * 保存设置
  32. * @return mixed|void
  33. */
  34. public function actionSaveSetting()
  35. {
  36. $post = \Yii::$app->request->post();
  37. $check = \Yii::$app->services->validate
  38. ->validate(
  39. $post,
  40. [
  41. [['status', 'order_cancel_time'], 'required'],
  42. [['status','order_cancel_time'], 'integer'],
  43. ]
  44. );
  45. if ($check === false) {
  46. return $this->error(\Yii::$app->services->validate->getErrorMessage());
  47. }
  48. if($post['order_cancel_time'] <= 0 ){
  49. return $this->error('超时取消时间需大于0');
  50. }
  51. $res = \Yii::$app->services->setting->addons->set($this->mall_id, SeckillEnum::ADDONS_NAME, ['basic' => $post]);
  52. if($res){
  53. return $this->success('操作成功');
  54. }
  55. return $this->error('保存失败');
  56. }
  57. }