OrderApplyRefund.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. namespace addons\shopro\notification\order;
  3. use addons\shopro\notification\Notification;
  4. use addons\shopro\notification\traits\Notification as NotificationTrait;
  5. /**
  6. * 订单申请全额退款通知
  7. */
  8. class OrderApplyRefund extends Notification
  9. {
  10. use NotificationTrait;
  11. // 队列延迟时间,必须继承 ShouldQueue 接口
  12. public $delay = 0;
  13. public $receiver_type = 'admin'; // 接收人:admin=管理员
  14. // 消息类型 Notification::$notificationType
  15. public $notification_type = 'shop';
  16. // 发送类型
  17. public $event = 'order_apply_refund';
  18. // 额外数据
  19. public $data = [];
  20. public $template = [
  21. 'MessageDefaultContent' => '您有订单申请全额退款,下单用户:{nickname},订单号:{order_sn},支付金额:{pay_fee},{refund_status}',
  22. // 'WechatOfficialAccount' => [
  23. // 'temp_no' => 'TM00004',
  24. // 'fields' => [
  25. // // 'first' => '您有订单申请全额退款,请及时处理',
  26. // // 'reason' => 'reason', // 退款原因
  27. // // 'refund' => 'pay_fee', // 退款金额
  28. // // 'remark' => '您有订单申请全额退款,请及时处理',
  29. // [
  30. // "template_field" => "first",
  31. // "value" => '您有订单申请全额退款,请及时处理',
  32. // ],
  33. // [
  34. // "name" => "退款原因",
  35. // "field" => "reason",
  36. // "template_field" => "reason",
  37. // ],
  38. // [
  39. // "name" => "退款金额",
  40. // "field" => "pay_fee",
  41. // "template_field" => "refund",
  42. // ],
  43. // [
  44. // "template_field" => "remark",
  45. // "value" => '您有订单申请全额退款,请及时处理',
  46. // ]
  47. // ],
  48. // ],
  49. 'WechatOfficialAccount' => [
  50. 'temp_no' => '46044',
  51. 'keywords' => ['订单编号', '退款金额', '申请时间'],
  52. 'fields' => [
  53. [
  54. "name" => "订单编号",
  55. "field" => "order_sn",
  56. "template_field" => "character_string12",
  57. ],
  58. [
  59. "name" => "退款金额",
  60. "field" => "pay_fee",
  61. "template_field" => "amount4",
  62. ],
  63. [
  64. "name" => "申请时间",
  65. "field" => "apply_date",
  66. "template_field" => "time3",
  67. ]
  68. ],
  69. ],
  70. 'WechatMiniProgram' => [
  71. 'category_id' => 670,
  72. 'tid' => '1468',
  73. 'kid' => [9,10], // 退款金额, 退款原因
  74. 'scene_desc' => '当有用户申请退款时,通知管理员', // 申请模板场景描述
  75. 'fields' => [
  76. // 'amount9' => 'pay_fee', // 退款金额
  77. // 'thing10' => 'reason', // 退款原因
  78. [
  79. "name" => "退款金额",
  80. "field" => "pay_fee",
  81. "template_field" => "amount9",
  82. ],
  83. [
  84. "name" => "退款原因",
  85. "field" => "reason",
  86. "template_field" => "thing10",
  87. ]
  88. ],
  89. ]
  90. ];
  91. // 返回的字段列表
  92. public $returnField = [
  93. 'name' => '订单退款申请',
  94. 'channels' => ['Sms', 'Email', 'WechatOfficialAccount'],
  95. 'fields' => [
  96. ['name' => '消息名称', 'field' => 'template'],
  97. ['name' => '订单ID', 'field' => 'order_id'],
  98. ['name' => '订单号', 'field' => 'order_sn'],
  99. ['name' => '下单用户', 'field' => 'nickname'],
  100. ['name' => '用户手机', 'field' => 'mobile'],
  101. ['name' => '退款金额', 'field' => 'pay_fee'],
  102. ['name' => '下单时间', 'field' => 'create_date'],
  103. ['name' => '支付时间', 'field' => 'paid_date'],
  104. ['name' => '退款原因', 'field' => 'reason'],
  105. ['name' => '退款状态', 'field' => 'refund_status'],
  106. ['name' => '申请时间', 'field' => 'apply_date']
  107. ]
  108. ];
  109. /**
  110. * 组合数据参数
  111. *
  112. * @param \think\Model $notifiable
  113. * @return array
  114. */
  115. protected function getData($notifiable)
  116. {
  117. $order = $this->data['order'];
  118. $ext = $order['ext'] ?? [];
  119. $user = $this->data['user'];
  120. $auto_refund = $this->data['auto_refund'];
  121. $data['template'] = $this->returnField['name']; // 模板名称
  122. $data['order_id'] = $order['id'];
  123. $data['order_sn'] = $order['order_sn'];
  124. $data['nickname'] = $user['nickname'] ?? '';
  125. $data['mobile'] = $user['mobile'] ?? '';
  126. $data['pay_fee'] = '¥' . $order['pay_fee'];
  127. $data['create_date'] = $order['createtime'];
  128. $data['paid_date'] = $order['paid_time'];
  129. $data['reason'] = '订单申请全额退款' . ($auto_refund ? ',已自动退款,请及时查看' : ',请及时处理');
  130. $data['refund_status'] = $auto_refund ? '已自动退款,请及时查看' : '请及时处理';
  131. $data['apply_date'] = $ext['apply_refund_date'] ?? date('Y-m-d H:i:s');
  132. // 统一跳转地址
  133. $data['jump_url'] = "";
  134. return $data;
  135. }
  136. }