EarlyWarningMessage.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace addons\CloudStock\common\sms;
  3. use addons\CloudStock\common\models\CloudStockSms;
  4. use common\enums\StatusEnum;
  5. use Overtrue\EasySms\Contracts\GatewayInterface;
  6. use Overtrue\EasySms\Message;
  7. class EarlyWarningMessage extends Message
  8. {
  9. protected $goods_name;
  10. protected $template_id;
  11. protected $mall_id;
  12. const sms_key = 'early_warning';
  13. public function __construct($mall_id, $goods_name)
  14. {
  15. $this->goods_name = $goods_name;
  16. $this->mall_id = $mall_id;
  17. parent::__construct();
  18. $this->getTempId();
  19. }
  20. public function getTempId()
  21. {
  22. $detail = CloudStockSms::findOne(['mall_id' => $this->mall_id, 'sms_key' => self::sms_key, 'status' => StatusEnum::ENABLED]);
  23. if (!isset($detail['temp_id'])) throw new \Exception('bonus短信通知,temp_id为空');
  24. $this->template_id = $detail['temp_id'];
  25. }
  26. // 定义直接使用内容发送平台的内容
  27. public function getContent(GatewayInterface $gateway = null)
  28. {
  29. return sprintf("您的%s库存不足,请及时进行补货", $this->goods_name);
  30. }
  31. // 定义使用模板发送方式平台所需要的模板 ID
  32. public function getTemplate(GatewayInterface $gateway = null)
  33. {
  34. return $this->template_id;
  35. }
  36. // 模板参数
  37. public function getData(GatewayInterface $gateway = null)
  38. {
  39. return [
  40. 'goods_name' => $this->goods_name,
  41. 'project' => $this->template_id,
  42. ];
  43. }
  44. }