55 lines
1015 B
PHP
55 lines
1015 B
PHP
<?php
|
|
namespace app\components;
|
|
use Yii;
|
|
use yii\base\BaseObject;
|
|
class SendLinkJob extends BaseObject implements \yii\queue\JobInterface {
|
|
|
|
public $link;
|
|
public $startAt;
|
|
public $times;
|
|
|
|
public function execute($queue)
|
|
{
|
|
if (! $this->isLinkValid()) {
|
|
return false;
|
|
}
|
|
if (4 == $this->times) {
|
|
return $this->sendToService();
|
|
}
|
|
|
|
$this->sendLink();
|
|
Yii::$app->queue->delay($this->getDelay())->push(new SendLinkJob([
|
|
'link' => $this->link,
|
|
'startAt' => $this->startAt,
|
|
'times' => ++$this->times,
|
|
]));
|
|
}
|
|
|
|
public function isLinkValid()
|
|
{
|
|
// ...
|
|
return true;
|
|
}
|
|
|
|
public function sendLink()
|
|
{
|
|
// 发链接到客服端
|
|
}
|
|
|
|
public function sendToService()
|
|
{
|
|
// 发到客服
|
|
}
|
|
|
|
protected function getDelay()
|
|
{
|
|
switch ($this->times) {
|
|
case 1 :
|
|
return 180; /* 三分钟 */
|
|
case 2 :
|
|
return 120; /* 两分钟 */
|
|
case 3 :
|
|
return 120; // 两分钟
|
|
}
|
|
}
|
|
} |