StockWarning.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. namespace addons\shopro\notification\goods;
  3. use addons\shopro\notification\Notification;
  4. use addons\shopro\notification\traits\Notification as NotificationTrait;
  5. /**
  6. * 库存预警提醒
  7. */
  8. class StockWarning extends Notification
  9. {
  10. use NotificationTrait;
  11. // 队列延迟时间,必须继承 ShouldQueue 接口
  12. public $delay = 0;
  13. public $receiver_type = 'admin'; // 接收人:user=用户
  14. // 消息类型 Notification::$notificationType
  15. public $notification_type = 'shop';
  16. // 发送类型
  17. public $event = 'stock_warning';
  18. // 额外数据
  19. public $data = [];
  20. public $template = [
  21. 'MessageDefaultContent' => '商品 {goods_name} 库存不足,请及时补货',
  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. 'WechatMiniProgram' => [
  62. 'category_id' => 670,
  63. 'tid' => '2105',
  64. 'kid' => [1, 4], // 商品名称,备注
  65. 'scene_desc' => '当库存不足时通知管理员', // 申请模板场景描述
  66. 'fields' => [
  67. // 'thing1' => 'event_name', // 商品名称
  68. // 'thing4' => 'amount', // 备注
  69. [
  70. "name" => "商品名称",
  71. "field" => "goods_name",
  72. "template_field" => "thing1",
  73. ],
  74. [
  75. "name" => "备注",
  76. "field" => "description",
  77. "template_field" => "thing4",
  78. ],
  79. ],
  80. ]
  81. ];
  82. // 返回的字段列表
  83. public $returnField = [
  84. 'name' => '商品补货通知',
  85. 'channels' => ['Sms', 'Email'],
  86. 'fields' => [
  87. ['name' => '消息名称', 'field' => 'template'],
  88. ['name' => '商品名称', 'field' => 'goods_name'],
  89. ['name' => '当前库存', 'field' => 'stock'],
  90. ['name' => '预警值', 'field' => 'stock_warning'],
  91. ['name' => '说明', 'field' => 'description'],
  92. ]
  93. ];
  94. /**
  95. * 组合数据参数
  96. *
  97. * @param \think\Model $notifiable
  98. * @return array
  99. */
  100. protected function getData($notifiable)
  101. {
  102. $goods = $this->data['goods'];
  103. $goodsSkuPrice = $this->data['goodsSkuPrice'];
  104. $stock_warning = $this->data['stock_warning'];
  105. $data['template'] = $this->returnField['name']; // 模板名称
  106. $data['goods_name'] = ($goodsSkuPrice['goods_sku_text'] ? join(',', $goodsSkuPrice['goods_sku_text']) . '-' : '') . ($goods ? $goods['title'] : '');
  107. $data['stock'] = $goodsSkuPrice['stock'];
  108. $data['stock_warning'] = $stock_warning;
  109. $data['description'] = '当前商品剩余库存' . $goodsSkuPrice['stock'] . ',低于预警阈值' . $stock_warning . ',请及时补货';
  110. // 统一跳转地址(先不跳)
  111. // $data['jump_url'] = "/pages/order/detail?id=" . $goods['id'];
  112. return $data;
  113. }
  114. }