|
@@ -58,40 +58,63 @@ class MemberCollectService extends BaseService
|
|
|
*/
|
|
|
public function getDataList($userId, $params, $pageSize = 15, $field='')
|
|
|
{
|
|
|
- $where = ['a.mark' => 1,'a.status'=>1,'a.user_id'=> $userId,'b.mark'=>1];
|
|
|
- $field = $field? $field : 'lev_a.id,lev_a.user_id,lev_a.type,lev_a.collect_uid,lev_a.create_time,lev_b.nickname,lev_b.avatar';
|
|
|
+ $where = ['a.mark' => 1,'a.status'=>1];
|
|
|
+ $field = $field? $field : 'lev_a.id,lev_a.user_id,lev_a.type,lev_a.collect_uid,lev_b.nickname,lev_b.avatar,lev_c.nickname as c_nickname,lev_c.avatar as c_avatar';
|
|
|
$sortType = isset($params['sort_type']) ? $params['sort_type'] : 1;
|
|
|
$order = 'id desc';
|
|
|
if($sortType == 1){
|
|
|
$order = 'create_time desc, lev_a.id desc';
|
|
|
}
|
|
|
- $list = $this->model->with(['mechanic'])
|
|
|
- ->from('member_collect as a')
|
|
|
- ->leftJoin('member as b', 'b.id', '=', 'a.collect_uid')
|
|
|
+ $list = $this->model->from('member_collect as a')
|
|
|
+ ->leftJoin('member as b', function($join){
|
|
|
+ $join->on('b.id', '=', 'a.user_id')
|
|
|
+ ->where('b.status', 1)
|
|
|
+ ->where('b.mark', 1);
|
|
|
+ })
|
|
|
+ ->leftJoin('member as c', function($join){
|
|
|
+ $join->on('c.id', '=', 'a.collect_uid')
|
|
|
+ ->where('c.status', 1)
|
|
|
+ ->where('c.mark', 1);
|
|
|
+ })
|
|
|
->where($where)
|
|
|
- ->where(function ($query) use ($params) {
|
|
|
- $userId = isset($params['user_id']) ? $params['user_id'] : 0;
|
|
|
- if ($userId > 0) {
|
|
|
- $query->where('a.user_id', $userId);
|
|
|
- }
|
|
|
-
|
|
|
+ ->where(function ($query) use ($params, $userId) {
|
|
|
$status = isset($params['status'])? $params['status'] : 0;
|
|
|
$status = $status>0? $status : 1;
|
|
|
if ($status > 0) {
|
|
|
$query->where('a.status', $status);
|
|
|
}
|
|
|
|
|
|
- $type = isset($params['type'])? $params['type'] : 0;
|
|
|
- $type = $type>0? $type : 1;
|
|
|
- if ($type > 0) {
|
|
|
- $query->where('a.type', $type);
|
|
|
+ $followType = isset($params['follow_type'])? $params['follow_type'] : 0;
|
|
|
+ if (in_array($followType,[1,2])) {
|
|
|
+ // 我关注的人
|
|
|
+ if($followType == 1){
|
|
|
+ $query->where('a.user_id', $userId);
|
|
|
+ }
|
|
|
+ // 关注我的人
|
|
|
+ else if($followType == 2){
|
|
|
+ $query->where('a.collect_uid', $userId);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ // 我关注的和关注我的人
|
|
|
+ $query->where(function($query) use($userId){
|
|
|
+ $query->where('a.user_id',$userId)
|
|
|
+ ->orWhere('a.collect_uid', $userId);
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
})
|
|
|
->where(function ($query) use ($params) {
|
|
|
$keyword = isset($params['kw']) ? $params['kw'] : '';
|
|
|
+ $followType = isset($params['follow_type'])? $params['follow_type'] : 0;
|
|
|
if ($keyword) {
|
|
|
- $query->where('b.nickname', 'like', "%{$keyword}%")->orWhere('b.username','like',"%{$keyword}%");
|
|
|
+ if($followType == 1){
|
|
|
+ $query->where('b.nickname', 'like', "%{$keyword}%")->orWhere('b.id','like',"%{$keyword}%");
|
|
|
+ }else if($followType == 2){
|
|
|
+ $query->where('c.nickname', 'like', "%{$keyword}%")->orWhere('c.id','like',"%{$keyword}%");
|
|
|
+ }else{
|
|
|
+ $query->where('b.nickname', 'like', "%{$keyword}%")->orWhere('b.id','like',"%{$keyword}%")
|
|
|
+ ->where('c.nickname', 'like', "%{$keyword}%")->orWhere('c.id','like',"%{$keyword}%");
|
|
|
+ }
|
|
|
}
|
|
|
})
|
|
|
->selectRaw($field)
|
|
@@ -100,15 +123,15 @@ class MemberCollectService extends BaseService
|
|
|
$list = $list ? $list->toArray() : [];
|
|
|
if ($list) {
|
|
|
foreach ($list['data'] as &$item) {
|
|
|
- $item['time_text'] = isset($item['create_time']) && $item['create_time']? dateFormat($item['create_time']) : '';
|
|
|
$item['avatar'] = isset($item['avatar']) && $item['avatar'] ? get_image_url($item['avatar']) : '';
|
|
|
- $mechaic = isset($item['mechanic'])? $item['mechanic'] : [];
|
|
|
- if($mechaic){
|
|
|
- $mechaic['avatar'] = isset($mechaic['avatar'])? get_image_url($mechaic['avatar']) : '';
|
|
|
- $mechaic['nickname'] = isset($mechaic['nickname']) && $mechaic['nickname']? $mechaic['nickname']: $mechaic['realname'];
|
|
|
+ $item['c_avatar'] = isset($item['c_avatar']) && $item['c_avatar'] ? get_image_url($item['c_avatar']) : '';
|
|
|
+ // 我关注的用户
|
|
|
+ if($userId == $item['user_id']){
|
|
|
+ $item['nickname'] = $item['c_nickname'];
|
|
|
+ $item['avatar'] = $item['c_avatar']? $item['c_avatar'] : get_image_url('/images/member/logo.png');
|
|
|
}
|
|
|
+
|
|
|
$item['checked'] = false;
|
|
|
- $item['mechanic'] = $mechaic;
|
|
|
}
|
|
|
}
|
|
|
|