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.
83 lines
2.6 KiB
83 lines
2.6 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | Niucloud-admin 企业快速开发的多应用管理平台
|
|
// +----------------------------------------------------------------------
|
|
// | 官方网址:https://www.niucloud.com
|
|
// +----------------------------------------------------------------------
|
|
// | niucloud团队 版权所有 开源版本可自由商用
|
|
// +----------------------------------------------------------------------
|
|
// | Author: Niucloud Team
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace app\service\api\apiService;
|
|
|
|
use app\model\dict\Dict;
|
|
use core\base\BaseApiService;
|
|
|
|
/**
|
|
* 公共服务层
|
|
* Class MemberService
|
|
* @package app\service\api\member
|
|
*/
|
|
class CommonService extends BaseApiService
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
//获取字典
|
|
public function getDictionary(array $where,string $field = '*'){
|
|
$model = (new Dict());
|
|
if(!empty($where['key'])){
|
|
$model = $model->where('key',$where['key']);
|
|
}
|
|
$res = $model->field($field)->find();//员工信息
|
|
|
|
if($res){
|
|
$res = $res->toArray();
|
|
}else{
|
|
$res = [];
|
|
}
|
|
return $res;
|
|
|
|
}
|
|
|
|
/**
|
|
* 对比新旧数据改变
|
|
* @param array $old_data 旧数据
|
|
* @param array $new_data 新数据
|
|
* @param array $ignoreFields 忽略验证的字段|默认[]
|
|
* @return array
|
|
*/
|
|
public function compareData(array $old_data, array $new_data, array $ignoreFields = ['updated_at'])
|
|
{
|
|
$changedFields = [];//改了那些字段
|
|
$oldChanges = [];//数据修改前的样子
|
|
$newChanges = [];//数据修改后的样子
|
|
|
|
foreach ($new_data as $key => $value) {
|
|
// 如果字段在忽略列表中,则跳过
|
|
if (in_array($key, $ignoreFields)) {
|
|
continue;
|
|
}
|
|
|
|
if (!isset($old_data[$key]) || $old_data[$key] != $value) {
|
|
$changedFields[] = $key;
|
|
$oldChanges[$key] = $old_data[$key] ?? null;
|
|
$newChanges[$key] = $value;
|
|
}
|
|
}
|
|
|
|
return [
|
|
'changed_fields' => $changedFields,
|
|
'old_values' => $oldChanges,
|
|
'new_values' => $newChanges,
|
|
|
|
'changed_fields_json' => json_encode($changedFields, JSON_UNESCAPED_UNICODE),
|
|
'old_values_json' => json_encode($oldChanges, JSON_UNESCAPED_UNICODE),
|
|
'new_values_json' => json_encode($newChanges, JSON_UNESCAPED_UNICODE)
|
|
];
|
|
}
|
|
|
|
}
|
|
|