RewardMessage.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 RewardMessage extends Message
  8. {
  9. protected $money;
  10. protected $template_id;
  11. protected $mall_id;
  12. const sms_key = 'bonus';
  13. public function __construct($mall_id, $money)
  14. {
  15. $this->money = $money;
  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'])) 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->money);
  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. 'money' => $this->money,
  41. ];
  42. }
  43. }