Files
cunkebao_v3/Server/extend/AccountWeight/UnitWeight/RestrictWeight.php

50 lines
1.2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace AccountWeight\UnitWeight;
use app\common\model\WechatRestricts as WechatRestrictsModel;
use library\interfaces\WechatAccountWeightResultSet as WechatAccountWeightResultSetInterface;
class RestrictWeight implements WechatAccountWeightResultSetInterface
{
private $weight;
/**
* 获取限制记录
*
* @param string $wechatId
* @return int
*/
private function getRestrictCount(string $wechatId): int
{
return WechatRestrictsModel::alias('r')
->field(
[
'r.id', 'r.restrictTime date', 'r.level', 'r.reason'
]
)
->where('r.wechatId', $wechatId)->select()
->count('*');
}
/**
* @inheritDoc
*/
public function settingFactor($wechatId): WechatAccountWeightResultSetInterface
{
$restrict = 10 - $this->getRestrictCount($wechatId);
// 规定没有限制记录拥有最高权重10条以上权重为0
$this->weight = ($restrict < 0 ? 0 : $restrict) * 10;
return $this;
}
/**
* @inheritDoc
*/
public function getResult(): int
{
return $this->weight ?: 0;
}
}