UserBindClient.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\listener\user;
  12. use app\services\work\WorkClientServices;
  13. use crmeb\interfaces\ListenerInterface;
  14. /**
  15. * 用户绑定客户
  16. * Class UserBindClient
  17. * @package app\listener\user
  18. */
  19. class UserBindClient implements ListenerInterface
  20. {
  21. public function handle($event): void
  22. {
  23. [$uid, $unionid] = $event;
  24. try {
  25. /** @var WorkClientServices $make */
  26. $make = app()->make(WorkClientServices::class);
  27. $clientInfo = $make->get(['unionid' => $unionid], ['id', 'unionid', 'uid']);
  28. if ($clientInfo) {
  29. $clientInfo->uid = $uid;
  30. $clientInfo->save();
  31. }
  32. } catch (\Throwable $e) {
  33. \think\facade\Log::error([
  34. 'error' => '用户绑定客户失败:' . $e->getMessage(),
  35. 'file' => $e->getFile(),
  36. 'line' => $e->getLine()
  37. ]);
  38. }
  39. }
  40. }