更新数据库加密相关操作

This commit is contained in:
2025-01-15 13:16:48 +08:00
parent 81069274be
commit 262ecc4f5e
12 changed files with 383 additions and 90 deletions

View File

@@ -9,8 +9,15 @@ use common\core\BaseAdminController;
use common\enums\UserRoleEnum;
use common\helpers\ArrayHelper;
use common\models\oldDb\AdminAccessToken;
use common\models\oldDb\DoctorInfo;
use common\models\oldDb\DoctorPatient;
use common\models\oldDb\LeadInfo;
use common\models\oldDb\Role;
use common\models\oldDb\ServInfo;
use common\models\oldDb\Store;
use common\models\oldDb\User;
use common\models\oldDb\UserPatient;
use common\modelsgii\oldDb\PharmacistInfo;
use common\services\SmsService;
use Yii;
use yii\base\Exception;
@@ -20,10 +27,100 @@ class LoginController extends BaseAdminController
public $modelClass = Admin::class;
public $enableCsrfValidation = false;
public $defaultAction = 'register';
public $optional = ['register', 'logout', 'login', 'send-code'];
public $optional = ['register', 'logout', 'login', 'send-code', 'test'];
public $mallId;
public function actionTest()
{
return UserPatient::find()->all();
$this->updateDoctor();
$this->updateUser();
$this->updateServInfo();
$this->updatePharmacistInfo();
$this->updateLeadInfo();
$this->updateUserPatient();
$this->updateDoctorPatient();
return ['执行完成'];
}
private function updateDoctor()
{
// 用到了身份证的模型:DoctorInfo
$info = DoctorInfo::find()->all();
foreach ($info as $v) {
if (!is_encrypted($v->idcard)) {
$v->updated_at = time();
}
$v->save();
}
}
private function updateUser()
{
$info = User::find()->all();
foreach ($info as $v) {
if (!is_encrypted($v->idcard)) {
$v->updated_at = time();
}
$v->save();
}
}
private function updateServInfo()
{
$info = ServInfo::find()->all();
foreach ($info as $v) {
if (!is_encrypted($v->idcard)) {
$v->updated_at = time();
}
$v->save();
}
}
private function updatePharmacistInfo()
{
$info = PharmacistInfo::find()->all();
foreach ($info as $v) {
if (!is_encrypted($v->idcard)) {
$v->updated_at = time();
}
$v->save();
}
}
private function updateLeadInfo()
{
$info = LeadInfo::find()->all();
foreach ($info as $v) {
if (!is_encrypted($v->idcard)) {
$v->updated_at = time();
}
$v->save();
}
}
private function updateUserPatient()
{
$info = UserPatient::find()->all();
foreach ($info as $v) {
if (!is_encrypted($v->id_card)) {
$v->updated_at = time();
}
$v->save();
}
}
private function updateDoctorPatient()
{
$info = DoctorPatient::find()->all();
foreach ($info as $v) {
if (!is_encrypted($v->id_card)) {
$v->updated_at = time();
}
$v->save();
}
}
public function actionLogin()
{
$post = Yii::$app->request->post();

View File

@@ -8,6 +8,7 @@
namespace admin\foundation;
use common\jobs\LogJob;
use common\services\DataEncryptor;
use Yii;
use yii\base\UserException;
use yii\helpers\Json;
@@ -49,6 +50,10 @@ class JsonResponseFormatter extends \yii\web\JsonResponseFormatter
if (is_array($value)) {
$value = self::aseEncode($value); // 递归处理子数组
} else {
// 数据库中加密的方法需要解密
if (in_array($key, \Yii::$app->params['database_ase_list']) && is_encrypted($value)) {
$value = (new DataEncryptor(Yii::$app->params['ase_key']))->decrypt($value);
}
if (in_array($key, \Yii::$app->params['aseList'])) {
if (is_string($key)) {
$value = ase_encode($value); // 加密指定键值