截流自动化的商城平台
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

CommunityUserLogic.php 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. namespace app\api\logic;
  3. use app\common\basics\Logic;
  4. use app\common\model\community\CommunityArticle;
  5. use app\common\model\community\CommunityFollow;
  6. use app\common\model\community\CommunityUser;
  7. use app\common\model\user\User;
  8. use app\common\server\ConfigServer;
  9. use app\common\server\UrlServer;
  10. /**
  11. * 社区用户相关
  12. * Class CommunityArticleLogic
  13. * @package app\api\logic
  14. */
  15. class CommunityUserLogic extends Logic
  16. {
  17. /**
  18. * @notes 获取个人中心信息
  19. * @param $user_id
  20. * @return mixed
  21. * @author 段誉
  22. * @date 2022/5/5 18:00
  23. */
  24. public static function getCenterInfo($user_id, $get)
  25. {
  26. // 是否获取当前登录者信息
  27. $is_self = true;
  28. // 当前登录者是否关注需获取信息的$get['user_id']
  29. $is_follow = false;
  30. if (!empty($get['user_id']) && $get['user_id'] != $user_id) {
  31. // 校验是否关注
  32. $relation = CommunityFollow::where([
  33. 'user_id' => $user_id,
  34. 'follow_id' => $get['user_id'],
  35. 'status' => 1
  36. ])->findOrEmpty();
  37. if (!$relation->isEmpty()) {
  38. $is_follow = true;
  39. }
  40. $user_id = $get['user_id'];
  41. $is_self = false;
  42. }
  43. $user = User::field(['id', 'sn', 'nickname', 'avatar'])->findOrEmpty($user_id)->toArray();
  44. $community = CommunityUser::getUserInfo($user_id);
  45. $user['avatar'] = !empty($user['avatar']) ? UrlServer::getFileUrl($user['avatar']) : '';
  46. $user['image'] = !empty($community['image']) ? UrlServer::getFileUrl($community['image']) : '';
  47. $user['signature'] = $community['signature'];
  48. $user['follow'] = CommunityFollow::where(['user_id' => $user_id, 'status' => 1])->count();
  49. $user['fans'] = CommunityFollow::where(['follow_id' => $user_id, 'status' => 1])->count();
  50. $user['like'] = CommunityArticle::where(['user_id' => $user_id])->sum('like');
  51. // 是否为当前登录者
  52. $user['is_self'] = $is_self ? 1 : 0;
  53. // 是否关注
  54. $user['is_follow'] = $is_follow ? 1 : 0;
  55. return $user;
  56. }
  57. /**
  58. * @notes 获取设置
  59. * @param $user_id
  60. * @return array|\think\Model
  61. * @author 段誉
  62. * @date 2022/5/5 18:39
  63. */
  64. public static function getSetting($user_id)
  65. {
  66. $user = CommunityUser::getUserInfo($user_id);
  67. if (empty($user['image'])) {
  68. $user['image'] = ConfigServer::get('community', 'user_bg');
  69. }
  70. return $user->toArray();
  71. }
  72. /**
  73. * @notes 个人设置
  74. * @param $user_id
  75. * @param $post
  76. * @return CommunityUser|false
  77. * @author 段誉
  78. * @date 2022/5/5 18:34
  79. */
  80. public static function setSetting($user_id, $post)
  81. {
  82. $user = CommunityUser::getUserInfo($user_id);
  83. if (empty($user)) {
  84. self::$error = '系统错误';
  85. return false;
  86. }
  87. return CommunityUser::where(['user_id' => $user_id])->update([
  88. 'signature' => $post['signature'] ?? '',
  89. 'image' => $post['image'] ?? '',
  90. ]);
  91. }
  92. }