2025-05-14 18:30:09 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
namespace AccountWeight;
|
|
|
|
|
|
|
|
|
|
|
|
use AccountWeight\Exceptions\WechatAccountWeightAssessmentException as WeightAssessmentException;
|
|
|
|
|
|
use library\ClassTable;
|
2025-10-23 09:51:43 +08:00
|
|
|
|
use library\Interfaces\WechatAccountWeightResultSet as WechatAccountWeightResultSetInterface;
|
|
|
|
|
|
use library\Interfaces\WechatAccountWeightAssessment as WechatAccountWeightAssessmentInterface;
|
2025-05-15 10:20:20 +08:00
|
|
|
|
use AccountWeight\UnitWeight;
|
|
|
|
|
|
use app\common\service\ClassTableService;
|
2025-05-14 18:30:09 +08:00
|
|
|
|
|
|
|
|
|
|
class WechatAccountWeightAssessment implements WechatAccountWeightAssessmentInterface
|
|
|
|
|
|
{
|
|
|
|
|
|
private $wechatId;
|
|
|
|
|
|
private $ageWeight;
|
|
|
|
|
|
private $activityWeigth;
|
|
|
|
|
|
private $restrictWeight;
|
|
|
|
|
|
private $realNameWeight;
|
2025-05-15 10:20:20 +08:00
|
|
|
|
protected $classTable;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 依赖注入
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param ClassTableService|null $classTable
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function __construct(ClassTableService $classTable = null)
|
|
|
|
|
|
{
|
|
|
|
|
|
$this->classTable = $classTable ?? app('ClassTable');
|
|
|
|
|
|
}
|
2025-05-14 18:30:09 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取言
|
|
|
|
|
|
* @return string
|
|
|
|
|
|
* @throws WechatAccountWeightAssessmentException
|
|
|
|
|
|
*/
|
|
|
|
|
|
private function getWechatId(): string
|
|
|
|
|
|
{
|
|
|
|
|
|
if (empty($this->wechatId)) {
|
|
|
|
|
|
throw new WeightAssessmentException('缺少验证参数');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return $this->wechatId;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @inheritDoc
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function calculAgeWeight(): WechatAccountWeightResultSetInterface
|
|
|
|
|
|
{
|
2025-05-15 10:20:20 +08:00
|
|
|
|
$AgeWeight = $this->classTable->getInstance(UnitWeight\AgeWeight::class);
|
2025-05-14 18:30:09 +08:00
|
|
|
|
|
|
|
|
|
|
if (!$this->ageWeight) {
|
|
|
|
|
|
$this->ageWeight = $AgeWeight->settingFactor(
|
|
|
|
|
|
$this->getWechatId()
|
|
|
|
|
|
)
|
|
|
|
|
|
->getResult();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return $AgeWeight;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @inheritDoc
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function calculActivityWeigth(): WechatAccountWeightResultSetInterface
|
|
|
|
|
|
{
|
2025-05-15 10:20:20 +08:00
|
|
|
|
$ActivityWeigth = $this->classTable->getInstance(UnitWeight\ActivityWeigth::class);
|
2025-05-14 18:30:09 +08:00
|
|
|
|
|
|
|
|
|
|
if (!$this->activityWeigth) {
|
|
|
|
|
|
$this->activityWeigth = $ActivityWeigth->settingFactor(
|
|
|
|
|
|
$this->getWechatId()
|
|
|
|
|
|
)
|
|
|
|
|
|
->getResult();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return $ActivityWeigth;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @inheritDoc
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function calculRestrictWeigth(): WechatAccountWeightResultSetInterface
|
|
|
|
|
|
{
|
2025-05-15 10:20:20 +08:00
|
|
|
|
$RestrictWeight = $this->classTable->getInstance(UnitWeight\RestrictWeight::class);
|
2025-05-14 18:30:09 +08:00
|
|
|
|
|
|
|
|
|
|
if (!$this->restrictWeight) {
|
|
|
|
|
|
$this->restrictWeight = $RestrictWeight->settingFactor(
|
|
|
|
|
|
$this->getWechatId()
|
|
|
|
|
|
)
|
|
|
|
|
|
->getResult();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return $RestrictWeight;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @inheritDoc
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function calculRealNameWeigth(): WechatAccountWeightResultSetInterface
|
|
|
|
|
|
{
|
2025-05-15 10:20:20 +08:00
|
|
|
|
$AccountWeight = $this->classTable->getInstance(UnitWeight\RealNameWeight::class);
|
2025-05-14 18:30:09 +08:00
|
|
|
|
|
|
|
|
|
|
if (!$this->realNameWeight) {
|
|
|
|
|
|
$this->realNameWeight = $AccountWeight->settingFactor(
|
|
|
|
|
|
$this->getWechatId()
|
|
|
|
|
|
)
|
|
|
|
|
|
->getResult();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return $AccountWeight;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @inheritDoc
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function getWeightScope(): int
|
|
|
|
|
|
{
|
|
|
|
|
|
return ceil(
|
|
|
|
|
|
(
|
|
|
|
|
|
$this->calculAgeWeight()->getResult() +
|
|
|
|
|
|
$this->calculActivityWeigth()->getResult() +
|
|
|
|
|
|
$this->calculRestrictWeigth()->getResult() +
|
|
|
|
|
|
$this->calculRealNameWeigth()->getResult()
|
|
|
|
|
|
) / 4);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @inheritDoc
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function settingFactor($params): WechatAccountWeightAssessmentInterface
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!is_string($params)) {
|
|
|
|
|
|
throw new WeightAssessmentException('参数错误,只能传微信ID');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$this->wechatId = $params;
|
|
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|