Jjhc.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 Jjhc {
  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. /**
  31. * 处理业务逻辑
  32. * @param type $data
  33. * @return bool
  34. */
  35. public function deal($data): bool {
  36. switch ($data['type']){
  37. case '1':
  38. $path = dirname(dirname(dirname(__FILE__)));
  39. $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($path . "/test.xlsx");
  40. $sheet = $spreadsheet->getSheet(0);
  41. $datas = $sheet->toArray();
  42. $writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx');
  43. $dataapi = new DataApi();
  44. for ($index = 0; $index <= count($datas); $index++) {
  45. echo "正在查询第" . ($index + 1) . "人({$datas[$index][3]})的失业险\r\n";
  46. $res = $dataapi->queryUnemploymentInsuranceByIdAndTime($datas[$index][3],'202201','202301');
  47. if($res){
  48. $i = 0;
  49. foreach ($res['data'] as $k => $v){
  50. if(strpos($v['AAB069'],"晋华") !== false || strpos($v['AAB069'],"渠梁") !== false){
  51. $i++;
  52. }
  53. }
  54. $res_str = "2022年共缴费{$i}个月";
  55. echo "第". ($index + 1) . "失业险整理完毕,姓名:{$datas[$index][1]},".$res_str."\r\n";
  56. $sheet->setCellValue('F' . ($index+1), $res_str);
  57. }
  58. sleep(5);
  59. }
  60. $writer->save($path . "/test.xlsx");
  61. return false;
  62. break;
  63. case '2':
  64. $path = dirname(dirname(dirname(__FILE__)));
  65. $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($path . "/test.xlsx");
  66. $sheet = $spreadsheet->getSheet(0);
  67. $datas = $sheet->toArray();
  68. $writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx');
  69. $dataapi = new DataApi();
  70. for ($index = 0; $index < count($datas); $index++) {
  71. echo "正在查询第" . ($index+1) . "人({$datas[$index][3]})的养老险\r\n";
  72. $res = $dataapi->queryOldAgeSecurityInsuranceByIdAndTime($datas[$index][3],'202201','202301');
  73. if($res){
  74. $i = 0;
  75. foreach ($res['data'] as $k => $v){
  76. if(strpos($v['AAB004'],"晋华") !== false || strpos($v['AAB004'],"渠梁") !== false){
  77. $i++;
  78. }
  79. }
  80. $res_str = "2022年共缴费{$i}个月";
  81. echo "第". ($index + 1) . "养老险整理完毕,姓名:{$datas[$index][1]},".$res_str."\r\n";
  82. $sheet->setCellValue('E' . ($index+1), $res_str);
  83. }
  84. sleep(2);
  85. }
  86. $writer->save($path . "/test.xlsx");
  87. return false;
  88. break;
  89. default:
  90. return false;
  91. }
  92. }
  93. }