NoticeController.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use App\Http\Controllers\Controller;
  4. use App\Http\helper\Helper;
  5. use App\Http\helper\NumConfig;
  6. use Illuminate\Http\Request;
  7. use Illuminate\Support\Facades\DB;
  8. use Illuminate\Support\Facades\Cache;
  9. use Storage;
  10. use Excel;
  11. use function GuzzleHttp\Psr7\uri_for;
  12. class NoticeController extends Controller
  13. {
  14. //系统公告列表
  15. public function systemList()
  16. {
  17. $where = ['HN_SC_NOTICE', 'SUSPENSION_NOTICE'];
  18. $list = DB::connection('write')->table('QPAccountsDB.dbo.SystemStatusInfo')->whereIn('StatusName', $where)->paginate(10);
  19. // 跑马灯
  20. //$hn_sc_notice = DB::connection('write')->table('QPAccountsDB.dbo.SystemStatusInfo')->where('StatusName', 'HN_SC_NOTICE')->first();
  21. // 停服公告
  22. //$suspension_notice = DB::connection('write')->table('QPAccountsDB.dbo.SystemStatusInfo')->where('StatusName', 'SUSPENSION_NOTICE')->first();
  23. $suspension_notice = DB::connection('write')->table('QPAccountsDB.dbo.SystemStatusInfo')->where('StatusName', 'SUSPENSION_NOTICE')->first();
  24. return view('admin.notice.system', compact('list'));
  25. }
  26. //公告发布页面
  27. public function systemAddView(Request $request)
  28. {
  29. $StatusName = $request->StatusName ?: '';
  30. if ($request->isMethod('post')) {
  31. $message = $request->input('message');
  32. if (!$message) {
  33. return $this->json(500, '必填参数不能为空');
  34. }
  35. //$time = date('Y-m-d H:i:s');
  36. //$publisher = $request->session()->get('admin')->account;//管理员信息
  37. //$result = DB::table('QPAccountsDB.dbo.SystemNotice')->insert(['publisher'=>$publisher,'message'=>$message,'created_at'=>$time]);
  38. $result = DB::table('QPAccountsDB.dbo.SystemStatusInfo')->where('StatusName', $StatusName)->update(['StatusString' => $message]);
  39. if ($result) {
  40. return $this->json(200, "发布成功");
  41. } else {
  42. return $this->json(500, '发布失败,请重试');
  43. }
  44. } else {
  45. $info = DB::table('QPAccountsDB.dbo.SystemStatusInfo')->where('StatusName', $StatusName)->first();
  46. return view('admin.notice.system_add', ['info' => $info]);
  47. }
  48. }
  49. // 修改状态
  50. public function updateStatus(Request $request)
  51. {
  52. $statusVal = $request->statusVal ?: '';
  53. $StatusName = $request->StatusName ?: '';
  54. DB::connection('write')->table('QPAccountsDB.dbo.SystemStatusInfo')->where('StatusName', $StatusName)->update(['StatusValue' => $statusVal]);
  55. return apiReturnSuc();
  56. }
  57. //版本更新列表
  58. public function versionList()
  59. {
  60. $list = DB::connection('write')->table('QPAccountsDB.dbo.VersionNumInfo')->where('del', 0)->orderBy('id', 'desc')->paginate(10);
  61. return view('admin.notice.version', ['list' => $list]);
  62. }
  63. //版本更新添加页面
  64. public function versionAddView()
  65. {
  66. return view('admin.notice.version_add');
  67. }
  68. //新增版本更新内容
  69. public function versionAdd(Request $request)
  70. {
  71. $params = $request->post();
  72. if (empty($params['message']) || empty($params['time'])) {
  73. return $this->json(500, '请填入完整信息');
  74. }
  75. $data = [
  76. 'version_number' => $params['version'],
  77. 'content' => $params['message'],
  78. 'add_time' => $params['time']
  79. ];
  80. $result = DB::table('QPAccountsDB.dbo.VersionNumInfo')->insert($data);
  81. if ($result) {
  82. return $this->json(200, "发布成功");
  83. } else {
  84. return $this->json(500, '发布失败,请重试');
  85. }
  86. }
  87. //版本更新修改页面
  88. public function versionUpdateView($id)
  89. {
  90. $version = DB::connection('write')->table('QPAccountsDB.dbo.VersionNumInfo')->select('id', 'version_number', 'content', 'add_time')->where('id', $id)->first();
  91. $version->add_time = substr($version->add_time, 0, 10);
  92. return view('admin.notice.version_update', ['version' => $version]);
  93. }
  94. //修改版本更新内容
  95. public function versionUpdate(Request $request, $id)
  96. {
  97. $params = $request->input();
  98. $params['update_time'] = date('Y-m-d H:i:s');
  99. $result = DB::table('QPAccountsDB.dbo.VersionNumInfo')->where('id', $id)->update($params);
  100. if ($result) {
  101. return $this->json(200, "修改成功");
  102. } else {
  103. return $this->json(500, '修改失败,请重试');
  104. }
  105. }
  106. //处罚公告列表
  107. public function punishList()
  108. {
  109. $list = DB::connection('write')->table('QPAccountsDB.dbo.punishInfo')->select('id', 'content', 'add_time', 'publish')->where('del', 0)->orderBy('id', 'desc')->paginate(10);
  110. return view('admin.notice.punish', ['list' => $list]);
  111. }
  112. //处罚公告添加页面
  113. public function punishAddView()
  114. {
  115. return view('admin.notice.punish_add');
  116. }
  117. //新增处罚公告
  118. public function punishAdd(Request $request)
  119. {
  120. $params = $request->post();
  121. if (!empty($params['message']) && !empty($params['time'])) {
  122. $data = [
  123. 'add_time' => $params['time'],
  124. 'Content' => $params['message']
  125. ];
  126. $result = DB::table('QPAccountsDB.dbo.punishInfo')->insert($data);
  127. if ($result) {
  128. return $this->json(200, "发布成功");
  129. } else {
  130. return $this->json(500, '发布失败,请重试');
  131. }
  132. } else {
  133. return $this->json(500, '请填入完整信息');
  134. }
  135. }
  136. //处罚公告详情,暂未使用
  137. public function punishDetail(Request $request, $id)
  138. {
  139. if (isset($params['edit'])) {
  140. $data = DB::connection('write')->table('QPAccountsDB.dbo.PunishInfo')->where('id', $params['id'])->first();
  141. if ($data) {
  142. return array('status' => true, 'msg' => '请求成功', 'data' => $data);
  143. } else {
  144. return array('status' => false, 'msg' => '请求失败,暂无数据', 'data' => []);
  145. }
  146. }
  147. $data = DB::connection('write')->table('QPAccountsDB.dbo.PunishInfo')->select('id', 'content', 'add_time')->where(['del' => 0, 'id' => $params['id']])->first();
  148. $con = [];
  149. if ($data) {
  150. $content = explode(';', str_replace("\n", '', $data->content));
  151. array_pop($content);
  152. foreach ($content as $key => $value) {
  153. $value = explode(',', $value);
  154. if (count($value) != 3) {
  155. return ['status' => false, 'message' => '请输入正确信息'];
  156. }
  157. $arr['name'] = $value[0];
  158. $arr['cause'] = $value[1];
  159. $arr['result'] = $value[2];
  160. $con[] = $arr;
  161. }
  162. $data->content = $con;
  163. return array('status' => true, 'msg' => '请求成功', 'data' => $data);
  164. } else {
  165. return array('status' => false, 'msg' => '请求失败,暂无数据', 'data' => []);
  166. }
  167. }
  168. //处罚公告修改页面
  169. public function punishUpdateView($id)
  170. {
  171. $punish = DB::connection('write')->table('QPAccountsDB.dbo.PunishInfo')->select('id', 'content', 'add_time', 'publish')->where('id', $id)->first();
  172. return view('admin.notice.punish_update', ['punish' => $punish]);
  173. }
  174. //修改处罚公告
  175. public function punishUpdate(Request $request, $id)
  176. {
  177. $params = $request->post();
  178. if (empty($params)) {
  179. $result = DB::table('QPAccountsDB.dbo.PunishInfo')->where('id', $id)->update(['publish' => 1]);
  180. } else {
  181. $result = DB::table('QPAccountsDB.dbo.PunishInfo')->where('id', $id)->update($params);
  182. }
  183. if ($result) {
  184. return $this->json(200, "修改成功");
  185. } else {
  186. return $this->json(500, '修改失败,请重试');
  187. }
  188. }
  189. public function excel(Request $request)
  190. {
  191. if ($request->isMethod('post') && $_FILES['file']) {
  192. //> 获取上传文件路径 $_FILES
  193. if ($_FILES['file']['error'] == 0) {
  194. //> 获取上传文件名称(已便于后面判断是否上传需要后缀文件)
  195. $name = $_FILES['file']['name'];
  196. //> 获取上传文件后缀 如(xls exe xlsx 等)
  197. $ext = strtolower(trim(substr($name, (strpos($name, '.') + 1))));
  198. //> 判断文件是否为指定的上传文件后缀
  199. if (!in_array($ext, array('xls', 'xlsx'))) {
  200. //> 返回上一次请求位置,并携带错误消息
  201. return redirect()->back()->withErrors('请输入xls或xlsx后缀文件')->withInput();
  202. }
  203. //> 获取文件上传路径
  204. $fileName = $_FILES['file']['tmp_name'];
  205. //> excel文件导入 上传文件
  206. Excel::load($fileName, function ($reader) {
  207. $list = $reader->get();
  208. Cache::put('excel', $list->toArray(), 1);
  209. });
  210. $list = Cache::get('excel');
  211. $str = '';
  212. foreach ($list as $key => $value) {
  213. $str .= $value[0] . ',' . $value[1] . ',' . $value[2] . ';' . "\n";
  214. }
  215. return view('admin.notice.punish_add', ['str' => $str]);
  216. }
  217. return view('admin.notice.punish_add', ['str' => '']);
  218. }
  219. }
  220. // 大厅活动公告
  221. public function hallAnnouncement(Request $request)
  222. {
  223. $list = DB::connection('write')->table('QPAccountsDB.dbo.HallNotice')
  224. ->orderByDesc('Sort')
  225. ->paginate(10);
  226. foreach ($list as &$value){
  227. $value->Title = base64_decode($value->Title);
  228. if ($value->Type == 1) $value->Content = base64_decode($value->Content);
  229. }
  230. return view('admin.notice.hall_announcement', compact('list'));
  231. }
  232. // 大厅活动公告-- 添加
  233. public function hallAnnouncementAdd(Request $request)
  234. {
  235. if ($request->isMethod('post')) {
  236. $post = $request->post();
  237. if (!empty($post['Content'])) $post['Content'] = base64_encode($post['Content']);
  238. if ($post['Type'] == 2) {
  239. if (empty($post['avatar'])) {
  240. return apiReturnFail(__('messages.admin.notice.image_required'));
  241. }
  242. $post['Content'] = $post['avatar'];
  243. $post['Abstract'] = $post['Url'];
  244. }
  245. if (empty($post['Content'])) {
  246. return apiReturnFail(__('messages.admin.notice.text_required'));
  247. }
  248. $post['Title'] = base64_encode($post['Title']);
  249. $count = DB::connection('write')->table('QPAccountsDB.dbo.HallNotice')
  250. ->count();
  251. if ($count >= 10) {
  252. return apiReturnFail(__('messages.admin.notice.max_notice_limit'));
  253. }
  254. unset($post['Url']);
  255. unset($post['avatar']);
  256. DB::connection('write')->table('QPAccountsDB.dbo.HallNotice')
  257. ->insert($post);
  258. return apiReturnSuc();
  259. }
  260. return view('admin.notice.hall_announcement_add');
  261. }
  262. // 大厅活动公告 -- 修改
  263. public function hallAnnouncementUpdate(Request $request, $id)
  264. {
  265. if ($request->isMethod('post')) {
  266. $post = $request->post();
  267. if (!empty($post['Content'])) $post['Content'] = base64_encode($post['Content']);
  268. if ($post['Type'] == 2) {
  269. if (empty($post['avatar'])) {
  270. return apiReturnFail(__('messages.admin.notice.image_required'));
  271. }
  272. $post['Content'] = $post['avatar'];
  273. $post['Abstract'] = $post['Url'];
  274. }
  275. if (empty($post['Content'])) {
  276. return apiReturnFail(__('messages.admin.notice.text_required'));
  277. }
  278. $post['LastTime'] = date('Y-m-d H:i:s');
  279. unset($post['Url']);
  280. unset($post['avatar']);
  281. $post['Title'] = base64_encode($post['Title']);
  282. DB::connection('write')->table('QPAccountsDB.dbo.HallNotice')
  283. ->where('ID', $id)
  284. ->update($post);
  285. return apiReturnSuc();
  286. }
  287. $info = DB::connection('write')->table('QPAccountsDB.dbo.HallNotice')
  288. ->where('ID', $id)
  289. ->first();
  290. $info->Title = base64_decode($info->Title);
  291. if ($info->Type == 1) $info->Content = base64_decode($info->Content);
  292. return view('admin.notice.hall_announcement_update', compact('info'));
  293. }
  294. // 大厅活动公告 -- 修改状态开关
  295. public function hallAnnouncementSwitch(Request $request, $id)
  296. {
  297. $Status = $request->Status ?: 0;
  298. $info = DB::connection('write')->table('QPAccountsDB.dbo.HallNotice')
  299. ->where('ID', $id)
  300. ->update(['Status' => $Status]);
  301. return apiReturnSuc();
  302. }
  303. // 大厅活动公告 -- 删除
  304. public function hallAnnouncementDel($id)
  305. {
  306. DB::connection('write')->table('QPAccountsDB.dbo.HallNotice')
  307. ->where('ID', $id)
  308. ->delete();
  309. return apiReturnSuc();
  310. }
  311. // 跑马灯
  312. public function horse_race_lamp()
  313. {
  314. $list = DB::connection('write')->table('QPPlatformDB.dbo.GameKindItem')
  315. ->whereIn('KindID',config('games.openKGame'))
  316. ->get();
  317. foreach ($list as &$value) {
  318. $first = DB::connection('write')->table('QPPlatformDB.dbo.RoomRunHorse')->where('GameID', $value->KindID)->select('Gap')->first();
  319. $value->Gap = isset($first->Gap) ? $first->Gap / NumConfig::NUM_VALUE : 0;
  320. }
  321. return view('admin.notice.horse_race_lamp', compact('list'));
  322. }
  323. // 跑马灯修改
  324. public function horse_race_lamp_update(Request $request, $id)
  325. {
  326. if ($request->isMethod('post')) {
  327. $post = $request->post();
  328. $list = DB::connection('write')->table('QPPlatformDB.dbo.GameRoomInfo')
  329. ->where('GameID', $id)
  330. ->select('GameID', 'SortID')
  331. ->groupBy('GameID', 'SortID')
  332. ->get();
  333. $data = [];
  334. foreach ($list as $key => $value) {
  335. $data[$key]['GameID'] = $value->GameID;
  336. $data[$key]['SortID'] = $value->SortID;
  337. $data[$key]['Gap'] = $post['Gap'] * NumConfig::NUM_VALUE;
  338. $data[$key]['Status'] = 1;
  339. }
  340. DB::connection('write')->table('QPPlatformDB.dbo.RoomRunHorse')->where('GameID', $id)->delete();
  341. DB::connection('write')->table('QPPlatformDB.dbo.RoomRunHorse')->where('GameID', $id)->insert($data);
  342. return apiReturnSuc();
  343. }
  344. $info = DB::connection('write')->table('QPPlatformDB.dbo.RoomRunHorse')->where('GameID', $id)->first();
  345. if ($info) {
  346. $info->Gap = $info->Gap / NumConfig::NUM_VALUE;
  347. }
  348. return view('admin.notice.horse_race_lamp_update', compact('info', 'id'));
  349. }
  350. }