| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <?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 TimeLimitFillMessage extends Message
- {
- protected $duration; //小时
- protected $template_id;
- protected $goods_name;
- protected $goods_id;
- protected $num;
- protected $mall_id;
- const sms_key = 'fill';
- public function __construct($mall_id, $duration, $goods_id, $num)
- {
- $this->duration = $duration;
- $this->goods_name = '';
- $this->goods_id = $goods_id;
- $this->num = $num;
- $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('fill短信通知,temp_id为空');
- }
- $this->template_id = $detail['temp_id'];
- }
- // 定义直接使用内容发送平台的内容
- public function getContent(GatewayInterface $gateway = null)
- {
- //您有一条新的补货提醒,补货商品名:${goods_name},补货数量:${num},补货时长(小时):${duration},请您在补货时长内及时补货。
- //您有一条新的补货提醒,补货商品编号:${goods_id},补货数量:${num},请您在${duration}小时内进行补货。
- // return sprintf("您有一条新的补货提醒,补货商品名:%s,补货数量:%s,补货时长(小时):%s,请您在补货时长内及时补货。", $this->goods_name,$this->num,$this->duration);
- return sprintf("您有一条新的补货提醒,补货商品编号:%s,补货数量:%s,补货时长(小时):%s,请您在补货时长内及时补货。", $this->goods_id,$this->num,$this->duration);
- }
- // 定义使用模板发送方式平台所需要的模板 ID
- public function getTemplate(GatewayInterface $gateway = null)
- {
- return $this->template_id;
- }
- // 模板参数
- public function getData(GatewayInterface $gateway = null)
- {
- return [
- 'duration' => $this->duration,
- 'goods_id' => $this->goods_id,
- 'goods_name' => $this->goods_name,
- 'num' => $this->num,
- 'project' => $this->template_id,
- ];
- }
- }
|