添加类型
This commit is contained in:
parent
0fdd3dc6ab
commit
227f12443e
|
|
@ -38,6 +38,16 @@ class Goods extends Base
|
|||
$field = "*";
|
||||
$order = "id desc";
|
||||
$data = GoodsModel::getList($whe, $field, $order, $this->page);
|
||||
|
||||
// 查询可用的盒子类型
|
||||
$goodsTypeList = Db::name('goods_type')
|
||||
->field('value,sort_order,remark,is_fenlei,fl_name')
|
||||
->where('is_fenlei', 1)
|
||||
->order('sort_order')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
View::assign('goodsTypeList', $goodsTypeList);
|
||||
View::assign('list', $data['list']);
|
||||
View::assign('count', $data['count']);
|
||||
View::assign('page', $data['page']);
|
||||
|
|
@ -52,7 +62,16 @@ class Goods extends Base
|
|||
if (!$request->isPost()) {
|
||||
$item_card = \app\common\model\ItemCard::where('id', '<', 3)->select()->toArray();
|
||||
$shang = Shang::where('id', 'between', [34, 38])->select()->toArray();
|
||||
|
||||
|
||||
// 查询可用的盒子类型
|
||||
$goodsTypeList = Db::name('goods_type')
|
||||
->field('value,sort_order,remark,is_fenlei,fl_name')
|
||||
->where('is_fenlei', 1)
|
||||
->order('sort_order')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
View::assign('goodsTypeList', $goodsTypeList);
|
||||
View::assign('shang', $shang);
|
||||
View::assign('item_card', $item_card);
|
||||
return View::fetch("Goods/goods_add");
|
||||
|
|
@ -224,6 +243,16 @@ class Goods extends Base
|
|||
$type = $info['type'];
|
||||
$item_card = \app\common\model\ItemCard::where('id', '<', 3)->select()->toArray();
|
||||
$shang = Shang::where('id', 'between', [34, 38])->select()->toArray();
|
||||
|
||||
// 查询可用的盒子类型
|
||||
$goodsTypeList = Db::name('goods_type')
|
||||
->field('value,sort_order,remark,is_fenlei,fl_name')
|
||||
->where('is_fenlei', 1)
|
||||
->order('sort_order')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
View::assign('goodsTypeList', $goodsTypeList);
|
||||
View::assign('shang', $shang);
|
||||
View::assign('item_card', $item_card);
|
||||
View::assign('type', $type);
|
||||
|
|
|
|||
213
app/admin/controller/GoodsType.php
Normal file
213
app/admin/controller/GoodsType.php
Normal file
|
|
@ -0,0 +1,213 @@
|
|||
<?php
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\common\model\GoodsType as GoodsTypeModel;
|
||||
use think\facade\View;
|
||||
use think\facade\Request;
|
||||
|
||||
class GoodsType extends Base
|
||||
{
|
||||
/**
|
||||
* 盒子类型列表
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
// 获取列表数据
|
||||
$list = GoodsTypeModel::getList();
|
||||
|
||||
// 渲染视图
|
||||
View::assign('list', $list);
|
||||
return View::fetch('Goods/type_index');
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加盒子类型
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
if (Request::isPost()) {
|
||||
// 获取表单数据
|
||||
$data = input('post.');
|
||||
|
||||
// 表单验证
|
||||
if (empty($data['name'])) {
|
||||
return $this->renderError('类型名称不能为空');
|
||||
}
|
||||
|
||||
if (!is_numeric($data['value'])) {
|
||||
return $this->renderError('类型key必须是数字');
|
||||
}
|
||||
|
||||
// 检查key是否已存在
|
||||
$exists = GoodsTypeModel::getInfo(['value' => $data['value']]);
|
||||
if ($exists) {
|
||||
return $this->renderError('类型key已存在,请更换');
|
||||
}
|
||||
|
||||
// 验证分类显示设置
|
||||
if (isset($data['is_fenlei']) && $data['is_fenlei'] == 1 && empty($data['fl_name'])) {
|
||||
return $this->renderError('选择分类显示时,必须填写分类名称');
|
||||
}
|
||||
|
||||
// 处理表单数据
|
||||
$data['is_show'] = isset($data['is_show']) ? 1 : 0;
|
||||
$data['is_fenlei'] = isset($data['is_fenlei']) ? 1 : 0;
|
||||
$data['sort_order'] = intval($data['sort_order']);
|
||||
|
||||
// 保存数据
|
||||
$result = GoodsTypeModel::add($data);
|
||||
if ($result) {
|
||||
return $this->renderSuccess('添加成功');
|
||||
} else {
|
||||
return $this->renderError('添加失败');
|
||||
}
|
||||
}
|
||||
|
||||
// 渲染视图,去掉布局,以便在弹出层中使用
|
||||
View::engine()->layout(false);
|
||||
return View::fetch('Goods/type_add');
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑盒子类型
|
||||
*/
|
||||
public function edit($id = 0)
|
||||
{
|
||||
if (Request::isPost()) {
|
||||
// 获取表单数据
|
||||
$data = input('post.');
|
||||
|
||||
// 表单验证
|
||||
if (empty($data['name'])) {
|
||||
return $this->renderError('类型名称不能为空');
|
||||
}
|
||||
|
||||
if (!is_numeric($data['value'])) {
|
||||
return $this->renderError('类型key必须是数字');
|
||||
}
|
||||
|
||||
// 检查key是否已存在(排除自身)
|
||||
$exists = GoodsTypeModel::getInfo([
|
||||
['value', '=', $data['value']],
|
||||
['id', '<>', $id]
|
||||
]);
|
||||
if ($exists) {
|
||||
return $this->renderError('类型key已存在,请更换');
|
||||
}
|
||||
|
||||
// 验证分类显示设置
|
||||
if (isset($data['is_fenlei']) && $data['is_fenlei'] == 1 && empty($data['fl_name'])) {
|
||||
return $this->renderError('选择分类显示时,必须填写分类名称');
|
||||
}
|
||||
|
||||
// 处理表单数据
|
||||
$data['is_show'] = isset($data['is_show']) ? 1 : 0;
|
||||
$data['is_fenlei'] = isset($data['is_fenlei']) ? 1 : 0;
|
||||
$data['sort_order'] = intval($data['sort_order']);
|
||||
|
||||
// 更新数据
|
||||
$result = GoodsTypeModel::edit($id, $data);
|
||||
if ($result) {
|
||||
return $this->renderSuccess('更新成功');
|
||||
} else {
|
||||
return $this->renderError('更新失败');
|
||||
}
|
||||
}
|
||||
|
||||
// 获取盒子类型信息
|
||||
$info = GoodsTypeModel::getInfo($id);
|
||||
if (empty($info)) {
|
||||
return $this->renderError('盒子类型不存在');
|
||||
}
|
||||
|
||||
// 渲染视图,去掉布局,以便在弹出层中使用
|
||||
View::engine()->layout(false);
|
||||
View::assign('info', $info);
|
||||
return View::fetch('Goods/type_edit');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除盒子类型
|
||||
*/
|
||||
public function delete($id = 0)
|
||||
{
|
||||
// 检查盒子类型是否存在
|
||||
$info = GoodsTypeModel::getInfo($id);
|
||||
if (empty($info)) {
|
||||
return $this->renderError('盒子类型不存在');
|
||||
}
|
||||
|
||||
// 删除盒子类型
|
||||
$result = GoodsTypeModel::remove($id);
|
||||
if ($result) {
|
||||
return $this->renderSuccess('删除成功');
|
||||
} else {
|
||||
return $this->renderError('删除失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改状态
|
||||
*/
|
||||
public function status()
|
||||
{
|
||||
// 获取参数
|
||||
$id = input('id', 0);
|
||||
$type = input('type', '');
|
||||
$value = input('value', 0);
|
||||
|
||||
// 参数检查
|
||||
if (empty($id) || empty($type)) {
|
||||
return $this->renderError('参数错误');
|
||||
}
|
||||
|
||||
// 检查盒子类型是否存在
|
||||
$info = GoodsTypeModel::getInfo($id);
|
||||
if (empty($info)) {
|
||||
return $this->renderError('盒子类型不存在');
|
||||
}
|
||||
|
||||
// 更新状态
|
||||
$data = [];
|
||||
if ($type == 'is_show') {
|
||||
$data['is_show'] = $value;
|
||||
} elseif ($type == 'is_fenlei') {
|
||||
$data['is_fenlei'] = $value;
|
||||
}
|
||||
|
||||
$result = GoodsTypeModel::edit($id, $data);
|
||||
if ($result) {
|
||||
return $this->renderSuccess('操作成功');
|
||||
} else {
|
||||
return $this->renderError('操作失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取盒子类型列表数据(用于前端DataTable调用)
|
||||
*/
|
||||
public function getTypeList()
|
||||
{
|
||||
// 获取请求参数
|
||||
$page = input('page', 1);
|
||||
$limit = input('limit', 15);
|
||||
|
||||
// 计算偏移量
|
||||
$offset = ($page - 1) * $limit;
|
||||
|
||||
// 获取数据总数
|
||||
$count = GoodsTypeModel::count();
|
||||
|
||||
// 获取当前页数据
|
||||
$list = GoodsTypeModel::order('sort_order asc')
|
||||
->limit($offset, $limit)
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
// 返回JSON格式数据
|
||||
return $this->renderSuccess('获取成功', [
|
||||
'list' => $list,
|
||||
'count' => $count
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -299,4 +299,13 @@ Route::rule('user_list', 'User/list', 'GET');
|
|||
Route::rule('user_box', 'User/user_box', 'GET');
|
||||
Route::rule('user_box_list', 'User/user_box_list', 'GET');
|
||||
Route::rule('user_order', 'User/user_order', 'GET');
|
||||
Route::rule('user_order_list', 'User/user_order_list', 'GET');
|
||||
Route::rule('user_order_list', 'User/user_order_list', 'GET');
|
||||
|
||||
// 盒子类型管理
|
||||
Route::get('goodstype/index', 'GoodsType/index');
|
||||
Route::get('goodstype/add', 'GoodsType/add');
|
||||
Route::post('goodstype/add', 'GoodsType/add');
|
||||
Route::rule('goodstype/edit', 'GoodsType/edit', 'GET|POST');
|
||||
Route::post('goodstype/delete', 'GoodsType/delete');
|
||||
Route::post('goodstype/status', 'GoodsType/status');
|
||||
Route::get('goodstype/getTypeList', 'GoodsType/getTypeList');
|
||||
|
|
@ -25,15 +25,9 @@
|
|||
<div class="layui-input-inline" style="width: 180px;margin-left: 0px">
|
||||
<select name="type" style="width:100%">
|
||||
<option value="">--盒子类型--</option>
|
||||
<option value="1" {if condition="$Request.get.type eq 1" }selected{/if}>一番赏</option>
|
||||
<option value="2" {if condition="$Request.get.type eq 2" }selected{/if}>无限赏</option>
|
||||
<option value="3" {if condition="$Request.get.type eq 3" }selected{/if}>擂台赏</option>
|
||||
<option value="5" {if condition="$Request.get.type eq 5" }selected{/if}>积分赏</option>
|
||||
<option value="6" {if condition="$Request.get.type eq 6" }selected{/if}>全局赏</option>
|
||||
<option value="8" {if condition="$Request.get.type eq 8" }selected{/if}>领主赏</option>
|
||||
<option value="9" {if condition="$Request.get.type eq 9" }selected{/if}>连击赏</option>
|
||||
<option value="10" {if condition="$Request.get.type eq 10" }selected{/if}>商城赏</option>
|
||||
<option value="11" {if condition="$Request.get.type eq 11" }selected{/if}>自制赏</option>
|
||||
{volist name="goodsTypeList" id="vo"}
|
||||
<option value="{$vo.value}" {if condition="$Request.get.type eq $vo.value" }selected{/if} title="{$vo.remark}">{$vo.fl_name}</option>
|
||||
{/volist}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -12,26 +12,9 @@
|
|||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">盒子类型</label>
|
||||
<div class="layui-input-inline" style="width:800px">
|
||||
<input type="radio" name="type" value="1" lay-filter="type" class="layui-input"
|
||||
title="一番赏" checked>
|
||||
<input type="radio" name="type" value="2" lay-filter="type" class="layui-input"
|
||||
title="无限赏">
|
||||
<input type="radio" name="type" value="3" lay-filter="type" class="layui-input"
|
||||
title="擂台赏">
|
||||
<input type="radio" name="type" value="5" lay-filter="type" class="layui-input"
|
||||
title="积分赏">
|
||||
<input type="radio" name="type" value="6" lay-filter="type" class="layui-input"
|
||||
title="全局赏">
|
||||
<input type="radio" name="type" value="8" lay-filter="type" class="layui-input"
|
||||
title="领主赏">
|
||||
<input type="radio" name="type" value="9" lay-filter="type" class="layui-input"
|
||||
title="连击赏">
|
||||
<input type="radio" name="type" value="10" lay-filter="type" class="layui-input"
|
||||
title="商城赏">
|
||||
<input type="radio" name="type" value="11" lay-filter="type" class="layui-input"
|
||||
title="自制赏">
|
||||
|
||||
|
||||
{volist name="goodsTypeList" id="vo"}
|
||||
<input type="radio" name="type" value="{$vo.value}" lay-filter="type" class="layui-input" title="{$vo.fl_name}" {if $key eq 0}checked{/if}>
|
||||
{/volist}
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
|
|
|
|||
|
|
@ -12,24 +12,9 @@
|
|||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">盒子类型</label>
|
||||
<div class="layui-input-inline" style="width: 700px">
|
||||
<input type="radio" value="1" lay-filter="type" class="layui-input" title="一番赏"
|
||||
disabled {if $type eq 1} checked {/if}>
|
||||
<input type="radio" value="2" lay-filter="type" class="layui-input" title="无限赏"
|
||||
disabled {if $type eq 2} checked {/if}>
|
||||
<input type="radio" value="3" lay-filter="type" class="layui-input" title="擂台赏"
|
||||
disabled {if $type eq 3} checked {/if}>
|
||||
<input type="radio" value="5" lay-filter="type" class="layui-input" title="积分赏"
|
||||
disabled {if $type eq 5} checked {/if}>
|
||||
<input type="radio" value="6" lay-filter="type" class="layui-input" title="全局赏"
|
||||
disabled {if $type eq 6} checked {/if}>
|
||||
<input type="radio" value="8" lay-filter="type" class="layui-input" title="领主赏"
|
||||
disabled {if $type eq 8} checked {/if}>
|
||||
<input type="radio" value="9" lay-filter="type" class="layui-input" title="连击赏"
|
||||
disabled {if $type eq 9} checked {/if}>
|
||||
<input type="radio" value="10" lay-filter="type" class="layui-input" title="商城赏"
|
||||
disabled {if $type eq 10} checked {/if}>
|
||||
<input type="radio" value="11" lay-filter="type" class="layui-input" title="自制赏"
|
||||
disabled {if $type eq 11} checked {/if}>
|
||||
{volist name="goodsTypeList" id="vo"}
|
||||
<input type="radio" value="{$vo.value}" lay-filter="type" class="layui-input" title="{$vo.fl_name}" disabled {if $type eq $vo.value} checked {/if}>
|
||||
{/volist}
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
|
|
|
|||
110
app/admin/view/Goods/type_add.html
Normal file
110
app/admin/view/Goods/type_add.html
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
{include file="Public:header2"/}
|
||||
<body>
|
||||
<div class="layui-fluid">
|
||||
<div class="layui-card">
|
||||
|
||||
<div class="layui-card-body" >
|
||||
<form class="layui-form" id="addForm" lay-filter="addForm">
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">类型名称</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="name" required lay-verify="required" placeholder="请输入类型名称" autocomplete="off" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">类型Key</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="number" name="value" required lay-verify="required" placeholder="请输入类型Key(数字)" autocomplete="off" class="layui-input">
|
||||
<div class="layui-form-mid layui-word-aux">类型Key必须是唯一的数字</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">排序</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="number" name="sort_order" value="0" required lay-verify="required" placeholder="请输入排序值" autocomplete="off" class="layui-input">
|
||||
<div class="layui-form-mid layui-word-aux">数字越小越靠前</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">首页显示</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="checkbox" name="is_show" lay-skin="switch" lay-text="是|否" checked>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">分类显示</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="checkbox" name="is_fenlei" lay-skin="switch" lay-text="是|否">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">分类名称</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="fl_name" placeholder="请输入分类显示名称" autocomplete="off" class="layui-input">
|
||||
<div class="layui-form-mid layui-word-aux">如果分类显示为"是",则必须填写分类名称</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item layui-form-text">
|
||||
<label class="layui-form-label">备注</label>
|
||||
<div class="layui-input-block">
|
||||
<textarea name="remark" placeholder="请输入备注信息" class="layui-textarea"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<div class="layui-input-block">
|
||||
<button class="layui-btn" lay-submit lay-filter="formSubmit">立即提交</button>
|
||||
<button type="reset" class="layui-btn layui-btn-primary">重置</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{include file="Public:footer"/}
|
||||
|
||||
<script>
|
||||
layui.use(['form', 'layer'], function(){
|
||||
var $ = layui.$;
|
||||
var form = layui.form;
|
||||
var layer = layui.layer;
|
||||
|
||||
// 确保开关正确渲染
|
||||
form.render();
|
||||
|
||||
//监听提交
|
||||
form.on('submit(formSubmit)', function(data){
|
||||
// 验证分类显示和分类名称
|
||||
if(data.field.is_fenlei === 'on' && !data.field.fl_name) {
|
||||
layer.msg('分类显示选择为"是"时,必须填写分类名称', {icon: 2, time: 1500});
|
||||
return false;
|
||||
}
|
||||
|
||||
var loadIndex = layer.load(1, {shade: [0.1, '#fff']});
|
||||
$.ajax({
|
||||
url: '{:url("goodstype/add")}',
|
||||
type: 'post',
|
||||
data: data.field,
|
||||
success: function(res) {
|
||||
layer.close(loadIndex);
|
||||
if (res.status) {
|
||||
layer.msg(res.msg, {icon: 1, time: 1000}, function() {
|
||||
// 关闭当前弹出层
|
||||
var index = parent.layer.getFrameIndex(window.name);
|
||||
parent.layer.close(index);
|
||||
});
|
||||
} else {
|
||||
layer.msg(res.msg, {icon: 2, time: 1500});
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
layer.close(loadIndex);
|
||||
layer.msg('网络或服务器异常,请稍后重试', {icon: 2, time: 1500});
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
111
app/admin/view/Goods/type_edit.html
Normal file
111
app/admin/view/Goods/type_edit.html
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
{include file="Public:header2"/}
|
||||
<body>
|
||||
<div class="layui-fluid">
|
||||
<div class="layui-card">
|
||||
|
||||
<div class="layui-card-body" >
|
||||
<form class="layui-form" id="editForm" lay-filter="editForm">
|
||||
<input type="hidden" name="id" value="{$info.id}">
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">类型名称</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="name" required lay-verify="required" placeholder="请输入类型名称" autocomplete="off" class="layui-input" value="{$info.name}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">类型Key</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="number" name="value" required lay-verify="required" placeholder="请输入类型Key(数字)" autocomplete="off" class="layui-input" value="{$info.value}">
|
||||
<div class="layui-form-mid layui-word-aux">类型Key必须是唯一的数字</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">排序</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="number" name="sort_order" value="{$info.sort_order}" required lay-verify="required" placeholder="请输入排序值" autocomplete="off" class="layui-input">
|
||||
<div class="layui-form-mid layui-word-aux">数字越小越靠前</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">首页显示</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="checkbox" name="is_show" lay-skin="switch" lay-text="是|否" {if $info.is_show eq 1}checked{/if}>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">分类显示</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="checkbox" name="is_fenlei" lay-skin="switch" lay-text="是|否" {if $info.is_fenlei eq 1}checked{/if}>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">分类名称</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="fl_name" placeholder="请输入分类显示名称" autocomplete="off" class="layui-input" value="{$info.fl_name}">
|
||||
<div class="layui-form-mid layui-word-aux">如果分类显示为"是",则必须填写分类名称</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item layui-form-text">
|
||||
<label class="layui-form-label">备注</label>
|
||||
<div class="layui-input-block">
|
||||
<textarea name="remark" placeholder="请输入备注信息" class="layui-textarea">{$info.remark}</textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<div class="layui-input-block">
|
||||
<button class="layui-btn" lay-submit lay-filter="formSubmit">立即提交</button>
|
||||
<button type="reset" class="layui-btn layui-btn-primary">重置</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{include file="Public:footer"/}
|
||||
|
||||
<script>
|
||||
layui.use(['form', 'layer'], function(){
|
||||
var $ = layui.$;
|
||||
var form = layui.form;
|
||||
var layer = layui.layer;
|
||||
|
||||
// 确保开关正确渲染
|
||||
form.render();
|
||||
|
||||
//监听提交
|
||||
form.on('submit(formSubmit)', function(data){
|
||||
// 验证分类显示和分类名称
|
||||
if(data.field.is_fenlei === 'on' && !data.field.fl_name) {
|
||||
layer.msg('分类显示选择为"是"时,必须填写分类名称', {icon: 2, time: 1500});
|
||||
return false;
|
||||
}
|
||||
|
||||
var loadIndex = layer.load(1, {shade: [0.1, '#fff']});
|
||||
$.ajax({
|
||||
url: '{:url("goodstype/edit")}?id=' + data.field.id,
|
||||
type: 'post',
|
||||
data: data.field,
|
||||
success: function(res) {
|
||||
layer.close(loadIndex);
|
||||
if (res.status) {
|
||||
layer.msg(res.msg, {icon: 1, time: 1000}, function() {
|
||||
// 关闭当前弹出层
|
||||
var index = parent.layer.getFrameIndex(window.name);
|
||||
parent.layer.close(index);
|
||||
});
|
||||
} else {
|
||||
layer.msg(res.msg, {icon: 2, time: 1500});
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
layer.close(loadIndex);
|
||||
layer.msg('网络或服务器异常,请稍后重试', {icon: 2, time: 1500});
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
178
app/admin/view/Goods/type_index.html
Normal file
178
app/admin/view/Goods/type_index.html
Normal file
|
|
@ -0,0 +1,178 @@
|
|||
{include file="Public:header2"/}
|
||||
<body>
|
||||
<style>
|
||||
.layui-table-cell {
|
||||
height: auto;
|
||||
}
|
||||
</style>
|
||||
<div class="layui-fluid">
|
||||
<div class="layui-card">
|
||||
<div class="layui-card-body">
|
||||
<div class="layui-btn-group">
|
||||
<button class="layui-btn layui-btn-normal layui-btn-sm" id="add-type">新增类型</button>
|
||||
</div>
|
||||
<table id="typeTable" lay-filter="typeTable"></table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{include file="Public:footer"/}
|
||||
|
||||
<!-- 操作列模板 -->
|
||||
<script type="text/html" id="operationTpl">
|
||||
<div class="layui-btn-group">
|
||||
<button class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit">编辑</button>
|
||||
<button class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</button>
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<!-- 开关模板 -->
|
||||
<script type="text/html" id="isShowTpl">
|
||||
<input type="checkbox" name="is_show" value="{{d.is_show}}" lay-skin="switch" lay-text="是|否" lay-filter="is_show" {{d.is_show == 1 ? 'checked' : ''}} data-id="{{d.id}}">
|
||||
</script>
|
||||
|
||||
<script type="text/html" id="isFenleiTpl">
|
||||
<input type="checkbox" name="is_fenlei" value="{{d.is_fenlei}}" lay-skin="switch" lay-text="是|否" lay-filter="is_fenlei" {{d.is_fenlei == 1 ? 'checked' : ''}} data-id="{{d.id}}">
|
||||
</script>
|
||||
|
||||
<script>
|
||||
layui.use(['table', 'form', 'layer'], function() {
|
||||
var $ = layui.$;
|
||||
var form = layui.form;
|
||||
var layer = layui.layer;
|
||||
var table = layui.table;
|
||||
|
||||
// 渲染表格
|
||||
table.render({
|
||||
elem: '#typeTable',
|
||||
url: '{:url("goodstype/getTypeList")}', // 后端提供的数据接口
|
||||
page: true, // 开启分页
|
||||
height: 'full-100',
|
||||
limit: 15, // 每页显示的条数
|
||||
limits: [15, 30, 50, 100], // 每页条数的选择项
|
||||
cols: [[ // 表头
|
||||
{field: 'id', title: 'ID', width: 80, sort: true, fixed: 'left'},
|
||||
{field: 'name', title: '类型名称', width: 150},
|
||||
{field: 'value', title: '类型Key', width: 100},
|
||||
{field: 'sort_order', title: '排序', width: 100, sort: true},
|
||||
{field: 'is_show', title: '首页显示', width: 120, templet: '#isShowTpl'},
|
||||
{field: 'is_fenlei', title: '分类显示', width: 120, templet: '#isFenleiTpl'},
|
||||
{field: 'fl_name', title: '分类名称', width: 150},
|
||||
{field: 'remark', title: '备注', width: 200},
|
||||
{fixed: 'right', title: '操作', toolbar: '#operationTpl', width: 150}
|
||||
]],
|
||||
response: {
|
||||
statusCode: 1 // 重新规定成功的状态码,默认:0
|
||||
},
|
||||
parseData: function(res) { // 将原始数据解析成 table 组件所规定的数据
|
||||
return {
|
||||
"code": res.status, // 解析接口状态
|
||||
"msg": res.msg, // 解析提示文本
|
||||
"count": res.data.count, // 解析数据长度
|
||||
"data": res.data.list // 解析数据列表
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
// 监听工具条事件
|
||||
table.on('tool(typeTable)', function(obj) {
|
||||
var data = obj.data; // 获得当前行数据
|
||||
var layEvent = obj.event; // 获得 lay-event 对应的值
|
||||
|
||||
if (layEvent === 'edit') { // 编辑
|
||||
layer.open({
|
||||
type: 2,
|
||||
title: '编辑盒子类型',
|
||||
area: ['80%', '85%'],
|
||||
fixed: false,
|
||||
maxmin: true,
|
||||
content: '{:url("goodstype/edit")}?id=' + data.id,
|
||||
end: function() {
|
||||
// 弹窗关闭后刷新表格
|
||||
table.reload('typeTable');
|
||||
}
|
||||
});
|
||||
} else if (layEvent === 'del') { // 删除
|
||||
layer.confirm('确定要删除此盒子类型吗?', function(index) {
|
||||
$.ajax({
|
||||
url: '{:url("goodstype/delete")}',
|
||||
type: 'post',
|
||||
data: {id: data.id},
|
||||
success: function(res) {
|
||||
if (res.status) {
|
||||
layer.msg(res.msg, {icon: 1, time: 1000});
|
||||
// 删除成功后刷新表格
|
||||
table.reload('typeTable');
|
||||
} else {
|
||||
layer.msg(res.msg, {icon: 2, time: 1500});
|
||||
}
|
||||
}
|
||||
});
|
||||
layer.close(index);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// 新增类型
|
||||
$('#add-type').on('click', function() {
|
||||
layer.open({
|
||||
type: 2,
|
||||
title: '添加盒子类型',
|
||||
area: ['80%', '85%'],
|
||||
fixed: false,
|
||||
maxmin: true,
|
||||
content: '{:url("goodstype/add")}',
|
||||
end: function() {
|
||||
// 弹窗关闭后刷新表格
|
||||
table.reload('typeTable');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// 监听首页显示开关
|
||||
form.on('switch(is_show)', function(obj) {
|
||||
var id = $(this).data('id');
|
||||
var value = obj.elem.checked ? 1 : 0;
|
||||
|
||||
$.ajax({
|
||||
url: '{:url("goodstype/status")}',
|
||||
type: 'post',
|
||||
data: {id: id, type: 'is_show', value: value},
|
||||
success: function(res) {
|
||||
if (res.status) {
|
||||
layer.msg(res.msg, {icon: 1, time: 1000});
|
||||
} else {
|
||||
layer.msg(res.msg, {icon: 2, time: 1500}, function() {
|
||||
obj.elem.checked = !obj.elem.checked;
|
||||
form.render();
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// 监听分类显示开关
|
||||
form.on('switch(is_fenlei)', function(obj) {
|
||||
var id = $(this).data('id');
|
||||
var value = obj.elem.checked ? 1 : 0;
|
||||
|
||||
$.ajax({
|
||||
url: '{:url("goodstype/status")}',
|
||||
type: 'post',
|
||||
data: {id: id, type: 'is_fenlei', value: value},
|
||||
success: function(res) {
|
||||
if (res.status) {
|
||||
layer.msg(res.msg, {icon: 1, time: 1000});
|
||||
} else {
|
||||
layer.msg(res.msg, {icon: 2, time: 1500}, function() {
|
||||
obj.elem.checked = !obj.elem.checked;
|
||||
form.render();
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
31
app/api/controller/Config.php
Normal file
31
app/api/controller/Config.php
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\api\controller\Base;
|
||||
use think\facade\Db;
|
||||
use \think\Request;
|
||||
|
||||
class Config extends Base
|
||||
{
|
||||
/**
|
||||
* 配置信息接口
|
||||
* 返回盒子类型等配置信息
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
// 查询盒子类型数据
|
||||
$goodsTypeList = Db::name('goods_type')
|
||||
->field('value, sort_order, name')
|
||||
->where('is_show', 1)
|
||||
->order('sort_order')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
// 返回数据
|
||||
return $this->renderSuccess('获取成功', [
|
||||
'good_type' => $goodsTypeList
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -166,4 +166,7 @@ Route::any('mall_ordermoney', 'Mall/mall_ordermoney');
|
|||
Route::any('mall_orderbuy', 'Mall/mall_orderbuy');
|
||||
|
||||
// 添加API路由
|
||||
Route::rule('goods/receive_sync', 'Goods/receive_sync', 'POST');
|
||||
Route::rule('goods/receive_sync', 'Goods/receive_sync', 'POST');
|
||||
|
||||
// 配置信息接口
|
||||
Route::rule('config', 'Config/index', 'GET');
|
||||
94
app/common/model/GoodsType.php
Normal file
94
app/common/model/GoodsType.php
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
<?php
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
class GoodsType extends Model
|
||||
{
|
||||
// 设置数据表名
|
||||
protected $name = 'goods_type';
|
||||
|
||||
// 设置主键
|
||||
protected $pk = 'id';
|
||||
|
||||
// 自动写入时间戳
|
||||
protected $autoWriteTimestamp = false;
|
||||
|
||||
/**
|
||||
* 获取所有盒子类型列表
|
||||
* @param array $where 查询条件
|
||||
* @param string $order 排序
|
||||
* @return array 盒子类型列表
|
||||
*/
|
||||
public static function getList($where = [], $order = 'sort_order asc')
|
||||
{
|
||||
return self::where($where)->order($order)->select()->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单个盒子类型信息
|
||||
* @param int|array $condition 查询条件
|
||||
* @return array|null 盒子类型信息
|
||||
*/
|
||||
public static function getInfo($condition)
|
||||
{
|
||||
if (is_numeric($condition)) {
|
||||
$where = ['id' => $condition];
|
||||
} else {
|
||||
$where = $condition;
|
||||
}
|
||||
|
||||
return self::where($where)->find();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加盒子类型
|
||||
* @param array $data 盒子类型数据
|
||||
* @return int|bool 成功返回新增ID,失败返回false
|
||||
*/
|
||||
public static function add($data)
|
||||
{
|
||||
$model = new self;
|
||||
$model->save($data);
|
||||
return $model->id ? $model->id : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改盒子类型
|
||||
* @param int $id 盒子类型ID
|
||||
* @param array $data 盒子类型数据
|
||||
* @return bool 是否成功
|
||||
*/
|
||||
public static function edit($id, $data)
|
||||
{
|
||||
return self::update($data, ['id' => $id]) !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除盒子类型
|
||||
* @param int $id 盒子类型ID
|
||||
* @return bool 是否成功
|
||||
*/
|
||||
public static function remove($id)
|
||||
{
|
||||
return self::destroy($id) !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有可用的盒子类型
|
||||
* @return array 盒子类型列表
|
||||
*/
|
||||
public static function getShowList()
|
||||
{
|
||||
return self::where('is_show', 1)->order('sort_order asc')->select()->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有可显示在分类中的盒子类型
|
||||
* @return array 分类列表
|
||||
*/
|
||||
public static function getFenleiList()
|
||||
{
|
||||
return self::where('is_fenlei', 1)->order('sort_order asc')->select()->toArray();
|
||||
}
|
||||
}
|
||||
|
|
@ -106,6 +106,10 @@ return [
|
|||
// 'url' => '/admin/yushou_rili',
|
||||
// 'name' => '预售日历',
|
||||
// ],
|
||||
[
|
||||
'title' => '盒子类型管理',
|
||||
'url' => '/admin/goodstype/index',
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
|
|
|
|||
|
|
@ -66,6 +66,10 @@ return [
|
|||
'url' => '/admin/goods',
|
||||
'name' => '盒子列表',
|
||||
],
|
||||
[
|
||||
'name' => '盒子类型管理',
|
||||
'url' => '/admin/goodstype/index',
|
||||
],
|
||||
[
|
||||
'url' => '/admin/card_shang',
|
||||
'name' => '抽奖等级设置',
|
||||
|
|
@ -220,10 +224,8 @@ return [
|
|||
],
|
||||
[
|
||||
'url' => '/admin/wechatofficialaccount',
|
||||
'name' => '微信公众号',
|
||||
'name' => '公众号支付',
|
||||
],
|
||||
|
||||
|
||||
[
|
||||
'url' => '/admin/systemconfig',
|
||||
'name' => '系统设置',
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user