2025-05-10 12:02:19 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace app\cunkebao\controller\wechat;
|
|
|
|
|
|
2025-05-15 10:50:28 +08:00
|
|
|
use AccountWeight\WechatAccountWeightAssessment as WeightAssessment;
|
|
|
|
|
use AccountWeight\WechatFriendAddLimitAssessment as LimitAssessment;
|
2025-05-15 16:14:48 +08:00
|
|
|
use app\common\model\WechatCustomer as WechatCustomerModel;
|
2025-05-12 15:32:42 +08:00
|
|
|
use app\common\model\WechatFriendShip as WechatFriendShipModel;
|
2025-05-14 15:00:21 +08:00
|
|
|
use app\common\model\WechatRestricts as WechatRestrictsModel;
|
2025-05-10 12:02:19 +08:00
|
|
|
use app\cunkebao\controller\BaseController;
|
2025-05-15 16:14:48 +08:00
|
|
|
use Eison\Utils\Helper\ArrHelper;
|
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
|
|
|
/**
|
2025-05-15 16:14:48 +08:00
|
|
|
* 获取微信客服信息
|
|
|
|
|
*
|
|
|
|
|
* @param string $wechatId
|
|
|
|
|
* @return WechatCustomerModel|null
|
|
|
|
|
* @throws \Exception
|
|
|
|
|
*/
|
|
|
|
|
private function getWechatCustomerModel(string $wechatId): ?WechatCustomerModel
|
|
|
|
|
{
|
|
|
|
|
if (!isset($this->WechatCustomerModel)) {
|
|
|
|
|
$this->WechatCustomerModel = WechatCustomerModel::where(
|
|
|
|
|
[
|
|
|
|
|
'wechatId' => $wechatId,
|
|
|
|
|
'companyId' => $this->getUserInfo('companyId')
|
|
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
->find();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->WechatCustomerModel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 计算账号年龄(从创建时间到现在)
|
2025-05-10 18:40:53 +08:00
|
|
|
*
|
|
|
|
|
* @param string $wechatId
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
protected function getRegisterDate(string $wechatId): string
|
|
|
|
|
{
|
2025-05-15 16:14:48 +08:00
|
|
|
return $this->getWechatCustomerModel($wechatId)->basic->registerDate ?? date('Y-m-d', time());
|
2025-05-10 18:40:53 +08:00
|
|
|
}
|
2025-05-10 12:02:19 +08:00
|
|
|
|
2025-05-10 18:40:53 +08:00
|
|
|
/**
|
2025-05-15 16:14:48 +08:00
|
|
|
* 获取昨日聊天次数
|
2025-05-10 18:40:53 +08:00
|
|
|
*
|
2025-05-15 16:14:48 +08:00
|
|
|
* @param WechatCustomerModel $customer
|
2025-05-10 18:40:53 +08:00
|
|
|
* @return int
|
|
|
|
|
*/
|
2025-05-15 16:14:48 +08:00
|
|
|
protected function getChatTimesPerDay(?WechatCustomerModel $customer): int
|
2025-05-10 12:02:19 +08:00
|
|
|
{
|
2025-05-15 16:14:48 +08:00
|
|
|
return $customer->activity->yesterdayMsgCount ?? 0;
|
2025-05-10 12:02:19 +08:00
|
|
|
}
|
|
|
|
|
|
2025-05-10 18:40:53 +08:00
|
|
|
/**
|
2025-05-15 16:14:48 +08:00
|
|
|
* 总聊天数量
|
2025-05-10 18:40:53 +08:00
|
|
|
*
|
2025-05-15 16:14:48 +08:00
|
|
|
* @param WechatCustomerModel $customer
|
2025-05-10 18:40:53 +08:00
|
|
|
* @return int
|
|
|
|
|
*/
|
2025-05-15 16:14:48 +08:00
|
|
|
protected function getChatTimesTotal(?WechatCustomerModel $customer): int
|
2025-05-10 18:40:53 +08:00
|
|
|
{
|
2025-05-15 16:14:48 +08:00
|
|
|
return $customer->activity->totalMsgCount ?? 0;
|
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 string
|
|
|
|
|
*/
|
|
|
|
|
protected function getActivityLevel(string $wechatId): array
|
|
|
|
|
{
|
2025-05-15 16:14:48 +08:00
|
|
|
$customer = $this->getWechatCustomerModel($wechatId);
|
|
|
|
|
|
2025-05-10 18:40:53 +08:00
|
|
|
return [
|
2025-05-15 16:14:48 +08:00
|
|
|
'allTimes' => $this->getChatTimesTotal($customer),
|
|
|
|
|
'dayTimes' => $this->getChatTimesPerDay($customer),
|
2025-05-10 18:40:53 +08:00
|
|
|
];
|
|
|
|
|
}
|
2025-05-10 12:02:19 +08:00
|
|
|
|
2025-05-10 18:40:53 +08:00
|
|
|
/**
|
2025-05-14 15:00:21 +08:00
|
|
|
* 获取限制记录
|
2025-05-10 18:40:53 +08:00
|
|
|
*
|
|
|
|
|
* @param string $wechatId
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
protected function getRestrict(string $wechatId): array
|
2025-05-10 12:02:19 +08:00
|
|
|
{
|
2025-05-14 15:00:21 +08:00
|
|
|
return WechatRestrictsModel::alias('r')
|
|
|
|
|
->field(
|
|
|
|
|
[
|
|
|
|
|
'r.id', 'r.restrictTime date', 'r.level', 'r.reason'
|
|
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
->where('r.wechatId', $wechatId)->select()
|
|
|
|
|
->toArray();
|
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 array
|
|
|
|
|
*/
|
|
|
|
|
protected function getAccountWeight(string $wechatId): array
|
|
|
|
|
{
|
2025-05-15 16:14:48 +08:00
|
|
|
$customer = $this->getWechatCustomerModel($wechatId);
|
|
|
|
|
$seeders = $customer ? (array)$customer->weight : array();
|
2025-05-10 12:02:19 +08:00
|
|
|
|
2025-05-15 16:14:48 +08:00
|
|
|
// 严谨返回
|
|
|
|
|
return ArrHelper::getValue('ageWeight,activityWeigth,restrictWeight,realNameWeight,scope', $seeders, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取当日最高添加好友记录
|
|
|
|
|
*
|
|
|
|
|
* @param string $wechatId
|
|
|
|
|
* @return int
|
|
|
|
|
* @throws \Exception
|
|
|
|
|
*/
|
|
|
|
|
protected function getAccountWeightAddLimit(string $wechatId): int
|
|
|
|
|
{
|
|
|
|
|
return $this->getWechatCustomerModel($wechatId)->weight->addLimit ?? 0;
|
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 $ownerWechatId
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
protected function getTodayNewFriendCount(string $ownerWechatId): int
|
|
|
|
|
{
|
2025-05-14 15:00:21 +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
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2025-05-15 10:20:20 +08:00
|
|
|
protected function getStatistics(string $wechatId): array
|
2025-05-10 18:40:53 +08:00
|
|
|
{
|
|
|
|
|
return [
|
2025-05-12 11:58:13 +08:00
|
|
|
'todayAdded' => $this->getTodayNewFriendCount($wechatId),
|
2025-05-15 16:14:48 +08:00
|
|
|
'addLimit' => $this->getAccountWeightAddLimit($wechatId)
|
2025-05-10 18:40:53 +08:00
|
|
|
];
|
|
|
|
|
}
|
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-14 14:17:36 +08:00
|
|
|
$wechatId = $this->request->param('id/s');
|
2025-05-10 12:02:19 +08:00
|
|
|
|
2025-05-10 18:40:53 +08:00
|
|
|
return ResponseHelper::success(
|
2025-05-15 10:20:20 +08:00
|
|
|
[
|
|
|
|
|
'accountAge' => $this->getRegisterDate($wechatId),
|
|
|
|
|
'activityLevel' => $this->getActivityLevel($wechatId),
|
|
|
|
|
'accountWeight' => $this->getAccountWeight($wechatId),
|
|
|
|
|
'statistics' => $this->getStatistics($wechatId),
|
|
|
|
|
'restrictions' => $this->getRestrict($wechatId),
|
|
|
|
|
]
|
2025-05-10 18:40:53 +08:00
|
|
|
);
|
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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|