屏蔽导入数据时名称为企业的身份证号码的检测和生成生日性别
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
0cc064bd53
commit
1d81f37aeb
@ -128,6 +128,7 @@ class Import extends Backend
|
||||
}
|
||||
foreach ($insert as $key => &$val) {
|
||||
//处理字段
|
||||
if($this->isCreditNo($val['cardid']) == true){
|
||||
$cardinfo = $this->checkcardid($val['cardid']);
|
||||
if ($cardinfo['iscard'] == false) {
|
||||
unset($insert[$key]);
|
||||
@ -135,12 +136,17 @@ class Import extends Backend
|
||||
$val['birthday'] = $cardinfo['birthday'];
|
||||
$val['genderdata'] = $cardinfo['sex'];
|
||||
}
|
||||
}else{
|
||||
$val['birthday'] = '0000-00-00';
|
||||
$val['genderdata'] = 'male';
|
||||
}
|
||||
if(!empty($val['frameno'])){
|
||||
$check_frameno = $this->check_frameno($val['frameno']);
|
||||
if($check_frameno == false){
|
||||
unset($insert[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
//todo:分组
|
||||
if(empty($val['category_id'])){
|
||||
$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']];
|
||||
}
|
||||
//var_dump($insert);
|
||||
|
||||
$prefix = Config::get('database.prefix');
|
||||
$count = 0;
|
||||
// if ($params['update']) {
|
||||
@ -330,6 +336,7 @@ class Import extends Backend
|
||||
if ($encoding != 'utf-8') {
|
||||
$line = mb_convert_encoding($line, 'utf-8', $encoding);
|
||||
}
|
||||
//var_dump($line);
|
||||
if ($n == 0 || preg_match('/^".*"$/', $line)) {
|
||||
fwrite($fp, $line . "\n");
|
||||
} else {
|
||||
@ -455,16 +462,22 @@ class Import extends Backend
|
||||
//var_dump($val);
|
||||
//todo:处理日期格式
|
||||
if($currentColumn == 8 || $currentColumn == 15){
|
||||
if($val==''){
|
||||
$val = '0000-00-00';
|
||||
}else{
|
||||
$val = date('Y-m-d',Date::excelToTimestamp($val));
|
||||
}
|
||||
}
|
||||
//todo:身份证校验
|
||||
if($currentColumn == 3){
|
||||
if($this->isCreditNo($val) == true){
|
||||
$cardinfo = $this->checkcardid($val);
|
||||
$check_cardid = $cardinfo['iscard'];
|
||||
if($check_cardid==false){
|
||||
$val=$val.'(身份证号错误)';
|
||||
}
|
||||
}
|
||||
}
|
||||
//todo:车牌重复检测
|
||||
if($currentColumn == 10 && strlen($val) > 3){
|
||||
$check_frameno = $this->check_frameno($val);
|
||||
@ -483,6 +496,7 @@ class Import extends Backend
|
||||
|
||||
$values[] = is_null($val) ? '' : $val;
|
||||
}
|
||||
//var_dump($values);
|
||||
//exit();
|
||||
$rows = [];
|
||||
$all = [];
|
||||
|
@ -1,7 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\controller;
|
||||
|
||||
use app\admin\library\Auth;
|
||||
use think\Config;
|
||||
use think\Controller;
|
||||
@ -12,53 +10,44 @@ use think\Model;
|
||||
use think\Session;
|
||||
use fast\Tree;
|
||||
use think\Validate;
|
||||
|
||||
/**
|
||||
* 后台控制器基类
|
||||
*/
|
||||
class Backend extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* 无需登录的方法,同时也就不需要鉴权了
|
||||
* @var array
|
||||
*/
|
||||
protected $noNeedLogin = [];
|
||||
|
||||
/**
|
||||
* 无需鉴权的方法,但需要登录
|
||||
* @var array
|
||||
*/
|
||||
protected $noNeedRight = [];
|
||||
|
||||
/**
|
||||
* 布局模板
|
||||
* @var string
|
||||
*/
|
||||
protected $layout = 'default';
|
||||
|
||||
/**
|
||||
* 权限控制类
|
||||
* @var Auth
|
||||
*/
|
||||
protected $auth = null;
|
||||
|
||||
/**
|
||||
* 模型对象
|
||||
* @var \think\Model
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
/**
|
||||
* 快速搜索时执行查找的字段
|
||||
*/
|
||||
protected $searchFields = 'id';
|
||||
|
||||
/**
|
||||
* 是否是关联查询
|
||||
*/
|
||||
protected $relationSearch = false;
|
||||
|
||||
/**
|
||||
* 是否开启数据限制
|
||||
* 支持auth/personal
|
||||
@ -66,76 +55,59 @@ class Backend extends Controller
|
||||
* 默认为禁用,若启用请务必保证表中存在admin_id字段
|
||||
*/
|
||||
protected $dataLimit = false;
|
||||
|
||||
/**
|
||||
* 数据限制字段
|
||||
*/
|
||||
protected $dataLimitField = 'admin_id';
|
||||
|
||||
/**
|
||||
* 数据限制开启时自动填充限制字段值
|
||||
*/
|
||||
protected $dataLimitFieldAutoFill = true;
|
||||
|
||||
/**
|
||||
* 是否开启Validate验证
|
||||
*/
|
||||
protected $modelValidate = false;
|
||||
|
||||
/**
|
||||
* 是否开启模型场景验证
|
||||
*/
|
||||
protected $modelSceneValidate = false;
|
||||
|
||||
/**
|
||||
* Multi方法可批量修改的字段
|
||||
*/
|
||||
protected $multiFields = 'status';
|
||||
|
||||
/**
|
||||
* Selectpage可显示的字段
|
||||
*/
|
||||
protected $selectpageFields = '*';
|
||||
|
||||
/**
|
||||
* 前台提交过来,需要排除的字段数据
|
||||
*/
|
||||
protected $excludeFields = "";
|
||||
|
||||
/**
|
||||
* 导入文件首行类型
|
||||
* 支持comment/name
|
||||
* 表示注释或字段名
|
||||
*/
|
||||
protected $importHeadType = 'comment';
|
||||
|
||||
/**
|
||||
* 引入后台控制器的traits
|
||||
*/
|
||||
use \app\admin\library\traits\Backend;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
$modulename = $this->request->module();
|
||||
$controllername = Loader::parseName($this->request->controller());
|
||||
$actionname = strtolower($this->request->action());
|
||||
|
||||
$path = str_replace('.', '/', $controllername) . '/' . $actionname;
|
||||
|
||||
// 定义是否Addtabs请求
|
||||
!defined('IS_ADDTABS') && define('IS_ADDTABS', input("addtabs") ? true : false);
|
||||
|
||||
// 定义是否Dialog请求
|
||||
!defined('IS_DIALOG') && define('IS_DIALOG', input("dialog") ? true : false);
|
||||
|
||||
// 定义是否AJAX请求
|
||||
!defined('IS_AJAX') && define('IS_AJAX', $this->request->isAjax());
|
||||
|
||||
// 检测IP是否允许
|
||||
check_ip_allowed();
|
||||
|
||||
$this->auth = Auth::instance();
|
||||
|
||||
// 设置当前请求的URI
|
||||
$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') {
|
||||
$url = preg_replace_callback("/([\?|&]+)ref=addtabs(&?)/i", function ($matches) {
|
||||
@ -175,7 +146,6 @@ class Backend extends Controller
|
||||
$this->redirect('index/index', [], 302, ['referer' => $url]);
|
||||
exit;
|
||||
}
|
||||
|
||||
// 设置面包屑导航数据
|
||||
$breadcrumb = [];
|
||||
if (!IS_DIALOG && !config('fastadmin.multiplenav') && config('fastadmin.breadcrumb')) {
|
||||
@ -183,22 +153,16 @@ class Backend extends Controller
|
||||
array_pop($breadcrumb);
|
||||
}
|
||||
$this->view->breadcrumb = $breadcrumb;
|
||||
|
||||
// 如果有使用模板布局
|
||||
if ($this->layout) {
|
||||
$this->view->engine->layout('layout/' . $this->layout);
|
||||
}
|
||||
|
||||
// 语言检测
|
||||
$lang = strip_tags($this->request->langset());
|
||||
|
||||
$site = Config::get("site");
|
||||
|
||||
$upload = \app\common\model\Config::upload();
|
||||
|
||||
// 上传信息配置后
|
||||
Hook::listen("upload_config_init", $upload);
|
||||
|
||||
// 配置信息
|
||||
$config = [
|
||||
'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")
|
||||
];
|
||||
$config = array_merge($config, Config::get("view_replace_str"));
|
||||
|
||||
Config::set('upload', array_merge(Config::get('upload'), $upload));
|
||||
|
||||
// 配置信息后
|
||||
Hook::listen("config_init", $config);
|
||||
//加载当前控制器语言包
|
||||
@ -228,7 +190,6 @@ class Backend extends Controller
|
||||
//渲染管理员对象
|
||||
$this->assign('admin', Session::get('admin'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载语言文件
|
||||
* @param string $name
|
||||
@ -238,7 +199,6 @@ class Backend extends Controller
|
||||
$name = Loader::parseName($name);
|
||||
Lang::load(APP_PATH . $this->request->module() . '/lang/' . $this->request->langset() . '/' . str_replace('.', '/', $name) . '.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* 渲染配置信息
|
||||
* @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]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成查询所需要的条件,排序方式
|
||||
* @param mixed $searchfields 快速查询的字段
|
||||
@ -324,7 +283,6 @@ class Backend extends Controller
|
||||
$sym = '=';
|
||||
}
|
||||
}
|
||||
|
||||
switch ($sym) {
|
||||
case '=':
|
||||
case '<>':
|
||||
@ -430,7 +388,6 @@ class Backend extends Controller
|
||||
};
|
||||
return [$where, $sort, $order, $offset, $limit, $page, $alias, $bind];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据限制的管理员ID
|
||||
* 禁用数据限制时返回的是null
|
||||
@ -450,7 +407,6 @@ class Backend extends Controller
|
||||
}
|
||||
return $adminIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Selectpage的实现方法
|
||||
*
|
||||
@ -462,7 +418,6 @@ class Backend extends Controller
|
||||
{
|
||||
//设置过滤方法
|
||||
$this->request->filter(['trim', 'strip_tags', 'htmlspecialchars']);
|
||||
|
||||
//搜索关键词,客户端输入以空格分开,这里接收为数组
|
||||
$word = (array)$this->request->request("q_word/a");
|
||||
//当前页
|
||||
@ -495,7 +450,6 @@ class Backend extends Controller
|
||||
$order[$v[0]] = $v[1];
|
||||
}
|
||||
$field = $field ? $field : 'name';
|
||||
|
||||
//如果有primaryvalue,说明当前是初始化传值
|
||||
if ($primaryvalue !== null) {
|
||||
$where = [$primarykey => ['in', $primaryvalue]];
|
||||
@ -538,9 +492,7 @@ class Backend extends Controller
|
||||
if (is_array($adminIds)) {
|
||||
$this->model->where($this->dataLimitField, 'in', $adminIds);
|
||||
}
|
||||
|
||||
$fields = is_array($this->selectpageFields) ? $this->selectpageFields : ($this->selectpageFields && $this->selectpageFields != '*' ? explode(',', $this->selectpageFields) : []);
|
||||
|
||||
//如果有primaryvalue,说明当前是初始化传值,按照选择顺序排序
|
||||
if ($primaryvalue !== null && preg_match("/^[a-z0-9_\-]+$/i", $primarykey)) {
|
||||
$primaryvalue = array_unique(is_array($primaryvalue) ? $primaryvalue : explode(',', $primaryvalue));
|
||||
@ -548,18 +500,14 @@ class Backend extends Controller
|
||||
$primaryvalue = array_map(function ($value) {
|
||||
return '\'' . $value . '\'';
|
||||
}, $primaryvalue);
|
||||
|
||||
$primaryvalue = implode(',', $primaryvalue);
|
||||
|
||||
$this->model->orderRaw("FIELD(`{$primarykey}`, {$primaryvalue})");
|
||||
} else {
|
||||
$this->model->order($order);
|
||||
}
|
||||
|
||||
$datalist = $this->model->where($where)
|
||||
->page($page, $pagesize)
|
||||
->select();
|
||||
|
||||
foreach ($datalist as $index => $item) {
|
||||
unset($item['password'], $item['salt']);
|
||||
if ($this->selectpageFields == '*') {
|
||||
@ -588,19 +536,16 @@ class Backend extends Controller
|
||||
//这里一定要返回有list这个字段,total是可选的,如果total<=list的数量,则会隐藏分页按钮
|
||||
return json(['list' => $list, 'total' => $total]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新Token
|
||||
*/
|
||||
protected function token()
|
||||
{
|
||||
$token = $this->request->param('__token__');
|
||||
|
||||
//验证Token
|
||||
if (!Validate::make()->check(['__token__' => $token], ['__token__' => 'require|token'])) {
|
||||
$this->error(__('Token verification error'), '', ['__token__' => $this->request->token()]);
|
||||
}
|
||||
|
||||
//刷新Token
|
||||
$this->request->token();
|
||||
}
|
||||
@ -695,4 +640,38 @@ class Backend extends Controller
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user