You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
117 lines
3.8 KiB
117 lines
3.8 KiB
<?php
|
|
|
|
namespace app\admin\controller\project;
|
|
|
|
use app\admin\model\AuthGroup;
|
|
use app\admin\model\AuthGroupAccess;
|
|
use app\admin\model\User;
|
|
use app\common\controller\Backend;
|
|
use app\common\model\ProjectCompanyUser;
|
|
use think\Db;
|
|
use think\exception\PDOException;
|
|
|
|
/**
|
|
* 企业用户管理
|
|
*
|
|
* @icon fa fa-circle-o
|
|
*/
|
|
class CompanyAudit extends ProjectBase
|
|
{
|
|
|
|
/**
|
|
* CompanyAudit模型对象
|
|
* @var \app\admin\model\project\CompanyAudit
|
|
*/
|
|
protected $model = null;
|
|
|
|
public $noNeedCompany = ['*'];
|
|
|
|
public function _initialize()
|
|
{
|
|
parent::_initialize();
|
|
$this->model = new \app\admin\model\project\CompanyAudit;
|
|
$this->view->assign("auditStatusList", $this->model->getAuditStatusList());
|
|
}
|
|
|
|
public function del($ids = null) {
|
|
if (false === $this->request->isPost()) {
|
|
$this->error(__("Invalid parameters"));
|
|
}
|
|
$ids = $ids ?: $this->request->post("ids");
|
|
if (empty($ids)) {
|
|
$this->error(__('Parameter %s can not be empty', 'ids'));
|
|
}
|
|
$pk = $this->model->getPk();
|
|
$adminIds = $this->getDataLimitAdminIds();
|
|
if (is_array($adminIds)) {
|
|
$this->model->where($this->dataLimitField, 'in', $adminIds);
|
|
}
|
|
$list = $this->model->where($pk, 'in', $ids)->select();
|
|
|
|
$count = 0;
|
|
Db::startTrans();
|
|
try {
|
|
foreach ($list as $item) {
|
|
$count += $item->delete();
|
|
}
|
|
//删除企业同时删除企业账号和企业绑定用户
|
|
ProjectCompanyUser::where('company_id', 'in', $ids)->delete();
|
|
|
|
//删除企业角色和角色权限
|
|
AuthGroup::where('company_id', 'in', $ids)->delete();
|
|
$user_id = \app\common\model\User::where('company_id', $ids)->value('id');
|
|
AuthGroupAccess::where('uid', 'in', $user_id)->delete();
|
|
|
|
//删除企业账号
|
|
\app\common\model\User::where('company_id', 'in', $ids)->update(['company_id'=>0]);
|
|
Db::commit();
|
|
} catch (PDOException|Exception $e) {
|
|
Db::rollback();
|
|
$this->error($e->getMessage());
|
|
}
|
|
if ($count) {
|
|
$this->success();
|
|
}
|
|
$this->error(__('No rows were deleted'));
|
|
}
|
|
|
|
/**
|
|
* 审核
|
|
* @return void
|
|
*/
|
|
public function audit(){
|
|
$status = $this->request->post('status','', 'intval');//1 成功 2 拒绝
|
|
$id = $this->request->post('id');
|
|
$company = $this->model->get($id);
|
|
$company->audit_status = $status;
|
|
$company->save();
|
|
$user = User::where('company_id', $id)->find();
|
|
//添加企业管理员角色基础数据
|
|
$role_data = [
|
|
'pid' => 1,
|
|
'type' => 1,
|
|
'name' => '企业管理员',
|
|
'rules' => '11,47,48,49,50,963,965,968,974,975,976,977,1036,1037,1038,1048,1057,5,962,970',
|
|
'status' => 'normal',
|
|
'company_id' => $id,
|
|
];
|
|
$groupModel = AuthGroup::create($role_data);
|
|
$group_id = $groupModel->id;
|
|
|
|
//添加企业管理员权限 (后台菜单权限)
|
|
// $group_id = AuthGroup::where('type', AuthGroup::$group_type[0]['id'])->value('id');
|
|
AuthGroupAccess::create(['uid' => $user->id, 'group_id' => $group_id]);
|
|
|
|
//记录企业用户关系 并添加企业角色 (接口数据权限)
|
|
ProjectCompanyUser::create(['company_id' => $id, 'user_id' => $user->id, 'role_id' => $group_id, 'role_type' => AuthGroup::$group_type[0]['id']]);
|
|
$this->success('操作成功', 'project/company_audit/index?ref=addtabs');
|
|
}
|
|
|
|
public function detail($ids = null) {
|
|
$data = $this->model->detail($ids);
|
|
$this->view->assign('row', $data);
|
|
return $this->view->fetch();
|
|
}
|
|
|
|
|
|
}
|
|
|