| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- <?php
- namespace addons\OperationCenter\backend\controllers;
- use Yii;
- use Exception;
- use yii\helpers\Json;
- use common\models\common\UpgradeCondition;
- use addons\OperationCenter\common\models\Level;
- use addons\OperationCenter\common\services\LevelService;
- use addons\OperationCenter\common\enums\OperationCenterEnum;
- /**
- * 等级控制器
- *
- * Class LevelController
- * @package addons\OperationCenter\backend\controllers
- */
- class LevelController extends BaseController
- {
- /**
- * @var boolean
- */
- public $enableCsrfValidation = false;
- /**
- * @var LevelService
- */
- protected $service;
- public function init()
- {
- parent::init();
- $this->service = new LevelService(['mall_id' => $this->mall_id]);
- }
- /**
- * 首页
- *
- * @return string
- */
- public function actionIndex()
- {
- if ($this->request->isAjax) {
- $params = $this->request->get();
- return $this->success('ok', $this->service->getPageList($params));
- }
- return $this->render($this->action->id);
- }
- /**
- * 升级条件
- *
- * @return string
- */
- public function actionCondition()
- {
- if (Yii::$app->request->isAjax) {
- try {
- if (Yii::$app->request->isGet) {
- $data['upgrade_condition'] = UpgradeCondition::getData(UpgradeCondition::$operation_center_condition_ids);
- $agentUpgradeCondition = Yii::$app->services->setting->addons->get($this->mall_id, OperationCenterEnum::OPERATION_CENTER, 'upgrade_condition');
- $data['checked_condition_keys'] = !empty($agentUpgradeCondition['level_upgrade_condition']) ? json_decode($agentUpgradeCondition['level_upgrade_condition'], true) : [];
- return $this->success('操作成功', $data);
- } else {
- $postData = Yii::$app->request->post();
- $res = Yii::$app->services->validate->validate($postData, [
- [['checked_condition_keys'], 'required'],
- ]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $data['upgrade_condition'] = ['level_upgrade_condition' => json_encode($postData['checked_condition_keys'])];
- Yii::$app->services->setting->addons->set($this->mall_id, OperationCenterEnum::OPERATION_CENTER, $data);
- UpgradeCondition::clear($postData['checked_condition_keys'], Level::class, $this->mall_id);
- return $this->success('操作成功');
- }
- } catch (Exception $e) {
- return $this->error($e->getMessage());
- }
- }
- return $this->render($this->action->id);
- }
- /**
- * 编辑等级
- *
- * @return string
- */
- public function actionEdit()
- {
- if ($this->request->isAjax) {
- // ID
- $id = $this->request->get('id');
- if ($this->request->isGet) {
- return $this->success('ok', $this->service->getLevelData($id));
- }
- if ($this->request->isPost) {
- $data = $this->request->post();
- unset($data['_csrf']);
- // $validate = Yii::$app->services->validate->validate($data, [
- // [['level', 'name'], 'required'],
- // [[
- // 'is_auto_upgrade', 'checked_condition_values',
- // 'checked_condition_keys', 'condition_type', 'upgrade_type_goods',
- // 'goods_list', 'upgrade_type_condition', 'goods_ids', 'goods_type',
- // 'buy_goods_type', 'explain', 'status'
- // ], 'safe']
- // ]);
- // if ($validate === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- return $this->service->setLevelData($id, $data)
- ? $this->success('ok')
- : $this->error($this->service->getError());
- }
- }
- // 获取等级升级的条件
- // $upgradeCondition = Yii::$app->services->setting->addons->get(
- // $this->mall_id, OperationCenterEnum::OPERATION_CENTER, 'upgrade_condition'
- // );
- // $list = [];
- // if(!empty($upgradeCondition['level_upgrade_condition'])) {
- // $ids = Json::decode($upgradeCondition['level_upgrade_condition'], true);
- // $list = UpgradeCondition::getData($ids);
- // }
- // $upgrade_condition_data = UpgradeCondition::getUpgradeConditionData($this, $this->mall_id, $list);
-
- return $this->render($this->action->id/* , $upgrade_condition_data */);
- }
- /**
- * 等级列表
- *
- * @return string
- */
- public function actionList()
- {
- return $this->success('ok', $this->service->getLevelList());
- }
- /**
- * 切换状态
- *
- * @return string
- */
- public function actionSwitchStatus()
- {
- $id = $this->request->get('id');
- $status = $this->request->get('status');
- return $this->service->switchStatus($id, $status)
- ? $this->success('ok')
- : $this->error($this->service->getError());
- }
- /**
- * 删除等级
- *
- * @return string
- */
- public function actionDelLevel()
- {
- $id = $this->request->get('id');
- return $this->service->delLevel($id)
- ? $this->success('ok')
- : $this->error($this->service->getError());
- }
- }
|