Couple.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\AdminBaseController;
  4. class Couple extends AdminBaseController
  5. {
  6. public function index()
  7. {
  8. return view();
  9. }
  10. public function import()
  11. {
  12. return view();
  13. }
  14. public function match()
  15. {
  16. $old_file = input('old_file/s', "");
  17. if (!file_exists($old_file)) {
  18. return '旧名单文件不存在';
  19. }
  20. $new_file = input('new_file/s', "");
  21. if (!file_exists($new_file)) {
  22. return '新名单文件不存在';
  23. }
  24. //初始化数据
  25. $data = ['id', 'name', 'card_type', 'idcard', 'sex', 'birthday', 'mobile', 'tag', 'company', 'street', 'industry', 'job', 'graduate', 'level', 'people'];
  26. $old_list = import_exl($old_file, $data, 1);
  27. $new_list = import_exl($new_file, $data, 1);
  28. if (empty($old_list)) {
  29. return '旧名单文件无数据';
  30. }
  31. if (empty($new_list)) {
  32. return '新名单文件无数据';
  33. }
  34. //数据处理
  35. $old_idcard = array_column($old_list, 'idcard');
  36. $new_idcard = array_column($new_list, 'idcard');
  37. $delete = array_diff($old_idcard, $new_idcard);
  38. $add = array_diff($new_idcard, $old_idcard);
  39. $list = array_intersect($new_idcard, $old_idcard);
  40. //旧名单重整
  41. $old_people_by_idcard = [];
  42. $old_people_by_company = [];
  43. foreach ($old_list as $v) {
  44. $old_people_by_idcard[$v['idcard']] = $v['people'];
  45. $old_people_by_company[$v['company']] = $v['people'];
  46. }
  47. //新名单重整
  48. $new_people_by_idcard = [];
  49. foreach ($new_list as $v) {
  50. $new_people_by_idcard[$v['idcard']] = $v['company'];
  51. }
  52. //匹配名单
  53. $res = [];
  54. foreach ($delete as $k => $v) {
  55. $item = $old_list[$k];
  56. $item['status'] = '过期';
  57. $res[] = $item;
  58. }
  59. foreach ($add as $k => $v) {
  60. $item = $new_list[$k];
  61. $item['status'] = '新增';
  62. $item['people'] = '';
  63. if (!empty($new_people_by_idcard[$v]) && !empty($old_people_by_company[$new_people_by_idcard[$v]])) {
  64. $item['people'] = $old_people_by_company[$new_people_by_idcard[$v]];
  65. }
  66. $res[] = $item;
  67. }
  68. foreach ($list as $k => $v) {
  69. $item = $new_list[$k];
  70. $item['status'] = '续期';
  71. $item['people'] = $old_people_by_idcard[$v];
  72. $res[] = $item;
  73. }
  74. $xlsCell = [
  75. ['id', '序号'],
  76. ['name', '姓名'],
  77. ['card_type', '证件类型'],
  78. ['idcard', '证件号码'],
  79. ['sex', '性别'],
  80. ['birthday', '出生日期'],
  81. ['mobile', '手机号码'],
  82. ['tag', '企业标签'],
  83. ['company', '单位名称'],
  84. ['street', '所属镇街'],
  85. ['industry', '产业领域'],
  86. ['job', '本单位现任职位'],
  87. ['graduate', '最高学历'],
  88. ['level', '人才层次'],
  89. ['people', '挂钩人员'],
  90. ['status', '状态'],
  91. ];
  92. export_exl("人才挂钩名单匹配记录", $xlsCell, $res, ['idcard', 'birthday', 'mobile']);
  93. }
  94. }