UserLike.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. /**
  5. * 模型
  6. */
  7. class UserLike extends Model
  8. {
  9. // 开启自动写入时间戳字段
  10. protected $autoWriteTimestamp = 'int';
  11. // 定义时间戳字段名
  12. protected $createTime = 'createtime';
  13. /**
  14. * 获取喜欢列表
  15. */
  16. public function getUserList($user_id,$pageStart=1,$pageNum=10) {
  17. $where = [];
  18. $where["a.fans_id"] = $user_id;
  19. $list = $this->alias("a")
  20. ->field("a.id,a.user_id,a.fans_id,u.nickname,u.avatar,u.age,u.constellation,u.wechat,hobby_ids,profession,u.copy_mobile,u.mobile")
  21. ->join("hx_user u","u.id = a.user_id","left")
  22. ->where($where)
  23. ->limit($pageStart,$pageNum)
  24. ->select();
  25. if($list) foreach($list as $k => $v) {
  26. if($v['hobby_ids']) {
  27. $list[$k]['hobby_ids'] = \app\common\model\Hobby::getHobbyNames($v['hobby_ids']);
  28. } else {
  29. $list[$k]['hobby_ids'] = [];
  30. }
  31. }
  32. return $list;
  33. }
  34. /**
  35. * 获取喜欢列表
  36. */
  37. public function getFansList($user_id,$pageStart=1,$pageNum=10) {
  38. $where = [];
  39. $where["a.user_id"] = $user_id;
  40. $list = $this->alias("a")
  41. ->field("a.id,a.fans_id as user_id,u.nickname,u.avatar,u.age,u.constellation,hobby_ids,profession,u.copy_mobile,u.mobile")
  42. ->join("hx_user u","u.id = a.fans_id","left")
  43. ->where($where)
  44. ->limit($pageStart,$pageNum)
  45. ->select();
  46. if($list) foreach($list as $k => $v) {
  47. if($v['hobby_ids']) {
  48. $list[$k]['hobby_ids'] = \app\common\model\Hobby::getHobbyNames($v['hobby_ids']);
  49. } else {
  50. $list[$k]['hobby_ids'] = [];
  51. }
  52. }
  53. return $list;
  54. }
  55. }