Commit f4fe4d26 authored by hujun's avatar hujun

新增商圈

parent 4161452f
......@@ -9,18 +9,94 @@
namespace app\index\controller;
class BusinessDistrict
use app\index\extend\Basic;
use app\model\GBusinessDistrict;
use app\model\Regions;
class BusinessDistrict extends Basic
{
public function index() {
return view('business_district/index');
}
public function edit() {
return view('business_district/edit');
if ($this->request->isPost()) {
$result['code'] = 200;
$result['msg'] = '';
$params = $this->request->param();
$business = new GBusinessDistrict();
$data['province'] = $params['province'];
$data['city'] = $params['city'];
$data['disc'] = $params['disc'];
$data['province_code'] = $params['province_code'];
$data['city_code'] = $params['city_code'];
$data['disc_code'] = $params['disc_code'];
$data['name'] = $params['business'];
$data['create_time'] = date('Y-m-d H:i:s');
$business->save($data);
if ($business->id) {
$result['code'] = 200;
$result['msg'] = '添加成功';
} else {
$result['code'] = 101;
$result['msg'] = '添加失败';
}
return $this->response( $result['code'], $result['msg'], $result['data']);
} else {
return view('business_district/edit');
}
}
public function del() {
}
/**
* 获取商圈列表
*
* @return mixed
*/
public function getBusiness() {
$data['status'] = 200;
$data['msg'] = '';
$params = $this->request->param();
$pageNo = empty($params['pageNo']) ? 1 : $params['pageNo'];
$pageSize = empty($params['pageSize']) ? 15 : $params['pageSize'];
$auth_group = New GBusinessDistrict();
$where = 'is_del = 0';
if ($params['name'] != NULL) {
$where .= ' and name like "'.$params['name'].'%"';
}
$fields = 'id,name,province,city,disc,status,create_time';
$data['list'] = $auth_group->getList($pageNo, $pageSize, 'id desc',$fields, $where);
$data['total'] = $auth_group->getTotal($where);
return $this->response(200, '', $data);
}
/**
* 获取省市区数据
*
* @return \think\Response
*/
public function regions() {
$code = $this->request->get('code');
$parent_code = $this->request->get('parent_code');
$regions = new Regions();
if ($code) {
$where = 'code = '.$code;
} elseif ($parent_code) {
$where = 'parentCode = '.$parent_code;
} else {
$type = $this->request->get('type') ? $this->request->get('type') : 1;
$where = 'type = '.$type;
}
$fields = 'code,parentCode,name';
$data = $regions->field($fields)->where($where)->select();
return $this->response(200, '', $data);
}
}
\ No newline at end of file
{layout name="global/frame_tpl" /}
<h1>商圈新增</h1>
\ No newline at end of file
......@@ -17,7 +17,7 @@
<div class="pull-right">
<ul class="bread_btn">
<li>
<a href="#modal_add_user" data-toggle="modal" class="btn btn-default"><i class="icon-plus"></i>
<a href="#modal_add_business" data-toggle="modal" class="btn btn-default" id="modal_add"><i class="icon-plus"></i>
添加商圈</a>
</li>
</ul>
......@@ -29,7 +29,7 @@
<table class="table table-striped table-bordered table-hover table-condensed">
<thead>
<tr>
<td colspan="7">
<td colspan="8">
<form action="" method="get" id="form_search">
<input class="form-control btn2" data-rule-phoneus="false" data-rule-required="false" id="name" name="name" placeholder="商圈名" type="text" value="">
<span class="btn btn-default btn3" id="search">搜索</span>
......@@ -44,6 +44,7 @@
<th class="text-center"></th>
<th class="text-center"></th>
<th class="text-center">状态</th>
<th class="text-center">创建时间</th>
<th class="text-center">操作</th>
</tr>
</thead>
......@@ -54,7 +55,6 @@
</div>
<!-- /#page-content-wrapper -->
<div class="text-right" id="pagediv">
</div>
</div>
</div>
......@@ -66,7 +66,7 @@
<!-- /#wrapper -->
<!-- /#新增用户模态框 -->
<div class="modal fade" id="modal_add_user" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal fade" id="modal_add_business" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
......@@ -78,15 +78,12 @@
</h4>
</div>
<div class="modal-body">
<form class="form-horizontal" action="/agents/add_user" id="add_user_form">
<form class="form-horizontal" action="/index/editBusinessDistrict" method="POST" id="add_business_form">
<div class="form-group">
<label for="province" class="col-md-3 control-label">省:</label>
<div class="col-md-7">
<select name="province" id="province" class="form-control btn6">
<option value="">请选择</option>
<option value=""></option>
<option value=""></option>
<option value=""></option>
<option>请选择</option>
</select>
<span class="use-span text-danger">(必填)</span>
</div>
......@@ -94,11 +91,8 @@
<div class="form-group">
<label for="city" class="col-md-3 control-label">市:</label>
<div class="col-md-7">
<select name="province" id="city" class="form-control btn6">
<option value="">请选择</option>
<option value=""></option>
<option value=""></option>
<option value=""></option>
<select name="city" id="city" class="form-control btn6">
<option>请选择</option>
</select>
<span class="use-span text-danger">(必填)</span>
</div>
......@@ -106,11 +100,8 @@
<div class="form-group">
<label for="disc" class="col-md-3 control-label">区:</label>
<div class="col-md-7">
<select name="province" id="disc" class="form-control btn6">
<option value="">请选择</option>
<option value=""></option>
<option value=""></option>
<option value=""></option>
<select name="disc" id="disc" class="form-control btn6">
<option>请选择</option>
</select>
<span class="use-span text-danger">(必填)</span>
</div>
......@@ -127,7 +118,7 @@
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal" id="close">关闭
</button>
<button type="button" class="btn btn-primary" id="add_user">
<button type="button" class="btn btn-primary" id="add_business">
提交
</button>
</div>
......
<?php
/**
* Created by PhpStorm.
* User: fuju
* Date: 2018/1/17
* Time: 15:44
*/
namespace app\model;
use think\Model;
class BaseModel extends Model
{
/**
* 记录总数
*
* @param $params
* @return int|string
*/
public function getTotal($params)
{
return $this->where($params)->count();
}
/**
* 列表
*
* @param type $pageNo
* @param type $pageSize
* @param type $order_
* @param type $field
* @param type $params
* @return type
*/
public function getList($pageNo = 1, $pageSize = 15, $order_ = 'id desc', $field = '', $params = '') {
return $this->field($field)
->where($params)
->order($order_)
->limit($pageSize)
->page($pageNo)
->select();
}
}
\ No newline at end of file
<?php
namespace app\model;
use think\Model;
class GBusinessDistrict extends BaseModel
{
protected $table = 'g_business_district';
}
......@@ -77,11 +77,13 @@ Route::group('index', [
'roleedit' => ['index/auth/roleedit', ['method' => 'get']], //编辑角色
'accessUser' => ['index/auth/accessUser', ['method' => 'get']], //成员授权
'BusinessDistrict' => ['index/BusinessDistrict/index', ['method' => 'get']], //商圈列表
'editBusinessDistrict' => ['index/BusinessDistrict/edit', ['method' => 'get']], //编辑商圈
'delBusinessDistrict' => ['index/BusinessDistrict/index', ['method' => 'get']], //删除商圈列表
'editBusinessDistrict' => ['index/BusinessDistrict/edit', ['method' => 'get | post']], //编辑商圈
'delBusinessDistrict' => ['index/BusinessDistrict/index', ['method' => 'post']], //删除商圈列表
'BusinessList' => ['index/BusinessDistrict/getBusiness', ['method' => 'get']], //获取商铺列表数据
'houseList' => ['index/Houses/index', ['method' => 'get']], //商铺列表
'houseEdit' => ['index/Houses/edit', ['method' => 'get']], //编辑商铺
'houseDel' => ['index/Houses/del', ['method' => 'get']], //删除商铺
'regions' => ['index/BusinessDistrict/regions', ['method' => 'get']], //删除商铺
]);
......
define (['doT', 'text!temp/auth_template_tpl.html', 'css!style/home.css','pagination','bootstrapJs'], function (doT, template) {
auth = {
define (['doT', 'text!temp/business_district_template_tpl.html', 'css!style/home.css','pagination','bootstrapJs'], function (doT, template) {
business = {
pageNo: 1, /*第几页*/
pageSize: 10, /*每页显示多少条*/
init: function () {
//初始化dot
$ ("body").append (template);
auth.getList ();
auth.event ();
business.getList ();
business.event ();
},
event: function () {
$("#search").click(function () {
business.getList(1);
});
$("#reset").click(function () {
document.getElementById("form_search").reset();
});
$("#modal_add").click(function () {
business.getRegionsProvince();
});
$("#province").change(function () {
business.getRegionsCity();
});
$("#city").change(function () {
business.getRegionsDisc();
});
$("#add_business").click(function () {
var params = {};
params.province = $("#province").find("option:selected").text();
params.city = $("#city").find("option:selected").text();
params.disc = $("#disc").find("option:selected").text();
params.province_code = $("#province").val();
params.city_code = $("#city").val();
params.disc_code = $("#disc").val();
params.business = $("#business").val();
$.ajax({
url : '/index/editBusinessDistrict.html',
type : 'POST',
async: true,
data : params,
dataType : 'json',
success : function (data) {
if (data.code == 200 ) {
alert('添加成功');
business.getList(1);
$("#modal_add_business").modal ('hide');
} else {
alert('添加失败');
}
}
});
});
},
getList: function (pageNo) {
auth.pageNo = pageNo;
business.pageNo = pageNo;
var params = {};
params.pageNo = auth.pageNo;
params.pageSize = auth.pageSize;
params.pageNo = business.pageNo;
params.pageSize = business.pageSize;
params.name = $("#name").val();
$.ajax ({
url: '/index/getAuth.html',
url: '/index/BusinessList.html',
type: 'GET',
async: true,
data: params,
dataType: 'json',
success: function (data) {
var temp = document.getElementById ('auth_list_tpl').innerHTML;
var temp = document.getElementById ('business_list_tpl').innerHTML;
var doTtmpl = doT.template (temp);
$ ("#auth_list").html (doTtmpl (data.data));
$ ("#business_list").html (doTtmpl (data.data.list));
/*分页代码*/
$ ("#pagediv").pagination ({
length: data.data.total,
current: pageNo,
every: auth.pageSize,
every: business.pageSize,
onClick: function (el) {
auth.getList (el.num.current);
business.getList (el.num.current);
}
});
}
});
},
getRegionsProvince : function () {
$.ajax ({
url: '/index/regions.html',
type: 'GET',
async: true,
dataType: 'json',
success: function (data) {
if (data.code == 200) {
var _html = '';
$.each(data.data, function (i,n) {
if (n.code == 310000) {
_html += '<option selected="selected" value="'+n.code+'">'+n.name+'</option>';
} else {
_html += '<option value="'+n.code+'">'+n.name+'</option>';
}
});
$("#province").html(_html);
business.getRegionsCity();
} else {
alert('请求省市区错误');
}
}
});
},
getRegionsCity : function () {
var params = {};
params.parent_code = $("#province").val();
if (params.parent_code == '请选择') {
params.parent_code = 310000;
}
$.ajax ({
url: '/index/regions.html',
type: 'GET',
async: true,
data: params,
dataType: 'json',
success: function (data) {
console.log(data)
if (data.code == 200) {
var _html = '';
$.each(data.data, function (i,n) {
if (n.code == 310000) {
_html += '<option selected="selected" value="'+n.code+'">'+n.name+'</option>';
} else {
_html += '<option value="'+n.code+'">'+n.name+'</option>';
}
});
$("#city").html(_html);
business.getRegionsDisc();
} else {
alert('请求省市区错误');
}
}
});
},
getRegionsDisc : function () {
var params = {};
params.parent_code = $("#city").val();
if (params.parent_code == '请选择') {
params.parent_code = 310100;
}
$.ajax ({
url: '/index/regions.html',
type: 'GET',
async: true,
data: params,
dataType: 'json',
success: function (data) {
if (data.code == 200) {
var _html = '';
$.each(data.data, function (i,n) {
_html += '<option value="'+n.code+'">'+n.name+'</option>';
});
$("#disc").html(_html);
} else {
alert('请求省市区错误');
}
}
});
}
};
return auth;
return business;
});
\ No newline at end of file
<script id="auth_list_tpl" type="text/template">
<script id="business_list_tpl" type="text/template">
[% if(it) { %]
[% for(var item in it){ %]
<tr class="text-center">
<td>[%= it[item]['id'] %]</td>
<td>[%= it[item]['title'] %]</td>
<td>[%= it[item]['name'] %]</td>
<td>[%= it[item]['province'] %]</td>
<td>[%= it[item]['city'] %]</td>
<td>[%= it[item]['disc'] %]</td>
<td>
[% if(it[item]['description']) { %]
[%= it[item]['description'] %]
[% if(it[item]["status"] == 0) { %]
显示
[% }else{ %]
不显示
[% } %]
</td>
<td>[%= it[item]["status"] %]</td>
<td>[%= it[item]['create_time']%]</td>
<td>
<a title="编辑" class="btn btn-success btn-xs" href="/admin.php/index/roleedit?id=[%= it[item]['id']%].html" style="margin-right:6px;">编辑</a>
<a title="权限分配" class="btn btn-info btn-xs" href="/admin.php/index/access?id=[%= it[item]['id']%].html" style="margin-right:6px;">权限分配</a>
<a title="成员授权" class="btn btn-primary btn-xs" href="/admin.php/index/accessUser?id=[%= it[item]['id']%].html" style="margin-right:6px;">成员授权</a>
<a title="权限分配" class="btn btn-info btn-xs" href="/admin.php/index/access?id=[%= it[item]['id']%].html" style="margin-right:6px;">是否显示</a>
<a title="成员授权" class="btn btn-danger btn-xs" href="/admin.php/index/accessUser?id=[%= it[item]['id']%].html" style="margin-right:6px;">删除</a>
</td>
</tr>
[% } %]
......
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