title) ? trim($req->title) : null; $request['type'] = isset($req->type) ? trim($req->type) : null; $dt = \App\Lib\DataTable\DataTable::init(); $dt->setDataSource('/admin/System/getArticle'); $dt->setLang('notice'); $dt->addColsFields('id', array('width' => 50)); $dt->addColsFields('title', array('templet' => '#title', 'sort' => false, 'width' => 120)); // $dt->addColsFields('content'); $dt->addColsFields('time'); $dt->addColsFields('type'); // $dt->addColsFields('typebind'); $dt->addColsFields('sort', array('width' => 120)); $dt->addColsFields('status', array('templet' => '#closeTool', 'sort' => false, 'width' => 120)); $dt->enableCheckBox(); $arr[] = 'view'; if (checkRriv('/admin/Notice/Edit')) { $arr[] = 'edit'; } $dt->setToolBar($arr, array('width' => 140)); return view('admin.systemSet/arictle', $dt->render($request)); } /** * 查看 */ function view(Req $req) { return $this->Edit($req); } /** * 编辑 */ function Edit(Req $req) { $id = $req->id; if (intval($id) < 1) { abort(404); } $db = new \App\Models\Article; if (!$req->isMethod('post')) { $data = $db->getDmsg($id, 1); if (!$data) { return responseToJson($data); } $select = $data["type"]; $child_id = $data["child_id"]; return view('admin.systemSet/editNotice', ['select' => intval($select), 'data' => $data, "child_id" => $child_id]); } else { $data['child_id'] = $req->child_id; $data['title'] = $req->input('title'); // $data['author'] = $req->input('author'); $data['sort'] = $req->input('sort'); $data['type'] = $req->input('type'); $data['img'] = $req->input('img'); $data['typebind'] = $req->input('typebind'); $data['mobilecontent'] = $req->mobilecontent; $data['mobileimg'] = $req->input('mobileimg'); $data['content'] = $req->desc; $res = $db->updateMsg($data, $id); $log = array( session('adminInfo.admin_name'), $data['title'] ); OperationLog(session('adminInfo.admin_id'), 'edit_game', $log); return responseToJson($res); } } /** * 新增公告 */ function addNotice(Req $req) { if (!$req->isMethod('post')) { return view('admin.systemSet/editNotice', ['select' => 0, "child_id" => 0]); } else { $data['title'] = $req->input('title'); $data['img'] = $req->input('img'); $data['sort'] = $req->input('sort'); $data['typebind'] = $req->input('typebind'); $data['mobilecontent'] = $req->mobilecontent; $data['mobileimg'] = $req->input('mobileimg'); $data['type'] = $req->type; $data['child_id'] = $req->child_id; $data['content'] = $req->desc; $log = array( session('adminInfo.admin_name'), $data['title'] ); $data['time'] = date('Y-m-d H:i:s'); $data['author'] = session('adminInfo.admin_name'); $data['identity'] = UUID(); $db = new \App\Models\Article; $res = $db->addNotice($data); OperationLog(session('adminInfo.admin_id'), 'add_notice', $log); return responseToJson(1); } } /** * 批量删除 * [delete description] * @return [type] [description] */ function delete(Req $req) { $id = $req->input('id'); if (empty($id)) { return responseToJson(-2001); } $ids = explode(',', $id); if (!is_array($ids) && intval($ids) < 0) { return responseToJson(-2002); } if (is_array($ids) && count($ids) > 0) { foreach ($ids as $k => $v) { if (intval($v) < 1) { unset($ids[$k]); } } } $rows = \App\Models\Article::whereIn('id', $ids)->delete(); if (!$rows) { return responseToJson(-2003); } return responseToJson(1); } function __Edit(Req $req) { $id = $req->id; if (intval($id) < 1) { abort(404); } $acticle_type = new ArticleType(); $db = new \App\Models\Article; if (!$req->isMethod('post')) { $data = $db->getDmsg($id, 1); if (!$data) { return responseToJson($data); } $datas = new \App\Models\LotteryMoney(); $arr = $datas->getlist(); $admin = \App\Model\TypeName::getAllType(); $selectdata = $acticle_type->type(); $_selectdata = $this->getTree($selectdata); $select = $data["type"]; $child_id = $data["child_id"]; //查出优惠活动的子类 $show_hui = $this->getTree($selectdata, 3); $show_hui = array_column($show_hui, "id"); 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]); } else { $data['child_id'] = $req->child_id; $data['title'] = $req->input('title'); $data['author'] = $req->input('author'); $data['sort'] = $req->input('sort'); $data['type'] = $req->input('type'); $data['img'] = $req->input('img'); $data['typebind'] = $req->input('typebind'); $data['mobilecontent'] = $req->mobilecontent; $data['mobileimg'] = $req->input('mobileimg'); $data['content'] = $req->desc; $res = $db->updateMsg($data, $id); $log = array( session('adminInfo.admin_name'), $data['title'] ); OperationLog(session('adminInfo.admin_id'), 'edit_game', $log); return responseToJson($res); } } /** * 批量删除 * [delete description] * @return [type] [description] */ function __delete(Req $req) { $id = $req->input('id'); if (empty($id)) { return responseToJson(-2001); //id����Ϊ�� } $ids = explode(',', $id); if (!is_array($ids) && intval($ids) < 0) { return responseToJson(-2002); //id���� } if (is_array($ids) && count($ids) > 0) { foreach ($ids as $k => $v) { if (intval($v) < 1) { unset($ids[$k]); } } } $rows = \App\Models\Article::whereIn('id', $ids)->delete(); if (!$rows) { return responseToJson(-2003); //id���� } return responseToJson(1); //id���� } function __addNotice(Req $req) { $acticle_type = new ArticleType(); if (!$req->isMethod('post')) { $datas = new \App\Models\LotteryMoney(); $arr = $datas->getlist(); // $admin = \App\Model\TypeName::getAllType(); $selectdata = $acticle_type->type(); //查出优惠活动的子类 $show_hui = $this->getTree($selectdata, 3); $show_hui = array_column($show_hui, "id"); 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)]); } else { $data['title'] = $req->input('title'); $data['img'] = $req->input('img'); $data['sort'] = $req->input('sort'); $data['typebind'] = $req->input('typebind'); $data['mobilecontent'] = $req->mobilecontent; $data['mobileimg'] = $req->input('mobileimg'); $data['type'] = $req->type; $data['child_id'] = $req->child_id; $data['content'] = $req->desc; $log = array( session('adminInfo.admin_name'), $data['title'] ); $data['time'] = date('Y-m-d H:i:s'); $data['author'] = session('adminInfo.admin_name'); $data['identity'] = UUID(); $db = new \App\Models\Article; $res = $db->addNotice($data); OperationLog(session('adminInfo.admin_id'), 'add_notice', $log); return responseToJson(1); } } public function upImg(Req $req) { if (!$req->hasFile('file')) { return responseToJson(-5050010022); } $img = $req->file('file'); $newFileName = md5(time() . rand(0, 10000)) . '.' . $img->getClientOriginalExtension(); if (!$img->isValid()) { return responseToJson(-5050010122); } if (file_exists(public_path('/home/img/' . date("Ym")) . $img->getClientOriginalName())) { return responseToJson(-5050012122); } $path_now = '/upload/img/' . date("Ym"); $newPath = public_path($path_now); $res = $img->move($newPath, $newFileName); if ($res) { $retarr = array( 'code' => 0, 'msg' => 'success', 'data' => array( 'src' => $path_now . '/' . $newFileName, 'title' => $img->getClientOriginalName(), ) ); echo json_encode($retarr); } else { return responseToJson(-5050010122); } } private function __getTree($array, $pid = 0, $cen = 0) { $arr = array(); $cen = ++$cen; $str = ""; foreach ($array as $k => $v) { if ($v['parent_id'] == $pid) { $str = str_repeat("    ", $cen - 1); $arr[] = ["id" => $v["id"], "name" => ($cen - 1 ? $str . "└" . $v["cate_name"] : $v["cate_name"])]; unset($array[$k]); $arr = array_merge($arr, $this->getTree($array, $v['id'], $cen)); } } return $arr; } /** * 关闭游戏接口 */ function __activeClose(Req $req) { $status = $req->has('status') ? $req->get('status') : ''; $active_id = $req->has('id') ? $req->get('id') : ''; if (empty($active_id)) { return responseToJson(-5030002031); } if ($status < 0) { return responseToJson(-5030002032); } $lottery = new \App\Models\Article(); $data = array( 'status' => $status, ); if ($status) { $data['status'] = 1; } else { $data['status'] = '0'; } $res = $lottery->closeGame(["id" => intval($active_id)], $data); return responseToJson($res); } } ?>