| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- <?php
- namespace addons\Dianqian\backend\controllers;
- use common\enums\StatusEnum;
- use common\models\common\ServiceAgreement;
- use common\models\goods\Goods;
- use Yii;
- use yii\helpers\Json;
- /**
- * Class SettingController
- * @package addons\BossBonus\backend\controllers
- */
- class SettingController extends BaseController
- {
- public $enableCsrfValidation = false;
- /**
- * @return mixed|string|void
- */
- public function actionIndex()
- {
- if (Yii::$app->request->isAjax) {
- if(Yii::$app->request->isGet){
- $configs = Yii::$app->services->setting->addons->get($this->mall_id, 'Dianqian', 'basic');
- if (!empty($configs['checkList'])) $configs['checkList'] = json_decode($configs['checkList'], true);
- // 获取协议列表
- $agreement = ServiceAgreement::find()->select('id,name')->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])->asArray()->all();
- return $this->success('操作成功', compact('configs','agreement'));
- }
- if(Yii::$app->request->isPost){
- $post = Yii::$app->request->post('basic');
- $rules = [
- [['sign_name','bg_img','help'], 'string'],
- [['checkList','agreement_id'], 'safe'],
- ];
- $res = Yii::$app->services->validate->validate($post, $rules);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- if (empty($post['checkList'])) { // 因为前端如何不选择,此处插入数会是一个null。会导致json_decode无法解析
- $post['checkList'] = json_encode([]);
- }
- Yii::$app->services->setting->addons->set($this->mall_id, 'Dianqian', ['basic' => $post]);
- return $this->success('操作成功');
- }
- }
- return $this->render('index');
- }
- }
|