123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349 |
- <?php
- namespace App\Http\Controllers\Api;
- use App\Service\GroupChatJoinWayService;
- use Illuminate\Http\Request;
- use App\Http\Controllers\Controller;
- use Illuminate\Validation\Rule;
- class GroupChatJoinWayController extends Controller
- {
- /**
- * 创建群活码
- * */
- public function setRule(Request $request)
- {
- $validator = \Validator::make($request->all(), [
- 'corpid' => 'required|string',
- 'chat_id_list' => 'required|string',
- 'name' => 'required|string',
- 'group_id' => 'nullable|int',
- 'join_type' => ['required', Rule::in([1, 2])],
- 'is_limit' => ['required', Rule::in([0, 1])],
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $params = [];
- $params['corpid'] = $request->input('corpid');
- $params['admin_id'] = $request->input('admin_id');
- $params['name'] = $request->input('name');
- $params['group_id'] = $request->input('group_id');
- $params['join_type'] = $request->input('join_type', 2); // 进群方式 1:顺序进群 2:随机进群
- $params['is_limit'] = $request->input('is_limit'); // 是否设置加群上限 0:否 1:是
- $params['user_list'] = $request->input('user_list'); // 生效成员。当客户点击客服时,会引导客户随机添加一名客服成员的企业微信
- $params['leading_words'] = $request->input('leading_words'); // 引导语
- $params['chat_id_list'] = json_decode($request->input('chat_id_list'), true); // 客户群ID列表
- # 设置群活码规则
- $errno = GroupChatJoinWayService::setRule($params);
- return self::returnValue([], $errno);
- }
- /**
- * 群活码编辑
- * */
- public function editRule(Request $request)
- {
- $validator = \Validator::make($request->all(), [
- 'corpid' => 'required|string',
- 'config_id' => 'required|string',
- 'chat_id_list' => 'required|string',
- 'name' => 'required|string',
- 'rule_id' => 'required|int',
- 'group_id' => 'nullable|int',
- 'join_type' => ['required', Rule::in([1, 2])],
- 'is_limit' => ['required', Rule::in([0, 1])],
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $params = [];
- $ruleId = $request->input('rule_id');
- $configId = $request->input('config_id');
- $params['corpid'] = $request->input('corpid');
- $params['admin_id'] = $request->input('admin_id');
- $params['name'] = $request->input('name');
- $params['group_id'] = $request->input('group_id');
- $params['join_type'] = $request->input('join_type', 2); // 进群方式 1:顺序进群 2:随机进群
- $params['is_limit'] = $request->input('is_limit'); // 是否设置加群上限 0:否 1:是
- $params['user_list'] = $request->input('user_list'); // 生效成员。当客户点击客服时,会引导客户随机添加一名客服成员的企业微信
- $params['leading_words'] = $request->input('leading_words'); // 引导语
- $params['chat_id_list'] = json_decode($request->input('chat_id_list'), true); // 客户群ID列表
- # 设置群活码规则
- $errno = GroupChatJoinWayService::editRule($params, $ruleId, $configId);
- return self::returnValue([], $errno);
- }
- /**
- * 群活码规则列表
- * */
- public function ruleList(Request $request)
- {
- $validator = \Validator::make($request->all(), [
- 'corpid' => 'required|string',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $corpid = $request->input('corpid');
- $groupId = $request->input('group_id');
- $name = $request->input('name');
- $page = $request->input('page', 1);
- $pageSize = $request->input('page_size', 20);
- list($data, $total) = GroupChatJoinWayService::ruleList($corpid, $groupId, $name, $page, $pageSize);
- return self::returnPageValue($data, $total, $pageSize, $page);
- }
- /**
- * 群活码详情
- * */
- public function ruleDetail(Request $request)
- {
- $validator = \Validator::make($request->all(), [
- 'corpid' => 'required|string',
- 'rule_id' => 'required|int',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $corpid = $request->input('corpid');
- $ruleId = $request->input('rule_id');
- # 获取群活码规则详情
- $errno = 0;
- $detail = GroupChatJoinWayService::ruleDetail($corpid, $ruleId, $errno);
- return self::returnValue($detail, $errno);
- }
- /**
- * 群活码禁用
- * */
- public function delQrcode(Request $request)
- {
- $validator = \Validator::make($request->all(), [
- 'corpid' => 'required|string',
- 'rule_id' => 'required|int',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $corpid = $request->input('corpid');
- $ruleId = $request->input('rule_id');
- # 群活码禁用
- $errno = GroupChatJoinWayService::delQrcode($corpid, $ruleId);
- return self::returnValue([], $errno);
- }
- /**
- * 群活码总概数据
- * */
- public function condition(Request $request)
- {
- $validator = \Validator::make($request->all(), [
- 'corpid' => 'required|string',
- 'rule_id' => 'required|int',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $corpid = $request->input('corpid');
- $ruleId = $request->input('rule_id');
- # 获取群活码总概数据
- $data = GroupChatJoinWayService::getCondition($corpid, $ruleId);
- return self::returnValue($data);
- }
- /**
- * 群活码每日数据分析
- * */
- public function dailyReport(Request $request)
- {
- $validator = \Validator::make($request->all(), [
- 'corpid' => 'required|string',
- 'rule_id' => 'required|int',
- 'start_date' => 'required|date_format:Y-m-d',
- 'end_date' => 'required|date_format:Y-m-d',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $corpid = $request->input('corpid');
- $ruleId = $request->input('rule_id');
- $startDate = $request->input('start_date');
- $endDate = $request->input('end_date');
- # 群活码每日数据分析
- $data = GroupChatJoinWayService::getDailyReport($corpid, $ruleId, $startDate, $endDate);
- return self::returnValue($data);
- }
- /**
- * 群活码扫码进群客户列表
- * */
- public function customerList(Request $request)
- {
- $validator = \Validator::make($request->all(), [
- 'corpid' => 'required|string',
- 'rule_id' => 'required|int',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $corpid = $request->input('corpid');
- $ruleId = $request->input('rule_id');
- $keyword = $request->input('keyword');
- $page = $request->input('page', 1);
- $pageSize = $request->input('page_size', 20);
- # 获取群活码扫码进群客户列表
- list($list, $count) = GroupChatJoinWayService::getMemberList($corpid, $ruleId, $keyword, $page, $pageSize);
- return self::returnPageValue($list, $count, $pageSize, $page);
- }
- /**
- * 群活码配置群的数据分析
- * */
- public function analysis(Request $request)
- {
- $validator = \Validator::make($request->all(), [
- 'corpid' => 'required|string',
- 'rule_id' => 'required|int',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $corpid = $request->input('corpid');
- $ruleId = $request->input('rule_id');
- # 群活码配置群的数据分析
- $data = GroupChatJoinWayService::chatGroupAnalysis($corpid, $ruleId);
- return self::returnValue($data);
- }
- /**
- * 扫码数据上报
- * */
- public function scan(Request $request)
- {
- $validator = \Validator::make($request->all(), [
- 'corpid' => 'required|string',
- 'rule_id' => 'required|int',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $corpid = $request->input('corpid');
- $ruleId = $request->input('rule_id');
- # 增加扫码次数
- $errno = GroupChatJoinWayService::scanNumIncr($corpid, $ruleId);
- return self::returnValue([], $errno);
- }
- /**
- * 创建临时渠道码
- * */
- public function contactQrcode(Request $request)
- {
- $validator = \Validator::make($request->all(), [
- 'corpid' => 'required|string',
- 'rule_id' => 'required|int',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $corpid = $request->input('corpid');
- $ruleId = $request->input('rule_id');
- # 生成临时渠道活码
- $errno = 0;
- $data = GroupChatJoinWayService::createTempContactQrcode($corpid, $ruleId, $errno);
- return self::returnValue($data, $errno);
- }
- /**
- * 获取群组下的群活码规则数
- * */
- public function chatGroupCountOfGroup(Request $request)
- {
- $validator = \Validator::make($request->all(), [
- 'corpid' => 'required|string',
- 'group_id' => 'required|int',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $corpid = $request->input('corpid');
- $groupId = $request->input('group_id');
- $count = GroupChatJoinWayService::chatGroupCountOfGroup($corpid, $groupId);
- return self::returnValue(['count' => $count]);
- }
- /**
- * 群活码二维码
- * */
- public function detail(Request $request)
- {
- $validator = \Validator::make($request->all(), [
- 'corpid' => 'required|string',
- 'rule_id' => 'required|int',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $corpid = $request->input('corpid');
- $ruleId = $request->input('rule_id');
- # 获取群活码规则详情
- $errno = 0;
- $qrcode = GroupChatJoinWayService::qrcodeDetail($corpid, $ruleId, $errno);
- return self::returnValue(['qrcode' => $qrcode], $errno);
- }
- }
|