123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- <?php
- namespace app\admin\controller;
- use app\admin\AdminBaseController;
- class Couple extends AdminBaseController
- {
- public function index()
- {
- return view();
- }
- public function import()
- {
- return view();
- }
- public function match()
- {
- $old_file = input('old_file/s', "");
- if (!file_exists($old_file)) {
- return '旧名单文件不存在';
- }
- $new_file = input('new_file/s', "");
- if (!file_exists($new_file)) {
- return '新名单文件不存在';
- }
- //初始化数据
- $data = ['id', 'name', 'card_type', 'idcard', 'sex', 'birthday', 'mobile', 'tag', 'company', 'street', 'industry', 'job', 'graduate', 'level', 'people'];
- $old_list = import_exl($old_file, $data, 1);
- $new_list = import_exl($new_file, $data, 1);
- if (empty($old_list)) {
- return '旧名单文件无数据';
- }
- if (empty($new_list)) {
- return '新名单文件无数据';
- }
- //数据处理
- $old_idcard = array_column($old_list, 'idcard');
- $new_idcard = array_column($new_list, 'idcard');
- $delete = array_diff($old_idcard, $new_idcard);
- $add = array_diff($new_idcard, $old_idcard);
- $list = array_intersect($new_idcard, $old_idcard);
- //旧名单重整
- $old_people_by_idcard = [];
- $old_people_by_company = [];
- foreach ($old_list as $v) {
- $old_people_by_idcard[$v['idcard']] = $v['people'];
- $old_people_by_company[$v['company']] = $v['people'];
- }
- //新名单重整
- $new_people_by_idcard = [];
- foreach ($new_list as $v) {
- $new_people_by_idcard[$v['idcard']] = $v['company'];
- }
- //匹配名单
- $res = [];
- foreach ($delete as $k => $v) {
- $item = $old_list[$k];
- $item['status'] = '过期';
- $res[] = $item;
- }
- foreach ($add as $k => $v) {
- $item = $new_list[$k];
- $item['status'] = '新增';
- $item['people'] = '';
- if (!empty($new_people_by_idcard[$v]) && !empty($old_people_by_company[$new_people_by_idcard[$v]])) {
- $item['people'] = $old_people_by_company[$new_people_by_idcard[$v]];
- }
- $res[] = $item;
- }
- foreach ($list as $k => $v) {
- $item = $new_list[$k];
- $item['status'] = '续期';
- $item['people'] = $old_people_by_idcard[$v];
- $res[] = $item;
- }
- $xlsCell = [
- ['id', '序号'],
- ['name', '姓名'],
- ['card_type', '证件类型'],
- ['idcard', '证件号码'],
- ['sex', '性别'],
- ['birthday', '出生日期'],
- ['mobile', '手机号码'],
- ['tag', '企业标签'],
- ['company', '单位名称'],
- ['street', '所属镇街'],
- ['industry', '产业领域'],
- ['job', '本单位现任职位'],
- ['graduate', '最高学历'],
- ['level', '人才层次'],
- ['people', '挂钩人员'],
- ['status', '状态'],
- ];
- export_exl("人才挂钩名单匹配记录", $xlsCell, $res, ['idcard', 'birthday', 'mobile']);
- }
- }
|