<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace Module\Edm\Schedule; use Carbon\Carbon; use ModStart\Core\Dao\ModelUtil; use ModStart\Core\Util\RandomUtil; use ModStart\Core\Util\TagUtil; use ModStart\Core\Util\TimeUtil; use Module\Edm\Job\EdmMailSendJob; use Module\Edm\Type\EdmTaskItemStatus; use Module\Edm\Type\EdmTaskItemSubscribeStatus; use Module\Edm\Type\EdmTaskItemVisitStatus; use Module\Edm\Type\EdmTaskStatus; use Module\Vendor\Provider\Schedule\AbstractScheduleBiz; class EdmTaskSendScheduler extends AbstractScheduleBiz { public function cron() { return $this->cronEveryMinute(); } public function title() { return 'EDM邮件发送'; } public function run() { goto f_sCb; MDmZG: foreach ($XrtJH as $gHpj9) { goto zJYqq; YJ2Mk: $FWGIk = array_map(function ($MNZ1i) { return $MNZ1i['id']; }, $ZaBc3); goto ecsr6; Ljjmt: foreach ($FWGIk as $FhIQB) { EdmMailSendJob::create($FhIQB); } goto tiL8y; ecsr6: ModelUtil::model('edm_task_item')->whereIn('id', $FWGIk)->update(array('status' => EdmTaskItemStatus::QUEUE, 'queueTime' => Carbon::now())); goto Ljjmt; zJYqq: $ZaBc3 = ModelUtil::model('edm_task_item')->where(array('taskId' => $gHpj9['id'], 'status' => EdmTaskItemStatus::CREATED))->limit($gHpj9['_queueCount'])->get(array('id'))->toArray(); goto EuWj3; EuWj3: if (empty($ZaBc3)) { continue; } goto YJ2Mk; tiL8y: } goto C1DP2; e01aR: foreach ($Oe7_O as $gHpj9) { goto YKN0Y; upjqy: $sQAE5 = TagUtil::string2Array($gHpj9['filterTags']); goto s_KaV; s_KaV: $r0XyP = ModelUtil::model('edm_email'); goto Yya38; Yya38: foreach ($sQAE5 as $z_f8F) { $r0XyP = $r0XyP->orWhere('tags', 'like', '%:' . $z_f8F . ':%'); } goto UGeh4; UAAYu: foreach ($GiaLg as $ber3G) { goto AT5y0; wELno: ModelUtil::insert('edm_task_item', array_merge($l970E, array('status' => EdmTaskItemStatus::CREATED, 'alias' => RandomUtil::string(10), 'visitStatus' => EdmTaskItemVisitStatus::NOT_VISIT, 'subscribeStatus' => EdmTaskItemSubscribeStatus::UNKNOWN))); goto JyJez; AT5y0: $l970E = array('taskId' => $gHpj9['id'], 'email' => $ber3G->email); goto SCdwj; SCdwj: if (ModelUtil::exists('edm_task_item', $l970E)) { continue; } goto wELno; JyJez: } goto RfylC; RfylC: ModelUtil::update('edm_task', $gHpj9['id'], array('itemProcessed' => true)); goto pyrdl; UGeh4: $GiaLg = $r0XyP->get(array('id', 'email')); goto Jnx3J; Jnx3J: ModelUtil::delete('edm_task_item', array('taskId' => $gHpj9['id'], 'status' => EdmTaskItemStatus::CREATED)); goto UAAYu; YKN0Y: if ($gHpj9['itemProcessed']) { continue; } goto upjqy; pyrdl: } goto oOhn1; f_sCb: $Oe7_O = ModelUtil::all('edm_task', array('status' => EdmTaskStatus::RUNNING)); goto e01aR; oOhn1: $XrtJH = array_filter(array_map(function ($gHpj9) { $gHpj9['_queueCount'] = 10; if ($gHpj9['limitEnable'] && $gHpj9['limitHourly'] > 0) { $KtGQd = ModelUtil::model('edm_task_item')->whereRaw('( queueTime IS NOT NULL AND queueTime > \'' . date(TimeUtil::FORMAT_DATETIME, time() - 3600) . '\' )')->where(array('taskId' => $gHpj9['id']))->whereIn('status', array(EdmTaskItemStatus::QUEUE, EdmTaskItemStatus::SUCCESS, EdmTaskItemStatus::SENDING, EdmTaskItemStatus::FAIL))->count(); $gHpj9['_queueCount'] = max(0, $gHpj9['limitHourly'] - $KtGQd); } if (!$gHpj9['_queueCount']) { return null; } return $gHpj9; }, $Oe7_O)); goto MDmZG; C1DP2: } }