with('user')->orderBy('id', 'desc'); $keyword = $request->input('keyword'); if ($keyword) { $keyword = trim($keyword); $communities = $communities->where('title', 'like', '%'.$keyword.'%'); } $admin_type = $request->session()->get('admin_type'); if ($admin_type == 'paas_admin') { $paas_obj = $request->session()->get('paas_obj'); $paas_community_ids = $community->paasCommunityIds($paas_obj->id); $communities = $communities->whereIn("id", $paas_community_ids); } if(is_numeric($request->is_hot)){ $communities = $communities->where('is_hot', $request->is_hot); } $communities = $communities->paginate(); foreach ($communities as $community){ if(!empty($community->user)){ $community->user->avatar = $community->user->userAvatar(); } } return $this->success('ok', $communities); } /** * 社群详情 * @param Request $request [description] * @param Community $community [description] * @return [type] [description] */ public function community(Request $request, Community $community, CommunityGroupLink $link, CommunityGroup $group) { $admin_type = $request->session()->get('admin_type'); if ($admin_type == 'paas_admin') { $paas_obj = $request->session()->get('paas_obj'); $paas_community_ids = $community->paasCommunityIds($paas_obj->id); if (!in_array($community->id, $paas_community_ids)) { return $this->failure('没有权限访问'); } } $group_ids = $link->where('community_id', $community->id)->pluck('group_id'); $groups = $group->whereIn('id', $group_ids)->get()->toArray(); $community->user = $community->user()->where('id', $community->user_id)->first(); $community->groups = $groups; return $this->success('ok', $community); } /** * 社区群员列表 * @param Request $request [description] * @param CommunityMember $member [description] * @return [type] [description] */ public function communityMembers(Request $request, Community $community) { $admin_type = $request->session()->get('admin_type'); if ($admin_type == 'paas_admin') { $paas_obj = $request->session()->get('paas_obj'); $paas_community_ids = $community->paasCommunityIds($paas_obj->id); if (!in_array($community->id, $paas_community_ids)) { return $this->failure('没有权限访问'); } } $status = $request->input('status', 1); $members = $community->members()->with('user')->whereHas('user', function($sql){ $sql->where('id', '>', 0); })->where('status', $status); $keyword = $request->input('keyword'); if ($keyword) { $keyword = trim($keyword); $members = $members->whereHas('user', function($sql) use($keyword){ $sql->where('name', 'like', '%'.$keyword.'%') ->orWhere('mobile', 'like', '%'.$keyword.'%'); }); } $members = $members->orderBy('id', 'desc')->paginate(); return $this->success('ok', $members); } /** * 添加社群 * @param Request $request [description] * @return [type] [description] */ public function storeCommunity(Request $request, Community $community, CommunityGroupLink $link, CommunityGroup $group) { $data['logo'] = $request->input('logo'); $data['title'] = $request->input('title'); $data['intro'] = $request->input('intro'); $data['qrcode'] = $request->input('qrcode'); $data['owner_name'] = $request->input('owner_name'); $data['owner_photo'] = $request->input('owner_photo'); $data['owner_wechat'] = $request->input('owner_wechat'); $data['poster'] = $request->input('poster'); $data['poster_path'] = $request->input('poster_path'); $data['wechat_qrcode'] = $request->input('wechat_qrcode'); if($request->has('price') && $request->price){ $data['is_free'] = 0; $data['price'] = $request->price; } $user_id = $request->user_id; if(empty($user_id)){ return $this->failure('小程序用户不存在'); } $data['user_id'] = $user_id; // if (!is_numeric($data['user_id'])) { // return $this->failure('请输入群主id'); // } $community = $community->create($data); $group_ids = $request->input('group_ids', []); if ($group_ids && count($group_ids)) { $new_data = []; foreach ($group_ids as $group_id) { $data = []; $data['group_id'] = $group_id; $data['community_id'] = $community->id; $data['created_at'] = date('Y-m-d H:i:s'); $data['updated_at'] = date('Y-m-d H:i:s'); $new_data[] = $data; $group_obj = $group->where('id', $group_id)->first(); if ($group_obj) { $group_obj->increment('num', 1); } } $link->insert($new_data); } $admin_type = $request->session()->get('admin_type'); if ($admin_type == 'paas_admin') { $paas_obj = $request->session()->get('paas_obj'); PaasCommunity::firstOrCreate(['paas_id'=>$paas_obj->id, 'community_id'=>$community->id]); } return $this->success('ok', $community); } /** * 修改社群 * @param Request $request [description] * @param Community $community [description] * @return [type] [description] */ public function updateCommunity(Request $request, Community $community, CommunityGroupLink $link) { if ($request->has('logo') && $request->logo != $community->logo) { $community->logo = $request->logo; } if ($request->has('title') && $request->title != $community->title) { $community->title = $request->title; } if ($request->has('intro') && $request->intro != $community->intro) { $community->intro = $request->intro; } if ($request->has('qrcode') && $request->qrcode != $community->qrcode) { $community->qrcode = $request->qrcode; } if ($request->has('owner_name') && $request->owner_name != $community->owner_name) { $community->owner_name = $request->owner_name; } if ($request->has('owner_photo') && $request->owner_photo != $community->owner_photo) { $community->owner_photo = $request->owner_photo; } if ($request->has('owner_wechat') && $request->owner_wechat != $community->owner_wechat) { $community->owner_wechat = $request->owner_wechat; } if ($request->has("viewer_id") && $request->input('viewer_id')) { $viewer_id = $request->viewer_id; $mobile = Viewer::where('id', $viewer_id)->value('mobile'); if(empty($mobile)){ return $this->failure('该用户没有绑定手机号'); } $community->user_id = User::where('mobile', $mobile)->value('id'); } if ($request->has("poster") && $request->input('poster') != $community->poster) { $community->poster = $request->poster; } if ($request->has("poster_path") && $request->input('poster_path') != $community->poster_path) { $community->poster_path = $request->poster_path; } if ($request->has('wechat_qrcode') && $request->input('wechat_qrcode') != $community->wechat_qrcode) { $community->wechat_qrcode = $request->wechat_qrcode; } if ($request->has('is_hot') && $request->is_hot != $community->is_hot) { $community->is_hot = $request->is_hot; } $community->save(); $group_ids = $request->input('group_ids', []); if ($group_ids && count($group_ids)) { $link->where('community_id', $community->id)->delete(); $new_data = []; foreach ($group_ids as $group_id) { $data = []; $data['group_id'] = $group_id; $data['community_id'] = $community->id; $data['created_at'] = date('Y-m-d H:i:s'); $data['updated_at'] = date('Y-m-d H:i:s'); $new_data[] = $data; } $link->insert($new_data); } return $this->success('update'); } /** * 删除社群 * @param Request $request [description] * @param Community $community [description] * @return [type] [description] */ public function deleteCommunity(Request $request, Community $community) { try{ DB::beginTransaction(); $community->delete(); CommunityMoment::where('community_id', $community->id)->delete(); CommunityMember::where('community_id', $community->id)->delete(); CommunityTopic::where('community_id', $community->id)->delete(); DB::commit(); return $this->success('ok'); } catch (\Exception $e) { DB::rollback(); \Log::error($e->getMessage()); return $this->failure("系统错误"); } } /** * 审核社群成员 * @param Request $request [description] * @param CommunityMember $member [description] * @return [type] [description] */ public function checkCommunityMembers(Request $request, CommunityMember $member) { $status = $request->input('status',0); $member->status = $status; $member->reason = $request->content; $member->save(); return $this->success('ok'); } /** * 删除社群成员 * @param Request $request [description] * @param CommunityMember $member [description] * @return [type] [description] */ public function deleteCommunityMember(Request $request, CommunityMember $member) { $member->community()->decrement('member_num', 1); $member->delete(); return $this->success('ok'); } public function communityGroups(Request $request, CommunityGroup $group) { $groups = $group->withCount('communityGroupLinks')->orderBy('id', 'desc'); $admin_type = $request->session()->get('admin_type'); if ($admin_type == 'paas_admin') { $paas_obj = $request->session()->get('paas_obj'); $paas_group_ids = $group->paasGroupIds($paas_obj->id); $groups = $groups->whereIn('id', $paas_group_ids); } $keyword = $request->input('keyword'); if ($keyword) { $keyword = trim($keyword); $groups = $groups->where('title', 'like', '%'.$keyword.'%'); } $nopage = $request->input('nopage'); if ($nopage) { $groups = $groups->get(); }else{ $groups = $groups->paginate(); } return $this->success('ok', $groups); } public function stroeCommunityGroup(Request $request) { $title = $request->input('title'); if (empty($title)) { return $this->failure('请输入名称'); } $logo = $request->input('logo'); if (empty($logo)) { return $this->failure('请上传logo'); } $intro = $request->input('intro'); if (empty($intro)) { return $this->failure('请输入简介'); } $user = auth()->user(); $user_viewer_id = 0; if($user->mobile){ $user_viewer_id = Viewer::where('mobile', $user->mobile)->value('id'); } try { \DB::beginTransaction(); $group = new CommunityGroup; $group->title = $title; $group->logo = $logo; $group->intro = $intro; if($request->has('back_logo') && $request->back_logo){ $group->back_logo = $request->back_logo; }else{ $group->back_logo = $logo; } $group->save(); $id_arr = []; if($request->has('user_id') && $request->user_id){ $id_arr = $request->user_id; } $insert_arr = []; foreach ($id_arr as $item){ $insert_arr[] = [ 'group_id' => $group->id, 'viewer_id' => Viewer::where('user_id', $item)->value('id'), 'user_id' => $item, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s'), ]; } //添加群分类管理员 $admin_id = CommunityGroupAdmin::where('group_id', 0)->pluck('viewer_id')->toArray(); $new_data = []; foreach ($admin_id as $k => $item){ $new_data[$k]['viewer_id'] = $item; $new_data[$k]['user_id'] = Viewer::where('id', $item)->value('user_id'); $new_data[$k]['group_id'] = $group->id; $new_data[$k]['created_at'] = date('Y-m-d H:i:s'); $new_data[$k]['updated_at'] = date('Y-m-d H:i:s'); } $new_data = array_merge($new_data, $insert_arr); CommunityGroupAdmin::insert($new_data); \DB::commit(); return $this->success('ok', $group); } catch (\Exception $e) { //\DB::rollback(); \Log::info($e->getMessage()); return $this->failure('添加失败'); } } public function updateCommunityGroup(Request $request, CommunityGroup $group) { if ($request->has('title') && $request->input('title') != $group->title) { $group->title = $request->title; } if ($request->has('logo') && $request->input('logo') != $group->logo) { $group->logo = $request->logo; } if ($request->has('back_logo') && $request->input('back_logo') != $group->back_logo) { $group->back_logo = $request->back_logo; } if ($request->has('intro') && $request->input('intro') != $group->intro) { $group->intro = $request->intro; } try { \DB::beginTransaction(); $group->save(); if($request->has('is_show') && is_numeric($request->is_show)){ $community_ids = CommunityGroupLink::where('group_id', $group->id)->pluck('community_id')->toArray(); if($request->is_show == 0){ Community::whereIn('id', $community_ids)->where('is_hided', 0)->update(['is_hided'=> 1]); CommunityMoment::whereIn('community_id', $community_ids)->where('is_show', 1)->update(['is_show'=> 0]); }else{ Community::whereIn('id', $community_ids)->where('is_hided', 1)->update(['is_hided'=> 0]); CommunityMoment::whereIn('community_id', $community_ids)->where('is_show', 0)->update(['is_show'=> 1]); } $group->is_show = $request->is_show; $group->save(); } //添加社群管理员 $id_arr = []; if($request->has('user_id')){ $user_id = $request->user_id; $admin_ids = CommunityGroupAdmin::where('group_id', $group->id)->pluck('user_id')->toArray(); $insert_id = array_diff($user_id, $admin_ids); $del_id = array_diff($admin_ids, $user_id); if(!empty($del_id)){ CommunityGroupAdmin::where('group_id', $group->id)->whereIn('user_id', $del_id)->delete(); } if(!empty($insert_id)){ $insert_arr = []; $new_arr = []; foreach ($insert_id as $val){ $new_arr['group_id'] = $group->id; $new_arr['user_id'] = $val; $new_arr['id'] = Viewer::where('user_id', $val)->value('id'); $new_arr['created_at'] = date('Y-m-d H:i:s'); $new_arr['updated_at'] = date('Y-m-d H:i:s'); $insert_arr[] = $new_arr; } CommunityGroupAdmin::insert($insert_arr); } } \DB::commit(); return $this->success('ok', $group); } catch (\Exception $e) { \DB::rollback(); \Log::error($e->getMessage()); return $this->failure('修改失败'); } } public function communityGroup(Request $request, CommunityGroup $group) { try { $communities = $group->groupCommunities(); $group->admin = $group->admin()->orderBy('created_at', 'desc')->paginate(); return $this->success('ok', compact('group', 'communities')); } catch (\Exception $e) { $this->getError($e); return $this->failure('信息获取失败,请稍后再试'); } } //设置为所有社群管理员 public function setGroupAdmin(Request $request, $viewer_id){ $is_admin = CommunityGroupAdmin::where('viewer_id', $viewer_id)->where('group_id', 0)->count(); if($is_admin){ return $this->failure('已是所有群组管理员'); } $group_id = CommunityGroup::where('is_show', 1)->pluck('id')->toArray(); $isadmin_group_id = CommunityGroupAdmin::where('viewer_id', $viewer_id)->pluck('group_id')->toArray(); $insert_ids = array_diff($group_id, $isadmin_group_id); $insert = []; foreach ($insert_ids as $k => $insert_id){ $insert[$k]['viewer_id'] = $viewer_id; $insert[$k]['group_id'] = $insert_id; $insert[$k]['created_at'] = date('Y-m-d H:i:s'); $insert[$k]['updated_at'] = date('Y-m-d H:i:s'); } $insert[] = [ 'viewer_id' => $viewer_id, //group_id为0代表所有群管理员 'group_id' => 0, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s'), ]; CommunityGroupAdmin::insert($insert); return $this->success('ok'); } //所有群管理员列表 public function allCommunityAdmins(Request $request){ $group_admin = CommunityGroupAdmin::with('viewer'); if($request->has('keyword') && $request->keyword){ $keyword = $request->keyword; $group_admin = $group_admin->whereHas('viewer' , function($query) use ($keyword){ $query->where('nickname', 'like', '%'.$keyword.'%'); }); } $group_admin = $group_admin->where('group_id', 0)->orderBy('created_at', 'desc')->paginate(); return $this->success('ok', $group_admin); } //取消所有社群分类管理权限 public function delAllGroupAdmin(Request $request, $viewer_id){ $is_admin = CommunityGroupAdmin::where('viewer_id', $viewer_id)->where('group_id', 0)->count(); if(empty($is_admin)){ return $this->failure('该用户不是超级管理员'); } CommunityGroupAdmin::where('viewer_id', $viewer_id)->delete(); return $this->success('ok'); } public function deleteCommunityGroup(Request $request, CommunityGroup $group) { $group->delete(); return $this->success('ok'); } //设置为所有群管理员 /** * 修改社群所属分类 * @param Request $request [description] * @param CommunityGroupLink $link [description] * @return [type] [description] */ public function updateCommunityGroupLink(Request $request, Community $community, CommunityGroup $group, CommunityGroupLink $link) { $link->where(['community_id'=> $community->id, 'group_id'=>$group->id])->delete(); return $this->success('ok', $link); } /** * 群主群列表 * @param Request $request [description] * @param User $user [description] * @param Community $community [description] * @return [type] [description] */ public function groupOwnerCommunities(Request $request, User $user, Community $community) { $communities = $community->where('user_id', $user->id)->orderBy('id', 'desc')->paginate(); return $this->success('ok', compact('user', 'communities')); } /** * 社群举报列表 * @param Request $request [description] * @param Community $community [description] * @return [type] [description] */ public function communityComplaints(Request $request, CommunityComplaintHistory $complaint) { $complaints = $complaint->with('user', 'community'); $keyword = $request->input('keyword'); if ($keyword) { $keyword = trim($keyword); $complaints = $complaints->whereHas('user', function($sql) use($keyword){ $sql->where('name', 'like', '%'.$keyword.'%'); }); } $status = $request->input('status', 0); $complaints = $complaints->where('status', $status)->orderBy('id', 'desc')->paginate(); return $this->success('ok', $complaints); } /** * 标记审核 * @param Request $request [description] * @param CommunityComplaintHistory $complaint [description] * @return [type] [description] */ public function checkCommunityComplaint(Request $request, CommunityComplaintHistory $complaint) { $status = 1; $complaint->status = $status; $complaint->save(); return $this->success('ok'); } /** * 隐藏/显示 * @param Request $request [description] * @param Community $community [description] * @return [type] [description] */ public function hideCommunity(Request $request, Community $community) { if ($community->is_hided) { $community->is_hided = 0; }else{ $community->is_hided = 1; } $community->save(); return $this->success('ok'); } /** * 所有社群动态 * @param Request $request [description] * @param CommunityMoment $community_moment [description] * @return [type] [description] */ public function communitiesMoments(Request $request, CommunityMoment $community_moment) { $moments = $community_moment->with('user', 'community')->orderBy('id', 'desc')->paginate(); return $this->success('ok', $moments); } /** * 社群动态 * @param request $request [description] * @param CommunityMoment $community_moment [description] * @return [type] [description] */ public function communityMoments(Request $request, Community $community, CommunityMoment $community_moment) { try { $moments = $community_moment->with('user:id,nickname,photo,circle_avatar', 'community', 'topic')->where('community_id', $community->id); $topic_id = $request->input('topic_id'); if ($topic_id) { $moments = $moments->where('topic_id', $topic_id); } $keyword = $request->input('keyword'); if (trim($keyword)) { $moments = $moments->where('content', 'like', '%'.trim($keyword).'%'); } $moments = $moments->orderBy('id', 'desc')->paginate(); } catch (\Exception $e) { $this->getError($e); return $this->failure('信息获取失败,请稍后再试'); } return $this->success('ok', $moments); } /** * 社群动态详情 * @param Request $request [description] * @param CommunityMoment $community_moment [description] * @return [type] [description] */ public function communityMoment(Request $request, CommunityMoment $community_moment) { try { $community_moment->photos = json_decode($community_moment->photos, true); $community_moment->topic; } catch (\Exception $e) { $this->getError($e); return $this->failure('信息获取失败,请稍后再试'); } return $this->success('ok', $community_moment); } /** * 删除社群动态 * @param Request $request [description] * @param CommunityMoment $community_moment [description] * @return [type] [description] */ public function deleteCommunityMoment(Request $request, CommunityMoment $community_moment) { $community_moment->delete(); return $this->success('ok'); } /** * 社群动态举报列表 * @param Request $request [description] * @param CommunityMomentComplaint $community_moment_complaint [description] * @return [type] [description] */ public function communityMomentComplaints(Request $request, CommunityMomentComplaint $community_moment_complaint) { $complaints = $community_moment_complaint->with('user', 'communityMoment.user')->whereHas('communityMoment', function($sql){ $sql->where('id', '>', 0); })->orderBY('id', 'desc')->paginate(); return $this->success('ok', $complaints); } public function communityMomentComplaint(Request $request, CommunityMomentComplaint $community_moment_complaint) { $community_moment_complaint->pics = json_decode($community_moment_complaint->pics, true); return $this->success('ok', $community_moment_complaint); } /** * 社群话题列表 * @param Request $request 请求参数 * @param Community $community 社群 * @return json 话题列表 */ public function communityTopics(Request $request, Community $community) { try { $topics = $community->topic()->withCount('moment'); $keyword = $request->input('keyword'); if (trim($keyword)) { $topics = $topics->where('name', 'like', '%'.$keyword.'%'); } $nopage = $request->input('nopage', 0); if ($nopage) { $topics = $topics->get(); }else{ $topics = $topics->with('creater:id,nickname,name,photo,circle_avatar')->orderBy('id', 'desc')->paginate(); } return $this->success('ok', compact('community', 'topics')); } catch (\Exception $e) { $this->getError($e); return $this->failure('信息获取失败,请稍后再试'); } } /** * 话题列表 * @param Request $request 请求参数 * @param Community $community 社群 * @return json 话题列表 */ public function Topics(Request $request) { try { $topics =CommunityTopic::with('community')->withCount('moment'); $keyword = $request->input('keyword'); if (trim($keyword)) { $topics = $topics->where('name', 'like', '%'.$keyword.'%'); } $nopage = $request->input('nopage', 0); if ($nopage) { $topics = $topics->get(); }else{ $topics = $topics->with('creater:id,nickname,name,photo,circle_avatar')->orderBy('id', 'desc')->paginate(); } return $this->success('ok', $topics); } catch (\Exception $e) { $this->getError($e); return $this->failure('信息获取失败,请稍后再试'); } } /** * 删除社群话题 * @param Request $request 请求参数 * @param CommunityTopic $community_topic 话题对象 * @return [type] */ public function deleteCommunityTopic(Request $request, CommunityTopic $community_topic) { try { DB::beginTransaction(); $community_topic->delete(); CommunityMoment::where('topic_id', $community_topic->id)->delete(); DB::commit(); return $this->success('ok'); } catch (\Exception $e) { DB::rollback(); $this->getError($e); return $this->failure('操作失败,请稍后再试'); } } //创建社群 public function stroeCommunity(Request $request){ $group_id = $request->input('group_id'); if (empty($group_id)) { return $this->failure('请选择社群分类'); } $wechatUser = session('wechat.oauth_user.new'); if(empty($wechatUser)){ $openId = $request->openid; }else{ $openId = $wechatUser->getId(); } $viewer_id = Viewer::where('openid', $openId)->value('id'); $group_admin_id = CommunityGroupAdmin::where('group_id', $group_id)->pluck('viewer_id')->toArray(); if(!in_array($viewer_id, $group_admin_id)){ return $this->failure('您没有权限创建社群,请联系社群管理员'); } $data['user_id'] = $request->user->id; $data['logo'] = $request->input('logo'); if (empty($data['logo'])) { return $this->failure('请上传社群logo'); } $data['title'] = $request->input('title'); if (empty($data['title'])) { return $this->failure('请输入社群名称'); } // $data['qrcode'] = $request->input('qrcode'); // if (empty($data['qrcode'])) { // // return $this->failure("请上传群二维码"); // } $data['wechat_qrcode'] = $request->input('wechat_qrcode'); if (empty($data['wechat_qrcode'])) { // return $this->failure('请上传群主微信二维码'); } $data['poster'] = $request->input('poster'); // if (empty($poster)) { // return $this->failure('请上传社群海报'); // } $data['poster_path'] = $request->input('poster_path'); $data['intro'] = $request->input('intro'); if (empty($data['intro'])) { return $this->failure('请输入社群描述'); } if(empty($request->price)){ $data['is_free'] = 0; $data['price'] = $request->price; } $community = New Community(); $community_member = new CommunityMember(); $link = New CommunityGroupLink(); $community_obj = $community->create($data); $link_obj = $link->create(['community_id'=>$community_obj->id, 'group_id'=>$group_id]); //自动入群 $community_member->create([ 'user_id'=>$data['user_id'], 'community_id'=>$community_obj->id, 'status'=>1, ]); return $this->success('ok', $community_obj); } //申请热门推荐列表 public function communityStars(Request $request){ $stars = CommunityStar::select('id', 'is_audit', 'is_show', 'created_at', 'user_id', 'is_home', 'sign_marriage_id', 'audited_at')->with(['user', 'profile']); if($request->has('keyword') && $request->keyword){ $keyword = $request->keyword; $stars = $stars->whereHas('user', function($query) use($keyword){ $query->where('name', 'like', '%'.$keyword.'%')->orWhere('mobile', 'like', '%'.$keyword.'%'); }); } if($request->has('is_audit') && is_numeric($request->is_audit)){ $stars = $stars->where('is_audit', $request->is_audit); } if($request->has('user_id') && is_numeric($request->user_id)){ $stars = $stars->where('user_id', $request->user_id); } //热门推荐? if($request->has('is_show') && is_numeric($request->is_show)){ $stars = $stars->where('is_show', $request->is_show); } //征婚交友 if($request->has('is_home') && is_numeric($request->is_home)){ $stars = $stars->where('is_home', $request->is_home); } //是否是福恋使者 // if($request->has('is_messenger') && $request->is_messenger){ // // } $stars = $stars->orderBy('id', 'desc')->paginate(); foreach ($stars as $star){ if(!empty($star) && !empty($star->user)){ $viewer_id = Viewer::where('user_id', $star->user_id)->orWhere('mobile', $star->user->mobile)->value('id'); if(!empty($viewer_id)){ $star->is_messenger = Messenger::where('viewer_id', $viewer_id)->where('is_audit', 1)->count(); } } } return $this->success('ok', $stars); } //审核热门推荐列表 public function updateCommunityStars(Request $request){ if(!$request->has('id') || !$request->id){ return $this->failure('请输入ID'); } // try { // DB::beginTransaction(); // $id_arr = explode(',', $request->id); $id = $request->id; $update = []; if($request->has('is_audit') && is_numeric($request->is_audit)) { $update['is_audit'] = $request->is_audit; if ($request->is_audit == 1) { $update['audited_at'] = date('Y-m-d H:i:s'); } } if($request->has('is_show') && is_numeric($request->is_show)) { $update['is_show'] = $request->is_show; } if($request->has('is_home') && is_numeric($request->is_home)) { $update['is_home'] = $request->is_home; } if($request->has('sort') && is_numeric($request->sort)) { $update['sort'] = $request->sort; } CommunityStar::where('id', $id)->update($update); return $this->success('ok'); // DB::commit(); // } catch (\Exception $e) { // DB::rollback(); // $this->getError($e); // return $this->failure('操作失败,请稍后再试'); // } } //征婚数据 public function starData(Request $request){ $allCount = CommunityStar::where('is_audit', 1); if($request->has('start_time') && $request->start_time && $request->has('end_time') && $request->end_time){ $allCount = $allCount->where('created_at', 'between', [$request->start_time, $request->end_time]); } $allCount = $allCount->count(); $beginYesterday=date("Y-m-d 00:00:00"); $endYesterday=date("Y-m-d 00:00:00",strtotime("-1 day")); $yesterdayCount = CommunityStar::where('is_audit', 1)->whereBetween('created_at', [$beginYesterday, $endYesterday])->count(); return $this->success('ok', compact('allCount', 'yesterdayCount')); } }