Commit 1c2c3f0e authored by clone's avatar clone

banner模块

parent 0189db8f
...@@ -5,6 +5,7 @@ namespace app\api\controller; ...@@ -5,6 +5,7 @@ namespace app\api\controller;
use app\api\extend\Basic; use app\api\extend\Basic;
use app\model\AttentionModel; use app\model\AttentionModel;
use think\Request; use think\Request;
use app\model\HouseImgs;
/** /**
* Created by PhpStorm. * Created by PhpStorm.
...@@ -17,11 +18,13 @@ class AttentionShop extends Basic ...@@ -17,11 +18,13 @@ class AttentionShop extends Basic
{ {
protected $attentionModel; protected $attentionModel;
protected $dbImg;
public function __construct($request = null) public function __construct($request = null)
{ {
parent::__construct($request); parent::__construct($request);
$this->attentionModel = new AttentionModel(); $this->attentionModel = new AttentionModel();
$this->dbImg = new HouseImgs();
} }
/** /**
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
define('IMG_PATH','https://admin.tonglianjituan.com/houseImg/'); define('IMG_PATH','https://admin.tonglianjituan.com/houseImg/');
define('LOCAL_IMG_HOST','/resource/lib/Attachments/');
return [ return [
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 应用设置 // | 应用设置
......
...@@ -32,7 +32,8 @@ class Banner extends Basic ...@@ -32,7 +32,8 @@ class Banner extends Basic
return view("banner/banner"); return view("banner/banner");
} }
public function getBannerList(){ public function getBannerList()
{
$field = "id,title,pic_path,url,sort,hits,is_show,up_user,create_time,update_time"; $field = "id,title,pic_path,url,sort,hits,is_show,up_user,create_time,update_time";
$params['is_show'] = array( "eq", 0 ); $params['is_show'] = array( "eq", 0 );
$pageNo = empty($_POST['pageNo']) ? 1 : $_POST['pageNo']; $pageNo = empty($_POST['pageNo']) ? 1 : $_POST['pageNo'];
...@@ -54,15 +55,43 @@ class Banner extends Basic ...@@ -54,15 +55,43 @@ class Banner extends Basic
/* $params = array( /* $params = array(
"id" => 2, "id" => 2,
"is_show" => 0 "is_show" => 0
); );*/
$msg = isset($params['id']) ? "修改" : "新增"; if (isset($_POST["id"])) {
$params["id"] = $_POST["id"];
}
if (isset($_POST["title"])) {
$params["title"] = $_POST["title"];
}
if (isset($_POST["url"])) {
$params["url"] = $_POST["url"];
}
if (isset($_POST["cover_image"])) {
$params["cover_image"] = $_POST["cover_image"];
}
if (isset($_POST["sort"])) {
$params["sort"] = $_POST["sort"];
}
if (isset($_POST["is_show"])) {
$params["is_show"] = $_POST["is_show"];
}
if (empty($params["title"]) || empty($params["url"]) || empty($params["cover_image"]) || empty($params["sort"])) {
return $this->response("101", "请提交正确的请求参数");
}
if (isset($params['id'])) {
$msg = "修改";
} else {
$msg = "新增";
$params["is_show"] = 0;
}
$result = $this->bannerModel->addOrUpdate($params); $result = $this->bannerModel->addOrUpdate($params);
if ($result['code'] == 200) { if ($result['code'] == 200) {
return $this->response("200", $msg . "成功", $result["msg"]); return $this->response("200", $msg . "成功", $result["msg"]);
} else { } else {
return $this->response("101", $msg . $result["msg"]); return $this->response("101", $msg . $result["msg"]);
}*/
} }
}
/** /**
* 修改是否显示 * 修改是否显示
...@@ -70,15 +99,15 @@ class Banner extends Basic ...@@ -70,15 +99,15 @@ class Banner extends Basic
*/ */
public function upIsShow() public function upIsShow()
{ {
/* $params = array( $params = array(
"id" => 1, "id" => $_POST["id"],
"is_show" => 1 "is_show" => $_POST["is_show"]
); );
$result = $this->bannerModel->upIsShow($params); $result = $this->bannerModel->upIsShow($params);
if ($result['code'] == 200) { if ($result['code'] == 200) {
return $this->response("200", "update success", $result["msg"]); return $this->response("200", "update success", $result["msg"]);
} else { } else {
return $this->response("101", "update error"); return $this->response("101", "update error");
}*/ }
} }
} }
\ No newline at end of file
...@@ -39,8 +39,8 @@ class BannerModel extends Model ...@@ -39,8 +39,8 @@ class BannerModel extends Model
if (isset($param['title'])) { if (isset($param['title'])) {
$arr["title"] = $param['title']; $arr["title"] = $param['title'];
} }
if (isset($param['pic_path'])) { if (isset($param['cover_image'])) {
$arr["pic_path"] = $param['pic_path']; $arr["pic_path"] = $param['cover_image'];
} }
if (isset($param['url'])) { if (isset($param['url'])) {
$arr["url"] = $param['url']; $arr["url"] = $param['url'];
...@@ -48,13 +48,13 @@ class BannerModel extends Model ...@@ -48,13 +48,13 @@ class BannerModel extends Model
if (isset($param['sort'])) { if (isset($param['sort'])) {
$arr["sort"] = $param['sort']; $arr["sort"] = $param['sort'];
} }
if (isset($param['title'])) { if (isset($param['is_show'])) {
$arr["is_show"] = $param['is_show']; $arr["is_show"] = $param['is_show'];
} }
$saveWhere = array(); $saveWhere = array();
if (isset($param['id'])) { if (isset($param['id'])) {
$result = $this->db $result = $this
->where("id=" . $param['id']) ->where("id=" . $param['id'])
->select(); ->select();
if (count($result) > 0) { if (count($result) > 0) {
...@@ -63,15 +63,19 @@ class BannerModel extends Model ...@@ -63,15 +63,19 @@ class BannerModel extends Model
return [ "code" => "101", "msg" => "数据不存在" ]; return [ "code" => "101", "msg" => "数据不存在" ];
} }
} else { } else {
$arr["create_time"] = date("Y-m-d H:i:s",time()); $arr["create_time"] = date("Y-m-d H:i:s", time());
$arr["update_time"] = date("Y-m-d H:i:s",time()); $arr["update_time"] = date("Y-m-d H:i:s", time());
} }
//todo 暂时未做登陆页
$arr["up_user"] = "admin";
Db::startTrans(); Db::startTrans();
try { try {
if(isset( $saveWhere["id"])){
$id = $banner->save($arr,$saveWhere); if (isset($saveWhere["id"])) {
}else{ $id = $this->save($arr, $saveWhere);
$id = $banner->save($arr); } else {
//print_r($arr);exit;
$id = $this->save($arr);
} }
Db::commit(); Db::commit();
return [ "code" => "200", "msg" => $id ]; return [ "code" => "200", "msg" => $id ];
...@@ -92,11 +96,11 @@ class BannerModel extends Model ...@@ -92,11 +96,11 @@ class BannerModel extends Model
$banner = $this->db; $banner = $this->db;
$arr = array( $arr = array(
"is_show" => $param['is_show'], "is_show" => $param['is_show'],
"update_time" =>date("Y-m-d H:i:s",time()) "update_time" => date("Y-m-d H:i:s", time())
); );
Db::startTrans(); Db::startTrans();
try { try {
$id = $banner->save($arr,["id"=>$param["id"]]); $id = $this->save($arr, [ "id" => $param["id"] ]);
Db::commit(); Db::commit();
return [ "code" => "200", "msg" => $id ]; return [ "code" => "200", "msg" => $id ];
} catch (\Exception $e) { } catch (\Exception $e) {
...@@ -130,7 +134,8 @@ class BannerModel extends Model ...@@ -130,7 +134,8 @@ class BannerModel extends Model
* @param $params * @param $params
* @return int|string * @return int|string
*/ */
function getBannerTotal($params){ function getBannerTotal($params)
{
return $this->db return $this->db
->where($params) ->where($params)
->count(); ->count();
......
...@@ -56,8 +56,16 @@ Route::group('index', [ ...@@ -56,8 +56,16 @@ Route::group('index', [
'consumer_list' => [ 'index/member.index/consumer_list', [ 'method' => 'get' ] ], 'consumer_list' => [ 'index/member.index/consumer_list', [ 'method' => 'get' ] ],
'diagram_list' => [ 'index/member.index/diagram_list', [ 'method' => 'get' ] ], 'diagram_list' => [ 'index/member.index/diagram_list', [ 'method' => 'get' ] ],
'entrust_list' => [ 'index/member.index/entrust_list', [ 'method' => 'get' ] ], 'entrust_list' => [ 'index/member.index/entrust_list', [ 'method' => 'get' ] ],
//banner模块
'banner' => [ 'index/banner/index', [ 'method' => 'get' ] ], 'banner' => [ 'index/banner/index', [ 'method' => 'get' ] ],
'bannerList' => [ 'index/banner/getBannerList', [ 'method' => 'post' ] ], 'bannerList' => [ 'index/banner/getBannerList', [ 'method' => 'post' ] ],
'addOrSave' => [ 'index/banner/addOrSave', [ 'method' => 'post' ] ],
'upIsShow' => [ 'index/banner/upIsShow', [ 'method' => 'post' ] ],
'usersList' => ['index/member/getUserList',['method'=>'get']], 'usersList' => ['index/member/getUserList',['method'=>'get']],
'users_list'=> ['index/member/index'] 'users_list'=> ['index/member/index']
]); ]);
......
...@@ -5,7 +5,7 @@ define (['doT', 'text!temp/banner_template_tpl.html', 'ckfinder', 'ckfinderStart ...@@ -5,7 +5,7 @@ define (['doT', 'text!temp/banner_template_tpl.html', 'ckfinder', 'ckfinderStart
var banner = { var banner = {
pageNo: 1, /*第几页*/ pageNo: 1, /*第几页*/
pageSize: 15, /*每页显示多少条*/ pageSize: 15, /*每页显示多少条*/
datas: "",
init: function () { init: function () {
//初始化dot //初始化dot
$ ("body").append (template); $ ("body").append (template);
...@@ -18,10 +18,53 @@ define (['doT', 'text!temp/banner_template_tpl.html', 'ckfinder', 'ckfinderStart ...@@ -18,10 +18,53 @@ define (['doT', 'text!temp/banner_template_tpl.html', 'ckfinder', 'ckfinderStart
BrowseServer ('cover_image'); BrowseServer ('cover_image');
}); });
$ ('#modal-add-do').on ('show.bs.modal', function () {
$ ("#editor_modal_title").html ("编辑广告");
});
$ ("#save_banner").click (function () { $ ("#save_banner").click (function () {
banner.addBanner (); var params = {};
params.title = $ ("#title").val ();
params.url = $ ("#url").val ();
params.cover_image = $ ("#cover_image").val ();
params.sort = $ ("#sort").val ();
if (!params.title || params.title == null) {
alert ("banner名称不能为空");
return false;
}
if (!params.url || params.url == null) {
alert ("url不能为空");
return false;
}
if (!params.cover_image || params.cover_image == null) {
alert ("banner图片不能为空");
return false;
}
if (!params.sort || params.sort == null) {
alert ("banner排序不能为空");
return false;
}
if ($ ("#id").val ()) {
params.id = $ ("#id").val ();
}
banner.addOrUpdateBanner (params);
});
$("#confirm_delete").click(function(){
var params = {};
params.id = $ ("#delete_id").val ();
params.is_show = 1;
banner.deleteBanner(params);
}); });
/* $(document).delegate(".modal_editor", "click", function () {
console.log(11111111);
});*/
}, },
/*获取banner list*/ /*获取banner list*/
getBannerList: function (pageNo) { getBannerList: function (pageNo) {
...@@ -32,7 +75,7 @@ define (['doT', 'text!temp/banner_template_tpl.html', 'ckfinder', 'ckfinderStart ...@@ -32,7 +75,7 @@ define (['doT', 'text!temp/banner_template_tpl.html', 'ckfinder', 'ckfinderStart
params.pageSize = banner.pageSize; params.pageSize = banner.pageSize;
$.ajax ({ $.ajax ({
url: '/index/bannerList', url: '/admin.php/index/bannerList',
type: 'POST', type: 'POST',
async: true, async: true,
data: params, data: params,
...@@ -54,20 +97,58 @@ define (['doT', 'text!temp/banner_template_tpl.html', 'ckfinder', 'ckfinderStart ...@@ -54,20 +97,58 @@ define (['doT', 'text!temp/banner_template_tpl.html', 'ckfinder', 'ckfinderStart
} }
}) });
}, },
addBanner: function () { addOrUpdateBanner: function (params) {
var params = {}; $.ajax ({
params.title = $ ("#title").val (); url: '/admin.php/index/addOrSave',
params.intro = $ ("#intro").val (); type: 'POST',
params.url = $ ("#url").val (); async: true,
params.cover_image = $ ("#cover_image").val (); data: params,
params.sort = $ ("#sort").val (); dataType: 'json',
if (empty (params.title)) { success: function (data) {
$ ("#modal-add-do").modal ('hide');
if (data.code == "101") {
alert (data.msg);
return false;
}
banner.getBannerList (banner.pageNo);
}
});
},
deleteBanner : function(params){
$.ajax ({
url: '/admin.php/index/upIsShow',
type: 'POST',
async: true,
data: params,
dataType: 'json',
success: function (data) {
$ ("#modal-delete").modal ('hide');
if (data.code == "101") {
alert (data.msg);
return false;
}
banner.getBannerList (banner.pageNo);
} }
});
} }
}; };
return banner return banner
}); });
function confirms (obj) {
var item = $ (obj).parents ("tr").find ("td");
$ ("#id").val ($ (obj).attr ("data-id"));
$ ("#title").val (item.eq (0).html ());
$ ("#url").val (item.eq (2).html ());
$ ("#cover_image").val (item.eq (1).find ("input").val ());
$ ("#sort").val (item.eq (3).html ());
}
function delete_banner (obj) {
$ ("#delete_id").val ($ (obj).attr ("data-id"));
}
<script id="banner_list_tpl" type="text/template"> <script id="banner_list_tpl" type="text/template">
[% if( it ) { %] [% if( it ) { %]
[% for(var item in it){ %] [% for(var item in it){ %]
<tr> <tr >
<td>[%= it[item]["title"] %]</td> <td>[%= it[item]["title"] %]</td>
<td> <td>
<img src="[%= it[item]['pic_path'] %]" class="diagram-image"> <input type="hidden" value='[%= it[item]["pic_path"] %]'>
<img src='/resource/lib/Attachments/[%= it[item]["pic_path"] %]' class="diagram-image" >
</td> </td>
<td>[%= it[item]["url"] %]</td> <td>[%= it[item]["url"] %]</td>
<td>[%= it[item]["sort"] %]</td> <td>[%= it[item]["sort"] %]</td>
<td>[%= it[item]["hits"] %]</td> <td>[%= it[item]["hits"] %]</td>
<td>[%= it[item]["up_user"] %]</td> <td>[%= it[item]["up_user"] %]</td>
<td> <td>
<a class="btn1 btn-success " href="#modal-do" data-toggle="modal"> <a class="btn1 btn-success " href="#modal-add-do" data-toggle="modal" onclick="confirms(this)" data-id="[%= it[item]['id'] %]" >
编辑 编辑
</a> </a>
<a class="btn1 btn-danger " href="#modal-delete" data-toggle="modal"> <a class="btn1 btn-danger " href="#modal-delete" data-toggle="modal" onclick="delete_banner(this)" data-id="[%= it[item]['id'] %]">
删除 删除
</a> </a>
</td> </td>
...@@ -42,13 +43,14 @@ ...@@ -42,13 +43,14 @@
</div> </div>
<div class="modal-body"> <div class="modal-body">
<div class="modal-body"> <div class="modal-body">
<input type="hidden" value="" id="delete_id"/>
确认删除吗? 确认删除吗?
</div> </div>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">关闭 <button type="button" class="btn btn-default" data-dismiss="modal">关闭
</button> </button>
<button type="button" class="btn btn-primary"> <button type="button" class="btn btn-primary" id="confirm_delete">
删除 删除
</button> </button>
</div> </div>
...@@ -63,22 +65,18 @@ ...@@ -63,22 +65,18 @@
<div class="modal-header"> <div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
</button> </button>
<h4 class="modal-title">新增广告</h4> <h4 class="modal-title" id="editor_modal_title">新增广告</h4>
</div> </div>
<div class="modal-body"> <div class="modal-body">
<form class="form-horizontal"> <form class="form-horizontal">
<div class="form-group"> <div class="form-group">
<label class="col-sm-3 control-label">标题:</label> <label class="col-sm-3 control-label">标题:</label>
<div class="col-sm-9"> <div class="col-sm-9">
<input type="hidden" value="" id="id"/>
<input type="text" class="form-control btn6" name="title" id="title" placeholder="请输入标题"> <input type="text" class="form-control btn6" name="title" id="title" placeholder="请输入标题">
</div> </div>
</div> </div>
<div class="form-group">
<label class="col-sm-3 control-label">备注:</label>
<div class="col-sm-9">
<input type="text" class="form-control btn6" name="title" id="intro" placeholder="请输入备注">
</div>
</div>
<div class="form-group"> <div class="form-group">
<label class="col-sm-3 control-label">链接:</label> <label class="col-sm-3 control-label">链接:</label>
<div class="col-sm-9"> <div class="col-sm-9">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment