瀏覽代碼

Merge branch 'zhongqi-birthDay' into dev

shizhongqi 2 月之前
父節點
當前提交
d9a675c7c1
共有 1 個文件被更改,包括 60 次插入11 次删除
  1. 60 11
      biz-hd/birthday/classes/BirthdayGiftClass.php

+ 60 - 11
biz-hd/birthday/classes/BirthdayGiftClass.php

@@ -8,6 +8,7 @@ use bizHd\custom\classes\HdClass;
 use bizHd\member\classes\MemberLevelClass;
 use bizHd\shop\classes\ShopClass;
 use bizHd\shop\classes\ShopExtClass;
+use common\components\noticeUtil;
 use common\components\orderSn;
 use common\components\printUtil;
 use common\components\ChuanglanSmsApi;
@@ -22,11 +23,11 @@ class BirthdayGiftClass extends BaseClass
 {
     public static $baseFile = '\bizHd\birthday\models\BirthdayGift';
 
-    const STATUS_NO_BIRTHDAY = 0;
-    const STATUS_PENDING_NOTIFY = 1;
-    const STATUS_PENDING_CLAIM = 2;
-    const STATUS_COLLECTED = 3;
-    const STATUS_EXPIRED = 4;
+    const STATUS_NO_BIRTHDAY = 0;    // 0未填写
+    const STATUS_PENDING_NOTIFY = 1; // 1待通知
+    const STATUS_PENDING_CLAIM = 2;  // 2待领取
+    const STATUS_COLLECTED = 3;      // 3已领取
+    const STATUS_EXPIRED = 4;        // 4超时放弃
 
     const EXPIRE_SECONDS = 86400;
 
@@ -153,7 +154,7 @@ class BirthdayGiftClass extends BaseClass
         return false;
     }
 
-    public static function matchesPeriod($custom, $period)
+    public static function matchesPeriod($custom, $period, $params = [])
     {
         $period = $period ?: 'week';
         if ($period == 'today') {
@@ -162,9 +163,49 @@ class BirthdayGiftClass extends BaseClass
         if ($period == 'tomorrow') {
             return self::matchesBirthdayOffset($custom, 1);
         }
-        return self::matchesBirthdayWeek($custom);
+        if ($period == 'week') {
+            return self::matchesBirthdayWeek($custom);
+        }
+        if ($period == 'all') {
+            return true;
+        }
+        if ($period == 'custom') {
+            return self::matchesCustomPeriod($custom, $params['startDate'] ?? '', $params['endDate'] ?? '');
+        }
+        return false;
+    }
+
+    public static function matchesCustomPeriod($custom, $startDate, $endDate)
+    {
+        $md = self::getBirthdayMonthDay($custom);
+        if (empty($md) || empty($startDate) || empty($endDate)) {
+            return false;
+        }
+        $start = strtotime(date('Y-m-d 00:00:00', strtotime($startDate)));
+        $end = strtotime(date('Y-m-d 23:59:59', strtotime($endDate)));
+        if ($start <= 0 || $end <= 0) {
+            return false;
+        }
+        if ($start > $end) {
+            $tmp = $start;
+            $start = $end;
+            $end = $tmp;
+        }
+        for ($year = intval(date('Y', $start)); $year <= intval(date('Y', $end)); $year++) {
+            $birthday = strtotime($year . '-' . str_pad($md[0], 2, '0', STR_PAD_LEFT) . '-' . str_pad($md[1], 2, '0', STR_PAD_LEFT) . ' 00:00:00');
+            if ($birthday >= $start && $birthday <= $end) {
+                return true;
+            }
+        }
+        return false;
     }
 
+    /**
+     * 获取符合条件的客户
+     * @param $shopId
+     * @param $mainId
+     * @return array
+     */
     public static function getEligibleCustoms($shopId, $mainId)
     {
         $levelMap = self::getLevelBenefitMap($mainId, $shopId);
@@ -178,6 +219,8 @@ class BirthdayGiftClass extends BaseClass
             foreach ($list as $custom) {
                 if (self::hasBirthdayBenefit($custom, $levelMap)) {
                     $result[] = $custom;
+                } else {
+                    noticeUtil::push('客户' . $custom->name . '(' . $custom->member . ')没有生日权益');
                 }
             }
         }
@@ -283,6 +326,12 @@ class BirthdayGiftClass extends BaseClass
         return $gift;
     }
 
+    /**
+     * 确保每年都有记录
+     * @param $shop
+     * @return bool
+     * @throws IntegrityException
+     */
     public static function ensureYearRecords($shop)
     {
         $shopId = intval($shop->id);
@@ -369,7 +418,7 @@ class BirthdayGiftClass extends BaseClass
                 if ($statusFilter < 0 && intval($gift->status) == self::STATUS_NO_BIRTHDAY) {
                     // 全部 Tab 也展示未填写
                 }
-                if (intval($gift->status) != self::STATUS_NO_BIRTHDAY && !self::matchesPeriod($custom, $period)) {
+                if (intval($gift->status) != self::STATUS_NO_BIRTHDAY && !self::matchesPeriod($custom, $period, $params)) {
                     continue;
                 }
                 if (intval($gift->status) == self::STATUS_NO_BIRTHDAY && $period != 'week') {
@@ -428,7 +477,7 @@ class BirthdayGiftClass extends BaseClass
                 }
                 $custom = $customMap[$customId];
                 $st = intval($gift->status);
-                if ($st != self::STATUS_NO_BIRTHDAY && !self::matchesPeriod($custom, $period)) {
+                if ($st != self::STATUS_NO_BIRTHDAY && !self::matchesPeriod($custom, $period, $params)) {
                     continue;
                 }
                 if ($st == self::STATUS_NO_BIRTHDAY && $period != 'week') {
@@ -477,9 +526,9 @@ class BirthdayGiftClass extends BaseClass
                     $name = '未配置礼品';
                 }
                 $st = intval($gift->status);
-                if ($st == self::STATUS_PENDING_CLAIM) {
+                if ($st == self::STATUS_PENDING_NOTIFY) {
                     $pending[$name] = ($pending[$name] ?? 0) + 1;
-                } elseif ($st == self::STATUS_COLLECTED) {
+                } elseif ($st == self::STATUS_PENDING_CLAIM || $st == self::STATUS_COLLECTED) {
                     $collected[$name] = ($collected[$name] ?? 0) + 1;
                 }
             }