PayRemindMessage.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace addons\Store\common\sms;
  3. use addons\Store\common\enums\StoreEnum;
  4. use Overtrue\EasySms\Contracts\GatewayInterface;
  5. use Overtrue\EasySms\Message;
  6. class PayRemindMessage extends Message
  7. {
  8. protected $order_no;
  9. protected $template_id;
  10. protected $shipping_type;
  11. protected $mall_id;
  12. public function __construct($mall_id, $order_no, $shipping_type)
  13. {
  14. $this->order_no = $order_no;
  15. $this->shipping_type = $shipping_type;
  16. $this->mall_id = $mall_id;
  17. parent::__construct();
  18. $this->getTempId();
  19. }
  20. public function getTempId()
  21. {
  22. $sms_setting = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'sms_setting');
  23. if (empty($sms_setting['is_pay_remind'])) throw new \Exception('o2o门店订单支付提醒未开启');
  24. if (empty($sms_setting['pay_template_id'])) throw new \Exception('o2o门店订单支付提醒,模板ID为空');
  25. $this->template_id = $sms_setting['pay_template_id'];
  26. }
  27. // 定义直接使用内容发送平台的内容
  28. public function getContent(GatewayInterface $gateway = null)
  29. {
  30. return sprintf("您有一笔新的订单,订单号:%s,配送方式为%s,请及时处理", $this->order_no, $this->shipping_type);
  31. }
  32. // 定义使用模板发送方式平台所需要的模板 ID
  33. public function getTemplate(GatewayInterface $gateway = null)
  34. {
  35. return $this->template_id;
  36. }
  37. // 模板参数
  38. public function getData(GatewayInterface $gateway = null)
  39. {
  40. return [
  41. 'order_no' => $this->order_no,
  42. 'shipping_type' => $this->shipping_type,
  43. 'project' => $this->template_id,
  44. ];
  45. }
  46. }