UserFriendsServices.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\services\user;
  12. use app\dao\user\UserFriendsDao;
  13. use app\services\BaseServices;
  14. /**
  15. * 获取好友列表
  16. * Class UserFriendsServices
  17. * @package app\services\user
  18. */
  19. class UserFriendsServices extends BaseServices
  20. {
  21. public function __construct(UserFriendsDao $dao)
  22. {
  23. $this->dao = $dao;
  24. }
  25. /**
  26. * 获取好友列表
  27. * @param array $where
  28. * @param array $with
  29. * @throws \think\db\exception\DataNotFoundException
  30. * @throws \think\db\exception\DbException
  31. * @throws \think\db\exception\ModelNotFoundException
  32. */
  33. public function getFriendList(array $where, array $with = [])
  34. {
  35. [$page, $limit] = $this->getPageValue();
  36. $list = $this->dao->getFriendList($where, $page, $limit, $with);
  37. $count = $this->dao->count($where);
  38. return compact('list', 'count');
  39. }
  40. /**
  41. * 保存好友关系
  42. * @param array $data
  43. * @return bool|mixed
  44. * @throws \think\db\exception\DataNotFoundException
  45. * @throws \think\db\exception\DbException
  46. * @throws \think\db\exception\ModelNotFoundException
  47. */
  48. public function saveFriend(array $data)
  49. {
  50. $userFriend = $this->dao->get(['uid' => $data['uid']]);
  51. if ($userFriend) {
  52. return true;
  53. } else {
  54. return $this->dao->save($data);
  55. }
  56. }
  57. }