企微短剧业务系统

MassMsgCancelService.php 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace App\Service;
  3. use App\Models\ChatGroupMassMsg;
  4. use App\Models\ChatGroupMassMsgRecord;
  5. use App\Models\MassMsg;
  6. use App\Models\MassMsgCancel;
  7. use App\Models\MassMsgRecord;
  8. use App\Models\MomentRecord;
  9. use App\Models\MomentTask;
  10. use App\Models\PeriodMassMsg\PeriodMassMsg;
  11. use App\Models\PeriodMassMsg\PeriodMassMsgRecord;
  12. use App\Models\System\Users;
  13. class MassMsgCancelService
  14. {
  15. /**
  16. * 创建企业群发停止任务
  17. * */
  18. public static function setConfig($ruleId, $type, $sysGroupId, $adminId)
  19. {
  20. # 检查是否已创建了该任务,不允许重复创建
  21. $isExist = MassMsgCancel::where('type', $type)->where('rule_id', $ruleId)->whereIn('status', [1,2])->exists();
  22. if($isExist) return 2432;
  23. # 校验规则状态
  24. if($type == 1) { // 正常群发,mass_msg
  25. $ruleModel = MassMsg::query();
  26. $recordModel = MassMsgRecord::query();
  27. } elseif ($type == 2) { // 智能群发,period_mass_msg
  28. $ruleModel = PeriodMassMsg::query();
  29. $recordModel = PeriodMassMsgRecord::query();
  30. } elseif ($type == 3) { // 客户群群发,chat_group_mass_msg
  31. $ruleModel = ChatGroupMassMsg::query();
  32. $recordModel = ChatGroupMassMsgRecord::query();
  33. } elseif ($type == 4) { // 客户朋友圈,moment_task
  34. $ruleModel = MomentTask::query();
  35. $recordModel = MomentRecord::query();
  36. }
  37. # 查询规则是不是已创建群发任务
  38. $count = $recordModel->where('rule_id', $ruleId)->count();
  39. if(!$count) return 2431;
  40. $title = $ruleModel->where('id', $ruleId)->value('name');
  41. return MassMsgCancel::setConfig($ruleId, $type, $title, $sysGroupId, $adminId);
  42. }
  43. /**
  44. * 企业群发停止任务列表
  45. * */
  46. public static function taskList($sysGroupId, $type, $page, $pageSize)
  47. {
  48. list($list, $count) = MassMsgCancel::getTaskList($sysGroupId, $type, $page, $pageSize);
  49. if($list->isEmpty()) return [[], 0];
  50. # 获取创建成员信息
  51. $adminIds = $list->pluck('admin_id');
  52. $adminData = Users::select(['id','name'])->whereIn('id', $adminIds)->get();
  53. foreach ($list as $datum) {
  54. # 处理创建人信息
  55. $adminInfo = $adminData->where('id', $datum->admin_id)->first();
  56. $datum->creator = isset($adminInfo->name) ? $adminInfo->name : '';
  57. unset($datum->admin_id);
  58. }
  59. return [$list, $count];
  60. }
  61. }