123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375 |
- <?php
- /**
- * Created by PhpStorm.
- * User: shensong
- * Date: 2022/6/23
- * Time: 17:38
- */
- namespace App\Http\Controllers\Api;
- use App\Http\Controllers\Controller;
- use App\Log;
- use App\Service\ChatMenuService;
- use App\Service\CustomerService;
- use Illuminate\Http\Request;
- class ChatMenuController extends Controller
- {
- // 创建话术组
- public function createChatMenuGroup(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required|string',
- 'group_name' => 'required|string',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $params['corpid'] = $request->input('corpid');
- $params['group_name'] = $request->input('group_name');
- $params['sys_group_id'] = $request->input('sys_group_id');
- list($res, $code) = ChatMenuService::createChatMenuGroup($params);
- return self::returnValue($res, $code);
- }
- public function chatMenuGroupList(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required|string',
- 'sys_group_id' => 'required|int',
- 'keyword' => 'nullable|string',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $params['corpid'] = $request->input('corpid');
- $params['keyword'] = $request->input('keyword');
- $params['sys_group_id'] = $request->input('sys_group_id');
- $params['page'] = $request->input('page', 1);
- $params['page_size'] = $request->input('page_size', 20);
- list($data, $count) = ChatMenuService::chatMenuGroupList($params);
- return self::returnPageValue($data, $count, $params['page_size'], $params['page']);
- }
- public function updateChatMenuGroup(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required|string',
- 'group_name' => 'required|string',
- 'group_id' => 'required|integer',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $params['corpid'] = $request->input('corpid');
- $params['group_name'] = $request->input('group_name');
- $params['sys_group_id'] = $request->input('sys_group_id');
- $params['group_id'] = $request->input('group_id');
- list($res, $code) = ChatMenuService::updateChatMenuGroup($params);
- return self::returnValue($res, $code);
- }
- public function deleteChatMenuGroup(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'group_id' => 'required|integer',
- 'type' => 'required|in:1,2'
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $params['group_id'] = $request->input('group_id');
- $params['type'] = $request->input('type', 1);
- list($res, $code) = ChatMenuService::deleteChatMenuGroup($params);
- return self::returnValue($res, $code);
- }
- public function updateChatMenuGroupSortOrder(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required|string',
- 'operate_group_id' => 'required|integer',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $params['corpid'] = $request->input('corpid');
- $params['operate_group_id'] = $request->input('operate_group_id');
- $params['front_group_id'] = $request->input('front_group_id');
- $params['behind_group_id'] = $request->input('behind_group_id');
- $params['sys_group_id'] = $request->input('sys_group_id');
- list($res, $code) = ChatMenuService::updateChatMenuGroupSortOrder($params);
- return self::returnValue($res, $code);
- }
- public function createChatMenuRule(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required|string',
- 'title' => 'required|string',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $params['group_id'] = $request->input('group_id');
- $params['title'] = $request->input('title');
- $params['corpid'] = $request->input('corpid');
- $params['sys_group_id'] = $request->input('sys_group_id');
- $params['msg_data_list'] = $request->input('msg_data_list');
- list($res, $code) = ChatMenuService::createChatMenuRule($params);
- return self::returnValue($res, $code);
- }
- public function chatMenuRuleList(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required|string',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $params['corpid'] = $request->input('corpid');
- $params['sys_group_id'] = $request->input('sys_group_id');
- $params['title'] = $request->input('title');
- $params['page'] = $request->input('page', 1);
- $params['page_size'] = $request->input('page_size', 20);
- $params['group_id'] = $request->input('group_id');
- list($data, $count) = ChatMenuService::chatMenuRuleList($params);
- return self::returnPageValue($data, $count, $params['page_size'], $params['page']);
- }
- public function chatMenuRuleDetail(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required|string',
- 'rule_id' => 'required|integer',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $params['corpid'] = $request->input('corpid');
- $params['sys_group_id'] = $request->input('sys_group_id');
- $params['rule_id'] = $request->input('rule_id');
- list($data, $code) = ChatMenuService::chatMenuRuleDetail($params);
- return self::returnValue($data, $code);
- }
- public function updateChatMenuRule(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required|string',
- 'title' => 'required|string',
- 'rule_id' => 'required|integer',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $params['group_id'] = $request->input('group_id');
- $params['title'] = $request->input('title');
- $params['corpid'] = $request->input('corpid');
- $params['sys_group_id'] = $request->input('sys_group_id');
- $params['msg_data_list'] = $request->input('msg_data_list');
- $params['rule_id'] = $request->input('rule_id');
- list($res, $code) = ChatMenuService::updateChatMenuRule($params);
- return self::returnValue($res, $code);
- }
- public function deleteChatMenuRule(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required|string',
- 'rule_id' => 'required|integer',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $params['rule_id'] = $request->input('rule_id');
- list($res, $code) = ChatMenuService::deleteChatMenuRule($params);
- return self::returnValue($res, $code);
- }
- public function updateChatMenuRuleSortOrder(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required|string',
- 'operate_rule_id' => 'required|integer',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $params['corpid'] = $request->input('corpid');
- $params['operate_rule_id'] = $request->input('operate_rule_id');
- $params['front_rule_id'] = $request->input('front_rule_id');
- $params['behind_rule_id'] = $request->input('behind_rule_id');
- $params['sys_group_id'] = $request->input('sys_group_id');
- list($res, $code) = ChatMenuService::updateChatMenuRuleSortOrder($params);
- return self::returnValue($res, $code);
- }
- /**
- * 快捷话术分组信息
- * */
- public function chatMenuGroupListForH5(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required|string',
- 'keyword' => 'nullable|string',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $params['corpid'] = $request->input('corpid');
- $params['keyword'] = $request->input('keyword');
- $params['page'] = $request->input('page', 1);
- $params['page_size'] = $request->input('page_size', 20);
- list($data, $count) = ChatMenuService::chatMenuGroupList($params);
- return self::returnPageValue($data, $count, $params['page_size'], $params['page']);
- }
- /**
- * 快捷话术信息列表
- * */
- public function chatMenuListForH5(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required|string',
- 'group_id' => 'required|integer',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $params['corpid'] = $request->input('corpid');
- $params['title'] = $request->input('title');
- $params['group_id'] = $request->input('group_id');
- $params['page'] = $request->input('page', 1);
- $params['page_size'] = $request->input('page_size', 20);
- list($data, $count) = ChatMenuService::chatMenuRuleListForH5($params);
- return self::returnPageValue($data, $count, $params['page_size'], $params['page']);
- }
- /**
- * 数据上报
- * */
- public function behaviorReport(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required|string',
- 'user_id' => 'required|string',
- 'rule_id' => 'required|int',
- 'msg_id' => 'required|int',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $params['corpid'] = $request->input('corpid');
- $params['user_id'] = $request->input('user_id');
- $params['external_userid'] = $request->input('external_userid');
- $params['rule_id'] = $request->input('rule_id');
- $params['msg_id'] = $request->input('msg_id');
- # 数据上报
- $error = ChatMenuService::behaviorReport($params);
- return self::returnValue([], $error);
- }
- /**
- * 将消息处理成可发送的数据结构
- * */
- public function chatMessage(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required|string',
- 'rule_id' => 'required|integer',
- 'msg_id' => 'required|integer',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $params['corpid'] = $request->input('corpid');
- $params['rule_id'] = $request->input('rule_id');
- $params['msg_id'] = $request->input('msg_id');
- $params['type'] = $request->input('type', 1); // 1快捷回复 2个人SOP
- # 消息处理成可发送的数据结构
- $errno = 0;
- $msgInfo = ChatMenuService::getChatMessage($params, $errno);
- if($errno) return self::returnValue([], $errno);
- return self::returnValue(['data' => $msgInfo]);
- }
- /**
- * 获取外部联系人信息
- * */
- public function getCustomerInfo(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required|string',
- 'external_userid' => 'required|string',
- 'user_id' => 'required|string',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $corpid = $request->input('corpid');
- $externalUserid = $request->input('external_userid');
- $userid = $request->input('user_id');
- # 获取外部联系人信息
- $userInfo = CustomerService::getCustomerInfo($corpid, $externalUserid, $userid);
- return self::returnValue(['user_info' => $userInfo]);
- }
- }
|