96 lines
2.4 KiB
PHP
96 lines
2.4 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\User;
|
|
use app\models\Model;
|
|
use yii\data\Pagination;
|
|
use app\components\SiteHelper;
|
|
|
|
|
|
class CommonRoleUserActionForm extends Model
|
|
{
|
|
public $user_id;
|
|
public $cx_mch_id;
|
|
public $type;
|
|
|
|
|
|
public $password;
|
|
|
|
|
|
public function rules()
|
|
{
|
|
return [
|
|
[['password'], 'trim'],
|
|
[['password'], 'string', 'min' => 8],
|
|
[['cx_mch_id', 'type'], 'integer'],
|
|
[['user_id', ], 'safe'],
|
|
[['user_id', 'cx_mch_id', 'type'], 'required'],
|
|
];
|
|
}
|
|
|
|
|
|
public function delete()
|
|
{
|
|
if(!$this->validate()){
|
|
return $this->getModelError();
|
|
}
|
|
$t = \Yii::$app->db->beginTransaction();
|
|
$model = User::findOne([
|
|
'id' => $this->user_id,
|
|
'is_delete' => 0,
|
|
]);
|
|
if($model == null){
|
|
return $this->apiReturnError('用户不存在或已经删除');
|
|
}
|
|
// $model->status = User::STATUS_ACCOUNT_LOGOUT;
|
|
$model->type = 0;
|
|
$model->updated_at = time();
|
|
if(!$model->save()){
|
|
$t->rollBack();
|
|
return $this->getModelError($model);
|
|
}
|
|
RoleUser::updateAll(['is_delete' => 1],['is_delete' => 0, 'user_id' => $this->user_id]);
|
|
$t->commit();
|
|
return $this->apiReturnSuccess("删除成功");
|
|
}
|
|
|
|
public function resetPwd()
|
|
{
|
|
if(!$this->validate()){
|
|
return $this->getModelError();
|
|
}
|
|
$model = User::findOne([
|
|
'id' => $this->user_id,
|
|
'is_delete' => 0,
|
|
'cx_mch_id' => $this->cx_mch_id,
|
|
'type' => [User::TYPE_STAFF,User::TYPE_BOSS_STAFF,User::TYPE_ADMIN_STAFF]
|
|
]);
|
|
if($model == null){
|
|
return $this->apiReturnError('用户不存在或已经删除');
|
|
}
|
|
$model->setPassword($this->password);
|
|
if(!$model->save()){
|
|
return $this->getModelError($model);
|
|
}
|
|
return $this->apiReturnSuccess("操作成功");
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|