php代码提交

This commit is contained in:
wong
2025-12-11 17:32:59 +08:00
parent b2760cde0e
commit 08fc18da86
5 changed files with 153 additions and 35 deletions

View File

@@ -136,6 +136,7 @@ Route::group('v1/', function () {
// 好友相关 // 好友相关
Route::group('friend', function () { Route::group('friend', function () {
Route::get('', 'app\cunkebao\controller\friend\GetFriendListV1Controller@index'); // 获取好友列表 Route::get('', 'app\cunkebao\controller\friend\GetFriendListV1Controller@index'); // 获取好友列表
Route::post('transfer', 'app\cunkebao\controller\friend\GetFriendListV1Controller@transfer'); // 好友转移
}); });
//群相关 //群相关

View File

@@ -1884,6 +1884,7 @@ class WorkbenchController extends Controller
$limit = $this->request->param('limit', 10); $limit = $this->request->param('limit', 10);
$keyword = $this->request->param('keyword', ''); $keyword = $this->request->param('keyword', '');
$workbenchId = $this->request->param('workbenchId', ''); $workbenchId = $this->request->param('workbenchId', '');
$isRecycle = $this->request->param('isRecycle', '');
if (empty($workbenchId)) { if (empty($workbenchId)) {
return json(['code' => 400, 'msg' => '参数错误']); return json(['code' => 400, 'msg' => '参数错误']);
} }
@@ -1897,7 +1898,7 @@ class WorkbenchController extends Controller
->join(['s2_wechat_friend' => 'wf'], 'wtc.wechatFriendId = wf.id') ->join(['s2_wechat_friend' => 'wf'], 'wtc.wechatFriendId = wf.id')
->join('users u', 'wtc.wechatAccountId = u.s2_accountId', 'left') ->join('users u', 'wtc.wechatAccountId = u.s2_accountId', 'left')
->field([ ->field([
'wtc.id', 'wtc.isRecycle', 'wtc.isRecycle', 'wtc.createTime', 'wtc.id', 'wtc.isRecycle', 'wtc.isRecycle', 'wtc.createTime','wtc.recycleTime',
'wf.wechatId', 'wf.alias', 'wf.nickname', 'wf.avatar', 'wf.gender', 'wf.phone', 'wf.wechatId', 'wf.alias', 'wf.nickname', 'wf.avatar', 'wf.gender', 'wf.phone',
'u.account', 'u.username' 'u.account', 'u.username'
]) ])
@@ -1908,11 +1909,18 @@ class WorkbenchController extends Controller
$query->where('wf.wechatId|wf.alias|wf.nickname|wf.phone|u.account|u.username', 'like', '%' . $keyword . '%'); $query->where('wf.wechatId|wf.alias|wf.nickname|wf.phone|u.account|u.username', 'like', '%' . $keyword . '%');
} }
if ($isRecycle != '' || $isRecycle != null) {
$query->where('isRecycle',$isRecycle);
}
$total = $query->count(); $total = $query->count();
$list = $query->page($page, $limit)->select(); $list = $query->page($page, $limit)->select();
foreach ($list as &$item) { foreach ($list as &$item) {
$item['createTime'] = date('Y-m-d H:i:s', $item['createTime']); $item['createTime'] = date('Y-m-d H:i:s', $item['createTime']);
$item['recycleTime'] = date('Y-m-d H:i:s', $item['recycleTime']);
} }
unset($item); unset($item);

View File

@@ -5,6 +5,7 @@ use app\common\model\Device as DeviceModel;
use app\common\model\DeviceUser as DeviceUserModel; use app\common\model\DeviceUser as DeviceUserModel;
use app\common\model\WechatFriendShip as WechatFriendShipModel; use app\common\model\WechatFriendShip as WechatFriendShipModel;
use app\cunkebao\controller\BaseController; use app\cunkebao\controller\BaseController;
use app\api\controller\AutomaticAssign;
use think\Db; use think\Db;
/** /**
@@ -66,29 +67,45 @@ class GetFriendListV1Controller extends BaseController
$where[] = ['ownerWechatId','in',$wechatIds]; $where[] = ['ownerWechatId','in',$wechatIds];
$data = Db::table('s2_wechat_friend') $data = Db::table('s2_wechat_friend')
->field(['nickname','avatar','alias','id','wechatId','ownerNickname','ownerAlias','ownerWechatId','createTime']) ->field([
'id', 'nickname', 'avatar', 'alias', 'wechatId',
'gender', 'phone', 'createTime', 'updateTime', 'deleteTime',
'ownerNickname', 'ownerAlias', 'ownerWechatId',
'accountUserName', 'accountNickname', 'accountRealName'
])
->where($where); ->where($where);
$total = $data->count(); $total = $data->count();
$list = $data->page($page, $limit)->order('id DESC')->select(); $list = $data->page($page, $limit)->order('id DESC')->select();
// 格式化时间字段和处理数据
// $data = WechatFriendShipModel::alias('wf') $formattedList = [];
// ->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']) foreach ($list as $item) {
// ->Join('wechat_account wa1','wf.wechatId = wa1.wechatId') $formattedItem = [
// ->Join('wechat_account wa2','wf.ownerWechatId = wa2.wechatId') 'id' => $item['id'],
// ->where($where); 'nickname' => $item['nickname'] ?? '',
// 'avatar' => $item['avatar'] ?? '',
// $total = $data->count(); 'alias' => $item['alias'] ?? '',
// $list = $data->page($page, $limit)->order('wf.id DESC')->group('wf.id')->select(); 'wechatId' => $item['wechatId'] ?? '',
'gender' => $item['gender'] ?? 0,
'phone' => $item['phone'] ?? '',
'account' => $item['accountUserName'] ?? '',
'username' => $item['accountRealName'] ?? '',
'createTime' => !empty($item['createTime']) ? date('Y-m-d H:i:s', $item['createTime']) : '1970-01-01 08:00:00',
'updateTime' => !empty($item['updateTime']) ? date('Y-m-d H:i:s', $item['updateTime']) : '1970-01-01 08:00:00',
'deleteTime' => !empty($item['deleteTime']) ? date('Y-m-d H:i:s', $item['deleteTime']) : '1970-01-01 08:00:00',
'ownerNickname' => $item['ownerNickname'] ?? '',
'ownerAlias' => $item['ownerAlias'] ?? '',
'ownerWechatId' => $item['ownerWechatId'] ?? '',
'accountNickname' => $item['accountNickname'] ?? ''
];
$formattedList[] = $formattedItem;
}
return json([ return json([
'code' => 200, 'code' => 200,
'msg' => '获取成功', 'msg' => '获取成功',
'data' => [ 'data' => [
'list' => $list, 'list' => $formattedList,
'total' => $total, 'total' => $total,
'companyId' => $this->getUserInfo('companyId') 'companyId' => $this->getUserInfo('companyId')
] ]
@@ -100,4 +117,95 @@ class GetFriendListV1Controller extends BaseController
]); ]);
} }
} }
/**
* 好友转移
* @return \think\response\Json
*/
public function transfer()
{
$friendId = $this->request->param('friendId', 0);
$toAccountId = $this->request->param('toAccountId', '');
$comment = $this->request->param('comment', '');
$companyId = $this->getUserInfo('companyId');
// 参数验证
if (empty($friendId)) {
return json([
'code' => 400,
'msg' => '好友ID不能为空'
]);
}
if (empty($toAccountId)) {
return json([
'code' => 400,
'msg' => '目标账号ID不能为空'
]);
}
try {
// 验证目标账号是否存在且属于当前公司
$accountInfo = Db::table('s2_company_account')
->where('id', $toAccountId)
->where('departmentId', $companyId)
->field('id as accountId, userName as accountUserName, realName as accountRealName, nickname as accountNickname, tenantId')
->find();
if (empty($accountInfo)) {
return json([
'code' => 404,
'msg' => '目标账号不存在'
]);
}
// 调用 AutomaticAssign 进行好友转移
$automaticAssign = new AutomaticAssign();
$result = $automaticAssign->allotWechatFriend([
'wechatFriendId' => $friendId,
'toAccountId' => $toAccountId,
'comment' => $comment,
'notifyReceiver' => false,
'optFrom' => 4
], true);
$resultData = json_decode($result, true);
if (!empty($resultData) && $resultData['code'] == 200) {
// 转移成功后更新数据库
$updateData = [
'accountId' => $accountInfo['accountId'],
'accountUserName' => $accountInfo['accountUserName'],
'accountRealName' => $accountInfo['accountRealName'],
'accountNickname' => $accountInfo['accountNickname'],
'updateTime' => time()
];
Db::table('s2_wechat_friend')
->where('id', $friendId)
->update($updateData);
return json([
'code' => 200,
'msg' => '好友转移成功',
'data' => [
'friendId' => $friendId,
'toAccountId' => $toAccountId
]
]);
} else {
return json([
'code' => 500,
'msg' => '好友转移失败:' . ($resultData['msg'] ?? '未知错误')
]);
}
} catch (\Exception $e) {
return json([
'code' => 500,
'msg' => '好友转移失败:' . $e->getMessage()
]);
}
}
} }

View File

@@ -43,10 +43,12 @@ class GetWechatOnDeviceFriendsV1Controller extends BaseController
[ [
'w.id', 'w.nickname', 'w.avatar', 'w.wechatId', 'w.id', 'w.nickname', 'w.avatar', 'w.wechatId',
'CASE WHEN w.alias IS NULL OR w.alias = "" THEN w.wechatId ELSE w.alias END AS wechatAccount', 'CASE WHEN w.alias IS NULL OR w.alias = "" THEN w.wechatId ELSE w.alias END AS wechatAccount',
'f.memo', 'f.tags' 'f.memo', 'f.tags',
'ff.accountUserName', 'ff.accountRealName','ff.id AS friendId'
] ]
) )
->join('wechat_account w', 'w.wechatId = f.wechatId'); ->join('wechat_account w', 'w.wechatId = f.wechatId')
->join(['s2_wechat_friend' => 'ff'], 'ff.id = f.id');
foreach ($where as $key => $value) { foreach ($where as $key => $value) {
if (is_numeric($key) && is_array($value) && isset($value[0]) && $value[0] === 'exp') { if (is_numeric($key) && is_array($value) && isset($value[0]) && $value[0] === 'exp') {

View File

@@ -77,7 +77,7 @@ class WorkbenchGroupCreateJob
{ {
try { try {
// 1. 查询启用了建群功能的数据 // 1. 查询启用了建群功能的数据
$workbenches = Workbench::where(['status' => 1, 'type' => 4, 'isDel' => 0])->order('id desc')->select(); $workbenches = Workbench::where(['status' => 1, 'type' => 4, 'isDel' => 0,'id' => 315])->order('id desc')->select();
foreach ($workbenches as $workbench) { foreach ($workbenches as $workbench) {
// 获取工作台配置 // 获取工作台配置
$config = WorkbenchGroupCreate::where('workbenchId', $workbench->id)->find(); $config = WorkbenchGroupCreate::where('workbenchId', $workbench->id)->find();
@@ -120,7 +120,6 @@ class WorkbenchGroupCreateJob
} }
} }
} }
if (empty($groupMemberWechatId)) { if (empty($groupMemberWechatId)) {
continue; continue;
} }
@@ -225,19 +224,20 @@ class WorkbenchGroupCreateJob
} }
} }
exit_data($adminWechatIds);
// 3. 从流量池用户中筛选出是群主好友的用户(按微信账号分组) // 3. 从流量池用户中筛选出是群主好友的用户(按微信账号分组)
$ownerFriendIdsByAccount = []; $ownerFriendIdsByAccount = [];
$wechatIds = []; $wechatIds = [];
// 获取群主的好友关系(从流量池中筛选) // 获取群主的好友关系(从流量池中筛选)
$ownerFriends = Db::name('wechat_friendship')->alias('f') $ownerFriends = Db::table('s2_wechat_friend')->alias('f')
->join(['s2_wechat_account' => 'a'], 'f.ownerWechatId=a.wechatId') ->join(['s2_wechat_account' => 'a'], 'f.wechatAccountId=a.id')
->where('f.companyId', $workbench->companyId)
->whereIn('f.wechatId', $batchUsers) ->whereIn('f.wechatId', $batchUsers)
->whereIn('f.ownerWechatId', $groupOwnerWechatIds) ->whereIn('a.wechatId', $groupOwnerWechatIds)
->where('f.isDeleted', 0)
->field('f.id,f.wechatId,a.id as wechatAccountId') ->field('f.id,f.wechatId,a.id as wechatAccountId')
->select(); ->select();
if (empty($ownerFriends)) { if (empty($ownerFriends)) {
Log::warning("未找到群主的好友跳过。工作台ID: {$workbench->id}"); Log::warning("未找到群主的好友跳过。工作台ID: {$workbench->id}");
return; return;
@@ -258,7 +258,6 @@ class WorkbenchGroupCreateJob
// 4.1 获取当前账号的管理员好友ID // 4.1 获取当前账号的管理员好友ID
$currentAdminFriendIds = []; $currentAdminFriendIds = [];
$accountWechatId = Db::table('s2_wechat_account')->where('id', $wechatAccountId)->value('wechatId'); $accountWechatId = Db::table('s2_wechat_account')->where('id', $wechatAccountId)->value('wechatId');
foreach ($adminFriendIds as $adminFriendId) { foreach ($adminFriendIds as $adminFriendId) {
$adminFriend = Db::table('s2_wechat_friend')->where('id', $adminFriendId)->find(); $adminFriend = Db::table('s2_wechat_friend')->where('id', $adminFriendId)->find();
if ($adminFriend && $adminFriend['ownerWechatId'] == $accountWechatId) { if ($adminFriend && $adminFriend['ownerWechatId'] == $accountWechatId) {
@@ -379,12 +378,12 @@ class WorkbenchGroupCreateJob
} }
// 从流量池用户中筛选出是管理员好友的用户 // 从流量池用户中筛选出是管理员好友的用户
$adminFriendsFromPool = Db::name('wechat_friendship')->alias('f') $adminFriendsFromPool = Db::table('s2_wechat_friend')->alias('f')
->join(['s2_wechat_account' => 'a'], 'f.ownerWechatId=a.wechatId') ->join(['s2_wechat_account' => 'a'], 'f.wechatAccountId=a.id')
->where('f.companyId', $workbench->companyId)
->whereIn('f.wechatId', $batchUsers) ->whereIn('f.wechatId', $batchUsers)
->whereIn('f.ownerWechatId', $adminWechatIds) ->whereIn('a.wechatId', $adminWechatIds)
->where('a.id', $wechatAccountId) ->where('a.id', $wechatAccountId)
->where('f.isDeleted', 0)
->field('f.id,f.wechatId') ->field('f.id,f.wechatId')
->select(); ->select();