Browse Source

excel批量导入津补贴申请

sugangqiang 1 năm trước cách đây
mục cha
commit
44f8e87e4b

+ 1 - 0
app/common/api/TalentAllowanceApi.php

@@ -100,6 +100,7 @@ class TalentAllowanceApi {
         $info = ["id" => $id];
         $old = self::getInfoById($id);
         $info["type"] = $old["type"];
+        $info["allowanceType"] = $old["allowanceType"];
         $enterpriseMap = \app\common\model\Enterprise::where("type", $old["type"])->column("name", "id");
         /*         * 查询工作单位记录 */
         $initDetailList = \app\common\model\TalentAllowancecontractDetail::where("mainId", $info["id"])->select()->toArray();

+ 12 - 12
app/enterprise/controller/TalentAllowance.php

@@ -101,16 +101,16 @@ class TalentAllowance extends EnterpriseController {
 
         $batch = BatchApi::getValidBatch(ProjectState::JBT, $this->user["type"])["batch"];
         if (!$batch) {
-            return new Response(Response::ERROR, "当前并无有效的申报批次进行中");
+            return \StrUtil::back(new Response(Response::ERROR, "当前并无有效的申报批次进行中"), "TalentAllowanceInfo.importCallBack");
         }
         if (!$tmp) {
-            return new Response(Response::ERROR, "没有上传批量申请文档");
+            return \StrUtil::back(new Response(Response::ERROR, "没有上传批量申请文档"), "TalentAllowanceInfo.importCallBack");
         }
         if (!isExcelFile($tmp->getMime())) {
-            return new Response(Response::ERROR, "只能识别Excel文档");
+            return \StrUtil::back(new Response(Response::ERROR, "只能识别Excel文档"), "TalentAllowanceInfo.importCallBack");
         }
         if (round($tmp->getSize() / 1024 / 1024, 2) > $maxFileSize) {
-            return new Response(Response::ERROR, "文档大小不能超过10MB");
+            return \StrUtil::back(new Response(Response::ERROR, "文档大小不能超过10MB"), "TalentAllowanceInfo.importCallBack");
         }
         $filepath = $tmp->getPathname();
         $rows = getExcelDatas($filepath);
@@ -125,35 +125,35 @@ class TalentAllowance extends EnterpriseController {
             $idCard = trim($row[1]);
             $allowanceType = trim($row[2]);
             if (!$idCard) {
-                return new Response(Response::ERROR, sprintf("第%d行身份证不能放空,请仔细检查内容完整后再重新提交", $no));
+                return \StrUtil::back(new Response(Response::ERROR, sprintf("第%d行身份证不能放空,请仔细检查内容完整后再重新提交", $no)), "TalentAllowanceInfo.importCallBack");
             }
             if (in_array($idCard, $idCards)) {
-                return new Response(Response::ERROR, sprintf("第%d行身份证存在重复,请请仔细检查内容无误后再重新提交", $no));
+                return \StrUtil::back(new Response(Response::ERROR, sprintf("第%d行身份证存在重复,请请仔细检查内容无误后再重新提交", $no)), "TalentAllowanceInfo.importCallBack");
             } else {
                 $idCards[] = $idCard;
             }
             if (!in_array($allowanceType, $allowanceTypes)) {
-                return new Response(Response::ERROR, sprintf("第%d行申请补贴类型错误,请仔细检查内容无误后再重新提交", $no));
+                return \StrUtil::back(new Response(Response::ERROR, sprintf("第%d行申请补贴类型错误,请仔细检查内容无误后再重新提交", $no)), "TalentAllowanceInfo.importCallBack");
             }
             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]));
+                        return \StrUtil::back(new Response(Response::ERROR, sprintf("第%d行%s不能为空,请仔细检查内容完整后再重新提交", $no, $titles[$i])), "TalentAllowanceInfo.importCallBack");
                     if (array_diff($months, $checkMonths))
-                        return new Response(Response::ERROR, sprintf("第%d行%s错误,请查看模板文档对应列说明修改后再重新提交", $no, $titles[$i]));
+                        return \StrUtil::back(new Response(Response::ERROR, sprintf("第%d行%s错误,请查看模板文档对应列说明修改后再重新提交", $no, $titles[$i])), "TalentAllowanceInfo.importCallBack");
                 }
             } 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]));
+                    return \StrUtil::back(new Response(Response::ERROR, sprintf("第%d行%s不能为空,请仔细检查内容完整后再重新提交", $no, $titles[5])), "TalentAllowanceInfo.importCallBack");
                 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]));
+                        return \StrUtil::back(new Response(Response::ERROR, sprintf("第%d行%s错误,请查看模板文档对应列说明修改后再重新提交", $no, $titles[5])), "TalentAllowanceInfo.importCallBack");
                 }
             }
         }
@@ -161,7 +161,7 @@ class TalentAllowance extends EnterpriseController {
         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, "已经成功添加到计划任务,请稍候查看申报列表进行确认");
+        return \StrUtil::back(new Response(Response::SUCCESS, "已经成功添加到计划任务,请稍候查看申报列表进行确认"), "TalentAllowanceInfo.importCallBack");
     }
 
     private function save($talentAllowance, \think\Request $request) {

+ 6 - 6
app/job/TalentAllowance.php

@@ -56,7 +56,7 @@ class TalentAllowance {
                         $where[] = ["card_number", "=", $importRow[1]];
                         $where[] = ["delete", "=", 0];
                         $where[] = ["checkState", "=", TalentState::CERTIFICATED];
-                        $ti = Db::table("new_talent_info")->where($where)->find()->toArray();
+                        $ti = Db::table("new_talent_info")->where($where)->find();
                         $talentId = $ti["id"];
                         $ti = \app\common\api\VerifyApi::getTalentInfoById($talentId);
                     }
@@ -350,24 +350,24 @@ class TalentAllowance {
                 $months = "";
                 if ($count == count($contractList)) {
                     if ($info["allowanceType"] == 2 && $i == 5) {
-                        $monthstr = str_replace([" ", ","], ",", trim($row[5]));
+                        $monthstr = str_replace([" ", ","], ",", trim($rowdata[5]));
                         $monthstr = str_replace(":", ":", $monthstr);
                         $months = array_filter(explode(",", $monthstr));
                         $tmp = [];
                         for ($n = 0; $n < count($months); $n++) {
-                            list($a, $b) = explode(":", $m);
+                            list($a, $b) = explode(":", $months[$n]);
                             $a = str_pad($a, 2, 0, STR_PAD_LEFT);
-                            $tmp[] = sprintf("%s:%s", $a, $b);
+                            $tmp[] = sprintf("%s=%s", $a, $b);
                         }
-                        $months = implode(",", $tmp);
+                        $months = $tmp ? 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 = $months ? implode(",", $months) : "";
                     }
-                    $months = implode(",", $months);
                 }
                 $list[] = [
                     "mainId" => $info["id"],