ActiveStatus.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace app\common\service\message\sharing;
  3. use app\common\service\message\Basics;
  4. use app\common\model\Setting as SettingModel;
  5. use app\common\enum\sharing\ActiveStatus as ActiveStatusEnum;
  6. /**
  7. * 消息通知服务 [拼团进度]
  8. * Class ActiveStatus
  9. * @package app\common\service\message\sharing
  10. */
  11. class ActiveStatus extends Basics
  12. {
  13. /**
  14. * 参数列表
  15. * @var array
  16. */
  17. protected $param = [
  18. 'active' => [], // 拼单详情
  19. 'status' => false, // 拼单状态
  20. ];
  21. /**
  22. * 发送消息通知
  23. * @param array $param
  24. * @return mixed|void
  25. * @throws \think\Exception
  26. */
  27. public function send($param)
  28. {
  29. // 记录参数
  30. $this->param = $param;
  31. // 微信订阅消息通知用户
  32. $this->onSendWxSubMsg();
  33. }
  34. /**
  35. * 微信订阅消息通知用户
  36. * @return bool
  37. * @throws \app\common\exception\BaseException
  38. * @throws \think\Exception
  39. * @throws \think\exception\DbException
  40. */
  41. private function onSendWxSubMsg()
  42. {
  43. // 拼单详情
  44. $activeInfo = $this->param['active'];
  45. $status = $this->param['status'];
  46. $wxappId = $activeInfo['wxapp_id'];
  47. // 获取订阅消息配置
  48. $template = SettingModel::getItem('submsg', $wxappId)['sharing']['active_status'];
  49. if (empty($template['template_id'])) {
  50. return false;
  51. }
  52. // 发送订阅消息
  53. foreach ($activeInfo['users'] as $item) {
  54. $this->sendWxSubMsg($wxappId, [
  55. 'touser' => $item['user']['open_id'],
  56. 'template_id' => $template['template_id'],
  57. 'page' => "pages/sharing/active/index?active_id={$activeInfo['active_id']}",
  58. 'data' => [
  59. // 拼团商品
  60. $template['keywords'][0] => ['value' => str_substr($activeInfo['goods']['goods_name'], 20)],
  61. // 拼团价格
  62. $template['keywords'][1] => ['value' => $item['sharing_order']['pay_price']],
  63. // 成团人数
  64. $template['keywords'][2] => ['value' => $activeInfo['people']],
  65. // 拼团进度
  66. $template['keywords'][3] => ['value' => "已有{$activeInfo['actual_people']}人参与"],
  67. // 温馨提示
  68. $template['keywords'][4] => ['value' => ActiveStatusEnum::data()[$status]['name']],
  69. ]
  70. ]);
  71. }
  72. return true;
  73. }
  74. }