UserFriendsJob.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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\jobs\user;
  12. use app\services\user\UserFriendsServices;
  13. use crmeb\basic\BaseJobs;
  14. use crmeb\traits\QueueTrait;
  15. use think\facade\Log;
  16. /**
  17. * 用户好友关系
  18. * Class UserFriendsJob
  19. * @package app\jobs\user
  20. */
  21. class UserFriendsJob extends BaseJobs
  22. {
  23. use QueueTrait;
  24. /**
  25. * 记录用户好友关系
  26. * @param int $uid
  27. * @param int $spreadUid
  28. * @return bool
  29. */
  30. public function doJob(int $uid, int $spreadUid)
  31. {
  32. if (!$uid || !$spreadUid || $uid == $spreadUid) {
  33. return true;
  34. }
  35. try {
  36. /** @var UserFriendsServices $serviceFriend */
  37. $serviceFriend = app()->make(UserFriendsServices::class);
  38. $serviceFriend->saveFriend($uid, $spreadUid);
  39. } catch (\Throwable $e) {
  40. Log::error('记录好友关系失败,失败原因:' . $e->getMessage());
  41. }
  42. return true;
  43. }
  44. }