all(); $page_size = empty($params['page_size']) ? 10 : $params['page_size']; $keyword = $request->get("keyword"); if (is_null($keyword)) { $corp_info = Corps::orderByDesc("corp_id")->paginate($page_size); } else { $corp_info = Corps::where("corp_name", "like", "%" . $keyword . "%") ->orderByDesc("corp_id")->paginate($page_size); } $data = Api::page($corp_info); //时间戳转换 foreach ($data['data'] as $key => $val) { $data['data'][$key] = Api::dateFormat($val); } return Api::json(config('code.success'), trans('msg.success'), $data); }catch(\Exception $e) { return Api::serviceError($e); } } /** * 应用列表 * corp_id 企业ID */ public function getAppList(Request $request){ try { $res = Apps::get(); $data = json_decode($res, true); $params = $request->all(); if (empty($params['corp_id'])) { return Api::json(config('code.params_error'), trans('params.corp_id').trans('msg.params_error')); } $userInfo = $request->session()->get('userInfo'); //给超级管理员的企业ID赋值。赋予当前选中的企业ID if ($userInfo['is_admin'] == 1) { $userInfo['corp_id'] = $params['corp_id']; $request->session()->put('userInfo', $userInfo); } return Api::json(config('code.success'), trans('msg.success'), $data); }catch(\Exception $e) { return Api::serviceError($e); } } /** * 获取应用详情 * id int 活动类行ID */ public function getAppInfo(Request $request){ try { $params = $request->all(); if (empty($params['app_id'])) { return Api::json(config('code.params_error'), trans('params.app_id').trans('msg.params_error')); } $data = Apps::where('app_id', $params['app_id'])->first(); return Api::json(config('code.success'), trans('msg.success'), $data); }catch(\Exception $e) { return Api::serviceError($e); } } /** * 获取七牛上传头token */ public function getUploadToken(Request $request){ try { $accessKey = env("QINIU_ACCESS_KEY"); $secretKey = env("QINIU_SECRET_KEY"); $auth = new Auth($accessKey, $secretKey); $bucket = env("QINIU_BUCKET"); // 生成上传Token $token = $auth->uploadToken($bucket); $data['token'] = $token; return Api::json(config('code.success'), trans('msg.success'), $data); }catch(\Exception $e) { return Api::serviceError($e); } } /** * 获取活动列表 * Corp_id int() 企业ID * 2018-05-08 16:55 韩 */ public function getList(Request $request){ try { $params = $request->all(); $keys = array('corp_id'); foreach ($keys as $key) { if (empty($params[$key])) { return Api::json(config('code.params_error'), trans('params.'.$key) . trans('msg.params_error')); } } $page_size = empty($params['page_size']) ? 10 : $params['page_size']; $user_info = Session::get('userInfo'); if (isset($params['keyword']) && !empty($params['keyword'])) { $data = Activitys::where('corp_id', $params['corp_id']) ->where('status', '1') // ->where('creator', $user_info['id']) ->where('is_complete_set', '1') ->where('title', 'like', "%" . $params['keyword'] . "%") ->orderByDesc("create_time")->paginate($page_size); } else { $data = Activitys::where('corp_id', $params['corp_id']) ->where('status', '1') // ->where('creator', $user_info['id']) ->where('is_complete_set', '1') ->orderByDesc("create_time")->paginate($page_size); } $data = Api::page($data); foreach ($data['data'] as $k => $v) { //管理路由地址 $app_info = Apps::where('app_id', $v['app_id'])->first()->toArray(); $data['data'][$k]['admin_url'] = $app_info['admin_url']; //游戏路由地址 $data['data'][$k]['game_url'] = env('WEB_URL') . '/' . $app_info['app_code'] . '?activity_id=' . $v['activity_id']; } //时间戳格式化 foreach ($data['data'] as $key => $val) { $data['data'][$key] = Api::dateFormat($val); //活动状态 if ($val['start_time'] > time()) { $data['data'][$key]['activity_status_text'] = '未开始'; } elseif ($val['end_time'] < time()) { $data['data'][$key]['activity_status_text'] = '已结束'; } else { if ($val['is_temp_stop'] == 1) { $data['data'][$key]['activity_status_text'] = '已暂停'; } else { $data['data'][$key]['activity_status_text'] = '进行中'; } } } return Api::json(config('code.success'), trans('msg.success'), $data); } catch(\Exception $e) { return Api::serviceError($e); } } /** * 获取用户信息 * @param Request $request * @return string */ public function getBaseAdmin(Request $request){ $params = $request->all(); $user_info = $request->session()->get('userInfo'); if($user_info['corp_id'] != 0){ $user_info['corp_short_name'] = Corps::where('corp_id', $user_info['corp_id'])->value('corp_short_name'); } if(empty($params['app_id'])){ // $admin_vip_config = AdminVip::where('admin_id', $user_info['id']) $admin_vip_config = CorpVip::where('corp_id', $user_info['corp_id']) ->where('vip_end_time', '>', time()) ->orderByDesc('vip_level') ->first(); } else { // $admin_vip_config = AdminVip::where('admin_id', $user_info['id']) $admin_vip_config = CorpVip::where('corp_id', $user_info['corp_id']) ->where('vip_end_time', '>', time()) ->where('app_id', $params['app_id']) ->orderByDesc('vip_level') ->first(); } if(!empty($admin_vip_config)){ $vipConfig = VipConfig::where('vip_level', $admin_vip_config['vip_level'])->first(); $user_info['time_range'] = ceil(($admin_vip_config['vip_end_time']-time())/(3600*24)); $user_info['vip_name'] = $vipConfig['vip_name']; $user_info['vip_end_time'] = date('Y-m-d H:i:s', $admin_vip_config['vip_end_time']); $user_info['vip_level'] = $admin_vip_config['vip_level']; //当前用户可创建活动数和已创建且在线的活动数 $user_info['online_act_num'] = $vipConfig['online_act_num']; $user_info['new_online_act'] = Activitys::where('corp_id', $user_info['corp_id']) ->where('status', 1) ->where('end_time', '>', time()) ->where('is_complete_set', 1) ->count(); } $user_info['env'] = env('APP_ENV'); return Api::json(config('code.success'), trans('msg.success'), $user_info); } // /**2018-10-29 迁移到DdController // * 获取公告列表 // * @param Request $request // * @return string // */ // public function getMessageList(Request $request){ // $res = Messages::orderByDesc('create_time')->limit(10)->get(); // return Api::json(config('code.success'), trans('msg.success'), $res); // } } ?>