ShopExpireMessage.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace addons\Store\common\sms;
  3. use addons\Store\common\enums\StoreEnum;
  4. use Overtrue\EasySms\Contracts\GatewayInterface;
  5. use Overtrue\EasySms\Message;
  6. class ShopExpireMessage extends Message
  7. {
  8. protected $day;
  9. protected $template_id;
  10. protected $store_name;
  11. protected $mall_id;
  12. public function __construct($mall_id, $day, $store_name)
  13. {
  14. $this->day = $day;
  15. $this->store_name = $store_name;
  16. $this->mall_id = $mall_id;
  17. parent::__construct();
  18. $this->getTempId();
  19. }
  20. public function getTempId()
  21. {
  22. $sms_setting = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'sms_setting');
  23. if (empty($sms_setting['is_alert_expire'])) throw new \Exception('o2o门店到期提醒未开启');
  24. if (empty($sms_setting['expire_template_id'])) throw new \Exception('o2o门店到期提醒,模板ID为空');
  25. $this->template_id = $sms_setting['expire_template_id'];
  26. }
  27. // 定义直接使用内容发送平台的内容
  28. public function getContent(GatewayInterface $gateway = null)
  29. {
  30. return sprintf("您的门店还有%s天到期,门店名:%s,请及时处理", $this->day, $this->store_name);
  31. }
  32. // 定义使用模板发送方式平台所需要的模板 ID
  33. public function getTemplate(GatewayInterface $gateway = null)
  34. {
  35. return $this->template_id;
  36. }
  37. // 模板参数
  38. public function getData(GatewayInterface $gateway = null)
  39. {
  40. return [
  41. 'day' => $this->day,
  42. 'store_name' => $this->store_name,
  43. 'project' => $this->template_id,
  44. ];
  45. }
  46. }