123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255 |
- <?php
- /**
- * 2018-06-25 韩
- */
-
- namespace App\Http\Controllers;
-
- use App\Http\Requests;
- use App\Models\VipConfig;
- use Illuminate\Http\Request;
-
- use DB;
- use Excel;
- use Session;
- use App\Common\Api;
- use App\Models\Activitys;
- use App\Models\Apps;
- use App\Models\Corps;
- use App\Models\AdminVip;
- use App\Models\CorpVip;
-
- use Qiniu\Auth;
-
- class ActivityController extends Controller
- {
- public function __construct(){
-
- }
-
- /**
- * 超级管理员获取企业列表
- * 2018-06-26 10:32:00
- * @param Request $request
- * @return string
- */
- public function getCorpList(Request $request){
- try {
- $params = $request->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);
- // }
- }
- ?>
|