123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453 |
- <?php
- /**
- * Created by PhpStorm.
- * 超级管理员-管理爱答题
- * User: guanxl
- * Date: 2018/7/4
- * Time: 11:45
- */
-
- namespace App\Http\Controllers\SuperAdmin;
-
- use App\Http\Controllers\Controller;
- use App\Http\Requests;
- use App\Models\Admin;
- use App\Models\BlockadeAnswer;
- use App\Models\Blockades;
- use App\Models\Categorys;
- use App\Models\Configs;
- use App\Models\Departments;
- use App\Models\KnowledgeRecords;
- use App\Models\Lotterys;
- use App\Models\PkAnswer;
- use App\Models\PkRooms;
- use App\Models\Prizes;
- use App\Models\Questions;
- use App\Models\Messages;
- use Illuminate\Http\Request;
-
- use App\Common\Api;
- use App\Models\Corps;
- use App\Models\Users;
- use App\Models\Apps;
- use App\Models\Activitys;
- use App\Services\ActivityService;
- use Illuminate\Support\Facades\Redis;
- use Illuminate\Support\Facades\Storage;
- use DB;
-
- class BrainstormingController extends Controller
- {
- /**
- * 爱答题企业列表
- * @return string
- */
- public function corpList(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("list?keyword=".$keyword);
-
- return view("superadmin.brainstorming.corp_list", ['data'=>$corpInfos]);
- }
-
- /**
- * 爱答题活动列表
- * @return string
- */
- public function activityList(Request $request){
- $params = $request->all();
-
- $keyword = isset($params['keyword'])?$params['keyword']:'';
- $corp_id = isset($params['corp_id'])?$params['corp_id']:0;
- $page_size = empty($params['page_size']) ? 15 : $params['page_size'];
-
- $sql = Activitys::where('status', '1')->where('is_complete_set', '1')->orderByDesc("create_time");
- if(isset($params['corp_id']) && !empty($params['corp_id'])){
- $sql = $sql->where('corp_id', $params['corp_id']);
- }
-
- if (isset($params['keyword']) && !empty($params['keyword'])) {
- $sql = $sql->where('title', 'like', "%" . $params['keyword'] . "%");
- }
-
- $data = $sql->paginate($page_size);
-
- //企业信息
- $corpIds = $data->pluck("corp_id");
- $corpNames = Corps::whereIn("corp_id",$corpIds)->pluck("corp_name","corp_id");
- //时间戳格式化
- foreach ($data as $key => $val) {
- //活动状态
- if ($val['start_time'] > time()) {
- $data[$key]['activity_status_text'] = '未开始';
- } elseif ($val['end_time'] < time()) {
- $data[$key]['activity_status_text'] = '已结束';
- } else {
- if ($val['is_temp_stop'] == 1) {
- $data[$key]['activity_status_text'] = '已暂停';
- } else {
- $data[$key]['activity_status_text'] = '进行中';
- }
- }
- $data[$key]['start_time'] = date('Y-m-d H:i', $val['start_time']);
- $data[$key]['end_time'] = date('Y-m-d H:i', $val['end_time']);
- $data[$key]['corp_name'] = $corpNames[$val['corp_id']];
-
- //管理路由地址
- $app_info = Apps::where('app_id', $val['app_id'])->first()->toArray();
- $data[$key]['admin_url'] = $app_info['admin_url'];
-
- //游戏路由地址
- $data[$key]['game_url'] = env('WEB_URL') . '/' . $app_info['app_code'] . '?activity_id=' . $val['activity_id'];
- }
-
- //分页
- $data->withPath("list?keyword=".$keyword.'&corp_id='.$corp_id);
-
- return view("superadmin.brainstorming.activity_list", ['data'=>$data]);
- }
-
- /**
- * 活动新增
- */
- public function activityAdd(Request $request){
- $params = $request->all();
-
- $app_id = 1;
- $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_not_null'));
- }
- }
-
- // $res = ActivityService::addAct($params['corp_id'], $app_id);
-
- return redirect(env('WEB_URL')."/manage/static/index.html#/Configger?app_id=1&corp_id=".$params['corp_id']);
- }
-
- /**
- * 爱答题活动回收站
- */
- public function activityRecycle(Request $request){
- $params = $request->all();
-
- $keyword = isset($params['keyword'])?$params['keyword']:'';
- $corp_id = isset($params['corp_id'])?$params['corp_id']:0;
- $page_size = empty($params['page_size']) ? 15 : $params['page_size'];
-
- $sql = Activitys::where('status', '0')->where('is_complete_set', '1')->orderByDesc("create_time");
- if(isset($params['corp_id']) && !empty($params['corp_id'])){
- $sql = $sql->where('corp_id', $params['corp_id']);
- }
-
- if (isset($params['keyword']) && !empty($params['keyword'])) {
- $sql = $sql->where('title', 'like', "%" . $params['keyword'] . "%");
- }
-
- $data = $sql->paginate($page_size);
-
- //企业信息
- $corpIds = $data->pluck("corp_id");
- $corpNames = Corps::whereIn("corp_id",$corpIds)->pluck("corp_name","corp_id");
-
- //时间戳格式化
- foreach ($data as $key => $val) {
- $data[$key]['start_time'] = date('Y-m-d H:i', $val['start_time']);
- $data[$key]['end_time'] = date('Y-m-d H:i', $val['end_time']);
- $data[$key]['corp_name'] = $corpNames[$val['corp_id']];
-
- //管理路由地址
- $app_info = Apps::where('app_id', $val['app_id'])->first()->toArray();
- $data[$key]['admin_url'] = $app_info['admin_url'];
-
- //游戏路由地址
- $data[$key]['game_url'] = env('WEB_URL') . '/' . $app_info['app_code'] . '?activity_id=' . $val['activity_id'];
- }
-
- //分页
- $data->withPath("recycle?keyword=".$keyword.'&corp_id='.$corp_id);
-
- return view("superadmin.brainstorming.activity_recycle", ['data'=>$data]);
- }
-
- /**
- * 活动二维码弹框页面
- * @param Request $request
- * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
- */
- public function imageUrl(Request $request){
- return view("superadmin.brainstorming.image_url", ['data'=>'']);
- }
-
- /**
- * 修改活动收费状态 1 免费限制人数 2 收费不限人数
- * @param Request $request
- * @return array|string
- */
- public function postChangeActivityType(Request $request){
- $params = $request->all();
- if(!isset($params['activity_id']) || empty($params['activity_id'])){
- return Api::json(config('code.params_error'), trans('msg.params_error'));
- }
- $activity_info = Activitys::where('activity_id', $params['activity_id'])->first();
- if(!$activity_info){
- return Api::json(config('code.fail'), trans('msg.activity_not_exist'));
- }
-
- $res = Activitys::where('activity_id', $params['activity_id'])->update(['activity_type'=> 2]);
- if($res){
- return Api::json(config('code.success'), trans('msg.success'));
- } else {
- Api::json(config('code.fail'), trans('msg.fail'));
- }
- return $params;
- }
-
- /**
- * 超管看板
- * @param Request $request
- * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
- */
- public function board(){
- $data = [];
- $data['user_online_count'] = Redis::get('bs_online');
- $data['activity_active_count'] = Activitys::where('end_time', '>', time())->where('start_time', '<', time())->where('status', 1)->where('is_complete_set', 1)->count();
- $data['activity_active'] = Activitys::where('end_time', '>', time())->where('start_time', '<', time())->where('status', 1)->where('is_complete_set', 1)->orderByDesc('update_time')->get();
- $data['activity_end'] = Activitys::where('end_time', '<', time())->where('status', 1)->where('is_complete_set', 1)->orderByDesc('end_time')->limit(10)->get();
-
- foreach($data['activity_active'] as $k=>$v){
- $data['activity_active'][$k]['user_count'] = Users::where('activity_id', $v['activity_id'])->where('status', 1)->count();
- $data['activity_active'][$k]['user_join'] = Users::where('activity_id', $v['activity_id'])->where('status', 1)->where('platform', '!=', NULL)->count();
-
- $user_online = Redis::get('bs_online:'.$v['activity_id']);
- $data['activity_active'][$k]['user_online'] = $user_online?$user_online:0;
-
- $data['activity_active'][$k]['must_success'] = Users::where('activity_id', $v['activity_id'])->where('status', 1)->where('is_blockade_success', 1)->count();
- $data['activity_active'][$k]['blockade_num'] = Blockades::where('activity_id', $v['activity_id'])->count();
- $data['activity_active'][$k]['pk_num'] = PkRooms::where('activity_id', $v['activity_id'])->count();
- $data['activity_active'][$k]['corp_short_name'] = Corps::where('corp_id', $v['corp_id'])->value('corp_short_name');
- }
-
- foreach($data['activity_end'] as $k=>$v){
- $data['activity_end'][$k]['user_count'] = Users::where('activity_id', $v['activity_id'])->where('status', 1)->count();
- $data['activity_end'][$k]['user_join'] = Users::where('activity_id', $v['activity_id'])->where('status', 1)->where('platform', '!=', NULL)->count();
- $data['activity_end'][$k]['must_success']= Users::where('activity_id', $v['activity_id'])->where('status', 1)->where('is_blockade_success', 1)->count();
- $data['activity_end'][$k]['blockade_num']= Blockades::where('activity_id', $v['activity_id'])->count();
- $data['activity_end'][$k]['pk_num'] = PkRooms::where('activity_id', $v['activity_id'])->count();
- $data['activity_end'][$k]['corp_short_name'] = Corps::where('corp_id', $v['corp_id'])->value('corp_short_name');
- }
-
- $data['source'] = $_SERVER['HTTP_USER_AGENT'];
-
- return view("superadmin.brainstorming.board", ['data'=>$data]);
- }
-
- /**
- * 活动复制
- */
- public function activityCopy(Request $request){
- $params = $request->all();
-
- $keys = array('activity_id', 'corp_id', 'app_id');
- foreach ($keys as $key) {
- if (empty($params[$key])) {
- return Api::json(config('code.params_error'), trans('params.'.$key) . trans('msg.params_not_null'));
- }
- }
-
- $res = ActivityService::copyActivity($params);
-
- return redirect(env('WEB_URL')."/manage/static/index.html#/Gamemove?activity_id=".$res."&corp_id=".$params['corp_id']."&app_id=".$params['app_id']."&index=2");
- }
-
- public function getChangeAdminIndex(Request $request){
- $params = $request->all();
- $activityId = $params['activity_id'];
- $activityInfo = ActivityService::getActivityInfo($activityId);
- $corpInfo = Corps::where('corp_id', $activityInfo['corp_id'])->first();
- $adminInfo = Admin::where('id', $activityInfo['creator'])->first();
- $data['title'] = $activityInfo['title'];
- $data['corp_name'] = $corpInfo['corp_name'];
- $data['username'] = $adminInfo['username'];
- $data['activity_id'] = $activityId;
- return view("superadmin.brainstorming.admin_change", ['data' => $data]);
- }
-
- /**
- * 活动转移
- * @param Request $request
- * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|string
- */
- public function postChangeAdmin(Request $request){
- $params = $request->all();
-
- $activityId = $params['activity_id'];
- $admin_new = $params['admin_new'];
-
- //活动信息
- $activityInfo = ActivityService::getActivityInfo($activityId);
- if(!$activityInfo){
- return Api::json(config('code.fail'), trans('msg.activity_not_exist'));
- }
-
- //新管理员信息
- $adminInfo = Admin::where('username', $admin_new)->where('status', 1)->first();
- if(!$adminInfo){
- return Api::json(config('code.fail'), trans('msg.admin_not_exist'));
- }
-
- $activity_res = Activitys::where('activity_id', $activityId)->update(['creator'=>$adminInfo['id'], 'corp_id'=>$adminInfo['corp_id']]);
-
- if($activityInfo['corp_id'] != $adminInfo['corp_id']) {
- $config_res = Configs::where('activity_id', $activityId)->update(['corp_id' => $adminInfo['corp_id']]);
- $user_res = Users::where('activity_id', $activityId)->update(['corp_id' => $adminInfo['corp_id']]);
- $category_res = Categorys::where('activity_id', $activityId)->update(['corp_id' => $adminInfo['corp_id']]);
- $question_res = Questions::where('activity_id', $activityId)->update(['corp_id' => $adminInfo['corp_id']]);
- $blockades_res = Blockades::where('activity_id', $activityId)->update(['corp_id' => $adminInfo['corp_id']]);
- $blockades_answer_res = BlockadeAnswer::where('activity_id', $activityId)->update(['corp_id' => $adminInfo['corp_id']]);
- $department_res = Departments::where('activity_id', $activityId)->update(['corp_id' => $adminInfo['corp_id']]);
- $knowledge_res = KnowledgeRecords::where('activity_id', $activityId)->update(['corp_id' => $adminInfo['corp_id']]);
- $pk_room_res = PkRooms::where('activity_id', $activityId)->update(['corp_id' => $adminInfo['corp_id']]);
- $pk_answer_res = PkAnswer::where('activity_id', $activityId)->update(['corp_id' => $adminInfo['corp_id']]);
- $lottery_res = Lotterys::where('activity_id', $activityId)->update(['corp_id' => $adminInfo['corp_id']]);
- $prize_res = Prizes::where('activity_id', $activityId)->update(['corp_id' => $adminInfo['corp_id']]);
-
- if($config_res && $user_res && $category_res && $question_res && $blockades_res && $blockades_answer_res && $department_res && $knowledge_res && $pk_room_res && $pk_answer_res && $lottery_res && $prize_res){
- return Api::json(config('code.success'), trans('msg.success'));
- }
- }
-
- if($activity_res){
- return Api::json(config('code.success'), trans('msg.success'));
- } else {
- return Api::json(config('code.fail'), trans('msg.sql_error'));
- }
- }
-
- /**
- * 公告发布
- * @param Request $request
- * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|string
- */
- public function notice(Request $request){
- if($request->isMethod('post')){
- if(!empty($_FILES['file']['tmp_name'])) {
- $file = $request->file('file');
- $name = $file->getClientOriginalName();//得到图片名;
- $ext = $file->getClientOriginalExtension();//得到图片后缀;
-
- $fileName = md5(uniqid($name));
- $fileName = $fileName.'.'.$ext;//生成新的的文件名
- Storage::disk('public')->put($fileName,file_get_contents($file->getRealPath()));
-
- $data = [
- 'src' => env('WEB_URL').'/manage/uploads/'.$fileName,
- 'title' => '',
- ];
- return response()->json([
- 'code' => 0,
- 'msg' => '',
- 'data' => $data
- ]);
- }
- } else {
- $params = $request->all();
- if(empty($params['message_id'])) {
- if(isset($params['title']) && isset($params['content'])) {
- //新增公告
- $query = [];
- $query['title'] = $params['title'];
- $query['content'] = $params['content'];
- $query['create_time'] = time();
-
- Messages::insert($query);
-
- return redirect('/manage/super/brainstorming/notice/list');
- } else {
- return view("superadmin.brainstorming.notice");
- }
- } else {
- if(isset($params['title']) && isset($params['content'])) {
- //编辑公告
- $query = [];
- $query['title'] = $params['title'];
- $query['content'] = $params['content'];
-
- Messages::where('ID', $params['message_id'])->update($query);
-
- return redirect('/manage/super/brainstorming/notice/list');
- } else {
- $data = Messages::where('ID', $params['message_id'])->where('status', 1)->first();
- return view("superadmin.brainstorming.notice", ['data' => $data]);
- }
- }
- }
- }
-
- /**
- * 公告列表
- * @param Request $request
- * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
- */
- public function noticeList(Request $request){
- $params = $request->all();
-
- $keyword = isset($params['keyword'])?$params['keyword']:'';
- $page_size = empty($params['page_size']) ? 10 : $params['page_size'];
-
- if(empty($keyword)){
- $sql = Messages::where('status', 1);
- } else {
- $sql = Messages::where('status', 1)->where('title', 'like', "%".$keyword."%");
- }
-
- $data = $sql->orderByDesc('create_time')->paginate($page_size);
-
- //分页
- $data->withPath("list?keyword=".$keyword);
-
- return view("superadmin.brainstorming.notice_list", ['data'=>$data]);
- }
-
- /**
- * 公告删除
- * @param Request $request
- * @return string
- */
- public function noticeDelete(Request $request){
- $params = $request->all();
-
- if(empty($params['message_id'])){
- return Api::json(config('code.params_error'), trans('msg.params_error'));
- }
-
- $res = Messages::where('ID', $params['message_id'])->update(['status'=>0]);
- if($res){
- return Api::json(config('code.success'), trans('msg.success'));
- } else {
- return Api::json(config('code.fail'), trans('msg.sql_error'));
- }
- }
- }
|