企微短剧业务系统

RadarController.php 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: shensong
  5. * Date: 2022/6/15
  6. * Time: 14:13
  7. */
  8. namespace App\Http\Controllers\Api;
  9. use App\Http\Controllers\Controller;
  10. use App\Log;
  11. use App\Service\RadarService;
  12. use Illuminate\Http\Request;
  13. class RadarController extends Controller
  14. {
  15. // 创建雷达组
  16. public function radarGroupCreate(Request $request)
  17. {
  18. $validator = \Validator::make($request->all(),[
  19. 'corpid' => 'required|string',
  20. 'group_name' => 'required|string',
  21. ]);
  22. if ($validator->fails()) {
  23. return self::returnValue($validator->getMessageBag(), 1102);
  24. }
  25. $params['corpid'] = $request->input('corpid');
  26. $params['group_name'] = $request->input('group_name');
  27. $params['sys_group_id'] = $request->input('sys_group_id');
  28. list($res, $code) = RadarService::radarGroupCreate($params);
  29. return self::returnValue($res, $code);
  30. }
  31. // 雷达组列表
  32. public function radarGroupList(Request $request)
  33. {
  34. $validator = \Validator::make($request->all(),[
  35. 'corpid' => 'required|string',
  36. 'keyword' => 'nullable|string',
  37. ]);
  38. if ($validator->fails()) {
  39. return self::returnValue($validator->getMessageBag(), 1102);
  40. }
  41. $params['corpid'] = $request->input('corpid');
  42. $params['keyword'] = $request->input('keyword');
  43. $params['sys_group_id'] = $request->input('sys_group_id');
  44. $params['page'] = $request->input('page', 1);
  45. $params['page_size'] = $request->input('page_size', 20);
  46. list($data, $count) = RadarService::radarGroupList($params);
  47. return self::returnPageValue($data, $count, $params['page_size'], $params['page']);
  48. }
  49. // 编辑雷达组
  50. public function radarGroupUpdate(Request $request)
  51. {
  52. $validator = \Validator::make($request->all(),[
  53. 'corpid' => 'required|string',
  54. 'group_name' => 'required|string',
  55. 'group_id' => 'required|integer',
  56. ]);
  57. if ($validator->fails()) {
  58. return self::returnValue($validator->getMessageBag(), 1102);
  59. }
  60. $params['corpid'] = $request->input('corpid');
  61. $params['group_name'] = $request->input('group_name');
  62. $params['sys_group_id'] = $request->input('sys_group_id');
  63. $params['group_id'] = $request->input('group_id');
  64. list($res, $code) = RadarService::radarGroupUpdate($params);
  65. return self::returnValue($res, $code);
  66. }
  67. // 删除雷达组
  68. public function radarGroupDelete(Request $request)
  69. {
  70. $validator = \Validator::make($request->all(),[
  71. 'group_id' => 'required|integer',
  72. 'type' => 'required|in:1,2'
  73. ]);
  74. if ($validator->fails()) {
  75. return self::returnValue($validator->getMessageBag(), 1102);
  76. }
  77. $params['group_id'] = $request->input('group_id');
  78. $params['type'] = $request->input('type', 1);
  79. list($res, $code) = RadarService::radarGroupDelete($params);
  80. return self::returnValue($res, $code);
  81. }
  82. // 雷达组排序
  83. public function radarGroupSortUpdate(Request $request)
  84. {
  85. $validator = \Validator::make($request->all(),[
  86. 'corpid' => 'required|string',
  87. 'operate_group_id' => 'required|integer',
  88. ]);
  89. if ($validator->fails()) {
  90. return self::returnValue($validator->getMessageBag(), 1102);
  91. }
  92. $params['corpid'] = $request->input('corpid');
  93. $params['operate_group_id'] = $request->input('operate_group_id');
  94. $params['front_group_id'] = $request->input('front_group_id');
  95. $params['behind_group_id'] = $request->input('behind_group_id');
  96. $params['sys_group_id'] = $request->input('sys_group_id');
  97. list($res, $code) = RadarService::radarGroupSortUpdate($params);
  98. return self::returnValue($res, $code);
  99. }
  100. // 创建雷达
  101. public function radarCreate(Request $request)
  102. {
  103. $validator = \Validator::make($request->all(),[
  104. 'corpid' => 'required|string',
  105. 'group_id' => 'nullable|integer',
  106. 'name' => 'required|string',
  107. 'type' => 'required|in:1,2,3,4',
  108. 'url_list' => 'required|array',
  109. 'title' => 'required|string',
  110. 'description' => 'required|string',
  111. 'cover_id' => 'required|integer',
  112. 'behavior_notification' => 'required|in:0,1',
  113. 'dynamic_notification' => 'required|in:0,1',
  114. 'customer_label' => 'required|in:0,1',
  115. 'tag_list' => 'required_if:customer_label,1'
  116. ]);
  117. if ($validator->fails()) {
  118. return self::returnValue($validator->getMessageBag(), 1102);
  119. }
  120. $params['corpid'] = $request->input('corpid');
  121. $params['group_id'] = $request->input('group_id');
  122. $params['name'] = $request->input('name');
  123. $params['sys_group_id'] = $request->input('sys_group_id');
  124. $params['type'] = $request->input('type');
  125. $params['url_list'] = $request->input('url_list');
  126. $params['title'] = $request->input('title');
  127. $params['description'] = $request->input('description');
  128. $params['cover_id'] = $request->input('cover_id');
  129. $params['behavior_notification'] = $request->input('behavior_notification');
  130. $params['dynamic_notification'] = $request->input('dynamic_notification');
  131. $params['customer_label'] = $request->input('customer_label');
  132. $params['tag_list'] = $request->input('tag_list');
  133. list($res, $code) = RadarService::radarCreate($params);
  134. return self::returnValue($res, $code);
  135. }
  136. // 雷达列表
  137. public function radarList(Request $request)
  138. {
  139. $validator = \Validator::make($request->all(),[
  140. 'corpid' => 'required|string',
  141. 'group_id' => 'nullable|integer',
  142. ]);
  143. if ($validator->fails()) {
  144. return self::returnValue($validator->getMessageBag(), 1102);
  145. }
  146. $params['corpid'] = $request->input('corpid');
  147. $params['sys_group_id'] = $request->input('sys_group_id');
  148. $params['group_id'] = $request->input('group_id');
  149. $params['name'] = $request->input('name');
  150. $params['page'] = $request->input('page', 1);
  151. $params['page_size'] = $request->input('page_size', 20);
  152. list($data, $count) = RadarService::radarList($params);
  153. return self::returnPageValue($data, $count, $params['page_size'], $params['page']);
  154. }
  155. // 雷达详情
  156. public function radarDetail(Request $request)
  157. {
  158. $validator = \Validator::make($request->all(),[
  159. 'corpid' => 'required|string',
  160. 'radar_id' => 'required|integer'
  161. ]);
  162. if ($validator->fails()) {
  163. return self::returnValue($validator->getMessageBag(), 1102);
  164. }
  165. $params['corpid'] = $request->input('corpid');
  166. $params['radar_id'] = $request->input('radar_id');
  167. $data = RadarService::radarDetail($params);
  168. return self::returnValue($data);
  169. }
  170. // 编辑雷达
  171. public function radarUpdate(Request $request)
  172. {
  173. $validator = \Validator::make($request->all(),[
  174. 'corpid' => 'required|string',
  175. 'group_id' => 'nullable|integer',
  176. 'name' => 'required|string',
  177. 'type' => 'required|in:1,2,3,4',
  178. 'url_list' => 'required|array',
  179. 'title' => 'required|string',
  180. 'description' => 'required|string',
  181. 'cover_id' => 'required|integer',
  182. 'behavior_notification' => 'required|in:0,1',
  183. 'dynamic_notification' => 'required|in:0,1',
  184. 'customer_label' => 'required|in:0,1',
  185. 'tag_list' => 'required_if:customer_label,1',
  186. 'radar_id' => 'required|integer'
  187. ]);
  188. if ($validator->fails()) {
  189. return self::returnValue($validator->getMessageBag(), 1102);
  190. }
  191. $params['corpid'] = $request->input('corpid');
  192. $params['group_id'] = $request->input('group_id');
  193. $params['name'] = $request->input('name');
  194. $params['sys_group_id'] = $request->input('sys_group_id');
  195. $params['type'] = $request->input('type');
  196. $params['url_list'] = $request->input('url_list');
  197. $params['title'] = $request->input('title');
  198. $params['description'] = $request->input('description');
  199. $params['cover_id'] = $request->input('cover_id');
  200. $params['behavior_notification'] = $request->input('behavior_notification');
  201. $params['dynamic_notification'] = $request->input('dynamic_notification');
  202. $params['customer_label'] = $request->input('customer_label');
  203. $params['tag_list'] = $request->input('tag_list');
  204. $params['radar_id'] = $request->input('radar_id');
  205. list($res, $code) = RadarService::radarUpdate($params);
  206. return self::returnValue($res, $code);
  207. }
  208. // 删除雷达
  209. public function radarDelete(Request $request)
  210. {
  211. $validator = \Validator::make($request->all(),[
  212. 'corpid' => 'required|string',
  213. 'radar_id' => 'required|integer'
  214. ]);
  215. if ($validator->fails()) {
  216. return self::returnValue($validator->getMessageBag(), 1102);
  217. }
  218. $params['corpid'] = $request->input('corpid');
  219. $params['radar_id'] = $request->input('radar_id');
  220. list($res, $code) = RadarService::radarDelete($params);
  221. return self::returnValue($res, $code);
  222. }
  223. // 雷达排序
  224. public function radarSortUpdate(Request $request)
  225. {
  226. $validator = \Validator::make($request->all(),[
  227. 'corpid' => 'required|string',
  228. 'operate_radar_id' => 'required|integer',
  229. ]);
  230. if ($validator->fails()) {
  231. return self::returnValue($validator->getMessageBag(), 1102);
  232. }
  233. $params['corpid'] = $request->input('corpid');
  234. $params['operate_radar_id'] = $request->input('operate_radar_id');
  235. $params['front_radar_id'] = $request->input('front_radar_id');
  236. $params['behind_radar_id'] = $request->input('behind_radar_id');
  237. $params['sys_group_id'] = $request->input('sys_group_id');
  238. list($res, $code) = RadarService::radarSortUpdate($params);
  239. return self::returnValue($res, $code);
  240. }
  241. public function dataStatisticsTotal(Request $request)
  242. {
  243. $validator = \Validator::make($request->all(),[
  244. 'corpid' => 'required|string',
  245. 'radar_id' => 'required|integer'
  246. ]);
  247. if ($validator->fails()) {
  248. return self::returnValue($validator->getMessageBag(), 1102);
  249. }
  250. $params['corpid'] = $request->input('corpid');
  251. $params['radar_id'] = $request->input('radar_id');
  252. $data = RadarService::dataStatisticsTotal($params);
  253. return self::returnValue($data);
  254. }
  255. // 数据分析--列表
  256. public function dataStatisticsList(Request $request)
  257. {
  258. $validator = \Validator::make($request->all(),[
  259. 'corpid' => 'required|string',
  260. 'radar_id' => 'required|integer'
  261. ]);
  262. if ($validator->fails()) {
  263. return self::returnValue($validator->getMessageBag(), 1102);
  264. }
  265. $params['corpid'] = $request->input('corpid');
  266. $params['radar_id'] = $request->input('radar_id');
  267. $params['page'] = $request->input('page', 1);
  268. $params['page_size'] = $request->input('page_size', 20);
  269. $params['channel'] = $request->input('channel');
  270. $params['customer_name'] = $request->input('customer_name');
  271. $params['start_date'] = $request->input('start_date');
  272. $params['end_date'] = $request->input('end_date');
  273. $params['user_list'] = $request->input('user_list');
  274. list($data, $count) = RadarService::dataStatisticsList($params);
  275. return self::returnPageValue($data, $count, $params['page_size'], $params['page']);
  276. }
  277. /**
  278. * H5页面需展示的雷达内容
  279. * */
  280. public function radarDetailForH5(Request $request)
  281. {
  282. $validator = \Validator::make($request->all(),[
  283. 'corpid' => 'required|string',
  284. 'radar_id' => 'required|integer',
  285. 'user_id' => 'required|string',
  286. 'token' => 'required|string',
  287. 'timestamp' => 'required',
  288. ]);
  289. if ($validator->fails()) {
  290. return self::returnValue($validator->getMessageBag(), 1102);
  291. }
  292. $corpid = $request->input('corpid');
  293. $radarId = $request->input('radar_id');
  294. $userId = $request->input('user_id');
  295. $token = $request->input('token');
  296. $timestamp = $request->input('timestamp');
  297. # 获取H5页面需要展示的雷达内容
  298. $errno = 0;
  299. $radarDetail = RadarService::radarDetailForH5($corpid, $radarId, $userId, $token, $timestamp, $errno);
  300. if($errno) return self::returnValue([] , $errno);
  301. return self::returnValue($radarDetail);
  302. }
  303. /**
  304. * 雷达获取的用户行为数据上报
  305. * */
  306. public function behaviorReport(Request $request)
  307. {
  308. $validator = \Validator::make($request->all(),[
  309. 'corpid' => 'required|string',
  310. 'radar_id' => 'required|integer',
  311. 'user_id' => 'required|string',
  312. 'token' => 'required|string',
  313. 'timestamp' => 'required',
  314. 'type' => 'required',
  315. 'request_id' => 'required',
  316. ]);
  317. if ($validator->fails()) {
  318. return self::returnValue($validator->getMessageBag(), 1102);
  319. }
  320. Log::logInfo('behaviorReport', $request->all(), 'interface');
  321. $param['corpid'] = $request->input('corpid');
  322. $param['radar_id'] = $request->input('radar_id');
  323. $param['user_id'] = $request->input('user_id');
  324. $param['external_userid'] = $request->input('external_userid');
  325. $param['openid'] = $request->input('openid');
  326. $param['device_id'] = $request->input('device_id');
  327. $param['channel'] = $request->input('channel'); // 渠道标识 1:朋友圈 2:群发消息 3:欢迎语 4:渠道活码
  328. $param['rule_id'] = $request->input('rule_id');
  329. $param['state'] = $request->input('state');
  330. $type = $request->input('type');
  331. $param['request_id'] = $request->input('request_id');
  332. $token = $request->input('token');
  333. $timestamp = $request->input('timestamp');
  334. # 数据上报
  335. $error = RadarService::behaviorReport($param, $type, $token, $timestamp);
  336. return self::returnValue([], $error);
  337. }
  338. // 渠道列表
  339. public function channelList()
  340. {
  341. $data = RadarService::channelList();
  342. return self::returnValue($data);
  343. }
  344. public function radarListForH5(Request $request)
  345. {
  346. $validator = \Validator::make($request->all(),[
  347. 'corpid' => 'required|string',
  348. 'group_id' => 'nullable|integer',
  349. ]);
  350. if ($validator->fails()) {
  351. return self::returnValue($validator->getMessageBag(), 1102);
  352. }
  353. $params['corpid'] = $request->input('corpid');
  354. $params['group_id'] = $request->input('group_id');
  355. $params['name'] = $request->input('name');
  356. $params['page'] = $request->input('page', 1);
  357. $params['page_size'] = $request->input('page_size', 20);
  358. list($data, $count) = RadarService::radarListForH5($params);
  359. return self::returnPageValue($data, $count, $params['page_size'], $params['page']);
  360. }
  361. // 获取h5中雷达组列表
  362. public function radarGroupListForH5(Request $request)
  363. {
  364. $validator = \Validator::make($request->all(),[
  365. 'corpid' => 'required|string',
  366. 'keyword' => 'nullable|string',
  367. ]);
  368. if ($validator->fails()) {
  369. return self::returnValue($validator->getMessageBag(), 1102);
  370. }
  371. $params['corpid'] = $request->input('corpid');
  372. $params['keyword'] = $request->input('keyword');
  373. $params['page'] = $request->input('page', 1);
  374. $params['page_size'] = $request->input('page_size', 20);
  375. list($data, $count) = RadarService::radarGroupList($params);
  376. return self::returnPageValue($data, $count, $params['page_size'], $params['page']);
  377. }
  378. public function getLinkMsgOfRadar(Request $request)
  379. {
  380. $validator = \Validator::make($request->all(),[
  381. 'corpid' => 'required|string',
  382. 'radar_id' => 'required|string',
  383. 'user_id' => 'required|string',
  384. ]);
  385. if ($validator->fails()) {
  386. return self::returnValue($validator->getMessageBag(), 1102);
  387. }
  388. $radarId = $request->input('radar_id');
  389. $corpid = $request->input('corpid');
  390. $userId = $request->input('user_id');
  391. $ruleId = time().rand(10000, 99999);
  392. $data = RadarService::getLinkMsgOfRadar($radarId, $corpid, $userId, 5, $ruleId);
  393. return self::returnValue($data);
  394. }
  395. }