SettingController.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace addons\Dianqian\backend\controllers;
  3. use common\enums\StatusEnum;
  4. use common\models\common\ServiceAgreement;
  5. use common\models\goods\Goods;
  6. use Yii;
  7. use yii\helpers\Json;
  8. /**
  9. * Class SettingController
  10. * @package addons\BossBonus\backend\controllers
  11. */
  12. class SettingController extends BaseController
  13. {
  14. public $enableCsrfValidation = false;
  15. /**
  16. * @return mixed|string|void
  17. */
  18. public function actionIndex()
  19. {
  20. if (Yii::$app->request->isAjax) {
  21. if(Yii::$app->request->isGet){
  22. $configs = Yii::$app->services->setting->addons->get($this->mall_id, 'Dianqian', 'basic');
  23. if (!empty($configs['checkList'])) $configs['checkList'] = json_decode($configs['checkList'], true);
  24. // 获取协议列表
  25. $agreement = ServiceAgreement::find()->select('id,name')->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])->asArray()->all();
  26. return $this->success('操作成功', compact('configs','agreement'));
  27. }
  28. if(Yii::$app->request->isPost){
  29. $post = Yii::$app->request->post('basic');
  30. $rules = [
  31. [['sign_name','bg_img','help'], 'string'],
  32. [['checkList','agreement_id'], 'safe'],
  33. ];
  34. $res = Yii::$app->services->validate->validate($post, $rules);
  35. if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  36. if (empty($post['checkList'])) { // 因为前端如何不选择,此处插入数会是一个null。会导致json_decode无法解析
  37. $post['checkList'] = json_encode([]);
  38. }
  39. Yii::$app->services->setting->addons->set($this->mall_id, 'Dianqian', ['basic' => $post]);
  40. return $this->success('操作成功');
  41. }
  42. }
  43. return $this->render('index');
  44. }
  45. }