| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- <?php
- /**
- * @link:http://www.gdqijianshi.com/
- * @copyright: Copyright (c) 2020 广东七件事集团
- * Created by PhpStorm
- * Author: ganxiaohao
- * Date: 2020-05-08
- * Time: 16:10
- */
- namespace addons\Store\client\controllers;
- use addons\Store\common\models\StoreBossLevelCommon;
- use addons\Store\common\models\StoreBossLevelForm;
- use addons\Store\common\models\StoreBossLevel;
- use common\enums\StatusEnum;
- use Yii;
- /**
- * 门店股东等级设置
- * Class StoreBossLevelController
- * @package addons\Store\client\controllers
- */
- class StoreBossLevelController extends BaseController
- {
- /**
- * @Author: 广东七件事 ganxiaohao
- * @Date: 2020-05-12
- * @Time: 9:52
- * @Note:等级列表
- * @return string|\yii\web\Response
- */
- public function actionIndex()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isPost) {
- } elseif (\Yii::$app->request->isGet) {
- $params = \Yii::$app->request->get();
- $where[] = ['=', 'mall_id', $this->mall_id];
- $where[] = ['=','store_id', $this->store_id];
- $where[] = ['=','is_delete', 0];
-
- if($params['keyword']){
- $where[]=['or', ['like', 'name',$params['keyword']], ['like', 'level', $params['keyword']]];
- }
- $params = [
- 'select' => '*',
- 'where' => $where,
- 'order' => 'level asc',
- 'page' => $params['page'],
- 'limit' => 20,
- ];
- $lists = StoreBossLevel::listPage($params, false, true);
-
-
- $data= [
- 'code' => 0,
- 'msg' => '',
- 'data' => [
- 'list' => $lists['list'],
- 'pagination' => $lists['pagination']
- ]
- ];
- return $this->asJson($data);
- }
- }
- return $this->render('/store-boss-level/index');
- }
- /**
- * @Author: 广东七件事 ganxiaohao
- * Date: 2020-05-10
- * Time: 22:26
- * @Note:已经启用的等级
- */
- public function actionEnableList()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isGet) {
- $where = [['mall_id' => $this->mall_id], ['store_id'=>$this->store_id],['is_enable'=>1],['=', 'status', StatusEnum::ENABLED]];
- $args['where'] = $where;
- $args['select'] = 'id,level,name';
- $args['order'] = 'level asc';
- $list['list'] = StoreBossLevel::lists($args, true);
- return $this->success('操作成功', $list);
- }
- }
- return $this->error();
- }
- /**
- * @Author: 广东七件事 ganxiaohao
- * @Date: 2020-05-12
- * @Time: 9:23
- * @Note:编辑
- * @return string|\yii\web\Response
- */
- public function actionEdit()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isPost) {
- $form = new StoreBossLevelForm();
- $form->attributes = \Yii::$app->request->post('form');
- $form->store_id = $this->store_id;
- $form->mall_id = $this->mall_id;
- return $this->asJson($form->setData( ));
- } elseif (\Yii::$app->request->isGet) {
- $form = new StoreBossLevelForm();
- $form->attributes=\Yii::$app->request->get();
- return $this->asJson($form->getDetail());
- }
- }
- return $this->render('/store-boss-level/edit');
- }
- /**
- * @Author: 广东七件事 ganxiaohao
- * @Date: 2020-05-12
- * @Time: 9:52
- * @Note:等级状态变更
- * @return \yii\web\Response
- */
- public function actionSwitchStatus()
- {
- $level = StoreBossLevel::findOne(['id' => \Yii::$app->request->post('id'),'store_id' => $this->store_id, 'is_delete' => 0]);
-
- if (!$level) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '该等级不存在或已被删除!',
- ]);
- }
- try {
- if ($level->is_use) {
- $level->is_use = 0;
- } else {
- $level->is_use = 1;
- }
- if ($level->save()) {
- return $this->asJson([
- 'code' =>1,
- 'msg' => '分销等级状态变更成功',
- ]);
- }
- } catch (\Exception $exception) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => $exception->getMessage()
- ]);
- }
- }
- /**
- * @Author: 广东七件事 ganxiaohao
- * @Date: 2020-05-12
- * @Time: 9:52
- * @Note:删除
- * @return \yii\web\Response
- */
- public function actionDelete()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isPost) {
- $id = \Yii::$app->request->post('id');
- if(!$id){
- return $this->error('参数错误');
- }
- $level = StoreBossLevel::findOne(['id' => $id,'store_id' => $this->store_id, 'is_delete' => 0]);
- $level->is_delete = 1;
- if (!$level->save()) {
- return $this->error($level->getError());
- }
- return $this->success('操作成功');
- }
- }
- }
- /**
- * @Author: 广东七件事 ganxiaohao
- * @Date: 2020-05-12
- * @Time: 9:47
- * @Note:获取分销配置以及权重
- * @return \yii\web\Response
- */
- public function actionSetting()
- {
- $list = (new StoreBossLevelCommon())->getLevelWeights();
- return $this->asJson([
- 'code' =>0,
- 'msg' => '',
- 'data' => [
- 'weights' => $list['newList'],
- 'match_weights' => $list['matchList'],
- ]
- ]);
- }
- }
|