$userId, 'type'=> 1, 'status'=> 1]; $collectExpire = Member::where(['id'=> $userId])->value('collect_expire'); if(!$isAuth && $collectExpire - time() <= 0){ return 0; } $count = UserCollect::where($where)->count('id'); return intval($count); } /** * 获取关注用户列表 * @param $params * @param $pageSize * @param string $field * @return $this */ public static function getUserList($userId, $params=[], $pageSize=20, $field=''){ // 验证有效时间,会员不限制 $where = ['uc.user_id'=> $userId,'uc.status'=> 1,'uc.type'=>1]; $memberInfo = Member::where(['id'=> $userId])->field('collect_expire,vip_auth,vip_expire')->find(); $vipAuth = isset($memberInfo['vip_auth']) ? intval($memberInfo['vip_auth']) : 0; $vipExpire = isset($memberInfo['vip_expire']) ? $memberInfo['vip_expire'] : 0; $collectExpire = isset($memberInfo['collect_expire'])? intval($memberInfo['collect_expire']) : 0; if((!$vipAuth || $vipExpire < time()) && $collectExpire - time() <= 0){ UserCollect::where(['user_id' => $userId]) ->update(['status' => 2, 'remark'=> '关注过期', 'updated_at' => date('Y-m-d H:i:s')]); return false; } $field = $field? $field : 'uc.id,uc.user_id,uc.type,uc.source_id,u.real_name,u.user_nickname,u.avatar,u.sex,u.birthday,mp.graduate,mp.education,mp.height,mp.weight,mp.show_graduate,mp.show_company,mp.company,mp.occupation,mp.province,mp.city,mp.home_province,mp.home_city'; return UserCollect::alias('uc') ->join('user u','u.id=uc.source_id','left') ->join('user_profile mp', 'mp.userid=u.id', 'left') ->where($where) ->field($field) ->paginate($pageSize) ->each(function($item, $k){ $item['avatar'] = isset($item['avatar']) ? cmf_get_image_preview_url($item['avatar']) : ''; if (isset($item['birthday'])) { $birthday = isset($item['birthday']) ? $item['birthday'] : 0; $item['birthday_txt'] = $birthday ? date('Y年m月d日', $birthday) : '无'; $item['birthday_code'] = $birthday ? date('Y-m-d', $birthday) : ''; $item['birthday_day'] = $birthday ? date('y年', $birthday) : ''; } $item['height_txt'] = '无'; if (isset($item['height'])) { $height = isset($item['height']) ? intval($item['height']) : 0; $item['height_txt'] = $height ? intval($item['height']) . 'CM' : '无'; } $item['weight_txt'] = '无'; if (isset($item['weight'])) { $weight = isset($item['weight']) ? intval($item['weight']) : 0; $item['weight_txt'] = $weight ? intval($item['weight']) . 'KG' : '无'; } // 学历 $educations = config('weixin.educations'); $edu = isset($item['education']) ? $item['education'] : 0; $item['education_txt'] = $edu && isset($educations[$edu]) ? $educations[$edu] : ''; // 地址 $province = isset($item['province']) ? trim($item['province']) : ''; $city = isset($item['city']) ? trim($item['city']) : ''; $homeProvince = isset($item['home_province']) ? trim($item['home_province']) : ''; $homeCity = isset($item['home_city']) ? trim($item['home_city']) : ''; $item['now_address'] = trim($province . ' ' . $city); $item['home_address'] = trim($homeProvince . ' ' . $homeCity); /* // 学历 $item['education'] = '无'; if (isset($item['education'])) { $educations = config('weixin.educations'); $edu = isset($item['education']) ? $item['education'] : 0; $item['education_txt'] = isset($educations[$edu]) ? $educations[$edu] : '无'; } // 地址 $item['now_address'] = '无'; if (isset($item['province'])) { $province = isset($item['province']) ? trim($item['province']) : ''; $city = isset($item['city']) ? trim($item['city']) : ''; $item['now_address'] = trim($province . ' ' . $city); } $item['home_address'] = '无'; if (isset($item['home_province'])) { $homeProvince = isset($item['home_province']) ? trim($item['home_province']) : ''; $homeCity = isset($item['home_city']) ? trim($item['home_city']) : ''; $item['home_address'] = trim($homeProvince . ' ' . $homeCity); }*/ // 格式化婚姻状况 $item['married_txt'] = '无'; if (isset($item['married'])) { $marrieds = config('weixin.marrieds'); $married = $item['married'] ? intval($item['married']) : 0; $item['married_txt'] = $married > 0 && isset($marrieds[$married - 1]) ? $marrieds[$married - 1] : '无'; } return $item; }); } /** * 获取关注我的用户列表 * @param $params * @param $pageSize * @param string $field * @return $this */ public static function getFollowUserList($userId, $params=[], $pageSize=20, $field=''){ // 验证有效时间,会员不限制 $page = input('page', 1); $where = ['uc.source_id'=> $userId,'uc.status'=> 1,'uc.type'=>1]; $cacheKey = "cache:collect:follow_".$userId.'_'.$page.'_'.md5(json_encode($params).$pageSize.$field); $dataList = PRedis::get($cacheKey); if($dataList){ return $dataList; } $field = $field? $field : 'uc.id,uc.user_id,uc.type,uc.source_id,u.real_name,u.user_nickname,u.avatar,u.sex,u.birthday,mp.graduate,mp.education,mp.height,mp.weight,mp.show_graduate,mp.show_company,mp.company,mp.occupation,mp.province,mp.city,mp.home_province,mp.home_city'; $query = UserCollect::alias('uc') ->distinct(true) ->join('user u','u.id=uc.user_id','left') ->join('user_profile mp', 'mp.userid=u.id', 'left') ->field($field) ->where($where) ->group('user_id'); $dataList = $query? $query->paginate($pageSize) ->each(function($item, $k){ $item['avatar'] = isset($item['avatar']) ? cmf_get_image_preview_url($item['avatar']) : ''; if (isset($item['birthday'])) { $birthday = isset($item['birthday']) ? $item['birthday'] : 0; $item['birthday_txt'] = $birthday ? date('Y年m月d日', $birthday) : '无'; $item['birthday_code'] = $birthday ? date('Y-m-d', $birthday) : ''; $item['birthday_day'] = $birthday ? date('y年', $birthday) : ''; } $item['height_txt'] = '无'; if (isset($item['height'])) { $height = isset($item['height']) ? intval($item['height']) : 0; $item['height_txt'] = $height ? intval($item['height']) . 'CM' : '无'; } $item['weight_txt'] = '无'; if (isset($item['weight'])) { $weight = isset($item['weight']) ? intval($item['weight']) : 0; $item['weight_txt'] = $weight ? intval($item['weight']) . 'KG' : '无'; } // 学历 $educations = config('weixin.educations'); $edu = isset($item['education']) ? $item['education'] : 0; $item['education_txt'] = $edu && isset($educations[$edu]) ? $educations[$edu] : ''; // 地址 $province = isset($item['province']) ? trim($item['province']) : ''; $city = isset($item['city']) ? trim($item['city']) : ''; $homeProvince = isset($item['home_province']) ? trim($item['home_province']) : ''; $homeCity = isset($item['home_city']) ? trim($item['home_city']) : ''; $item['now_address'] = trim($province . ' ' . $city); $item['home_address'] = trim($homeProvince . ' ' . $homeCity); /* // 学历 $item['education'] = '无'; if (isset($item['education'])) { $educations = config('weixin.educations'); $edu = isset($item['education']) ? $item['education'] : 0; $item['education_txt'] = isset($educations[$edu]) ? $educations[$edu] : '无'; } // 地址 $item['now_address'] = '无'; if (isset($item['province'])) { $province = isset($item['province']) ? trim($item['province']) : ''; $city = isset($item['city']) ? trim($item['city']) : ''; $item['now_address'] = trim($province . ' ' . $city); } $item['home_address'] = '无'; if (isset($item['home_province'])) { $homeProvince = isset($item['home_province']) ? trim($item['home_province']) : ''; $homeCity = isset($item['home_city']) ? trim($item['home_city']) : ''; $item['home_address'] = trim($homeProvince . ' ' . $homeCity); }*/ // 格式化婚姻状况 $item['married_txt'] = '无'; if (isset($item['married'])) { $marrieds = config('weixin.marrieds'); $married = $item['married'] ? intval($item['married']) : 0; $item['married_txt'] = $married > 0 && isset($marrieds[$married - 1]) ? $marrieds[$married - 1] : '无'; } return $item; }) : []; $dataList = $dataList? $dataList->toArray() : []; if($dataList){ $dataList['total'] = $query->count(); } PRedis::set($cacheKey, $dataList, 30); return $dataList; } /** * 验证是否收藏过 * @param $userId 当前有用户 * @param $sourceId 收藏对象ID * @param int $type 收藏类型:1-用户,2-活动 * @return mixed */ public static function checkCollect($userId, $sourceId, $type = 1){ $where = ['user_id'=> $userId, 'type'=> $type, 'source_id'=> $sourceId,'status'=> 1]; return UserCollect::where($where)->value('id'); } /** * 获取关注用户列表 * @param $params * @param $pageSize * @param string $field * @return $this */ public static function getActivityList($params=[], $pageSize=20, $field=''){ $where = ['uc.status'=> 1,'uc.type'=>2]; $field = $field? $field : 'uc.id,uc.user_id,uc.type,uc.source_id,a.title,a.cover_img as thumb,a.price,a.nums,a.addtime,a.starttime,a.endtime'; return UserCollect::alias('uc') ->join('activity a','a.id=uc.source_id','left') ->where($where) ->field($field) ->paginate($pageSize) ->each(function($item, $k){ $item['thumb'] = isset($item['thumb']) ? cmf_get_image_preview_url($item['thumb']) : ''; $startTime = isset($item['starttime'])? $item['starttime'] : 0; $endTime = isset($item['endtime'])? $item['endtime'] : 0; $addTime = isset($item['addtime'])? $item['addtime'] : 0; if($startTime<=time() && $endTime>= time()){ $item['act_status'] = 1; // 进行中 }else if($endTime < time()){ $item['act_status'] = 2; // 已结束 }else if($startTime>time()){ $item['act_status'] = 0; // 未开始 } $item['thumb'] = $item['thumb']? cmf_get_image_preview_url($item['thumb']) : ''; $item['publish_at'] = $addTime? date('Y-m-d H:i:s', $addTime) : date('Y-m-d H:i:s'); $item['start_at'] = $startTime? date('Y-m-d H:i:s', $startTime) : date('Y-m-d H:i:s'); $item['end_at'] = $endTime? date('Y-m-d H:i:s', $endTime) : date('Y-m-d H:i:s'); // 报名人列表和人数 $showNum = config('activity.showNum'); $showNum = $showNum? $showNum : 6; $id = isset($item['id'])? $item['id'] : 0; $result = Books::getBookList($id, $showNum); $item['book_num'] = isset($result['total'])? intval($result['total']) : 0; $item['book_list'] = isset($result['data'])? $result['data'] : []; return $item; }); } }