Snsfriend.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. namespace app\common\model;
  3. use think\facade\Db;
  4. /**
  5. * ============================================================================
  6. * DSMall多用户商城
  7. * ============================================================================
  8. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  9. * 网站地址: http://www.csdeshang.com
  10. * ----------------------------------------------------------------------------
  11. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  12. * 不允许对程序代码以任何形式任何目的的再发布。
  13. * ============================================================================
  14. * 数据层模型
  15. */
  16. class Snsfriend extends BaseModel {
  17. public $page_info;
  18. /**
  19. * 好友添加
  20. * @access public
  21. * @author csdeshang
  22. * @param type $data 数据
  23. * @return type
  24. */
  25. public function addSnsfriend($data) {
  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. switch ($type) {
  42. case 'simple':
  43. $data = Db::name('snsfriend')->where($condition)->field($field);
  44. break;
  45. case 'detail':
  46. $data = Db::name('snsfriend')->alias('snsfriend')->where($condition)->field($field)->join('member member', 'snsfriend.friend_tomid=member.member_id');
  47. break;
  48. case 'fromdetail':
  49. $data = Db::name('snsfriend')->alias('snsfriend')->where($condition)->field($field)->join('member member', 'snsfriend.friend_frommid=member.member_id');
  50. break;
  51. }
  52. if($pagesize){
  53. $data= $data->paginate(['list_rows'=>$pagesize,'query' => request()->param()],false);
  54. $this->page_info = $data;
  55. $friend_list = $data->items();
  56. }else{
  57. $friend_list= $data->select()->toArray();
  58. }
  59. return $friend_list;
  60. }
  61. /**
  62. * 取得我的好友
  63. * @access public
  64. * @author csdeshang
  65. * @param type $condition 条件
  66. * @param type $limit 限制
  67. * @param type $member_list 会员列表
  68. * @return array
  69. */
  70. public function getFriendList($condition = array(), $limit = 50, $member_list = array())
  71. {
  72. $list = Db::name('snsfriend')->where($condition)->order('friend_addtime desc')->paginate(['list_rows'=>$limit,'query' => request()->param()],false);
  73. if ($list) {
  74. foreach ($list as $k => $v) {
  75. $member = array();
  76. $u_id = $v['friend_tomid'];
  77. $member['u_id'] = $u_id;
  78. $member['u_name'] = $v['friend_tomname'];
  79. $member['avatar'] = get_member_avatar_for_id($u_id);
  80. $member['friend'] = 1;
  81. $member_list[$u_id] = $member;
  82. }
  83. }
  84. $this->page_info=$list;
  85. return $member_list;
  86. }
  87. /**
  88. * 获取好友详细
  89. * @access public
  90. * @author csdeshang
  91. * @param type $condition 条件
  92. * @param type $field 字段
  93. * @return type
  94. */
  95. public function getOneSnsfriend($condition, $field = '*') {
  96. return Db::name('snsfriend')->where($condition)->field($field)->find();
  97. }
  98. /**
  99. * 好友总数
  100. * @access public
  101. * @author csdeshang
  102. * @param type $condition 条件
  103. * @return type
  104. */
  105. public function getSnsfriendCount($condition) {
  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. if (empty($data)) {
  120. return false;
  121. }
  122. //得到条件语句
  123. $result = Db::name('snsfriend')->where($condition)->update($data);
  124. return $result;
  125. }
  126. /**
  127. * 删除关注
  128. * @access public
  129. * @author csdeshang
  130. * @param type $condition
  131. * @return boolean
  132. */
  133. public function delSnsfriend($condition) {
  134. if (empty($condition)) {
  135. return false;
  136. }
  137. return Db::name('snsfriend')->where($condition)->delete();
  138. }
  139. }