Snsfriend.php 4.5 KB

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