BrainstormingController.php 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * 超级管理员-管理爱答题
  5. * User: guanxl
  6. * Date: 2018/7/4
  7. * Time: 11:45
  8. */
  9. namespace App\Http\Controllers\SuperAdmin;
  10. use App\Http\Controllers\Controller;
  11. use App\Http\Requests;
  12. use App\Models\Admin;
  13. use App\Models\BlockadeAnswer;
  14. use App\Models\Blockades;
  15. use App\Models\Categorys;
  16. use App\Models\Configs;
  17. use App\Models\Departments;
  18. use App\Models\KnowledgeRecords;
  19. use App\Models\Lotterys;
  20. use App\Models\PkAnswer;
  21. use App\Models\PkRooms;
  22. use App\Models\Prizes;
  23. use App\Models\Questions;
  24. use App\Models\Messages;
  25. use Illuminate\Http\Request;
  26. use App\Common\Api;
  27. use App\Models\Corps;
  28. use App\Models\Users;
  29. use App\Models\Apps;
  30. use App\Models\Activitys;
  31. use App\Services\ActivityService;
  32. use Illuminate\Support\Facades\Redis;
  33. use Illuminate\Support\Facades\Storage;
  34. use DB;
  35. class BrainstormingController extends Controller
  36. {
  37. /**
  38. * 爱答题企业列表
  39. * @return string
  40. */
  41. public function corpList(Request $request){
  42. $params = $request->all();
  43. $page_size = empty($params['page_size']) ? 10 : $params['page_size'];
  44. $keyword = $request->get("keyword");
  45. if (is_null($keyword)) {
  46. $corpInfos = Corps::orderBy("corp_id")->paginate($page_size);
  47. } else {
  48. $corpInfos = Corps::where("corp_name", "like", "%" . $keyword . "%")
  49. ->orderBy("corp_id")->paginate($page_size);
  50. }
  51. //数据处理
  52. foreach($corpInfos as $k=>$corpInfo){
  53. if($corpInfo['source_type'] == 'agh'){
  54. $corpInfos[$k]['source_type'] = '爱关怀';
  55. }
  56. $corpInfos[$k]['has_wesuit'] = $corpInfo['has_wesuit'] == 0 ? '未开启':'已开启';
  57. $corpInfos[$k]['activity_num'] = Activitys::where('corp_id', $corpInfo['corp_id'])->where('status', 1)->where('is_complete_set', 1)->count();
  58. }
  59. $corpInfos->withPath("list?keyword=".$keyword);
  60. return view("superadmin.brainstorming.corp_list", ['data'=>$corpInfos]);
  61. }
  62. /**
  63. * 爱答题活动列表
  64. * @return string
  65. */
  66. public function activityList(Request $request){
  67. $params = $request->all();
  68. $keyword = isset($params['keyword'])?$params['keyword']:'';
  69. $corp_id = isset($params['corp_id'])?$params['corp_id']:0;
  70. $page_size = empty($params['page_size']) ? 15 : $params['page_size'];
  71. $sql = Activitys::where('status', '1')->where('is_complete_set', '1')->orderByDesc("create_time");
  72. if(isset($params['corp_id']) && !empty($params['corp_id'])){
  73. $sql = $sql->where('corp_id', $params['corp_id']);
  74. }
  75. if (isset($params['keyword']) && !empty($params['keyword'])) {
  76. $sql = $sql->where('title', 'like', "%" . $params['keyword'] . "%");
  77. }
  78. $data = $sql->paginate($page_size);
  79. //企业信息
  80. $corpIds = $data->pluck("corp_id");
  81. $corpNames = Corps::whereIn("corp_id",$corpIds)->pluck("corp_name","corp_id");
  82. //时间戳格式化
  83. foreach ($data as $key => $val) {
  84. //活动状态
  85. if ($val['start_time'] > time()) {
  86. $data[$key]['activity_status_text'] = '未开始';
  87. } elseif ($val['end_time'] < time()) {
  88. $data[$key]['activity_status_text'] = '已结束';
  89. } else {
  90. if ($val['is_temp_stop'] == 1) {
  91. $data[$key]['activity_status_text'] = '已暂停';
  92. } else {
  93. $data[$key]['activity_status_text'] = '进行中';
  94. }
  95. }
  96. $data[$key]['start_time'] = date('Y-m-d H:i', $val['start_time']);
  97. $data[$key]['end_time'] = date('Y-m-d H:i', $val['end_time']);
  98. $data[$key]['corp_name'] = $corpNames[$val['corp_id']];
  99. //管理路由地址
  100. $app_info = Apps::where('app_id', $val['app_id'])->first()->toArray();
  101. $data[$key]['admin_url'] = $app_info['admin_url'];
  102. //游戏路由地址
  103. $data[$key]['game_url'] = env('WEB_URL') . '/' . $app_info['app_code'] . '?activity_id=' . $val['activity_id'];
  104. }
  105. //分页
  106. $data->withPath("list?keyword=".$keyword.'&corp_id='.$corp_id);
  107. return view("superadmin.brainstorming.activity_list", ['data'=>$data]);
  108. }
  109. /**
  110. * 活动新增
  111. */
  112. public function activityAdd(Request $request){
  113. $params = $request->all();
  114. $app_id = 1;
  115. $keys = array('corp_id');
  116. foreach ($keys as $key) {
  117. if (empty($params[$key])) {
  118. return Api::json(config('code.params_error'), trans('params.'.$key) . trans('msg.params_not_null'));
  119. }
  120. }
  121. // $res = ActivityService::addAct($params['corp_id'], $app_id);
  122. return redirect(env('WEB_URL')."/manage/static/index.html#/Configger?app_id=1&corp_id=".$params['corp_id']);
  123. }
  124. /**
  125. * 爱答题活动回收站
  126. */
  127. public function activityRecycle(Request $request){
  128. $params = $request->all();
  129. $keyword = isset($params['keyword'])?$params['keyword']:'';
  130. $corp_id = isset($params['corp_id'])?$params['corp_id']:0;
  131. $page_size = empty($params['page_size']) ? 15 : $params['page_size'];
  132. $sql = Activitys::where('status', '0')->where('is_complete_set', '1')->orderByDesc("create_time");
  133. if(isset($params['corp_id']) && !empty($params['corp_id'])){
  134. $sql = $sql->where('corp_id', $params['corp_id']);
  135. }
  136. if (isset($params['keyword']) && !empty($params['keyword'])) {
  137. $sql = $sql->where('title', 'like', "%" . $params['keyword'] . "%");
  138. }
  139. $data = $sql->paginate($page_size);
  140. //企业信息
  141. $corpIds = $data->pluck("corp_id");
  142. $corpNames = Corps::whereIn("corp_id",$corpIds)->pluck("corp_name","corp_id");
  143. //时间戳格式化
  144. foreach ($data as $key => $val) {
  145. $data[$key]['start_time'] = date('Y-m-d H:i', $val['start_time']);
  146. $data[$key]['end_time'] = date('Y-m-d H:i', $val['end_time']);
  147. $data[$key]['corp_name'] = $corpNames[$val['corp_id']];
  148. //管理路由地址
  149. $app_info = Apps::where('app_id', $val['app_id'])->first()->toArray();
  150. $data[$key]['admin_url'] = $app_info['admin_url'];
  151. //游戏路由地址
  152. $data[$key]['game_url'] = env('WEB_URL') . '/' . $app_info['app_code'] . '?activity_id=' . $val['activity_id'];
  153. }
  154. //分页
  155. $data->withPath("recycle?keyword=".$keyword.'&corp_id='.$corp_id);
  156. return view("superadmin.brainstorming.activity_recycle", ['data'=>$data]);
  157. }
  158. /**
  159. * 活动二维码弹框页面
  160. * @param Request $request
  161. * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  162. */
  163. public function imageUrl(Request $request){
  164. return view("superadmin.brainstorming.image_url", ['data'=>'']);
  165. }
  166. /**
  167. * 修改活动收费状态 1 免费限制人数 2 收费不限人数
  168. * @param Request $request
  169. * @return array|string
  170. */
  171. public function postChangeActivityType(Request $request){
  172. $params = $request->all();
  173. if(!isset($params['activity_id']) || empty($params['activity_id'])){
  174. return Api::json(config('code.params_error'), trans('msg.params_error'));
  175. }
  176. $activity_info = Activitys::where('activity_id', $params['activity_id'])->first();
  177. if(!$activity_info){
  178. return Api::json(config('code.fail'), trans('msg.activity_not_exist'));
  179. }
  180. $res = Activitys::where('activity_id', $params['activity_id'])->update(['activity_type'=> 2]);
  181. if($res){
  182. return Api::json(config('code.success'), trans('msg.success'));
  183. } else {
  184. Api::json(config('code.fail'), trans('msg.fail'));
  185. }
  186. return $params;
  187. }
  188. /**
  189. * 超管看板
  190. * @param Request $request
  191. * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  192. */
  193. public function board(){
  194. $data = [];
  195. $data['user_online_count'] = Redis::get('bs_online');
  196. $data['activity_active_count'] = Activitys::where('end_time', '>', time())->where('start_time', '<', time())->where('status', 1)->where('is_complete_set', 1)->count();
  197. $data['activity_active'] = Activitys::where('end_time', '>', time())->where('start_time', '<', time())->where('status', 1)->where('is_complete_set', 1)->orderByDesc('update_time')->get();
  198. $data['activity_end'] = Activitys::where('end_time', '<', time())->where('status', 1)->where('is_complete_set', 1)->orderByDesc('end_time')->limit(10)->get();
  199. foreach($data['activity_active'] as $k=>$v){
  200. $data['activity_active'][$k]['user_count'] = Users::where('activity_id', $v['activity_id'])->where('status', 1)->count();
  201. $data['activity_active'][$k]['user_join'] = Users::where('activity_id', $v['activity_id'])->where('status', 1)->where('platform', '!=', NULL)->count();
  202. $user_online = Redis::get('bs_online:'.$v['activity_id']);
  203. $data['activity_active'][$k]['user_online'] = $user_online?$user_online:0;
  204. $data['activity_active'][$k]['must_success'] = Users::where('activity_id', $v['activity_id'])->where('status', 1)->where('is_blockade_success', 1)->count();
  205. $data['activity_active'][$k]['blockade_num'] = Blockades::where('activity_id', $v['activity_id'])->count();
  206. $data['activity_active'][$k]['pk_num'] = PkRooms::where('activity_id', $v['activity_id'])->count();
  207. $data['activity_active'][$k]['corp_short_name'] = Corps::where('corp_id', $v['corp_id'])->value('corp_short_name');
  208. }
  209. foreach($data['activity_end'] as $k=>$v){
  210. $data['activity_end'][$k]['user_count'] = Users::where('activity_id', $v['activity_id'])->where('status', 1)->count();
  211. $data['activity_end'][$k]['user_join'] = Users::where('activity_id', $v['activity_id'])->where('status', 1)->where('platform', '!=', NULL)->count();
  212. $data['activity_end'][$k]['must_success']= Users::where('activity_id', $v['activity_id'])->where('status', 1)->where('is_blockade_success', 1)->count();
  213. $data['activity_end'][$k]['blockade_num']= Blockades::where('activity_id', $v['activity_id'])->count();
  214. $data['activity_end'][$k]['pk_num'] = PkRooms::where('activity_id', $v['activity_id'])->count();
  215. $data['activity_end'][$k]['corp_short_name'] = Corps::where('corp_id', $v['corp_id'])->value('corp_short_name');
  216. }
  217. $data['source'] = $_SERVER['HTTP_USER_AGENT'];
  218. return view("superadmin.brainstorming.board", ['data'=>$data]);
  219. }
  220. /**
  221. * 活动复制
  222. */
  223. public function activityCopy(Request $request){
  224. $params = $request->all();
  225. $keys = array('activity_id', 'corp_id', 'app_id');
  226. foreach ($keys as $key) {
  227. if (empty($params[$key])) {
  228. return Api::json(config('code.params_error'), trans('params.'.$key) . trans('msg.params_not_null'));
  229. }
  230. }
  231. $res = ActivityService::copyActivity($params);
  232. 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");
  233. }
  234. public function getChangeAdminIndex(Request $request){
  235. $params = $request->all();
  236. $activityId = $params['activity_id'];
  237. $activityInfo = ActivityService::getActivityInfo($activityId);
  238. $corpInfo = Corps::where('corp_id', $activityInfo['corp_id'])->first();
  239. $adminInfo = Admin::where('id', $activityInfo['creator'])->first();
  240. $data['title'] = $activityInfo['title'];
  241. $data['corp_name'] = $corpInfo['corp_name'];
  242. $data['username'] = $adminInfo['username'];
  243. $data['activity_id'] = $activityId;
  244. return view("superadmin.brainstorming.admin_change", ['data' => $data]);
  245. }
  246. /**
  247. * 活动转移
  248. * @param Request $request
  249. * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|string
  250. */
  251. public function postChangeAdmin(Request $request){
  252. $params = $request->all();
  253. $activityId = $params['activity_id'];
  254. $admin_new = $params['admin_new'];
  255. //活动信息
  256. $activityInfo = ActivityService::getActivityInfo($activityId);
  257. if(!$activityInfo){
  258. return Api::json(config('code.fail'), trans('msg.activity_not_exist'));
  259. }
  260. //新管理员信息
  261. $adminInfo = Admin::where('username', $admin_new)->where('status', 1)->first();
  262. if(!$adminInfo){
  263. return Api::json(config('code.fail'), trans('msg.admin_not_exist'));
  264. }
  265. $activity_res = Activitys::where('activity_id', $activityId)->update(['creator'=>$adminInfo['id'], 'corp_id'=>$adminInfo['corp_id']]);
  266. if($activityInfo['corp_id'] != $adminInfo['corp_id']) {
  267. $config_res = Configs::where('activity_id', $activityId)->update(['corp_id' => $adminInfo['corp_id']]);
  268. $user_res = Users::where('activity_id', $activityId)->update(['corp_id' => $adminInfo['corp_id']]);
  269. $category_res = Categorys::where('activity_id', $activityId)->update(['corp_id' => $adminInfo['corp_id']]);
  270. $question_res = Questions::where('activity_id', $activityId)->update(['corp_id' => $adminInfo['corp_id']]);
  271. $blockades_res = Blockades::where('activity_id', $activityId)->update(['corp_id' => $adminInfo['corp_id']]);
  272. $blockades_answer_res = BlockadeAnswer::where('activity_id', $activityId)->update(['corp_id' => $adminInfo['corp_id']]);
  273. $department_res = Departments::where('activity_id', $activityId)->update(['corp_id' => $adminInfo['corp_id']]);
  274. $knowledge_res = KnowledgeRecords::where('activity_id', $activityId)->update(['corp_id' => $adminInfo['corp_id']]);
  275. $pk_room_res = PkRooms::where('activity_id', $activityId)->update(['corp_id' => $adminInfo['corp_id']]);
  276. $pk_answer_res = PkAnswer::where('activity_id', $activityId)->update(['corp_id' => $adminInfo['corp_id']]);
  277. $lottery_res = Lotterys::where('activity_id', $activityId)->update(['corp_id' => $adminInfo['corp_id']]);
  278. $prize_res = Prizes::where('activity_id', $activityId)->update(['corp_id' => $adminInfo['corp_id']]);
  279. 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){
  280. return Api::json(config('code.success'), trans('msg.success'));
  281. }
  282. }
  283. if($activity_res){
  284. return Api::json(config('code.success'), trans('msg.success'));
  285. } else {
  286. return Api::json(config('code.fail'), trans('msg.sql_error'));
  287. }
  288. }
  289. /**
  290. * 公告发布
  291. * @param Request $request
  292. * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|string
  293. */
  294. public function notice(Request $request){
  295. if($request->isMethod('post')){
  296. if(!empty($_FILES['file']['tmp_name'])) {
  297. $file = $request->file('file');
  298. $name = $file->getClientOriginalName();//得到图片名;
  299. $ext = $file->getClientOriginalExtension();//得到图片后缀;
  300. $fileName = md5(uniqid($name));
  301. $fileName = $fileName.'.'.$ext;//生成新的的文件名
  302. Storage::disk('public')->put($fileName,file_get_contents($file->getRealPath()));
  303. $data = [
  304. 'src' => env('WEB_URL').'/manage/uploads/'.$fileName,
  305. 'title' => '',
  306. ];
  307. return response()->json([
  308. 'code' => 0,
  309. 'msg' => '',
  310. 'data' => $data
  311. ]);
  312. }
  313. } else {
  314. $params = $request->all();
  315. if(empty($params['message_id'])) {
  316. if(isset($params['title']) && isset($params['content'])) {
  317. //新增公告
  318. $query = [];
  319. $query['title'] = $params['title'];
  320. $query['content'] = $params['content'];
  321. $query['create_time'] = time();
  322. Messages::insert($query);
  323. return redirect('/manage/super/brainstorming/notice/list');
  324. } else {
  325. return view("superadmin.brainstorming.notice");
  326. }
  327. } else {
  328. if(isset($params['title']) && isset($params['content'])) {
  329. //编辑公告
  330. $query = [];
  331. $query['title'] = $params['title'];
  332. $query['content'] = $params['content'];
  333. Messages::where('ID', $params['message_id'])->update($query);
  334. return redirect('/manage/super/brainstorming/notice/list');
  335. } else {
  336. $data = Messages::where('ID', $params['message_id'])->where('status', 1)->first();
  337. return view("superadmin.brainstorming.notice", ['data' => $data]);
  338. }
  339. }
  340. }
  341. }
  342. /**
  343. * 公告列表
  344. * @param Request $request
  345. * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  346. */
  347. public function noticeList(Request $request){
  348. $params = $request->all();
  349. $keyword = isset($params['keyword'])?$params['keyword']:'';
  350. $page_size = empty($params['page_size']) ? 10 : $params['page_size'];
  351. if(empty($keyword)){
  352. $sql = Messages::where('status', 1);
  353. } else {
  354. $sql = Messages::where('status', 1)->where('title', 'like', "%".$keyword."%");
  355. }
  356. $data = $sql->orderByDesc('create_time')->paginate($page_size);
  357. //分页
  358. $data->withPath("list?keyword=".$keyword);
  359. return view("superadmin.brainstorming.notice_list", ['data'=>$data]);
  360. }
  361. /**
  362. * 公告删除
  363. * @param Request $request
  364. * @return string
  365. */
  366. public function noticeDelete(Request $request){
  367. $params = $request->all();
  368. if(empty($params['message_id'])){
  369. return Api::json(config('code.params_error'), trans('msg.params_error'));
  370. }
  371. $res = Messages::where('ID', $params['message_id'])->update(['status'=>0]);
  372. if($res){
  373. return Api::json(config('code.success'), trans('msg.success'));
  374. } else {
  375. return Api::json(config('code.fail'), trans('msg.sql_error'));
  376. }
  377. }
  378. }