| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <?php
- namespace addons\CloudStock\common\sms;
- use addons\CloudStock\common\models\CloudStockSms;
- use common\enums\StatusEnum;
- use Overtrue\EasySms\Contracts\GatewayInterface;
- use Overtrue\EasySms\Message;
- class EarlyWarningMessage extends Message
- {
- protected $goods_name;
- protected $template_id;
- protected $mall_id;
- const sms_key = 'early_warning';
- public function __construct($mall_id, $goods_name)
- {
- $this->goods_name = $goods_name;
- $this->mall_id = $mall_id;
- parent::__construct();
- $this->getTempId();
- }
- public function getTempId()
- {
- $detail = CloudStockSms::findOne(['mall_id' => $this->mall_id, 'sms_key' => self::sms_key, 'status' => StatusEnum::ENABLED]);
- if (!isset($detail['temp_id'])) throw new \Exception('bonus短信通知,temp_id为空');
- $this->template_id = $detail['temp_id'];
- }
- // 定义直接使用内容发送平台的内容
- public function getContent(GatewayInterface $gateway = null)
- {
- return sprintf("您的%s库存不足,请及时进行补货", $this->goods_name);
- }
- // 定义使用模板发送方式平台所需要的模板 ID
- public function getTemplate(GatewayInterface $gateway = null)
- {
- return $this->template_id;
- }
- // 模板参数
- public function getData(GatewayInterface $gateway = null)
- {
- return [
- 'goods_name' => $this->goods_name,
- 'project' => $this->template_id,
- ];
- }
- }
|