企微短剧业务系统

ChatMenuController.php 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: shensong
  5. * Date: 2022/6/23
  6. * Time: 17:38
  7. */
  8. namespace App\Http\Controllers\Api;
  9. use App\Http\Controllers\Controller;
  10. use App\Log;
  11. use App\Service\ChatMenuService;
  12. use App\Service\CustomerService;
  13. use Illuminate\Http\Request;
  14. class ChatMenuController extends Controller
  15. {
  16. // 创建话术组
  17. public function createChatMenuGroup(Request $request)
  18. {
  19. $validator = \Validator::make($request->all(),[
  20. 'corpid' => 'required|string',
  21. 'group_name' => 'required|string',
  22. ]);
  23. if ($validator->fails()) {
  24. return self::returnValue($validator->getMessageBag(), 1102);
  25. }
  26. $params['corpid'] = $request->input('corpid');
  27. $params['group_name'] = $request->input('group_name');
  28. $params['sys_group_id'] = $request->input('sys_group_id');
  29. list($res, $code) = ChatMenuService::createChatMenuGroup($params);
  30. return self::returnValue($res, $code);
  31. }
  32. public function chatMenuGroupList(Request $request)
  33. {
  34. $validator = \Validator::make($request->all(),[
  35. 'corpid' => 'required|string',
  36. 'sys_group_id' => 'required|int',
  37. 'keyword' => 'nullable|string',
  38. ]);
  39. if ($validator->fails()) {
  40. return self::returnValue($validator->getMessageBag(), 1102);
  41. }
  42. $params['corpid'] = $request->input('corpid');
  43. $params['keyword'] = $request->input('keyword');
  44. $params['sys_group_id'] = $request->input('sys_group_id');
  45. $params['page'] = $request->input('page', 1);
  46. $params['page_size'] = $request->input('page_size', 20);
  47. list($data, $count) = ChatMenuService::chatMenuGroupList($params);
  48. return self::returnPageValue($data, $count, $params['page_size'], $params['page']);
  49. }
  50. public function updateChatMenuGroup(Request $request)
  51. {
  52. $validator = \Validator::make($request->all(),[
  53. 'corpid' => 'required|string',
  54. 'group_name' => 'required|string',
  55. 'group_id' => 'required|integer',
  56. ]);
  57. if ($validator->fails()) {
  58. return self::returnValue($validator->getMessageBag(), 1102);
  59. }
  60. $params['corpid'] = $request->input('corpid');
  61. $params['group_name'] = $request->input('group_name');
  62. $params['sys_group_id'] = $request->input('sys_group_id');
  63. $params['group_id'] = $request->input('group_id');
  64. list($res, $code) = ChatMenuService::updateChatMenuGroup($params);
  65. return self::returnValue($res, $code);
  66. }
  67. public function deleteChatMenuGroup(Request $request)
  68. {
  69. $validator = \Validator::make($request->all(),[
  70. 'group_id' => 'required|integer',
  71. 'type' => 'required|in:1,2'
  72. ]);
  73. if ($validator->fails()) {
  74. return self::returnValue($validator->getMessageBag(), 1102);
  75. }
  76. $params['group_id'] = $request->input('group_id');
  77. $params['type'] = $request->input('type', 1);
  78. list($res, $code) = ChatMenuService::deleteChatMenuGroup($params);
  79. return self::returnValue($res, $code);
  80. }
  81. public function updateChatMenuGroupSortOrder(Request $request)
  82. {
  83. $validator = \Validator::make($request->all(),[
  84. 'corpid' => 'required|string',
  85. 'operate_group_id' => 'required|integer',
  86. ]);
  87. if ($validator->fails()) {
  88. return self::returnValue($validator->getMessageBag(), 1102);
  89. }
  90. $params['corpid'] = $request->input('corpid');
  91. $params['operate_group_id'] = $request->input('operate_group_id');
  92. $params['front_group_id'] = $request->input('front_group_id');
  93. $params['behind_group_id'] = $request->input('behind_group_id');
  94. $params['sys_group_id'] = $request->input('sys_group_id');
  95. list($res, $code) = ChatMenuService::updateChatMenuGroupSortOrder($params);
  96. return self::returnValue($res, $code);
  97. }
  98. public function createChatMenuRule(Request $request)
  99. {
  100. $validator = \Validator::make($request->all(),[
  101. 'corpid' => 'required|string',
  102. 'title' => 'required|string',
  103. ]);
  104. if ($validator->fails()) {
  105. return self::returnValue($validator->getMessageBag(), 1102);
  106. }
  107. $params['group_id'] = $request->input('group_id');
  108. $params['title'] = $request->input('title');
  109. $params['corpid'] = $request->input('corpid');
  110. $params['sys_group_id'] = $request->input('sys_group_id');
  111. $params['msg_data_list'] = $request->input('msg_data_list');
  112. list($res, $code) = ChatMenuService::createChatMenuRule($params);
  113. return self::returnValue($res, $code);
  114. }
  115. public function chatMenuRuleList(Request $request)
  116. {
  117. $validator = \Validator::make($request->all(),[
  118. 'corpid' => 'required|string',
  119. ]);
  120. if ($validator->fails()) {
  121. return self::returnValue($validator->getMessageBag(), 1102);
  122. }
  123. $params['corpid'] = $request->input('corpid');
  124. $params['sys_group_id'] = $request->input('sys_group_id');
  125. $params['title'] = $request->input('title');
  126. $params['page'] = $request->input('page', 1);
  127. $params['page_size'] = $request->input('page_size', 20);
  128. $params['group_id'] = $request->input('group_id');
  129. list($data, $count) = ChatMenuService::chatMenuRuleList($params);
  130. return self::returnPageValue($data, $count, $params['page_size'], $params['page']);
  131. }
  132. public function chatMenuRuleDetail(Request $request)
  133. {
  134. $validator = \Validator::make($request->all(),[
  135. 'corpid' => 'required|string',
  136. 'rule_id' => 'required|integer',
  137. ]);
  138. if ($validator->fails()) {
  139. return self::returnValue($validator->getMessageBag(), 1102);
  140. }
  141. $params['corpid'] = $request->input('corpid');
  142. $params['sys_group_id'] = $request->input('sys_group_id');
  143. $params['rule_id'] = $request->input('rule_id');
  144. list($data, $code) = ChatMenuService::chatMenuRuleDetail($params);
  145. return self::returnValue($data, $code);
  146. }
  147. public function updateChatMenuRule(Request $request)
  148. {
  149. $validator = \Validator::make($request->all(),[
  150. 'corpid' => 'required|string',
  151. 'title' => 'required|string',
  152. 'rule_id' => 'required|integer',
  153. ]);
  154. if ($validator->fails()) {
  155. return self::returnValue($validator->getMessageBag(), 1102);
  156. }
  157. $params['group_id'] = $request->input('group_id');
  158. $params['title'] = $request->input('title');
  159. $params['corpid'] = $request->input('corpid');
  160. $params['sys_group_id'] = $request->input('sys_group_id');
  161. $params['msg_data_list'] = $request->input('msg_data_list');
  162. $params['rule_id'] = $request->input('rule_id');
  163. list($res, $code) = ChatMenuService::updateChatMenuRule($params);
  164. return self::returnValue($res, $code);
  165. }
  166. public function deleteChatMenuRule(Request $request)
  167. {
  168. $validator = \Validator::make($request->all(),[
  169. 'corpid' => 'required|string',
  170. 'rule_id' => 'required|integer',
  171. ]);
  172. if ($validator->fails()) {
  173. return self::returnValue($validator->getMessageBag(), 1102);
  174. }
  175. $params['rule_id'] = $request->input('rule_id');
  176. list($res, $code) = ChatMenuService::deleteChatMenuRule($params);
  177. return self::returnValue($res, $code);
  178. }
  179. public function updateChatMenuRuleSortOrder(Request $request)
  180. {
  181. $validator = \Validator::make($request->all(),[
  182. 'corpid' => 'required|string',
  183. 'operate_rule_id' => 'required|integer',
  184. ]);
  185. if ($validator->fails()) {
  186. return self::returnValue($validator->getMessageBag(), 1102);
  187. }
  188. $params['corpid'] = $request->input('corpid');
  189. $params['operate_rule_id'] = $request->input('operate_rule_id');
  190. $params['front_rule_id'] = $request->input('front_rule_id');
  191. $params['behind_rule_id'] = $request->input('behind_rule_id');
  192. $params['sys_group_id'] = $request->input('sys_group_id');
  193. list($res, $code) = ChatMenuService::updateChatMenuRuleSortOrder($params);
  194. return self::returnValue($res, $code);
  195. }
  196. /**
  197. * 快捷话术分组信息
  198. * */
  199. public function chatMenuGroupListForH5(Request $request)
  200. {
  201. $validator = \Validator::make($request->all(),[
  202. 'corpid' => 'required|string',
  203. 'keyword' => 'nullable|string',
  204. ]);
  205. if ($validator->fails()) {
  206. return self::returnValue($validator->getMessageBag(), 1102);
  207. }
  208. $params['corpid'] = $request->input('corpid');
  209. $params['keyword'] = $request->input('keyword');
  210. $params['page'] = $request->input('page', 1);
  211. $params['page_size'] = $request->input('page_size', 20);
  212. list($data, $count) = ChatMenuService::chatMenuGroupList($params);
  213. return self::returnPageValue($data, $count, $params['page_size'], $params['page']);
  214. }
  215. /**
  216. * 快捷话术信息列表
  217. * */
  218. public function chatMenuListForH5(Request $request)
  219. {
  220. $validator = \Validator::make($request->all(),[
  221. 'corpid' => 'required|string',
  222. 'group_id' => 'required|integer',
  223. ]);
  224. if ($validator->fails()) {
  225. return self::returnValue($validator->getMessageBag(), 1102);
  226. }
  227. $params['corpid'] = $request->input('corpid');
  228. $params['title'] = $request->input('title');
  229. $params['group_id'] = $request->input('group_id');
  230. $params['page'] = $request->input('page', 1);
  231. $params['page_size'] = $request->input('page_size', 20);
  232. list($data, $count) = ChatMenuService::chatMenuRuleListForH5($params);
  233. return self::returnPageValue($data, $count, $params['page_size'], $params['page']);
  234. }
  235. /**
  236. * 数据上报
  237. * */
  238. public function behaviorReport(Request $request)
  239. {
  240. $validator = \Validator::make($request->all(),[
  241. 'corpid' => 'required|string',
  242. 'user_id' => 'required|string',
  243. 'rule_id' => 'required|int',
  244. 'msg_id' => 'required|int',
  245. ]);
  246. if ($validator->fails()) {
  247. return self::returnValue($validator->getMessageBag(), 1102);
  248. }
  249. $params['corpid'] = $request->input('corpid');
  250. $params['user_id'] = $request->input('user_id');
  251. $params['external_userid'] = $request->input('external_userid');
  252. $params['rule_id'] = $request->input('rule_id');
  253. $params['msg_id'] = $request->input('msg_id');
  254. # 数据上报
  255. $error = ChatMenuService::behaviorReport($params);
  256. return self::returnValue([], $error);
  257. }
  258. /**
  259. * 将消息处理成可发送的数据结构
  260. * */
  261. public function chatMessage(Request $request)
  262. {
  263. $validator = \Validator::make($request->all(),[
  264. 'corpid' => 'required|string',
  265. 'rule_id' => 'required|integer',
  266. 'msg_id' => 'required|integer',
  267. ]);
  268. if ($validator->fails()) {
  269. return self::returnValue($validator->getMessageBag(), 1102);
  270. }
  271. $params['corpid'] = $request->input('corpid');
  272. $params['rule_id'] = $request->input('rule_id');
  273. $params['msg_id'] = $request->input('msg_id');
  274. $params['type'] = $request->input('type', 1); // 1快捷回复 2个人SOP
  275. # 消息处理成可发送的数据结构
  276. $errno = 0;
  277. $msgInfo = ChatMenuService::getChatMessage($params, $errno);
  278. if($errno) return self::returnValue([], $errno);
  279. return self::returnValue(['data' => $msgInfo]);
  280. }
  281. /**
  282. * 获取外部联系人信息
  283. * */
  284. public function getCustomerInfo(Request $request)
  285. {
  286. $validator = \Validator::make($request->all(),[
  287. 'corpid' => 'required|string',
  288. 'external_userid' => 'required|string',
  289. 'user_id' => 'required|string',
  290. ]);
  291. if ($validator->fails()) {
  292. return self::returnValue($validator->getMessageBag(), 1102);
  293. }
  294. $corpid = $request->input('corpid');
  295. $externalUserid = $request->input('external_userid');
  296. $userid = $request->input('user_id');
  297. # 获取外部联系人信息
  298. $userInfo = CustomerService::getCustomerInfo($corpid, $externalUserid, $userid);
  299. return self::returnValue(['user_info' => $userInfo]);
  300. }
  301. }