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