存客宝微信好友表更名,模型动态引用
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
"use client"
|
||||
|
||||
import { useState, useEffect, useRef, useCallback } from "react"
|
||||
import { useRouter } from "next/navigation"
|
||||
import * as React from "react"
|
||||
import { useRouter, useParams } from "next/navigation"
|
||||
import { Card } from "@/components/ui/card"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import {
|
||||
@@ -136,8 +137,16 @@ interface WechatAccountSummary {
|
||||
}[];
|
||||
}
|
||||
|
||||
export default function WechatAccountDetailPage({ params }: { params: { id: string } }) {
|
||||
interface PageProps {
|
||||
params: {
|
||||
id: string
|
||||
}
|
||||
}
|
||||
|
||||
export default function WechatAccountDetailPage() {
|
||||
const router = useRouter()
|
||||
const params = useParams()
|
||||
const id = params?.id as string
|
||||
const [account, setAccount] = useState<WechatAccountDetail | null>(null)
|
||||
const [accountSummary, setAccountSummary] = useState<WechatAccountSummary | null>(null)
|
||||
const [showRestrictions, setShowRestrictions] = useState(false)
|
||||
@@ -177,7 +186,7 @@ export default function WechatAccountDetailPage({ params }: { params: { id: stri
|
||||
const decodedData = JSON.parse(decodeURIComponent(dataParam));
|
||||
setInitialData(decodedData);
|
||||
// 使用初始数据设置account
|
||||
const mockData = generateMockAccountData();
|
||||
const mockData = generateMockAccountData(id);
|
||||
if (decodedData) {
|
||||
mockData.avatar = decodedData.avatar;
|
||||
mockData.nickname = decodedData.nickname;
|
||||
@@ -194,12 +203,12 @@ export default function WechatAccountDetailPage({ params }: { params: { id: stri
|
||||
}
|
||||
} else {
|
||||
// 如果没有初始数据,使用模拟数据
|
||||
const mockData = generateMockAccountData();
|
||||
const mockData = generateMockAccountData(id);
|
||||
setAccount(mockData);
|
||||
setFriendsTotal(mockData.friendCount);
|
||||
setIsLoading(false);
|
||||
}
|
||||
}, []);
|
||||
}, [id]);
|
||||
|
||||
// 计算好友列表容器高度
|
||||
const getFriendsContainerHeight = () => {
|
||||
@@ -212,7 +221,7 @@ export default function WechatAccountDetailPage({ params }: { params: { id: stri
|
||||
};
|
||||
|
||||
// 生成模拟账号数据(作为备用,服务器请求失败时使用)
|
||||
const generateMockAccountData = (): WechatAccountDetail => {
|
||||
const generateMockAccountData = (accountId: string): WechatAccountDetail => {
|
||||
// 生成随机标签
|
||||
const generateRandomTags = (count: number): FriendTag[] => {
|
||||
const tagPool = [
|
||||
@@ -288,7 +297,7 @@ export default function WechatAccountDetailPage({ params }: { params: { id: stri
|
||||
const friends = generateFriends(friendCount);
|
||||
|
||||
const mockAccount: WechatAccountDetail = {
|
||||
id: params.id,
|
||||
id: accountId,
|
||||
avatar:
|
||||
"https://hebbkx1anhila5yf.public.blob.vercel-storage.com/img_v3_02jn_e7fcc2a4-3560-478d-911a-4ccd69c6392g.jpg-a8zVtwxMuSrPWN9dfWH93EBY0yM3Dh.jpeg",
|
||||
nickname: "卡若-25vig",
|
||||
@@ -490,7 +499,7 @@ export default function WechatAccountDetailPage({ params }: { params: { id: stri
|
||||
const fetchSummaryData = useCallback(async () => {
|
||||
try {
|
||||
setIsLoading(true);
|
||||
const response = await fetchWechatAccountSummary(params.id);
|
||||
const response = await fetchWechatAccountSummary(id);
|
||||
if (response.code === 200) {
|
||||
setAccountSummary(response.data);
|
||||
} else {
|
||||
@@ -510,7 +519,7 @@ export default function WechatAccountDetailPage({ params }: { params: { id: stri
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
}, [params.id]);
|
||||
}, [id]);
|
||||
|
||||
// 在页面加载和切换到概览标签时获取数据
|
||||
useEffect(() => {
|
||||
|
||||
@@ -279,7 +279,10 @@ export default function WechatAccountsPage() {
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center space-x-2">
|
||||
<h3 className="font-medium truncate max-w-[180px]">{account.nickname}</h3>
|
||||
<Badge variant={account.status === "normal" ? "default" : "destructive"} className={account.status === "normal" ? "bg-green-500 hover:bg-green-600 text-white" : ""}>
|
||||
<Badge
|
||||
variant={account.status === "normal" ? "default" : "destructive"}
|
||||
className={`min-w-[48px] text-center justify-center ${account.status === "normal" ? "bg-green-500 hover:bg-green-600 text-white" : ""}`}
|
||||
>
|
||||
{account.status === "normal" ? "正常" : "异常"}
|
||||
</Badge>
|
||||
</div>
|
||||
|
||||
@@ -8,12 +8,12 @@ use think\model\concern\SoftDelete;
|
||||
/**
|
||||
* 微信好友模型类
|
||||
*/
|
||||
class WechatFriend extends Model
|
||||
class WechatFriendShip extends Model
|
||||
{
|
||||
use SoftDelete;
|
||||
|
||||
// 设置表名
|
||||
protected $name = 'wechat_friend';
|
||||
protected $name = 'wechat_friendship';
|
||||
|
||||
// 自动写入时间戳
|
||||
protected $autoWriteTimestamp = true;
|
||||
@@ -24,8 +24,8 @@ Route::group('v1/', function () {
|
||||
Route::group('device/wechats', function () {
|
||||
Route::get('', 'app\cunkebao\controller\wechat\GetWechatsOnDevicesV1Controller@index'); // 获取在线微信账号列表
|
||||
Route::get(':id/summary', 'app\cunkebao\controller\wechat\GetWechatOnDeviceSummarizeV1Controller@index'); // 获取微信号详情
|
||||
Route::get(':id/friends', 'app\cunkebao\controller\wechat\GetWechatOnDeviceFriendsV1Controller@index'); // 获取微信好友列表
|
||||
|
||||
Route::get('friends', 'app\cunkebao\controller\DeviceWechat@getFriends'); // 获取微信好友列表
|
||||
Route::get('count', 'app\cunkebao\controller\DeviceWechat@count'); // 获取在线微信账号数量
|
||||
Route::get('device-count', 'app\cunkebao\controller\DeviceWechat@deviceCount'); // 获取有登录微信的设备数量
|
||||
Route::put('refresh', 'app\cunkebao\controller\DeviceWechat@refresh'); // 刷新设备微信状态
|
||||
|
||||
@@ -7,7 +7,7 @@ use app\common\model\DeviceTaskconf as DeviceTaskconfModel;
|
||||
use app\common\model\DeviceUser as DeviceUserModel;
|
||||
use app\common\model\DeviceWechatLogin;
|
||||
use app\common\model\User as UserModel;
|
||||
use app\common\model\WechatFriend;
|
||||
use app\common\model\WechatFriendShip as WechatFriendShipModel;
|
||||
use app\cunkebao\controller\BaseController;
|
||||
use Eison\Utils\Helper\ArrHelper;
|
||||
use library\ResponseHelper;
|
||||
@@ -97,7 +97,7 @@ class GetDeviceDetailV1Controller extends BaseController
|
||||
$ownerWechatId = DeviceWechatLogin::where(compact('companyId', 'deviceId'))->order('createTime desc')->value('wechatId');
|
||||
|
||||
if ($ownerWechatId) {
|
||||
return WechatFriend::where(['ownerWechatId' => $ownerWechatId])->count();
|
||||
return WechatFriendShipModel::where(['ownerWechatId' => $ownerWechatId])->count();
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace app\cunkebao\controller\device;
|
||||
use app\common\model\Device as DeviceModel;
|
||||
use app\common\model\DeviceUser as DeviceUserModel;
|
||||
use app\common\model\User as UserModel;
|
||||
use app\common\model\WechatFriend as WechatFriendModel;
|
||||
use app\common\model\WechatFriendShip as WechatFriendShipModel;
|
||||
use app\cunkebao\controller\BaseController;
|
||||
use library\ResponseHelper;
|
||||
|
||||
@@ -105,7 +105,7 @@ class GetDeviceListV1Controller extends BaseController
|
||||
$sections = $item->toArray();
|
||||
|
||||
if ($item->wechatId) {
|
||||
$sections['totalFriend'] = WechatFriendModel::where(['ownerWechatId' => $item->wechatId])->count();
|
||||
$sections['totalFriend'] = WechatFriendShipModel::where(['ownerWechatId' => $item->wechatId])->count();
|
||||
}
|
||||
|
||||
array_push($resultSets, $sections);
|
||||
|
||||
@@ -6,7 +6,7 @@ use app\common\model\DeviceUser as DeviceUserModel;
|
||||
use app\common\model\DeviceWechatLogin as DeviceWechatLoginModel;
|
||||
use app\common\model\User as UserModel;
|
||||
use app\common\model\WechatAccount as WechatAccountModel;
|
||||
use app\common\model\WechatFriend;
|
||||
use app\common\model\WechatFriendShip;
|
||||
use app\cunkebao\controller\BaseController;
|
||||
use library\ResponseHelper;
|
||||
|
||||
@@ -110,7 +110,7 @@ class GetRelatedAccountsV1Controller extends BaseController
|
||||
*/
|
||||
protected function countFriend(string $wechatId): int
|
||||
{
|
||||
return WechatFriend::where(['ownerWechatId' => $wechatId])->count();
|
||||
return WechatFriendShip::where(['ownerWechatId' => $wechatId])->count();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,7 +3,7 @@ namespace app\cunkebao\controller\friend;
|
||||
|
||||
use app\common\model\Device as DeviceModel;
|
||||
use app\common\model\DeviceUser as DeviceUserModel;
|
||||
use app\common\model\WechatFriend;
|
||||
use app\common\model\WechatFriendShip as WechatFriendShipModel;
|
||||
use app\cunkebao\controller\BaseController;
|
||||
use think\Db;
|
||||
|
||||
@@ -42,7 +42,7 @@ class GetFriendListV1Controller extends BaseController
|
||||
}
|
||||
|
||||
|
||||
$data = WechatFriend::alias('wf')
|
||||
$data = WechatFriendShipModel::alias('wf')
|
||||
->field(['wa1.nickname','wa1.avatar','wa1.alias','wf.id','wf.wechatId','wa2.nickname as ownerNickname','wa2.alias as ownerAlias','wa2.wechatId as ownerWechatId','wf.createTime'])
|
||||
->Join('wechat_account wa1','wf.wechatId = wa1.wechatId')
|
||||
->Join('wechat_account wa2','wf.ownerWechatId = wa2.wechatId')
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
namespace app\cunkebao\controller\wechat;
|
||||
|
||||
use app\common\model\WechatAccount as WechatAccountModel;
|
||||
use app\common\model\WechatFriendShip as WechatFriendShipModel;
|
||||
use library\ResponseHelper;
|
||||
use think\Controller;
|
||||
|
||||
/**
|
||||
* 设备微信控制器
|
||||
*/
|
||||
class GetWechatOnDeviceFriendsV1Controller extends Controller
|
||||
{
|
||||
/**
|
||||
* 构建返回数据
|
||||
*
|
||||
* @param \think\Paginator $result
|
||||
* @return array
|
||||
*/
|
||||
protected function makeResultedSet(\think\Paginator $result): array
|
||||
{
|
||||
$resultSets = [];
|
||||
|
||||
foreach ($result->items() as $item) {
|
||||
|
||||
|
||||
dd($item);
|
||||
|
||||
$sections = $item->toArray() + [];
|
||||
|
||||
array_push($resultSets, $sections);
|
||||
}
|
||||
|
||||
return $resultSets;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据微信账号ID获取好友列表
|
||||
*
|
||||
* @param array $where
|
||||
* @return \think\Paginator 分页对象
|
||||
*/
|
||||
protected function getFriendsByWechatIdAndQueryParams(array $where): \think\Paginator
|
||||
{
|
||||
$query = WechatFriendShipModel::alias('f')
|
||||
->field(
|
||||
[
|
||||
'w.id', 'w.nickname', 'w.avatar',
|
||||
'CASE WHEN w.alias IS NULL OR w.alias = "" THEN w.wechatId ELSE w.alias END AS wechatId',
|
||||
'f.memo', 'f.tags'
|
||||
]
|
||||
)
|
||||
->join('wechat_account w', 'w.wechatId = f.wechatId');
|
||||
|
||||
foreach ($where as $key => $value) {
|
||||
if (is_numeric($key) && is_array($value) && isset($value[0]) && $value[0] === 'exp') {
|
||||
$query->whereExp('', $value[1]);
|
||||
continue;
|
||||
}
|
||||
|
||||
$query->where($key, $value);
|
||||
}
|
||||
|
||||
return $query->paginate($this->request->param('limit/d', 10), false, ['page' => $this->request->param('page/d', 1)]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取原始的64位的微信id
|
||||
*
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function getStringWechatIdByNumberId(): string
|
||||
{
|
||||
$account = WechatAccountModel::find(
|
||||
$this->request->param('id/d')
|
||||
);
|
||||
|
||||
if (is_null($account)) {
|
||||
throw new \Exception('微信账号不存在', 404);
|
||||
}
|
||||
|
||||
return 'udbfnvtk';
|
||||
|
||||
return $account->wechatId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建查询条件
|
||||
*
|
||||
* @param array $params
|
||||
* @return array
|
||||
*/
|
||||
protected function makeWhere(array $params = []): array
|
||||
{
|
||||
// 关键词搜索(同时搜索好友备注和标签)
|
||||
if (!empty($keyword = $this->request->param('keyword'))) {
|
||||
$where[] = ['exp', "f.memo LIKE '%{$keyword}%' OR f.tags LIKE '%{$keyword}%'"];
|
||||
}
|
||||
|
||||
$where['f.ownerWechatId'] = $this->getStringWechatIdByNumberId();
|
||||
|
||||
return array_merge($where, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取微信好友列表
|
||||
*
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
try {
|
||||
$result = $this->getFriendsByWechatIdAndQueryParams(
|
||||
$this->makeWhere()
|
||||
);
|
||||
|
||||
return ResponseHelper::success(
|
||||
[
|
||||
'list' => $this->makeResultedSet($result),
|
||||
'total' => $result->total(),
|
||||
]
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
return ResponseHelper::error($e->getMessage(), $e->getCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
namespace app\cunkebao\controller\wechat;
|
||||
|
||||
use app\common\model\WechatAccount as WechatAccountModel;
|
||||
use app\common\model\WechatFriend as WechatFriendModel;
|
||||
use app\common\model\WechatFriendShip as WechatFriendShipModel;
|
||||
use app\cunkebao\controller\BaseController;
|
||||
use library\ResponseHelper;
|
||||
|
||||
@@ -208,7 +208,7 @@ class GetWechatOnDeviceSummarizeV1Controller extends BaseController
|
||||
*/
|
||||
protected function getTodayNewFriendCount(string $ownerWechatId): int
|
||||
{
|
||||
return WechatFriendModel::where( compact('ownerWechatId') )
|
||||
return WechatFriendShipModel::where( compact('ownerWechatId') )
|
||||
->whereBetween('createTime',
|
||||
[
|
||||
strtotime(date('Y-m-d 00:00:00')),
|
||||
@@ -239,9 +239,11 @@ class GetWechatOnDeviceSummarizeV1Controller extends BaseController
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function getStringWechatId(): string
|
||||
protected function getStringWechatIdByNumberId(): string
|
||||
{
|
||||
$account = WechatAccountModel::find(333333);
|
||||
$account = WechatAccountModel::find(
|
||||
$this->request->param('id/d')
|
||||
);
|
||||
|
||||
if (is_null($account)) {
|
||||
throw new \Exception('微信账号不存在', 404);
|
||||
@@ -258,9 +260,9 @@ class GetWechatOnDeviceSummarizeV1Controller extends BaseController
|
||||
public function index()
|
||||
{
|
||||
try {
|
||||
// $wechatId = $this->getStringWechatId();
|
||||
$wechatId = '1111111';
|
||||
$wechatId = $this->getStringWechatIdByNumberId();
|
||||
|
||||
// 以下内容依次加工数据
|
||||
$accountAge = $this->getRegisterDate($wechatId);
|
||||
$activityLevel = $this->getActivityLevel($wechatId);
|
||||
$accountWeight = $this->getAccountWeight($wechatId);
|
||||
|
||||
@@ -8,7 +8,7 @@ use app\common\model\DeviceUser as DeviceUserModel;
|
||||
use app\common\model\DeviceWechatLogin as DeviceWechatLoginModel;
|
||||
use app\common\model\User as UserModel;
|
||||
use app\common\model\WechatAccount as WechatAccountModel;
|
||||
use app\common\model\WechatFriend as WechatFriendModel;
|
||||
use app\common\model\WechatFriendShip as WechatFriendShipModel;
|
||||
use app\cunkebao\controller\BaseController;
|
||||
use library\ResponseHelper;
|
||||
|
||||
@@ -36,7 +36,7 @@ class GetWechatsOnDevicesV1Controller extends BaseController
|
||||
*/
|
||||
protected function getTodayNewFriendCount(string $ownerWechatId): int
|
||||
{
|
||||
return WechatFriendModel::where( compact('ownerWechatId') )
|
||||
return WechatFriendShipModel::where( compact('ownerWechatId') )
|
||||
->whereBetween('createTime',
|
||||
[
|
||||
strtotime(date('Y-m-d 00:00:00')),
|
||||
@@ -65,7 +65,7 @@ class GetWechatsOnDevicesV1Controller extends BaseController
|
||||
*/
|
||||
protected function getFriendsCount(string $ownerWechatId): int
|
||||
{
|
||||
return WechatFriendModel::where(compact('ownerWechatId'))->count();
|
||||
return WechatFriendShipModel::where(compact('ownerWechatId'))->count();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -184,7 +184,7 @@ class GetWechatsOnDevicesV1Controller extends BaseController
|
||||
|
||||
$where['w.wechatId'] = array('in', implode(',', $wechatIds));
|
||||
|
||||
return array_merge($params, $where);
|
||||
return array_merge($where, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
<?php
|
||||
namespace app\cunkebao\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 微信好友模型类
|
||||
*/
|
||||
class WechatFriend extends Model
|
||||
{
|
||||
// 设置表名
|
||||
protected $name = 'wechat_friend';
|
||||
|
||||
/**
|
||||
* 根据微信账号ID获取好友列表
|
||||
*
|
||||
* @param string $ownerWechatId 所有者微信ID
|
||||
* @param array $params 查询条件参数
|
||||
* @param int $page 页码
|
||||
* @param int $limit 每页数量
|
||||
* @return array 好友列表和总数
|
||||
*/
|
||||
public static function getFriendsByWechatId($ownerWechatId, $params = [], $page = 1, $limit = 20)
|
||||
{
|
||||
// 构建基础查询
|
||||
$query = self::where('ownerWechatId', $ownerWechatId)
|
||||
->where('isDeleted', 0);
|
||||
|
||||
// 添加筛选条件(昵称、备注、微信号、标签)
|
||||
if (!empty($params['keyword'])) {
|
||||
$keyword = $params['keyword'];
|
||||
$query->where(function($q) use ($keyword) {
|
||||
$q->whereOr('nickname', 'like', "%{$keyword}%")
|
||||
->whereOr('conRemark', 'like', "%{$keyword}%")
|
||||
->whereOr('alias', 'like', "%{$keyword}%")
|
||||
->whereOr("JSON_SEARCH(labels, 'one', '%{$keyword}%') IS NOT NULL");
|
||||
});
|
||||
}
|
||||
|
||||
// 计算总数
|
||||
$total = $query->count();
|
||||
|
||||
// 分页查询数据
|
||||
$friends = $query->page($page, $limit)
|
||||
->order('createTime desc')
|
||||
->field('wechatId, alias, avatar, labels, accountNickname, accountRealName, nickname, conRemark, gender, region')
|
||||
->select();
|
||||
|
||||
return [
|
||||
'list' => $friends,
|
||||
'total' => $total,
|
||||
'page' => $page,
|
||||
'limit' => $limit
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ use app\common\model\Company as CompanyModel;
|
||||
use app\common\model\Device as DeviceModel;
|
||||
use app\common\model\DeviceWechatLogin as DeviceWechatLoginModel;
|
||||
use app\common\model\User as UserModel;
|
||||
use app\common\model\WechatFriend as WechatFriendModel;
|
||||
use app\common\model\WechatFriendShip as WechatFriendModel;
|
||||
use app\superadmin\controller\BaseController;
|
||||
use library\ResponseHelper;
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace app\superadmin\controller\company;
|
||||
|
||||
use app\common\model\Device as DeviceModel;
|
||||
use app\common\model\DeviceWechatLogin as DeviceWechatLoginModel;
|
||||
use app\common\model\WechatFriend as WechatFriendModel;
|
||||
use app\common\model\WechatFriendShip as WechatFriendShipModel;
|
||||
use Eison\Utils\Helper\ArrHelper;
|
||||
use library\ResponseHelper;
|
||||
use think\Controller;
|
||||
@@ -72,7 +72,7 @@ class GetCompanyDevicesForProfileController extends Controller
|
||||
$relations = $this->getDeviceWechatRelationsByDeviceIds($deviceIds);
|
||||
|
||||
// 统计微信好友数量
|
||||
$friendCounts = WechatFriendModel::alias('f')
|
||||
$friendCounts = WechatFriendShipModel::alias('f')
|
||||
->field([
|
||||
'f.ownerWechatId wechatId', 'count(*) friendCount'
|
||||
])
|
||||
|
||||
Reference in New Issue
Block a user