ScoreChange.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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 ScoreChange 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 = 'score_change';
  18. // 额外数据
  19. public $data = [];
  20. public $template = [
  21. 'MessageDefaultContent' => '您的积分发生变化,变动类型:{event_name},变动数量:{amount},请及时查看',
  22. // 'WechatOfficialAccount' => [
  23. // 'temp_no' => 'OPENTM415437052',
  24. // 'fields' => [
  25. // // 'first' => '您的积分发生变动,请及时查看',
  26. // // 'keyword1' => 'event_name', // 交易类型
  27. // // 'keyword2' => 'amount', // 交易金额
  28. // // 'keyword3' => 'create_date', // 交易时间
  29. // // 'keyword4' => 'score', // 账户余额
  30. // // 'remark' => '您的积分发生变动,请及时查看',
  31. // [
  32. // "template_field" => "first",
  33. // "value" => '您的积分发生变动,请及时查看',
  34. // ],
  35. // [
  36. // "name" => "交易类型",
  37. // "field" => "event_name",
  38. // "template_field" => "keyword1",
  39. // ],
  40. // [
  41. // "name" => "交易金额",
  42. // "field" => "amount",
  43. // "template_field" => "keyword2",
  44. // ],
  45. // [
  46. // "name" => "交易时间",
  47. // "field" => "create_date",
  48. // "template_field" => "keyword3",
  49. // ],
  50. // [
  51. // "name" => "账户余额",
  52. // "field" => "score",
  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' => '3613',
  69. 'kid' => [8,15,6,7], // 变动原因,积分变动,积分总额,变动时间
  70. 'scene_desc' => '当积分发生变化时通知用户', // 申请模板场景描述
  71. 'fields' => [
  72. // 'thing8' => 'event_name', // 变动原因
  73. // 'number1' => 'amount', // 积分变动
  74. // 'number6' => 'score', // 积分总额
  75. // 'time7' => 'create_date', // 变动时间
  76. [
  77. "name" => "变动原因",
  78. "field" => "event_name",
  79. "template_field" => "thing8",
  80. ],
  81. [
  82. "name" => "积分变动值",
  83. "field" => "amount",
  84. "template_field" => "character_string15",
  85. ],
  86. [
  87. "name" => "积分总额",
  88. "field" => "score",
  89. "template_field" => "number6",
  90. ],
  91. [
  92. "name" => "变动时间",
  93. "field" => "create_date",
  94. "template_field" => "time7",
  95. ],
  96. ],
  97. ]
  98. ];
  99. // 返回的字段列表
  100. public $returnField = [
  101. 'name' => '积分变动通知',
  102. 'channels' => ['Sms', 'Email', 'WechatOfficialAccount', 'WechatMiniProgram'],
  103. 'fields' => [
  104. ['name' => '消息名称', 'field' => 'template'],
  105. ['name' => '变动用户', 'field' => 'nickname'],
  106. ['name' => '用户手机', 'field' => 'mobile'],
  107. ['name' => '变动类型', 'field' => 'event_name'],
  108. ['name' => '变动数量', 'field' => 'amount'],
  109. ['name' => '变动前', 'field' => 'before'],
  110. ['name' => '变动后', 'field' => 'after'],
  111. ['name' => '当前积分', 'field' => 'score'],
  112. ['name' => '备注信息', 'field' => 'memo'],
  113. ['name' => '变动时间', 'field' => 'create_date'],
  114. ]
  115. ];
  116. /**
  117. * 组合数据参数
  118. *
  119. * @param \think\Model $notifiable
  120. * @return array
  121. */
  122. protected function getData($notifiable)
  123. {
  124. $walletLog = $this->data['walletLog'];
  125. $type = $this->data['type'];
  126. $data['template'] = $this->returnField['name']; // 模板名称
  127. $data['nickname'] = $notifiable['nickname'];
  128. $data['mobile'] = $notifiable['mobile'];
  129. $data['event_name'] = '积分变动';
  130. $data['amount'] = $walletLog['amount'];
  131. $data['before'] = $walletLog['before'];
  132. $data['after'] = $walletLog['after'];
  133. $data['score'] = $walletLog['after'];
  134. $data['memo'] = $walletLog['event_text'] . ($walletLog['memo'] ? ('-' . $walletLog['memo']) : '');
  135. $data['create_date'] = $walletLog['createtime'];
  136. // 统一跳转地址
  137. $data['jump_url'] = "/pages/user/wallet/score";
  138. return $data;
  139. }
  140. }