From 0d533525fee48b9ee51fcac2c8ca6959a3980a6a Mon Sep 17 00:00:00 2001 From: chenzhi Date: Tue, 15 Dec 2020 19:14:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=9D=83=E9=99=90=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AuthManagerController.class.php | 19 ++++-- .../Admin/Model/AuthGroupModel.class.php | 2 +- .../Admin/Model/SubsiteModel.class.php | 59 +++++++++++++++++++ 3 files changed, 73 insertions(+), 7 deletions(-) diff --git a/Application/Admin/Controller/AuthManagerController.class.php b/Application/Admin/Controller/AuthManagerController.class.php index 266684cde..9f3c009a1 100644 --- a/Application/Admin/Controller/AuthManagerController.class.php +++ b/Application/Admin/Controller/AuthManagerController.class.php @@ -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")); diff --git a/Application/Admin/Model/AuthGroupModel.class.php b/Application/Admin/Model/AuthGroupModel.class.php index 59dabdf40..30c10b25e 100644 --- a/Application/Admin/Model/AuthGroupModel.class.php +++ b/Application/Admin/Model/AuthGroupModel.class.php @@ -15,7 +15,7 @@ use Think\Model; * Class AuthGroupModel * @author 朱亚杰 */ -class AuthGroupModel extends Model { +class AuthGroupModel extends SubsiteModel { const TYPE_ADMIN = 1; // 管理员用户组类型标识 const MEMBER = 'member'; const UCENTER_MEMBER = 'ucenter_member'; diff --git a/Application/Admin/Model/SubsiteModel.class.php b/Application/Admin/Model/SubsiteModel.class.php index 4a32915be..413ec6b50 100644 --- a/Application/Admin/Model/SubsiteModel.class.php +++ b/Application/Admin/Model/SubsiteModel.class.php @@ -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; + } + + + } \ No newline at end of file