123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358 |
- <?php
- namespace App\Http\Controllers\Api;
- use App\Service\CircleMassMsgRecordService;
- use App\Service\CircleMassMsgService;
- use Illuminate\Http\Request;
- use App\Http\Controllers\Controller;
- use Illuminate\Validation\Rule;
- class CircleMassMsgController extends Controller
- {
- /**
- * 智能群发消息规则设置
- * */
- public function setRule(Request $request)
- {
- $validator = \Validator::make($request->all(), [
- 'corpid' => 'required|string',
- 'name' => 'required|string',
- 'interval_type' => ['required', Rule::in([1, 2])],
- 'content' => ['required_without:attachments', 'nullable'],
- 'attachments' => ['required_without:content', 'nullable'],
- 'tag_screen_type' => ['nullable', Rule::in([0, 1, 2, 3])],
- 'customer_filter' => ['nullable', Rule::in([0, 1])],
- 'pay_status' => ['nullable', Rule::in([0, 1])],
- 'pay_num_min' => 'nullable|int',
- 'pay_num_max' => 'nullable|int',
- ]);
- 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['is_all'] = $request->input('is_all', 0); // 是否应用于全部员工 0否 1是
- $params['senders'] = $request->input('senders'); // 群发账号集合
- $params['content'] = $request->input('content');
- $params['attachments'] = $request->input('attachments');
- $params['gender'] = $request->input('gender', 3); // 客户性别 0未知 1男性 2女性 3全部
- $params['interval_type'] = $request->input('interval_type', 0); // 脚本检索间隔类型 1指定时间点检索 2间隔指定时间段检索
- $params['interval_time'] = $request->input('interval_time', 0); // 用户添加间隔时间。 单位:分钟
- $params['interval'] = $request->input('interval', 0); // 指定间隔小时数,interval_type为2时生效
- $params['time_points'] = $request->input('time_points'); // 需要检索的时间点集合,interval_type为1时生效
- $params['tag_screen_type'] = $request->input('tag_screen_type', 0); // 标签筛选方式 0未设置标签筛选 1所选标签满足其一 2所选标签全部满足 3无任何标签
- $params['tag_list'] = $request->input('tag_list');
- $params['exclude_tag_list'] = $request->input('exclude_tag_list');
- // 付费情况
- $params['pay_status'] = $request->input('pay_status'); // 是否付费 0:未付费 1:付费
- $params['pay_num_min'] = $request->input('pay_num_min'); // 最小付费次数
- $params['pay_num_max'] = $request->input('pay_num_max'); // 最大付费次数
- # 智能群发规则设置
- $errNo = CircleMassMsgService::setRule($ruleId, $params);
- return self::returnValue([], $errNo);
- }
- /**
- * 群发消息列表
- * */
- public function recordLists(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required|string',
- 'rule_id' => 'required|integer',
- '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 ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $corpid = $request->input('corpid');
- $ruleId = $request->input('rule_id');
- $sendTimeStart = $request->input('send_time_start');
- $sendTimeEnd = $request->input('send_time_end');
- $page = $request->input('page', 1);
- $pageSize = $request->input('page_size', 20);
- $sortColumn = $request->input('sort_column','send_time');
- $sortMethod = $request->input('sort_method','desc');
- # 获取群发规则列表
- $errno = 0;
- list($list, $count) = CircleMassMsgRecordService::recordList(
- $corpid, $ruleId, $sendTimeStart, $sendTimeEnd, $sortColumn, $sortMethod, $page, $pageSize, $errno
- );
- if($errno) return self::returnValue([], $errno);
- return self::returnPageValue($list, $count, $pageSize, $page);
- }
- /**
- * 智能群发规则列表
- * */
- public function ruleLists(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required|string',
- 'create_time_start' => 'nullable|date_format:Y-m-d H:i:s',
- 'create_time_end' => 'nullable|date_format:Y-m-d H:i:s',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $corpid = $request->input('corpid');
- $creatorId = $request->input('creator_id');
- $createTimeStart = $request->input('create_time_start');
- $createTimeEnd = $request->input('create_time_end');
- $page = $request->input('page', 1);
- $pageSize = $request->input('page_size', 20);
- # 获取群发规则列表
- $errno = 0;
- list($list, $count) = CircleMassMsgService::ruleList(
- $corpid, $creatorId, $createTimeStart,$createTimeEnd, $page, $pageSize, $errno
- );
- if($errno) return self::returnValue([], $errno);
- return self::returnPageValue($list, $count, $pageSize, $page);
- }
- public function recordDetail(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required|string',
- 'rule_id' => 'required|integer',
- 'send_num' => 'required|numeric',
- 'send_date' => 'required|date',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $corpid = $request->input('corpid');
- $ruleId = $request->input('rule_id');
- $sendNum = $request->input('send_num');
- $sendDate = $request->input('send_date');
- # 获取群发消息详情
- $errno = 0;
- $detail = CircleMassMsgRecordService::recordDetail($corpid, $ruleId, $sendNum, $sendDate, $errno);
- return self::returnValue($detail, $errno);
- }
- /**
- * 智能群发规则详情
- * */
- public function ruleDetail(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 = CircleMassMsgService::ruleDetail($corpid, $ruleId, $errno);
- return self::returnValue($detail, $errno);
- }
- /**
- * 群发消息数据概览
- * @param Request $request
- * @return array
- */
- public function overview(Request $request){
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required|string',
- 'rule_id' => 'required|integer',
- 'send_num' => 'required|numeric',
- 'send_date' => 'required|date'
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $corpid = $request->input('corpid');
- $ruleId = $request->input('rule_id');
- $sendNum = $request->input('send_num');
- $sendDate = $request->input('send_date');
- $res = CircleMassMsgRecordService::overview($corpid, $ruleId, $sendNum, $sendDate);
- return self::returnValue( $res , 0 );
- }
- /**
- * 群发消息发送成员名单
- * @param Request $request
- * @return array
- */
- public function senderList(Request $request){
- $support_type = ['all','sent','unsent','fail']; //支持的查询类型
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required|string',
- 'rule_id' => 'required|integer',
- 'send_num' => 'required|numeric',
- 'send_date' => 'required|date',
- 'type' => Rule::in($support_type)
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $corpid = $request->input('corpid');
- $ruleId = $request->input('rule_id');
- $sendNum = $request->input('send_num');
- $sendDate = $request->input('send_date');
- $type = $request->input("type",$support_type[0]);
- $page = $request->input("page",1);
- $pageSize = $request->input("page_size",20);
- $keyword = $request->input("keyword");
- list($total,$list) = CircleMassMsgRecordService::senderList($corpid, $ruleId, $sendNum, $sendDate, $type, $keyword, $page, $pageSize);
- return self::returnPageValue($list,$total,$pageSize,$page);
- }
- /**
- * 群发消息发送成员名单 - 导出
- * @param Request $request
- * @return array
- */
- public function senderListExport(Request $request){
- $support_type = ['all','sent','unsent','fail']; //支持的查询类型
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required|string',
- 'rule_id' => 'required|integer',
- 'send_num' => 'required|numeric',
- 'send_date' => 'required|date',
- 'type' => Rule::in($support_type)
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $corpid = $request->input('corpid');
- $ruleId = $request->input('rule_id');
- $sendNum = $request->input('send_num');
- $sendDate = $request->input('send_date');
- $type = $request->input("type",$support_type[0]);
- $keyword = $request->input("keyword");
- CircleMassMsgRecordService::senderListExport($corpid, $ruleId, $sendNum, $sendDate, $type, $keyword);
- }
- /**
- * 获取群发详情-客户列表
- * @param Request $request
- * @return array
- */
- public function massSendCustList(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'rule_id' => 'required|int',
- 'send_num' => 'required|numeric',
- 'send_date' => 'required|date',
- 'sender' => 'nullable|string',
- 'name' => 'nullable|string',
- 'type' => 'nullable|int|in:0,1,2,3,4'
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $ruleId = $request->input('rule_id');
- $sendNum = $request->input('send_num');
- $sendDate = $request->input('send_date');
- $sender = $request->input('sender');
- $name = $request->input('name');
- $type = $request->input('type');
- $page = $request->input('page', 1);
- $pageSize = (int)$request->input('page_size', 20);
- list($data, $total) = CircleMassMsgRecordService::massSendCustList($ruleId, $sendNum, $sendDate, $sender, $name, $type, $page, $pageSize);
- return self::returnPageValue($data, $total, $pageSize, $page);
- }
- /**
- * 获取群发详情-客户列表导出
- * @param Request $request
- * @return array
- */
- public function massSendCustListExport(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'rule_id' => 'required|int',
- 'send_num' => 'required|numeric',
- 'send_date' => 'required|date',
- 'sender' => 'nullable|string',
- 'name' => 'nullable|string',
- 'type' => 'nullable|int|in:0,1,2,3,4'
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $ruleId = $request->input('rule_id');
- $sendNum = $request->input('send_num');
- $sendDate = $request->input('send_date');
- $sender = $request->input('sender');
- $name = $request->input('name');
- $type = $request->input('type');
- CircleMassMsgRecordService::massSendCustListExport($ruleId, $sendNum, $sendDate, $sender, $name, $type);
- }
- /**
- * 智能群发规则状态变更
- * */
- public function updateStatus(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 = CircleMassMsgService::updateRuleStatus($corpid, $ruleId, $status);
- return self::returnValue([], $errno);
- }
- }
|