Apply.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace app\common\service\message\dealer;
  3. use app\common\service\message\Basics;
  4. use app\common\model\Setting as SettingModel;
  5. use app\common\enum\dealer\ApplyStatus as ApplyStatusEnum;
  6. /**
  7. * 消息通知服务 [分销商入驻]
  8. * Class Apply
  9. * @package app\common\service\message\dealer
  10. */
  11. class Apply extends Basics
  12. {
  13. /**
  14. * 参数列表
  15. * @var array
  16. */
  17. protected $param = [
  18. 'apply' => [], // 申请记录
  19. 'user' => [], // 用户信息
  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|mixed
  37. * @throws \app\common\exception\BaseException
  38. * @throws \think\Exception
  39. * @throws \think\exception\DbException
  40. */
  41. private function onSendWxSubMsg()
  42. {
  43. $applyInfo = $this->param['apply'];
  44. $userInfo = $this->param['user'];
  45. $wxappId = $applyInfo['wxapp_id'];
  46. // 获取订阅消息配置
  47. $template = SettingModel::getItem('submsg', $wxappId)['dealer']['apply'];
  48. if (empty($template['template_id'])) {
  49. return false;
  50. }
  51. // 发送订阅消息
  52. return $this->sendWxSubMsg($wxappId, [
  53. 'touser' => $userInfo['open_id'],
  54. 'template_id' => $template['template_id'],
  55. 'page' => 'pages/dealer/index/index',
  56. 'data' => [
  57. // 申请时间
  58. $template['keywords'][0] => ['value' => $applyInfo['apply_time']],
  59. // 审核状态
  60. $template['keywords'][1] => ['value' => ApplyStatusEnum::data()[$applyInfo['apply_status']]['name']],
  61. // 审核时间
  62. $template['keywords'][2] => ['value' => $applyInfo['audit_time']],
  63. // 备注信息
  64. $template['keywords'][3] => ['value' => $this->getRemarkValue($applyInfo)],
  65. ]
  66. ]);
  67. }
  68. /**
  69. * 备注信息
  70. * @param $applyInfo
  71. * @return string
  72. */
  73. private function getRemarkValue($applyInfo)
  74. {
  75. $remark = '分销商入驻审核通知';
  76. if ($applyInfo['apply_status'] == 30) {
  77. $remark .= "\n驳回原因:{$applyInfo['reject_reason']}";
  78. }
  79. return $this->getSubstr($remark);
  80. }
  81. }