commit | author | age
|
2207d6
|
1 |
<?php |
W |
2 |
/** |
|
3 |
* Created by PhpStorm |
|
4 |
* User: 风哀伤 |
|
5 |
* Date: 2021/1/20 |
|
6 |
* Time: 11:40 上午 |
|
7 |
* @copyright: ©2020 浙江禾匠信息科技 |
|
8 |
* @link: http://www.zjhejiang.com |
|
9 |
*/ |
|
10 |
|
|
11 |
namespace app\jobs; |
|
12 |
|
|
13 |
use app\models\Goods; |
|
14 |
use app\models\Mall; |
|
15 |
use yii\queue\JobInterface; |
|
16 |
|
|
17 |
class GoodsDownJob extends BaseJob implements JobInterface |
|
18 |
{ |
|
19 |
/** |
|
20 |
* @var Goods |
|
21 |
*/ |
|
22 |
public $goods; |
|
23 |
|
|
24 |
/** |
|
25 |
* @var Mall $mall |
|
26 |
*/ |
|
27 |
public $mall; |
|
28 |
|
|
29 |
public $sell_end_time; |
|
30 |
|
|
31 |
/** |
|
32 |
* @param \yii\queue\Queue $queue |
|
33 |
* @return mixed|void |
|
34 |
* 商品销售时间结束自动下架 |
|
35 |
*/ |
|
36 |
public function execute($queue) |
|
37 |
{ |
|
38 |
try { |
|
39 |
$this->setRequest(); |
|
40 |
$mall = Mall::findOne($this->mall->id); |
|
41 |
\Yii::$app->setMall($mall); |
|
42 |
$goods = Goods::findOne($this->goods->id); |
|
43 |
if (strtotime($goods->sell_end_time) !== strtotime($this->sell_end_time)) { |
|
44 |
throw new \Exception('商品销售时间已被更改'); |
|
45 |
} |
|
46 |
$goods->status = 0; |
|
47 |
$goods->save(); |
|
48 |
} catch (\Exception $exception) { |
|
49 |
\Yii::warning('--商品自动下架' . $this->goods->id . '--'); |
|
50 |
\Yii::warning($exception); |
|
51 |
} |
|
52 |
} |
|
53 |
} |