| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- <?php
- namespace addons\Seed\backend\controllers;
- use addons\Seed\common\enums\SeedEnum;
- use addons\Seed\common\models\SeedStoreSetting;
- use addons\Store\common\models\Store;
- use common\enums\StatusEnum;
- use common\models\mall\MallAddons;
- use Yii;
- use yii\helpers\Json;
- /**
- * Class SettingController
- * @package addons\Seed\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){
- $config = Yii::$app->services->setting->addons->get($this->mall_id, SeedEnum::ADDONS_NAME, 'basic');
- // 店铺列表获取
- $stores = [];
- if ($config['no_partake_stores'] && MallAddons::isInstall($this->mall_id, 'Store')) {
- $stores = Store::find()->select('id,store_name,logo_img')->where(['id' => Json::decode($config['no_partake_stores'], true)])->asArray()->all();
- }
- return $this->success('操作成功', compact('config', 'stores'));
- }
- if(Yii::$app->request->isPost){
- $post = Yii::$app->request->post('basic');
- $rules = [
- [['seed_status','collect_type'], 'integer'],
- [['multiple', 'pool_percent', 'ad_percent','basic_unit_price', 'release_cycle'], 'number'],
- [['quota_setting', 'no_partake_stores'], 'safe']
- ];
- $res = Yii::$app->services->validate->validate($post, $rules);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- if (is_array($post['quota_setting'])) $post['quota_setting'] = Json::encode($post['quota_setting']);
- if (is_array($post['no_partake_stores'])) $post['no_partake_stores'] = Json::encode($post['no_partake_stores']);
- Yii::$app->services->setting->addons->set($this->mall_id, SeedEnum::ADDONS_NAME, ['basic' => $post]);
- return $this->success('操作成功');
- }
- }
- return $this->render('index');
- }
- /**
- * 店铺设置
- * @Author: lun
- * @DateTime: 2022/8/23 0023 17:17
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|string|void
- */
- public function actionStore()
- {
- $retuest = Yii::$app->request;
- if ($retuest->isAjax) {
- if ($retuest->isGet) {
- $get = Yii::$app->request->get();
- // 检查提交的参数
- $res = Yii::$app->services->validate->validate($get,[
- [['store_id','page','limit'], 'integer'],
- ]);
- if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- // 获取店铺统一设置
- $config = Yii::$app->services->setting->addons->get($this->mall_id, SeedEnum::ADDONS_NAME, 'store');
- $where = $list = [];
- $where[] = ['=', 'mall_id', $this->mall_id];
- !empty($get['store_id']) && $where[] = ['=', 'store_id', $get['store_id']];
- $where[] = ['=', 'status', StatusEnum::ENABLED];
- // 参数
- $params = array('where' => $where, 'order' => 'created_at desc', 'with' => ['store'], 'limit' => $get['limit']);
- $list = SeedStoreSetting::listPage($params, false, true);
- return $this->success('获取成功', compact('list','config'));
- } else {
- // 校验
- $post = Yii::$app->request->post();
- $rules = [
- [['type','store_id','status'], 'integer'],// 类型[1=统一设置,2=店铺独立设置]
- [['percent'], 'number'],
- ];
- $res = Yii::$app->services->validate->validate($post, $rules);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $post = SeedStoreSetting::exceptNullVal($post);// 去除空值
- // 存入设置
- if ($post['type'] == 1) {
- Yii::$app->services->setting->addons->set($this->mall_id, SeedEnum::ADDONS_NAME, ['store' => ['percent' => $post['percent']]]);
- } else {
- $post['mall_id'] = $this->mall_id;
- $res = SeedStoreSetting::setData($post);
- if ($res === false) return $this->error('操作失败:'.SeedStoreSetting::getStaticError());
- }
- return $this->success('操作成功');
- }
- } else {
- return $this->render($this->action->id);
- }
- }
- }
|