Selaa lähdekoodia

生活补贴申请次数变更计算方式

sugangqiang 1 vuosi sitten
vanhempi
commit
18a46814f1

+ 12 - 2
app/common/api/LivingAllowanceApi.php

@@ -201,8 +201,18 @@ class LivingAllowanceApi {
         $where = [];
         $where[] = ["idCard", "=", $idCard];
         $where[] = ["checkState", "<>", LaState::LA_NOTPASS];
-        $list = LaModel::where($where)->distinct(true)->field("substr(year,1,4)")->select();
-        return count($list);
+        $list = LaModel::where($where)->distinct(true)->field("substr(year,1,4) as year")->select()->toArray();
+        $years = array_column($list, "year");
+        return $years;
+    }
+
+    public static function getPassYearsByIdCard($idCard) {
+        $where = [];
+        $where[] = ["idCard", "=", $idCard];
+        $where[] = ["checkState", "=", LaState::LA_PASS];
+        $list = LaModel::where($where)->distinct(true)->field("substr(year,1,4) as year")->select()->toArray();
+        $passYears = array_column($list, "year");
+        return $passYears;
     }
 
 }

+ 9 - 6
app/enterprise/controller/LivingAllowance.php

@@ -92,11 +92,14 @@ class LivingAllowance extends EnterpriseController {
             return $responseObj;
         }
         if (!$info["id"]) {
-            $where = [];
-            $where[] = ["idCard", "=", $info["idCard"]];
-            $where[] = ["checkState", "=", LaState::LA_PASS];
-            $totalApplyCount = LaModel::where($where)->count();
-            if ($totalApplyCount >= 3) {
+            $year = substr($info["year"], 0, 4);
+
+            $passYears = CommonLaApi::getPassYearsByIdCard($info["idCard"]);
+            if (in_array($year, $passYears)) {
+                return $responseObj->msg = "您今年度已经申报过了,每年度仅能享受一次生活补贴!";
+            }
+
+            if (count($passYears) >= 3) {
                 return $responseObj->msg = "一个人最多享受三次!";
             }
         }
@@ -253,7 +256,7 @@ class LivingAllowance extends EnterpriseController {
                 $data["createTime"] = date("Y-m-d H:i:s");
                 $data["createUser"] = $this->user["uid"];
                 $data["creditStatus"] = 1;
-                $count = CommonLaApi::getApplyCountByIdCard($data["idCard"]);
+                $count = count(CommonLaApi::getPassYearsByIdCard($data["idCard"]));
                 $data["applyCount"] = $count + 1;
                 if ($data["applyCount"] > 1 && !$data["personalTax"]) {
                     throw new ValidateException("非首年申报必须填写个税缴交情况!");