优化新品推荐商品查询

This commit is contained in:
wangxiaowei 2024-07-30 10:08:32 +08:00
parent c95f8cca8a
commit d52e177840
4 changed files with 49 additions and 28 deletions

@ -45,24 +45,6 @@ class Login extends AdminBase
*/
public function login()
{
// event('Notice', [
// 'scene' => NoticeEnum::AFTER_SALE_NOTICE_SHOP,
// 'mobile' => 15005837859,
// 'params' => [
// 'user_id' => 979,
// 'after_sale_sn' => '202306071624224802'
// ]
// ]);
event('Notice', [
'scene' => NoticeEnum::AFTER_SALE_NOTICE_SHOP_REFUND,
'mobile' => 15005837859,
'params' => [
'user_id' => 979,
'after_sale_sn' => '202306071624224802'
]
]);
dump(123);
die;
if ($this->request->isAjax()) {
$post = request()->post();
(new LoginValidate())->goCheck();

@ -313,9 +313,9 @@ class Goods extends Api
return JsonServer::success('获取成功', $list);
}
public function newGoodsList()
public function newGoods()
{
// 等于1是获取4条推荐商品 等于2是获取全部的商品
// 等于recommend是获取4条推荐商品 等于all是获取全部的商品
$type = $this->request->get('type');
$page = $this->request->get('page_no', $this->page_no);
$size = $this->request->get('page_size', $this->page_size);
@ -323,4 +323,5 @@ class Goods extends Api
$list = GoodsLogic::goodsList($type, $page, $size);
return JsonServer::success('获取成功', $list);
}
}

@ -964,12 +964,17 @@ class GoodsLogic extends Logic
}
public static function goodsList($type, $page, $size) {
$where[] = ['create_time', '>=', strtotime("today")];
$where[] = ['create_time', '<=', strtotime("tomorrow") - 1];
$onSaleWhere = [
'del' => GoodsEnum::DEL_NORMAL, // 未删除
'status' => GoodsEnum::STATUS_SHELVES, // 上架中
'audit_status' => GoodsEnum::AUDIT_STATUS_OK, // 审核通过
];
$list = $goods = [];
if ($type == 'recommend') {
$list = Db::name('new_goods')
->alias('ng')
@ -980,12 +985,26 @@ class GoodsLogic extends Logic
->limit(4)
->select()
->toArray();
foreach ($list as &$v) {
$count = count($list);
if ($count < 4) {
$goods = Db::name('goods')
->where($where)
->where($onSaleWhere)
->limit(4 - $count)
->order('create_time desc')
->select()
->toArray();
}
$result = array_merge($list, $goods);
foreach ($result as &$v) {
if (isset($v['image'])) {
$v['image'] = UrlServer::getFileUrl($v['image']);
}
}
return $list;
return $result;
} else if ($type == 'all') {
$list = Db::name('new_goods')
->alias('ng')
@ -996,8 +1015,22 @@ class GoodsLogic extends Logic
->select()
->toArray();
$count = Db::name('new_goods')->count();
foreach ($list as &$v) {
$goods = Db::name('goods')
->where($where)
->where($onSaleWhere)
->order('create_time desc')
->page($page, $size)
->select()
->toArray();
$count = Db::name('goods')
->where($where)
->where($onSaleWhere)
->count();
$result = array_merge($list, $goods);
foreach ($result as &$v) {
if (isset($v['image'])) {
$v['image'] = UrlServer::getFileUrl($v['image']);
}
@ -1006,7 +1039,7 @@ class GoodsLogic extends Logic
$more = is_more($count, $page, $size); //是否有下一页
return [
'lists' => $list,
'lists' => $result,
'page_no' => $page,
'page_size' => $size,
'count' => $count,

@ -974,10 +974,16 @@ class IndexLogic extends Logic
private static function getIndexHotList()
{
$hot_list = $order_goods = [];
$onSaleWhere = [
'del' => GoodsEnum::DEL_NORMAL, // 未删除
'status' => GoodsEnum::STATUS_SHELVES, // 上架中
'audit_status' => GoodsEnum::AUDIT_STATUS_OK, // 审核通过
];
$hot_list = Db::name('hot_list')
->alias('hl')
->join('goods g', 'hl.goods_id = g.id')
->where($onSaleWhere)
->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')
->order('sort desc')
@ -994,11 +1000,10 @@ class IndexLogic extends Logic
$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')
->field('og.goods_id, og.create_time, 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')
->order('og.create_time desc, count desc')
->select()
->toArray();
}