123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- <?php
- /**
- * Created by PhpStorm.
- * User: gevnc
- * Date: 2018/7/3
- * Time: 17:39
- */
-
- namespace App\Http\Controllers;
-
- use App\Http\Controllers\Controller;
- use App\Models\CorpVip;
- use App\Models\VipConfig;
- use Illuminate\Http\Request;
-
- use App\Common\Api;
- use App\Models\Corps;
- use App\Models\Activitys;
- use App\Models\Admin;
-
- class SuperAdminController extends Controller
- {
- public function index(){
- return view("superadmin.index");
- }
-
- public function home(){
- return redirect("/manage/super/brainstorming/board");
- }
-
- /**
- * 企业管理
- * @param Request $request
- * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
- */
- public function corp(Request $request){
- $params = $request->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]);
- }
- }
- }
|