sugangqiang 2 years ago
parent
commit
d172eacba5
1 changed files with 50 additions and 0 deletions
  1. 50 0
      app/common/api/IntegralRecordApi.php

+ 50 - 0
app/common/api/IntegralRecordApi.php

@@ -103,4 +103,54 @@ class IntegralRecordApi {
         return $info;
         return $info;
     }
     }
 
 
+    public static function calIntegral($enterprise_id, $cardType, $cardNumber, $itemId) {
+        $item = getCacheById("IntegralItem", $itemId);
+        $projectMax = 0; //项目总上限
+        $itemMax = 0; //标准总上限
+        if ($item) {
+            $project = getCacheById("IntegralProject", $item["projectId"]);
+            if ($project["limit"] == 1) {
+                //项目下所有规则总上限
+                $where = [];
+                $where[] = ["r.enterprise_id", "=", $enterprise_id];
+                $where[] = ["r.card_type", "=", $cardType];
+                $where[] = ["r.card_number", "=", $cardNumber];
+                $where[] = ["r.checkState", ">=", IntegralState::SUCCESS];
+                $where[] = ["i.projectId", "=", $project["id"]];
+                if ($project["yearly"] == 1) {
+                    //年度重置只算当年度
+                    $startTime = date("Y-01-01 00:00:00");
+                    $endTime = date("Y-12-31 23:59:59");
+                    $where[] = ["r.createTime", "between", [$startTime, $endTime]];
+                }
+                $totalPoints = Db::table("new_integral_detail")->alias("d")->leftJoin("new_integral_record r", "r.id=d.record_id")->leftJoin("new_integral_item i", "i.id=d.item_id")->where($where)->sum("d.point");
+            }
+            if ($item["limit"] == 1) {
+                //规则上限
+            }
+
+            if ($project["limit"] == 2) {
+                //项目没有设置上限
+                if ($item["limit"] == 2) {
+                    //标准没有设置上限
+                } else {
+                    //标准有设置上限,并检查标准有没有年度重置
+                    if ($item["yearly"] == 1) {
+                        //标准有年度重置
+                    } else {
+                        //标准没有重置
+                    }
+                }
+            } else {
+                //有设置上限,并检查有没有年度重置
+                if ($project["yearly"] == 1) {
+                    //有年度重置
+                } else {
+                    //没有重置
+                }
+            }
+        }
+        return 0;
+    }
+
 }
 }