diff --git a/application/admin/controller/Dashboard.php b/application/admin/controller/Dashboard.php index 1edc25b..9fb5437 100644 --- a/application/admin/controller/Dashboard.php +++ b/application/admin/controller/Dashboard.php @@ -77,7 +77,9 @@ class Dashboard extends Backend 'visittime'=>['<=',Date::unixtime('day', 0,'end')] ); $visit = Visit::where($visit_where)->where('status',0)->count(); - //var_dump(Visit::getlastsql()); + //今日生日 + $birthday_users = Db::query("select count(*) as num from car_user4s_user where MONTH(birthday) = MONTH(NOW()) and DAY(birthday) = DAY(NOW())"); + //var_dump(Db::getlastsql(), $birthday_users); $index_data = [ 'totaluser' => User::count(), 'totalvipuser' => User::where('level_id','>','1')->count(), @@ -96,6 +98,7 @@ class Dashboard extends Backend // return $item['Data_length'] + $item['Index_length']; // }, $dbTableList)), // 'totalworkingaddon' => $totalworkingaddon, + 'birthday_num' => isset($birthday_users[0]['num']) ? $birthday_users[0]['num'] : 0, 'ins_end' => $ins_end, 'visit' => $visit, 'all_visit' => Visit::count(), diff --git a/application/admin/controller/import/Log.php b/application/admin/controller/import/Log.php index 64e3fac..2387404 100644 --- a/application/admin/controller/import/Log.php +++ b/application/admin/controller/import/Log.php @@ -9,6 +9,7 @@ use PhpOffice\PhpSpreadsheet\Cell\Coordinate; use PhpOffice\PhpSpreadsheet\Reader\Xlsx; use PhpOffice\PhpSpreadsheet\Reader\Xls; use PhpOffice\PhpSpreadsheet\Reader\Csv; +use PhpOffice\PhpSpreadsheet\Shared\Date; use think\Exception; use think\exception\PDOException; use think\exception\ValidateException; @@ -81,7 +82,7 @@ class Log extends Backend * 添加 */ public function add() - { + { if ($this->request->isPost()) { $params = $this->request->post("row/a"); $step = $params['step']; @@ -99,18 +100,13 @@ class Log extends Backend $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate; $this->model->validateFailException(true)->validate($validate); } - //新建表导入处理 - if ($params['newtable']) { - $prefix = Config::get('database.prefix'); - $table = $prefix . $params['newtable']; - $check = db()->query("SHOW TABLES LIKE '%{$table}%';"); - if ($check) { - $this->error(__($params['newtable'] . '表已经存在')); - } - } else { - if (!$params['table']) $this->error('未选择目标表'); - } + $prefix = Config::get('database.prefix'); + //导入文件首行类型,默认是注释,如果需要使用字段名称请使用name + $importHeadType = 'comment';//name + $table = $prefix.'user4s_user'; + $params['newtable'] = false; + $params['table'] = $table; $fileData = $this->fileData($params); @@ -130,52 +126,41 @@ class Log extends Backend } } if ($has_admin_id) { - foreach ($insert as &$val) { + foreach ($insert as $key => &$val) { if (!isset($val['admin_id']) || empty($val['admin_id'])) { $val['admin_id'] = $this->auth->isLogin() ? $this->auth->id : 0; } } } + foreach ($insert as $key => &$val) { + //处理字段 + $cardinfo = $this->checkcardid($val['cardid']); + if ($cardinfo['iscard'] == false) { + unset($insert[$key]); + }else{ + $val['birthday'] = $cardinfo['birthday']; + $val['genderdata'] = $cardinfo['sex']; + } + if(empty($val['frameno'])){ + unset($insert[$key]); + }else{ + $check_frameno = $this->check_frameno($val['frameno']); + if($check_frameno == false){ + unset($insert[$key]); + } + } + } + var_dump($insert);exit(); $prefix = Config::get('database.prefix'); $count = 0; if ($params['update']) { foreach ($insert as &$val) { - $count += Db::name(str_replace($prefix, "", $params['table'])) + $count += Db::name('user4s_user') ->where($params['update'], $val['pid']) ->update($val); } } else { - if ($params['to']) { - $file = db('attachment')->where('url', $fileData['path'])->find(); - $this->fieldModel = new \app\admin\model\salary\Field; - $fields = $this->fieldModel->where('name', 'not in', ['pid', 'name', 'status', 'create_time', 'update_time', 'deletetime'])->select(); - $toData = []; - // dump($fields); - $insertData = []; - foreach ($insert as $key => $val) { - foreach ($fields as $ke => $field) { - if (isset($val[$field['name']])) { - $toData[$ke]['pid'] = $val['pid']; - $toData[$ke]['name'] = $val['name']; - $toData[$ke]['type'] = $field['name']; - $toData[$ke]['type_name'] = $field['desc']; - $toData[$ke]['field_type'] = $field['type']; - $toData[$ke]['je'] = $val[$field['name']]; - $toData[$ke]['filename'] = $file['filename']; - $toData[$ke]['sha1'] = $file['sha1']; - $toData[$ke]['createtime'] = time(); - } - } - if ($insertData) $insertData = array_merge($insertData, $toData); - else $insertData = $toData; - } - // dump($insertData); - // exit; - Db::name(str_replace($prefix, "", $params['to']))->where('sha1', $file['sha1'])->delete(); - $res = Db::name(str_replace($prefix, "", $params['to']))->insertAll($insertData); - } else { - $res = Db::name(str_replace($prefix, "", $params['table']))->insertAll($insert); - } + $res = Db::name('user4s_user')->insertAll($insert); $count = count($insert); } @@ -283,11 +268,23 @@ class Log extends Backend } } - + public function check_frameno($frameno) + { + if(empty($frameno)){ + return false; + } + $user = new \app\common\model\user4s\User; + $has_frameno = $user->where(['frameno' =>$frameno])->find(); + if (empty($has_frameno->id)) { + return true; + }else{ + return false; + } + } protected function fileData($params) { $file = $path = $params['path']; - $row = $params['row']; + $row = 2; $sheet = 0; if (!$file) { $this->error(__('Parameter %s can not be empty', 'file')); @@ -330,8 +327,9 @@ class Log extends Backend $prefix = Config::get('database.prefix'); //导入文件首行类型,默认是注释,如果需要使用字段名称请使用name - $importHeadType = $params['head_type']; - $table = $params['table']; + $importHeadType = 'comment';//name + $table = $prefix.'user4s_user'; + $params['newtable'] = false; $database = \think\Config::get('database.database'); $fieldArr = []; $notnull = []; @@ -342,6 +340,7 @@ class Log extends Backend "SELECT COLUMN_NAME,COLUMN_COMMENT,COLUMN_TYPE,IS_NULLABLE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = ? AND TABLE_SCHEMA = ?", [$table, $database] ); + //var_dump($list,$table, $database); foreach ($list as $k => $v) { if ($v['COLUMN_NAME'] !== $pk) { if ($importHeadType == 'comment') { @@ -373,10 +372,12 @@ class Log extends Backend } $currentSheet = $PHPExcel->getSheet($sheet); //读取文件中的第一个工作表 $allColumn = $currentSheet->getHighestDataColumn(); //取得最大的列号 + $allColumn = 'O'; //todo:取得最大的列号 + //var_dump($allColumn); $allRow = $currentSheet->getHighestRow(); //取得一共有多少行 $maxColumnNumber = Coordinate::columnIndexFromString($allColumn); $fields = []; - + //todo:处理表头第一行 for ($currentRow = 1; $currentRow <= 1; $currentRow++) { for ($currentColumn = 1; $currentColumn <= $maxColumnNumber; $currentColumn++) { $val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue(); @@ -388,6 +389,34 @@ class Log extends Backend 'field' => $val, 'fieldName' => isset($fieldArr[$val]) ? $fieldArr[$val]['COLUMN_NAME'] : '--' //Pinyin::get($val), ); + + //手动加入表头字段 + // if($val == '身份证' && $currentColumn == 3){ + // $val = '性别'; + // $fields[] = $val; + // $col[] = array( + // 'title' => $val, + // 'class' => isset($fieldArr[$val]) ? 'success' : '-', + // 'type' => isset($fieldArr[$val]) ? $fieldArr[$val]['COLUMN_TYPE'] : '--', + // 'field' => $val, + // 'fieldName' => isset($fieldArr[$val]) ? $fieldArr[$val]['COLUMN_NAME'] : '--' //Pinyin::get($val), + // ); + // $val = '生日'; + // $fields[] = $val; + // $col[] = array( + // 'title' => $val, + // 'class' => isset($fieldArr[$val]) ? 'success' : '-', + // 'type' => isset($fieldArr[$val]) ? $fieldArr[$val]['COLUMN_TYPE'] : '--', + // 'field' => $val, + // 'fieldName' => isset($fieldArr[$val]) ? $fieldArr[$val]['COLUMN_NAME'] : '--' //Pinyin::get($val), + // ); + // //var_dump($col);exit(); + // $count += 2; + // } + // if($currentColumn == $maxColumnNumber){ + // $fields[] = '身份证校验'; + // $fields[] = '车架号校验'; + // } if (isset($fieldArr[$val])) { $count += 1; } @@ -395,14 +424,35 @@ class Log extends Backend } for ($currentRow = $row; $currentRow <= $allRow; $currentRow++) { $values = []; + // $check_cardid = true; + // $check_frameno = true; for ($currentColumn = 1; $currentColumn <= $maxColumnNumber; $currentColumn++) { + //var_dump($currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)); $val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue(); + //todo:处理日期格式 + if($currentColumn == 8 || $currentColumn == 15){ + $val = date('Y-m-d',Date::excelToTimestamp($val)); + } + $values[] = is_null($val) ? '' : $val; + //todo:手工处理自定义字段 + // if($currentColumn == 3){ + // $cardinfo = $this->checkcardid($val); + // $check_cardid = $cardinfo['iscard']; + // $values[] = $cardinfo['sex'] == 'female' ?'女':'男'; + // $values[] = $cardinfo['birthday']; + // } + // if($currentColumn == 10){ + // $check_frameno = $this->check_frameno($val); + // } + // if($currentColumn == $maxColumnNumber){ + // $values[] = $check_cardid?'成功':'失败'; + // $values[] = $check_frameno?'成功':'失败'; + // } } $rows = []; $all = []; $temp = array_combine($fields, $values); - foreach ($temp as $k => $v) { if (isset($fieldArr[$k]) && $k !== '') { $rows[$fieldArr[$k]['COLUMN_NAME']] = $v; @@ -415,6 +465,7 @@ class Log extends Backend } $allData[] = $all; } + return array( 'path' => $path, 'field' => $col, diff --git a/application/admin/controller/user4s/User.php b/application/admin/controller/user4s/User.php index e5cd421..00ae73d 100644 --- a/application/admin/controller/user4s/User.php +++ b/application/admin/controller/user4s/User.php @@ -12,6 +12,13 @@ use think\Db; use think\exception\PDOException; use think\exception\ValidateException; +use think\Config; +use PhpOffice\PhpSpreadsheet\Cell\Coordinate; +use PhpOffice\PhpSpreadsheet\Reader\Xlsx; +use PhpOffice\PhpSpreadsheet\Reader\Xls; +use PhpOffice\PhpSpreadsheet\Reader\Csv; +use fast\Pinyin; + /** * 用户档案 * @@ -99,7 +106,7 @@ class User extends Backend $this->request->filter(['strip_tags', 'trim']); if ($this->request->isAjax()) { $id = $this->request->param('id'); - if(empty($id)){ + if (empty($id)) { $result = array("code" => 1, "msg" => '用户ID为空'); return json($result); }; @@ -107,7 +114,7 @@ class User extends Backend if (!$row) { $result = array("code" => 1, "msg" => __('No Results were found')); return json($result); - }else{ + } else { //$row->getRelation('category')->visible(['name']); //$row->getRelation('level')->visible(['name']); $result = array("code" => 0, "msg" => 'success', "data" => $row); @@ -139,16 +146,29 @@ class User extends Backend $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate; $this->model->validateFailException(true)->validate($validate); } + $cardinfo = $this->checkcardid($params['cardid']); + if ($cardinfo['iscard'] == false) { + $this->model->rollback(); + $this->error('身份证号错误'); + } else { + $params['birthday'] = $cardinfo['birthday']; + $params['genderdata'] = $cardinfo['sex']; + } + $has_frameno = $this->model->get(['frameno', $params['frameno']]); + if (!empty($has_frameno->id)) { + $this->model->rollback(); + $this->error('车架号重复'); + } $result = $this->model->allowField(true)->save($params); //var_dump($params['need_visit']); //新加用户期初等级 - if($result && $this->model->id){ - if($params['need_visit'] == 1){ - $log_res = $this->model->afterlog($this->auth->id,$this->model,$this->model->id,'',true); - }else{ - $log_res = $this->model->afterlog($this->auth->id,$this->model,$this->model->id,'',false); + if ($result && $this->model->id) { + if ($params['need_visit'] == 1) { + $log_res = $this->model->afterlog($this->auth->id, $this->model, $this->model->id, '', true); + } else { + $log_res = $this->model->afterlog($this->auth->id, $this->model, $this->model->id, '', false); } - if(!$log_res){ + if (!$log_res) { $this->model->rollback(); $this->error('新增失败'); } @@ -197,8 +217,82 @@ class User extends Backend if ($this->request->isPost()) { $params = $this->request->post("row/a"); + if ($params) { + $params = $this->preExcludeFields($params); + $result = false; + $this->model->startTrans(); + try { + //是否采用模型验证 + if ($this->modelValidate) { + $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); + $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate; + $row->validateFailException(true)->validate($validate); + } + $cardinfo = $this->checkcardid($params['cardid']); + if ($cardinfo['iscard'] == false) { + $this->model->rollback(); + $this->error('身份证号错误'); + } else { + $params['birthday'] = $cardinfo['birthday']; + $params['genderdata'] = $cardinfo['sex']; + } + $has_frameno = $this->model->get(['frameno', $params['frameno']]); + if (!empty($has_frameno->id)) { + $this->model->rollback(); + $this->error('车架号重复'); + } + $result = $this->model->allowField(true)->save($params); + $result = $row->allowField(true)->save($params); + $this->model->commit(); + } catch (ValidateException $e) { + $this->model->rollback(); + $this->error($e->getMessage()); + } catch (PDOException $e) { + $this->model->rollback(); + $this->error($e->getMessage()); + } catch (Exception $e) { + $this->model->rollback(); + $this->error($e->getMessage()); + } + if ($result !== false) { + $this->success(); + } else { + $this->error(__('No rows were updated')); + } + } + $this->error(__('Parameter %s can not be empty', '')); } - return parent::edit($ids); + $this->view->assign("row", $row); + return $this->view->fetch(); + } + public function check_cardid() + { + if ($this->request->isPost()) { + $params = $this->request->post("row/a"); + if ($params) { + $cardinfo = $this->checkcardid($params['cardid']); + if ($cardinfo['iscard']) { + $this->success('身份证号正确'); + } + } + $this->error('身份证号错误'); + } + $this->error('获取数据错误'); + } + public function check_frameno() + { + if ($this->request->isPost()) { + $params = $this->request->post("row/a"); + if ($params) { + $has_frameno = $this->model->where(['frameno' => $params['frameno']])->find(); + //var_dump($has_frameno); + if (empty($has_frameno->id)) { + $this->success('车架号正确'); + } + } + $this->error('车架号重复'); + } + $this->error('车架号重复'); } /** * 删除 @@ -274,7 +368,7 @@ class User extends Backend //记录用户充值、积分、等级记录 $log_data = array( 'user4s_id' => $row->id, - 'admin_id'=>$this->auth->id + 'admin_id' => $this->auth->id ); //余额充值 if ($params['balance'] > 0) { @@ -296,10 +390,10 @@ class User extends Backend $log_data['start'] = $row->integral; $log_data['end'] = $end; $log_data['state'] = 1; - if($now > 0){ - $log_data['description'] = $params['description'].' 赠送积分:'.$now; - }else{ - $log_data['description'] = $params['description'].' 系统后台扣除积分'.$now; + if ($now > 0) { + $log_data['description'] = $params['description'] . ' 赠送积分:' . $now; + } else { + $log_data['description'] = $params['description'] . ' 系统后台扣除积分' . $now; } $this->log_model = new \app\common\model\user4s\Log(); $this->log_model->isUpdate(false)->save($log_data); @@ -312,12 +406,12 @@ class User extends Backend $log_data['start'] = $row->level_id; $log_data['end'] = $end; - $log_data['description'] = '会员等级变动,由 '.$all_level[$row->level_id].' 更改为:'.$all_level[$end]; + $log_data['description'] = '会员等级变动,由 ' . $all_level[$row->level_id] . ' 更改为:' . $all_level[$end]; //var_dump($log_data); $this->levellog_model->isUpdate(false)->save($log_data); $user_data['level_id'] = $end; } - if(isset($user_data['balance']) || isset($user_data['integral']) || isset($user_data['level_id'])){ + if (isset($user_data['balance']) || isset($user_data['integral']) || isset($user_data['level_id'])) { //var_dump($user_data); //$this->model->get($row->id); $this->model->save($user_data, ['id' => $row->id]); @@ -338,17 +432,28 @@ class User extends Backend $this->relationSearch = true; //设置过滤方法 $this->request->filter(['strip_tags', 'trim']); + $start_date = strtotime("-1 year"); - $end_date = strtotime("+2 month",$start_date); + $end_date = strtotime("+2 month", $start_date); $ins_where = array( - 'insdate'=>['between',[date('Y-m-d',$start_date),date('Y-m-d',$end_date)]] + 'insdate' => ['between', [date('Y-m-d', $start_date), date('Y-m-d', $end_date)]] ); + if ($this->request->isAjax()) { list($where, $sort, $order, $offset, $limit) = $this->buildparams(); $list = $this->model ->with(['category', 'level']) ->where($where) - ->where($ins_where) + ->where(function ($query) { + for ($y=1; $y<=20; $y++) { + $start_date = strtotime("-".$y." year"); + $end_date = strtotime("+2 month", $start_date); + $ins_where = array( + 'insdate' => ['between', [date('Y-m-d', $start_date), date('Y-m-d', $end_date)]] + ); + $query->whereOr($ins_where); + } + }) ->order($sort, $order) ->paginate($limit); //var_dump($this->model->getLastSql()); @@ -357,7 +462,7 @@ class User extends Backend $row->getRelation('level')->visible(['name']); } - $result = array("total" => $list->total(), "rows" => $list->items(),"extend" => ['start_date' => date('Y-m-d',$start_date), 'end_date' => date('Y-m-d',$end_date)]); + $result = array("total" => $list->total(), "rows" => $list->items(), "extend" => ['start_date' => date('m-d', $start_date), 'end_date' => date('m-d', $end_date)]); return json($result); } @@ -390,31 +495,33 @@ class User extends Backend if (!empty($params['inscom']) && !empty($params['insdate'])) { $log_data = array( 'user4s_id' => $row->id, - 'admin_id'=>$this->auth->id, - 'inscom'=>$params['inscom'], - 'insdate'=>$params['insdate'], - 'star'=>$params['star'], - 'description'=>$params['description'] + 'admin_id' => $this->auth->id, + 'instype' => $params['instype'], + 'inscom' => $params['inscom'], + 'insdate' => $params['insdate'], + 'star' => $params['star'], + 'description' => $params['description'] ); $this->Inslog_model = new \app\common\model\user4s\Inslog(); $this->Inslog_model->isUpdate(false)->save($log_data); $user_data = array( - 'inscom'=>$params['inscom'], - 'insdate'=>$params['insdate'], + 'instype' => $params['instype'], + 'inscom' => $params['inscom'], + 'insdate' => $params['insdate'], ); $this->model->save($user_data, ['id' => $row->id]); - }else{ - $this->error('请填写续保信息',url('user4s/user/expireins',['user4s_id'=>$row->id])); + } else { + $this->error('请填写续保信息', url('user4s/user/expireins', ['user4s_id' => $row->id])); } - $this->success('续保成功!',url('user4s/user/expireins',['user4s_id'=>$row->id])); + $this->success('续保成功!', url('user4s/user/expireins', ['user4s_id' => $row->id])); } //var_dump($col); $all_star = array( - 1=>'★', - 2=>'★★', - 3=>'★★★', - 4=>'★★★★', - 5=>'★★★★★', + 1 => '★', + 2 => '★★', + 3 => '★★★', + 4 => '★★★★', + 5 => '★★★★★', ); $this->view->assign("now", date('Y-m-d')); $this->view->assign("all_star", $all_star); @@ -422,4 +529,177 @@ class User extends Backend return $this->view->fetch(); } + /** + * 过生日用户列表 + */ + public function birthday() + { + //当前是否为关联查询 + $this->relationSearch = true; + //设置过滤方法 + $this->request->filter(['strip_tags', 'trim']); + + if ($this->request->isAjax()) { + $birthday_users = Db::query("select id from car_user4s_user where MONTH(birthday) = MONTH(NOW()) and DAY(birthday) = DAY(NOW())"); + if(empty($birthday_users)){ + $result = array("total" => 0, "rows" => [], "extend" => ['start_date' => date('m-d')]); + return json($result); + }else{ + foreach ($birthday_users as $key => $value) { + $birthday_user_ids[] = $value['id']; + } + } + if(empty($birthday_user_ids)){ + $result = array("total" => 0, "rows" => [], "extend" => ['start_date' => date('m-d')]); + return json($result); + } + //var_dump($birthday_user_ids); + list($where, $sort, $order, $offset, $limit) = $this->buildparams(); + $list = $this->model + ->with(['category', 'level']) + ->where($where) + ->where('user.id', 'in', $birthday_user_ids) + ->order($sort, $order) + ->paginate($limit); + //var_dump($this->model->getLastSql()); + foreach ($list as $row) { + $row->getRelation('category')->visible(['name']); + $row->getRelation('level')->visible(['name']); + } + + $result = array("total" => $list->total(), "rows" => $list->items(), "extend" => ['start_date' => date('m-d')]); + return json($result); + } + return $this->view->fetch(); + } + /** + * 导入数据界面 + */ + public function excel() + { + if ($this->request->isPost()) { + $params = $this->request->post("row/a"); + $step = $params['step']; + if ($params) { + $params = $this->preExcludeFields($params); + if ($this->dataLimit && $this->dataLimitFieldAutoFill) { + $params[$this->dataLimitField] = $this->auth->id; + } + $result = false; + Db::startTrans(); + try { + //是否采用模型验证 + if ($this->modelValidate) { + $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); + $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate; + $this->model->validateFailException(true)->validate($validate); + } + //新建表导入处理 + if ($params['newtable']) { + $prefix = Config::get('database.prefix'); + $table = $prefix . $params['newtable']; + $check = db()->query("SHOW TABLES LIKE '%{$table}%';"); + if ($check) { + $this->error(__($params['newtable'] . '表已经存在')); + } + } else { + if (!$params['table']) $this->error('未选择目标表'); + } + + $fileData = $this->fileData($params); + + + $fileData['params'] = http_build_query($params); + $fileData['newtable'] = $params['newtable']; + if (!$step) { + $this->success('匹配到' . $fileData['count'] . '列,开始预览', '', $fileData); + } + $insert = $fileData['insert']; + $fieldArr = $fileData['fieldArr']; + //是否包含admin_id字段 + $has_admin_id = false; + foreach ($fieldArr as $name => $key) { + if ($key == 'admin_id') { + $has_admin_id = true; + break; + } + } + if ($has_admin_id) { + foreach ($insert as &$val) { + if (!isset($val['admin_id']) || empty($val['admin_id'])) { + $val['admin_id'] = $this->auth->isLogin() ? $this->auth->id : 0; + } + } + } + $prefix = Config::get('database.prefix'); + $count = 0; + if ($params['update']) { + foreach ($insert as &$val) { + $count += Db::name(str_replace($prefix, "", $params['table'])) + ->where($params['update'], $val['pid']) + ->update($val); + } + } else { + if ($params['to']) { + $file = db('attachment')->where('url', $fileData['path'])->find(); + $this->fieldModel = new \app\admin\model\salary\Field; + $fields = $this->fieldModel->where('name', 'not in', ['pid', 'name', 'status', 'create_time', 'update_time', 'deletetime'])->select(); + $toData = []; + // dump($fields); + $insertData = []; + foreach ($insert as $key => $val) { + foreach ($fields as $ke => $field) { + if (isset($val[$field['name']])) { + $toData[$ke]['pid'] = $val['pid']; + $toData[$ke]['name'] = $val['name']; + $toData[$ke]['type'] = $field['name']; + $toData[$ke]['type_name'] = $field['desc']; + $toData[$ke]['field_type'] = $field['type']; + $toData[$ke]['je'] = $val[$field['name']]; + $toData[$ke]['filename'] = $file['filename']; + $toData[$ke]['sha1'] = $file['sha1']; + $toData[$ke]['createtime'] = time(); + } + } + if ($insertData) $insertData = array_merge($insertData, $toData); + else $insertData = $toData; + } + // dump($insertData); + // exit; + Db::name(str_replace($prefix, "", $params['to']))->where('sha1', $file['sha1'])->delete(); + $res = Db::name(str_replace($prefix, "", $params['to']))->insertAll($insertData); + } else { + $res = Db::name(str_replace($prefix, "", $params['table']))->insertAll($insert); + } + $count = count($insert); + } + + + Db::commit(); + } catch (ValidateException $e) { + Db::rollback(); + $this->error($e->getMessage()); + } catch (PDOException $e) { + Db::rollback(); + $this->error($e->getMessage()); + } catch (Exception $e) { + Db::rollback(); + $this->error($e->getMessage()); + } + if ($count !== false) { + $params['status'] = 'normal'; + $result = $this->model->allowField(true)->save($params); + $tip = $params['update'] ? '成功更新' : '成功新增'; + $this->success($tip . $count . '条记录', '', array('count' => $count)); + } else { + $this->error(__('No rows were inserted')); + } + } + + $this->error(__('Parameter %s can not be empty', '')); + } + $this->view->assign("update", $this->request->request('update')); + $this->view->assign("to", $this->request->request('to')); + return $this->view->fetch(); + } } diff --git a/application/admin/lang/zh-cn/user4s/inslog.php b/application/admin/lang/zh-cn/user4s/inslog.php index f170366..8ef1952 100644 --- a/application/admin/lang/zh-cn/user4s/inslog.php +++ b/application/admin/lang/zh-cn/user4s/inslog.php @@ -4,8 +4,9 @@ return [ 'Id' => 'ID', 'User4s_id' => '会员', 'Admin_id' => '操作员', - 'Inscom' => '保险类型', - 'Insdate' => '保险日期', + 'Instype' => '保险类型', + 'Inscom' => '保险公司', + 'Insdate' => '保险日期', 'Description' => '备注', 'Star' => '满意度', 'Createtime' => '创建时间', diff --git a/application/admin/lang/zh-cn/user4s/user.php b/application/admin/lang/zh-cn/user4s/user.php index f3b11fb..9b4b343 100644 --- a/application/admin/lang/zh-cn/user4s/user.php +++ b/application/admin/lang/zh-cn/user4s/user.php @@ -16,7 +16,10 @@ return [ 'Carno' => '车牌号码', 'Model' => '车型', 'Color' => '颜色', - 'Inscom' => '保险类型', + 'Cardid' => '身份证号', + 'Frameno' => '车架号', + 'Instype' => '保险类型', + 'Inscom' => '保险公司', 'Insdate' => '保险日期', 'Tags' => '标签', 'Description' => '备注', diff --git a/application/admin/view/dashboard/index.html b/application/admin/view/dashboard/index.html index e35f643..7a0df48 100644 --- a/application/admin/view/dashboard/index.html +++ b/application/admin/view/dashboard/index.html @@ -196,19 +196,19 @@
- - + +
- {$all_visit} - {:__('全部回访单')} + {$birthday_num} + {:__('生日提醒')}
- - + +
{$sumprice|round=###,2} {:__('充值总金额')} diff --git a/application/admin/view/import/log/add.html b/application/admin/view/import/log/add.html index 59dfae3..ff8cae4 100644 --- a/application/admin/view/import/log/add.html +++ b/application/admin/view/import/log/add.html @@ -1,35 +1,14 @@
- +
-
导入参数
+
导入客户档案
-
-
- -
- {empty name="table"} {:Form::select('row[table]', $tableList, $table, [])} - - {else /} - {$table} {/empty} -
-
-
-
+ + -
- -
- {:Form::select('row[head_type]', ['comment'=>'注释', 'name'=>'字段名'], 'comment', ['data-rule'=>'required'])} - -
-
- -
-
+
@@ -61,17 +30,6 @@
- - - -
diff --git a/application/admin/view/user4s/user/add.html b/application/admin/view/user4s/user/add.html index 9f2767b..ce0de39 100644 --- a/application/admin/view/user4s/user/add.html +++ b/application/admin/view/user4s/user/add.html @@ -14,15 +14,9 @@
- +
- -
- {foreach name="genderdataList" item="vo"} - - {/foreach} -
- +
@@ -31,6 +25,12 @@
+
+ +
+ +
+
@@ -43,12 +43,7 @@
- +
@@ -80,16 +75,22 @@
- +
+
+ +
+ +
+
- +
diff --git a/application/admin/view/user4s/user/edit.html b/application/admin/view/user4s/user/edit.html index 7d2972e..f27f851 100644 --- a/application/admin/view/user4s/user/edit.html +++ b/application/admin/view/user4s/user/edit.html @@ -14,54 +14,33 @@
- +
- -
- {foreach name="genderdataList" item="vo"} - - {/foreach} -
- +
+
- -
-
- +
+ -
- +
@@ -82,15 +61,21 @@
- +
- + +
+
+
+ +
+
- +
{:__('Recycle bin')}
diff --git a/application/admin/view/user4s/user/renewal.html b/application/admin/view/user4s/user/renewal.html index 3149620..27e91b8 100644 --- a/application/admin/view/user4s/user/renewal.html +++ b/application/admin/view/user4s/user/renewal.html @@ -17,11 +17,17 @@
- +
+
+ +
+ +
+
@@ -37,24 +43,30 @@
- +
+
+ +
+ +
+
- +
- 本次续保的保险开始时间,方便下次提醒。 + 本次续保的保险开始日期,下次将从本日期的下一年的当月当日开始提醒。
diff --git a/application/common/controller/Backend.php b/application/common/controller/Backend.php index e923fab..b50651b 100644 --- a/application/common/controller/Backend.php +++ b/application/common/controller/Backend.php @@ -604,4 +604,97 @@ class Backend extends Controller //刷新Token $this->request->token(); } + /** + * 根据身份证号获取信息 + * @param $idcard 18位身份证号码 + * @return string birthday 出生日期,格式:yyyy-mm-dd + * @return bool iscard 是否为合法的身份证号码 + * @return int flag 0标示成年,1标示未成年 + * @return int age 年龄 + */ + public function checkcardid($IDCard) + { + $result['iscard'] = false; + $result['flag'] = ''; //0标示成年,1标示未成年 + $result['tdate'] = ''; //生日,格式如:2012-11-15 + if(empty($IDCard)){ + $result['iscard'] = false; + return $result; + } + if ($this->isIDCard($IDCard) == false) { + $result['iscard'] = false; + return $result; + } + if (!preg_match("/^(\\d{15}$|^\\d{18}$|^\\d{17}(\\d|X|x))$/", $IDCard)) { + $result['iscard'] = false; + return $result; + } else { + $tyear = intval(substr($IDCard, 6, 4)); + $tmonth = intval(substr($IDCard, 10, 2)); + $tday = intval(substr($IDCard, 12, 2)); + if ($tyear > date("Y") || $tyear < (date("Y") - 100)) { + $flag = 0; + } elseif ($tmonth < 0 || $tmonth > 12) { + $flag = 0; + } elseif ($tday < 0 || $tday > 31) { + $flag = 0; + } else { + $tdate = $tyear . "-" . $tmonth . "-" . $tday; + if ((time() - mktime(0, 0, 0, $tmonth, $tday, $tyear)) > 18 * 365 * 24 * 60 * 60) { + $flag = 0; + } else { + $flag = 1; + } + } + } + $sexint = (int) substr($IDCard, 16, 1); + if (empty($IDCard)) return null; + # 获得出生年月日的时间戳 + $date = strtotime(substr($IDCard, 6, 8)); + # 获得今日的时间戳 + $today = strtotime('today'); + # 得到两个日期相差的大体年数 + $diff = floor(($today - $date) / 86400 / 365); + # strtotime加上这个年数后得到那日的时间戳后与今日的时间戳相比 + $age = strtotime(substr($IDCard, 6, 8) . ' +' . $diff . 'years') > $today ? ($diff + 1) : $diff; + $result['age'] = $age; + $result['iscard'] = true; //0:未知错误,1:身份证格式错误,2:无错误 + $result['isAdult'] = $flag; //0标示成年,1标示未成年 + $result['birthday'] = $tdate; //生日日期 + $result['sex'] = $sexint % 2 === 0 ? 'female' : 'male'; //male=男,female=女 + return $result; + } + /** + * 判断字符串是否是身份证号 + */ + public function isIDCard($IDCard) + { + if(empty($IDCard)){ + return false; + } + # 转化为大写,如出现x + $IDCard = strtoupper($IDCard); + # 加权因子 + $wi = array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2); + $ai = array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'); + # 按顺序循环处理前17位 + $sigma = 0; + # 提取前17位的其中一位,并将变量类型转为实数 + for ($i = 0; $i < 17; $i++) { + $b = (int)$IDCard{$i}; + # 提取相应的加权因子 + $w = $wi[$i]; + # 把从身份证号码中提取的一位数字和加权因子相乘,并累加 + $sigma += $b * $w; + } + # 计算序号 + $sIDCard = $sigma % 11; + # 按照序号从校验码串中提取相应的字符。 + $check_IDCard = $ai[$sIDCard]; + if ($IDCard{17} == $check_IDCard) { + return true; + } else { + return false; + } + } } diff --git a/public/assets/js/backend/dashboard.js b/public/assets/js/backend/dashboard.js index 9e06365..b2a6620 100644 --- a/public/assets/js/backend/dashboard.js +++ b/public/assets/js/backend/dashboard.js @@ -74,6 +74,11 @@ define(['jquery', 'bootstrap', 'backend', 'addtabs', 'table', 'echarts', 'echart 'user4s/visit?status=0': [Config.index_data.visit, 'red', 'badge'] }); } + if (Config.index_data.birthday_num > 0) { + top.window.Backend.api.sidebar({ + 'user4s/user/birthday': [Config.index_data.birthday_num, 'orange', 'badge'] + }); + } // if (Config.index_data.all_visit > 0) { // top.window.Backend.api.sidebar({ // 'user4s/visit': [Config.index_data.all_visit, 'teal', 'label'] diff --git a/public/assets/js/backend/import/log.js b/public/assets/js/backend/import/log.js index d9ca11a..c60f5cf 100644 --- a/public/assets/js/backend/import/log.js +++ b/public/assets/js/backend/import/log.js @@ -92,7 +92,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'editable'], function $("#import").addClass("disabled"); // $("#createtable").hide(); // $("#updatetable").hide(); - if ($("#c-row").val() && $("#selecthead_type select").val() && $("#selectable select").val() && $("#c-rowpath").val()) { + if ($("#c-row").val() && $("#c-rowpath").val()) { Toastr.success('开始预览结果'); // $("#submit").trigger("click"); @@ -121,10 +121,10 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'editable'], function }); html += "" html += "" - $.each(columns, function(i, item) { - if (item.class != "success") html += "" - else html += "" - }); + // $.each(columns, function(i, item) { + // if (item.class != "success") html += "" + // else html += "" + // }); html += "" $.each(xlsdata, function(i, item) { html += "" @@ -144,14 +144,14 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'editable'], function } } - $("#selectable select").on("change", function() { - $("#c-newtable").val('') - reset() - }) - $("#c-newtable").on("change", function() { - $("#selectable select").val(""); - reset() - }) + // $("#selectable select").on("change", function() { + // $("#c-newtable").val('') + // reset() + // }) + // $("#c-newtable").on("change", function() { + // $("#selectable select").val(""); + // reset() + // }) $("#c-row").on("change", function() { reset() }) diff --git a/public/assets/js/backend/user4s/inslog.js b/public/assets/js/backend/user4s/inslog.js index 19323ae..3e457a3 100644 --- a/public/assets/js/backend/user4s/inslog.js +++ b/public/assets/js/backend/user4s/inslog.js @@ -33,15 +33,17 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'editable'], function //{field: 'user4s_id', title: __('User4s_id'),operate: false}, //{field: 'admin_id', title: __('Admin_id'),operate: false}, {field: 'user.name', title: __('会员姓名'), operate: 'LIKE'}, - {field: 'user.name', title: __('会员电话'), operate: 'LIKE',visible: false}, - {field: 'inscom', title: __('Inscom'), operate: 'LIKE',editable:true}, + { field: 'user.name', title: __('会员电话'), operate: 'LIKE', visible: false }, + + { field: 'inscom', title: __('Inscom'), operate: 'LIKE', editable: true }, + {field: 'instype', title: __('Instype'), operate: 'LIKE',editable:true}, { field: 'insdate', title: __('Insdate'), operate: 'BETWEEN', addclass: 'datetimepicker',data: 'data-date-format="YYYY-MM-DD",data-date-use-current="true"', autocomplete: false }, {field: 'description', title: __('Description'), operate: 'LIKE',editable:true}, {field: 'star_f', title: __('Star'),operate:false}, - { field: 'createtime_f', title: __('Createtime'), operate: false }, - {field: 'createtime', title: __('Createtime'),datetimeFormat:'YYYY-MM-DD', operate: 'BETWEEN', addclass: 'datetimepicker',data: 'data-date-format="YYYY-MM-DD",data-date-use-current="true"', autocomplete: false,visible: false}, + { field: 'createtime_f', title: __('续保时间'), operate: false }, + {field: 'createtime', title: __('续保时间'),datetimeFormat:'YYYY-MM-DD', operate: 'BETWEEN', addclass: 'datetimepicker',data: 'data-date-format="YYYY-MM-DD",data-date-use-current="true"', autocomplete: false,visible: false}, {field: 'admin.id', title: __('Admin.id'),operate: false,visible: false}, - {field: 'admin.username', title: __('操作员'), operate: false}, + {field: 'admin.nickname', title: __('操作员'), operate: false}, {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate} diff --git a/public/assets/js/backend/user4s/user.js b/public/assets/js/backend/user4s/user.js index 47faf3f..09c28a7 100644 --- a/public/assets/js/backend/user4s/user.js +++ b/public/assets/js/backend/user4s/user.js @@ -58,7 +58,8 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'editable'], function {field: 'id', title: __('会员ID'), operate:false}, { field: 'name', title: __('Name'), operate: 'LIKE',editable:true }, { field: 'tel', title: __('Tel'), operate: 'LIKE' ,editable:true}, - { field: 'genderdata', title: __('Genderdata'), operate: false,searchList: { "male": __('Genderdata male'), "female": __('Genderdata female') }, formatter: Table.api.formatter.normal }, + { field: 'cardid', title: __('身份证号'), operate: '=',visible:false }, + { field: 'frameno', title: __('车架号'), operate: '=',visible:false}, // { // field: 'category_id', title: __('Category_id'), searchList: $.getJSON("user4s/category/searchlist"), formatter: function (value, row, index) { // return row['category']['name']; @@ -75,21 +76,22 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'editable'], function { field: 'integral', title: __('Integral'), operate: false }, //{field: 'city', title: __('City'), operate: 'LIKE'}, { field: 'buydate', title: __('Buydate'), operate: 'BETWEEN', addclass: 'datetimepicker',data: 'data-date-format="YYYY-MM-DD",data-date-use-current="true"', autocomplete: false }, - { field: 'carno', title: __('Carno'), operate: 'LIKE' ,editable:true}, - { field: 'model', title: __('Model'), operate: 'LIKE' ,editable:true}, + { field: 'carno', title: __('Carno'), operate: false ,editable:true}, + { field: 'model', title: __('Model'), operate: false ,editable:true}, { field: 'color', title: __('Color'), operate: false ,editable:true}, - //{field: 'inscom', title: __('Inscom'), operate: 'LIKE'}, + { field: 'inscom', title: __('保险公司'), operate: false, visible: false }, + {field: 'instype', title: __('保险类型'), operate: false,visible:false}, { field: 'insdate', title: __('Insdate'), operate: 'BETWEEN', addclass: 'datetimepicker',data: 'data-date-format="YYYY-MM-DD",data-date-use-current="true"', autocomplete: false }, //{field: 'tags', title: __('Tags'), operate: 'LIKE', formatter: Table.api.formatter.flag}, //{field: 'description', title: __('Description'), operate:false}, { - field: 'admin_id', title: __('Admin_id'), operate: false, formatter: function (value, row, index) { + field: 'admin_id', title: __('Admin_id'), operate: false,visible:false, formatter: function (value, row, index) { return row['fuzheren']; } }, //{ field: 'createtime', title: __('Createtime'), operate: false, addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime,datetimeFormat:'YYYY-MM-DD'}, //{field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime}, - { field: 'status', title: __('Status'), operate: '=',searchList: { "0": __('Status 0'), "1": __('Status 1') }, formatter: Table.api.formatter.status }, + { field: 'status', title: __('Status'), operate: false,searchList: { "0": __('Status 0'), "1": __('Status 1') }, formatter: Table.api.formatter.status }, //{ field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate }, { @@ -326,7 +328,9 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'editable'], function { field: 'carno', title: __('Carno'), operate: 'LIKE' }, { field: 'model', title: __('Model'), operate: false }, { field: 'color', title: __('Color'), operate: false }, - {field: 'inscom', title: __('Inscom'), operate: 'LIKE'}, + + { field: 'inscom', title: __('Inscom'), operate: 'LIKE' }, + {field: 'instype', title: __('Instype'), operate: 'LIKE'}, { field: 'insdate', title: __('Insdate'), operate: 'BETWEEN', addclass: 'datetimepicker',data: 'data-date-format="YYYY-MM-DD",data-date-use-current="true"', autocomplete: false }, { field: 'admin_id', title: __('Admin_id'), operate: false, formatter: function (value, row, index) { @@ -374,6 +378,169 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'editable'], function renewal: function () { Controller.api.bindevent(); }, + birthday: function () { + // 初始化表格参数配置 + Table.api.init({ + extend: { + index_url: 'user4s/user/birthday' + location.search, + table: 'user4s_user', + } + }); + + var table = $("#table"); + //当表格数据加载完成时 + table.on('load-success.bs.table', function (e, data) { + //这里可以获取从服务端获取的JSON数据 + console.log(data); + //这里我们手动设置底部的值 + $("#start_date").text(data.extend.start_date); + }); + // 初始化表格 + table.bootstrapTable({ + url: $.fn.bootstrapTable.defaults.extend.index_url, + pk: 'id', + sortName: 'id', + fixedColumns: true, + fixedRightNumber: 1, + showToggle: false, + //maintainSelected: true, + columns: [ + [ + { checkbox: true }, + //{field: 'id', title: __('Id'), operate:false}, + { field: 'name', title: __('Name'), operate: 'LIKE' }, + { field: 'tel', title: __('Tel'), operate: 'LIKE' }, + { field: 'birthday', title: __('生日'), operate: false}, + { field: 'cardid', title: __('Cardid'), operate: false }, + { field: 'buydate', title: __('Buydate'), operate: false}, + { field: 'carno', title: __('Carno'), operate: 'LIKE' }, + { field: 'model', title: __('Model'), operate: false }, + { field: 'color', title: __('Color'), operate: false }, + + { field: 'inscom', title: __('Inscom'), operate: 'LIKE' }, + {field: 'instype', title: __('Instype'), operate: 'LIKE'}, + { field: 'insdate', title: __('Insdate'), operate: 'BETWEEN', addclass: 'datetimepicker',data: 'data-date-format="YYYY-MM-DD",data-date-use-current="true"', autocomplete: false }, + { + field: 'admin_id', title: __('Admin_id'), operate: false, formatter: function (value, row, index) { + return row['fuzheren']; + } + }, + // { + // field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, + // buttons: [ + // { + // name: 'renewal', + // text: __('续保'), + // title: __('续保'), + // classname: 'btn btn-xs btn-danger btn-dialog', + // icon: 'fa fa-dashboard', + // url: 'user4s/user/renewal', + // extend: 'data-area=\'["1000px","800px"]\'', + // callback: function (data) { + // Layer.alert("接收到回传数据:" + JSON.stringify(data), { title: "回传数据" }); + // }, + // visible: function (row) { + // //返回true时按钮显示,返回false隐藏 + // return true; + // } + // }, + // { + // name: 'inslog', + // text: __('续保记录'), + // title: __('续保记录'), + // classname: 'btn btn-xs btn-warning btn-dialog', + // icon: 'fa fa-calendar-check-o', + // url: 'user4s/inslog/index?user4s_id={id}', + // extend: 'data-area=\'["1000px","800px"]\'', + // }, + // ], + // formatter: Table.api.formatter.operate + // } + ] + ], + + }); + // 为表格绑定事件 + Table.api.bindevent(table); + }, + excel: function() { + function reset() { + $("#step").val(0); + $("#import").addClass("disabled"); + if ($("#c-row").val() && $("#selecthead_type select").val() && $("#selectable select").val() && $("#c-rowpath").val()) { + Toastr.success('开始预览结果'); + // $("#submit").trigger("click"); + + Fast.api.ajax({ + url: 'import/log/preview', + data: $("form[role=form]").serialize(), + dataType: 'json', + }, function(data) { + console.log(data) + let columns = data.field + let xlsdata = data.data + let tableField = data.fieldArr + var select = "" + if (xlsdata.length) { + $("#step").val(1); + $("#import").removeClass("disabled"); + // Toastr.success("与狼"); + } + $.each(tableField, function(i, item) { + select += "" + }); + html = "" + $.each(columns, function(i, item) { + html += "" + item.field + "" + + }); + html += "" + html += "" + $.each(columns, function(i, item) { + if (item.class != "success") html += "" + else html += "" + }); + html += "" + $.each(xlsdata, function(i, item) { + html += "" + $.each(columns, function(i, f) { + html += "" + item[f.field] + "" + + }); + + html += "" + + }); + + $("#tableset").html(html) + }, function() { + return false; + }); + } + } + + $("#selectable select").on("change", function() { + $("#c-newtable").val('') + reset() + }) + $("#c-newtable").on("change", function() { + $("#selectable select").val(""); + reset() + }) + $("#c-row").on("change", function() { + reset() + }) + $("#c-rowpath").on("change", function() { + reset() + }) + $("#selecthead_type select").on("change", function() { + reset() + }) + $("#import").on("click", function() { + $("#submit").trigger("click"); + }) + Controller.api.bindevent(); + }, api: { bindevent: function (table) { Form.api.bindevent($("form[role=form]"));