| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- namespace addons\ValetOrder\backend\controllers;
- use addons\ValetOrder\common\service\SettingService;
- use common\enums\StatusEnum;
- use common\models\user\UserLevel;
- use Yii;
- /**
- * 默认控制器
- *
- * Class DefaultController
- * @package addons\WangDianTong\backend\controllers
- */
- class SettingController extends BaseController
- {
- public $enableCsrfValidation = false;
- /**
- * 首页
- *
- * @return string
- */
- public function actionIndex()
- {
- if (\Yii::$app->request->isAjax) {
- $service = new SettingService();
- if (\Yii::$app->request->isGet) {
- $ret = $service->get($this->mall_id);
- if (empty($ret)) {
- $ret = [
- 'is_enable' => 0,
- 'is_enable_sms_code' => 0,
- 'is_enable_order_refund' => 0,
- ];
- }
- $ret['allow_all_level_valet_order'] = $ret['allow_all_level_valet_order'] ?? 1;
- $ret['is_limit_same_team'] = $ret['is_limit_same_team'] ?? 0;
- $ret['allow_valet_order_user_levels'] = $ret['allow_valet_order_user_levels'] ?? '';
- $ret['allow_valet_order_user_levels'] = array_filter(explode(',', $ret['allow_valet_order_user_levels']), function ($val) {
- return is_numeric($val);
- });
- return $this->success('success', $ret);
- } else if (\Yii::$app->request->isPost) {
- $data = Yii::$app->request->post();
- $valid = Yii::$app->services->validate->validate($data, [
- [['is_enable', 'is_enable_sms_code', 'is_enable_order_refund', 'allow_all_level_valet_order', 'is_limit_same_team', 'is_hide_order_price', 'is_enable_other_identity_price'], 'integer'],
- [['allow_valet_order_user_levels'], 'safe'],
- ]);
- if ($valid === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- if (isset($data['allow_valet_order_user_levels'])) {
- $data['allow_valet_order_user_levels'] = implode(',', array_filter($data['allow_valet_order_user_levels'], function ($val) {
- return is_numeric($val);
- }));
- }
- // 保存"使用代下单用户的等级价格"开关配置
- if (!empty($data['is_enable_other_identity_price'])) {
- try {
- $service->createValetOrderDefaultUser($this->mall_id);
- }catch (\Exception $e) {
- return $this->error($e->getMessage());
- }
- }
- return $service->save($this->mall_id, $data) ? $this->success("保存成功", $data) : $this->error('保存失败');
- }
- }
- return $this->render('index');
- }
- /**
- * @return mixed|null
- */
- public function actionGetData()
- {
- $userLevelList = UserLevel::getUserLevel([['mall_id' => $this->mall_id], ['status' => StatusEnum::ENABLED]], [], 1);
- return $this->success('success', ['user_level_list' => $userLevelList]);
- }
- }
|