MoneyChange.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. namespace addons\shopro\notification\wallet;
  3. use addons\shopro\notification\Notification;
  4. use addons\shopro\notification\traits\Notification as NotificationTrait;
  5. /**
  6. * 余额变动通知
  7. */
  8. class MoneyChange extends Notification
  9. {
  10. use NotificationTrait;
  11. // 队列延迟时间,必须继承 ShouldQueue 接口
  12. public $delay = 0;
  13. public $receiver_type = 'user'; // 接收人:user=用户
  14. // 消息类型 Notification::$notificationType
  15. public $notification_type = 'shop';
  16. // 发送类型
  17. public $event = 'money_change';
  18. // 额外数据
  19. public $data = [];
  20. public $template = [
  21. 'MessageDefaultContent' => '您的余额发生变化,变动类型:{event_name},变动金额:{amount},请及时查看',
  22. // 'WechatOfficialAccount' => [
  23. // 'temp_no' => 'OPENTM401833445',
  24. // 'fields' => [
  25. // // 'first' => '您的余额发生变动,请及时查看',
  26. // // 'keyword1' => 'create_date', // 变动时间
  27. // // 'keyword2' => 'event_name', // 变动类型
  28. // // 'keyword3' => 'amount', // 变动金额
  29. // // 'keyword4' => 'money', // 当前余额
  30. // // 'remark' => '您的余额发生变动,请及时查看',
  31. // [
  32. // "template_field" => "first",
  33. // "value" => '您的余额发生变动,请及时查看',
  34. // ],
  35. // [
  36. // "name" => "变动时间",
  37. // "field" => "create_date",
  38. // "template_field" => "keyword1",
  39. // ],
  40. // [
  41. // "name" => "变动类型",
  42. // "field" => "event_name",
  43. // "template_field" => "keyword2",
  44. // ],
  45. // [
  46. // "name" => "变动金额",
  47. // "field" => "amount",
  48. // "template_field" => "keyword3",
  49. // ],
  50. // [
  51. // "name" => "当前余额",
  52. // "field" => "money",
  53. // "template_field" => "keyword4",
  54. // ],
  55. // [
  56. // "template_field" => "remark",
  57. // "value" => '您的余额发生变动,请及时查看',
  58. // ]
  59. // ],
  60. // ],
  61. 'WechatOfficialAccount' => [
  62. 'temp_no' => false, // 目前公众号类目模板库,找不到符合条件模板
  63. 'keywords' => [],
  64. 'fields' => [],
  65. ],
  66. 'WechatMiniProgram' => [
  67. 'category_id' => 670,
  68. 'tid' => '4148',
  69. 'kid' => [8,1,2,4,5], // 变动类型,变动金额,账户余额,时间,备注
  70. 'scene_desc' => '当余额发生变化时通知用户', // 申请模板场景描述
  71. 'fields' => [
  72. // 'thing8' => 'event_name', // 变动类型
  73. // 'amount1' => 'amount', // 变动金额
  74. // 'amount2' => 'money', // 账户余额
  75. // 'date' => 'create_date', // 时间
  76. // 'thing5' => 'memo', // 备注
  77. [
  78. "name" => "变动类型",
  79. "field" => "event_name",
  80. "template_field" => "thing8",
  81. ],
  82. [
  83. "name" => "变动金额",
  84. "field" => "amount",
  85. "template_field" => "amount1",
  86. ],
  87. [
  88. "name" => "账户余额",
  89. "field" => "money",
  90. "template_field" => "amount2",
  91. ],
  92. [
  93. "name" => "时间",
  94. "field" => "create_date",
  95. "template_field" => "date4",
  96. ],
  97. [
  98. "name" => "备注",
  99. "field" => "memo",
  100. "template_field" => "thing5",
  101. ],
  102. ],
  103. ]
  104. ];
  105. // 返回的字段列表
  106. public $returnField = [
  107. 'name' => '余额变动通知',
  108. 'channels' => ['Sms', 'Email', 'WechatOfficialAccount', 'WechatMiniProgram'],
  109. 'fields' => [
  110. ['name' => '消息名称', 'field' => 'template'],
  111. ['name' => '变动用户', 'field' => 'nickname'],
  112. ['name' => '用户手机', 'field' => 'mobile'],
  113. ['name' => '变动类型', 'field' => 'event_name'],
  114. ['name' => '变动金额', 'field' => 'amount'],
  115. ['name' => '变动前', 'field' => 'before'],
  116. ['name' => '变动后', 'field' => 'after'],
  117. ['name' => '当前余额', 'field' => 'money'],
  118. ['name' => '备注信息', 'field' => 'memo'],
  119. ['name' => '变动时间', 'field' => 'create_date'],
  120. ]
  121. ];
  122. /**
  123. * 组合数据参数
  124. *
  125. * @param \think\Model $notifiable
  126. * @return array
  127. */
  128. protected function getData($notifiable)
  129. {
  130. $walletLog = $this->data['walletLog'];
  131. $type = $this->data['type'];
  132. $data['template'] = $this->returnField['name']; // 模板名称
  133. $data['nickname'] = $notifiable['nickname'];
  134. $data['mobile'] = $notifiable['mobile'];
  135. $data['event_name'] = '余额变动';
  136. $data['amount'] = '¥' . $walletLog['amount'];
  137. $data['before'] = '¥' . $walletLog['before'];
  138. $data['after'] = '¥' . $walletLog['after'];
  139. $data['money'] = '¥' . $walletLog['after'];
  140. $data['memo'] = $walletLog['event_text'] . ($walletLog['memo'] ? ('-' . $walletLog['memo']) : '');
  141. $data['create_date'] = $walletLog['createtime'];
  142. // 统一跳转地址
  143. $data['jump_url'] = "/pages/user/wallet/money";
  144. return $data;
  145. }
  146. }