企微短剧业务系统

MassMsgController.php 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Service\MassMsgRuleService;
  4. use App\Service\MassMsgService;
  5. use Illuminate\Http\Request;
  6. use App\Http\Controllers\Controller;
  7. use Illuminate\Validation\Rule;
  8. class MassMsgController extends Controller
  9. {
  10. /*
  11. * 设置群发消息规则
  12. * */
  13. public function setRule(Request $request)
  14. {
  15. $validator = \Validator::make($request->all(),[
  16. 'corpid' => 'required|string',
  17. 'name' => 'required|string',
  18. 'send_type' => ['required', Rule::in([1, 2])],
  19. 'send_time' => 'required|date_format:Y-m-d H:i:s',
  20. 'chat_type' => ['nullable', Rule::in([1, 2])],
  21. 'content' => ['required_without:attachments', 'nullable'],
  22. 'attachments' => ['required_without:content', 'nullable'],
  23. 'add_time_start' => 'nullable|date_format:Y-m-d H:i:s',
  24. 'add_time_end' => 'nullable|date_format:Y-m-d H:i:s',
  25. 'tag_screen_type' => ['nullable', Rule::in([0, 1, 2, 3])],
  26. 'customer_filter' => ['nullable', Rule::in([0, 1])],
  27. 'pay_status' => ['nullable', Rule::in([0, 1])],
  28. 'pay_num_min' => 'nullable|int',
  29. 'pay_num_max' => 'nullable|int',
  30. ]);
  31. if ($validator->fails()) {
  32. return self::returnValue($validator->getMessageBag(), 1102);
  33. }
  34. $params = array();
  35. $ruleId = $request->input('rule_id');
  36. $params['corpid'] = $request->input('corpid');
  37. $params['admin_id'] = $request->input('admin_id');
  38. $params['name'] = $request->input('name');
  39. $params['send_type'] = $request->input('send_type'); // 发送类型 1:立即发送 2:定时发送
  40. $params['send_time'] = $request->input('send_time');
  41. $params['senders'] = $request->input('senders'); // 群发账号,为空代表全部群发账号
  42. $params['chat_type'] = $request->input('chat_type', 1); // 1:single,表示发送给客户 2:group表示发送给客户群
  43. $params['customer_filter'] = $request->input('customer_filter'); // 0:全部客户 1:筛选客户
  44. $params['content'] = $request->input('content');
  45. $params['attachments'] = $request->input('attachments');
  46. $params['gender'] = $request->input('gender'); // 客户性别 0未知 1男性 2女性
  47. $params['is_customize_time'] = $request->input('is_customize_time', 0); // 是否自定义了客户添加时间
  48. $params['timeline'] = $request->input('timeline', 0); // 时间线 单位:小时
  49. $params['add_time_start'] = $request->input('add_time_start');
  50. $params['add_time_end'] = $request->input('add_time_end');
  51. // 标签筛选方式 0未设置标签筛选 1所选标签满足其一 2所选标签全部满足 3无任何标签
  52. $params['tag_screen_type'] = $request->input('tag_screen_type', 0);
  53. $params['tag_list'] = $request->input('tag_list');
  54. $params['exclude_tag_list'] = $request->input('exclude_tag_list');
  55. $params['pay_status'] = $request->input('pay_status'); // 是否付费
  56. $params['pay_num_min'] = $request->input('pay_num_min'); // 最小付费次数
  57. $params['pay_num_max'] = $request->input('pay_num_max'); // 最大付费次数
  58. $params['operate_type'] = $request->input('operate_type', 1);# 运营类型 1单主体 2多主体
  59. $params['add_days_later'] = $request->input('add_days_later'); // 添加客服x天之后(非只能推送客户)
  60. $params['operator_group_id'] = $request->input('operator_group_id');// 运营组ID
  61. $params['multiple_senders'] = $request->input('multiple_senders');
  62. $params['is_operation'] = $request->input('is_operation');
  63. # 设置群发规则
  64. $errNo = MassMsgRuleService::setRule($ruleId, $params);
  65. return self::returnValue([], $errNo);
  66. }
  67. public function getLicenseExpirationUserList(Request $request) {
  68. $params['corpid'] = $request->input('corpid');
  69. $params['senders'] = $request->input('senders'); // 群发账号,为空代表全部群发账号
  70. $params['operator_group_id'] = $request->input('operator_group_id');// 运营组ID
  71. $params['multiple_senders'] = $request->input('multiple_senders');
  72. $params['is_operation'] = $request->input('is_operation');
  73. $params['operate_type'] = $request->input('operate_type', 1);
  74. if(1 == $params['operate_type']){
  75. $userList = MassMsgRuleService::getLicenseExpirationUserList($params);
  76. $userList = [$userList];
  77. } else {
  78. $userList = MassMsgRuleService::getMultipleCorpLicenseExpirationUserList($params);
  79. }
  80. return self::returnValue($userList);
  81. }
  82. /**
  83. * 查询满足对应条件的外部联系人数量
  84. * */
  85. public function customerMatchCount(Request $request)
  86. {
  87. $validator = \Validator::make($request->all(),[
  88. 'corpid' => 'required|string',
  89. 'add_time_start' => 'nullable|date_format:Y-m-d H:i:s',
  90. 'add_time_end' => 'nullable|date_format:Y-m-d H:i:s',
  91. 'tag_screen_type' => ['nullable', Rule::in([0, 1, 2, 3])],
  92. 'customer_filter' => ['nullable', Rule::in([0, 1])],
  93. 'pay_status' => ['nullable', Rule::in([0, 1])],
  94. 'pay_num_min' => 'nullable|int',
  95. 'pay_num_max' => 'nullable|int',
  96. ]);
  97. if ($validator->fails()) {
  98. return self::returnValue($validator->getMessageBag(), 1102);
  99. }
  100. $params = array();
  101. $params['corpid'] = $request->input('corpid');
  102. $params['senders'] = $request->input('senders'); // 群发账号,为空代表全部群发账号
  103. $params['customer_filter'] = $request->input('customer_filter'); // 0:全部客户 1:筛选客户
  104. $params['gender'] = $request->input('gender'); // 客户性别 0未知 1男性 2女性
  105. $params['is_customize_time'] = $request->input('is_customize_time', 1); // 是否自定义了客户添加时间
  106. $params['timeline'] = $request->input('timeline', 0); // 时间线 单位:小时
  107. $params['add_time_start'] = $request->input('add_time_start');
  108. $params['add_time_end'] = $request->input('add_time_end');
  109. $params['send_time'] = $request->input('send_time');
  110. $params['tag_screen_type'] = $request->input('tag_screen_type', 0); // 标签筛选方式 0未设置标签筛选 1所选标签满足其一 2所选标签全部满足 3无任何标签
  111. $params['tag_list'] = $request->input('tag_list');
  112. $params['exclude_tag_list'] = $request->input('exclude_tag_list');
  113. // 付费情况
  114. $params['pay_status'] = $request->input('pay_status'); // 是否付费
  115. $params['pay_num_min'] = $request->input('pay_num_min'); // 最小付费次数
  116. $params['pay_num_max'] = $request->input('pay_num_max'); // 最大付费次数
  117. # 运营类型
  118. $params['operate_type'] = $request->input('operate_type', 1);
  119. $params['add_days_later'] = $request->input('add_days_later');
  120. $params['operator_group_id'] = $request->input('operator_group_id');// 运营组ID
  121. $params['multiple_senders'] = $request->input('multiple_senders');
  122. $params['is_operation'] = $request->input('is_operation');
  123. $total = 0;
  124. if(1 == $params['operate_type']){
  125. $errNo = MassMsgRuleService::getCustomerMatchCount($params, $total);
  126. } else {
  127. $errNo = MassMsgRuleService::getMultipleCorpCustomerMatchCount($params, $total);
  128. }
  129. return self::returnValue(['total' => $total], $errNo);
  130. }
  131. /*
  132. * 群发消息列表
  133. * */
  134. public function ruleLists(Request $request)
  135. {
  136. $validator = \Validator::make($request->all(),[
  137. 'corpid' => 'required|string',
  138. 'send_time_start' => 'nullable|date_format:Y-m-d H:i:s',
  139. 'send_time_end' => 'nullable|date_format:Y-m-d H:i:s',
  140. 'create_time_start' => 'nullable|date_format:Y-m-d H:i:s',
  141. 'create_time_end' => 'nullable|date_format:Y-m-d H:i:s',
  142. ]);
  143. if ($validator->fails()) {
  144. return self::returnValue($validator->getMessageBag(), 1102);
  145. }
  146. $corpid = $request->input('corpid');
  147. $creatorId = $request->input('creator_id');
  148. $keyword = $request->input('keyword');
  149. $sendTimeStart = $request->input('send_time_start');
  150. $sendTimeEnd = $request->input('send_time_end');
  151. $page = $request->input('page', 1);
  152. $pageSize = $request->input('page_size', 20);
  153. $createTimeStart = $request->input('create_time_start');
  154. $createTimeEnd = $request->input('create_time_end');
  155. $sortColumn = $request->input('sort_column','send_time');
  156. $sortMethod = $request->input('sort_method','desc');
  157. # 获取群发规则列表
  158. $errno = 0;
  159. list($list, $count) = MassMsgRuleService::ruleList(
  160. $corpid, $creatorId, $keyword, $sendTimeStart, $sendTimeEnd, $createTimeStart,$createTimeEnd,$sortColumn,$sortMethod, $page, $pageSize, $errno
  161. );
  162. if($errno) return self::returnValue([], $errno);
  163. return self::returnPageValue($list, $count, $pageSize, $page);
  164. }
  165. /*
  166. * 群发消息详情
  167. * */
  168. public function ruleDetail(Request $request)
  169. {
  170. $validator = \Validator::make($request->all(),[
  171. 'corpid' => 'required|string',
  172. 'rule_id' => 'required|integer',
  173. ]);
  174. if ($validator->fails()) {
  175. return self::returnValue($validator->getMessageBag(), 1102);
  176. }
  177. $corpid = $request->input('corpid');
  178. $ruleId = $request->input('rule_id');
  179. # 获取群发消息详情
  180. $errno = 0;
  181. $detail = MassMsgRuleService::ruleDetail($corpid, $ruleId, $errno);
  182. return self::returnValue($detail, $errno);
  183. }
  184. /*
  185. * 群发规则删除
  186. * */
  187. public function updateStatus(Request $request)
  188. {
  189. $validator = \Validator::make($request->all(),[
  190. 'corpid' => 'required|string',
  191. 'rule_id' => 'required|integer',
  192. 'status' => ['required', Rule::in([0, 1])],
  193. ]);
  194. if ($validator->fails()) {
  195. return self::returnValue($validator->getMessageBag(), 1102);
  196. }
  197. $corpid = $request->input('corpid');
  198. $status = $request->input('status');
  199. $ruleId = $request->input('rule_id');
  200. $errno = MassMsgRuleService::updateRuleStatus($corpid, $ruleId, $status);
  201. return self::returnValue([], $errno);
  202. }
  203. /*
  204. * 给朋友圈消息未发送成员发送消息提醒
  205. * */
  206. public function noticeUser(Request $request)
  207. {
  208. $validator = \Validator::make($request->all(),[
  209. 'corpid' => 'required|string',
  210. 'rule_id' => 'required|integer',
  211. ]);
  212. if ($validator->fails()) {
  213. return self::returnValue($validator->getMessageBag(), 1102);
  214. }
  215. $corpid = $request->input('corpid');
  216. $ruleId = $request->input('rule_id');
  217. $errno = MassMsgRuleService::noticeUser($corpid, $ruleId);
  218. return self::returnValue([], $errno);
  219. }
  220. /*
  221. * 群发消息数据概览
  222. * @param Request $request
  223. * @return array
  224. */
  225. public function overview(Request $request){
  226. $validator = \Validator::make($request->all(),[
  227. 'corpid' => 'required|string',
  228. 'rule_id' => 'required|integer',
  229. ]);
  230. if ($validator->fails()) {
  231. return self::returnValue($validator->getMessageBag(), 1102);
  232. }
  233. $corpid = $request->input('corpid');
  234. $ruleId = $request->input('rule_id');
  235. $res = MassMsgRuleService::overview($corpid, $ruleId);
  236. return self::returnValue( $res , 0 );
  237. }
  238. /*
  239. * 群发消息发送成员名单
  240. * @param Request $request
  241. * @return array
  242. */
  243. public function sender_list(Request $request){
  244. $support_type = ['all','sent','unsent','fail']; //支持的查询类型
  245. $validator = \Validator::make($request->all(),[
  246. 'corpid' => 'required|string',
  247. 'rule_id' => 'required|integer',
  248. 'type' => Rule::in($support_type)
  249. ]);
  250. if ($validator->fails()) {
  251. return self::returnValue($validator->getMessageBag(), 1102);
  252. }
  253. $corpid = $request->input('corpid');
  254. $ruleId = $request->input('rule_id');
  255. $type = $request->input("type",$support_type[0]);
  256. $page = $request->input("page",1);
  257. $page_size = $request->input("page_size",20);
  258. $keyword = $request->input("keyword");
  259. list($total,$list) = MassMsgRuleService::sender_list($corpid, $ruleId,$type,$keyword,$page,$page_size);
  260. return self::returnPageValue($list,$total,$page_size,$page);
  261. }
  262. /*
  263. * 群发消息发送成员名单 - 导出
  264. * @param Request $request
  265. * @return array
  266. */
  267. public function sender_list_export(Request $request){
  268. $support_type = ['all','sent','unsent','fail']; //支持的查询类型
  269. $validator = \Validator::make($request->all(),[
  270. 'corpid' => 'required|string',
  271. 'rule_id' => 'required|integer',
  272. 'type' => Rule::in($support_type)
  273. ]);
  274. if ($validator->fails()) {
  275. return self::returnValue($validator->getMessageBag(), 1102);
  276. }
  277. $corpid = $request->input('corpid');
  278. $ruleId = $request->input('rule_id');
  279. $type = $request->input("type",$support_type[0]);
  280. $keyword = $request->input("keyword");
  281. MassMsgRuleService::sender_list_export($corpid, $ruleId,$type,$keyword);
  282. }
  283. /*
  284. * 获取群发详情-客户列表
  285. * @param Request $request
  286. * @return array
  287. */
  288. public function massSendCustList(Request $request)
  289. {
  290. $validator = \Validator::make($request->all(),[
  291. 'rule_id' => 'required|int',
  292. 'sender' => 'nullable|string',
  293. 'name' => 'nullable|string',
  294. 'type' => 'nullable|int|in:0,1,2,3,4'
  295. ]);
  296. if ($validator->fails()) {
  297. return self::returnValue($validator->getMessageBag(), 1102);
  298. }
  299. $rule_id = $request->input('rule_id');
  300. $sender = $request->input('sender');
  301. $name = $request->input('name');
  302. $type = $request->input('type');
  303. $senderCorpid = $request->input('sender_corpid');
  304. $page = $request->input('page', 1);
  305. $pagesize = (int)$request->input('page_size', 20);
  306. list($data, $total) = MassMsgRuleService::massSendCustList($rule_id, $sender, $name, $type, $page, $pagesize, $senderCorpid);
  307. return self::returnPageValue($data, $total, $pagesize, $page);
  308. }
  309. /*
  310. * 获取群发详情-客户列表导出
  311. * @param Request $request
  312. * @return array
  313. */
  314. public function massSendCustListExport(Request $request)
  315. {
  316. $validator = \Validator::make($request->all(),[
  317. 'rule_id' => 'required|int',
  318. 'sender' => 'nullable|string',
  319. 'name' => 'nullable|string',
  320. 'type' => 'nullable|int|in:0,1,2,3,4'
  321. ]);
  322. if ($validator->fails()) {
  323. return self::returnValue($validator->getMessageBag(), 1102);
  324. }
  325. $rule_id = $request->input('rule_id');
  326. $sender = $request->input('sender');
  327. $name = $request->input('name');
  328. $type = $request->input('type');
  329. $senderCorpid = $request->input('sender_corpid');
  330. MassMsgRuleService::massSendCustListExport($rule_id, $sender, $name, $type, $senderCorpid);
  331. }
  332. /**
  333. * 安卓客服端获取待确认群发消息列表
  334. * */
  335. public function senderConfirmList(Request $request)
  336. {
  337. $validator = \Validator::make($request->all(),[
  338. 'device_id' => 'required|string',
  339. ]);
  340. if ($validator->fails()) {
  341. return self::returnValue($validator->getMessageBag(), 1102);
  342. }
  343. $deviceId = $request->input('device_id');
  344. # 获取待确认的群发消息
  345. $msgList = MassMsgService::senderConfirmList($deviceId);
  346. return self::returnValue(['list' => $msgList]);
  347. }
  348. public function sendNoticeList(Request $request)
  349. {
  350. $validator = \Validator::make($request->all(),[
  351. 'start_date' => 'nullable|date',
  352. 'end_date' => 'nullable|date'
  353. ]);
  354. if ($validator->fails()) {
  355. return self::returnValue($validator->getMessageBag(), 1102);
  356. }
  357. $params['sys_group_id'] = $request->input('sys_group_id');
  358. $params['start_date'] = $request->input('start_date');
  359. $params['end_date'] = $request->input('end_date');
  360. $params['corp_id'] = $request->input('corp_id');
  361. $params['user_name'] = $request->input('user_name');
  362. $params['send_status'] = $request->input('send_status');
  363. $params['msg_type'] = $request->input('msg_type');
  364. $page = $request->input('page', 1);
  365. $pageSize = $request->input('page_size');
  366. list($data, $count) = MassMsgService::sendNoticeList($params, $page, $pageSize);
  367. return self::returnPageValue($data, $count, $pageSize, $page);
  368. }
  369. public function sendNoticeListNew(Request $request) {
  370. $validator = \Validator::make($request->all(),[
  371. 'start_date' => 'nullable|date',
  372. 'end_date' => 'nullable|date',
  373. 'msg_type' => 'required|in:1,2,3,4'
  374. ]);
  375. if ($validator->fails()) {
  376. return self::returnValue($validator->getMessageBag(), 1102);
  377. }
  378. $params['sys_group_id'] = $request->input('sys_group_id');
  379. $params['start_date'] = $request->input('start_date');
  380. $params['end_date'] = $request->input('end_date');
  381. $params['corp_id'] = $request->input('corp_id');
  382. $params['user_name'] = $request->input('user_name');
  383. $params['msg_type'] = $request->input('msg_type');
  384. $page = $request->input('page', 1);
  385. $pageSize = $request->input('page_size');
  386. list($data, $count) = MassMsgService::sendNoticeListNew($params, $page, $pageSize);
  387. return self::returnPageValue($data, $count, $pageSize, $page);
  388. }
  389. }