OrderRefund.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <?php
  2. namespace addons\shopro\notification\order;
  3. use addons\shopro\notification\Notification;
  4. use addons\shopro\notification\traits\Notification as NotificationTrait;
  5. use app\admin\model\shopro\Refund;
  6. /**
  7. * 订单退款通知
  8. */
  9. class OrderRefund extends Notification
  10. {
  11. use NotificationTrait;
  12. // 队列延迟时间,必须继承 ShouldQueue 接口
  13. public $delay = 0;
  14. public $receiver_type = 'user'; // 接收人:user=用户
  15. // 消息类型 Notification::$notificationType
  16. public $notification_type = 'shop';
  17. // 发送类型
  18. public $event = 'order_refund';
  19. // 额外数据
  20. public $data = [];
  21. public $template = [
  22. 'MessageDefaultContent' => '您的订单已退款,订单号:{order_sn},退款金额:{refund_money},请注意查收',
  23. // 'WechatOfficialAccount' => [
  24. // 'temp_no' => 'OPENTM413279802',
  25. // 'fields' => [
  26. // // 'first' => '您的订单已退款,点击查看详情',
  27. // // 'keyword1' => 'order_sn', // 订单编号
  28. // // 'keyword2' => 'goods_title', // 商品名称
  29. // // 'keyword3' => 'refund_money', // 退款金额
  30. // // 'remark' => '您的订单已退款,点击查看详情',
  31. // [
  32. // "template_field" => "first",
  33. // "value" => '您的订单已退款,点击查看详情',
  34. // ],
  35. // [
  36. // "name" => "订单编号",
  37. // "field" => "order_sn",
  38. // "template_field" => "keyword1",
  39. // ],
  40. // [
  41. // "name" => "商品名称",
  42. // "field" => "goods_title",
  43. // "template_field" => "keyword2",
  44. // ],
  45. // [
  46. // "name" => "退款金额",
  47. // "field" => "refund_money",
  48. // "template_field" => "keyword3",
  49. // ],
  50. // [
  51. // "template_field" => "remark",
  52. // "value" => '您的订单已退款,点击查看详情',
  53. // ]
  54. // ],
  55. // ],
  56. 'WechatOfficialAccount' => [
  57. 'temp_no' => '45762',
  58. 'keywords' => ['订单编号', '商品名称', '退款金额'],
  59. 'fields' => [
  60. [
  61. "name" => "订单编号",
  62. "field" => "order_sn",
  63. "template_field" => "character_string10",
  64. ],
  65. [
  66. "name" => "商品名称",
  67. "field" => "goods_title",
  68. "template_field" => "thing8",
  69. ],
  70. [
  71. "name" => "退款金额",
  72. "field" => "refund_money",
  73. "template_field" => "amount2",
  74. ]
  75. ],
  76. ],
  77. 'WechatMiniProgram' => [
  78. 'category_id' => 670,
  79. 'tid' => '1451',
  80. 'kid' => [7,10,3], // 订单编号,商品名称,退款金额
  81. 'scene_desc' => '当订单发生退款时通知用户', // 申请模板场景描述
  82. 'fields' => [
  83. // 'character_string7' => 'order_sn', // 订单编号
  84. // 'thing10' => 'goods_title', // 商品名称
  85. // 'amount3' => 'refund_money', // 退款金额
  86. [
  87. "name" => "订单编号",
  88. "field" => "order_sn",
  89. "template_field" => "character_string7",
  90. ],
  91. [
  92. "name" => "商品名称",
  93. "field" => "goods_title",
  94. "template_field" => "thing10",
  95. ],
  96. [
  97. "name" => "退款金额",
  98. "field" => "refund_money",
  99. "template_field" => "amount3",
  100. ],
  101. ],
  102. ]
  103. ];
  104. // 返回的字段列表
  105. public $returnField = [
  106. 'name' => '订单退款成功通知',
  107. 'channels' => ['Sms', 'Email', 'WechatOfficialAccount', 'WechatMiniProgram'],
  108. 'fields' => [
  109. ['name' => '消息名称', 'field' => 'template'],
  110. ['name' => '订单ID', 'field' => 'order_id'],
  111. ['name' => '订单号', 'field' => 'order_sn'],
  112. ['name' => '订单金额', 'field' => 'order_amount'],
  113. ['name' => '用户昵称', 'field' => 'nickname'],
  114. ['name' => '用户手机', 'field' => 'mobile'],
  115. ['name' => '商品名称', 'field' => 'goods_title'],
  116. ['name' => '商品金额', 'field' => 'goods_amount'],
  117. ['name' => '退款金额', 'field' => 'refund_money'],
  118. ['name' => '退款类型', 'field' => 'refund_type'],
  119. ['name' => '退款时间', 'field' => 'refund_date']
  120. ]
  121. ];
  122. /**
  123. * 组合数据参数
  124. *
  125. * @param \think\Model $notifiable
  126. * @return array
  127. */
  128. protected function getData($notifiable)
  129. {
  130. $order = $this->data['order'];
  131. $items = $this->data['items'];
  132. $refund_method = $this->data['refund_method'];
  133. $refund_type = $this->data['refund_type'];
  134. $data['template'] = $this->returnField['name']; // 模板名称
  135. $data['order_id'] = $order['id'];
  136. $data['order_sn'] = $order['order_sn'];
  137. $data['order_amount'] = '¥' . $order['order_amount'];
  138. $data['nickname'] = $notifiable['nickname'];
  139. $data['mobile'] = $notifiable['mobile'];
  140. if ($refund_method == 'full_refund') {
  141. // 全额退款
  142. $refund_money = $order['pay_fee'];
  143. $goods_title = '订单全部商品';
  144. $goods_amount = $order['goods_amount'];
  145. } else {
  146. $item = $items[0]; // 只有一个商品
  147. $refund_money = $item['refund_fee'];
  148. $goods_title = $item['goods_title'];
  149. $goods_amount = ($item['goods_price'] * $item['goods_num']);
  150. }
  151. $refundTypeList = (new Refund)->refundTypeList();
  152. $data['goods_title'] = $goods_title;
  153. $data['goods_amount'] = '¥' . $goods_amount;
  154. $data['refund_money'] = '¥' . $refund_money;
  155. $data['refund_type'] = $refundTypeList[$refund_type] ?? '';
  156. $data['refund_date'] = $order['updatetime'];
  157. // 统一跳转地址
  158. $data['jump_url'] = "/pages/order/detail?id=" . $order['id'];
  159. return $data;
  160. }
  161. }