Snsfriend.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. namespace app\common\model;
  3. use think\facade\Db;
  4. /**
  5. * ============================================================================
  6. *
  7. * ============================================================================
  8. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  9. * 网站地址: https://www.valimart.net/
  10. * ----------------------------------------------------------------------------
  11. *
  12. * ============================================================================
  13. * 数据层模型
  14. */
  15. class Snsfriend extends BaseModel {
  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. $result = Db::name('snsfriend')->insertGetId($data);
  26. return $result;
  27. }
  28. /**
  29. * 好友列表
  30. * @access public
  31. * @author csdeshang
  32. * @param type $condition 条件
  33. * @param type $field 字段
  34. * @param type $pagesize 分页
  35. * @param type $type 类型
  36. * @return type
  37. */
  38. public function getSnsfriendList($condition, $field = '*', $pagesize = '', $type = 'simple') {
  39. //得到条件语句
  40. switch ($type) {
  41. case 'simple':
  42. $data = Db::name('snsfriend')->where($condition)->field($field);
  43. break;
  44. case 'detail':
  45. $data = Db::name('snsfriend')->alias('snsfriend')->where($condition)->field($field)->join('member member', 'snsfriend.friend_tomid=member.member_id');
  46. break;
  47. case 'fromdetail':
  48. $data = Db::name('snsfriend')->alias('snsfriend')->where($condition)->field($field)->join('member member', 'snsfriend.friend_frommid=member.member_id');
  49. break;
  50. }
  51. if($pagesize){
  52. $data= $data->paginate(['list_rows'=>$pagesize,'query' => request()->param()],false);
  53. $this->page_info = $data;
  54. $friend_list = $data->items();
  55. }else{
  56. $friend_list= $data->select()->toArray();
  57. }
  58. return $friend_list;
  59. }
  60. /**
  61. * 取得我的好友
  62. * @access public
  63. * @author csdeshang
  64. * @param type $condition 条件
  65. * @param type $limit 限制
  66. * @param type $member_list 会员列表
  67. * @return array
  68. */
  69. public function getFriendList($condition = array(), $limit = 50, $member_list = array())
  70. {
  71. $list = Db::name('snsfriend')->where($condition)->order('friend_addtime desc')->paginate(['list_rows'=>$limit,'query' => request()->param()],false);
  72. if ($list) {
  73. foreach ($list as $k => $v) {
  74. $member = array();
  75. $u_id = $v['friend_tomid'];
  76. $member['u_id'] = $u_id;
  77. $member['u_name'] = $v['friend_tomname'];
  78. $member['avatar'] = get_member_avatar_for_id($u_id);
  79. $member['friend'] = 1;
  80. $member_list[$u_id] = $member;
  81. }
  82. }
  83. $this->page_info=$list;
  84. return $member_list;
  85. }
  86. /**
  87. * 获取好友详细
  88. * @access public
  89. * @author csdeshang
  90. * @param type $condition 条件
  91. * @param type $field 字段
  92. * @return type
  93. */
  94. public function getOneSnsfriend($condition, $field = '*') {
  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. $count = Db::name('snsfriend')->where($condition)->count();
  107. return $count;
  108. }
  109. /**
  110. * 更新好友信息
  111. * @access public
  112. * @author csdeshang
  113. * @param type $data 更新数据
  114. * @param type $condition 条件
  115. * @return boolean
  116. */
  117. public function editSnsfriend($data, $condition) {
  118. if (empty($data)) {
  119. return false;
  120. }
  121. //得到条件语句
  122. $result = Db::name('snsfriend')->where($condition)->update($data);
  123. return $result;
  124. }
  125. /**
  126. * 删除关注
  127. * @access public
  128. * @author csdeshang
  129. * @param type $condition
  130. * @return boolean
  131. */
  132. public function delSnsfriend($condition) {
  133. if (empty($condition)) {
  134. return false;
  135. }
  136. return Db::name('snsfriend')->where($condition)->delete();
  137. }
  138. }