最新服务器上的版本,以后用这个
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
/**
 * 卡卷提醒
 */
 
namespace app\jobs;
 
use app\forms\common\template\order_pay_template\AccountChangeInfo;
use app\forms\common\template\TemplateList;
use app\models\User;
use app\models\UserCard;
use yii\base\Component;
use yii\queue\JobInterface;
 
class UserCardCreatedJob extends BaseJob implements JobInterface
{
    public $id;
 
    public $mall;
    public $user_id;
 
    public function execute($queue)
    {
        try {
            $this->setRequest();
            $model = UserCard::find()->with('card')->where([
                'mall_id' => $this->mall->id,
                'id' => $this->id,
                'is_use' => 0,
                'is_delete' => 0,
            ])->andWhere(['>', 'end_time', mysql_timestamp()])->one();
 
            if (!$model) {
                throw new \Exception('卡卷已过期或已使用或已删除');
            }
            try {
                TemplateList::getInstance()->getTemplateClass(AccountChangeInfo::TPL_NAME)->send([
                    'page' => 'pages/card/index/index',
                    'user' => User::findOne($this->user_id),
                    'remark' => '[' . $model->name . ']',
                    'desc' => '卡卷即将过期,请尽快使用'
                ]);
            } catch (\Exception $exception) {
                \Yii::warning('卡卷过期提醒发送失败 => ' . $exception->getMessage());
            }
            return $model;
        } catch (\Exception $e) {
            \Yii::error($e->getMessage());
        }
    }
}