all(); $page_size = empty($params['page_size']) ? 10 : $params['page_size']; $keyword = $request->get("keyword"); if (is_null($keyword)) { $corpInfos = Corps::orderBy("corp_id")->paginate($page_size); } else { $corpInfos = Corps::where("corp_name", "like", "%" . $keyword . "%") ->orderBy("corp_id")->paginate($page_size); } //数据处理 foreach($corpInfos as $k=>$corpInfo){ if($corpInfo['source_type'] == 'agh'){ $corpInfos[$k]['source_type'] = '爱关怀'; } $corpInfos[$k]['has_wesuit'] = $corpInfo['has_wesuit'] == 0 ? '未开启':'已开启'; $corpInfos[$k]['activity_num'] = Activitys::where('corp_id', $corpInfo['corp_id'])->where('status', 1)->where('is_complete_set', 1)->count(); } $corpInfos->withPath("corp?keyword=".$keyword); return view("superadmin.corp_manage", ['data'=>$corpInfos]); } /** * 新增企业 * @param Request $request * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|string */ public function corpAdd(Request $request){ if($request->isMethod('post')){ $params = $request->all(); $query = []; $query['corp_name'] = $params['corp_name']; $query['corp_short_name'] = $params['corp_short_name']; $query['contact_name'] = $params['contact_name']; $query['contact_phone'] = $params['contact_phone']; $query['contact_email'] = $params['contact_email']; $query['contact_address'] = $params['contact_address']; $query['update_time'] = time(); $query['create_time'] = time(); $res = Corps::insert($query); if($res){ return Api::json(config('code.success'), trans('msg.success')); } else { return Api::json(config('code.fail'), trans('msg.fail')); } } else { return view("superadmin.corp_add"); } } /** * 管理员管理 * @param Request $request * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function adminAdd(Request $request){ $params = $request->all(); if($request->isMethod('post')){ $query = []; $query['name'] = $params['name']; $query['username'] = $params['username']; $query['password'] = md5($params['password']); $query['is_admin'] = $params['is_admin']; $query['corp_id'] = $params['corp_id']; $query['status'] = 1; $query['update_time'] = time(); $query['create_time'] = time(); $userNameRepeat = Admin::where('username', $params['username'])->first(); if($userNameRepeat){ return Api::json(config('code.fail'), '账号已存在,请重新输入!'); } $res = Admin::insert($query); if($res){ return Api::json(config('code.success'), trans('msg.success')); } else { return Api::json(config('code.fail'), trans('msg.fail')); } } else { $corp_id = $params['corp_id']; $admins = Admin::where('corp_id', $corp_id)->get(); $data['corp_id'] = $corp_id; $data['admins'] = $admins; return view("superadmin.admin_add", ['data'=>$data]); } } /** * 会员设置 * @param Request $request * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|string */ public function vipSet(Request $request){ $params = $request->all(); if(isset($params['vip_time_set']) && !empty($params['vip_time_set'])){ $vipInfo = CorpVip::where('corp_id', $params['corp_id'])->first(); if($vipInfo){ CorpVip::where('corp_id', $params['corp_id'])->update(['vip_end_time'=>strtotime($params['vip_time_set']) + 3600*24 -1, 'vip_level'=>$params['vip_level']]); } else { $query = []; $query['corp_id'] = $params['corp_id']; $query['app_id'] = 1; $query['vip_level'] = $params['vip_level']; $query['vip_start_time'] = time(); $query['vip_end_time'] = strtotime($params['vip_time_set']) + 3600*24 -1; $query['update_time'] = $query['create_time'] = time(); CorpVip::insert($query); } //修改该企业已有活动的收费状态(体验版升级为其他版本时修改状态) $vipInfo = CorpVip::where('corp_id', $params['corp_id'])->first(); if($vipInfo['vip_level'] != 1){ Activitys::where('corp_id', $params['corp_id'])->where('activity_type', 1)->update(['activity_type'=>2]); } return Api::json(config('code.success'), trans('msg.success')); } else { $corpInfo = Corps::where('corp_id', $params['corp_id'])->first(); if(!$corpInfo){ return Api::json(config('code.fail'), '企业不存在'); } $vipInfo = CorpVip::where('corp_id', $params['corp_id'])->first(); $data = []; $data['corp_id'] = $params['corp_id']; $data['vipConfigs'] = VipConfig::get(); if($vipInfo) { $data['corp_name'] = $corpInfo['corp_name']; $data['vip_end_time'] = $vipInfo['vip_end_time']; $data['vip_name'] = VipConfig::where('vip_level', $vipInfo['vip_level'])->value('vip_name'); $data['online_user_num'] = VipConfig::where('vip_level', $vipInfo['vip_level'])->value('online_user_num'); } else { $data['corp_name'] = $corpInfo['corp_name']; $data['vip_name'] = '非会员'; } return view("superadmin.vip_set", ['data'=>$data]); } } }