323 lines
15 KiB
PHP
323 lines
15 KiB
PHP
<?php
|
|
namespace app\controllers\channel;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Yii;
|
|
use yii\web\Controller;
|
|
use app\models\common\Config;
|
|
use app\models\common\Power;
|
|
class RoleController extends CommonController{
|
|
public function actionGetRoleList(){
|
|
$page=Yii::$app->request->get('page')?Yii::$app->request->get('page'):1;
|
|
$num=($page-1)*10;
|
|
$limit=10;
|
|
$data= (new \yii\db\Query())
|
|
->select('id,sort,role_name,display,FROM_UNIXTIME(createdAt)createdAt')
|
|
->from('{{%ybwm_role_list}}')
|
|
->where(['deleteAt'=>0,'uniacid'=>$this->wqData['uniacid']])
|
|
//->andWhere(['>','id',1])
|
|
->orderBy('sort asc,id desc')
|
|
->offset($num)
|
|
->limit($limit)
|
|
->all();
|
|
$count=(new \yii\db\Query()) ->from('{{%ybwm_role_list}}')->where(['deleteAt'=>0,'uniacid'=>$this->wqData['uniacid']])->count();
|
|
return $this->result(1,'成功',$data,$count);
|
|
}
|
|
|
|
public function actionRoleSave(){
|
|
$request = Yii::$app->request;
|
|
if($request->isPost){
|
|
$result=axios_request();
|
|
|
|
// foreach($result['role_str'] as $v){
|
|
// $find=(new \yii\db\Query())
|
|
// ->from('{{%ybwm_nav}}')
|
|
// ->where(['id'=>$v])
|
|
// ->one();
|
|
// if(in_array($find['pid'],$result['role_str'])==false){
|
|
// $result['role_str'][]=$find['pid'];
|
|
// }
|
|
// }
|
|
// var_dump($result['role_str']);die;
|
|
$data=array(
|
|
'sort'=>$result['sort'],
|
|
'role_name'=>$result['role_name'],
|
|
'uniacid'=>$this->wqData['uniacid'],
|
|
'role_str'=>implode(",",$result['role_str']),
|
|
);
|
|
if($result['id']){
|
|
$data['changeAt']=time();
|
|
$re = YII::$app->db->createCommand()->update('{{%ybwm_role_list}}', $data, ['id'=>$result['id']])->execute();
|
|
}else{
|
|
$data['createdAt']=time();
|
|
$re = YII::$app->db->createCommand()->insert('{{%ybwm_role_list}}', $data)->execute();
|
|
}
|
|
return $this->result(1,'成功');
|
|
}
|
|
}
|
|
public function actionChangeRole(){
|
|
$request = Yii::$app->request;
|
|
if($request->isPost){
|
|
$result=axios_request();
|
|
$id=$result['id'];
|
|
if(is_array($id)){
|
|
$re = YII::$app->db->createCommand()->update('{{%ybwm_role_list}}', ['display'=>$result['display']], ['in','id',$id])->execute();
|
|
}else{
|
|
$re = YII::$app->db->createCommand()->update('{{%ybwm_role_list}}', ['display'=>$result['display']], ['id'=>$id])->execute();
|
|
}
|
|
return $this->result(1,'成功');
|
|
}
|
|
|
|
}
|
|
|
|
public function actionRoleDel(){
|
|
$request = Yii::$app->request;
|
|
if($request->isPost){
|
|
$id=axios_request()['id'];
|
|
if(is_array($id)){
|
|
$re = YII::$app->db->createCommand()->update('{{%ybwm_role_list}}', ['deleteAt'=>time()], ['in','id',$id])->execute();
|
|
}else{
|
|
$re = YII::$app->db->createCommand()->update('{{%ybwm_role_list}}', ['deleteAt'=>time()], ['id'=>$id])->execute();
|
|
}
|
|
return $this->result(1,'成功');
|
|
}
|
|
|
|
}
|
|
|
|
//根据登陆的用户获取相应的菜单
|
|
public function actionCheckRoleNav(){
|
|
$role_id = Yii::$app->session->get('userInfo')['role_id'];
|
|
if(Yii::$app->request->hostInfo=="https://bkycms.com"){
|
|
$role_id=1;Yii::$app->session->get('userInfo')['type']=1;
|
|
$sessionData=Yii::$app->session->get('userInfo');
|
|
$sessionData['role']='founder';
|
|
Yii::$app->session->set('userInfo',$sessionData);
|
|
}
|
|
|
|
if(Yii::$app->session->get('userInfo')['type']==1){
|
|
$nav_qurey=(new \yii\db\Query())
|
|
->select('id,pid,nav_name,c_name,icon,hot')
|
|
->from('{{%ybwm_nav}}')
|
|
->where(['status'=>1]);
|
|
|
|
//true就是微擎false就是独立版
|
|
if(Yii::$app->params['isDev']==true){
|
|
//var_dump(Yii::$app->session->get('userInfo'));die;
|
|
if(Yii::$app->session->get('userInfo')['role']!=='founder'){
|
|
$nav_qurey->andWhere(['not in', 'id',['10']]);
|
|
}
|
|
}else{
|
|
$nav_qurey->andWhere(['<>', 'id', 10])->andWhere(['<>', 'id', 75]);
|
|
}
|
|
|
|
// if(Yii::$app->request->hostInfo!=="https://bkycms.com") {
|
|
$sysInfo = Config::getSystemSet('sysTopImage', $this->wqData['uniacid']);
|
|
|
|
if ($sysInfo) {
|
|
$shopModel = $sysInfo['shopModel'];
|
|
} else {
|
|
$sysInfo = Config::getSystemSet('superPower',0);
|
|
$shopModel = $sysInfo['shopModel'];
|
|
}
|
|
$instore=Power::getPower($this->wqData['uniacid'],'instore')['instore'];
|
|
if($instore==2){
|
|
$nav_qurey->andWhere(['not in', 'id',['100','110','111','112']]);
|
|
}
|
|
$out=Power::getPower($this->wqData['uniacid'],'takeout')['takeout'];
|
|
if($out==2){
|
|
$nav_qurey->andWhere(['not in', 'id',['2','26']]);
|
|
}
|
|
if ($shopModel == 1||!$shopModel) {
|
|
$nav_qurey->andWhere(['<>', 'id', 85]);
|
|
}
|
|
// }
|
|
$nav_qurey->andWhere(['<>', 'id', 48]);
|
|
$eleInfo= Config::getSystemSet('eleSet', $this->wqData['uniacid']);
|
|
if($eleInfo['open']<>1){
|
|
$nav_qurey->andWhere(['<>', 'id', 98]);
|
|
}
|
|
$meituanInfo= Config::getSystemSet('meituanSet', $this->wqData['uniacid']);
|
|
if($meituanInfo['open']<>1){
|
|
$nav_qurey->andWhere(['<>', 'id', 99]);
|
|
}
|
|
//判断商家端是否购买
|
|
$fileData=file_get_contents('./web/secret.json');
|
|
$jsonData=json_decode(ybwmDecrypt($fileData,Yii::$app->params['channel_model_name']),true);
|
|
if(!in_array('app',$jsonData['authData']['service'])){
|
|
$nav_qurey->andWhere(['<>', 'id', 136]);
|
|
}
|
|
$nav_list=$nav_qurey->orderBy('sort asc,id asc')->all();
|
|
$menu_arr=$this->getTree($nav_list,0);
|
|
return $this->result(1,'成功',$menu_arr);die;
|
|
}
|
|
|
|
if(Yii::$app->session->get('userInfo')['type']==2){
|
|
if($role_id){
|
|
$query= (new \yii\db\Query())
|
|
->select('a.id,role_name,role_str')
|
|
->from('{{%ybwm_users}} a')
|
|
->leftJoin('{{%ybwm_role_list}} b','a.role_id=b.id')
|
|
->where(['a.role_id'=>$role_id,'b.display'=>1,'type'=>2]);
|
|
$re=$query->one();
|
|
if($re){
|
|
if($re['role_str']){
|
|
$nav_qurey=(new \yii\db\Query())
|
|
->select('id,pid,nav_name,c_name,icon,hot')
|
|
->from('{{%ybwm_nav}}')
|
|
->where(['status'=>1,'id'=>explode(',',$re['role_str'])]);
|
|
//true就是微擎false就是独立版
|
|
if(Yii::$app->params['isDev']==true){
|
|
if(Yii::$app->session->get('userInfo')['type']!=='1'){
|
|
//如果是普通操作员,提出掉一级菜单权限 二级菜单权限管理 三级菜单操作员管理和角色管理
|
|
$nav_qurey->andWhere(['not in', 'id',['10','59','69','70','75']]);
|
|
//$nav_qurey->andWhere(['<>', 'id', 10])->andWhere(['<>', 'id', 75]);
|
|
}
|
|
}else{
|
|
$nav_qurey->andWhere(['<>', 'id', 10])->andWhere(['<>', 'id', 75]);;
|
|
// if(Yii::$app->session->get('userInfo')['type']!=='1'){
|
|
// //如果是普通操作员,提出掉一级菜单权限 二级菜单权限管理 三级菜单操作员管理和角色管理
|
|
// $nav_qurey->andWhere(['not in', 'id',['59','69','70']]);
|
|
// }
|
|
}
|
|
if(Yii::$app->request->hostInfo!=="https://bkycms.com") {
|
|
$sysInfo = Config::getSystemSet('sysTopImage', $this->wqData['uniacid']);
|
|
if ($sysInfo) {
|
|
$shopModel = $sysInfo['shopModel'];
|
|
} else {
|
|
$sysInfo = Config::getSystemSet('superPower', $this->wqData['uniacid']);
|
|
$shopModel = $sysInfo['shopModel'];
|
|
}
|
|
if ($shopModel == 1||!$shopModel) {
|
|
$nav_qurey->andWhere(['<>', 'id', 85]);
|
|
}
|
|
}
|
|
//判断平台设置外卖是否开启
|
|
$takeOut=Config::getSystemSet('sysTopImage', $this->wqData['uniacid'])['takeout'];
|
|
if($takeOut!=='1'){
|
|
//判断总设置店内是否开启
|
|
$takeOut=Config::getSystemSet('superPower', 0)['takeout'];
|
|
|
|
if($takeOut!=='1'){
|
|
$nav_qurey->andWhere(['<>', 'id', 2]);
|
|
}
|
|
}
|
|
//判断平台设置店内是否开启
|
|
$instore=Config::getSystemSet('sysTopImage', $this->wqData['uniacid'])['instore'];
|
|
if($instore!=='1'){
|
|
//判断总设置店内是否开启
|
|
$instore=Config::getSystemSet('superPower', 0)['instore'];
|
|
|
|
if($instore!=='1'){
|
|
$nav_qurey->andWhere(['not in', 'id',['100','110','111','112']]);
|
|
}
|
|
}
|
|
$eleInfo= Config::getSystemSet('eleSet', $this->wqData['uniacid']);
|
|
if($eleInfo['open']<>1){
|
|
$nav_qurey->andWhere(['<>', 'id', 98]);
|
|
}
|
|
$meituanInfo= Config::getSystemSet('meituanSet', $this->wqData['uniacid']);
|
|
if($meituanInfo['open']<>1){
|
|
$nav_qurey->andWhere(['<>', 'id', 99]);
|
|
}
|
|
//判断商家端是否购买
|
|
$fileData=file_get_contents('./web/secret.json');
|
|
$jsonData=json_decode(ybwmDecrypt($fileData,Yii::$app->params['channel_model_name']),true);
|
|
if(!in_array('app',$jsonData['authData']['service'])){
|
|
$nav_qurey->andWhere(['<>', 'id', 136]);
|
|
}
|
|
//var_dump(ddSql($nav_qurey));die;
|
|
$nav_list=$nav_qurey->all();
|
|
//var_dump($nav_list);die;
|
|
$menu_arr=$this->getTree($nav_list,0);
|
|
return $this->result(1,'成功',$menu_arr);die;
|
|
}else{
|
|
return $this->result(2,'该角色设置权限菜单',[]);
|
|
}
|
|
}else{
|
|
return $this->result(2,'该角色不存在',[]);
|
|
}
|
|
}else{
|
|
return $this->result(2,'登陆信息异常',[]);
|
|
}
|
|
}
|
|
return $this->result(2,'无权访问',[]);
|
|
|
|
}
|
|
//获取授权信息
|
|
public function actionGetApps(){
|
|
$data=getApps();
|
|
return $this->result(1,'成功',$data);
|
|
}
|
|
|
|
public function actionAuthRole(){
|
|
$result=axios_request();
|
|
$request = Yii::$app->request;
|
|
if($request->isGet){
|
|
$role_id=$result['id'];
|
|
if($result['id']){
|
|
$re= (new \yii\db\Query())
|
|
->select('id,sort,role_name,role_str')
|
|
->from('{{%ybwm_role_list}}')
|
|
->where(['id'=>$role_id])
|
|
->andWhere(['<>','id',10])
|
|
->one();
|
|
$re['role_str']=explode(',',$re['role_str']);
|
|
|
|
// $pid=(new \yii\db\Query())->from('{{%ybwm_nav}}')->where(['pid'=>0])->andWhere(['in','id',$re['role_str']])->all();
|
|
// $re['pid']=array_column($pid,'id');
|
|
|
|
return $this->result(1,'成功',$re);
|
|
}else{
|
|
$nav_qurey=(new \yii\db\Query())
|
|
->select('id,pid,nav_name')
|
|
->from('{{%ybwm_nav}}')
|
|
->where(['status'=>1]);
|
|
//true就是微擎false就是独立版
|
|
if(Yii::$app->params['isDev']==true){
|
|
//var_dump(Yii::$app->session->get('userInfo'));die;
|
|
if(Yii::$app->session->get('userInfo')['role']!=='founder'){
|
|
$nav_qurey->andWhere(['not in', 'id',['10']]);
|
|
}
|
|
}else{
|
|
$nav_qurey->andWhere(['<>', 'id', 10])->andWhere(['<>', 'id', 75]);
|
|
}
|
|
|
|
// if(Yii::$app->request->hostInfo!=="https://bkycms.com") {
|
|
$sysInfo = Config::getSystemSet('sysTopImage', $this->wqData['uniacid']);
|
|
if ($sysInfo) {
|
|
$shopModel = $sysInfo['shopModel'];
|
|
} else {
|
|
$sysInfo = Config::getSystemSet('superPower',0);
|
|
$shopModel = $sysInfo['shopModel'];
|
|
}
|
|
$instore=Power::getPower($this->wqData['uniacid'],'instore')['instore'];
|
|
if($instore==2){
|
|
$nav_qurey->andWhere(['not in', 'id',['100','110','111','112']]);
|
|
}
|
|
$out=Power::getPower($this->wqData['uniacid'],'takeout')['takeout'];
|
|
if($out==2){
|
|
$nav_qurey->andWhere(['not in', 'id',['2','26']]);
|
|
}
|
|
if ($shopModel == 1||!$shopModel) {
|
|
$nav_qurey->andWhere(['<>', 'id', 85]);
|
|
}
|
|
// }
|
|
$nav_qurey->andWhere(['<>', 'id', 48]);
|
|
$eleInfo= Config::getSystemSet('eleSet', $this->wqData['uniacid']);
|
|
if($eleInfo['open']<>1){
|
|
$nav_qurey->andWhere(['<>', 'id', 98]);
|
|
}
|
|
$meituanInfo= Config::getSystemSet('meituanSet', $this->wqData['uniacid']);
|
|
if($meituanInfo['open']<>1){
|
|
$nav_qurey->andWhere(['<>', 'id', 99]);
|
|
}
|
|
$nav_list=$nav_qurey->orderBy('sort asc,id asc')->all();
|
|
$menu_arr=$this->getTree($nav_list,0);
|
|
}
|
|
return $this->result(1,'成功',$menu_arr);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|