Beispiel #1
0
 public static function send($identify, array $options = [], array $use = [])
 {
     $noticeId = static::getSendNoticeId($identify);
     if (!$noticeId || !($types = NoticeType::getTypesByNoticeId($noticeId))) {
         return;
         // 通知ID不存在/已被禁用/已关闭全部通知方式
     }
     $auth = auth();
     if ($auth->check()) {
         $triggerUserId = $auth->user()->getAuthIdentifier();
     } else {
         $triggerUserId = 0;
     }
     $triggerIp = request()->ip();
     $triggerToken = session()->getId();
     foreach ($types as $type) {
         if (!static::hasType($type) || $use && !in_array($type, $use)) {
             continue;
         }
         $noticeRecord = NoticeRecord::create(['notice_id' => $noticeId, 'type' => $type, 'vars' => $vars, 'trigger_user_id' => $triggerUserId, 'trigger_ip' => $triggerIp, 'trigger_token' => $triggerToken, 'created_at' => time()]);
         $class = __NAMESPACE__ . '\\Notice' . ucfirst($type) . 'Record';
         $options['notice_record_id'] = $noticeRecord->getKey();
         $result = $class::createNotice($options, true);
         if ($result) {
             foreach ($result as $block) {
                 $class = 'App\\Jobs\\Notice\\' . ucfirst($type);
                 $job = new $class($noticeRecord, $block);
                 $job->onQueue('notices');
                 return app(Dispatcher::class)->dispatch($job);
             }
         }
     }
 }
Beispiel #2
0
 public function createTypeNoticeRecord(NoticeRecord $noticeRecord, \Closure $callback = null)
 {
     $typeClass = NoticeRecord::getTypeRecordModelClass($noticeRecord->type);
     $options = $this->options;
     $options['notice_record_id'] = $noticeRecord->id;
     $results = $typeClass::createNoticeRecord($options);
     if (!$results) {
         return;
     }
     $results = array_chunk($results, 10, true);
     foreach ($results as $chunk) {
         $callback && $callback($noticeRecord, $chunk);
     }
 }