123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?php
- namespace App\Service;
- use App\Models\ChatGroupMassMsg;
- use App\Models\ChatGroupMassMsgRecord;
- use App\Models\MassMsg;
- use App\Models\MassMsgCancel;
- use App\Models\MassMsgRecord;
- use App\Models\MomentRecord;
- use App\Models\MomentTask;
- use App\Models\PeriodMassMsg\PeriodMassMsg;
- use App\Models\PeriodMassMsg\PeriodMassMsgRecord;
- use App\Models\System\Users;
- class MassMsgCancelService
- {
- /**
- * 创建企业群发停止任务
- * */
- public static function setConfig($ruleId, $type, $sysGroupId, $adminId)
- {
- # 检查是否已创建了该任务,不允许重复创建
- $isExist = MassMsgCancel::where('type', $type)->where('rule_id', $ruleId)->whereIn('status', [1,2])->exists();
- if($isExist) return 2432;
- # 校验规则状态
- if($type == 1) { // 正常群发,mass_msg
- $ruleModel = MassMsg::query();
- $recordModel = MassMsgRecord::query();
- } elseif ($type == 2) { // 智能群发,period_mass_msg
- $ruleModel = PeriodMassMsg::query();
- $recordModel = PeriodMassMsgRecord::query();
- } elseif ($type == 3) { // 客户群群发,chat_group_mass_msg
- $ruleModel = ChatGroupMassMsg::query();
- $recordModel = ChatGroupMassMsgRecord::query();
- } elseif ($type == 4) { // 客户朋友圈,moment_task
- $ruleModel = MomentTask::query();
- $recordModel = MomentRecord::query();
- }
- # 查询规则是不是已创建群发任务
- $count = $recordModel->where('rule_id', $ruleId)->count();
- if(!$count) return 2431;
- $title = $ruleModel->where('id', $ruleId)->value('name');
- return MassMsgCancel::setConfig($ruleId, $type, $title, $sysGroupId, $adminId);
- }
- /**
- * 企业群发停止任务列表
- * */
- public static function taskList($sysGroupId, $type, $page, $pageSize)
- {
- list($list, $count) = MassMsgCancel::getTaskList($sysGroupId, $type, $page, $pageSize);
- if($list->isEmpty()) return [[], 0];
- # 获取创建成员信息
- $adminIds = $list->pluck('admin_id');
- $adminData = Users::select(['id','name'])->whereIn('id', $adminIds)->get();
- foreach ($list as $datum) {
- # 处理创建人信息
- $adminInfo = $adminData->where('id', $datum->admin_id)->first();
- $datum->creator = isset($adminInfo->name) ? $adminInfo->name : '';
- unset($datum->admin_id);
- }
- return [$list, $count];
- }
- }
|