getUserInfo('s2_accountId'); $userId = $this->getUserInfo('id'); $companyId = $this->getUserInfo('companyId'); if (empty($accountId)){ return ResponseHelper::error('请先登录'); } $accountIds1= Db::table('s2_wechat_friend')->where(['accountId' => $accountId,'isDeleted' => 0])->group('wechatAccountId')->column('wechatAccountId'); $accountIds2 = Db::table('s2_wechat_chatroom')->where(['accountId' => $accountId,'isDeleted' => 0])->group('wechatAccountId')->column('wechatAccountId'); // 确保即使有空数组也不会报错,并且去除重复值 $accountIds = array_unique(array_merge($accountIds1 ?: [], $accountIds2 ?: [])); $list = Db::table('s2_wechat_account') ->whereIn('id',$accountIds) ->order('id desc') ->group('id') ->select(); foreach ($list as $k=>&$v){ $v['createTime'] = !empty($v['createTime']) ? date('Y-m-d H:i:s',$v['createTime']) : ''; $v['updateTime'] = !empty($v['updateTime']) ? date('Y-m-d H:i:s',$v['updateTime']) : ''; $v['labels'] = json_decode($v['labels'],true); $momentsSetting = Db::name('kf_moments_settings')->where(['userId' => $userId,'companyId' => $companyId,'wechatId' =>$v['id']])->find(); $v['momentsMax'] = !empty($momentsSetting['max']) ? $momentsSetting['max'] : 5; $v['momentsNum'] = !empty($momentsSetting['sendNum']) ? $momentsSetting['sendNum'] : 0; unset( $v['accountUserName'], $v['accountRealName'], $v['accountNickname'], ); } unset($v); return ResponseHelper::success($list); } }