2025-05-10 12:02:19 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
namespace app\cunkebao\controller\wechat;
|
|
|
|
|
|
|
|
|
|
|
|
use app\common\model\WechatAccount as WechatAccountModel;
|
2025-05-12 15:32:42 +08:00
|
|
|
|
use app\common\model\WechatFriendShip as WechatFriendShipModel;
|
2025-05-10 12:02:19 +08:00
|
|
|
|
use app\cunkebao\controller\BaseController;
|
2025-05-10 18:40:53 +08:00
|
|
|
|
use library\ResponseHelper;
|
2025-05-10 12:02:19 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 设备微信控制器
|
|
|
|
|
|
*/
|
|
|
|
|
|
class GetWechatOnDeviceSummarizeV1Controller extends BaseController
|
|
|
|
|
|
{
|
2025-05-10 18:40:53 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* TODO 计算账号年龄(从创建时间到现在)
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param string $wechatId
|
|
|
|
|
|
* @return string
|
|
|
|
|
|
*/
|
|
|
|
|
|
protected function getRegisterDate(string $wechatId): string
|
|
|
|
|
|
{
|
|
|
|
|
|
return date('Y-m-d H:i:s', strtotime('-15 months'));
|
|
|
|
|
|
}
|
2025-05-10 12:02:19 +08:00
|
|
|
|
|
2025-05-10 18:40:53 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* TODO 获取每天聊天次数。
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param string $wechatId
|
|
|
|
|
|
* @return int
|
|
|
|
|
|
*/
|
|
|
|
|
|
protected function getChatTimesPerDay(string $wechatId): int
|
2025-05-10 12:02:19 +08:00
|
|
|
|
{
|
2025-05-10 18:40:53 +08:00
|
|
|
|
return mt_rand(0, 100);
|
2025-05-10 12:02:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-10 18:40:53 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* TODO 总聊天数量
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param string $wechatId
|
|
|
|
|
|
* @return int
|
|
|
|
|
|
*/
|
|
|
|
|
|
protected function getChatTimesTotal(string $wechatId): int
|
|
|
|
|
|
{
|
|
|
|
|
|
return mt_rand(2000, 1000000);
|
|
|
|
|
|
}
|
2025-05-10 12:02:19 +08:00
|
|
|
|
|
2025-05-10 18:40:53 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 计算活跃程度(根据消息数)
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param string $wechatId
|
|
|
|
|
|
* @return string
|
|
|
|
|
|
*/
|
|
|
|
|
|
protected function getActivityLevel(string $wechatId): array
|
|
|
|
|
|
{
|
|
|
|
|
|
return [
|
|
|
|
|
|
'allTimes' => $this->getChatTimesTotal($wechatId),
|
|
|
|
|
|
'dayTimes' => $this->getChatTimesPerDay($wechatId),
|
|
|
|
|
|
];
|
|
|
|
|
|
}
|
2025-05-10 12:02:19 +08:00
|
|
|
|
|
2025-05-10 18:40:53 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* TODO 获取限制记录
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param string $wechatId
|
|
|
|
|
|
* @return array
|
|
|
|
|
|
*/
|
|
|
|
|
|
protected function getRestrict(string $wechatId): array
|
2025-05-10 12:02:19 +08:00
|
|
|
|
{
|
2025-05-10 18:40:53 +08:00
|
|
|
|
return [
|
|
|
|
|
|
[
|
|
|
|
|
|
'id' => 1,
|
2025-05-12 11:58:13 +08:00
|
|
|
|
'level' => 2,
|
2025-05-10 18:40:53 +08:00
|
|
|
|
'reason' => '频繁添加好友',
|
|
|
|
|
|
'date' => date('Y-m-d H:i:s', strtotime('-1 day')),
|
|
|
|
|
|
],
|
|
|
|
|
|
[
|
|
|
|
|
|
'id' => 2,
|
2025-05-12 11:58:13 +08:00
|
|
|
|
'level' => 3,
|
2025-05-10 18:40:53 +08:00
|
|
|
|
'reason' => '营销内容违规',
|
|
|
|
|
|
'date' => date('Y-m-d H:i:s', strtotime('-1 day')),
|
|
|
|
|
|
],
|
|
|
|
|
|
];
|
|
|
|
|
|
}
|
2025-05-10 12:02:19 +08:00
|
|
|
|
|
2025-05-10 18:40:53 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 计算两个时间相差几个月
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param string $wechatId
|
|
|
|
|
|
* @return float|int
|
|
|
|
|
|
* @throws \DateMalformedStringException
|
|
|
|
|
|
*/
|
|
|
|
|
|
protected function getDateDiff(string $wechatId): int
|
|
|
|
|
|
{
|
|
|
|
|
|
$currentData = new \DateTime(date('Y-m-d H:i:s', time()));
|
|
|
|
|
|
$registerDate = new \DateTime($this->getRegisterDate($wechatId));
|
2025-05-10 12:02:19 +08:00
|
|
|
|
|
2025-05-10 18:40:53 +08:00
|
|
|
|
$interval = date_diff($currentData, $registerDate);
|
2025-05-10 12:02:19 +08:00
|
|
|
|
|
2025-05-10 18:40:53 +08:00
|
|
|
|
return $interval->y * 12 + $interval->m;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 计算账号年龄权重
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param string $wechatId
|
|
|
|
|
|
* @return int
|
|
|
|
|
|
* @throws \DateMalformedStringException
|
|
|
|
|
|
*/
|
|
|
|
|
|
protected function _calculAgeWeight(string $wechatId): int
|
|
|
|
|
|
{
|
|
|
|
|
|
// 规定账号年龄五年起拥有最高权重
|
|
|
|
|
|
$cha = ceil($this->getDateDiff($wechatId) / 60) * 100;
|
2025-05-10 12:02:19 +08:00
|
|
|
|
|
2025-05-10 18:40:53 +08:00
|
|
|
|
return $cha > 100 ? 100 : $cha;
|
2025-05-10 12:02:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-10 18:40:53 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 计算活跃度权重
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param string $wechatId
|
|
|
|
|
|
* @return int
|
|
|
|
|
|
*/
|
|
|
|
|
|
protected function _calActivityWeigth(string $wechatId): int
|
|
|
|
|
|
{
|
|
|
|
|
|
// 规定每天发送50条消息起拥有最高权重
|
|
|
|
|
|
$cha = ceil($this->getChatTimesPerDay($wechatId) / 50) * 100;
|
2025-05-10 12:02:19 +08:00
|
|
|
|
|
2025-05-10 18:40:53 +08:00
|
|
|
|
return $cha > 100 ? 100 : $cha;
|
|
|
|
|
|
}
|
2025-05-10 12:02:19 +08:00
|
|
|
|
|
2025-05-10 18:40:53 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 计算限制影响权重
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param string $wechatId
|
|
|
|
|
|
* @return int
|
|
|
|
|
|
*/
|
|
|
|
|
|
protected function _calRestrictWeigth(string $wechatId): int
|
|
|
|
|
|
{
|
|
|
|
|
|
$list = $this->getRestrict($wechatId); // 2
|
|
|
|
|
|
$gtmd = 10 - count($list); // 规定没有限制记录拥有最高权重,10条以上权重为0
|
|
|
|
|
|
|
|
|
|
|
|
return ($gtmd < 0 ? 0 : $gtmd) * 10;
|
|
|
|
|
|
}
|
2025-05-10 12:02:19 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
2025-05-10 18:40:53 +08:00
|
|
|
|
* 计算实名认证权重
|
2025-05-10 12:02:19 +08:00
|
|
|
|
*
|
2025-05-10 18:40:53 +08:00
|
|
|
|
* @param string $wechatId
|
|
|
|
|
|
* @return int
|
2025-05-10 12:02:19 +08:00
|
|
|
|
*/
|
2025-05-10 18:40:53 +08:00
|
|
|
|
protected function _calRealNameWeigth(string $wechatId): int
|
2025-05-10 12:02:19 +08:00
|
|
|
|
{
|
2025-05-10 18:40:53 +08:00
|
|
|
|
return 100;
|
|
|
|
|
|
}
|
2025-05-10 12:02:19 +08:00
|
|
|
|
|
2025-05-10 18:40:53 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 计算好友数量(每5权重=1好友,最多20个)
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param int $weight
|
|
|
|
|
|
* @return int
|
|
|
|
|
|
*/
|
|
|
|
|
|
protected function _calAllowedFriends(int $weight): int
|
|
|
|
|
|
{
|
|
|
|
|
|
$adjustedWeight = $weight;
|
|
|
|
|
|
$lastDigit = $weight % 10;
|
2025-05-10 12:02:19 +08:00
|
|
|
|
|
2025-05-10 18:40:53 +08:00
|
|
|
|
if ($weight < 10) {
|
|
|
|
|
|
if ($lastDigit < 5) {
|
|
|
|
|
|
$adjustedWeight = 5;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$adjustedWeight = 10;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-05-10 12:02:19 +08:00
|
|
|
|
|
2025-05-10 18:40:53 +08:00
|
|
|
|
return min(20, floor($adjustedWeight / 5));
|
|
|
|
|
|
}
|
2025-05-10 12:02:19 +08:00
|
|
|
|
|
2025-05-10 18:40:53 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 获取账号权重
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param string $wechatId
|
|
|
|
|
|
* @return array
|
|
|
|
|
|
*/
|
|
|
|
|
|
protected function getAccountWeight(string $wechatId): array
|
|
|
|
|
|
{
|
|
|
|
|
|
$ageWeight = $this->_calculAgeWeight($wechatId); // 账号年龄权重
|
|
|
|
|
|
$activityWeigth = $this->_calActivityWeigth($wechatId); // 计算活跃度权重
|
|
|
|
|
|
$restrictWeight = $this->_calRestrictWeigth($wechatId); // 计算限制影响权重
|
|
|
|
|
|
$realNameWeight = $this->_calRealNameWeigth($wechatId); // 计算实名认证权重
|
2025-05-10 12:02:19 +08:00
|
|
|
|
|
2025-05-10 18:40:53 +08:00
|
|
|
|
$scope = ceil(($ageWeight + $activityWeigth + $restrictWeight + $realNameWeight) / 4); // 计算总分
|
2025-05-10 12:02:19 +08:00
|
|
|
|
|
2025-05-10 18:40:53 +08:00
|
|
|
|
return compact(
|
|
|
|
|
|
'scope',
|
|
|
|
|
|
'ageWeight',
|
|
|
|
|
|
'activityWeigth',
|
|
|
|
|
|
'restrictWeight',
|
|
|
|
|
|
'realNameWeight'
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
2025-05-10 12:02:19 +08:00
|
|
|
|
|
2025-05-10 18:40:53 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 计算今日新增好友数量
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param string $ownerWechatId
|
|
|
|
|
|
* @return int
|
|
|
|
|
|
*/
|
|
|
|
|
|
protected function getTodayNewFriendCount(string $ownerWechatId): int
|
|
|
|
|
|
{
|
2025-05-12 15:32:42 +08:00
|
|
|
|
return WechatFriendShipModel::where( compact('ownerWechatId') )
|
2025-05-10 18:40:53 +08:00
|
|
|
|
->whereBetween('createTime',
|
|
|
|
|
|
[
|
|
|
|
|
|
strtotime(date('Y-m-d 00:00:00')),
|
|
|
|
|
|
strtotime(date('Y-m-d 23:59:59'))
|
|
|
|
|
|
]
|
|
|
|
|
|
)
|
|
|
|
|
|
->count('*');
|
|
|
|
|
|
}
|
2025-05-10 12:02:19 +08:00
|
|
|
|
|
2025-05-10 18:40:53 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 获取账号加友统计数据.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param string $wechatId
|
|
|
|
|
|
* @param array $accountWeight
|
|
|
|
|
|
* @return array
|
|
|
|
|
|
*/
|
|
|
|
|
|
protected function getStatistics(string $wechatId, array $accountWeight): array
|
|
|
|
|
|
{
|
|
|
|
|
|
return [
|
2025-05-12 11:58:13 +08:00
|
|
|
|
'todayAdded' => $this->getTodayNewFriendCount($wechatId),
|
2025-05-10 18:40:53 +08:00
|
|
|
|
'addLimit' => $this->_calAllowedFriends($accountWeight['scope'])
|
|
|
|
|
|
];
|
|
|
|
|
|
}
|
2025-05-10 12:02:19 +08:00
|
|
|
|
|
2025-05-10 18:40:53 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 获取原始的64位的微信id
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return string
|
|
|
|
|
|
* @throws \Exception
|
|
|
|
|
|
*/
|
2025-05-12 15:32:42 +08:00
|
|
|
|
protected function getStringWechatIdByNumberId(): string
|
2025-05-10 18:40:53 +08:00
|
|
|
|
{
|
2025-05-12 15:32:42 +08:00
|
|
|
|
$account = WechatAccountModel::find(
|
|
|
|
|
|
$this->request->param('id/d')
|
|
|
|
|
|
);
|
2025-05-10 12:02:19 +08:00
|
|
|
|
|
2025-05-10 18:40:53 +08:00
|
|
|
|
if (is_null($account)) {
|
|
|
|
|
|
throw new \Exception('微信账号不存在', 404);
|
|
|
|
|
|
}
|
2025-05-10 12:02:19 +08:00
|
|
|
|
|
2025-05-10 18:40:53 +08:00
|
|
|
|
return $account->wechatId;
|
|
|
|
|
|
}
|
2025-05-10 12:02:19 +08:00
|
|
|
|
|
2025-05-10 18:40:53 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 获取微信号详情
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return \think\response\Json
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function index()
|
|
|
|
|
|
{
|
|
|
|
|
|
try {
|
2025-05-12 15:32:42 +08:00
|
|
|
|
$wechatId = $this->getStringWechatIdByNumberId();
|
2025-05-10 12:02:19 +08:00
|
|
|
|
|
2025-05-12 15:32:42 +08:00
|
|
|
|
// 以下内容依次加工数据
|
2025-05-10 18:40:53 +08:00
|
|
|
|
$accountAge = $this->getRegisterDate($wechatId);
|
|
|
|
|
|
$activityLevel = $this->getActivityLevel($wechatId);
|
|
|
|
|
|
$accountWeight = $this->getAccountWeight($wechatId);
|
|
|
|
|
|
$statistics = $this->getStatistics($wechatId, $accountWeight);
|
|
|
|
|
|
$restrictions = $this->getRestrict($wechatId);
|
2025-05-10 12:02:19 +08:00
|
|
|
|
|
2025-05-10 18:40:53 +08:00
|
|
|
|
return ResponseHelper::success(
|
|
|
|
|
|
compact(
|
|
|
|
|
|
'accountAge',
|
|
|
|
|
|
'activityLevel',
|
|
|
|
|
|
'accountWeight',
|
|
|
|
|
|
'statistics',
|
|
|
|
|
|
'restrictions'
|
|
|
|
|
|
)
|
|
|
|
|
|
);
|
2025-05-10 12:02:19 +08:00
|
|
|
|
} catch (\Exception $e) {
|
2025-05-10 18:40:53 +08:00
|
|
|
|
return ResponseHelper::error($e->getMessage(), $e->getCode());
|
2025-05-10 12:02:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|