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

@@ -5,6 +5,7 @@ use app\common\model\Device as DeviceModel;
use app\common\model\DeviceUser as DeviceUserModel;
use app\common\model\WechatFriendShip as WechatFriendShipModel;
use app\cunkebao\controller\BaseController;
use app\api\controller\AutomaticAssign;
use think\Db;
/**
@@ -66,29 +67,45 @@ class GetFriendListV1Controller extends BaseController
$where[] = ['ownerWechatId','in',$wechatIds];
$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);
$total = $data->count();
$list = $data->page($page, $limit)->order('id DESC')->select();
// $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')
// ->where($where);
//
// $total = $data->count();
// $list = $data->page($page, $limit)->order('wf.id DESC')->group('wf.id')->select();
// 格式化时间字段和处理数据
$formattedList = [];
foreach ($list as $item) {
$formattedItem = [
'id' => $item['id'],
'nickname' => $item['nickname'] ?? '',
'avatar' => $item['avatar'] ?? '',
'alias' => $item['alias'] ?? '',
'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([
'code' => 200,
'msg' => '获取成功',
'data' => [
'list' => $list,
'list' => $formattedList,
'total' => $total,
'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()
]);
}
}
}