企微短剧业务系统

MomentController.php 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Service\MomentService;
  4. use Illuminate\Http\Request;
  5. use App\Http\Controllers\Controller;
  6. use Illuminate\Validation\Rule;
  7. class MomentController extends Controller
  8. {
  9. /**
  10. * 创建朋友圈任务规则
  11. * */
  12. public function setRule(Request $request)
  13. {
  14. $validator = \Validator::make($request->all(),[
  15. 'corpid' => 'required|string',
  16. 'name' => 'required|string',
  17. 'filter_type' => ['required', Rule::in([1, 2])],
  18. 'send_type' => ['required', Rule::in([1, 2])],
  19. 'send_time' => 'required|date_format:Y-m-d H:i:s',
  20. 'content' => ['required_without:attachments', 'nullable'],
  21. 'attachments' => ['required_without:content', 'nullable'],
  22. ]);
  23. if ($validator->fails()) {
  24. return self::returnValue($validator->getMessageBag(), 1102);
  25. }
  26. $params = array();
  27. $ruleId = $request->input('rule_id');
  28. $params['corpid'] = $request->input('corpid');
  29. $params['admin_id'] = $request->input('admin_id');
  30. $params['name'] = $request->input('name');
  31. $params['filter_type'] = $request->input('filter_type'); // 朋友圈类型 1企业发表 2个人发表
  32. $params['send_type'] = $request->input('send_type'); // 发送类型 1立即发送 2定时发送
  33. $params['send_time'] = $request->input('send_time');
  34. $params['sender_list'] = $request->input('sender_list'); // 发送朋友圈成员userid集合
  35. $params['department_list'] = $request->input('department_list'); // 发送朋友圈部门id集合
  36. $params['customer_filter'] = $request->input('customer_filter'); // 0全部客户 1筛选客户
  37. $params['customer_tag_list'] = $request->input('customer_tag_list'); // 可见客户标签集合
  38. $params['content'] = $request->input('content');
  39. $params['attachments'] = $request->input('attachments');
  40. $params['operate_type'] = $request->input('operate_type', 1); // 运营类型 1单主体 2多主体
  41. $params['operator_group_id'] = $request->input('operator_group_id'); // 运营组ID
  42. $params['multiple_senders'] = $request->input('multiple_senders');
  43. $params['is_operation'] = $request->input('is_operation');
  44. # 设置群发规则
  45. $errNo = MomentService::setRule($ruleId, $params);
  46. return self::returnValue([], $errNo);
  47. }
  48. /**
  49. * 朋友圈任务列表
  50. * */
  51. public function taskList(Request $request)
  52. {
  53. $validator = \Validator::make($request->all(),[
  54. 'corpid' => 'required|string',
  55. 'send_time_start' => 'nullable|date_format:Y-m-d H:i:s',
  56. 'send_time_end' => 'nullable|date_format:Y-m-d H:i:s',
  57. 'create_time_start' => 'nullable|date_format:Y-m-d H:i:s',
  58. 'create_time_end' => 'nullable|date_format:Y-m-d H:i:s',
  59. 'filter_type' => ['nullable', Rule::in([1, 2])],
  60. ]);
  61. if ($validator->fails()) {
  62. return self::returnValue($validator->getMessageBag(), 1102);
  63. }
  64. $corpid = $request->input('corpid');
  65. $creatorId = $request->input('creator_id');
  66. $filterType = $request->input('filter_type');
  67. $sendTimeStart = $request->input('send_time_start');
  68. $sendTimeEnd = $request->input('send_time_end');
  69. $page = $request->input('page', 1);
  70. $pageSize = $request->input('page_size', 20);
  71. $createTimeStart = $request->input('create_time_start');
  72. $createTimeEnd = $request->input('create_time_end');
  73. $sortColumn = $request->input('sort_column','send_time');
  74. $sortMethod = $request->input('sort_method','desc');
  75. # 获取群发规则列表
  76. $errno = 0;
  77. list($list, $count) = MomentService::taskList(
  78. $corpid, $creatorId, $filterType, $sendTimeStart, $sendTimeEnd,$createTimeStart,$createTimeEnd,$sortColumn,$sortMethod, $page, $pageSize, $errno
  79. );
  80. if($errno) return self::returnValue([], $errno);
  81. return self::returnPageValue($list, $count, $pageSize, $page);
  82. }
  83. /**
  84. * 朋友圈任务详情
  85. * */
  86. public function taskDetail(Request $request)
  87. {
  88. $validator = \Validator::make($request->all(),[
  89. 'corpid' => 'required|string',
  90. 'rule_id' => 'required|integer',
  91. ]);
  92. if ($validator->fails()) {
  93. return self::returnValue($validator->getMessageBag(), 1102);
  94. }
  95. $corpid = $request->input('corpid');
  96. $ruleId = $request->input('rule_id');
  97. # 获取群发消息详情
  98. $errno = 0;
  99. $detail = MomentService::ruleDetail($corpid, $ruleId, $errno);
  100. return self::returnValue($detail, $errno);
  101. }
  102. /**
  103. * 朋友圈任务状态修改
  104. * */
  105. public function changeStatus(Request $request)
  106. {
  107. $validator = \Validator::make($request->all(),[
  108. 'corpid' => 'required|string',
  109. 'rule_id' => 'required|integer',
  110. 'status' => ['required', Rule::in([0, 1])],
  111. ]);
  112. if ($validator->fails()) {
  113. return self::returnValue($validator->getMessageBag(), 1102);
  114. }
  115. $corpid = $request->input('corpid');
  116. $status = $request->input('status');
  117. $ruleId = $request->input('rule_id');
  118. $errno = MomentService::updateRuleStatus($corpid, $ruleId, $status);
  119. return self::returnValue([], $errno);
  120. }
  121. /**
  122. * 朋友圈点赞评论详情接口
  123. */
  124. public function momentInteract(Request $request)
  125. {
  126. $validators = \Validator::make($request->all(), [
  127. 'corpid' => 'required|string',
  128. 'moment_id' => 'required|string',
  129. 'userid' => 'required|string'
  130. ]);
  131. if ($validators->fails()) {
  132. return self::returnValue($validators->getMessageBag(), 1102);
  133. }
  134. $corpid = $request->input('corpid');
  135. $moment_id = $request->input('moment_id');
  136. $userid = $request->input('userid');
  137. $res = MomentService::momentInteract($corpid, $moment_id, $userid);
  138. return self::returnValue($res);
  139. }
  140. /*
  141. * 查询满足对应条件的外部联系人数量
  142. * */
  143. public function customerMatchCount(Request $request)
  144. {
  145. $validator = \Validator::make($request->all(), [
  146. 'corpid' => 'required|string',
  147. ]);
  148. if ($validator->fails()) {
  149. return self::returnValue($validator->getMessageBag(), 1102);
  150. }
  151. $params = array();
  152. $params['corpid'] = $request->input('corpid');
  153. $params['filter_type'] = $request->input('filter_type'); // 朋友圈类型 1企业发表 2个人发表
  154. $params['sender_list'] = $request->input('sender_list'); // 发送朋友圈成员userid集合
  155. $params['department_list'] = $request->input('department_list'); // 发送朋友圈部门id集合
  156. $params['customer_filter'] = $request->input('customer_filter'); // 0全部客户 1筛选客户
  157. $params['customer_tag_list'] = $request->input('customer_tag_list'); // 可见客户标签集合
  158. # 运营类型
  159. $params['operate_type'] = $request->input('operate_type', 1);
  160. $params['operator_group_id'] = $request->input('operator_group_id');// 运营组ID
  161. $params['multiple_senders'] = $request->input('multiple_senders');
  162. $params['is_operation'] = $request->input('is_operation');
  163. $total = 0;
  164. # 朋友圈预计展示到的客户数
  165. if(1 == $params['operate_type']){
  166. $errNo = MomentService::getCustomerMatchCount($params, $total);
  167. } else {
  168. $errNo = MomentService::getMultipleCorpCustomerMatchCount($params, $total);
  169. }
  170. return self::returnValue(['total' => $total], $errNo);
  171. }
  172. /**
  173. * 朋友圈发送记录列表
  174. * @param Request $request
  175. * @return array
  176. */
  177. public function momentRecordList(Request $request)
  178. {
  179. $validators = \Validator::make($request->all(),[
  180. 'corpid' => 'required|string',
  181. 'user_id_list' => 'nullable|array',
  182. 'send_time_start' => 'nullable|date_format:Y-m-d H:i:s',
  183. 'send_time_end' => 'nullable|date_format:Y-m-d H:i:s',
  184. ]);
  185. if ($validators->fails()) {
  186. return self::returnValue($validators->getMessageBag(), 1102);
  187. }
  188. $corpid = $request->input('corpid');
  189. $userIdList = $request->input('user_id_list');
  190. $sendTimeStart = $request->input('send_time_start');
  191. $sendTimeEnd = $request->input('send_time_end');
  192. $page = $request->input('page', 1);
  193. $pageSize = $request->input('page_size', 20);
  194. $errno = 0;
  195. list($list, $count) = MomentService::momentRecordList(
  196. $corpid, $userIdList, $sendTimeStart, $sendTimeEnd, $page, $pageSize, $errno
  197. );
  198. if($errno) return self::returnValue([], $errno);
  199. return self::returnPageValue($list, $count, $pageSize, $page);
  200. }
  201. /**
  202. * 给朋友圈消息未发送成员发送消息提醒
  203. * */
  204. public function noticeUser(Request $request)
  205. {
  206. $validator = \Validator::make($request->all(),[
  207. 'corpid' => 'required|string',
  208. 'rule_id' => 'required|integer',
  209. ]);
  210. if ($validator->fails()) {
  211. return self::returnValue($validator->getMessageBag(), 1102);
  212. }
  213. $corpid = $request->input('corpid');
  214. $ruleId = $request->input('rule_id');
  215. $errno = MomentService::noticeUser($corpid, $ruleId);
  216. return self::returnValue([], $errno);
  217. }
  218. /**
  219. * 安卓客服端获取待确认群发消息列表
  220. * */
  221. public function senderConfirmList(Request $request)
  222. {
  223. $validator = \Validator::make($request->all(),[
  224. 'device_id' => 'required|string',
  225. ]);
  226. if ($validator->fails()) {
  227. return self::returnValue($validator->getMessageBag(), 1102);
  228. }
  229. $deviceId = $request->input('device_id');
  230. # 获取待确认的群发消息
  231. $msgList = MomentService::senderConfirmList($deviceId);
  232. return self::returnValue(['list' => $msgList]);
  233. }
  234. }