AgentAuditServiceListener.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace App\Listeners;
  3. use App\Events\AgentAuditEvent;
  4. use App\Events\AgentAuditServiceEvent;
  5. use App\Models\User;
  6. use App\Models\Warea;
  7. use Illuminate\Queue\Listener;
  8. use Illuminate\Support\Facades\Log;
  9. class AgentAuditServiceListener {
  10. protected $template_id;
  11. protected $url;
  12. //认证审核通知 通知上级 和 邀请人 审核结果
  13. public function __construct()
  14. {
  15. $this->template_id='ibTVb5-mUemyjvLYgQnYI6jpqFh_xQBtzLCb1xOQblQ';
  16. $this->url='http://admin.app.jiuweiyun.cn/#/team/zhengwei';
  17. }
  18. /**
  19. * Handle the event.
  20. *
  21. * @param AgentAuditServiceListener $event
  22. * @return void
  23. */
  24. public function handle(AgentAuditServiceEvent $event)
  25. {
  26. try{
  27. $data=$event->data;
  28. $id=$data['id'];
  29. $app=app('wechat.official_account');
  30. $phone=Warea::where('id',$id)->value('phone');
  31. $user=User::where('mobile',$phone)->first();
  32. if ($user->openid){
  33. $app->template_message->send([
  34. 'touser' => $user->openid,
  35. 'template_id' => $this->template_id,
  36. 'url' => $this->url,
  37. 'data' => $data['data']
  38. ]);
  39. }
  40. }catch (\Exception $exception){
  41. Log::error('发送模板消息出错,出错内容为'.$exception);
  42. }
  43. }
  44. }