TimeLimitFillMessage.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace addons\CloudStockTwo\common\sms;
  3. use addons\CloudStockTwo\common\models\CloudStockTwoSms;
  4. use common\enums\StatusEnum;
  5. use Overtrue\EasySms\Contracts\GatewayInterface;
  6. use Overtrue\EasySms\Message;
  7. class TimeLimitFillMessage extends Message
  8. {
  9. protected $duration; //小时
  10. protected $template_id;
  11. protected $goods_name;
  12. protected $num;
  13. protected $mall_id;
  14. const sms_key = 'fill';
  15. public function __construct($mall_id, $duration, $goods_name, $num)
  16. {
  17. $this->duration = $duration;
  18. $this->goods_name = $goods_name;
  19. $this->num = $num;
  20. $this->mall_id = $mall_id;
  21. parent::__construct();
  22. $this->getTempId();
  23. }
  24. public function getTempId()
  25. {
  26. $detail = CloudStockTwoSms::findOne(['mall_id' => $this->mall_id, 'sms_key' => self::sms_key, 'status' => StatusEnum::ENABLED]);
  27. if (!isset($detail['temp_id'])) {
  28. throw new \Exception('fill短信通知,temp_id为空');
  29. }
  30. $this->template_id = $detail['temp_id'];
  31. }
  32. // 定义直接使用内容发送平台的内容
  33. public function getContent(GatewayInterface $gateway = null)
  34. {
  35. //您有一条新的补货提醒,补货商品名:${goods_name},补货数量:${num},补货时长(小时):${duration},请您在补货时长内及时补货。
  36. return sprintf("您有一条新的补货提醒,补货商品名:%s,补货数量:%s,补货时长(小时):%s,请您在补货时长内及时补货。", $this->goods_name,$this->num,$this->duration);
  37. }
  38. // 定义使用模板发送方式平台所需要的模板 ID
  39. public function getTemplate(GatewayInterface $gateway = null)
  40. {
  41. return $this->template_id;
  42. }
  43. // 模板参数
  44. public function getData(GatewayInterface $gateway = null)
  45. {
  46. return [
  47. 'duration' => $this->duration,
  48. 'goods_name' => $this->goods_name,
  49. 'num' => $this->num
  50. ];
  51. }
  52. }