NoticeController.php 7.7 KB

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