Browse Source

批量导入津补贴申请

sugangqiang 1 year ago
parent
commit
df6bb57b72
2 changed files with 160 additions and 4 deletions
  1. 78 1
      app/enterprise/controller/TalentAllowance.php
  2. 82 3
      app/job/TalentAllowance.php

+ 78 - 1
app/enterprise/controller/TalentAllowance.php

@@ -71,6 +71,10 @@ class TalentAllowance extends EnterpriseController {
         return view("", ["year" => $batch, "type" => $this->user["type"], "row" => $info]);
     }
 
+    /**
+     * 批量提交申请
+     * @return Response
+     */
     public function batchApply() {
         $ids = $this->request["ids"];
         $ids = array_filter(explode(",", $ids));
@@ -82,7 +86,80 @@ class TalentAllowance extends EnterpriseController {
         }
 
         for ($i = 0; $i < count($ids); $i++) {
-            queue("app\job\TalentAllowance", ["type" => 1, "talentId" => $ids[$i], "enterprise" => $this->user, "year" => $batch, "allowanceType" => $allowanceType]);
+            queue("app\job\TalentAllowance", ["type" => 1, "method" => 1, "talentId" => $ids[$i], "enterprise" => $this->user, "year" => $batch, "allowanceType" => $allowanceType]);
+        }
+        return new Response(Response::SUCCESS, "已经成功添加到计划任务,请稍候查看申报列表进行确认");
+    }
+
+    /**
+     * 批量导入申请
+     * @return Response
+     */
+    public function batchImportApply() {
+        $maxFileSize = 10; //mb
+        $tmp = $this->request->file("file");
+
+        $batch = BatchApi::getValidBatch(ProjectState::JBT, $this->user["type"])["batch"];
+        if (!$batch) {
+            return new Response(Response::ERROR, "当前并无有效的申报批次进行中");
+        }
+        if (!$tmp) {
+            return new Response(Response::ERROR, "没有上传批量申请文档");
+        }
+        if (!isExcelFile($tmp->getMime())) {
+            return new Response(Response::ERROR, "只能识别Excel文档");
+        }
+        if (round($tmp->getSize() / 1024 / 1024, 2) > $maxFileSize) {
+            return new Response(Response::ERROR, "文档大小不能超过10MB");
+        }
+        $filepath = $tmp->getPathname();
+        $rows = getExcelDatas($filepath);
+        array_shift($rows); //去标题行
+        //检查excel文件有没有问题
+        $checkMonths = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
+        $titles = ["姓名", "身份证", "申请补贴类型", "个税缴纳月份", "工资发放月份", "考勤情况", "养老保险", "失业保险", "医疗保险"];
+        $allowanceTypes = ["工作津贴", "一次性交通补贴"];
+        $idCards = [];
+        foreach ($rows as $key => $row) {
+            $no = $key + 2;
+            $idCard = trim($row[1]);
+            $allowanceType = trim($row[2]);
+            if (!$idCard) {
+                return new Response(Response::ERROR, sprintf("第%d行身份证不能放空,请仔细检查内容完整后再重新提交", $no));
+            }
+            if (in_array($idCard, $idCards)) {
+                return new Response(Response::ERROR, sprintf("第%d行身份证存在重复,请请仔细检查内容无误后再重新提交", $no));
+            } else {
+                $idCards[] = $idCard;
+            }
+            if (!in_array($allowanceType, $allowanceTypes)) {
+                return new Response(Response::ERROR, sprintf("第%d行申请补贴类型错误,请仔细检查内容无误后再重新提交", $no));
+            }
+            if ($allowanceType == "工作津贴") {
+                for ($i = 3; $i < 9; $i++) {
+                    $monthstr = str_replace([" ", ","], ",", trim($row[$i]));
+                    $months = array_filter(explode(",", $monthstr));
+                    if (!$months)
+                        return new Response(Response::ERROR, sprintf("第%d行%s不能为空,请仔细检查内容完整后再重新提交", $no, $titles[$i]));
+                    if (array_diff($months, $checkMonths))
+                        return new Response(Response::ERROR, sprintf("第%d行%s错误,请查看模板文档对应列说明修改后再重新提交", $no, $titles[$i]));
+                }
+            } else {
+                $monthstr = str_replace([" ", ","], ",", trim($row[5]));
+                $monthstr = str_replace(":", ":", $monthstr);
+                $months = array_filter(explode(",", $monthstr));
+                if (!$months)
+                    return new Response(Response::ERROR, sprintf("第%d行%s不能为空,请仔细检查内容完整后再重新提交", $no, $titles[5]));
+                foreach ($months as $m) {
+                    list($a, $b) = explode(":", $m);
+                    if (!in_array($a, $checkMonths) || !is_numeric($b) || $b > 31 || $b < 0)
+                        return new Response(Response::ERROR, sprintf("第%d行%s错误,请查看模板文档对应列说明修改后再重新提交", $no, $titles[5]));
+                }
+            }
+        }
+
+        for ($i = 0; $i < count($rows); $i++) {
+            queue("app\job\TalentAllowance", ["type" => 1, "method" => 2, "data" => $rows[$i], "enterprise" => $this->user, "year" => $batch, "allowanceType" => trim($rows[$i][2]) == "工作津贴" ? 1 : 2]);
         }
         return new Response(Response::SUCCESS, "已经成功添加到计划任务,请稍候查看申报列表进行确认");
     }

+ 82 - 3
app/job/TalentAllowance.php

@@ -44,12 +44,22 @@ class TalentAllowance {
             case 1:
                 //添加保存未提交的津补贴申报
                 try {
+                    $method = $data["method"];
                     $talentId = $data["talentId"];
+                    $importRow = $data["data"];
                     $enterprise = $data["enterprise"];
                     $year = $data["year"];
                     $allowanceType = $data["allowanceType"];
-
-                    $ti = \app\common\api\VerifyApi::getTalentInfoById($talentId);
+                    if ($method == 1) {
+                        $ti = \app\common\api\VerifyApi::getTalentInfoById($talentId);
+                    } else {
+                        $where[] = ["card_number", "=", $importRow[1]];
+                        $where[] = ["delete", "=", 0];
+                        $where[] = ["checkState", "=", TalentState::CERTIFICATED];
+                        $ti = Db::table("new_talent_info")->where($where)->find()->toArray();
+                        $talentId = $ti["id"];
+                        $ti = \app\common\api\VerifyApi::getTalentInfoById($talentId);
+                    }
                     if ($ti["checkState"] != TalentState::CERTIFICATED || $ti["enterprise_id"] != $enterprise["uid"] || !$year || !$allowanceType) {
                         return false;
                     }
@@ -120,7 +130,11 @@ class TalentAllowance {
                      * 4.添加津补贴核查项目
                      */
                     //核查项目详情表
-                    $this->createAllowanceProject($data, $contractDetailList);
+                    if ($method == 1) {
+                        $this->createAllowanceProject($data, $contractDetailList);
+                    } else {
+                        $this->createAllowanceProject_m2($data, $contractDetailList, $importRow);
+                    }
                     \app\common\model\TalentAllowanceArrange::insertAll($arrangeList);
                     //添加日志
                     TalentChecklog::create([
@@ -305,4 +319,69 @@ class TalentAllowance {
         }
     }
 
+    private function createAllowanceProject_m2($info, $contractList, $rowdata) {
+        $count = 0;
+        foreach ($contractList as $detail) {
+            $count++;
+            $list = [];
+
+            for ($i = 3; $i < count($rowdata); $i++) {
+                $project = 1;
+                switch ($i) {
+                    case 3:
+                        $project = AllowanceProjectEnum::PROJECT_TAX;
+                        break;
+                    case 4:
+                        $project = AllowanceProjectEnum::PROJECT_WAGES;
+                        break;
+                    case 5:
+                        $project = AllowanceProjectEnum::PROJECT_ATTENDANCE;
+                        break;
+                    case 6:
+                        $project = AllowanceProjectEnum::PROJECT_SB_PENSION;
+                        break;
+                    case 7:
+                        $project = AllowanceProjectEnum::PROJECT_SB_UNEMPLOYMENT;
+                        break;
+                    case 8:
+                        $project = AllowanceProjectEnum::PROJECT_SB_MEDICA;
+                        break;
+                }
+                $months = "";
+                if ($count == count($contractList)) {
+                    if ($info["allowanceType"] == 2 && $i == 5) {
+                        $monthstr = str_replace([" ", ","], ",", trim($row[5]));
+                        $monthstr = str_replace(":", ":", $monthstr);
+                        $months = array_filter(explode(",", $monthstr));
+                        $tmp = [];
+                        for ($n = 0; $n < count($months); $n++) {
+                            list($a, $b) = explode(":", $m);
+                            $a = str_pad($a, 2, 0, STR_PAD_LEFT);
+                            $tmp[] = sprintf("%s:%s", $a, $b);
+                        }
+                        $months = implode(",", $tmp);
+                    } else {
+                        $monthstr = str_replace([" ", ","], ",", trim($rowdata[$i]));
+                        $months = array_filter(explode(",", $monthstr));
+                        for ($n = 0; $n < count($months); $n++) {
+                            $months[$n] = str_pad($months[$n], 2, 0, STR_PAD_LEFT);
+                        }
+                    }
+                    $months = implode(",", $months);
+                }
+                $list[] = [
+                    "mainId" => $info["id"],
+                    "baseId" => $detail["id"],
+                    "enterpriseId" => $detail["enterpriseId"],
+                    "project" => $project,
+                    "months" => $months,
+                    "isLock" => 1,
+                    "createTime" => date("Y-m-d H:i:s")
+                ];
+            }
+
+            \app\common\model\TalentAllowanceProject::insertAll($list);
+        }
+    }
+
 }