From 1d81f37aeb98b8de485049cde669331a24eaed43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=9F=E5=87=A1=E6=87=82?= Date: Tue, 12 Jul 2022 14:54:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B1=8F=E8=94=BD=E5=AF=BC=E5=85=A5=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=97=B6=E5=90=8D=E7=A7=B0=E4=B8=BA=E4=BC=81=E4=B8=9A?= =?UTF-8?q?=E7=9A=84=E8=BA=AB=E4=BB=BD=E8=AF=81=E5=8F=B7=E7=A0=81=E7=9A=84?= =?UTF-8?q?=E6=A3=80=E6=B5=8B=E5=92=8C=E7=94=9F=E6=88=90=E7=94=9F=E6=97=A5?= =?UTF-8?q?=E6=80=A7=E5=88=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controller/user4s/Import.php | 36 +++++--- application/common/controller/Backend.php | 89 +++++++------------ 2 files changed, 59 insertions(+), 66 deletions(-) diff --git a/application/admin/controller/user4s/Import.php b/application/admin/controller/user4s/Import.php index 3349d89..429ecc9 100644 --- a/application/admin/controller/user4s/Import.php +++ b/application/admin/controller/user4s/Import.php @@ -128,12 +128,17 @@ class Import extends Backend } foreach ($insert as $key => &$val) { //处理字段 - $cardinfo = $this->checkcardid($val['cardid']); - if ($cardinfo['iscard'] == false) { - unset($insert[$key]); + if($this->isCreditNo($val['cardid']) == true){ + $cardinfo = $this->checkcardid($val['cardid']); + if ($cardinfo['iscard'] == false) { + unset($insert[$key]); + }else{ + $val['birthday'] = $cardinfo['birthday']; + $val['genderdata'] = $cardinfo['sex']; + } }else{ - $val['birthday'] = $cardinfo['birthday']; - $val['genderdata'] = $cardinfo['sex']; + $val['birthday'] = '0000-00-00'; + $val['genderdata'] = 'male'; } if(!empty($val['frameno'])){ $check_frameno = $this->check_frameno($val['frameno']); @@ -141,6 +146,7 @@ class Import extends Backend 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,14 +462,20 @@ class Import extends Backend //var_dump($val); //todo:处理日期格式 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:身份证校验 if($currentColumn == 3){ - $cardinfo = $this->checkcardid($val); - $check_cardid = $cardinfo['iscard']; - if($check_cardid==false){ - $val=$val.'(身份证号错误)'; + if($this->isCreditNo($val) == true){ + $cardinfo = $this->checkcardid($val); + $check_cardid = $cardinfo['iscard']; + if($check_cardid==false){ + $val=$val.'(身份证号错误)'; + } } } //todo:车牌重复检测 @@ -483,6 +496,7 @@ class Import extends Backend $values[] = is_null($val) ? '' : $val; } + //var_dump($values); //exit(); $rows = []; $all = []; diff --git a/application/common/controller/Backend.php b/application/common/controller/Backend.php index 26c433d..9a37fd9 100644 --- a/application/common/controller/Backend.php +++ b/application/common/controller/Backend.php @@ -1,7 +1,5 @@ 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; + } }