LevelUpgradeMessage.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 LevelUpgradeMessage extends Message
  8. {
  9. protected $level_name;
  10. protected $template_id;
  11. protected $mall_id;
  12. const sms_key = 'upgrade';
  13. public function __construct($mall_id, $level_name)
  14. {
  15. $this->level_name = $level_name;
  16. $this->mall_id = $mall_id;
  17. parent::__construct();
  18. $this->getTempId();
  19. }
  20. public function getTempId()
  21. {
  22. $detail = CloudStockTwoSms::findOne(['mall_id' => $this->mall_id, 'sms_key' => self::sms_key, 'status' => StatusEnum::ENABLED]);
  23. if (!isset($detail['temp_id'])) {
  24. throw new \Exception('fill短信通知,temp_id为空');
  25. }
  26. $this->template_id = $detail['temp_id'];
  27. }
  28. // 定义直接使用内容发送平台的内容
  29. public function getContent(GatewayInterface $gateway = null)
  30. {
  31. return sprintf("恭喜你,你的云库存代理商等级升到了%s", $this->level_name);
  32. }
  33. // 定义使用模板发送方式平台所需要的模板 ID
  34. public function getTemplate(GatewayInterface $gateway = null)
  35. {
  36. return $this->template_id;
  37. }
  38. // 模板参数
  39. public function getData(GatewayInterface $gateway = null)
  40. {
  41. return [
  42. 'level_name' => $this->level_name,
  43. ];
  44. }
  45. }