From 3a5edfe0f8d46c9c1e4a4f71ec6e42163e8f99ab Mon Sep 17 00:00:00 2001 From: wangxiaowei Date: Fri, 26 Jul 2024 22:21:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=83=AD=E9=94=80=E6=A6=9C?= =?UTF-8?q?=E5=8D=95=E5=92=8C=E6=96=B0=E5=93=81=E6=8E=A8=E8=8D=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/HotList.php | 79 ++++++++++++++++++++++++++++++ app/admin/controller/NewGoods.php | 77 +++++++++++++++++++++++++++++ app/admin/view/new_goods/add.html | 80 +++++++++++++++++++++++++++++++ app/api/controller/Goods.php | 12 +++++ app/api/logic/GoodsLogic.php | 46 +++++++++++++++++- 5 files changed, 293 insertions(+), 1 deletion(-) create mode 100644 app/admin/controller/HotList.php create mode 100644 app/admin/controller/NewGoods.php create mode 100644 app/admin/view/new_goods/add.html diff --git a/app/admin/controller/HotList.php b/app/admin/controller/HotList.php new file mode 100644 index 00000000..8ce4859b --- /dev/null +++ b/app/admin/controller/HotList.php @@ -0,0 +1,79 @@ +request->isAjax()) { + $get = $this->request->get(); + $lists = HotListLogic::lists($get); + return JsonServer::success('', $lists); + } + return view(); + } + + public function add() + { + if ($this->request->isAjax()) { + $form = $this->request->post(); + $result = HotListLogic::create($form); + if ($result['code'] == 1) { + return JsonServer::success('添加成功'); + } + return JsonServer::error($result['msg']); + } + return view(''); + } + + // 修改 + public function audit() + { + if ($this->request->isAjax()) { + $post = $this->request->post(); + $result = HotListLogic::edit($post); + if ($result['code'] == 1) { + return JsonServer::success('修改成功'); + } + return JsonServer::error($result['msg']); + } + + $id = $this->request->get('id'); + return view('', [ + 'detail' => HotListLogic::detail($id) + ]); + } + + // 删除 + public function del() + { + if ($this->request->isAjax()) { + $post = $this->request->post(); + $result = HotListLogic::del($post['id']); + if ($result) { + return JsonServer::success('删除成功'); + } + + return JsonServer::error('删除失败'); + } + } + + // 选择商品 + public function goods() + { + if ($this->request->isAjax()) { + $get = $this->request->get(); + return JsonServer::success('', GoodsLogic::lists($get)); + } + + return view(); + } +} \ No newline at end of file diff --git a/app/admin/controller/NewGoods.php b/app/admin/controller/NewGoods.php new file mode 100644 index 00000000..9911866e --- /dev/null +++ b/app/admin/controller/NewGoods.php @@ -0,0 +1,77 @@ +request->isAjax()) { + $get = $this->request->get(); + $lists = NewGoodsLogic::lists($get); + return JsonServer::success('', $lists); + } + return view(); + } + + public function add() + { + if ($this->request->isAjax()) { + $form = $this->request->post(); + $result = NewGoodsLogic::create($form); + if ($result['code'] == 1) { + return JsonServer::success('添加成功'); + } + return JsonServer::error($result['msg']); + } + return view(''); + } + + // 修改 + public function audit() + { + if ($this->request->isAjax()) { + $post = $this->request->post(); + $result = NewGoodsLogic::edit($post); + if ($result['code'] == 1) { + return JsonServer::success('修改成功'); + } + return JsonServer::error($result['msg']); + } + + $id = $this->request->get('id'); + return view('', [ + 'detail' => NewGoodsLogic::detail($id) + ]); + } + + // 删除 + public function del() + { + if ($this->request->isAjax()) { + $post = $this->request->post(); + $result = NewGoodsLogic::del($post['id']); + if ($result) { + return JsonServer::success('删除成功'); + } + + return JsonServer::error('删除失败'); + } + } + + // 选择商品 + public function goods() + { + if ($this->request->isAjax()) { + $get = $this->request->get(); + return JsonServer::success('', GoodsLogic::lists($get)); + } + + return view(); + } +} \ No newline at end of file diff --git a/app/admin/view/new_goods/add.html b/app/admin/view/new_goods/add.html new file mode 100644 index 00000000..d2976c5d --- /dev/null +++ b/app/admin/view/new_goods/add.html @@ -0,0 +1,80 @@ +{layout name="layout2" /} + + +
+
+
+ +
+
+ + 选择商品 +
+
+ +
+ +
+ +
+
+
+
+ +
+
+ + + + \ No newline at end of file diff --git a/app/api/controller/Goods.php b/app/api/controller/Goods.php index 3efdc8a8..50f59fa4 100644 --- a/app/api/controller/Goods.php +++ b/app/api/controller/Goods.php @@ -302,6 +302,7 @@ class Goods extends Api } } + // 2024-07-26 新版获取热销榜单 public function hotList() { @@ -311,4 +312,15 @@ class Goods extends Api return JsonServer::success('获取成功', $list); } + + public function newGoodsList() + { + // 等于1是获取4条推荐商品 等于2是获取全部的商品 + $type = $this->request->get('type'); + $page = $this->request->get('page_no', $this->page_no); + $size = $this->request->get('page_size', $this->page_size); + + $list = GoodsLogic::goodsList($type, $page, $size); + return JsonServer::success('获取成功', $list); + } } \ No newline at end of file diff --git a/app/api/logic/GoodsLogic.php b/app/api/logic/GoodsLogic.php index 5316c495..b9684e37 100644 --- a/app/api/logic/GoodsLogic.php +++ b/app/api/logic/GoodsLogic.php @@ -897,7 +897,7 @@ class GoodsLogic extends Logic ->alias('hl') ->join('goods g', 'hl.goods_id = g.id') ->where('delete_time', 0) - ->field('hl.id as hl_id, hl.goods_id, g.id as id, g.name, g.image, g.issuing_price, g.market_price, g.min_price, g.purchase_price, g.wholesale_price') + ->field('hl.id as hl_id, g.id as id, g.name, g.image, g.issuing_price, g.market_price, g.min_price, g.purchase_price, g.wholesale_price') ->select() ->toArray(); foreach ($hot_list as &$v) { @@ -950,4 +950,48 @@ class GoodsLogic extends Logic return $data; } + + public static function goodsList($type, $page, $size) { + if ($type == 'recommend') { + $list = Db::name('new_goods') + ->alias('ng') + ->join('goods g', 'ng.goods_id = g.id') + ->where('delete_time', 0) + ->field('ng.id as ng_id, g.id as id, g.name, g.image, g.issuing_price, g.market_price, g.min_price, g.purchase_price, g.wholesale_price') + ->limit(4) + ->select() + ->toArray(); + foreach ($list as &$v) { + if (isset($v['image'])) { + $v['image'] = UrlServer::getFileUrl($v['image']); + } + } + return $list; + } else if ($type == 'all') { + $list = Db::name('new_goods') + ->alias('ng') + ->join('goods g', 'ng.goods_id = g.id') + ->where('delete_time', 0) + ->field('ng.id as ng_id, g.id as id, g.name, g.image, g.issuing_price, g.market_price, g.min_price, g.purchase_price, g.wholesale_price') + ->select() + ->toArray(); + + $count = Db::name('new_goods')->count(); + foreach ($list as &$v) { + if (isset($v['image'])) { + $v['image'] = UrlServer::getFileUrl($v['image']); + } + } + + $more = is_more($count, $page, $size); //是否有下一页 + + return [ + 'lists' => $list, + 'page_no' => $page, + 'page_size' => $size, + 'count' => $count, + 'more' => $more + ]; + } + } }