企微短剧业务系统

CircleMassMsgController.php 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Service\CircleMassMsgRecordService;
  4. use App\Service\CircleMassMsgService;
  5. use Illuminate\Http\Request;
  6. use App\Http\Controllers\Controller;
  7. use Illuminate\Validation\Rule;
  8. class CircleMassMsgController 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. 'interval_type' => ['required', Rule::in([1, 2])],
  19. 'content' => ['required_without:attachments', 'nullable'],
  20. 'attachments' => ['required_without:content', 'nullable'],
  21. 'tag_screen_type' => ['nullable', Rule::in([0, 1, 2, 3])],
  22. 'customer_filter' => ['nullable', Rule::in([0, 1])],
  23. 'pay_status' => ['nullable', Rule::in([0, 1])],
  24. 'pay_num_min' => 'nullable|int',
  25. 'pay_num_max' => 'nullable|int',
  26. ]);
  27. if ($validator->fails()) {
  28. return self::returnValue($validator->getMessageBag(), 1102);
  29. }
  30. $params = array();
  31. $ruleId = $request->input('rule_id');
  32. $params['corpid'] = $request->input('corpid');
  33. $params['admin_id'] = $request->input('admin_id');
  34. $params['name'] = $request->input('name');
  35. $params['is_all'] = $request->input('is_all', 0); // 是否应用于全部员工 0否 1是
  36. $params['senders'] = $request->input('senders'); // 群发账号集合
  37. $params['content'] = $request->input('content');
  38. $params['attachments'] = $request->input('attachments');
  39. $params['gender'] = $request->input('gender', 3); // 客户性别 0未知 1男性 2女性 3全部
  40. $params['interval_type'] = $request->input('interval_type', 0); // 脚本检索间隔类型 1指定时间点检索 2间隔指定时间段检索
  41. $params['interval_time'] = $request->input('interval_time', 0); // 用户添加间隔时间。 单位:分钟
  42. $params['interval'] = $request->input('interval', 0); // 指定间隔小时数,interval_type为2时生效
  43. $params['time_points'] = $request->input('time_points'); // 需要检索的时间点集合,interval_type为1时生效
  44. $params['tag_screen_type'] = $request->input('tag_screen_type', 0); // 标签筛选方式 0未设置标签筛选 1所选标签满足其一 2所选标签全部满足 3无任何标签
  45. $params['tag_list'] = $request->input('tag_list');
  46. $params['exclude_tag_list'] = $request->input('exclude_tag_list');
  47. // 付费情况
  48. $params['pay_status'] = $request->input('pay_status'); // 是否付费 0:未付费 1:付费
  49. $params['pay_num_min'] = $request->input('pay_num_min'); // 最小付费次数
  50. $params['pay_num_max'] = $request->input('pay_num_max'); // 最大付费次数
  51. # 智能群发规则设置
  52. $errNo = CircleMassMsgService::setRule($ruleId, $params);
  53. return self::returnValue([], $errNo);
  54. }
  55. /**
  56. * 群发消息列表
  57. * */
  58. public function recordLists(Request $request)
  59. {
  60. $validator = \Validator::make($request->all(),[
  61. 'corpid' => 'required|string',
  62. 'rule_id' => 'required|integer',
  63. 'send_time_start' => 'nullable|date_format:Y-m-d H:i:s',
  64. 'send_time_end' => 'nullable|date_format:Y-m-d H:i:s',
  65. ]);
  66. if ($validator->fails()) {
  67. return self::returnValue($validator->getMessageBag(), 1102);
  68. }
  69. $corpid = $request->input('corpid');
  70. $ruleId = $request->input('rule_id');
  71. $sendTimeStart = $request->input('send_time_start');
  72. $sendTimeEnd = $request->input('send_time_end');
  73. $page = $request->input('page', 1);
  74. $pageSize = $request->input('page_size', 20);
  75. $sortColumn = $request->input('sort_column','send_time');
  76. $sortMethod = $request->input('sort_method','desc');
  77. # 获取群发规则列表
  78. $errno = 0;
  79. list($list, $count) = CircleMassMsgRecordService::recordList(
  80. $corpid, $ruleId, $sendTimeStart, $sendTimeEnd, $sortColumn, $sortMethod, $page, $pageSize, $errno
  81. );
  82. if($errno) return self::returnValue([], $errno);
  83. return self::returnPageValue($list, $count, $pageSize, $page);
  84. }
  85. /**
  86. * 智能群发规则列表
  87. * */
  88. public function ruleLists(Request $request)
  89. {
  90. $validator = \Validator::make($request->all(),[
  91. 'corpid' => 'required|string',
  92. 'create_time_start' => 'nullable|date_format:Y-m-d H:i:s',
  93. 'create_time_end' => 'nullable|date_format:Y-m-d H:i:s',
  94. ]);
  95. if ($validator->fails()) {
  96. return self::returnValue($validator->getMessageBag(), 1102);
  97. }
  98. $corpid = $request->input('corpid');
  99. $creatorId = $request->input('creator_id');
  100. $createTimeStart = $request->input('create_time_start');
  101. $createTimeEnd = $request->input('create_time_end');
  102. $page = $request->input('page', 1);
  103. $pageSize = $request->input('page_size', 20);
  104. # 获取群发规则列表
  105. $errno = 0;
  106. list($list, $count) = CircleMassMsgService::ruleList(
  107. $corpid, $creatorId, $createTimeStart,$createTimeEnd, $page, $pageSize, $errno
  108. );
  109. if($errno) return self::returnValue([], $errno);
  110. return self::returnPageValue($list, $count, $pageSize, $page);
  111. }
  112. public function recordDetail(Request $request)
  113. {
  114. $validator = \Validator::make($request->all(),[
  115. 'corpid' => 'required|string',
  116. 'rule_id' => 'required|integer',
  117. 'send_num' => 'required|numeric',
  118. 'send_date' => 'required|date',
  119. ]);
  120. if ($validator->fails()) {
  121. return self::returnValue($validator->getMessageBag(), 1102);
  122. }
  123. $corpid = $request->input('corpid');
  124. $ruleId = $request->input('rule_id');
  125. $sendNum = $request->input('send_num');
  126. $sendDate = $request->input('send_date');
  127. # 获取群发消息详情
  128. $errno = 0;
  129. $detail = CircleMassMsgRecordService::recordDetail($corpid, $ruleId, $sendNum, $sendDate, $errno);
  130. return self::returnValue($detail, $errno);
  131. }
  132. /**
  133. * 智能群发规则详情
  134. * */
  135. public function ruleDetail(Request $request)
  136. {
  137. $validator = \Validator::make($request->all(),[
  138. 'corpid' => 'required|string',
  139. 'rule_id' => 'required|integer',
  140. ]);
  141. if ($validator->fails()) {
  142. return self::returnValue($validator->getMessageBag(), 1102);
  143. }
  144. $corpid = $request->input('corpid');
  145. $ruleId = $request->input('rule_id');
  146. # 获取智能群发规则详情
  147. $errno = 0;
  148. $detail = CircleMassMsgService::ruleDetail($corpid, $ruleId, $errno);
  149. return self::returnValue($detail, $errno);
  150. }
  151. /**
  152. * 群发消息数据概览
  153. * @param Request $request
  154. * @return array
  155. */
  156. public function overview(Request $request){
  157. $validator = \Validator::make($request->all(),[
  158. 'corpid' => 'required|string',
  159. 'rule_id' => 'required|integer',
  160. 'send_num' => 'required|numeric',
  161. 'send_date' => 'required|date'
  162. ]);
  163. if ($validator->fails()) {
  164. return self::returnValue($validator->getMessageBag(), 1102);
  165. }
  166. $corpid = $request->input('corpid');
  167. $ruleId = $request->input('rule_id');
  168. $sendNum = $request->input('send_num');
  169. $sendDate = $request->input('send_date');
  170. $res = CircleMassMsgRecordService::overview($corpid, $ruleId, $sendNum, $sendDate);
  171. return self::returnValue( $res , 0 );
  172. }
  173. /**
  174. * 群发消息发送成员名单
  175. * @param Request $request
  176. * @return array
  177. */
  178. public function senderList(Request $request){
  179. $support_type = ['all','sent','unsent','fail']; //支持的查询类型
  180. $validator = \Validator::make($request->all(),[
  181. 'corpid' => 'required|string',
  182. 'rule_id' => 'required|integer',
  183. 'send_num' => 'required|numeric',
  184. 'send_date' => 'required|date',
  185. 'type' => Rule::in($support_type)
  186. ]);
  187. if ($validator->fails()) {
  188. return self::returnValue($validator->getMessageBag(), 1102);
  189. }
  190. $corpid = $request->input('corpid');
  191. $ruleId = $request->input('rule_id');
  192. $sendNum = $request->input('send_num');
  193. $sendDate = $request->input('send_date');
  194. $type = $request->input("type",$support_type[0]);
  195. $page = $request->input("page",1);
  196. $pageSize = $request->input("page_size",20);
  197. $keyword = $request->input("keyword");
  198. list($total,$list) = CircleMassMsgRecordService::senderList($corpid, $ruleId, $sendNum, $sendDate, $type, $keyword, $page, $pageSize);
  199. return self::returnPageValue($list,$total,$pageSize,$page);
  200. }
  201. /**
  202. * 群发消息发送成员名单 - 导出
  203. * @param Request $request
  204. * @return array
  205. */
  206. public function senderListExport(Request $request){
  207. $support_type = ['all','sent','unsent','fail']; //支持的查询类型
  208. $validator = \Validator::make($request->all(),[
  209. 'corpid' => 'required|string',
  210. 'rule_id' => 'required|integer',
  211. 'send_num' => 'required|numeric',
  212. 'send_date' => 'required|date',
  213. 'type' => Rule::in($support_type)
  214. ]);
  215. if ($validator->fails()) {
  216. return self::returnValue($validator->getMessageBag(), 1102);
  217. }
  218. $corpid = $request->input('corpid');
  219. $ruleId = $request->input('rule_id');
  220. $sendNum = $request->input('send_num');
  221. $sendDate = $request->input('send_date');
  222. $type = $request->input("type",$support_type[0]);
  223. $keyword = $request->input("keyword");
  224. CircleMassMsgRecordService::senderListExport($corpid, $ruleId, $sendNum, $sendDate, $type, $keyword);
  225. }
  226. /**
  227. * 获取群发详情-客户列表
  228. * @param Request $request
  229. * @return array
  230. */
  231. public function massSendCustList(Request $request)
  232. {
  233. $validator = \Validator::make($request->all(),[
  234. 'rule_id' => 'required|int',
  235. 'send_num' => 'required|numeric',
  236. 'send_date' => 'required|date',
  237. 'sender' => 'nullable|string',
  238. 'name' => 'nullable|string',
  239. 'type' => 'nullable|int|in:0,1,2,3,4'
  240. ]);
  241. if ($validator->fails()) {
  242. return self::returnValue($validator->getMessageBag(), 1102);
  243. }
  244. $ruleId = $request->input('rule_id');
  245. $sendNum = $request->input('send_num');
  246. $sendDate = $request->input('send_date');
  247. $sender = $request->input('sender');
  248. $name = $request->input('name');
  249. $type = $request->input('type');
  250. $page = $request->input('page', 1);
  251. $pageSize = (int)$request->input('page_size', 20);
  252. list($data, $total) = CircleMassMsgRecordService::massSendCustList($ruleId, $sendNum, $sendDate, $sender, $name, $type, $page, $pageSize);
  253. return self::returnPageValue($data, $total, $pageSize, $page);
  254. }
  255. /**
  256. * 获取群发详情-客户列表导出
  257. * @param Request $request
  258. * @return array
  259. */
  260. public function massSendCustListExport(Request $request)
  261. {
  262. $validator = \Validator::make($request->all(),[
  263. 'rule_id' => 'required|int',
  264. 'send_num' => 'required|numeric',
  265. 'send_date' => 'required|date',
  266. 'sender' => 'nullable|string',
  267. 'name' => 'nullable|string',
  268. 'type' => 'nullable|int|in:0,1,2,3,4'
  269. ]);
  270. if ($validator->fails()) {
  271. return self::returnValue($validator->getMessageBag(), 1102);
  272. }
  273. $ruleId = $request->input('rule_id');
  274. $sendNum = $request->input('send_num');
  275. $sendDate = $request->input('send_date');
  276. $sender = $request->input('sender');
  277. $name = $request->input('name');
  278. $type = $request->input('type');
  279. CircleMassMsgRecordService::massSendCustListExport($ruleId, $sendNum, $sendDate, $sender, $name, $type);
  280. }
  281. /**
  282. * 智能群发规则状态变更
  283. * */
  284. public function updateStatus(Request $request)
  285. {
  286. $validator = \Validator::make($request->all(),[
  287. 'corpid' => 'required|string',
  288. 'rule_id' => 'required|integer',
  289. 'status' => ['required', Rule::in([0, 1])],
  290. ]);
  291. if ($validator->fails()) {
  292. return self::returnValue($validator->getMessageBag(), 1102);
  293. }
  294. $corpid = $request->input('corpid');
  295. $status = $request->input('status');
  296. $ruleId = $request->input('rule_id');
  297. $errno = CircleMassMsgService::updateRuleStatus($corpid, $ruleId, $status);
  298. return self::returnValue([], $errno);
  299. }
  300. }