diff --git a/app/admin/logic/HotListLogic.php b/app/admin/logic/HotListLogic.php
new file mode 100644
index 00000000..6fb33c4a
--- /dev/null
+++ b/app/admin/logic/HotListLogic.php
@@ -0,0 +1,80 @@
+with(['goods'])
+ ->where('delete_time', 0)
+ ->paginate([
+ 'page' => $get['page'],
+ 'list_rows' => $get['limit'],
+ 'var_page' => 'page'
+ ])->toArray();;
+ return ['count' => $lists['total'], 'lists' => $lists['data']];
+ }
+
+ // 获取详情
+ public static function detail($id)
+ {
+ $result = HotList::with('goods')->where(['id' => $id, 'delete_time' => 0])->find();
+ return $result;
+ }
+
+ // 添加表单信息
+ public static function create($form)
+ {
+ if (!empty($form['sort']) && !is_numeric($form['sort'])) {
+ return ['code' => -1, 'msg' => '请输入整数'];
+ }
+
+ $result = HotList::create([
+ 'goods_id' => $form['goods_id'],
+ 'sort' => $form['sort'],
+ 'create_time' => time()
+ ]);
+
+ if ($result) {
+ return ['code' => 1, 'msg' => '添加成功'];
+ }
+
+ return ['code' => -1, 'msg' => '添加失败'];
+ }
+
+ // 修改表单信息
+ public static function edit($form)
+ {
+ $result = HotList::where(['id' => $form['id']])->update([
+ 'goods_id' => $form['goods_id'],
+ 'sort' => $form['sort'],
+ 'update_time' => time()
+ ]);
+
+ if ($result) {
+ return ['code' => 1, 'msg' => '修改成功'];
+ }
+
+ return ['code' => -1, 'msg' => '修改失败'];
+ }
+
+ // 删除文章
+ public static function del($id)
+ {
+ $result = HotList::where(['id' => $id])->update(['delete_time' => time()]);
+ if ($result) {
+ return true;
+ }
+ return false;
+ }
+}
\ No newline at end of file
diff --git a/app/admin/logic/NewGoodsLogic.php b/app/admin/logic/NewGoodsLogic.php
new file mode 100644
index 00000000..5a34b699
--- /dev/null
+++ b/app/admin/logic/NewGoodsLogic.php
@@ -0,0 +1,82 @@
+with(['goods' => function ($query) use ($where) {
+ $query->where($where);
+ }])
+ ->where('delete_time', 0)
+ ->paginate([
+ 'page' => $get['page'],
+ 'list_rows' => $get['limit'],
+ 'var_page' => 'page'
+ ])->toArray();;
+ return ['count' => $lists['total'], 'lists' => $lists['data']];
+ }
+
+ // 获取详情
+ public static function detail($id)
+ {
+ $result = NewGoods::with('goods')->where(['id' => $id, 'delete_time' => 0])->find();
+ return $result;
+ }
+
+ // 添加表单信息
+ public static function create($form)
+ {
+ if (!empty($form['sort']) && !is_numeric($form['sort'])) {
+ return ['code' => -1, 'msg' => '请输入整数'];
+ }
+
+ $result = NewGoods::create([
+ 'goods_id' => $form['goods_id'],
+ 'sort' => $form['sort'],
+ 'create_time' => time()
+ ]);
+
+ if ($result) {
+ return ['code' => 1, 'msg' => '添加成功'];
+ }
+
+ return ['code' => -1, 'msg' => '添加失败'];
+ }
+
+ // 修改表单信息
+ public static function edit($form)
+ {
+ $result = NewGoods::where(['id' => $form['id']])->update([
+ 'goods_id' => $form['goods_id'],
+ 'sort' => $form['sort'],
+ 'update_time' => time()
+ ]);
+
+ if ($result) {
+ return ['code' => 1, 'msg' => '修改成功'];
+ }
+
+ return ['code' => -1, 'msg' => '修改失败'];
+ }
+
+ // 删除文章
+ public static function del($id)
+ {
+ $result = NewGoods::where(['id' => $id])->update(['delete_time' => time()]);
+ if ($result) {
+ return true;
+ }
+ return false;
+ }
+}
\ No newline at end of file
diff --git a/app/admin/view/hot_list/add.html b/app/admin/view/hot_list/add.html
new file mode 100644
index 00000000..d0f29fa0
--- /dev/null
+++ b/app/admin/view/hot_list/add.html
@@ -0,0 +1,80 @@
+{layout name="layout2" /}
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/admin/view/hot_list/audit.html b/app/admin/view/hot_list/audit.html
new file mode 100644
index 00000000..43d57ec1
--- /dev/null
+++ b/app/admin/view/hot_list/audit.html
@@ -0,0 +1,80 @@
+{layout name="layout2" /}
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/admin/view/hot_list/goods.html b/app/admin/view/hot_list/goods.html
new file mode 100644
index 00000000..baf700c3
--- /dev/null
+++ b/app/admin/view/hot_list/goods.html
@@ -0,0 +1,105 @@
+{layout name="layout1" /}
+
+
+
\ No newline at end of file
diff --git a/app/admin/view/hot_list/lists.html b/app/admin/view/hot_list/lists.html
new file mode 100644
index 00000000..56392f65
--- /dev/null
+++ b/app/admin/view/hot_list/lists.html
@@ -0,0 +1,181 @@
+{layout name="layout1" /}
+
+
+
\ No newline at end of file
diff --git a/app/admin/view/mall_news/audit.html b/app/admin/view/mall_news/audit.html
index 5b871f41..3aaf8430 100644
--- a/app/admin/view/mall_news/audit.html
+++ b/app/admin/view/mall_news/audit.html
@@ -90,7 +90,7 @@
商品:
diff --git a/app/admin/view/new_goods/audit.html b/app/admin/view/new_goods/audit.html
new file mode 100644
index 00000000..68e37b80
--- /dev/null
+++ b/app/admin/view/new_goods/audit.html
@@ -0,0 +1,80 @@
+{layout name="layout2" /}
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/admin/view/new_goods/goods.html b/app/admin/view/new_goods/goods.html
new file mode 100644
index 00000000..9ec77d74
--- /dev/null
+++ b/app/admin/view/new_goods/goods.html
@@ -0,0 +1,105 @@
+{layout name="layout1" /}
+
+
+
\ No newline at end of file
diff --git a/app/admin/view/new_goods/lists.html b/app/admin/view/new_goods/lists.html
new file mode 100644
index 00000000..551baf10
--- /dev/null
+++ b/app/admin/view/new_goods/lists.html
@@ -0,0 +1,181 @@
+{layout name="layout1" /}
+
+
+
\ No newline at end of file
diff --git a/app/api/controller/Goods.php b/app/api/controller/Goods.php
index 6b779157..3efdc8a8 100644
--- a/app/api/controller/Goods.php
+++ b/app/api/controller/Goods.php
@@ -290,14 +290,25 @@ class Goods extends Api
}
}
+ // 根据商品名称搜索
public function searchByName()
{
if($this->request->isGet()) {
$shop_name = $this->request->get('shop_name');
- $data = GoodsLogic::searchByName($shop_name);
+ $data = GoodsLogic::searchByName($shop_name, $this->user_id);
return JsonServer::success('获取成功', $data);
}else{
return JsonServer::error('请求方式错误');
}
}
+
+ // 2024-07-26 新版获取热销榜单
+ public function hotList()
+ {
+ $page = $this->request->get('page_no', $this->page_no);
+ $size = $this->request->get('page_size', $this->page_size);
+ $list = GoodsLogic::hotList($page, $size);
+
+ return JsonServer::success('获取成功', $list);
+ }
}
\ No newline at end of file
diff --git a/app/api/controller/HotList.php b/app/api/controller/HotList.php
new file mode 100644
index 00000000..3c64f78f
--- /dev/null
+++ b/app/api/controller/HotList.php
@@ -0,0 +1,20 @@
+ GoodsEnum::AUDIT_STATUS_OK, // 审核通过
];
- $where[] = ['name', 'like', '%' . $shop_name . '%'];
+ $where[] = ['name', 'like', '%' . trim($shop_name) . '%'];
+
+ SearchRecord::create([
+ 'user_id'=>$user_id,
+ 'keyword'=>$shop_name,
+ 'count' => 1,
+ 'update_time' => time(),
+ 'del' => 0
+ ]);
+
$goods = Goods::field('id, name')
->where($onSaleWhere)
->where($where)
+ ->order('id desc')
->select()->toArray();
+ if ($goods) {
+ return $goods;
+ }
- return $goods;
+ return [];
+ }
+
+ public static function hotList($page, $size)
+ {
+ $hot_list = [];
+ if ($page == 1) {
+ $hot_list = Db::name('hot_list')
+ ->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')
+ ->select()
+ ->toArray();
+ foreach ($hot_list as &$v) {
+ if (isset($v['image'])) {
+ $v['image'] = UrlServer::getFileUrl($v['image']);
+ }
+ }
+ }
+
+ $where[] = ['og.create_time', '>=', strtotime("today")];
+ $where[] = ['og.create_time', '<=', strtotime("tomorrow") - 1];
+
+ $order_goods = Db::name('order_goods')
+ ->alias('og')
+ ->join('goods g', 'og.goods_id = g.id')
+ ->where($where)
+ ->field('og.goods_id, count(*) as count, g.id as gid, g.name, g.image, g.issuing_price, g.market_price, g.min_price, g.purchase_price, g.wholesale_price')
+ ->group('og.goods_id')
+ ->order('count desc, og.create_time desc')
+ ->page($page, $size)
+ ->select()
+ ->toArray();
+
+ $count = Db::name('order_goods')
+ ->alias('og')
+ ->where($where)
+ ->count();
+
+ foreach ($order_goods as &$v) {
+ if (isset($v['image'])) {
+ $v['image'] = UrlServer::getFileUrl($v['image']);
+ }
+ }
+
+ $more = is_more($count, $page, $size); //是否有下一页
+
+ $list = $order_goods;
+ if ($page == 1) {
+ $list = array_merge($hot_list, $order_goods);
+ }
+
+ $data = [
+ 'lists' => $list,
+ 'hot_list' => $hot_list,
+ 'page_no' => $page,
+ 'page_size' => $size,
+ 'count' => $count,
+ 'more' => $more
+ ];
+
+ return $data;
}
}
diff --git a/app/api/logic/HotListLogic.php b/app/api/logic/HotListLogic.php
new file mode 100644
index 00000000..9f992bd7
--- /dev/null
+++ b/app/api/logic/HotListLogic.php
@@ -0,0 +1,21 @@
+alias('hl')
+ ->join('goods g', 'hl.goods_id = g.id')
+ ->where('delete_time', 0)
+ ->field('hl.*, g.id as gid, g.name, g.image, g.issuing_price, g.market_price, g.min_price, g.purchase_price, g.wholesale_price')
+ ->limit(6)
+ ->select();
+
+ }
+}
\ No newline at end of file
diff --git a/app/api/logic/IndexLogic.php b/app/api/logic/IndexLogic.php
index 7d4602d2..faca22ee 100644
--- a/app/api/logic/IndexLogic.php
+++ b/app/api/logic/IndexLogic.php
@@ -230,6 +230,10 @@ class IndexLogic extends Logic
}
}
+ // 热销榜单
+ $hot_list = self::getIndexHotList();
+
+
return [
'headlines' => $headlines,
'hots' => $hots,
@@ -243,6 +247,7 @@ class IndexLogic extends Logic
'set_price_type'=>$set_price_type,
// 'mall_news' => [],
'mall_news' => $mall_news,
+ 'hot_list' => $hot_list,
];
}
@@ -965,4 +970,42 @@ class IndexLogic extends Logic
return $result;
}
+
+ private static function getIndexHotList()
+ {
+ $hot_list = Db::name('hot_list')
+ ->alias('hl')
+ ->join('goods g', 'hl.goods_id = g.id')
+ ->where('delete_time', 0)
+ ->field('hl.*, g.id as gid, g.name, g.image, g.issuing_price, g.market_price, g.min_price, g.purchase_price, g.wholesale_price')
+ ->limit(6)
+ ->select()
+ ->toArray();
+
+ $count = count($hot_list);
+ if ($count < 6) {
+ $where[] = ['og.create_time', '>=', strtotime("today")];
+ $where[] = ['og.create_time', '<=', strtotime("tomorrow") - 1];
+
+ $order_goods = Db::name('order_goods')
+ ->alias('og')
+ ->join('goods g', 'og.goods_id = g.id')
+ ->where($where)
+ ->field('og.goods_id, count(*) as count, g.id as gid, g.name, g.image, g.issuing_price, g.market_price, g.min_price, g.purchase_price, g.wholesale_price')
+ ->group('og.goods_id')
+ ->limit(6 - $count)
+ ->order('count desc, og.create_time desc')
+ ->select()
+ ->toArray();
+ }
+
+ $result = array_merge($hot_list, $order_goods);
+ foreach ($result as &$v) {
+ if (isset($v['image'])) {
+ $v['image'] = UrlServer::getFileUrl($v['image']);
+ }
+ }
+
+ return $result;
+ }
}
diff --git a/app/api/logic/NewGoodsLogic.php b/app/api/logic/NewGoodsLogic.php
new file mode 100644
index 00000000..17af907f
--- /dev/null
+++ b/app/api/logic/NewGoodsLogic.php
@@ -0,0 +1,10 @@
+belongsTo(Goods::class,'goods_id', 'id')->field('id, name, image');
+ }
+}
\ No newline at end of file
diff --git a/app/common/model/NewGoods.php b/app/common/model/NewGoods.php
new file mode 100644
index 00000000..e775fa47
--- /dev/null
+++ b/app/common/model/NewGoods.php
@@ -0,0 +1,16 @@
+belongsTo(Goods::class,'goods_id', 'id')->field('id, name, image');
+ }
+}
\ No newline at end of file