屏蔽导入数据时名称为企业的身份证号码的检测和生成生日性别
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
孟凡懂 2022-07-12 14:54:03 +08:00
parent 0cc064bd53
commit 1d81f37aeb
2 changed files with 59 additions and 66 deletions

View File

@ -128,12 +128,17 @@ class Import extends Backend
} }
foreach ($insert as $key => &$val) { foreach ($insert as $key => &$val) {
//处理字段 //处理字段
$cardinfo = $this->checkcardid($val['cardid']); if($this->isCreditNo($val['cardid']) == true){
if ($cardinfo['iscard'] == false) { $cardinfo = $this->checkcardid($val['cardid']);
unset($insert[$key]); if ($cardinfo['iscard'] == false) {
unset($insert[$key]);
}else{
$val['birthday'] = $cardinfo['birthday'];
$val['genderdata'] = $cardinfo['sex'];
}
}else{ }else{
$val['birthday'] = $cardinfo['birthday']; $val['birthday'] = '0000-00-00';
$val['genderdata'] = $cardinfo['sex']; $val['genderdata'] = 'male';
} }
if(!empty($val['frameno'])){ if(!empty($val['frameno'])){
$check_frameno = $this->check_frameno($val['frameno']); $check_frameno = $this->check_frameno($val['frameno']);
@ -141,6 +146,7 @@ class Import extends Backend
unset($insert[$key]); unset($insert[$key]);
} }
} }
//todo:分组 //todo:分组
if(empty($val['category_id'])){ if(empty($val['category_id'])){
$val['category_id'] = $this->all_cates[1]; $val['category_id'] = $this->all_cates[1];
@ -158,7 +164,7 @@ class Import extends Backend
} }
$val['level_id'] = $this->all_levels_name[$val['level_id']]; $val['level_id'] = $this->all_levels_name[$val['level_id']];
} }
//var_dump($insert);
$prefix = Config::get('database.prefix'); $prefix = Config::get('database.prefix');
$count = 0; $count = 0;
// if ($params['update']) { // if ($params['update']) {
@ -330,6 +336,7 @@ class Import extends Backend
if ($encoding != 'utf-8') { if ($encoding != 'utf-8') {
$line = mb_convert_encoding($line, 'utf-8', $encoding); $line = mb_convert_encoding($line, 'utf-8', $encoding);
} }
//var_dump($line);
if ($n == 0 || preg_match('/^".*"$/', $line)) { if ($n == 0 || preg_match('/^".*"$/', $line)) {
fwrite($fp, $line . "\n"); fwrite($fp, $line . "\n");
} else { } else {
@ -455,14 +462,20 @@ class Import extends Backend
//var_dump($val); //var_dump($val);
//todo:处理日期格式 //todo:处理日期格式
if($currentColumn == 8 || $currentColumn == 15){ if($currentColumn == 8 || $currentColumn == 15){
$val = date('Y-m-d',Date::excelToTimestamp($val)); if($val==''){
$val = '0000-00-00';
}else{
$val = date('Y-m-d',Date::excelToTimestamp($val));
}
} }
//todo:身份证校验 //todo:身份证校验
if($currentColumn == 3){ if($currentColumn == 3){
$cardinfo = $this->checkcardid($val); if($this->isCreditNo($val) == true){
$check_cardid = $cardinfo['iscard']; $cardinfo = $this->checkcardid($val);
if($check_cardid==false){ $check_cardid = $cardinfo['iscard'];
$val=$val.'(身份证号错误)'; if($check_cardid==false){
$val=$val.'(身份证号错误)';
}
} }
} }
//todo:车牌重复检测 //todo:车牌重复检测
@ -483,6 +496,7 @@ class Import extends Backend
$values[] = is_null($val) ? '' : $val; $values[] = is_null($val) ? '' : $val;
} }
//var_dump($values);
//exit(); //exit();
$rows = []; $rows = [];
$all = []; $all = [];

View File

@ -1,7 +1,5 @@
<?php <?php
namespace app\common\controller; namespace app\common\controller;
use app\admin\library\Auth; use app\admin\library\Auth;
use think\Config; use think\Config;
use think\Controller; use think\Controller;
@ -12,53 +10,44 @@ use think\Model;
use think\Session; use think\Session;
use fast\Tree; use fast\Tree;
use think\Validate; use think\Validate;
/** /**
* 后台控制器基类 * 后台控制器基类
*/ */
class Backend extends Controller class Backend extends Controller
{ {
/** /**
* 无需登录的方法,同时也就不需要鉴权了 * 无需登录的方法,同时也就不需要鉴权了
* @var array * @var array
*/ */
protected $noNeedLogin = []; protected $noNeedLogin = [];
/** /**
* 无需鉴权的方法,但需要登录 * 无需鉴权的方法,但需要登录
* @var array * @var array
*/ */
protected $noNeedRight = []; protected $noNeedRight = [];
/** /**
* 布局模板 * 布局模板
* @var string * @var string
*/ */
protected $layout = 'default'; protected $layout = 'default';
/** /**
* 权限控制类 * 权限控制类
* @var Auth * @var Auth
*/ */
protected $auth = null; protected $auth = null;
/** /**
* 模型对象 * 模型对象
* @var \think\Model * @var \think\Model
*/ */
protected $model = null; protected $model = null;
/** /**
* 快速搜索时执行查找的字段 * 快速搜索时执行查找的字段
*/ */
protected $searchFields = 'id'; protected $searchFields = 'id';
/** /**
* 是否是关联查询 * 是否是关联查询
*/ */
protected $relationSearch = false; protected $relationSearch = false;
/** /**
* 是否开启数据限制 * 是否开启数据限制
* 支持auth/personal * 支持auth/personal
@ -66,76 +55,59 @@ class Backend extends Controller
* 默认为禁用,若启用请务必保证表中存在admin_id字段 * 默认为禁用,若启用请务必保证表中存在admin_id字段
*/ */
protected $dataLimit = false; protected $dataLimit = false;
/** /**
* 数据限制字段 * 数据限制字段
*/ */
protected $dataLimitField = 'admin_id'; protected $dataLimitField = 'admin_id';
/** /**
* 数据限制开启时自动填充限制字段值 * 数据限制开启时自动填充限制字段值
*/ */
protected $dataLimitFieldAutoFill = true; protected $dataLimitFieldAutoFill = true;
/** /**
* 是否开启Validate验证 * 是否开启Validate验证
*/ */
protected $modelValidate = false; protected $modelValidate = false;
/** /**
* 是否开启模型场景验证 * 是否开启模型场景验证
*/ */
protected $modelSceneValidate = false; protected $modelSceneValidate = false;
/** /**
* Multi方法可批量修改的字段 * Multi方法可批量修改的字段
*/ */
protected $multiFields = 'status'; protected $multiFields = 'status';
/** /**
* Selectpage可显示的字段 * Selectpage可显示的字段
*/ */
protected $selectpageFields = '*'; protected $selectpageFields = '*';
/** /**
* 前台提交过来,需要排除的字段数据 * 前台提交过来,需要排除的字段数据
*/ */
protected $excludeFields = ""; protected $excludeFields = "";
/** /**
* 导入文件首行类型 * 导入文件首行类型
* 支持comment/name * 支持comment/name
* 表示注释或字段名 * 表示注释或字段名
*/ */
protected $importHeadType = 'comment'; protected $importHeadType = 'comment';
/** /**
* 引入后台控制器的traits * 引入后台控制器的traits
*/ */
use \app\admin\library\traits\Backend; use \app\admin\library\traits\Backend;
public function _initialize() public function _initialize()
{ {
$modulename = $this->request->module(); $modulename = $this->request->module();
$controllername = Loader::parseName($this->request->controller()); $controllername = Loader::parseName($this->request->controller());
$actionname = strtolower($this->request->action()); $actionname = strtolower($this->request->action());
$path = str_replace('.', '/', $controllername) . '/' . $actionname; $path = str_replace('.', '/', $controllername) . '/' . $actionname;
// 定义是否Addtabs请求 // 定义是否Addtabs请求
!defined('IS_ADDTABS') && define('IS_ADDTABS', input("addtabs") ? true : false); !defined('IS_ADDTABS') && define('IS_ADDTABS', input("addtabs") ? true : false);
// 定义是否Dialog请求 // 定义是否Dialog请求
!defined('IS_DIALOG') && define('IS_DIALOG', input("dialog") ? true : false); !defined('IS_DIALOG') && define('IS_DIALOG', input("dialog") ? true : false);
// 定义是否AJAX请求 // 定义是否AJAX请求
!defined('IS_AJAX') && define('IS_AJAX', $this->request->isAjax()); !defined('IS_AJAX') && define('IS_AJAX', $this->request->isAjax());
// 检测IP是否允许 // 检测IP是否允许
check_ip_allowed(); check_ip_allowed();
$this->auth = Auth::instance(); $this->auth = Auth::instance();
// 设置当前请求的URI // 设置当前请求的URI
$this->auth->setRequestUri($path); $this->auth->setRequestUri($path);
// 检测是否需要验证登录 // 检测是否需要验证登录
@ -160,7 +132,6 @@ class Backend extends Controller
} }
} }
} }
// 非选项卡时重定向 // 非选项卡时重定向
if (!$this->request->isPost() && !IS_AJAX && !IS_ADDTABS && !IS_DIALOG && input("ref") == 'addtabs') { if (!$this->request->isPost() && !IS_AJAX && !IS_ADDTABS && !IS_DIALOG && input("ref") == 'addtabs') {
$url = preg_replace_callback("/([\?|&]+)ref=addtabs(&?)/i", function ($matches) { $url = preg_replace_callback("/([\?|&]+)ref=addtabs(&?)/i", function ($matches) {
@ -175,7 +146,6 @@ class Backend extends Controller
$this->redirect('index/index', [], 302, ['referer' => $url]); $this->redirect('index/index', [], 302, ['referer' => $url]);
exit; exit;
} }
// 设置面包屑导航数据 // 设置面包屑导航数据
$breadcrumb = []; $breadcrumb = [];
if (!IS_DIALOG && !config('fastadmin.multiplenav') && config('fastadmin.breadcrumb')) { if (!IS_DIALOG && !config('fastadmin.multiplenav') && config('fastadmin.breadcrumb')) {
@ -183,22 +153,16 @@ class Backend extends Controller
array_pop($breadcrumb); array_pop($breadcrumb);
} }
$this->view->breadcrumb = $breadcrumb; $this->view->breadcrumb = $breadcrumb;
// 如果有使用模板布局 // 如果有使用模板布局
if ($this->layout) { if ($this->layout) {
$this->view->engine->layout('layout/' . $this->layout); $this->view->engine->layout('layout/' . $this->layout);
} }
// 语言检测 // 语言检测
$lang = strip_tags($this->request->langset()); $lang = strip_tags($this->request->langset());
$site = Config::get("site"); $site = Config::get("site");
$upload = \app\common\model\Config::upload(); $upload = \app\common\model\Config::upload();
// 上传信息配置后 // 上传信息配置后
Hook::listen("upload_config_init", $upload); Hook::listen("upload_config_init", $upload);
// 配置信息 // 配置信息
$config = [ $config = [
'site' => array_intersect_key($site, array_flip(['name', 'indexurl', 'cdnurl', 'version', 'timezone', 'languages'])), 'site' => array_intersect_key($site, array_flip(['name', 'indexurl', 'cdnurl', 'version', 'timezone', 'languages'])),
@ -212,9 +176,7 @@ class Backend extends Controller
'referer' => Session::get("referer") 'referer' => Session::get("referer")
]; ];
$config = array_merge($config, Config::get("view_replace_str")); $config = array_merge($config, Config::get("view_replace_str"));
Config::set('upload', array_merge(Config::get('upload'), $upload)); Config::set('upload', array_merge(Config::get('upload'), $upload));
// 配置信息后 // 配置信息后
Hook::listen("config_init", $config); Hook::listen("config_init", $config);
//加载当前控制器语言包 //加载当前控制器语言包
@ -228,7 +190,6 @@ class Backend extends Controller
//渲染管理员对象 //渲染管理员对象
$this->assign('admin', Session::get('admin')); $this->assign('admin', Session::get('admin'));
} }
/** /**
* 加载语言文件 * 加载语言文件
* @param string $name * @param string $name
@ -238,7 +199,6 @@ class Backend extends Controller
$name = Loader::parseName($name); $name = Loader::parseName($name);
Lang::load(APP_PATH . $this->request->module() . '/lang/' . $this->request->langset() . '/' . str_replace('.', '/', $name) . '.php'); Lang::load(APP_PATH . $this->request->module() . '/lang/' . $this->request->langset() . '/' . str_replace('.', '/', $name) . '.php');
} }
/** /**
* 渲染配置信息 * 渲染配置信息
* @param mixed $name 键名或数组 * @param mixed $name 键名或数组
@ -248,7 +208,6 @@ class Backend extends Controller
{ {
$this->view->config = array_merge($this->view->config ? $this->view->config : [], is_array($name) ? $name : [$name => $value]); $this->view->config = array_merge($this->view->config ? $this->view->config : [], is_array($name) ? $name : [$name => $value]);
} }
/** /**
* 生成查询所需要的条件,排序方式 * 生成查询所需要的条件,排序方式
* @param mixed $searchfields 快速查询的字段 * @param mixed $searchfields 快速查询的字段
@ -324,7 +283,6 @@ class Backend extends Controller
$sym = '='; $sym = '=';
} }
} }
switch ($sym) { switch ($sym) {
case '=': case '=':
case '<>': case '<>':
@ -430,7 +388,6 @@ class Backend extends Controller
}; };
return [$where, $sort, $order, $offset, $limit, $page, $alias, $bind]; return [$where, $sort, $order, $offset, $limit, $page, $alias, $bind];
} }
/** /**
* 获取数据限制的管理员ID * 获取数据限制的管理员ID
* 禁用数据限制时返回的是null * 禁用数据限制时返回的是null
@ -450,7 +407,6 @@ class Backend extends Controller
} }
return $adminIds; return $adminIds;
} }
/** /**
* Selectpage的实现方法 * Selectpage的实现方法
* *
@ -462,7 +418,6 @@ class Backend extends Controller
{ {
//设置过滤方法 //设置过滤方法
$this->request->filter(['trim', 'strip_tags', 'htmlspecialchars']); $this->request->filter(['trim', 'strip_tags', 'htmlspecialchars']);
//搜索关键词,客户端输入以空格分开,这里接收为数组 //搜索关键词,客户端输入以空格分开,这里接收为数组
$word = (array)$this->request->request("q_word/a"); $word = (array)$this->request->request("q_word/a");
//当前页 //当前页
@ -495,7 +450,6 @@ class Backend extends Controller
$order[$v[0]] = $v[1]; $order[$v[0]] = $v[1];
} }
$field = $field ? $field : 'name'; $field = $field ? $field : 'name';
//如果有primaryvalue,说明当前是初始化传值 //如果有primaryvalue,说明当前是初始化传值
if ($primaryvalue !== null) { if ($primaryvalue !== null) {
$where = [$primarykey => ['in', $primaryvalue]]; $where = [$primarykey => ['in', $primaryvalue]];
@ -538,9 +492,7 @@ class Backend extends Controller
if (is_array($adminIds)) { if (is_array($adminIds)) {
$this->model->where($this->dataLimitField, 'in', $adminIds); $this->model->where($this->dataLimitField, 'in', $adminIds);
} }
$fields = is_array($this->selectpageFields) ? $this->selectpageFields : ($this->selectpageFields && $this->selectpageFields != '*' ? explode(',', $this->selectpageFields) : []); $fields = is_array($this->selectpageFields) ? $this->selectpageFields : ($this->selectpageFields && $this->selectpageFields != '*' ? explode(',', $this->selectpageFields) : []);
//如果有primaryvalue,说明当前是初始化传值,按照选择顺序排序 //如果有primaryvalue,说明当前是初始化传值,按照选择顺序排序
if ($primaryvalue !== null && preg_match("/^[a-z0-9_\-]+$/i", $primarykey)) { if ($primaryvalue !== null && preg_match("/^[a-z0-9_\-]+$/i", $primarykey)) {
$primaryvalue = array_unique(is_array($primaryvalue) ? $primaryvalue : explode(',', $primaryvalue)); $primaryvalue = array_unique(is_array($primaryvalue) ? $primaryvalue : explode(',', $primaryvalue));
@ -548,18 +500,14 @@ class Backend extends Controller
$primaryvalue = array_map(function ($value) { $primaryvalue = array_map(function ($value) {
return '\'' . $value . '\''; return '\'' . $value . '\'';
}, $primaryvalue); }, $primaryvalue);
$primaryvalue = implode(',', $primaryvalue); $primaryvalue = implode(',', $primaryvalue);
$this->model->orderRaw("FIELD(`{$primarykey}`, {$primaryvalue})"); $this->model->orderRaw("FIELD(`{$primarykey}`, {$primaryvalue})");
} else { } else {
$this->model->order($order); $this->model->order($order);
} }
$datalist = $this->model->where($where) $datalist = $this->model->where($where)
->page($page, $pagesize) ->page($page, $pagesize)
->select(); ->select();
foreach ($datalist as $index => $item) { foreach ($datalist as $index => $item) {
unset($item['password'], $item['salt']); unset($item['password'], $item['salt']);
if ($this->selectpageFields == '*') { if ($this->selectpageFields == '*') {
@ -588,19 +536,16 @@ class Backend extends Controller
//这里一定要返回有list这个字段,total是可选的,如果total<=list的数量,则会隐藏分页按钮 //这里一定要返回有list这个字段,total是可选的,如果total<=list的数量,则会隐藏分页按钮
return json(['list' => $list, 'total' => $total]); return json(['list' => $list, 'total' => $total]);
} }
/** /**
* 刷新Token * 刷新Token
*/ */
protected function token() protected function token()
{ {
$token = $this->request->param('__token__'); $token = $this->request->param('__token__');
//验证Token //验证Token
if (!Validate::make()->check(['__token__' => $token], ['__token__' => 'require|token'])) { if (!Validate::make()->check(['__token__' => $token], ['__token__' => 'require|token'])) {
$this->error(__('Token verification error'), '', ['__token__' => $this->request->token()]); $this->error(__('Token verification error'), '', ['__token__' => $this->request->token()]);
} }
//刷新Token //刷新Token
$this->request->token(); $this->request->token();
} }
@ -695,4 +640,38 @@ class Backend extends Controller
return false; return false;
} }
} }
/**
* 判断是否为合法的身份证号码
* @param $mobile
* @return int
*/
public function isCreditNo($vStr)
{
$vCity = array(
'11', '12', '13', '14', '15', '21', '22',
'23', '31', '32', '33', '34', '35', '36',
'37', '41', '42', '43', '44', '45', '46',
'50', '51', '52', '53', '54', '61', '62',
'63', '64', '65', '71', '81', '82', '91'
);
if (!preg_match('/^([\d]{17}[xX\d]|[\d]{15})$/', $vStr)) return false;
if (!in_array(substr($vStr, 0, 2), $vCity)) return false;
$vStr = preg_replace('/[xX]$/i', 'a', $vStr);
$vLength = strlen($vStr);
if ($vLength == 18) {
$vBirthday = substr($vStr, 6, 4) . '-' . substr($vStr, 10, 2) . '-' . substr($vStr, 12, 2);
} else {
$vBirthday = '19' . substr($vStr, 6, 2) . '-' . substr($vStr, 8, 2) . '-' . substr($vStr, 10, 2);
}
if (date('Y-m-d', strtotime($vBirthday)) != $vBirthday) return false;
if ($vLength == 18) {
$vSum = 0;
for ($i = 17; $i >= 0; $i--) {
$vSubStr = substr($vStr, 17 - $i, 1);
$vSum += (pow(2, $i) % 11) * (($vSubStr == 'a') ? 10 : intval($vSubStr, 11));
}
if ($vSum % 11 != 1) return false;
}
return true;
}
} }