TimeLimitFillMessage.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 TimeLimitFillMessage extends Message
  8. {
  9. protected $duration; //小时
  10. protected $template_id;
  11. protected $goods_name;
  12. protected $goods_id;
  13. protected $num;
  14. protected $mall_id;
  15. const sms_key = 'fill';
  16. public function __construct($mall_id, $duration, $goods_id, $num)
  17. {
  18. $this->duration = $duration;
  19. $this->goods_name = '';
  20. $this->goods_id = $goods_id;
  21. $this->num = $num;
  22. $this->mall_id = $mall_id;
  23. parent::__construct();
  24. $this->getTempId();
  25. }
  26. public function getTempId()
  27. {
  28. $detail = CloudStockSms::findOne(['mall_id' => $this->mall_id, 'sms_key' => self::sms_key, 'status' => StatusEnum::ENABLED]);
  29. if (!isset($detail['temp_id'])) {
  30. throw new \Exception('fill短信通知,temp_id为空');
  31. }
  32. $this->template_id = $detail['temp_id'];
  33. }
  34. // 定义直接使用内容发送平台的内容
  35. public function getContent(GatewayInterface $gateway = null)
  36. {
  37. //您有一条新的补货提醒,补货商品名:${goods_name},补货数量:${num},补货时长(小时):${duration},请您在补货时长内及时补货。
  38. //您有一条新的补货提醒,补货商品编号:${goods_id},补货数量:${num},请您在${duration}小时内进行补货。
  39. // return sprintf("您有一条新的补货提醒,补货商品名:%s,补货数量:%s,补货时长(小时):%s,请您在补货时长内及时补货。", $this->goods_name,$this->num,$this->duration);
  40. return sprintf("您有一条新的补货提醒,补货商品编号:%s,补货数量:%s,补货时长(小时):%s,请您在补货时长内及时补货。", $this->goods_id,$this->num,$this->duration);
  41. }
  42. // 定义使用模板发送方式平台所需要的模板 ID
  43. public function getTemplate(GatewayInterface $gateway = null)
  44. {
  45. return $this->template_id;
  46. }
  47. // 模板参数
  48. public function getData(GatewayInterface $gateway = null)
  49. {
  50. return [
  51. 'duration' => $this->duration,
  52. 'goods_id' => $this->goods_id,
  53. 'goods_name' => $this->goods_name,
  54. 'num' => $this->num,
  55. 'project' => $this->template_id,
  56. ];
  57. }
  58. }