私域操盘手 - 调整账号权重计算规则,引入 WechatCustomer

This commit is contained in:
柳清爽
2025-05-15 16:14:48 +08:00
parent 2fec134ad7
commit b55f999de8
4 changed files with 98 additions and 29 deletions

View File

@@ -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;
}
/**

View File

@@ -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);