Snsfriend.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. namespace app\common\model;
  3. use think\facade\Db;
  4. /**
  5. *
  6. *
  7. * ----------------------------------------------------------------------------
  8. *
  9. * 数据层模型
  10. */
  11. class Snsfriend extends BaseModel
  12. {
  13. public $page_info;
  14. /**
  15. * 好友添加
  16. * @access public
  17. * @author csdeshang
  18. * @param type $data 数据
  19. * @return type
  20. */
  21. public function addSnsfriend($data)
  22. {
  23. $result = Db::name('snsfriend')->insertGetId($data);
  24. return $result;
  25. }
  26. /**
  27. * 好友列表
  28. * @access public
  29. * @author csdeshang
  30. * @param type $condition 条件
  31. * @param type $field 字段
  32. * @param type $pagesize 分页
  33. * @param type $type 类型
  34. * @return type
  35. */
  36. public function getSnsfriendList($condition, $field = '*', $pagesize = '', $type = 'simple')
  37. {
  38. //得到条件语句
  39. switch ($type) {
  40. case 'simple':
  41. $data = Db::name('snsfriend')->where($condition)->field($field);
  42. break;
  43. case 'detail':
  44. $data = Db::name('snsfriend')->alias('snsfriend')->where($condition)->field($field)->join('member member', 'snsfriend.friend_tomid=member.member_id');
  45. break;
  46. case 'fromdetail':
  47. $data = Db::name('snsfriend')->alias('snsfriend')->where($condition)->field($field)->join('member member', 'snsfriend.friend_frommid=member.member_id');
  48. break;
  49. }
  50. if ($pagesize) {
  51. $data = $data->paginate(['list_rows' => $pagesize, 'query' => request()->param()], false);
  52. $this->page_info = $data;
  53. $friend_list = $data->items();
  54. } else {
  55. $friend_list = $data->select()->toArray();
  56. }
  57. return $friend_list;
  58. }
  59. /**
  60. * 取得我的好友
  61. * @access public
  62. * @author csdeshang
  63. * @param type $condition 条件
  64. * @param type $limit 限制
  65. * @param type $member_list 会员列表
  66. * @return array
  67. */
  68. public function getFriendList($condition = array(), $limit = 50, $member_list = array())
  69. {
  70. $list = Db::name('snsfriend')->where($condition)->order('friend_addtime desc')->paginate(['list_rows' => $limit, 'query' => request()->param()], false);
  71. if ($list) {
  72. foreach ($list as $k => $v) {
  73. $member = array();
  74. $u_id = $v['friend_tomid'];
  75. $member['u_id'] = $u_id;
  76. $member['u_name'] = $v['friend_tomname'];
  77. $member['avatar'] = get_member_avatar_for_id($u_id);
  78. $member['friend'] = 1;
  79. $member_list[$u_id] = $member;
  80. }
  81. }
  82. $this->page_info = $list;
  83. return $member_list;
  84. }
  85. /**
  86. * 获取好友详细
  87. * @access public
  88. * @author csdeshang
  89. * @param type $condition 条件
  90. * @param type $field 字段
  91. * @return type
  92. */
  93. public function getOneSnsfriend($condition, $field = '*')
  94. {
  95. return Db::name('snsfriend')->where($condition)->field($field)->find();
  96. }
  97. /**
  98. * 好友总数
  99. * @access public
  100. * @author csdeshang
  101. * @param type $condition 条件
  102. * @return type
  103. */
  104. public function getSnsfriendCount($condition)
  105. {
  106. //得到条件语句
  107. $count = Db::name('snsfriend')->where($condition)->count();
  108. return $count;
  109. }
  110. /**
  111. * 更新好友信息
  112. * @access public
  113. * @author csdeshang
  114. * @param type $data 更新数据
  115. * @param type $condition 条件
  116. * @return boolean
  117. */
  118. public function editSnsfriend($data, $condition)
  119. {
  120. if (empty($data)) {
  121. return false;
  122. }
  123. //得到条件语句
  124. $result = Db::name('snsfriend')->where($condition)->update($data);
  125. return $result;
  126. }
  127. /**
  128. * 删除关注
  129. * @access public
  130. * @author csdeshang
  131. * @param type $condition
  132. * @return boolean
  133. */
  134. public function delSnsfriend($condition)
  135. {
  136. if (empty($condition)) {
  137. return false;
  138. }
  139. return Db::name('snsfriend')->where($condition)->delete();
  140. }
  141. }