liche update for admin brand set type

This commit is contained in:
xxb
2021-07-29 16:33:41 +08:00
parent 0da7eeb90f
commit f7a466d23b
8 changed files with 139 additions and 43 deletions
+26 -10
View File
@@ -32,6 +32,10 @@ class Brand extends HD_Controller
$this->data['brand_name'] && $where["brand_name like '%" . $this->data['brand_name'] . "%'"] = null;
$count = $this->bizBrand->count($where);
$list = $this->bizBrand->select($where, 'id desc', $page, $pagesize);
$typeAry = $this->bizBrand->type_ary();//类型
foreach($list as &$brand){
$brand['type_name'] = $typeAry[$brand['type']];
}
$this->data['lists'] = $list;
$this->data['pager'] = array('count' => ceil($count / $pagesize), 'curr' => $page, 'totle' => $count);
$this->data['_title'] = '品牌列表';
@@ -47,9 +51,15 @@ class Brand extends HD_Controller
if (!$info || empty($info)) {
return $this->show_json(SYS_CODE_FAIL, '数据不存在!');
}
$this->data['id'] = $id;
$this->data['info'] = $info;
$action = '/biz/brand/brand/edit';
} else {
$info = array('type' => 0);
$action = '/biz/brand/brand/add';
}
$this->data['info'] = $info;
$this->data['action'] = $action;
$this->data['typeAry'] = $this->bizBrand->type_ary();
$this->data['_title'] = $id ? '编辑品牌' : '新增品牌';
return $this->show_view('biz/brand/edit');
}
@@ -75,8 +85,10 @@ class Brand extends HD_Controller
if (!$this->if_ajax) {
return $this->show_json(SYS_CODE_FAIL, '提交出错!');
}
$brand_name = $this->input->post('brand_name');
$img = $this->input->post('img');
$info = $this->input->post('info');
$brand_name = $info['brand_name'];
$img = $info['brand_logo'];
$type = $info['type'];
if (!$brand_name || empty($brand_name)) {
return $this->show_json(SYS_CODE_FAIL, '品牌名称不能为空');
}
@@ -89,6 +101,7 @@ class Brand extends HD_Controller
$add_brand_data = array(
'brand_name' => $brand_name,
'brand_logo' => $img,
'type' => intval($type),
'c_time' => time()
);
$brand_id = $this->bizBrand->add($add_brand_data);
@@ -103,17 +116,19 @@ class Brand extends HD_Controller
if (!$this->if_ajax) {
return $this->show_json(SYS_CODE_FAIL, '提交出错!');
}
$id = $this->input->get('id');
$info = $this->bizBrand->get(array('id' => $id));
if (!$info || empty($info)) {
$info = $this->input->post('info');
$id = $info['id'];
$brand_name = $info['brand_name'];
$img = $info['brand_logo'];
$type = $info['type'];
$row = $this->bizBrand->get(array('id' => $id));
if (!$row || empty($row)) {
return $this->show_json(SYS_CODE_FAIL, '数据不存在!');
}
$brand_name = $this->input->post('brand_name');
$img = $this->input->post('img');
if (!$brand_name || empty($brand_name)) {
return $this->show_json(SYS_CODE_FAIL, '品牌名称不能为空');
}
//防止品牌名称重复添加
//防止品牌名称重复
$where1 = array('brand_name' => $brand_name, "status<>-1" => null);
$id && $where1['id <>'] = $id;//修改时也不允许重复
$old = $this->bizBrand->get($where1);
@@ -123,6 +138,7 @@ class Brand extends HD_Controller
$add_brand_data = array(
'brand_name' => $brand_name,
'brand_logo' => $img,
'type' => intval($type),
);
$this->bizBrand->update($add_brand_data, array('id' => $id));
return $this->show_json(SYS_CODE_SUCCESS, '保存成功');
+94 -29
View File
@@ -1,35 +1,100 @@
<?php if ($info || !empty($info)){ ?>
<form class="am-form am-form-horizontal" action="/biz/brand/brand/edit?id=<?= $info['id'] ?>" data-auto="true" method=""
style="width: 90%;padding-top: 10px">
<?php }else{ ?>
<form class="am-form am-form-horizontal" action="/biz/brand/brand/add" data-auto="true" method=""
style="width: 90%;padding-top: 10px">
<?php } ?>
<div class="am-form-group">
<label class="am-para-label">品牌名称:</label>
<div class="am-para-input"><input type="text" placeholder="输入品牌名称" name="brand_name"
value="<?= $info['brand_name'] ?>"/></div>
<form id="vue-edit" class="am-form am-form-horizontal" :action="action" data-auto="true" method="post" style="width: 90%;padding-top: 10px">
<div class="am-form-group">
<label class="am-para-label">品牌名称:</label>
<div class="am-para-input">
<input type="text" placeholder="输入品牌名称" name="brand_name" v-model="info.brand_name"/>
</div>
<div class="am-form-group" style="margin-bottom: 0">
<label class="am-para-label">logo</label>
<div class="am-para-input">
<div class="am-form-group am-form-file">
<button type="button" class="am-btn am-btn-default am-btn-sm"
data-file="1" data-type="jpg,png,gif,png,jpeg"
data-uptype="qiniu" data-field="img"><i class="am-icon-cloud-upload"></i> 选择要上传的文件
</button>
</div>
<div class="am-form-group" style="margin-bottom: 0">
<label class="am-para-label">logo</label>
<div class="am-para-input">
<div class="am-form-group am-form-file">
<button type="button" class="am-btn am-btn-default am-btn-sm"
data-file="1" data-type="jpg,png,gif,png,jpeg"
data-uptype="qiniu" data-field="img"><i class="am-icon-cloud-upload"></i> 选择要上传的文件
</button>
<input type="hidden" name="img" value="<?= $info['brand_logo'] ?>" class="layui-input">
<img data-tips-image style="height:auto;max-height:32px;max-width:32px"
src="<?= $info['brand_logo'] ? build_qiniu_image_url($info['brand_logo']) : '' ?>"/>
尺寸100x100
</div>
<input type="hidden" id="brand_logo" name="img" value="<?= $info['brand_logo'] ?>" class="layui-input">
<img data-tips-image style="height:auto;max-height:32px;max-width:32px"
src="<?= $info['brand_logo'] ? build_qiniu_image_url($info['brand_logo']) : '' ?>"/>
尺寸100x100
</div>
</div>
<div class="am-form-group" style="margin-bottom: 2rem">
<div class="am-para-input">
<button class="am-btn am-btn-secondary" type="submit">保存</button>
</div>
</div>
<div class="am-form-group">
<label class="am-para-label">类型:</label>
<div class="am-para-input wp20">
<select name="type" v-model="info.type">
<option value="0">选择类型</option>
<option v-for="(v,i) in typeAry" :value="i">{{v}}</option>
</select>
</div>
</form>
</div>
<div class="am-form-group" style="margin-bottom: 2rem">
<div class="am-para-input">
<button class="am-btn am-btn-secondary" type="button" @click="saveEdit">保存</button>
</div>
</div>
</form>
<script>
var loading = 0;
var vue_obj;
$(function(){
vue_obj = new Vue({
el: '#vue-edit',
data: {
info:{},
action:'',
typeAry:[]
},
mounted:function(){
var vm = this;
vm.info = <?=json_encode($info)?>;
vm.action = '<?=$action?>';
vm.typeAry = <?=json_encode($typeAry)?>;
},
methods:{
saveEdit:function(){
var vm = this;
if(1 == loading){
return 0;
}
loading = 1;
vm.info.brand_logo = $("#brand_logo").val();
$.ajax({
url: vm.action,
type: 'post',
dataType: 'json',
data: {info:vm.info},
beforeSend: function () {
layer.load(1, {
shade: [0.1, '#fff'] //0.1透明度的白色背景
});
},
success: function (data) {
loading = 0;
if (1 == data.code) {
layer.msg(data.msg, {
icon: 1,
time: 2000
}, function () {
window.location.reload();
});
} else {
layer.msg(data.msg, {icon: 2});
}
},
complete: function () {
loading = 0;
layer.closeAll('loading');
}
});
}
},
watch:{}
});
});
</script>
+2
View File
@@ -24,6 +24,7 @@
<tr>
<th width="10%"><span>ID</span></th>
<th width="20%"><span>品牌名称</span></th>
<th width="10%"><span>类型</span></th>
<th width="35%"><span>操作</span></th>
</tr>
</thead>
@@ -32,6 +33,7 @@
<tr>
<td><?= $v['id'] ?></td>
<td><?= $v['brand_name'] ?></td>
<td><?= $v['type_name'] ?></td>
<td>
<a href="javascript:void (0);" data-modal="/biz/brand/brand/get?id=<?= $v['id'] ?>"
class="am-text-primary"><?= '编辑' ?></a> |
+1 -1
View File
@@ -10,7 +10,7 @@
<meta name="renderer" content="webkit">
<link rel="stylesheet" type="text/css" href="/AmazeUI/assets/css/amazeui.css">
<link rel="stylesheet" type="text/css" href="/static/css/common.css?t=1">
<link rel="stylesheet" type="text/css" href="/static/css/common.css?t=7">
<link rel="stylesheet" type="text/css" href="/static/css/mobilemedia.css">
<link rel="stylesheet" type="text/css" href="/static/css/iconfont/iconfont.css">
<link rel="stylesheet" type="text/css" href="/static/js/plugin/bootstrap/css/bootstrap.css">
-2
View File
@@ -24,7 +24,6 @@
<thead>
<tr>
<th width="15%"><span>城市ID</span></th>
<th width="10%"><span>首字母</span></th>
<th width="15%"><span>城市名称</span></th>
<th width="10%"><span>操作</span></th>
<th width=""><span class="mr10">区域</span><button data-title="保存" type="button" class="am-btn am-btn-success am-btn-xs" @click="save_area">保存</button></th>
@@ -33,7 +32,6 @@
<tbody>
<tr v-for="(v,i) in lists">
<td>{{v.city_id}}</td>
<td>{{v.firstchar}}</td>
<td>{{v.name}}</td>
<td>
<a data-ajax="post" data-action="/sys/city/city/del" :data-params-id="v.id" class="am-btn am-btn-danger am-btn-xs">删除</a>
+14
View File
@@ -17,4 +17,18 @@ class Biz_brand_model extends HD_Model
parent::__construct($this->table_name, 'default');
}
/**
* 获取类型
* @param null $key
* @return mixed
*/
function type_ary($key = null){
$map = array('1' => '直营店', '2' => '二网', '3' => '合作店');
if(!is_null($key)){
return $map[$key];
}
return $map;
}
}
+1
View File
@@ -40,6 +40,7 @@ create table lc_biz_brand (
u_time timestamp not null default current_timestamp on update current_timestamp,
primary key (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='品牌表';
alter table lc_biz_brand add column type tinyint(1) not null default 0 comment '类型:1-直营店,2-二网,3-合作店' after brand_logo;
-- ----------------------------
-- Title:商家标签关系
File diff suppressed because one or more lines are too long