123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318 |
- <?php
- namespace App\Http\Controllers\Api;
- use App\Log;
- use App\Service\AndroidToolService;
- use App\Support\EmailQueue;
- use Illuminate\Http\Request;
- use App\Http\Controllers\Controller;
- use Illuminate\Validation\Rule;
- class AndroidToolController extends Controller
- {
- /**
- * 安卓手机与企微、客服信息绑定关系设置
- * */
- public function editCorpBind(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'device_id' => 'required|string',
- 'title' => 'required|string',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $adminId = $request->input('admin_id');
- $sysGroupId = $request->input('sys_group_id');
- $title = $request->input('title');
- $deviceId = $request->input('device_id');
- $bindList = $request->input('bind_list');
- $forwardStatus = $request->input('forward_status', 0);
- # 配置绑定关系
- $errno = AndroidToolService::editCorpBind($title, $deviceId, $bindList, $adminId, $sysGroupId, $forwardStatus);
- return self::returnValue([], $errno);
- }
- /**
- * 安卓设备绑定信息详情
- * */
- public function bindDetail(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'device_id' => 'required|string',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $sysGroupId = $request->input('sys_group_id');
- $deviceId = $request->input('device_id');
- # 获取设备绑定信息
- $detail = AndroidToolService::bindDetail($deviceId, $sysGroupId);
- return self::returnValue($detail);
- }
- /**
- * 安卓设备信息列表
- * */
- public function deviceList(Request $request)
- {
- $sysGroupId = $request->input('sys_group_id');
- $keyword = $request->input('keyword');
- $corpid = $request->input('corpid');
- $userId = $request->input('user_id');
- $page = $request->input('page', 1);
- $pageSize = $request->input('page_size', 20);
- # 获取安卓设备信息列表
- list($list, $count) = AndroidToolService::getDeviceList($keyword, $corpid, $userId, $sysGroupId, $page, $pageSize);
- return self::returnPageValue($list, $count, $pageSize, $page);
- }
- /**
- * 绑定待共享的目标客服
- * */
- public function takeoverUserBind(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'title' => 'required|string',
- 'corpid' => 'required|string',
- 'user_id' => 'required|string',
- 'takeover_users' => 'required|string',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $adminId = $request->input('admin_id');
- $sysGroupId = $request->input('sys_group_id');
- $title = $request->input('title');
- $corpid = $request->input('corpid');
- $userId = $request->input('user_id');
- $takeoverUsers = $request->input('takeover_users');
- # 配置共享关系
- $errno = AndroidToolService::takeoverUserBind($title, $corpid, $userId, $takeoverUsers, $adminId, $sysGroupId);
- return self::returnValue([], $errno);
- }
- /**
- * 共享的目标客服绑定关系列表
- * */
- public function shareConfigList(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required|string',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $sysGroupId = $request->input('sys_group_id');
- $corpid = $request->input('corpid');
- $userId = $request->input('user_id');
- $page = $request->input('page', 1);
- $pageSize = $request->input('page_size', 20);
- # 获取配置关系列表
- list($list, $count) = AndroidToolService::takeoverUserBindList($corpid, $userId, $page, $pageSize, $sysGroupId);
- return self::returnPageValue($list, $count, $pageSize, $page);
- }
- /**
- * 配置状态变更
- * */
- public function shareConfigStatusChange(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required|string',
- 'user_id' => 'required|string',
- 'status' => ['required', Rule::in([0, 1])],
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $sysGroupId = $request->input('sys_group_id');
- $adminId = $request->input('admin_id');
- $corpid = $request->input('corpid');
- $userId = $request->input('user_id');
- $status = $request->input('status');
- # 修改配置状态
- $errno = AndroidToolService::shareConfigStatusChange($corpid, $userId, $status, $sysGroupId, $adminId);
- return self::returnValue([], $errno);
- }
- /**
- * 安卓工具异常上报
- * */
- public function warnReport(Request $request)
- {
- $deviceList = ['c4ae1d58-f97b-3bb0-9fd5-6bb3ee756901'];
- $deviceId = $request->input('device_id');
- if(in_array($deviceId, $deviceList)) return [];
- $exception = $request->input('exception');
- $version = $request->input('version');
- $header = $request->header();
- Log::logError('安卓工具异常上报', [
- 'deviceId' => $deviceId,
- 'exception' => $exception,
- 'version' => $version,
- 'header' => $header,
- ], 'AndroidExceptionReport');
- EmailQueue::rPush('模拟点击工具运行过程发生异常', json_encode([
- 'deviceId' => $deviceId,
- 'exception' => $exception,
- 'version' => $version,
- 'header' => $header,
- ], 256), ['xiaohua.hou@kuxuan-inc.com'], '猎羽');
- }
- # 获取历史数据以及开关状态
- public function getHistoryDataAndStatus(Request $request) {
- $validator = \Validator::make($request->all(),[
- 'deviceId' => 'required|string',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $deviceId = $request->input('deviceId');
- # 获取开关状态
- $status = AndroidToolService::getUploadDataStatus();
- # 获取设备上一次最后一次导入数据
- $data = AndroidToolService::getHistoryData($deviceId);
- return self::returnValue(['data' => $data, 'status' => $status]);
- }
- # 接收上传数据
- public function receiveUploadData(Request $request) {
- $validator = \Validator::make($request->all(),[
- 'deviceId' => 'required|string',
- 'companyName' => 'required|string',
- 'userName' => 'required|string',
- 'oneways' => 'required',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $deviceId = $request->input('deviceId');// 设备
- $companyName = $request->input('companyName'); // 公司名称
- $userName = $request->input('userName');// 客服名称
- $endUpload = $request->input('endUpload'); // 是否导入完成
- $oneways = $request->input('oneways');
- $errcode = 0;
- AndroidToolService::receiveUploadData($deviceId, $companyName, $userName, $endUpload, $oneways, $errcode);
- return self::returnValue('', $errcode);
- }
- public function sendLogEmail(Request $request) {
- $uploadFiles = $request->file('uploadFiles');
- $subject = $request->input('subject');
- $userName = $request->input('user_name');
- $corpName = $request->input('corp_name');
- $deviceId = $request->input('device_id');
- $msgType = $request->input('msg_type');
- $timeInterval = $request->input('time_interval');
- $description = $request->input('description');
- $res = AndroidToolService::sendLogEmail($uploadFiles, $subject, $userName, $corpName, $deviceId, $msgType, $timeInterval, $description);
- return self::returnValue($res);
- }
- public function waitCreate(Request $request) {
- $validator = \Validator::make($request->all(), [
- 'device_id' => 'required|string',
- ]);
- if ($validator->fails()) {
- return self::returnValue(['error' => $validator->errors()], 1102);
- }
- $deviceId = $request->input('device_id');
- # 获取待邀请入群的新用户
- $result = AndroidToolService::waitCreate($deviceId);
- Log::logInfo('邀请转发消息客服入群请求日志', [
- 'device_id' => $deviceId,
- 'response' => $result
- ], 'waitCreate');
- return self::returnValue($result);
- }
- public function forwardMessageRecord(Request $request)
- {
- $validator = \Validator::make($request->all(), [
- 'device_id' => 'required|string',
- ]);
- if ($validator->fails()) {
- return self::returnValue(['error' => $validator->errors()], 1102);
- }
- Log::logInfo('记录数据', [$request->all()], 'debug');
- $deviceId = $request->input('device_id');
- $requestId = $request->input('request_id');
- $userName = $request->input('user_name');
- $corpName = $request->input('corp_name');
- $chatList = $request->input('chat_list');
- $message = $request->input('message');
- $messageFrom = $request->input('message_from');
- AndroidToolService::forwardMessageRecord($deviceId, $requestId, $userName, $corpName, $chatList, $message, $messageFrom);
- return self::returnValue(true);
- }
- /**
- * 获取转发数据记录
- * */
- public function forwardMsgRecord(Request $request)
- {
- $validator = \Validator::make($request->all(), [
- 'corpid' => 'required|string',
- ]);
- if ($validator->fails()) {
- return self::returnValue(['error' => $validator->errors()], 1102);
- }
- $corpid = $request->input('corpid');
- $page = $request->input('page', 1);
- $pageSize = $request->input('page_size', 20);
- list($list, $count) = AndroidToolService::getForwardMsgRecordList($corpid, $page, $pageSize);
- return self::returnPageValue($list, $count, $pageSize, $page);
- }
- }
|