diff --git a/app/MyController.php b/app/MyController.php index e82cc2f..b839b3d 100755 --- a/app/MyController.php +++ b/app/MyController.php @@ -37,6 +37,19 @@ abstract class MyController extends BaseController return json($this->renderJson($status, $msg, $data)); } + /** + * 返回layui.table格式的数据 + */ + protected function renderTable($msg = 'success', $count = 0, $data = [], $code = 0) + { + return json([ + 'code' => $code, + 'msg' => $msg, + 'count' => $count, + 'data' => $data + ]); + } + /** * 获取post数据 (数组) */ diff --git a/app/admin/controller/Goods.php b/app/admin/controller/Goods.php index 86b135b..deb155c 100755 --- a/app/admin/controller/Goods.php +++ b/app/admin/controller/Goods.php @@ -20,25 +20,56 @@ class Goods extends Base */ public function goods(Request $request) { - $title = trim(input('get.title')); - $status = trim(input('get.status')); - $type = trim(input('get.type')); - $whe = array(); - if ($title) { - $whe[] = ['title', 'like', '%' . $title . '%']; - } - if ($status) { - $whe[] = ['status', '=', $status]; - } - if ($type) { - $whe[] = ['type', '=', $type]; - } else { - $whe[] = ['type', 'notIn', [4, 7]]; - } - $field = "*"; - $order = "id desc"; - $data = GoodsModel::getList($whe, $field, $order, $this->page); + return View::fetch("Goods/goods"); + } + + /** + * 获取盒子列表数据(前后端分离接口) + */ + public function getGoodsList(Request $request) + { + $page = $request->param('page/d', 1); + $limit = $request->param('limit/d', 20); + $title = $request->param('title/s', ''); + $status = $request->param('status/s', ''); + $type = $request->param('type/s', ''); + + // 构建查询条件 + $where = []; + if (!empty($title)) { + $where[] = ['title', 'like', "%{$title}%"]; + } + if ($status !== '') { + $where[] = ['status', '=', $status]; + } + if ($type !== '') { + $where[] = ['type', '=', $type]; + } + + $query = GoodsModel::where($where)->order('id desc'); + $count = $query->count(); + + $list = $query->page($page, $limit)->select()->toArray(); + + // 处理图片路径 + foreach ($list as &$item) { + $item['imgurl'] = imageUrl($item['imgurl']); + if (!empty($item['imgurl_detail'])) { + $item['imgurl_detail'] = imageUrl($item['imgurl_detail']); + } + // 添加格式化时间 + $item['addtime_text'] = date('Y-m-d H:i', $item['addtime']); + } + + return $this->renderTable('获取成功', $count, $list); + } + + /** + * 获取盒子类型列表(前后端分离接口) + */ + public function getGoodsTypeList() + { // 查询可用的盒子类型 $goodsTypeList = Db::name('goods_type') ->field('value,sort_order,remark,is_fenlei,fl_name') @@ -47,11 +78,7 @@ class Goods extends Base ->select() ->toArray(); - View::assign('goodsTypeList', $goodsTypeList); - View::assign('list', $data['list']); - View::assign('count', $data['count']); - View::assign('page', $data['page']); - return View::fetch("Goods/goods"); + return $this->renderTable('获取成功', count($goodsTypeList), $goodsTypeList); } /** diff --git a/app/admin/route/app.php b/app/admin/route/app.php index c0c167c..97449ee 100755 --- a/app/admin/route/app.php +++ b/app/admin/route/app.php @@ -150,6 +150,8 @@ Route::rule('card_set', 'CardGoods/card_set', 'GET|POST'); #Goods.php盒子管理 #============================ Route::rule('goods', 'Goods/goods', 'GET|POST'); +Route::rule('api/goods/list', 'Goods/getGoodsList', 'GET'); +Route::rule('api/goods/types', 'Goods/getGoodsTypeList', 'GET'); Route::rule('goods_add', 'Goods/goods_add', 'GET|POST'); Route::rule('goods_edit', 'Goods/goods_edit', 'GET|POST'); Route::rule('goods_del', 'Goods/goods_del', 'GET|POST'); diff --git a/app/admin/view/Goods/goods.html b/app/admin/view/Goods/goods.html index c869a7d..621eca0 100755 --- a/app/admin/view/Goods/goods.html +++ b/app/admin/view/Goods/goods.html @@ -1,212 +1,286 @@ {include file="Public:header2"/}
-