123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473 |
- <?php
- /**
- * Created by PhpStorm.
- * User: shensong
- * Date: 2022/6/15
- * Time: 14:13
- */
- namespace App\Http\Controllers\Api;
- use App\Http\Controllers\Controller;
- use App\Log;
- use App\Service\RadarService;
- use Illuminate\Http\Request;
- class RadarController extends Controller
- {
- // 创建雷达组
- public function radarGroupCreate(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) = RadarService::radarGroupCreate($params);
- return self::returnValue($res, $code);
- }
- // 雷达组列表
- public function radarGroupList(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['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) = RadarService::radarGroupList($params);
- return self::returnPageValue($data, $count, $params['page_size'], $params['page']);
- }
- // 编辑雷达组
- public function radarGroupUpdate(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) = RadarService::radarGroupUpdate($params);
- return self::returnValue($res, $code);
- }
- // 删除雷达组
- public function radarGroupDelete(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) = RadarService::radarGroupDelete($params);
- return self::returnValue($res, $code);
- }
- // 雷达组排序
- public function radarGroupSortUpdate(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) = RadarService::radarGroupSortUpdate($params);
- return self::returnValue($res, $code);
- }
- // 创建雷达
- public function radarCreate(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required|string',
- 'group_id' => 'nullable|integer',
- 'name' => 'required|string',
- 'type' => 'required|in:1,2,3,4',
- 'url_list' => 'required|array',
- 'title' => 'required|string',
- 'description' => 'required|string',
- 'cover_id' => 'required|integer',
- 'behavior_notification' => 'required|in:0,1',
- 'dynamic_notification' => 'required|in:0,1',
- 'customer_label' => 'required|in:0,1',
- 'tag_list' => 'required_if:customer_label,1'
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $params['corpid'] = $request->input('corpid');
- $params['group_id'] = $request->input('group_id');
- $params['name'] = $request->input('name');
- $params['sys_group_id'] = $request->input('sys_group_id');
- $params['type'] = $request->input('type');
- $params['url_list'] = $request->input('url_list');
- $params['title'] = $request->input('title');
- $params['description'] = $request->input('description');
- $params['cover_id'] = $request->input('cover_id');
- $params['behavior_notification'] = $request->input('behavior_notification');
- $params['dynamic_notification'] = $request->input('dynamic_notification');
- $params['customer_label'] = $request->input('customer_label');
- $params['tag_list'] = $request->input('tag_list');
- list($res, $code) = RadarService::radarCreate($params);
- return self::returnValue($res, $code);
- }
- // 雷达列表
- public function radarList(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required|string',
- 'group_id' => 'nullable|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['group_id'] = $request->input('group_id');
- $params['name'] = $request->input('name');
- $params['page'] = $request->input('page', 1);
- $params['page_size'] = $request->input('page_size', 20);
- list($data, $count) = RadarService::radarList($params);
- return self::returnPageValue($data, $count, $params['page_size'], $params['page']);
- }
- // 雷达详情
- public function radarDetail(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required|string',
- 'radar_id' => 'required|integer'
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $params['corpid'] = $request->input('corpid');
- $params['radar_id'] = $request->input('radar_id');
- $data = RadarService::radarDetail($params);
- return self::returnValue($data);
- }
- // 编辑雷达
- public function radarUpdate(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required|string',
- 'group_id' => 'nullable|integer',
- 'name' => 'required|string',
- 'type' => 'required|in:1,2,3,4',
- 'url_list' => 'required|array',
- 'title' => 'required|string',
- 'description' => 'required|string',
- 'cover_id' => 'required|integer',
- 'behavior_notification' => 'required|in:0,1',
- 'dynamic_notification' => 'required|in:0,1',
- 'customer_label' => 'required|in:0,1',
- 'tag_list' => 'required_if:customer_label,1',
- 'radar_id' => 'required|integer'
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $params['corpid'] = $request->input('corpid');
- $params['group_id'] = $request->input('group_id');
- $params['name'] = $request->input('name');
- $params['sys_group_id'] = $request->input('sys_group_id');
- $params['type'] = $request->input('type');
- $params['url_list'] = $request->input('url_list');
- $params['title'] = $request->input('title');
- $params['description'] = $request->input('description');
- $params['cover_id'] = $request->input('cover_id');
- $params['behavior_notification'] = $request->input('behavior_notification');
- $params['dynamic_notification'] = $request->input('dynamic_notification');
- $params['customer_label'] = $request->input('customer_label');
- $params['tag_list'] = $request->input('tag_list');
- $params['radar_id'] = $request->input('radar_id');
- list($res, $code) = RadarService::radarUpdate($params);
- return self::returnValue($res, $code);
- }
- // 删除雷达
- public function radarDelete(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required|string',
- 'radar_id' => 'required|integer'
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $params['corpid'] = $request->input('corpid');
- $params['radar_id'] = $request->input('radar_id');
- list($res, $code) = RadarService::radarDelete($params);
- return self::returnValue($res, $code);
- }
- // 雷达排序
- public function radarSortUpdate(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required|string',
- 'operate_radar_id' => 'required|integer',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $params['corpid'] = $request->input('corpid');
- $params['operate_radar_id'] = $request->input('operate_radar_id');
- $params['front_radar_id'] = $request->input('front_radar_id');
- $params['behind_radar_id'] = $request->input('behind_radar_id');
- $params['sys_group_id'] = $request->input('sys_group_id');
- list($res, $code) = RadarService::radarSortUpdate($params);
- return self::returnValue($res, $code);
- }
- public function dataStatisticsTotal(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required|string',
- 'radar_id' => 'required|integer'
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $params['corpid'] = $request->input('corpid');
- $params['radar_id'] = $request->input('radar_id');
- $data = RadarService::dataStatisticsTotal($params);
- return self::returnValue($data);
- }
- // 数据分析--列表
- public function dataStatisticsList(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required|string',
- 'radar_id' => 'required|integer'
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $params['corpid'] = $request->input('corpid');
- $params['radar_id'] = $request->input('radar_id');
- $params['page'] = $request->input('page', 1);
- $params['page_size'] = $request->input('page_size', 20);
- $params['channel'] = $request->input('channel');
- $params['customer_name'] = $request->input('customer_name');
- $params['start_date'] = $request->input('start_date');
- $params['end_date'] = $request->input('end_date');
- $params['user_list'] = $request->input('user_list');
- list($data, $count) = RadarService::dataStatisticsList($params);
- return self::returnPageValue($data, $count, $params['page_size'], $params['page']);
- }
- /**
- * H5页面需展示的雷达内容
- * */
- public function radarDetailForH5(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required|string',
- 'radar_id' => 'required|integer',
- 'user_id' => 'required|string',
- 'token' => 'required|string',
- 'timestamp' => 'required',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $corpid = $request->input('corpid');
- $radarId = $request->input('radar_id');
- $userId = $request->input('user_id');
- $token = $request->input('token');
- $timestamp = $request->input('timestamp');
- # 获取H5页面需要展示的雷达内容
- $errno = 0;
- $radarDetail = RadarService::radarDetailForH5($corpid, $radarId, $userId, $token, $timestamp, $errno);
- if($errno) return self::returnValue([] , $errno);
- return self::returnValue($radarDetail);
- }
- /**
- * 雷达获取的用户行为数据上报
- * */
- public function behaviorReport(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required|string',
- 'radar_id' => 'required|integer',
- 'user_id' => 'required|string',
- 'token' => 'required|string',
- 'timestamp' => 'required',
- 'type' => 'required',
- 'request_id' => 'required',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- Log::logInfo('behaviorReport', $request->all(), 'interface');
- $param['corpid'] = $request->input('corpid');
- $param['radar_id'] = $request->input('radar_id');
- $param['user_id'] = $request->input('user_id');
- $param['external_userid'] = $request->input('external_userid');
- $param['openid'] = $request->input('openid');
- $param['device_id'] = $request->input('device_id');
- $param['channel'] = $request->input('channel'); // 渠道标识 1:朋友圈 2:群发消息 3:欢迎语 4:渠道活码
- $param['rule_id'] = $request->input('rule_id');
- $param['state'] = $request->input('state');
- $type = $request->input('type');
- $param['request_id'] = $request->input('request_id');
- $token = $request->input('token');
- $timestamp = $request->input('timestamp');
- # 数据上报
- $error = RadarService::behaviorReport($param, $type, $token, $timestamp);
- return self::returnValue([], $error);
- }
- // 渠道列表
- public function channelList()
- {
- $data = RadarService::channelList();
- return self::returnValue($data);
- }
- public function radarListForH5(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required|string',
- 'group_id' => 'nullable|integer',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $params['corpid'] = $request->input('corpid');
- $params['group_id'] = $request->input('group_id');
- $params['name'] = $request->input('name');
- $params['page'] = $request->input('page', 1);
- $params['page_size'] = $request->input('page_size', 20);
- list($data, $count) = RadarService::radarListForH5($params);
- return self::returnPageValue($data, $count, $params['page_size'], $params['page']);
- }
- // 获取h5中雷达组列表
- public function radarGroupListForH5(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) = RadarService::radarGroupList($params);
- return self::returnPageValue($data, $count, $params['page_size'], $params['page']);
- }
- public function getLinkMsgOfRadar(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required|string',
- 'radar_id' => 'required|string',
- 'user_id' => 'required|string',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $radarId = $request->input('radar_id');
- $corpid = $request->input('corpid');
- $userId = $request->input('user_id');
- $ruleId = time().rand(10000, 99999);
- $data = RadarService::getLinkMsgOfRadar($radarId, $corpid, $userId, 5, $ruleId);
- return self::returnValue($data);
- }
- }
|