2025-05-14 18:30:09 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
namespace AccountWeight\UnitWeight;
|
|
|
|
|
|
|
2025-05-15 16:14:48 +08:00
|
|
|
|
use app\common\model\WechatCustomer as WechatCustomerModel;
|
2025-05-14 18:30:09 +08:00
|
|
|
|
use library\interfaces\WechatAccountWeightResultSet as WechatAccountWeightResultSetInterface;
|
|
|
|
|
|
|
|
|
|
|
|
class AgeWeight implements WechatAccountWeightResultSetInterface
|
|
|
|
|
|
{
|
|
|
|
|
|
private $weight;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 计算账号年龄(从创建时间到现在)
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param string $wechatId
|
|
|
|
|
|
* @return string
|
|
|
|
|
|
*/
|
|
|
|
|
|
private function getRegisterDate(string $wechatId): string
|
|
|
|
|
|
{
|
2025-05-15 16:14:48 +08:00
|
|
|
|
$basic = (string)WechatCustomerModel::where([
|
|
|
|
|
|
'wechatId' => $wechatId,
|
|
|
|
|
|
]
|
|
|
|
|
|
)
|
|
|
|
|
|
->value('basic');
|
|
|
|
|
|
|
2025-05-15 17:10:51 +08:00
|
|
|
|
$basic = json_decode($basic);
|
2025-05-15 16:14:48 +08:00
|
|
|
|
|
|
|
|
|
|
// 如果没有设置账号注册时间,则默认今天,即账号年龄为0
|
|
|
|
|
|
return $basic && isset($basic->registerDate) ? $basic->registerDate : date('Y-m-d', time());
|
2025-05-14 18:30:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 计算两个时间相差几个月
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param string $wechatId
|
|
|
|
|
|
* @return int
|
|
|
|
|
|
* @throws \DateMalformedStringException
|
|
|
|
|
|
*/
|
|
|
|
|
|
private function getDateTimeDiff(string $wechatId): int
|
|
|
|
|
|
{
|
2025-05-15 16:14:48 +08:00
|
|
|
|
$currentData = new \DateTime(date('Y-m-d', time()));
|
2025-05-14 18:30:09 +08:00
|
|
|
|
$registerDate = new \DateTime($this->getRegisterDate($wechatId));
|
|
|
|
|
|
|
|
|
|
|
|
$interval = date_diff($currentData, $registerDate);
|
|
|
|
|
|
|
|
|
|
|
|
return $interval->y * 12 + $interval->m;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @inheritDoc
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function settingFactor($wechatId): WechatAccountWeightResultSetInterface
|
|
|
|
|
|
{
|
|
|
|
|
|
$cha = ceil($this->getDateTimeDiff($wechatId) / 60) * 100;
|
|
|
|
|
|
|
|
|
|
|
|
// 规定账号年龄五年起拥有最高权重
|
|
|
|
|
|
$this->weight = $cha > 100 ? 100 : $cha;
|
|
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @inheritDoc
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function getResult(): int
|
|
|
|
|
|
{
|
|
|
|
|
|
return $this->weight ?: 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|