作者 何书鹏
1 个管道 的构建 通过 耗费 3 秒

合并分支 'heshupeng' 到 'master'

城市代理



查看合并请求 !368
<?php
namespace app\admin\controller;
use app\common\controller\Backend;
use think\Db;
/**
* 代理地区管理
*
* @icon fa fa-circle-o
*/
class AdminArea extends Backend
{
/**
* AdminArea模型对象
* @var \app\admin\model\AdminArea
*/
protected $model = null;
public function _initialize()
{
parent::_initialize();
$this->model = new \app\admin\model\AdminArea;
}
/**
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
*/
/**
* 查看
*/
public function index()
{
//当前是否为关联查询
$this->relationSearch = false;
//设置过滤方法
$this->request->filter(['strip_tags', 'trim']);
if ($this->request->isAjax())
{
//如果发送的来源是Selectpage,则转发到Selectpage
if ($this->request->request('keyField'))
{
return $this->selectpage();
}
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$total = $this->model
->where('admin_id',$this->request->request('admin_id'))
->where($where)
->order($sort, $order)
->count();
$list = $this->model
->where('admin_id',$this->request->request('admin_id'))
->where($where)
->order($sort, $order)
->limit($offset, $limit)
->select();
foreach ($list as $row) {
$row->visible(['id','area']);
}
$list = collection($list)->toArray();
$result = array("total" => $total, "rows" => $list);
return json($result);
}
return $this->view->fetch();
}
/**
* 添加
*/
public function add()
{
$admin_id = $this->request->request('admin_id');
if ($this->request->isPost()) {
$params = $this->request->post("row/a");
if ($params) {
$params = $this->preExcludeFields($params);
if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
$params[$this->dataLimitField] = $this->auth->id;
}
// 当前账号的角色组ID数组
$group_id_arr = Db::name('auth_group_access')->where('uid',$admin_id)->column('group_id');
// 地区ID
$area_name = strrpos($params['area'], '/') === false ? $params['area'] : substr($params['area'],strrpos($params['area'], '/')+1);
$area = \app\admin\model\Area::getByname($area_name);
if(in_array(6,$group_id_arr) && $area['level'] != 2){
$this->error('城市代理只能选择城市');
}
if(in_array(7,$group_id_arr) && $area['level'] != 3){
$this->error('区县代理只能选择区县');
}
$params['area_id'] = $area['id'];
$params['admin_id'] = $admin_id;
$result = false;
Db::startTrans();
try {
//是否采用模型验证
if ($this->modelValidate) {
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
$this->model->validateFailException(true)->validate($validate);
}
$result = $this->model->allowField(true)->save($params);
Db::commit();
} catch (ValidateException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (PDOException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($result !== false) {
$this->success();
} else {
$this->error(__('No rows were inserted'));
}
}
$this->error(__('Parameter %s can not be empty', ''));
}
return $this->view->fetch();
}
/**
* 编辑
*/
public function edit($ids = null)
{
$row = $this->model->get($ids);
if (!$row) {
$this->error(__('No Results were found'));
}
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds)) {
if (!in_array($row[$this->dataLimitField], $adminIds)) {
$this->error(__('You have no permission'));
}
}
if ($this->request->isPost()) {
$params = $this->request->post("row/a");
if ($params) {
$params = $this->preExcludeFields($params);
// 当前账号的角色组ID数组
$group_id_arr = Db::name('auth_group_access')->where('uid',$row['admin_id'])->column('group_id');
// 地区ID
$area_name = strrpos($params['area'], '/') === false ? $params['area'] : substr($params['area'],strrpos($params['area'], '/')+1);
$area = \app\admin\model\Area::getByname($area_name);
if(in_array(6,$group_id_arr) && $area['level'] != 2){
$this->error('城市代理只能选择城市');
}
if(in_array(7,$group_id_arr) && $area['level'] != 3){
$this->error('区县代理只能选择区县');
}
$params['area_id'] = $area['id'];
$result = false;
Db::startTrans();
try {
//是否采用模型验证
if ($this->modelValidate) {
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
$row->validateFailException(true)->validate($validate);
}
$result = $row->allowField(true)->save($params);
Db::commit();
} catch (ValidateException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (PDOException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($result !== false) {
$this->success();
} else {
$this->error(__('No rows were updated'));
}
}
$this->error(__('Parameter %s can not be empty', ''));
}
$this->view->assign("row", $row);
return $this->view->fetch();
}
}
... ...
... ... @@ -89,7 +89,26 @@ class House extends Backend
if ($params) {
$params = $this->preExcludeFields($params);
// 当前账号的角色组ID数组
$group_id_arr = array_column($this->auth->getGroups(), 'group_id');
// 城市或区县代理
if(!in_array(1,$group_id_arr) && array_intersect([6,7],$group_id_arr)){
// 地区
$area_name = strrpos($params['area'], '/') === false ? $params['area'] : substr($params['area'],strrpos($params['area'], '/')+1);
$area = \app\admin\model\Area::getByname($area_name);
// 代理地区
if($area['level'] == 3 && in_array(6,$group_id_arr)){
$admin_area_name = substr($params['area'],0,strrpos($params['area'], '/'));
}else{
$admin_area_name = $params['area'];
}
$admin_area = \app\admin\model\AdminArea::getByArea($admin_area_name);
if(!$admin_area){
$this->error('抱歉,您不能开发其他区域的小区');
}
}
// 小区编号
$data = Db::name('house')
->field('max(com_number) as num')
->find();
... ... @@ -170,6 +189,26 @@ class House extends Backend
$params = $this->request->post("row/a");
if ($params) {
$params = $this->preExcludeFields($params);
// 当前账号的角色组ID数组
$group_id_arr = array_column($this->auth->getGroups(), 'group_id');
// 城市或区县代理
if(!in_array(1,$group_id_arr) && array_intersect([6,7],$group_id_arr)){
// 地区
$area_name = strrpos($params['area'], '/') === false ? $params['area'] : substr($params['area'],strrpos($params['area'], '/')+1);
$area = \app\admin\model\Area::getByname($area_name);
// 代理地区
if($area['level'] == 3 && in_array(6,$group_id_arr)){
$admin_area_name = substr($params['area'],0,strrpos($params['area'], '/'));
}else{
$admin_area_name = $params['area'];
}
$admin_area = \app\admin\model\AdminArea::getByArea($admin_area_name);
if(!$admin_area){
$this->error('抱歉,您不能开发其他区域的小区');
}
}
$result = false;
Db::startTrans();
try {
... ...
... ... @@ -82,6 +82,15 @@ class Store extends Backend
return json($result);
}
// 城市或区县代理
$have_store_num = 0;
$group_id_arr = array_column($this->auth->getGroups(), 'group_id');
if(!in_array(1,$group_id_arr) && array_intersect([6,7],$group_id_arr)){
$have_store_num = 1;
}
$store_num = Admin::where('id',$this->auth->id)->value('store_num');
$this->view->assign('have_store_num',$have_store_num);
$this->view->assign('store_num',$store_num);
return $this->view->fetch();
}
... ... @@ -169,6 +178,12 @@ class Store extends Backend
$openid = Db::name('third')->where('user_id',$row->user_id)->value('openid');
$url = 'http://community.t.brotop.cn/admininfo.php';
$this->wxsendmessage($openid,$send_data,config('option.template')['store_pass'],$url);
// 城市或区县代理,可审核商铺数量减一
$group_id_arr = array_column($this->auth->getGroups(), 'group_id');
$admin = Admin::get($this->auth->id);
if(!in_array(1,$group_id_arr) && array_intersect([6,7],$group_id_arr) && $admin['store_num'] > 0){
$admin->setDec('store_num');
}
}
if($params['status'] == 4) {
// 审核不通过,执行退款操作
... ...
<?php
return [
'Admin_id' => '管理员ID',
'Area_id' => '区域ID',
'Area' => '代理地区',
'Createtime' => '创建时间',
'Updatetime' => '更新时间'
];
... ...
<?php
namespace app\admin\model;
use think\Model;
class AdminArea extends Model
{
// 表名
protected $name = 'admin_area';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = false;
// 追加属性
protected $append = [
];
}
... ...
<?php
namespace app\admin\validate;
use think\Validate;
class AdminArea extends Validate
{
/**
* 验证规则
*/
protected $rule = [
];
/**
* 提示消息
*/
protected $message = [
];
/**
* 验证场景
*/
protected $scene = [
'add' => [],
'edit' => [],
];
}
... ...
<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Area')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-area" data-rule="required" class="form-control" name="row[area]" type="text" value="" data-toggle="city-picker">
</div>
</div>
<div class="form-group layer-footer">
<label class="control-label col-xs-12 col-sm-2"></label>
<div class="col-xs-12 col-sm-8">
<button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
<button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
</div>
</div>
</form>
... ...
<form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Area')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-area" data-rule="required" class="form-control" name="row[area]" type="text" value="{$row.area|htmlentities}" data-toggle="city-picker">
</div>
</div>
<div class="form-group layer-footer">
<label class="control-label col-xs-12 col-sm-2"></label>
<div class="col-xs-12 col-sm-8">
<button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
<button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
</div>
</div>
</form>
... ...
<div class="panel panel-default panel-intro">
{:build_heading()}
<div class="panel-body">
<div id="myTabContent" class="tab-content">
<div class="tab-pane fade active in" id="one">
<div class="widget-body no-padding">
<div id="toolbar" class="toolbar">
<a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
<a href="javascript:;" class="btn btn-success btn-add {:$auth->check('admin_area/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>
<a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('admin_area/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>
<a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('admin_area/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>
</div>
<table id="table" class="table table-striped table-bordered table-hover table-nowrap"
data-operate-edit="{:$auth->check('admin_area/edit')}"
data-operate-del="{:$auth->check('admin_area/del')}"
width="100%">
</table>
</div>
</div>
</div>
</div>
</div>
... ...
... ... @@ -36,6 +36,12 @@
{:build_radios('row[status]', ['normal'=>__('Normal'), 'hidden'=>__('Hidden')])}
</div>
</div>
<div class="form-group" id="store_num" style="display: none">
<label class="control-label col-xs-12 col-sm-2">{:__('可审核商铺数量')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-store_num" class="form-control form-control" name="row[store_num]" type="number" value="0">
</div>
</div>
<div class="form-group hidden layer-footer">
<label class="control-label col-xs-12 col-sm-2"></label>
<div class="col-xs-12 col-sm-8">
... ...
... ... @@ -42,6 +42,12 @@
{:build_radios('row[status]', ['normal'=>__('Normal'), 'hidden'=>__('Hidden')], $row['status'])}
</div>
</div>
<div class="form-group" id="store_num" style="display: none">
<label class="control-label col-xs-12 col-sm-2">{:__('可审核商铺数量')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-store_num" class="form-control form-control" name="row[store_num]" type="number" value="{$row.store_num}">
</div>
</div>
<div class="form-group hidden layer-footer">
<label class="control-label col-xs-12 col-sm-2"></label>
<div class="col-xs-12 col-sm-8">
... ...
... ... @@ -17,6 +17,9 @@
<div class="widget-body no-padding">
<div id="toolbar" class="toolbar">
<a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
{eq name="have_store_num" value="1"}
<span style="color: red">可审核商铺数量:{$store_num}</span>
{/eq}
<!-- <a href="javascript:;" class="btn btn-success btn-add {:$auth->check('store/store/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>-->
<!-- <a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('store/store/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>-->
<!-- <a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('store/store/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>-->
... ...
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'admin_area/index' + location.search,
add_url: 'admin_area/add' + location.search,
edit_url: 'admin_area/edit',
del_url: 'admin_area/del',
multi_url: 'admin_area/multi',
table: 'admin_area',
}
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
columns: [
[
{checkbox: true},
{field: 'id', title: __('Id')},
{field: 'area', title: __('Area')},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
]
]
});
// 为表格绑定事件
Table.api.bindevent(table);
},
add: function () {
Controller.api.bindevent();
},
edit: function () {
Controller.api.bindevent();
},
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
}
}
};
return Controller;
});
\ No newline at end of file
... ...
... ... @@ -37,7 +37,23 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
{field: 'email', title: __('Email')},
{field: 'status', title: __("Status"), formatter: Table.api.formatter.status},
{field: 'logintime', title: __('Login time'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: function (value, row, index) {
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, buttons:
[
{
text: '代理地区',
title: '代理地区',
icon: 'fa fa-list',
classname: 'btn btn-xs btn-primary btn-dialog',
url: 'admin_area/index?admin_id={id}',
extend: 'data-area=\'["80%","80%"]\'',
visible: function(row){
var group = row.groups.split(',');
if($.inArray("1", group) === -1 && $.inArray("6", group) !== -1 || $.inArray("7", group) !== -1){
return true;
}
}
}
],formatter: function (value, row, index) {
if(row.id == Config.admin.id){
return '';
}
... ... @@ -52,10 +68,29 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
},
add: function () {
Form.api.bindevent($("form[role=form]"));
Controller.api.change();
},
edit: function () {
Form.api.bindevent($("form[role=form]"));
}
Controller.api.change();
setTimeout(function () {
$('select[name="group[]"]').trigger("change");
}, 100);
},
api: {
change: function () {
$('select[name="group[]"]').change(function () {
var group = $(this).val();
if($.inArray("1", group) === -1 && $.inArray("6", group) !== -1 || $.inArray("7", group) !== -1){
$('#store_num').show();
$("form[role=form]").validator("setField", "#c-store_num", "required;");
}else{
$('#store_num').hide();
$("form[role=form]").validator("setField", "#c-store_num", null);
}
})
}
}
};
return Controller;
});
\ No newline at end of file
... ...