OrderNew.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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\order\Address;
  6. /**
  7. * 新订单通知
  8. */
  9. class OrderNew extends Notification
  10. {
  11. use NotificationTrait;
  12. // 队列延迟时间,必须继承 ShouldQueue 接口
  13. public $delay = 0;
  14. public $receiver_type = 'admin'; // 接收人:user=用户
  15. // 消息类型 Notification::$notificationType
  16. public $notification_type = 'shop';
  17. // 发送类型
  18. public $event = 'order_new';
  19. // 额外数据
  20. public $data = [];
  21. public $template = [
  22. 'MessageDefaultContent' => '您有新的待处理订单,下单用户:{nickname},订单号:{order_sn},订单金额:{order_amount},请及时处理',
  23. // 'WechatOfficialAccount' => [
  24. // 'temp_no' => 'OPENTM417875155',
  25. // 'fields' => [
  26. // // 'first' => '您有新的订单待处理',
  27. // // 'keyword1' => 'order_sn', // 订单号
  28. // // 'keyword2' => 'pay_fee', // 实付金额
  29. // // 'keyword3' => 'create_date', // 下单时间
  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" => "pay_fee",
  43. // "template_field" => "keyword2",
  44. // ],
  45. // [
  46. // "name" => "下单时间",
  47. // "field" => "create_date",
  48. // "template_field" => "keyword3",
  49. // ],
  50. // [
  51. // "template_field" => "remark",
  52. // "value" => '您有新的订单待处理,请及时处理',
  53. // ]
  54. // ],
  55. // ],
  56. 'WechatOfficialAccount' => [
  57. 'temp_no' => '46624',
  58. 'keywords' => ['订单号', '订单金额', '下单时间'],
  59. 'fields' => [
  60. [
  61. "name" => "订单号",
  62. "field" => "order_sn",
  63. "template_field" => "character_string1",
  64. ],
  65. [
  66. "name" => "订单金额",
  67. "field" => "order_amount",
  68. "template_field" => "amount3",
  69. ],
  70. [
  71. "name" => "下单时间",
  72. "field" => "create_date",
  73. "template_field" => "time9",
  74. ]
  75. ],
  76. ],
  77. 'WechatMiniProgram' => [
  78. 'category_id' => 670,
  79. 'tid' => '1476',
  80. 'kid' => [4,12,6], // 订单编号,实付金额,订单时间
  81. 'scene_desc' => '当有新订单时通知管理员', // 申请模板场景描述
  82. 'fields' => [
  83. // 'character_string4' => 'order_sn', // 订单编号
  84. // 'amount12' => 'pay_fee', // 实付金额
  85. // 'date6' => 'create_date', // 订单时间
  86. [
  87. "name" => "订单编号",
  88. "field" => "order_sn",
  89. "template_field" => "character_string4",
  90. ],
  91. [
  92. "name" => "实付金额",
  93. "field" => "pay_fee",
  94. "template_field" => "amount12",
  95. ],
  96. [
  97. "name" => "订单时间",
  98. "field" => "create_date",
  99. "template_field" => "date6",
  100. ],
  101. ],
  102. ]
  103. ];
  104. // 返回的字段列表
  105. public $returnField = [
  106. 'name' => '新订单通知',
  107. 'channels' => ['Sms', 'Email', 'WechatOfficialAccount'],
  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' => 'pay_fee'],
  116. ['name' => '收货人', 'field' => 'consignee'],
  117. ['name' => '收货地址', 'field' => 'address'],
  118. ['name' => '下单时间', 'field' => 'create_date'],
  119. ['name' => '支付时间', 'field' => 'paid_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. $user = $this->data['user'];
  132. $address = Address::where('order_id', $order['id'])->find();
  133. if ($address) {
  134. $consignee = $address['consignee'] . '-' . $address['mobile'];
  135. $address_info = $address['province_name'] . '/' . $address['city_name'] . '/' . $address['district_name'] . '/' . $address['address'];
  136. }
  137. $data['template'] = $this->returnField['name']; // 模板名称
  138. $data['order_id'] = $order['id'];
  139. $data['order_sn'] = $order['order_sn'];
  140. $data['order_amount'] = '¥' . $order['order_amount'];
  141. $data['nickname'] = $user['nickname'] ?? '';
  142. $data['mobile'] = $user['mobile'] ?? '';
  143. $data['pay_fee'] = '¥' . $order['pay_fee'];
  144. $data['consignee'] = $consignee ?? '';
  145. $data['address'] = $address_info ?? '';
  146. $data['create_date'] = $order['createtime'];
  147. $data['paid_date'] = $order['paid_time'];
  148. // 统一跳转地址(先不跳)
  149. // $data['jump_url'] = "/pages/order/detail?id=" . $order['id'];
  150. return $data;
  151. }
  152. }