Data.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. namespace app\job;
  3. use app\common\api\BatchApi;
  4. use app\common\api\TalentLogApi;
  5. use app\common\model\TalentChecklog;
  6. use app\common\state\ProjectState;
  7. use think\queue\Job;
  8. use think\facade\Log;
  9. use think\facade\Db;
  10. use app\common\api\ChuanglanSmsApi;
  11. // 给类文件的命名空间起个别名
  12. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  13. //Xlsx类 保存文件功能类
  14. use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
  15. use app\admin\api\DataApi;
  16. class Data {
  17. public function fire(Job $job, $data) {
  18. if ($this->deal($data)) {
  19. Log::info(json_encode($data));
  20. $job->delete();
  21. return true;
  22. }
  23. Log::error(json_encode($data));
  24. if ($job->attempts() >= 3) {
  25. $job->delete();
  26. return false;
  27. }
  28. $job->release(10); //10秒后重试
  29. }
  30. public function deal($data): bool {
  31. $id = $data['id'];
  32. $res = Db::table("new_data_check")->where('id', $id)->findOrEmpty();
  33. switch ($data['type']){
  34. case '1':
  35. if ($res) {
  36. if ($res['task_status'] != -1) {
  37. return true;
  38. }
  39. try {
  40. $path = dirname(dirname(dirname(__FILE__)));
  41. $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($path ."/public/storage/" . $res['task_file']);
  42. $sheet = $spreadsheet->getSheet(0);
  43. $datas = $sheet->toArray();
  44. $datas = array_slice($datas, 1); //去标题
  45. $writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx');
  46. $dataapi = new DataApi();
  47. for ($index = 0; $index <= count($datas); $index++) {
  48. $cards_list = [];
  49. if(empty($datas[$index][2])){//如果文件没有提供出生日期,查询系统内的出生日期
  50. echo "正在查询第" . ($index + 1) . "人({$datas[$index][0]})的出生日期\r\n";
  51. $info = Db::table('new_talent_info')->where("name ", "=", $datas[$index][0])->where('card_number', '=', $datas[$index][1])->find();
  52. if($info){
  53. $birthday = $info['birthday'];
  54. }else{
  55. $birthday = false;
  56. }
  57. }else{
  58. $birthday = $datas[$index][2];
  59. }
  60. if($birthday){
  61. echo "正在查询第" . ($index + 1) . "人({$datas[$index][0]}----{$birthday})的证件号\r\n";
  62. $cards = $dataapi->IDNumber($datas[$index][0],date("Ymd",strtotime($birthday)));
  63. if($cards['code'] == '01' && count($cards['data']) >= 1){
  64. foreach ($cards['data'] as $card){
  65. array_push($cards_list,$card['aac147']);
  66. }
  67. }
  68. }
  69. array_push($cards_list,$datas[$index][1]);
  70. array_push($cards_list,substr($datas[$index][1],4));//到底里把所有能取到证件号的渠道得到的证件号放一起
  71. $cards_list = array_unique($cards_list);//去掉重复的证件号码
  72. $shixian = [];
  73. $yanglao = [];//定义失业险和养老险数据
  74. foreach ($cards_list as $v){
  75. if(count($shixian) == 0){
  76. echo "正在查询第" . ($index + 1) . "人({$datas[$index][0]}----{$v})的失业险\r\n";
  77. $start = $data['year'] . "01";
  78. $end = $data['year'] + 1 . "01";
  79. $res = $dataapi->queryUnemploymentInsuranceByIdAndTime($v,"{$start}","{$end}");
  80. Db::table('data_check_log')->save(['realname' => $datas[$index][0],'card' => $v,'params' => json_encode(['card' => $v,'start' => $start,'end' => $end]), 'result' => json_encode($res),'createTime' => date("Y-m-d H:i:s",time())]);
  81. if($res){
  82. $i = 0;
  83. $months = [];
  84. if(count($res['data']) > 0){
  85. foreach ($res['data'] as $k => $v){
  86. if(strpos($v['AAB069'],"晋华") !== false || strpos($v['AAB069'],"渠梁") !== false){
  87. $i++;
  88. array_push($months,$v['AAE003']);
  89. }
  90. }
  91. sort($months);
  92. $res_str = "2022年共缴费{$i}个月,分别是:".implode('、',$months);
  93. echo "第". ($index + 1) . "失业险整理完毕,姓名:{$datas[$index][1]},".$res_str."\r\n";
  94. $sheet->setCellValue('F' . ($index+1), $res_str);
  95. break;
  96. }
  97. }
  98. }
  99. echo "第". ($index + 1) . "失业险整理完毕,姓名:{$datas[$index][1]},2022年共缴费0个月\r\n";
  100. $sheet->setCellValue('F' . ($index+1), "2022年共缴费0个月");
  101. sleep(3);
  102. }
  103. }
  104. } catch (\Exception $e) {
  105. var_dump($e->getMessage());
  106. Db::table("new_data_check")->where('id', $id)->update(['task_result' => $e->getMessage(), 'task_status' => 0, 'updateTime' => date("Y-m-d H:i:s", time())]);
  107. return false;
  108. }
  109. }
  110. $path = dirname(dirname(dirname(__FILE__)));
  111. $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($path . "/test.xlsx");
  112. $sheet = $spreadsheet->getSheet(0);
  113. $datas = $sheet->toArray();
  114. break;
  115. }
  116. }
  117. }