NoticeController.php 11 KB

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