From 121b714d710cf3c865f4a1b5efe81abec11056d1 Mon Sep 17 00:00:00 2001
From: quanwei <419654421@qq.com>
Date: Sat, 01 Nov 2025 14:36:36 +0800
Subject: [PATCH] 修复名片模板生成失败问题 修复后台名片查看不显示头像和logo问题

---
 admin/app/common.php |  123 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 123 insertions(+), 0 deletions(-)

diff --git a/admin/app/common.php b/admin/app/common.php
index 0cf82bf..50dc019 100644
--- a/admin/app/common.php
+++ b/admin/app/common.php
@@ -392,4 +392,127 @@
     }
 
     return json_decode($decrypted,true);
+}
+
+/**
+ * @param BaseQuery $model
+ * @param string $section
+ * @param string $prefix
+ * @param string $field
+ * @return mixed
+ */
+function getModelTime($model, string $section, $prefix = 'create_time', $field = '-',$time = '')
+{
+    if (!isset($section)) return $model;
+    switch ($section) {
+        case 'today':
+            $model->whereBetween($prefix, [strtotime('today'), strtotime('tomorrow -1second')]);
+            break;
+        case 'week':
+            $model->whereBetween($prefix, [strtotime('this week 00:00:00'), strtotime('next week 00:00:00 -1second')]);
+            break;
+        case 'month':
+            $model->whereBetween($prefix, [strtotime('first Day of this month 00:00:00'), strtotime('first Day of next month 00:00:00 -1second')]);
+            break;
+        case 'year':
+            $model->whereBetween($prefix, [strtotime('this year 1/1'), strtotime('next year 1/1 -1second')]);
+            break;
+        case 'yesterday':
+            $model->whereBetween($prefix, [strtotime('yesterday'), strtotime('today -1second')]);
+            break;
+        case 'quarter':
+            list($startTime, $endTime) = getMonth();
+            $model = $model->where($prefix, '>', $startTime);
+            $model = $model->where($prefix, '<', $endTime);
+            break;
+        case 'lately7':
+            $model = $model->where($prefix, 'between', [strtotime("-7 day"), strtotime(date('Y-m-d H:i:s'))]);
+            break;
+        case 'lately30':
+            $model = $model->where($prefix, 'between', [strtotime("-30 day"), strtotime(date('Y-m-d H:i:s'))]);
+            break;
+        default:
+            if (strstr($section, $field) !== false) {
+                list($startTime, $endTime) = explode($field, $section);
+                if (strlen($startTime) == 4) {
+                    $model->whereBetweenTime($prefix, strtotime($section), strtotime($section . ' +1day -1second'));
+                } else {
+                    if ($startTime == $endTime) {
+                        $model = $model->whereBetweenTime($prefix, strtotime(date('Y-m-d 0:0:0', strtotime($startTime))), strtotime(date('Y-m-d 23:59:59', strtotime($endTime))));
+                    } else if(strpos($startTime, ':')) {
+                        $model = $model->whereBetweenTime($prefix, $startTime, $endTime);
+                    } else {
+                        $model = $model->whereBetweenTime($prefix, strtotime($startTime), strtotime($endTime . ' +1day -1second'));
+                    }
+                }
+            }
+            break;
+    }
+    return $model;
+}
+
+function getDatesBetweenTwoDays($startDate, $endDate, $md = 'm-d')
+{
+    $dates = [];
+    if (strtotime($startDate) > strtotime($endDate)) {
+        //如果开始日期大于结束日期,直接return 防止下面的循环出现死循环
+        return $dates;
+    } elseif ($startDate == $endDate) {
+        //开始日期与结束日期是同一天时
+        array_push($dates, date($md, strtotime($startDate)));
+        return $dates;
+    } else {
+        array_push($dates, date($md, strtotime($startDate)));
+        $currentDate = $startDate;
+        do {
+            $nextDate = date('Y-m-d', strtotime($currentDate . ' +1 days'));
+            array_push($dates, date($md, strtotime($currentDate . ' +1 days')));
+            $currentDate = $nextDate;
+        } while ($endDate != $currentDate);
+        return $dates;
+    }
+}
+
+function getStartModelTime(string $section)
+{
+    switch ($section) {
+        case 'today':
+        case 'yesterday':
+            return date('Y-m-d', strtotime($section));
+        case 'week':
+            return date('Y-m-d', strtotime('this week'));
+        case 'month':
+            return date('Y-m-d', strtotime('first Day of this month'));
+        case 'year':
+            return date('Y-m-d', strtotime('this year 1/1'));
+        case 'quarter':
+            list($startTime, $endTime) = getMonth();
+            return $startTime;
+        case 'lately7':
+            return date('Y-m-d', strtotime("-7 day"));
+        case 'lately30':
+            return date('Y-m-d', strtotime("-30 day"));
+        default:
+            if (strstr($section, '-') !== false) {
+                list($startTime, $endTime) = explode('-', $section);
+                return date('Y-m-d H:i:s', strtotime($startTime));
+            }
+            return date('Y-m-d H:i:s');
+    }
+}
+/**
+ * 获取本季度 time
+ * @param int|string $time
+ * @param $ceil
+ * @return array
+ */
+function getMonth($time = '', $ceil = 0)
+{
+    if ($ceil != 0)
+        $season = ceil(date('n') / 3) - $ceil;
+    else
+        $season = ceil(date('n') / 3);
+    $firstday = date('Y-m-01', mktime(0, 0, 0, ($season - 1) * 3 + 1, 1, date('Y')));
+    $lastday = date('Y-m-t', mktime(0, 0, 0, $season * 3, 1, date('Y')));
+    return array($firstday, $lastday);
 }
\ No newline at end of file

--
Gitblit v1.9.2