PointChangeNotice.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2020/6/14
  6. * Time: 10:09
  7. */
  8. namespace app\common\services\notice\official;
  9. use app\common\services\notice\BaseMessageBody;
  10. use app\common\services\notice\share\OfficialNoticeTemplate;
  11. class PointChangeNotice extends BaseMessageBody
  12. {
  13. use OfficialNoticeTemplate;
  14. public $member;
  15. public $point;
  16. public $status;
  17. public function __construct($member,$point,$status)
  18. {
  19. $this->member = $member;
  20. $this->point = $point;
  21. $this->status = $status;
  22. }
  23. public function organizeData()
  24. {
  25. // TODO: Implement organizeData() method.
  26. $this->data = [
  27. ['name' => '商城名称', 'value' => \Setting::get('shop.shop')['name']],
  28. ['name' => '昵称', 'value' => $this->member->nickname],
  29. ['name' => '时间', 'value' => date('Y-m-d H:i', time())],
  30. ['name' => '积分变动金额', 'value' => $this->point['point']],
  31. ['name' => '积分变动类型', 'value' => $this->status],
  32. ['name' => '变动后积分数值', 'value' => $this->point['after_point']]
  33. ];
  34. }
  35. public function sendMessage()
  36. {
  37. // TODO: Implement sendMessage() method.
  38. $this->getTemplate('point_change');
  39. $this->organizeData();
  40. \Log::debug("新版公众号消息-积分1",$this->template_id);
  41. \Log::debug("新版公众号消息-积分2",$this->member->hasOneFans->openid);
  42. \Log::debug("新版公众号消息-积分3",$this->data);
  43. $result = (new OfficialMessageNotice($this->temp_id,$this->member->hasOneFans->openid,$this->data,[],1,$this->url))->sendMessage();
  44. if (app('plugins')->isEnabled('instation-message')) {
  45. //开启了站内消息插件
  46. event(new \Yunshop\InstationMessage\event\PointChangeEvent([
  47. 'changeTime'=>date('Y-m-d H:i', time()),
  48. 'changeType'=>$this->status,
  49. 'changeNum'=>$this->point['point'],
  50. 'afterChange'=>$this->point['after_point'],
  51. 'member_id'=>$this->member->uid,
  52. 'uniacid'=>\YunShop::app()->uniacid
  53. ]));
  54. }
  55. if ($result['status'] == 0) {
  56. \Log::debug($result['message']);
  57. }
  58. }
  59. }