NoticeController.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. function view(Req $req){
  39. return $this->Edit($req);
  40. }
  41. function Edit(Req $req){
  42. $id = $req->id;
  43. // $id=Request::has('id')?Request::get('id'):'';
  44. if (intval($id) < 1) {
  45. abort(404);
  46. }
  47. $acticle_type = new ArticleType();
  48. $db = new \App\Models\Article;
  49. if (!$req->isMethod('post')) {
  50. $data = $db->getDmsg($id, 1);
  51. if (!$data) {
  52. return responseToJson($data);
  53. }
  54. $datas = new \App\Models\LotteryMoney();
  55. $arr = $datas->getlist();
  56. // $admin = \App\Model\TypeName::getAllType();
  57. $selectdata = $acticle_type->type();
  58. $_selectdata = $this->getTree($selectdata);
  59. $select = $data["type"];
  60. $child_id = $data["child_id"];
  61. //查出优惠活动的子类
  62. $show_hui = $this->getTree($selectdata,3);
  63. $show_hui = array_column($show_hui,"id");
  64. 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]);
  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. * [delete description]
  88. * @return [type] [description]
  89. */
  90. function delete(Req $req) {
  91. $id = $req->input('id');
  92. if (empty($id)) {
  93. return responseToJson(-2001); //id������
  94. }
  95. $ids = explode(',', $id);
  96. if (!is_array($ids) && intval($ids) < 0) {
  97. return responseToJson(-2002); //id����
  98. }
  99. if (is_array($ids) && count($ids) > 0) {
  100. foreach ($ids as $k => $v) {
  101. if (intval($v) < 1) {
  102. unset($ids[$k]);
  103. }
  104. }
  105. }
  106. $rows = \App\Models\Article::whereIn('id', $ids)->delete();
  107. if (!$rows) {
  108. return responseToJson(-2003); //id����
  109. }
  110. return responseToJson(1); //id����
  111. }
  112. function addNotice(Req $req){
  113. $acticle_type = new ArticleType();
  114. if (!$req->isMethod('post')) {
  115. $datas = new \App\Models\LotteryMoney();
  116. $arr = $datas->getlist();
  117. // $admin = \App\Model\TypeName::getAllType();
  118. $selectdata = $acticle_type->type();
  119. //查出优惠活动的子类
  120. $show_hui = $this->getTree($selectdata,3);
  121. $show_hui = array_column($show_hui,"id");
  122. 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)]);
  123. }else{
  124. $data['title'] = $req->input('title');
  125. $data['img'] = $req->input('img');
  126. $data['sort'] = $req->input('sort');
  127. $data['typebind'] = $req->input('typebind');
  128. $data['mobilecontent'] = $req->mobilecontent;
  129. $data['mobileimg'] = $req->input('mobileimg');
  130. $data['type'] =$req->type;
  131. $data['child_id'] =$req->child_id;
  132. $data['content'] = $req->desc;
  133. $log = array(
  134. session('adminInfo.admin_name'),
  135. $data['title']
  136. );
  137. $data['time'] = date('Y-m-d H:i:s');
  138. $data['author'] = session('adminInfo.admin_name');
  139. $data['identity'] = UUID();
  140. $db = new \App\Models\Article;
  141. $res = $db->addNotice($data);
  142. OperationLog(session('adminInfo.admin_id'), 'add_notice', $log);
  143. return responseToJson(1);
  144. }
  145. }
  146. function upImg(Req $req){
  147. if (!$req->hasFile('file')) {
  148. return responseToJson(-5050010022);
  149. }
  150. $img = $req->file('file');
  151. $newFileName = md5(time() . rand(0, 10000)) . '.' . $img->getClientOriginalExtension();
  152. if (!$img->isValid()) {
  153. return responseToJson(-5050010122);
  154. }
  155. if (file_exists(public_path('/home/img') . $img->getClientOriginalName())) {
  156. return responseToJson(-5050012122);
  157. }
  158. $newPath = public_path('/home/img');
  159. $res = $img->move($newPath, $img->getClientOriginalName());
  160. if ($res) {
  161. $retarr = array(
  162. 'code' => 0,
  163. 'msg' => 'success',
  164. 'data' => array(
  165. 'src' => $res->getPathname(),
  166. 'title' => $img->getClientOriginalName(),
  167. )
  168. );
  169. echo json_encode($retarr);
  170. } else {
  171. return responseToJson(-5050010122);
  172. }
  173. }
  174. private function getTree($array, $pid = 0, $cen = 0)
  175. {
  176. $arr = array();
  177. $cen = ++$cen;
  178. $str = "";
  179. foreach ($array as $k => $v) {
  180. if ($v['parent_id'] == $pid) {
  181. $str = str_repeat("&nbsp;&nbsp;&nbsp;&nbsp;", $cen - 1);
  182. $arr[] = ["id" => $v["id"], "name" => ($cen - 1 ? $str . "└" . $v["cate_name"] : $v["cate_name"])];
  183. unset($array[$k]);
  184. $arr = array_merge($arr, $this->getTree($array, $v['id'], $cen));
  185. }
  186. }
  187. return $arr;
  188. }
  189. /**
  190. * 关闭游戏接口
  191. */
  192. function activeClose(Req $req) {
  193. $status = $req->has('status') ? $req->get('status') : '';
  194. $active_id = $req->has('id') ? $req->get('id') : '';
  195. if (empty($active_id)) {
  196. return responseToJson(-5030002031);
  197. }
  198. if ($status < 0) {
  199. return responseToJson(-5030002032);
  200. }
  201. $lottery = new \App\Models\Article();
  202. $data = array(
  203. 'status' => $status,
  204. );
  205. if ($status) {
  206. $data['status'] = 1;
  207. } else {
  208. $data['status'] = '0';
  209. }
  210. $res = $lottery->closeGame(["id"=>intval($active_id)],$data );
  211. return responseToJson($res);
  212. }
  213. }
  214. ?>