From b55f999de8445b7ee0866c484cc479c4728cece7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=B3=E6=B8=85=E7=88=BD?= Date: Thu, 15 May 2025 16:14:48 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=81=E5=9F=9F=E6=93=8D=E7=9B=98=E6=89=8B?= =?UTF-8?q?=20-=20=E8=B0=83=E6=95=B4=E8=B4=A6=E5=8F=B7=E6=9D=83=E9=87=8D?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=E8=A7=84=E5=88=99=EF=BC=8C=E5=BC=95=E5=85=A5?= =?UTF-8?q?=20WechatCustomer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/model/WechatCustomer.php | 21 +++++ ...GetWechatOnDeviceSummarizeV1Controller.php | 81 +++++++++++++------ .../UnitWeight/ActivityWeigth.php | 11 ++- .../AccountWeight/UnitWeight/AgeWeight.php | 14 +++- 4 files changed, 98 insertions(+), 29 deletions(-) create mode 100644 Server/application/common/model/WechatCustomer.php diff --git a/Server/application/common/model/WechatCustomer.php b/Server/application/common/model/WechatCustomer.php new file mode 100644 index 000000000..c467338ca --- /dev/null +++ b/Server/application/common/model/WechatCustomer.php @@ -0,0 +1,21 @@ +WechatCustomerModel)) { + $this->WechatCustomerModel = WechatCustomerModel::where( + [ + 'wechatId' => $wechatId, + 'companyId' => $this->getUserInfo('companyId') + ] + ) + ->find(); + } + + return $this->WechatCustomerModel; + } + + /** + * 计算账号年龄(从创建时间到现在) * * @param string $wechatId * @return string */ protected function getRegisterDate(string $wechatId): string { - return date('Y-m-d H:i:s', strtotime('-' . mt_rand(1, 150) . ' months')); + return $this->getWechatCustomerModel($wechatId)->basic->registerDate ?? date('Y-m-d', time()); } /** - * TODO 获取每天聊天次数。 + * 获取昨日聊天次数 * - * @param string $wechatId + * @param WechatCustomerModel $customer * @return int */ - protected function getChatTimesPerDay(string $wechatId): int + protected function getChatTimesPerDay(?WechatCustomerModel $customer): int { - return mt_rand(0, 100); + return $customer->activity->yesterdayMsgCount ?? 0; } /** - * TODO 总聊天数量 + * 总聊天数量 * - * @param string $wechatId + * @param WechatCustomerModel $customer * @return int */ - protected function getChatTimesTotal(string $wechatId): int + protected function getChatTimesTotal(?WechatCustomerModel $customer): int { - return mt_rand(100, 1000000); + return $customer->activity->totalMsgCount ?? 0; } /** @@ -55,9 +79,11 @@ class GetWechatOnDeviceSummarizeV1Controller extends BaseController */ protected function getActivityLevel(string $wechatId): array { + $customer = $this->getWechatCustomerModel($wechatId); + return [ - 'allTimes' => $this->getChatTimesTotal($wechatId), - 'dayTimes' => $this->getChatTimesPerDay($wechatId), + 'allTimes' => $this->getChatTimesTotal($customer), + 'dayTimes' => $this->getChatTimesPerDay($customer), ]; } @@ -87,17 +113,23 @@ class GetWechatOnDeviceSummarizeV1Controller extends BaseController */ protected function getAccountWeight(string $wechatId): array { - // 微信账号加友权重评估 - $assessment = $this->classTable->getInstance(WeightAssessment::class); - $assessment->settingFactor($wechatId); + $customer = $this->getWechatCustomerModel($wechatId); + $seeders = $customer ? (array)$customer->weight : array(); - return [ - 'ageWeight' => $assessment->calculAgeWeight()->getResult(), // 账号年龄权重 - 'activityWeigth' => $assessment->calculActivityWeigth()->getResult(), // 计算活跃度权重 - 'restrictWeight' => $assessment->calculRestrictWeigth()->getResult(), // 计算限制影响权重 - 'realNameWeight' => $assessment->calculRealNameWeigth()->getResult(), // 计算实名认证权重 - 'scope' => $assessment->getWeightScope(), // 计算总分 - ]; + // 严谨返回 + return ArrHelper::getValue('ageWeight,activityWeigth,restrictWeight,realNameWeight,scope', $seeders, 0); + } + + /** + * 获取当日最高添加好友记录 + * + * @param string $wechatId + * @return int + * @throws \Exception + */ + protected function getAccountWeightAddLimit(string $wechatId): int + { + return $this->getWechatCustomerModel($wechatId)->weight->addLimit ?? 0; } /** @@ -128,10 +160,7 @@ class GetWechatOnDeviceSummarizeV1Controller extends BaseController { return [ 'todayAdded' => $this->getTodayNewFriendCount($wechatId), - 'addLimit' => (new LimitAssessment()) - ->maxLimit( - $this->classTable->getInstance(WeightAssessment::class) - ), + 'addLimit' => $this->getAccountWeightAddLimit($wechatId) ]; } diff --git a/Server/extend/AccountWeight/UnitWeight/ActivityWeigth.php b/Server/extend/AccountWeight/UnitWeight/ActivityWeigth.php index f3f36835c..dde5f9e32 100644 --- a/Server/extend/AccountWeight/UnitWeight/ActivityWeigth.php +++ b/Server/extend/AccountWeight/UnitWeight/ActivityWeigth.php @@ -2,6 +2,7 @@ namespace AccountWeight\UnitWeight; +use app\common\model\WechatCustomer as WechatCustomerModel; use library\interfaces\WechatAccountWeightResultSet as WechatAccountWeightResultSetInterface; class ActivityWeigth implements WechatAccountWeightResultSetInterface @@ -16,7 +17,15 @@ class ActivityWeigth implements WechatAccountWeightResultSetInterface */ private function getChatTimesPerDay(string $wechatId): int { - return mt_rand(0, 100); + $activity = (string)WechatCustomerModel::where([ + 'wechatId' => $wechatId, + ] + ) + ->value('activity'); + + $activity = json_decode($activity, true); + + return $activity->yesterdayMsgCount ?? 0; } /** diff --git a/Server/extend/AccountWeight/UnitWeight/AgeWeight.php b/Server/extend/AccountWeight/UnitWeight/AgeWeight.php index fef778f65..6025ebfc9 100644 --- a/Server/extend/AccountWeight/UnitWeight/AgeWeight.php +++ b/Server/extend/AccountWeight/UnitWeight/AgeWeight.php @@ -2,6 +2,7 @@ namespace AccountWeight\UnitWeight; +use app\common\model\WechatCustomer as WechatCustomerModel; use library\interfaces\WechatAccountWeightResultSet as WechatAccountWeightResultSetInterface; class AgeWeight implements WechatAccountWeightResultSetInterface @@ -16,7 +17,16 @@ class AgeWeight implements WechatAccountWeightResultSetInterface */ private function getRegisterDate(string $wechatId): string { - return date('Y-m-d H:i:s', strtotime('-15 months')); + $basic = (string)WechatCustomerModel::where([ + 'wechatId' => $wechatId, + ] + ) + ->value('basic'); + + $basic = json_decode($basic, true); + + // 如果没有设置账号注册时间,则默认今天,即账号年龄为0 + return $basic && isset($basic->registerDate) ? $basic->registerDate : date('Y-m-d', time()); } /** @@ -28,7 +38,7 @@ class AgeWeight implements WechatAccountWeightResultSetInterface */ private function getDateTimeDiff(string $wechatId): int { - $currentData = new \DateTime(date('Y-m-d H:i:s', time())); + $currentData = new \DateTime(date('Y-m-d', time())); $registerDate = new \DateTime($this->getRegisterDate($wechatId)); $interval = date_diff($currentData, $registerDate);