Couple.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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', 'company', 'level', 'street', 'mobile', '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, 'mobile');
  36. $new_idcard = array_column($new_list, 'mobile');
  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_mobile = [];
  42. $old_people_by_company = [];
  43. foreach ($old_list as $v) {
  44. $old_people_by_mobile[$v['mobile']] = $v['people'];
  45. $old_people_by_company[$v['company']] = $v['people'];
  46. }
  47. //新名单重整
  48. $new_people_by_mobile = [];
  49. foreach ($new_list as $v) {
  50. $new_people_by_mobile[$v['mobile']] = $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. if (!empty($new_people_by_mobile[$v]) && !empty($old_people_by_company[$new_people_by_mobile[$v]])) {
  63. $item['people'] = $old_people_by_company[$new_people_by_mobile[$v]];
  64. }
  65. $res[] = $item;
  66. }
  67. foreach ($list as $k => $v) {
  68. $item = $new_list[$k];
  69. $item['status'] = '续期';
  70. $item['people'] = $old_people_by_mobile[$v];
  71. $res[] = $item;
  72. }
  73. $xlsCell = [
  74. ['id', '序号'],
  75. ['name', '姓名'],
  76. ['company', '单位名称'],
  77. ['level', '人才层次'],
  78. ['street', '所属镇街'],
  79. ['mobile', '联系方式'],
  80. ['people', '挂钩人员'],
  81. ['status', '状态'],
  82. ];
  83. export_exl("人才挂钩名单匹配记录", $xlsCell, $res);
  84. }
  85. }