| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- <?php
- namespace app\job;
- use app\common\api\BatchApi;
- use app\common\api\TalentLogApi;
- use app\common\model\TalentChecklog;
- use app\common\state\ProjectState;
- use think\queue\Job;
- use think\facade\Log;
- use think\facade\Db;
- use app\common\api\ChuanglanSmsApi;
- // 给类文件的命名空间起个别名
- use PhpOffice\PhpSpreadsheet\Spreadsheet;
- //Xlsx类 保存文件功能类
- use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
- use app\admin\api\DataApi;
- class Jjhc {
- public function fire(Job $job, $data) {
- if ($this->deal($data)) {
- Log::info(json_encode($data));
- $job->delete();
- return true;
- }
- Log::error(json_encode($data));
- if ($job->attempts() >= 3) {
- $job->delete();
- return false;
- }
- $job->release(10); //10秒后重试
- }
- /**
- * 处理业务逻辑
- * @param type $data
- * @return bool
- */
- public function deal($data): bool {
- switch ($data['type']){
- case '1':
- $path = dirname(dirname(dirname(__FILE__)));
- $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($path . "/test.xlsx");
- $sheet = $spreadsheet->getSheet(0);
- $datas = $sheet->toArray();
- $writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx');
- $dataapi = new DataApi();
- for ($index = 0; $index <= count($datas); $index++) {
- echo "正在查询第" . ($index + 1) . "人({$datas[$index][3]})的失业险\r\n";
- $res = $dataapi->queryUnemploymentInsuranceByIdAndTime($datas[$index][3],'202201','202301');
- if($res){
- $i = 0;
- foreach ($res['data'] as $k => $v){
- if(strpos($v['AAB069'],"晋华") !== false || strpos($v['AAB069'],"渠梁") !== false){
- $i++;
- }
- }
- $res_str = "2022年共缴费{$i}个月";
- echo "第". ($index + 1) . "失业险整理完毕,姓名:{$datas[$index][1]},".$res_str."\r\n";
- $sheet->setCellValue('F' . ($index+1), $res_str);
- }
- sleep(5);
- }
- $writer->save($path . "/test.xlsx");
- return false;
- break;
- case '2':
- $path = dirname(dirname(dirname(__FILE__)));
- $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($path . "/test.xlsx");
- $sheet = $spreadsheet->getSheet(0);
- $datas = $sheet->toArray();
- $writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx');
- $dataapi = new DataApi();
- for ($index = 0; $index < count($datas); $index++) {
- echo "正在查询第" . ($index+1) . "人({$datas[$index][3]})的养老险\r\n";
- $res = $dataapi->queryOldAgeSecurityInsuranceByIdAndTime($datas[$index][3],'202201','202301');
- if($res){
- $i = 0;
- foreach ($res['data'] as $k => $v){
- if(strpos($v['AAB004'],"晋华") !== false || strpos($v['AAB004'],"渠梁") !== false){
- $i++;
- }
- }
- $res_str = "2022年共缴费{$i}个月";
- echo "第". ($index + 1) . "养老险整理完毕,姓名:{$datas[$index][1]},".$res_str."\r\n";
- $sheet->setCellValue('E' . ($index+1), $res_str);
- }
- sleep(2);
- }
- $writer->save($path . "/test.xlsx");
- return false;
- break;
- default:
- return false;
- }
- }
- }
|