作者 何书鹏
1 个管道 的构建 失败 耗费 8 秒

超级管理员给用户分配组织

... ... @@ -3,6 +3,9 @@
namespace app\admin\controller\user;
use app\admin\library\Auth;
use app\admin\model\AuthGroup;
use app\admin\model\ThirdExam;
use app\admin\model\ThirdStudy;
use app\common\controller\Backend;
use app\common\model\User as UserModel;
use Exception;
... ... @@ -591,4 +594,40 @@ class User extends Backend
$this->success();
}
/**
* 分配组织
*/
public function fporganization($ids = null)
{
if ($this->request->isPost()) {
empty($ids) && $this->error('请选择用户');
$organization_id = $this->request->post("organization_id");
empty($organization_id) && $this->error('请选择组织');
$update_data = ['organization_id'=>$organization_id];
Db::startTrans();
try {
$this->model->where('id','in',$ids)->update($update_data);
ThirdStudy::where('third_id','in',$ids)->update($update_data);
ThirdExam::where('user_id','in',$ids)->update($update_data);
Db::commit();
} catch (ValidateException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (PDOException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
$this->success();
}
$this->getOrganizationId() > 0 && $this->error(__('You have no permission'));
$organizationList = AuthGroup::where('is_organization','1')->column('name','id');
$this->view->assign('organizationList',$organizationList);
return $this->view->fetch();
}
}
... ...
<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('组织')}:</label>
<div class="col-xs-12 col-sm-8">
<select id="c-organization_id" data-rule="required" class="form-control selectpicker" name="organization_id">
{foreach name="organizationList" item="vo"}
<option value="{$key}" {in name="key" value=""}selected{/in}>{$vo}</option>
{/foreach}
</select>
</div>
</div>
<div class="form-group layer-footer">
<label class="control-label col-xs-12 col-sm-2"></label>
<div class="col-xs-12 col-sm-8">
<button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
<button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
</div>
</div>
</form>
... ...
... ... @@ -16,6 +16,7 @@
<!--</div>-->
<a href="javascript:;" class="btn btn-danger btn-import {:$auth->check('user/user/import')?'':'hide'}" title="{:__('Import')}" id="btn-import-file" data-url="ajax/upload" data-mimetype="csv,xls,xlsx" data-multiple="false"><i class="fa fa-upload"></i> {:__('Import')}</a>
<a href="/assets/import_moudle/用户数据导入.xlsx" class="btn btn-danger {:$auth->check('user/user/import')?'':'hide'}" title="{:__('导入模板')}"> {:__('导入模板')}</a>
<a href="javascript:;" class="btn btn-info btn-disabled disabled {:$auth->check('user/user/fpOrganization')?'':'hide'}" title="分配组织" id="btn-fp-organization">分配组织</a>
<a href="javascript:;" class="btn btn-default" style="font-size:14px;color:dodgerblue;">
<span class="extend">
用户数量:<span id="total">0</span>
... ...
... ... @@ -94,6 +94,13 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
// 为表格绑定事件
Table.api.bindevent(table);
//分配组织
$(document).on('click','#btn-fp-organization',function (){
var ids = Table.api.selectedids(table);
Fast.api.open('user/user/fporganization?ids=' + ids, '分配组织');
return false;
})
},
add: function () {
Controller.api.bindevent();
... ... @@ -101,6 +108,9 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
edit: function () {
Controller.api.bindevent();
},
fporganization: function () {
Form.api.bindevent($("form[role=form]"));
},
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
... ...