119 lines
3.9 KiB
PHP
119 lines
3.9 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @author Any
|
|
* @description KISS
|
|
* @date 2021年9月13日
|
|
* @version 1.0.0
|
|
*
|
|
* _____LOG_____
|
|
*
|
|
*/
|
|
namespace app\models\common\auth;
|
|
|
|
use app\models\auth\Role;
|
|
use app\models\auth\RoleUser;
|
|
use app\models\auth\RolePermission;
|
|
use app\models\Model;
|
|
use yii\data\Pagination;
|
|
use app\components\SiteHelper;
|
|
|
|
|
|
class CommonRoleActionForm extends Model
|
|
{
|
|
public $role_id;
|
|
public $cx_mch_id;
|
|
|
|
public function rules()
|
|
{
|
|
return [
|
|
[['cx_mch_id'], 'integer'],
|
|
[['role_id', ], 'safe'],
|
|
[['role_id', 'cx_mch_id'], 'required'],
|
|
];
|
|
}
|
|
|
|
|
|
public function delete()
|
|
{
|
|
if(!$this->validate()){
|
|
return $this->getModelError();
|
|
}
|
|
if(is_array($this->role_id)){
|
|
foreach ($this->role_id as $role_id){
|
|
$t = \Yii::$app->db->beginTransaction();
|
|
$model = Role::findOne([
|
|
'id' => $role_id,
|
|
'is_delete' => 0,
|
|
'cx_mch_id' => $this->cx_mch_id
|
|
]);
|
|
if($model == null)
|
|
continue;
|
|
|
|
if($model->name == '财务'){
|
|
$t->rollBack();
|
|
return $this->apiReturnError('财务属于系统角色,无法删除');
|
|
}
|
|
if($model->name == '运营'){
|
|
$t->rollBack();
|
|
return $this->apiReturnError('运营属于系统角色,无法删除');
|
|
}
|
|
if($model->name == 'BOSS账号'){
|
|
$t->rollBack();
|
|
return $this->apiReturnError('BOSS账号属于系统角色,无法删除');
|
|
}
|
|
if($model->name == '总部管理员'){
|
|
$t->rollBack();
|
|
return $this->apiReturnError('总部管理员属于系统角色,无法删除');
|
|
}
|
|
$model->is_delete = 1;
|
|
Role::deleteRolePermission($role_id, $this->cx_mch_id);
|
|
RoleUser::updateAll(['is_delete' => 1], ['is_delete' => 0, 'role_id' => $role_id]);
|
|
if(!$model->save()){
|
|
$t->rollBack();
|
|
return $this->getModelError($model);
|
|
}
|
|
$t->commit();
|
|
}
|
|
} else {
|
|
$t = \Yii::$app->db->beginTransaction();
|
|
$model = Role::findOne([
|
|
'id' => $this->role_id,
|
|
'is_delete' => 0,
|
|
'cx_mch_id' => $this->cx_mch_id
|
|
]);
|
|
if($model == null){
|
|
return $this->apiReturnError('角色不存在或已经删除');
|
|
}
|
|
if($model->name == '财务'){
|
|
$t->rollBack();
|
|
return $this->apiReturnError('财务属于系统角色,无法删除');
|
|
}
|
|
if($model->name == '运营'){
|
|
$t->rollBack();
|
|
return $this->apiReturnError('运营属于系统角色,无法删除');
|
|
}
|
|
if($model->name == 'BOSS账号'){
|
|
$t->rollBack();
|
|
return $this->apiReturnError('BOSS账号属于系统角色,无法删除');
|
|
}
|
|
if($model->name == '总部管理员'){
|
|
$t->rollBack();
|
|
return $this->apiReturnError('总部管理员属于系统角色,无法删除');
|
|
}
|
|
$model->is_delete = 1;
|
|
Role::deleteRolePermission($this->role_id, $this->cx_mch_id);
|
|
RoleUser::updateAll(['is_delete' => 1], ['is_delete' => 0, 'role_id' => $this->role_id]);
|
|
if(!$model->save()){
|
|
$t->rollBack();
|
|
return $this->getModelError($model);
|
|
}
|
|
$t->commit();
|
|
}
|
|
return $this->apiReturnSuccess("删除成功");
|
|
}
|
|
|
|
|
|
}
|
|
|