From 227f12443e1401c56973e108b773fbbbce10ffc2 Mon Sep 17 00:00:00 2001 From: manghe Date: Sat, 22 Mar 2025 00:27:51 +0000 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/Goods.php | 31 +++- app/admin/controller/GoodsType.php | 213 +++++++++++++++++++++++++++ app/admin/route/app.php | 11 +- app/admin/view/Goods/goods.html | 12 +- app/admin/view/Goods/goods_add.html | 23 +-- app/admin/view/Goods/goods_edit.html | 21 +-- app/admin/view/Goods/type_add.html | 110 ++++++++++++++ app/admin/view/Goods/type_edit.html | 111 ++++++++++++++ app/admin/view/Goods/type_index.html | 178 ++++++++++++++++++++++ app/api/controller/Config.php | 31 ++++ app/api/route/app.php | 5 +- app/common/model/GoodsType.php | 94 ++++++++++++ app/config/menu.php | 4 + config/menu.php | 8 +- 14 files changed, 799 insertions(+), 53 deletions(-) create mode 100644 app/admin/controller/GoodsType.php create mode 100644 app/admin/view/Goods/type_add.html create mode 100644 app/admin/view/Goods/type_edit.html create mode 100644 app/admin/view/Goods/type_index.html create mode 100644 app/api/controller/Config.php create mode 100644 app/common/model/GoodsType.php diff --git a/app/admin/controller/Goods.php b/app/admin/controller/Goods.php index 481b66e..0ecb5b2 100755 --- a/app/admin/controller/Goods.php +++ b/app/admin/controller/Goods.php @@ -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); diff --git a/app/admin/controller/GoodsType.php b/app/admin/controller/GoodsType.php new file mode 100644 index 0000000..82b14be --- /dev/null +++ b/app/admin/controller/GoodsType.php @@ -0,0 +1,213 @@ +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 + ]); + } +} \ No newline at end of file diff --git a/app/admin/route/app.php b/app/admin/route/app.php index ea7ae92..5ebcfad 100755 --- a/app/admin/route/app.php +++ b/app/admin/route/app.php @@ -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'); \ No newline at end of file +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'); \ No newline at end of file diff --git a/app/admin/view/Goods/goods.html b/app/admin/view/Goods/goods.html index ef2bcec..3066942 100755 --- a/app/admin/view/Goods/goods.html +++ b/app/admin/view/Goods/goods.html @@ -25,15 +25,9 @@
diff --git a/app/admin/view/Goods/goods_add.html b/app/admin/view/Goods/goods_add.html index 9054764..1c09435 100755 --- a/app/admin/view/Goods/goods_add.html +++ b/app/admin/view/Goods/goods_add.html @@ -12,26 +12,9 @@
- - - - - - - - - - - + {volist name="goodsTypeList" id="vo"} + + {/volist}
diff --git a/app/admin/view/Goods/goods_edit.html b/app/admin/view/Goods/goods_edit.html index b0714b9..b2ef5a0 100755 --- a/app/admin/view/Goods/goods_edit.html +++ b/app/admin/view/Goods/goods_edit.html @@ -12,24 +12,9 @@
- - - - - - - - - + {volist name="goodsTypeList" id="vo"} + + {/volist}
diff --git a/app/admin/view/Goods/type_add.html b/app/admin/view/Goods/type_add.html new file mode 100644 index 0000000..8b026ef --- /dev/null +++ b/app/admin/view/Goods/type_add.html @@ -0,0 +1,110 @@ +{include file="Public:header2"/} + +
+
+ +
+
+
+ +
+ +
+
+
+ +
+ +
类型Key必须是唯一的数字
+
+
+
+ +
+ +
数字越小越靠前
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
如果分类显示为"是",则必须填写分类名称
+
+
+
+ +
+ +
+
+
+
+ + +
+
+
+
+
+
+ +{include file="Public:footer"/} + + + + \ No newline at end of file diff --git a/app/admin/view/Goods/type_edit.html b/app/admin/view/Goods/type_edit.html new file mode 100644 index 0000000..b8bcb26 --- /dev/null +++ b/app/admin/view/Goods/type_edit.html @@ -0,0 +1,111 @@ +{include file="Public:header2"/} + +
+
+ +
+
+ +
+ +
+ +
+
+
+ +
+ +
类型Key必须是唯一的数字
+
+
+
+ +
+ +
数字越小越靠前
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
如果分类显示为"是",则必须填写分类名称
+
+
+
+ +
+ +
+
+
+
+ + +
+
+
+
+
+
+ +{include file="Public:footer"/} + + + + \ No newline at end of file diff --git a/app/admin/view/Goods/type_index.html b/app/admin/view/Goods/type_index.html new file mode 100644 index 0000000..e356e0e --- /dev/null +++ b/app/admin/view/Goods/type_index.html @@ -0,0 +1,178 @@ +{include file="Public:header2"/} + + +
+
+
+
+ +
+
+
+
+
+ +{include file="Public:footer"/} + + + + + + + + + + + + \ No newline at end of file diff --git a/app/api/controller/Config.php b/app/api/controller/Config.php new file mode 100644 index 0000000..e3cb681 --- /dev/null +++ b/app/api/controller/Config.php @@ -0,0 +1,31 @@ +field('value, sort_order, name') + ->where('is_show', 1) + ->order('sort_order') + ->select() + ->toArray(); + + // 返回数据 + return $this->renderSuccess('获取成功', [ + 'good_type' => $goodsTypeList + ]); + } +} \ No newline at end of file diff --git a/app/api/route/app.php b/app/api/route/app.php index a017703..25bca7e 100755 --- a/app/api/route/app.php +++ b/app/api/route/app.php @@ -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'); \ No newline at end of file +Route::rule('goods/receive_sync', 'Goods/receive_sync', 'POST'); + +// 配置信息接口 +Route::rule('config', 'Config/index', 'GET'); \ No newline at end of file diff --git a/app/common/model/GoodsType.php b/app/common/model/GoodsType.php new file mode 100644 index 0000000..048cc25 --- /dev/null +++ b/app/common/model/GoodsType.php @@ -0,0 +1,94 @@ +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(); + } +} \ No newline at end of file diff --git a/app/config/menu.php b/app/config/menu.php index d8cc4b9..10f0510 100755 --- a/app/config/menu.php +++ b/app/config/menu.php @@ -106,6 +106,10 @@ return [ // 'url' => '/admin/yushou_rili', // 'name' => '预售日历', // ], + [ + 'title' => '盒子类型管理', + 'url' => '/admin/goodstype/index', + ], ], ], [ diff --git a/config/menu.php b/config/menu.php index ad837b9..116578f 100755 --- a/config/menu.php +++ b/config/menu.php @@ -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' => '系统设置',