123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285 |
- <?php
- namespace App\Http\Controllers\Api;
- use App\Service\MomentService;
- use Illuminate\Http\Request;
- use App\Http\Controllers\Controller;
- use Illuminate\Validation\Rule;
- class MomentController extends Controller
- {
- /**
- * 创建朋友圈任务规则
- * */
- public function setRule(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required|string',
- 'name' => 'required|string',
- 'filter_type' => ['required', Rule::in([1, 2])],
- 'send_type' => ['required', Rule::in([1, 2])],
- 'send_time' => 'required|date_format:Y-m-d H:i:s',
- 'content' => ['required_without:attachments', 'nullable'],
- 'attachments' => ['required_without:content', 'nullable'],
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $params = array();
- $ruleId = $request->input('rule_id');
- $params['corpid'] = $request->input('corpid');
- $params['admin_id'] = $request->input('admin_id');
- $params['name'] = $request->input('name');
- $params['filter_type'] = $request->input('filter_type'); // 朋友圈类型 1企业发表 2个人发表
- $params['send_type'] = $request->input('send_type'); // 发送类型 1立即发送 2定时发送
- $params['send_time'] = $request->input('send_time');
- $params['sender_list'] = $request->input('sender_list'); // 发送朋友圈成员userid集合
- $params['department_list'] = $request->input('department_list'); // 发送朋友圈部门id集合
- $params['customer_filter'] = $request->input('customer_filter'); // 0全部客户 1筛选客户
- $params['customer_tag_list'] = $request->input('customer_tag_list'); // 可见客户标签集合
- $params['content'] = $request->input('content');
- $params['attachments'] = $request->input('attachments');
- $params['operate_type'] = $request->input('operate_type', 1); // 运营类型 1单主体 2多主体
- $params['operator_group_id'] = $request->input('operator_group_id'); // 运营组ID
- $params['multiple_senders'] = $request->input('multiple_senders');
- $params['is_operation'] = $request->input('is_operation');
- # 设置群发规则
- $errNo = MomentService::setRule($ruleId, $params);
- return self::returnValue([], $errNo);
- }
- /**
- * 朋友圈任务列表
- * */
- public function taskList(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required|string',
- 'send_time_start' => 'nullable|date_format:Y-m-d H:i:s',
- 'send_time_end' => 'nullable|date_format:Y-m-d H:i:s',
- 'create_time_start' => 'nullable|date_format:Y-m-d H:i:s',
- 'create_time_end' => 'nullable|date_format:Y-m-d H:i:s',
- 'filter_type' => ['nullable', Rule::in([1, 2])],
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $corpid = $request->input('corpid');
- $creatorId = $request->input('creator_id');
- $filterType = $request->input('filter_type');
- $sendTimeStart = $request->input('send_time_start');
- $sendTimeEnd = $request->input('send_time_end');
- $page = $request->input('page', 1);
- $pageSize = $request->input('page_size', 20);
- $createTimeStart = $request->input('create_time_start');
- $createTimeEnd = $request->input('create_time_end');
- $sortColumn = $request->input('sort_column','send_time');
- $sortMethod = $request->input('sort_method','desc');
- # 获取群发规则列表
- $errno = 0;
- list($list, $count) = MomentService::taskList(
- $corpid, $creatorId, $filterType, $sendTimeStart, $sendTimeEnd,$createTimeStart,$createTimeEnd,$sortColumn,$sortMethod, $page, $pageSize, $errno
- );
- if($errno) return self::returnValue([], $errno);
- return self::returnPageValue($list, $count, $pageSize, $page);
- }
- /**
- * 朋友圈任务详情
- * */
- public function taskDetail(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required|string',
- 'rule_id' => 'required|integer',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $corpid = $request->input('corpid');
- $ruleId = $request->input('rule_id');
- # 获取群发消息详情
- $errno = 0;
- $detail = MomentService::ruleDetail($corpid, $ruleId, $errno);
- return self::returnValue($detail, $errno);
- }
- /**
- * 朋友圈任务状态修改
- * */
- public function changeStatus(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required|string',
- 'rule_id' => 'required|integer',
- 'status' => ['required', Rule::in([0, 1])],
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $corpid = $request->input('corpid');
- $status = $request->input('status');
- $ruleId = $request->input('rule_id');
- $errno = MomentService::updateRuleStatus($corpid, $ruleId, $status);
- return self::returnValue([], $errno);
- }
- /**
- * 朋友圈点赞评论详情接口
- */
- public function momentInteract(Request $request)
- {
- $validators = \Validator::make($request->all(), [
- 'corpid' => 'required|string',
- 'moment_id' => 'required|string',
- 'userid' => 'required|string'
- ]);
- if ($validators->fails()) {
- return self::returnValue($validators->getMessageBag(), 1102);
- }
- $corpid = $request->input('corpid');
- $moment_id = $request->input('moment_id');
- $userid = $request->input('userid');
- $res = MomentService::momentInteract($corpid, $moment_id, $userid);
- return self::returnValue($res);
- }
- /*
- * 查询满足对应条件的外部联系人数量
- * */
- public function customerMatchCount(Request $request)
- {
- $validator = \Validator::make($request->all(), [
- 'corpid' => 'required|string',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $params = array();
- $params['corpid'] = $request->input('corpid');
- $params['filter_type'] = $request->input('filter_type'); // 朋友圈类型 1企业发表 2个人发表
- $params['sender_list'] = $request->input('sender_list'); // 发送朋友圈成员userid集合
- $params['department_list'] = $request->input('department_list'); // 发送朋友圈部门id集合
- $params['customer_filter'] = $request->input('customer_filter'); // 0全部客户 1筛选客户
- $params['customer_tag_list'] = $request->input('customer_tag_list'); // 可见客户标签集合
- # 运营类型
- $params['operate_type'] = $request->input('operate_type', 1);
- $params['operator_group_id'] = $request->input('operator_group_id');// 运营组ID
- $params['multiple_senders'] = $request->input('multiple_senders');
- $params['is_operation'] = $request->input('is_operation');
- $total = 0;
- # 朋友圈预计展示到的客户数
- if(1 == $params['operate_type']){
- $errNo = MomentService::getCustomerMatchCount($params, $total);
- } else {
- $errNo = MomentService::getMultipleCorpCustomerMatchCount($params, $total);
- }
- return self::returnValue(['total' => $total], $errNo);
- }
- /**
- * 朋友圈发送记录列表
- * @param Request $request
- * @return array
- */
- public function momentRecordList(Request $request)
- {
- $validators = \Validator::make($request->all(),[
- 'corpid' => 'required|string',
- 'user_id_list' => 'nullable|array',
- 'send_time_start' => 'nullable|date_format:Y-m-d H:i:s',
- 'send_time_end' => 'nullable|date_format:Y-m-d H:i:s',
- ]);
- if ($validators->fails()) {
- return self::returnValue($validators->getMessageBag(), 1102);
- }
- $corpid = $request->input('corpid');
- $userIdList = $request->input('user_id_list');
- $sendTimeStart = $request->input('send_time_start');
- $sendTimeEnd = $request->input('send_time_end');
- $page = $request->input('page', 1);
- $pageSize = $request->input('page_size', 20);
- $errno = 0;
- list($list, $count) = MomentService::momentRecordList(
- $corpid, $userIdList, $sendTimeStart, $sendTimeEnd, $page, $pageSize, $errno
- );
- if($errno) return self::returnValue([], $errno);
- return self::returnPageValue($list, $count, $pageSize, $page);
- }
- /**
- * 给朋友圈消息未发送成员发送消息提醒
- * */
- public function noticeUser(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required|string',
- 'rule_id' => 'required|integer',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $corpid = $request->input('corpid');
- $ruleId = $request->input('rule_id');
- $errno = MomentService::noticeUser($corpid, $ruleId);
- return self::returnValue([], $errno);
- }
- /**
- * 安卓客服端获取待确认群发消息列表
- * */
- public function senderConfirmList(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'device_id' => 'required|string',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $deviceId = $request->input('device_id');
- # 获取待确认的群发消息
- $msgList = MomentService::senderConfirmList($deviceId);
- return self::returnValue(['list' => $msgList]);
- }
- }
|