好友迁移由30分钟改为10分钟
This commit is contained in:
@@ -22,7 +22,7 @@ class CheckUnreadMessageCommand extends Command
|
||||
{
|
||||
$this->setName('check:unread-message')
|
||||
->setDescription('检查未读/未回复消息并自动迁移好友')
|
||||
->addOption('minutes', 'm', \think\console\input\Option::VALUE_OPTIONAL, '未读/未回复分钟数,默认30分钟', 30)
|
||||
->addOption('minutes', 'm', \think\console\input\Option::VALUE_OPTIONAL, '未读/未回复分钟数,默认10分钟', 10)
|
||||
->addOption('page-size', 'p', \think\console\input\Option::VALUE_OPTIONAL, '每页处理数量,默认100条', 100);
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ class CheckUnreadMessageCommand extends Command
|
||||
{
|
||||
$minutes = intval($input->getOption('minutes'));
|
||||
if ($minutes <= 0) {
|
||||
$minutes = 30;
|
||||
$minutes = 10;
|
||||
}
|
||||
|
||||
$pageSize = intval($input->getOption('page-size'));
|
||||
|
||||
@@ -3,10 +3,6 @@
|
||||
namespace app\cunkebao\controller\wechat;
|
||||
|
||||
use app\common\controller\ExportController;
|
||||
use app\common\model\Device as DeviceModel;
|
||||
use app\common\model\DeviceUser as DeviceUserModel;
|
||||
use app\common\model\DeviceWechatLogin as DeviceWechatLoginModel;
|
||||
use app\common\model\User as UserModel;
|
||||
use app\cunkebao\controller\BaseController;
|
||||
use library\ResponseHelper;
|
||||
use think\Db;
|
||||
@@ -16,58 +12,53 @@ use think\Db;
|
||||
*/
|
||||
class GetWechatMomentsV1Controller extends BaseController
|
||||
{
|
||||
/**
|
||||
* 主操盘手获取项目下所有设备ID
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getCompanyDevicesId(): array
|
||||
{
|
||||
return DeviceModel::where('companyId', $this->getUserInfo('companyId'))
|
||||
->column('id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 非主操盘手仅可查看分配到的设备
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getUserDevicesId(): array
|
||||
{
|
||||
return DeviceUserModel::where([
|
||||
'userId' => $this->getUserInfo('id'),
|
||||
'companyId' => $this->getUserInfo('companyId'),
|
||||
])->column('deviceId');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前用户可访问的设备ID
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getDevicesId(): array
|
||||
{
|
||||
return ($this->getUserInfo('isAdmin') == UserModel::ADMIN_STP)
|
||||
? $this->getCompanyDevicesId()
|
||||
: $this->getUserDevicesId();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户可访问的微信ID集合
|
||||
* 使用 s2_wechat_friend 验证好友归属:
|
||||
* - 非管理员:当前账号在好友表中的 ownerWechatId 集合
|
||||
* - 管理员:公司下所有账号在好友表中的 ownerWechatId 集合
|
||||
*
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function getAccessibleWechatIds(): array
|
||||
{
|
||||
$deviceIds = $this->getDevicesId();
|
||||
if (empty($deviceIds)) {
|
||||
throw new \Exception('暂无可用设备', 200);
|
||||
$companyId = $this->getUserInfo('companyId');
|
||||
$isAdmin = $this->getUserInfo('isAdmin');
|
||||
$accountId = $this->getUserInfo('s2_accountId');
|
||||
|
||||
if (empty($companyId)) {
|
||||
throw new \Exception('请先登录', 401);
|
||||
}
|
||||
|
||||
return DeviceWechatLoginModel::distinct(true)
|
||||
->where('companyId', $this->getUserInfo('companyId'))
|
||||
->whereIn('deviceId', $deviceIds)
|
||||
// 管理员:根据公司下所有账号的好友归属(s2_wechat_friend.accountId -> ownerWechatId)
|
||||
if (!empty($isAdmin)) {
|
||||
// 获取公司下所有账号ID
|
||||
$accountIds = Db::table('s2_company_account')
|
||||
->where('departmentId', $companyId)
|
||||
->column('id');
|
||||
|
||||
if (empty($accountIds)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// 从好友表中取出这些账号的 ownerWechatId(去重,排除已删除好友)
|
||||
return Db::table('s2_wechat_friend')
|
||||
->distinct(true)
|
||||
->whereIn('accountId', $accountIds)
|
||||
->where('isDeleted', 0)
|
||||
->column('wechatId');
|
||||
}
|
||||
|
||||
// 非管理员:仅根据当前账号在好友表中的 ownerWechatId 列表
|
||||
if (empty($accountId)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return Db::table('s2_wechat_friend')
|
||||
->distinct(true)
|
||||
->where('accountId', $accountId)
|
||||
->where('isDeleted', 0)
|
||||
->column('wechatId');
|
||||
}
|
||||
|
||||
@@ -79,29 +70,45 @@ class GetWechatMomentsV1Controller extends BaseController
|
||||
public function index()
|
||||
{
|
||||
try {
|
||||
// 可选参数:wechatId 不传则查看当前账号可访问的所有微信的朋友圈
|
||||
$wechatId = $this->request->param('wechatId/s', '');
|
||||
if (empty($wechatId)) {
|
||||
return ResponseHelper::error('wechatId不能为空');
|
||||
}
|
||||
|
||||
// 权限校验:只能查看当前账号可访问的微信
|
||||
// 获取当前账号可访问的微信ID集合(内部已做权限控制)
|
||||
$accessibleWechatIds = $this->getAccessibleWechatIds();
|
||||
if (!in_array($wechatId, $accessibleWechatIds, true)) {
|
||||
return ResponseHelper::error('无权查看该微信的朋友圈', 403);
|
||||
// 如果传了 wechatId,则只允许查看自己有权限的该微信
|
||||
$targetWechatIds = [];
|
||||
if (!empty($wechatId)) {
|
||||
if (!in_array($wechatId, $accessibleWechatIds, true)) {
|
||||
return ResponseHelper::error('无权查看该微信的朋友圈', 403);
|
||||
}
|
||||
$targetWechatIds = [$wechatId];
|
||||
} else {
|
||||
// 未传 wechatId,则查看所有有权限的微信的朋友圈
|
||||
$targetWechatIds = $accessibleWechatIds;
|
||||
}
|
||||
|
||||
// 获取对应的微信账号ID
|
||||
$accountId = Db::table('s2_wechat_account')
|
||||
->where('wechatId', $wechatId)
|
||||
->value('id');
|
||||
if (empty($targetWechatIds)) {
|
||||
return ResponseHelper::error('暂无可查看的微信账号', 404);
|
||||
}
|
||||
|
||||
if (empty($accountId)) {
|
||||
// 获取对应的微信账号ID集合
|
||||
$accountIds = Db::table('s2_wechat_account')
|
||||
->whereIn('wechatId', $targetWechatIds)
|
||||
->column('id');
|
||||
|
||||
if (empty($accountIds)) {
|
||||
return ResponseHelper::error('微信账号不存在或尚未同步', 404);
|
||||
}
|
||||
|
||||
// 查询朋友圈:如果传了 userName 参数,则只查看指定用户的;否则查看所有
|
||||
$query = Db::table('s2_wechat_moments')
|
||||
->where('wechatAccountId', $accountId)
|
||||
->where('userName', $wechatId);
|
||||
->whereIn('wechatAccountId', $accountIds);
|
||||
|
||||
// 如果传了 userName 参数,则只查看指定用户的朋友圈
|
||||
$userName = $this->request->param('userName/s', '');
|
||||
if (!empty($userName)) {
|
||||
$query->where('userName', $userName);
|
||||
}
|
||||
|
||||
// 关键词搜索
|
||||
if ($keyword = trim((string)$this->request->param('keyword', ''))) {
|
||||
@@ -175,6 +182,7 @@ class GetWechatMomentsV1Controller extends BaseController
|
||||
return ResponseHelper::error('微信账号不存在或尚未同步', 404);
|
||||
}
|
||||
|
||||
// 查询朋友圈(不限制 userName,导出所有朋友圈)
|
||||
$query = Db::table('s2_wechat_moments')
|
||||
->where('wechatAccountId', $accountId);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user