$corpid, 'user_id' => $userId, 'external_userid' => $externalUserId , 'type' => $type, 'content' => $content, 'attachments' => $attachments], 'interface'); $res = UserOpinionFeedback::addRecord($corpid, $userId, $externalUserId, $type, $content, $attachments); # 反馈用户拉黑 $userDetailDeal = CustomerDetails::suffix($corpid)->where('corpid', $corpid)->where('user_id', $userId) ->where('external_userid', $externalUserId)->update(['blacklist_status' => 1]); Log::logInfo('userOpinionFeedbackAction', ['corpid' => $corpid, 'user_id' => $userId, 'external_userid' => $externalUserId , 'type' => $type, 'content' => $content, 'attachments' => $attachments, 'blacklist_deal' => $userDetailDeal], 'interface'); # 给反馈客户打标签 RedisModel::lPush(CustomerTagService::CUSTOMER_TAG_MARK_RDS, json_encode([ 'corpid' => $corpid, 'user_id' => $userId, 'external_userid' => $externalUserId, 'type' => 2, 'tag_group_name' => '猎羽', 'tag_name_list' => ['投诉客户'] ], 256)); if($res) { # 发送短信提醒 self::remindUser($corpid, $userId); return ['成功', 0]; } return ['失败', 500]; } public static function userOpinionFeedbackList($sysGroupId, $userId, $page, $pageSize) { # 查询当前登录账号的企微权限列表 $corpIdList = AdminManageCorp::query()->where("is_delete",0) ->where("view_type",'helper') ->where("sys_user_id",$sysGroupId) ->pluck("corpid"); $corpids = AuthorizeCorp::getCorpIdList($corpIdList); # 查询列表 $params = ['corpid_list' => $corpids]; $userSqlArr = []; if(!empty($userId) && is_array($userId)) { foreach($userId as $item) { $userSqlArr[] = "('" . $item['corpid'] . "','" . $item['user_id'] . "')"; } } if(!empty($userSqlArr)) $params['user_sql'] = $userSqlArr; $query = UserOpinionFeedback::getDataQuery($params); # 记录条数 $countQuery = clone $query; $count = $countQuery->count(); # 数据格式化处理 $list = $query->select(['id', 'corpid', 'user_id', 'external_userid', 'type', 'content', 'attachments', 'create_time']) ->orderBy('create_time', 'desc')->offset(($page - 1) * $pageSize) ->limit($pageSize)->get(); $corpidList = array_unique(array_column($list->toArray(), 'corpid')); $corpDataList = AuthorizeCorp::getAllCorpList($corpidList); $userSql = []; foreach ($list as $item) { $key = $item->corpid . '#' . $item->user_id; $userSql[$key] = "('" . $item->corpid . "','" . $item->user_id . "')"; } $userDataList = DjUser::getUserBySearch(['user_sql' => $userSql]); $complainTypeArr = config('wxad.complain'); $typeList = []; foreach ($complainTypeArr['data'] as $item) { $typeList[$item['type']] = $item['title']; if(isset($item['child'])){ foreach($item['child']['data'] as $i) { $pTitle = $typeList[$i['ptype']] ?? ''; $typeList[$i['type']] = $pTitle.'--'.$i['title']; } } } foreach($list as $item) { # 企微名称 $corpInfo = $corpDataList->where('corpid', $item->corpid)->first(); $item->corp_name = $corpInfo->corp_name ?? null; # 客服名称 $userInfo = $userDataList->where('corpid', $item->corpid)->where('user_id', $item->user_id)->first(); $item->user_name = $userInfo->name ?? null; # 客户信息 $customerInfo = Customer::getCustomerInfoByExternalUserId($item->corpid, $item->external_userid); $item->customer_name = $customerInfo->name ?? null; $item->customer_avatar = $customerInfo->avatar ?? null; # 反馈类型 $item->type_title = $typeList[$item->type]; # 附件 $item->attachments = json_decode($item->attachments, 1); } return [$list, $count]; } # 短信提醒 public static function remindUser($corpid, $userId) { try{ # 查询客服对应的预警人 $groupIds = WarnGroupDjuser::getGroupIdByCorpUser($corpid, $userId); $groupIds = array_unique(array_column($groupIds->toArray(), 'group_id')); if(empty($groupIds)) { Log::logInfo('获取预警组为空', [ 'type' => 'feed_back', 'res' => '没有待提醒的手机号码', 'corpId' => $corpid, 'userId' => $userId, ], 'feedBackRemindUser'); return ; } $enableGroupIds = WarnGroup::query()->select(['id'])->whereIn('id', $groupIds)->where('enable', 1) ->get(); $enableGroupIds = array_column($enableGroupIds->toArray(), 'id'); if(empty($enableGroupIds)) { Log::logInfo('获取预警组为空', [ 'type' => 'feed_back', 'res' => '没有待提醒的手机号码', 'corpId' => $corpid, 'userId' => $userId, ], 'feedBackRemindUser'); return ; } // 获取预警人员 $groupUserArr = WarnGroupUser::getUserList($enableGroupIds); // 提取手机号 $phones = []; foreach($groupUserArr as $groupInfo) { foreach($groupInfo as $info) { if(!empty($info['user_phone']) && !in_array($info['user_phone'], $phones)) { $phones[] = $info['user_phone']; } } } if(empty($phones)) { Log::logInfo('短信发送结果', [ 'type' => 'feed_back', 'res' => '没有待提醒的手机号码', 'corpId' => $corpid, 'userId' => $userId, ], 'feedBackRemindUser'); return ; } // 发送短信 $param['corp'] = AuthorizeCorp::query()->where('corpid', $corpid)->value('corp_name'); $param['user'] = DjUser::query()->where('corpid', $corpid)->where('user_id', $userId) ->value('name'); foreach ($phones as $phone) { $res = YPSMS::warn_check_rule($phone, $param, 'feed_back'); Log::logInfo('短信发送结果', [ 'type' => 'feed_back', 'res' => $res, 'corpId' => $corpid, 'userId' => $userId, 'warnUserPhone' => $phone, ], 'feedBackRemindUser'); } } catch (\Exception $exception) { EmailQueue::rPush('客户意见反馈提醒客服异常', json_encode([ 'corpid' => $corpid, 'user_id' => $userId, 'err_msg' => $exception->getFile().'('.$exception->getLine().'):'.$exception->getMessage() ]), ['song.shen@kuxuan-inc.com'], '猎羽'); Log::logError('客户意见反馈提醒客服异常', [ 'corpid' => $corpid, 'user_id' => $userId, 'err_msg' => $exception->getFile().'('.$exception->getLine().'):'.$exception->getMessage(), 'trace' => $exception->getTraceAsString() ], 'feedBackRemindUserError'); } } }