存客宝应用接口初始化

This commit is contained in:
Ghost
2026-01-05 10:25:32 +08:00
parent fa37227954
commit 02797ba50a
414 changed files with 85530 additions and 75 deletions

View File

@@ -0,0 +1,49 @@
<?php
namespace AccountWeight\UnitWeight;
use app\common\model\WechatCustomer as WechatCustomerModel;
use library\Interfaces\WechatAccountWeightResultSet as WechatAccountWeightResultSetInterface;
class ActivityWeigth implements WechatAccountWeightResultSetInterface
{
private $weight;
/**
* 获取每天聊天次数。
*
* @param string $wechatId
* @return int
*/
private function getChatTimesPerDay(string $wechatId): int
{
$activity = (string)WechatCustomerModel::where([
'wechatId' => $wechatId,
]
)
->value('activity');
return json_decode($activity)->yesterdayMsgCount ?? 0;
}
/**
* @inheritDoc
*/
public function settingFactor($wechatId): WechatAccountWeightResultSetInterface
{
$times = intval($this->getChatTimesPerDay($wechatId) / 50 * 100);
// 规定每天发送50条消息起拥有最高权重
$this->weight = $times > 100 ? 100 : $times;
return $this;
}
/**
* @inheritDoc
*/
public function getResult(): int
{
return $this->weight ?: 0;
}
}

View File

@@ -0,0 +1,69 @@
<?php
namespace AccountWeight\UnitWeight;
use app\common\model\WechatCustomer as WechatCustomerModel;
use library\Interfaces\WechatAccountWeightResultSet as WechatAccountWeightResultSetInterface;
class AgeWeight implements WechatAccountWeightResultSetInterface
{
private $weight;
/**
* 计算账号年龄(从创建时间到现在)
*
* @param string $wechatId
* @return string
*/
private function getRegisterDate(string $wechatId): string
{
$basic = (string)WechatCustomerModel::where([
'wechatId' => $wechatId,
]
)
->value('basic');
$basic = json_decode($basic);
// 如果没有设置账号注册时间则默认今天即账号年龄为0
return $basic && isset($basic->registerDate) ? $basic->registerDate : date('Y-m-d', time());
}
/**
* 计算两个时间相差几个月
*
* @param string $wechatId
* @return int
* @throws \DateMalformedStringException
*/
private function getDateTimeDiff(string $wechatId): int
{
$currentData = new \DateTime(date('Y-m-d', time()));
$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;
}
}

View File

@@ -0,0 +1,39 @@
<?php
namespace AccountWeight\UnitWeight;
use library\Interfaces\WechatAccountWeightResultSet as WechatAccountWeightResultSetInterface;
class RealNameWeight implements WechatAccountWeightResultSetInterface
{
private $weight;
/**
* 使用微信要求必须得实名,所以统一返回满分
*
* @return int
*/
private function hereWeGo(): int
{
return 100;
}
/**
* @inheritDoc
*/
public function settingFactor($wechatId): WechatAccountWeightResultSetInterface
{
$this->weight = $this->hereWeGo();
return $this;
}
/**
* @inheritDoc
*/
public function getResult(): int
{
return $this->weight ?: 0;
}
}

View File

@@ -0,0 +1,50 @@
<?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;
}
}