NoticeController.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. <?php
  2. /**
  3. * 系统设置
  4. */
  5. namespace App\Http\Controllers\Admin;
  6. use App\Http\Controllers\Controller;
  7. use App\Models\ArticleType;
  8. use Illuminate\Http\Request as Req;
  9. /**
  10. *
  11. */
  12. class NoticeController extends Controller
  13. {
  14. /**
  15. * 活动公告
  16. */
  17. function Index(Req $req)
  18. {
  19. $request['title'] = isset($req->title) ? trim($req->title) : null;
  20. $request['type'] = isset($req->type) ? trim($req->type) : null;
  21. $dt = \App\Lib\DataTable\DataTable::init();
  22. $dt->setDataSource('/admin/System/getArticle');
  23. $dt->setLang('notice');
  24. $dt->addColsFields('id', array('width' => 50));
  25. $dt->addColsFields('title', array('templet' => '#title', 'sort' => false, 'width' => 120));
  26. // $dt->addColsFields('content');
  27. $dt->addColsFields('time');
  28. $dt->addColsFields('type');
  29. // $dt->addColsFields('typebind');
  30. $dt->addColsFields('sort', array('width' => 120));
  31. $dt->addColsFields('status', array('templet' => '#closeTool', 'sort' => false, 'width' => 120));
  32. $dt->enableCheckBox();
  33. $arr[] = 'view';
  34. if (checkRriv('/admin/Notice/Edit')) {
  35. $arr[] = 'edit';
  36. }
  37. $dt->setToolBar($arr, array('width' => 140));
  38. return view('admin.systemSet/arictle', $dt->render($request));
  39. }
  40. /**
  41. * 查看
  42. */
  43. function view(Req $req)
  44. {
  45. return $this->Edit($req);
  46. }
  47. /**
  48. * 编辑
  49. */
  50. function Edit(Req $req)
  51. {
  52. $id = $req->id;
  53. if (intval($id) < 1) {
  54. abort(404);
  55. }
  56. $db = new \App\Models\Article;
  57. if (!$req->isMethod('post')) {
  58. $data = $db->getDmsg($id, 1);
  59. if (!$data) {
  60. return responseToJson($data);
  61. }
  62. $select = $data["type"];
  63. $child_id = $data["child_id"];
  64. return view('admin.systemSet/editNotice', ['select' => intval($select), 'data' => $data, "child_id" => $child_id]);
  65. } else {
  66. $data['child_id'] = $req->child_id;
  67. $data['title'] = $req->input('title');
  68. // $data['author'] = $req->input('author');
  69. $data['sort'] = $req->input('sort');
  70. $data['type'] = $req->input('type');
  71. $data['img'] = $req->input('img');
  72. $data['typebind'] = $req->input('typebind');
  73. $data['mobilecontent'] = $req->mobilecontent;
  74. $data['mobileimg'] = $req->input('mobileimg');
  75. $data['content'] = $req->desc;
  76. $res = $db->updateMsg($data, $id);
  77. $log = array(
  78. session('adminInfo.admin_name'),
  79. $data['title']
  80. );
  81. OperationLog(session('adminInfo.admin_id'), 'edit_game', $log);
  82. return responseToJson($res);
  83. }
  84. }
  85. /**
  86. * 新增公告
  87. */
  88. function addNotice(Req $req)
  89. {
  90. if (!$req->isMethod('post')) {
  91. return view('admin.systemSet/editNotice', ['select' => 0, "child_id" => 0]);
  92. } else {
  93. $data['title'] = $req->input('title');
  94. $data['img'] = $req->input('img');
  95. $data['sort'] = $req->input('sort');
  96. $data['typebind'] = $req->input('typebind');
  97. $data['mobilecontent'] = $req->mobilecontent;
  98. $data['mobileimg'] = $req->input('mobileimg');
  99. $data['type'] = $req->type;
  100. $data['child_id'] = $req->child_id;
  101. $data['content'] = $req->desc;
  102. $log = array(
  103. session('adminInfo.admin_name'),
  104. $data['title']
  105. );
  106. $data['time'] = date('Y-m-d H:i:s');
  107. $data['author'] = session('adminInfo.admin_name');
  108. $data['identity'] = UUID();
  109. $db = new \App\Models\Article;
  110. $res = $db->addNotice($data);
  111. OperationLog(session('adminInfo.admin_id'), 'add_notice', $log);
  112. return responseToJson(1);
  113. }
  114. }
  115. /**
  116. * 批量删除
  117. * [delete description]
  118. * @return [type] [description]
  119. */
  120. function delete(Req $req)
  121. {
  122. $id = $req->input('id');
  123. if (empty($id)) {
  124. return responseToJson(-2001);
  125. }
  126. $ids = explode(',', $id);
  127. if (!is_array($ids) && intval($ids) < 0) {
  128. return responseToJson(-2002);
  129. }
  130. if (is_array($ids) && count($ids) > 0) {
  131. foreach ($ids as $k => $v) {
  132. if (intval($v) < 1) {
  133. unset($ids[$k]);
  134. }
  135. }
  136. }
  137. $rows = \App\Models\Article::whereIn('id', $ids)->delete();
  138. if (!$rows) {
  139. return responseToJson(-2003);
  140. }
  141. return responseToJson(1);
  142. }
  143. function __Edit(Req $req)
  144. {
  145. $id = $req->id;
  146. if (intval($id) < 1) {
  147. abort(404);
  148. }
  149. $acticle_type = new ArticleType();
  150. $db = new \App\Models\Article;
  151. if (!$req->isMethod('post')) {
  152. $data = $db->getDmsg($id, 1);
  153. if (!$data) {
  154. return responseToJson($data);
  155. }
  156. $datas = new \App\Models\LotteryMoney();
  157. $arr = $datas->getlist();
  158. $admin = \App\Model\TypeName::getAllType();
  159. $selectdata = $acticle_type->type();
  160. $_selectdata = $this->getTree($selectdata);
  161. $select = $data["type"];
  162. $child_id = $data["child_id"];
  163. //查出优惠活动的子类
  164. $show_hui = $this->getTree($selectdata, 3);
  165. $show_hui = array_column($show_hui, "id");
  166. return view('admin.systemSet/editNotice', ['select' => intval($select), 'data' => $data, 'show_hui' => json_encode($show_hui),/*'admin'=>$admin,*/
  167. 'list' => 1, 'arr' => $arr['data'], "child_id" => $child_id, "selectdata" => $_selectdata]);
  168. } else {
  169. $data['child_id'] = $req->child_id;
  170. $data['title'] = $req->input('title');
  171. $data['author'] = $req->input('author');
  172. $data['sort'] = $req->input('sort');
  173. $data['type'] = $req->input('type');
  174. $data['img'] = $req->input('img');
  175. $data['typebind'] = $req->input('typebind');
  176. $data['mobilecontent'] = $req->mobilecontent;
  177. $data['mobileimg'] = $req->input('mobileimg');
  178. $data['content'] = $req->desc;
  179. $res = $db->updateMsg($data, $id);
  180. $log = array(
  181. session('adminInfo.admin_name'),
  182. $data['title']
  183. );
  184. OperationLog(session('adminInfo.admin_id'), 'edit_game', $log);
  185. return responseToJson($res);
  186. }
  187. }
  188. /**
  189. * 批量删除
  190. * [delete description]
  191. * @return [type] [description]
  192. */
  193. function __delete(Req $req)
  194. {
  195. $id = $req->input('id');
  196. if (empty($id)) {
  197. return responseToJson(-2001); //id������
  198. }
  199. $ids = explode(',', $id);
  200. if (!is_array($ids) && intval($ids) < 0) {
  201. return responseToJson(-2002); //id����
  202. }
  203. if (is_array($ids) && count($ids) > 0) {
  204. foreach ($ids as $k => $v) {
  205. if (intval($v) < 1) {
  206. unset($ids[$k]);
  207. }
  208. }
  209. }
  210. $rows = \App\Models\Article::whereIn('id', $ids)->delete();
  211. if (!$rows) {
  212. return responseToJson(-2003); //id����
  213. }
  214. return responseToJson(1); //id����
  215. }
  216. function __addNotice(Req $req)
  217. {
  218. $acticle_type = new ArticleType();
  219. if (!$req->isMethod('post')) {
  220. $datas = new \App\Models\LotteryMoney();
  221. $arr = $datas->getlist();
  222. // $admin = \App\Model\TypeName::getAllType();
  223. $selectdata = $acticle_type->type();
  224. //查出优惠活动的子类
  225. $show_hui = $this->getTree($selectdata, 3);
  226. $show_hui = array_column($show_hui, "id");
  227. return view('admin.systemSet/editNotice', ['select' => 0,/*'admin'=>$admin,*/
  228. 'show_hui' => json_encode($show_hui), 'arr' => $arr['data'], "child_id" => 0, "selectdata" => $this->getTree($selectdata)]);
  229. } else {
  230. $data['title'] = $req->input('title');
  231. $data['img'] = $req->input('img');
  232. $data['sort'] = $req->input('sort');
  233. $data['typebind'] = $req->input('typebind');
  234. $data['mobilecontent'] = $req->mobilecontent;
  235. $data['mobileimg'] = $req->input('mobileimg');
  236. $data['type'] = $req->type;
  237. $data['child_id'] = $req->child_id;
  238. $data['content'] = $req->desc;
  239. $log = array(
  240. session('adminInfo.admin_name'),
  241. $data['title']
  242. );
  243. $data['time'] = date('Y-m-d H:i:s');
  244. $data['author'] = session('adminInfo.admin_name');
  245. $data['identity'] = UUID();
  246. $db = new \App\Models\Article;
  247. $res = $db->addNotice($data);
  248. OperationLog(session('adminInfo.admin_id'), 'add_notice', $log);
  249. return responseToJson(1);
  250. }
  251. }
  252. public function upImg(Req $req)
  253. {
  254. if (!$req->hasFile('file')) {
  255. return responseToJson(-5050010022);
  256. }
  257. $img = $req->file('file');
  258. $newFileName = md5(time() . rand(0, 10000)) . '.' . $img->getClientOriginalExtension();
  259. if (!$img->isValid()) {
  260. return responseToJson(-5050010122);
  261. }
  262. if (file_exists(public_path('/home/img/' . date("Ym")) . $img->getClientOriginalName())) {
  263. return responseToJson(-5050012122);
  264. }
  265. $path_now = '/upload/img/' . date("Ym");
  266. $newPath = public_path($path_now);
  267. $res = $img->move($newPath, $newFileName);
  268. if ($res) {
  269. $retarr = array(
  270. 'code' => 0,
  271. 'msg' => 'success',
  272. 'data' => array(
  273. 'src' => $path_now . '/' . $newFileName,
  274. 'title' => $img->getClientOriginalName(),
  275. )
  276. );
  277. echo json_encode($retarr);
  278. } else {
  279. return responseToJson(-5050010122);
  280. }
  281. }
  282. private function __getTree($array, $pid = 0, $cen = 0)
  283. {
  284. $arr = array();
  285. $cen = ++$cen;
  286. $str = "";
  287. foreach ($array as $k => $v) {
  288. if ($v['parent_id'] == $pid) {
  289. $str = str_repeat("&nbsp;&nbsp;&nbsp;&nbsp;", $cen - 1);
  290. $arr[] = ["id" => $v["id"], "name" => ($cen - 1 ? $str . "└" . $v["cate_name"] : $v["cate_name"])];
  291. unset($array[$k]);
  292. $arr = array_merge($arr, $this->getTree($array, $v['id'], $cen));
  293. }
  294. }
  295. return $arr;
  296. }
  297. /**
  298. * 关闭游戏接口
  299. */
  300. function __activeClose(Req $req)
  301. {
  302. $status = $req->has('status') ? $req->get('status') : '';
  303. $active_id = $req->has('id') ? $req->get('id') : '';
  304. if (empty($active_id)) {
  305. return responseToJson(-5030002031);
  306. }
  307. if ($status < 0) {
  308. return responseToJson(-5030002032);
  309. }
  310. $lottery = new \App\Models\Article();
  311. $data = array(
  312. 'status' => $status,
  313. );
  314. if ($status) {
  315. $data['status'] = 1;
  316. } else {
  317. $data['status'] = '0';
  318. }
  319. $res = $lottery->closeGame(["id" => intval($active_id)], $data);
  320. return responseToJson($res);
  321. }
  322. }
  323. ?>