企微短剧业务系统

AndroidToolController.php 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Log;
  4. use App\Service\AndroidToolService;
  5. use App\Support\EmailQueue;
  6. use Illuminate\Http\Request;
  7. use App\Http\Controllers\Controller;
  8. use Illuminate\Validation\Rule;
  9. class AndroidToolController extends Controller
  10. {
  11. /**
  12. * 安卓手机与企微、客服信息绑定关系设置
  13. * */
  14. public function editCorpBind(Request $request)
  15. {
  16. $validator = \Validator::make($request->all(),[
  17. 'device_id' => 'required|string',
  18. 'title' => 'required|string',
  19. ]);
  20. if ($validator->fails()) {
  21. return self::returnValue($validator->getMessageBag(), 1102);
  22. }
  23. $adminId = $request->input('admin_id');
  24. $sysGroupId = $request->input('sys_group_id');
  25. $title = $request->input('title');
  26. $deviceId = $request->input('device_id');
  27. $bindList = $request->input('bind_list');
  28. $forwardStatus = $request->input('forward_status', 0);
  29. # 配置绑定关系
  30. $errno = AndroidToolService::editCorpBind($title, $deviceId, $bindList, $adminId, $sysGroupId, $forwardStatus);
  31. return self::returnValue([], $errno);
  32. }
  33. /**
  34. * 安卓设备绑定信息详情
  35. * */
  36. public function bindDetail(Request $request)
  37. {
  38. $validator = \Validator::make($request->all(),[
  39. 'device_id' => 'required|string',
  40. ]);
  41. if ($validator->fails()) {
  42. return self::returnValue($validator->getMessageBag(), 1102);
  43. }
  44. $sysGroupId = $request->input('sys_group_id');
  45. $deviceId = $request->input('device_id');
  46. # 获取设备绑定信息
  47. $detail = AndroidToolService::bindDetail($deviceId, $sysGroupId);
  48. return self::returnValue($detail);
  49. }
  50. /**
  51. * 安卓设备信息列表
  52. * */
  53. public function deviceList(Request $request)
  54. {
  55. $sysGroupId = $request->input('sys_group_id');
  56. $keyword = $request->input('keyword');
  57. $corpid = $request->input('corpid');
  58. $userId = $request->input('user_id');
  59. $page = $request->input('page', 1);
  60. $pageSize = $request->input('page_size', 20);
  61. # 获取安卓设备信息列表
  62. list($list, $count) = AndroidToolService::getDeviceList($keyword, $corpid, $userId, $sysGroupId, $page, $pageSize);
  63. return self::returnPageValue($list, $count, $pageSize, $page);
  64. }
  65. /**
  66. * 绑定待共享的目标客服
  67. * */
  68. public function takeoverUserBind(Request $request)
  69. {
  70. $validator = \Validator::make($request->all(),[
  71. 'title' => 'required|string',
  72. 'corpid' => 'required|string',
  73. 'user_id' => 'required|string',
  74. 'takeover_users' => 'required|string',
  75. ]);
  76. if ($validator->fails()) {
  77. return self::returnValue($validator->getMessageBag(), 1102);
  78. }
  79. $adminId = $request->input('admin_id');
  80. $sysGroupId = $request->input('sys_group_id');
  81. $title = $request->input('title');
  82. $corpid = $request->input('corpid');
  83. $userId = $request->input('user_id');
  84. $takeoverUsers = $request->input('takeover_users');
  85. # 配置共享关系
  86. $errno = AndroidToolService::takeoverUserBind($title, $corpid, $userId, $takeoverUsers, $adminId, $sysGroupId);
  87. return self::returnValue([], $errno);
  88. }
  89. /**
  90. * 共享的目标客服绑定关系列表
  91. * */
  92. public function shareConfigList(Request $request)
  93. {
  94. $validator = \Validator::make($request->all(),[
  95. 'corpid' => 'required|string',
  96. ]);
  97. if ($validator->fails()) {
  98. return self::returnValue($validator->getMessageBag(), 1102);
  99. }
  100. $sysGroupId = $request->input('sys_group_id');
  101. $corpid = $request->input('corpid');
  102. $userId = $request->input('user_id');
  103. $page = $request->input('page', 1);
  104. $pageSize = $request->input('page_size', 20);
  105. # 获取配置关系列表
  106. list($list, $count) = AndroidToolService::takeoverUserBindList($corpid, $userId, $page, $pageSize, $sysGroupId);
  107. return self::returnPageValue($list, $count, $pageSize, $page);
  108. }
  109. /**
  110. * 配置状态变更
  111. * */
  112. public function shareConfigStatusChange(Request $request)
  113. {
  114. $validator = \Validator::make($request->all(),[
  115. 'corpid' => 'required|string',
  116. 'user_id' => 'required|string',
  117. 'status' => ['required', Rule::in([0, 1])],
  118. ]);
  119. if ($validator->fails()) {
  120. return self::returnValue($validator->getMessageBag(), 1102);
  121. }
  122. $sysGroupId = $request->input('sys_group_id');
  123. $adminId = $request->input('admin_id');
  124. $corpid = $request->input('corpid');
  125. $userId = $request->input('user_id');
  126. $status = $request->input('status');
  127. # 修改配置状态
  128. $errno = AndroidToolService::shareConfigStatusChange($corpid, $userId, $status, $sysGroupId, $adminId);
  129. return self::returnValue([], $errno);
  130. }
  131. /**
  132. * 安卓工具异常上报
  133. * */
  134. public function warnReport(Request $request)
  135. {
  136. $deviceList = ['c4ae1d58-f97b-3bb0-9fd5-6bb3ee756901'];
  137. $deviceId = $request->input('device_id');
  138. if(in_array($deviceId, $deviceList)) return [];
  139. $exception = $request->input('exception');
  140. $version = $request->input('version');
  141. $header = $request->header();
  142. Log::logError('安卓工具异常上报', [
  143. 'deviceId' => $deviceId,
  144. 'exception' => $exception,
  145. 'version' => $version,
  146. 'header' => $header,
  147. ], 'AndroidExceptionReport');
  148. EmailQueue::rPush('模拟点击工具运行过程发生异常', json_encode([
  149. 'deviceId' => $deviceId,
  150. 'exception' => $exception,
  151. 'version' => $version,
  152. 'header' => $header,
  153. ], 256), ['xiaohua.hou@kuxuan-inc.com'], '猎羽');
  154. }
  155. # 获取历史数据以及开关状态
  156. public function getHistoryDataAndStatus(Request $request) {
  157. $validator = \Validator::make($request->all(),[
  158. 'deviceId' => 'required|string',
  159. ]);
  160. if ($validator->fails()) {
  161. return self::returnValue($validator->getMessageBag(), 1102);
  162. }
  163. $deviceId = $request->input('deviceId');
  164. # 获取开关状态
  165. $status = AndroidToolService::getUploadDataStatus();
  166. # 获取设备上一次最后一次导入数据
  167. $data = AndroidToolService::getHistoryData($deviceId);
  168. return self::returnValue(['data' => $data, 'status' => $status]);
  169. }
  170. # 接收上传数据
  171. public function receiveUploadData(Request $request) {
  172. $validator = \Validator::make($request->all(),[
  173. 'deviceId' => 'required|string',
  174. 'companyName' => 'required|string',
  175. 'userName' => 'required|string',
  176. 'oneways' => 'required',
  177. ]);
  178. if ($validator->fails()) {
  179. return self::returnValue($validator->getMessageBag(), 1102);
  180. }
  181. $deviceId = $request->input('deviceId');// 设备
  182. $companyName = $request->input('companyName'); // 公司名称
  183. $userName = $request->input('userName');// 客服名称
  184. $endUpload = $request->input('endUpload'); // 是否导入完成
  185. $oneways = $request->input('oneways');
  186. $errcode = 0;
  187. AndroidToolService::receiveUploadData($deviceId, $companyName, $userName, $endUpload, $oneways, $errcode);
  188. return self::returnValue('', $errcode);
  189. }
  190. public function sendLogEmail(Request $request) {
  191. $uploadFiles = $request->file('uploadFiles');
  192. $subject = $request->input('subject');
  193. $userName = $request->input('user_name');
  194. $corpName = $request->input('corp_name');
  195. $deviceId = $request->input('device_id');
  196. $msgType = $request->input('msg_type');
  197. $timeInterval = $request->input('time_interval');
  198. $description = $request->input('description');
  199. $res = AndroidToolService::sendLogEmail($uploadFiles, $subject, $userName, $corpName, $deviceId, $msgType, $timeInterval, $description);
  200. return self::returnValue($res);
  201. }
  202. public function waitCreate(Request $request) {
  203. $validator = \Validator::make($request->all(), [
  204. 'device_id' => 'required|string',
  205. ]);
  206. if ($validator->fails()) {
  207. return self::returnValue(['error' => $validator->errors()], 1102);
  208. }
  209. $deviceId = $request->input('device_id');
  210. # 获取待邀请入群的新用户
  211. $result = AndroidToolService::waitCreate($deviceId);
  212. Log::logInfo('邀请转发消息客服入群请求日志', [
  213. 'device_id' => $deviceId,
  214. 'response' => $result
  215. ], 'waitCreate');
  216. return self::returnValue($result);
  217. }
  218. public function forwardMessageRecord(Request $request)
  219. {
  220. $validator = \Validator::make($request->all(), [
  221. 'device_id' => 'required|string',
  222. ]);
  223. if ($validator->fails()) {
  224. return self::returnValue(['error' => $validator->errors()], 1102);
  225. }
  226. Log::logInfo('记录数据', [$request->all()], 'debug');
  227. $deviceId = $request->input('device_id');
  228. $requestId = $request->input('request_id');
  229. $userName = $request->input('user_name');
  230. $corpName = $request->input('corp_name');
  231. $chatList = $request->input('chat_list');
  232. $message = $request->input('message');
  233. $messageFrom = $request->input('message_from');
  234. AndroidToolService::forwardMessageRecord($deviceId, $requestId, $userName, $corpName, $chatList, $message, $messageFrom);
  235. return self::returnValue(true);
  236. }
  237. /**
  238. * 获取转发数据记录
  239. * */
  240. public function forwardMsgRecord(Request $request)
  241. {
  242. $validator = \Validator::make($request->all(), [
  243. 'corpid' => 'required|string',
  244. ]);
  245. if ($validator->fails()) {
  246. return self::returnValue(['error' => $validator->errors()], 1102);
  247. }
  248. $corpid = $request->input('corpid');
  249. $page = $request->input('page', 1);
  250. $pageSize = $request->input('page_size', 20);
  251. list($list, $count) = AndroidToolService::getForwardMsgRecordList($corpid, $page, $pageSize);
  252. return self::returnPageValue($list, $count, $pageSize, $page);
  253. }
  254. }