优化权限修改

master
chenzhi 4 years ago
parent 28e93fe832
commit 0d533525fe

@ -205,12 +205,14 @@ class AuthManagerController extends AdminController{
}
}
if(isset($_POST['rules'])){
$isrules = true;
if(!empty($ruleiddata)){
$_POST['rules'] = array_merge($_POST['rules'],$ruleiddata);
}
sort($_POST['rules']);
$_POST['rules'] = implode( ',' , array_unique($_POST['rules']));
}else{
$isrules = false;
$_POST['rules'] = '';
}
$_POST['module'] = 'admin';
@ -220,7 +222,7 @@ class AuthManagerController extends AdminController{
if ( $data ) {
if ( empty($data['id']) ) {
\Think\Log::actionLog('AuthManager/createGroup','authGroup',1);
$r = SM("auth_group","sys_")->add($data);
$r = $AuthGroup->syncAdd($data);
addOperationLog(array(
"op_type"=>0,
"key"=> $_POST['title'],
@ -228,8 +230,12 @@ class AuthManagerController extends AdminController{
));
}else{
\Think\Log::actionLog('AuthManager/editGroup','authGroup',1);
$r = SM("auth_group","sys_")->save($data);
// dd($r);
if($isrules){
$r = SM("auth_group","sys_")->save($data);
}else{
$r = $AuthGroup->where("id={$data['id']}")->syncSave($data);
}
//操作日志不传title表示是访问授权
$oparr = array(
"op_type"=>1,
@ -308,7 +314,8 @@ class AuthManagerController extends AdminController{
$savedata = [
"status"=>$status
];
$res = M("AuthGroup")->where("id in ({$ids})")->save($savedata);
// dd($savedata);
$res = D("AuthGroup")->where("id in ({$ids})")->syncSave($savedata);
if($res !==false ){
$this->success($msg['success'],$msg['url'],$msg['ajax']);
}else{
@ -571,7 +578,7 @@ class AuthManagerController extends AdminController{
$promoteData = '';
}
if ($AuthGroup->where("id = {$gid}")->save(array(
if ($AuthGroup->where("id = {$gid}")->syncSave(array(
'data_empower_type' => $data_empower_type,
'data_president' => $promoteData,
'show_data' => $show_data,
@ -620,7 +627,7 @@ class AuthManagerController extends AdminController{
$data = json_encode($data);
$AuthGroup->where(['id'=>$gid])->save(['market_percentage'=>$data]);
$AuthGroup->where(['id'=>$gid])->syncSave(['market_percentage'=>$data]);
$this->success("编辑成功",U("index"));

@ -15,7 +15,7 @@ use Think\Model;
* Class AuthGroupModel
* @author 朱亚杰 <zhuyajie@topthink.net>
*/
class AuthGroupModel extends Model {
class AuthGroupModel extends SubsiteModel {
const TYPE_ADMIN = 1; // 管理员用户组类型标识
const MEMBER = 'member';
const UCENTER_MEMBER = 'ucenter_member';

@ -14,5 +14,64 @@ use Think\Model;
* 文档基础模型
*/
class SubsiteModel extends Model{
//批量添加
protected $dbcount=0;
protected $syncKey="id";
protected $syncData;
protected $syncWhere=false;
public function __construct($name = '', $tablePrefix = '', $connection = '')
{
parent::__construct($name, $tablePrefix, $connection);
if(in_array($this->trueTableName,C('SUBSITE_TABLE'))){
$SUBSITE_DB = C("SUBSITE_DB_CONFIG");
$i = 1;
foreach ($SUBSITE_DB as $k => $v) {
$this->db($i,$v);
$i++;
}
$this->dbcount = $i;
}
}
//修改主键默认id
public function syncKey($key){
$this->syncKey = $key;
return $this;
}
//持续化数据条件
protected function syncCreate($data)
{
$this->syncData = $data;
if(isset($this->options['where'])){
$this->syncWhere = $this->options['where'];
}
}
//同步添加
public function syncAdd($data)
{
$this->syncCreate($data);
$syncVal = $this->db(0)->add();
if(empty($syncVal)){
return $syncVal;
}
$this->syncData[$this->syncKey] = $syncVal;
for ($i=1; $i < $this->dbcount; $i++) {
$this->db($i)->add($this->syncData);
}
return $syncVal;
}
//同步修改
public function syncSave($data)
{
$this->syncCreate($data);
for ($i=0; $i < $this->dbcount; $i++) {
$this->db($i)->where($this->syncWhere)->save($this->syncData);
}
return true;
}
}
Loading…
Cancel
Save