首页水果分页查询完善+购物车模块
This commit is contained in:
parent
0736256395
commit
4a2a77e59a
@ -8,7 +8,7 @@
|
|||||||
// | Author: CRMEB Team <admin@crmeb.com>
|
// | Author: CRMEB Team <admin@crmeb.com>
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
//移动端商城API
|
//移动端商城API
|
||||||
let domain = 'http://192.168.2.123:8084'
|
let domain = 'http://192.168.2.192:8084'
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
// 请求域名 格式: https://您的域名
|
// 请求域名 格式: https://您的域名
|
||||||
|
|||||||
@ -31,12 +31,12 @@ spring:
|
|||||||
type: com.alibaba.druid.pool.DruidDataSource
|
type: com.alibaba.druid.pool.DruidDataSource
|
||||||
driver-class-name: com.mysql.jdbc.Driver
|
driver-class-name: com.mysql.jdbc.Driver
|
||||||
url: jdbc:mysql://127.0.0.1:3306/crmeb?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimeZone=GMT+8
|
url: jdbc:mysql://127.0.0.1:3306/crmeb?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimeZone=GMT+8
|
||||||
username: root
|
username: crmeb
|
||||||
password: z2003m10L15
|
password: 111111
|
||||||
redis:
|
redis:
|
||||||
host: 127.0.0.1 #地址
|
host: 127.0.0.1 #地址
|
||||||
port: 6379 #端口
|
port: 6379 #端口
|
||||||
password:
|
password: 111111
|
||||||
timeout: 10000 # 连接超时时间(毫秒)
|
timeout: 10000 # 连接超时时间(毫秒)
|
||||||
database: 3 #默认数据库
|
database: 3 #默认数据库
|
||||||
jedis:
|
jedis:
|
||||||
|
|||||||
@ -25,12 +25,12 @@ spring:
|
|||||||
type: com.alibaba.druid.pool.DruidDataSource
|
type: com.alibaba.druid.pool.DruidDataSource
|
||||||
driver-class-name: com.mysql.jdbc.Driver
|
driver-class-name: com.mysql.jdbc.Driver
|
||||||
url: jdbc:mysql://127.0.0.1:3306/crmeb?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimeZone=GMT+8
|
url: jdbc:mysql://127.0.0.1:3306/crmeb?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimeZone=GMT+8
|
||||||
username: root
|
username: crmeb
|
||||||
password: z2003m10L15
|
password: 111111
|
||||||
redis:
|
redis:
|
||||||
host: 127.0.0.1 #地址
|
host: 127.0.0.1 #地址
|
||||||
port: 6379 #端口
|
port: 6379 #端口
|
||||||
password:
|
password: 111111
|
||||||
timeout: 10000 # 连接超时时间(毫秒)
|
timeout: 10000 # 连接超时时间(毫秒)
|
||||||
database: 10 #默认数据库
|
database: 10 #默认数据库
|
||||||
jedis:
|
jedis:
|
||||||
|
|||||||
@ -25,12 +25,12 @@ spring:
|
|||||||
type: com.alibaba.druid.pool.DruidDataSource
|
type: com.alibaba.druid.pool.DruidDataSource
|
||||||
driver-class-name: com.mysql.jdbc.Driver
|
driver-class-name: com.mysql.jdbc.Driver
|
||||||
url: jdbc:mysql://127.0.0.1:3306/crmeb?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimeZone=GMT+8
|
url: jdbc:mysql://127.0.0.1:3306/crmeb?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimeZone=GMT+8
|
||||||
username: root
|
username: crmeb
|
||||||
password: z2003m10L15
|
password: 1111111
|
||||||
redis:
|
redis:
|
||||||
host: 127.0.0.1 #地址
|
host: 127.0.0.1 #地址
|
||||||
port: 6379 #端口
|
port: 6379 #端口
|
||||||
password:
|
password: 111111
|
||||||
timeout: 10000 # 连接超时时间(毫秒)
|
timeout: 10000 # 连接超时时间(毫秒)
|
||||||
database: 15 #默认数据库
|
database: 15 #默认数据库
|
||||||
jedis:
|
jedis:
|
||||||
|
|||||||
@ -7,7 +7,7 @@ crmeb:
|
|||||||
wechat-js-api-beta: true #微信js api是否是beta版本
|
wechat-js-api-beta: true #微信js api是否是beta版本
|
||||||
asyncConfig: false #是否同步config表数据到redis
|
asyncConfig: false #是否同步config表数据到redis
|
||||||
asyncWeChatProgramTempList: false #是否同步小程序公共模板库
|
asyncWeChatProgramTempList: false #是否同步小程序公共模板库
|
||||||
imagePath: /当前项目更根目录的素材文件(绝对路径)/crmebimage/ # 服务器图片路径配置 斜杠结尾
|
imagePath: /idea/shopping2/crmeb_java/crmeb/crmeb/crmebimage/ # 服务器图片路径配置 斜杠结尾
|
||||||
database: mysql
|
database: mysql
|
||||||
|
|
||||||
# 配置端口
|
# 配置端口
|
||||||
@ -34,14 +34,13 @@ spring:
|
|||||||
locale: zh_CN
|
locale: zh_CN
|
||||||
time-zone: GMT+8
|
time-zone: GMT+8
|
||||||
date-format: yyyy-MM-dd HH:mm:ss
|
date-format: yyyy-MM-dd HH:mm:ss
|
||||||
# 数据库配置
|
#数据库配置
|
||||||
datasource:
|
datasource:
|
||||||
type: com.alibaba.druid.pool.DruidDataSource
|
type: com.alibaba.druid.pool.DruidDataSource
|
||||||
driver-class-name: com.mysql.jdbc.Driver
|
driver-class-name: com.mysql.jdbc.Driver
|
||||||
url: jdbc:mysql://127.0.0.1:3306/crmeb?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimeZone=GMT+8
|
url: jdbc:mysql://127.0.0.1:3306/crmeb?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimeZone=GMT+8
|
||||||
username: root
|
username: root
|
||||||
password: z2003m10L15
|
password: z2003m10L15
|
||||||
|
|
||||||
redis:
|
redis:
|
||||||
host: 127.0.0.1 #地址
|
host: 127.0.0.1 #地址
|
||||||
port: 6379 #端口
|
port: 6379 #端口
|
||||||
|
|||||||
@ -52,10 +52,11 @@ public class CartController {
|
|||||||
@ApiImplicitParams({
|
@ApiImplicitParams({
|
||||||
@ApiImplicitParam(name="isValid", value="类型,true-有效商品,false-无效商品", required = true),
|
@ApiImplicitParam(name="isValid", value="类型,true-有效商品,false-无效商品", required = true),
|
||||||
@ApiImplicitParam(name="page", value="页码", required = true),
|
@ApiImplicitParam(name="page", value="页码", required = true),
|
||||||
@ApiImplicitParam(name="limit", value="每页数量", required = true)
|
@ApiImplicitParam(name="limit", value="每页数量", required = true),
|
||||||
|
@ApiImplicitParam(name="keyword", value="搜索关键词", required = false)
|
||||||
})
|
})
|
||||||
public CommonResult<CommonPage<CartInfoResponse>> getList(@RequestParam Boolean isValid, @Validated PageParamRequest pageParamRequest) {
|
public CommonResult<CommonPage<CartInfoResponse>> getList(@RequestParam Boolean isValid, @RequestParam String keyword,@Validated PageParamRequest pageParamRequest) {
|
||||||
CommonPage<CartInfoResponse> restPage = CommonPage.restPage(storeCartService.getList(pageParamRequest, isValid));
|
CommonPage<CartInfoResponse> restPage = CommonPage.restPage(storeCartService.getList(pageParamRequest, isValid,keyword));
|
||||||
return CommonResult.success(restPage);
|
return CommonResult.success(restPage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -10,13 +10,11 @@ import com.zbkj.common.response.IndexProductResponse;
|
|||||||
import com.zbkj.front.service.IndexService;
|
import com.zbkj.front.service.IndexService;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParam;
|
||||||
|
import io.swagger.annotations.ApiImplicitParams;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -68,9 +66,17 @@ public class IndexController {
|
|||||||
*/
|
*/
|
||||||
@ApiOperation(value = "首页水果列表")
|
@ApiOperation(value = "首页水果列表")
|
||||||
@RequestMapping(value = "/pagelist/product/{searchStatus}", method = RequestMethod.GET)
|
@RequestMapping(value = "/pagelist/product/{searchStatus}", method = RequestMethod.GET)
|
||||||
@ApiImplicitParam(name = "searchStatus", value = "搜索类型 【0 售卖中 1 团购结束 】", dataType = "String", required = true)
|
@ApiImplicitParams({
|
||||||
public CommonResult<CommonPage<IndexProductResponse>> getProductList(@PathVariable(value = "searchStatus") String searchStatus, PageParamRequest pageParamRequest) {
|
@ApiImplicitParam(name = "searchStatus", value = "搜索类型 【0 售卖中 1 预售 2 结束】", dataType = "String", required = true),
|
||||||
return CommonResult.success(indexService.findIndexFruitList(searchStatus, pageParamRequest));
|
@ApiImplicitParam(name = "keyword", value = "搜索关键词", dataType = "String")
|
||||||
|
})
|
||||||
|
public CommonResult<List<IndexProductResponse>> getProductList(
|
||||||
|
@PathVariable(value = "searchStatus") String searchStatus,
|
||||||
|
@RequestParam(value = "keyword", required = false) String keyword,
|
||||||
|
PageParamRequest pageParamRequest) {
|
||||||
|
//分页
|
||||||
|
CommonPage<IndexProductResponse> pageResult = indexService.findIndexFruitList(searchStatus, keyword, pageParamRequest);
|
||||||
|
return CommonResult.success(pageResult.getList());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -55,7 +55,7 @@ public interface IndexService{
|
|||||||
* @param pageParamRequest
|
* @param pageParamRequest
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
CommonPage<IndexProductResponse> findIndexFruitList(String searchStatus, PageParamRequest pageParamRequest);
|
CommonPage<IndexProductResponse> findIndexFruitList(String searchStatus, String keyword,PageParamRequest pageParamRequest);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取颜色配置
|
* 获取颜色配置
|
||||||
|
|||||||
@ -22,6 +22,7 @@ import com.zbkj.common.model.user.User;
|
|||||||
import com.zbkj.front.service.IndexService;
|
import com.zbkj.front.service.IndexService;
|
||||||
import com.zbkj.service.delete.ProductUtils;
|
import com.zbkj.service.delete.ProductUtils;
|
||||||
import com.zbkj.service.service.*;
|
import com.zbkj.service.service.*;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@ -43,6 +44,7 @@ import java.util.stream.Collectors;
|
|||||||
* | Author: CRMEB Team <admin@crmeb.com>
|
* | Author: CRMEB Team <admin@crmeb.com>
|
||||||
* +----------------------------------------------------------------------
|
* +----------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
public class IndexServiceImpl implements IndexService {
|
public class IndexServiceImpl implements IndexService {
|
||||||
|
|
||||||
@ -197,24 +199,25 @@ public class IndexServiceImpl implements IndexService {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public CommonPage<IndexProductResponse> findIndexFruitList(String searchStatus, PageParamRequest pageParamRequest) {
|
public CommonPage<IndexProductResponse> findIndexFruitList(String searchStatus, String keyword, PageParamRequest pageParamRequest) {
|
||||||
//在0,1,2搜索类型范围类
|
// 验证searchStatus是否在允许的范围内
|
||||||
if (!searchStatus.equals(Constants.INDEX_FRUIT_ONGOING)
|
if (!searchStatus.equals(Constants.INDEX_FRUIT_ONGOING)
|
||||||
&& !searchStatus.equals(Constants.INDEX_FRUIT_BOOKING)
|
&& !searchStatus.equals(Constants.INDEX_FRUIT_BOOKING)
|
||||||
&& !searchStatus.equals(Constants.INDEX_FRUIT_SETTLED)) {
|
&& !searchStatus.equals(Constants.INDEX_FRUIT_SETTLED)) {
|
||||||
return CommonPage.restPage(new ArrayList<>());
|
return CommonPage.restPage(new ArrayList<>());
|
||||||
}
|
}
|
||||||
//分页查询
|
// 分页查询(传入keyword)
|
||||||
List<StoreProduct> fruitList = storeProductService.getFruitList(searchStatus, pageParamRequest);
|
List<StoreProduct> fruitList = storeProductService.getFruitList(searchStatus, keyword, pageParamRequest);
|
||||||
//查出来为空
|
log.info("fruitList: {}", fruitList);//crmebimage/public/maintain/2025/04/25/juzi.jpg
|
||||||
|
// 查出来为空
|
||||||
if(CollUtil.isEmpty(fruitList)) {
|
if(CollUtil.isEmpty(fruitList)) {
|
||||||
return CommonPage.restPage(new ArrayList<>());
|
return CommonPage.restPage(new ArrayList<>());
|
||||||
}
|
}
|
||||||
//转换为响应对象:将 List<StoreProduct> 转换为 List<IndexProductResponse>
|
// 转换为响应对象
|
||||||
List<IndexProductResponse> responseList = fruitList.stream()
|
List<IndexProductResponse> responseList = fruitList.stream()
|
||||||
.map(this::convertToIndexProductResponse)
|
.map(this::convertToIndexProductResponse)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
// 4. 封装分页响应
|
log.info("responseList: {}", responseList);
|
||||||
return CommonPage.restPage(responseList);
|
return CommonPage.restPage(responseList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -15,7 +15,7 @@ spring:
|
|||||||
driver-class-name: com.mysql.jdbc.Driver
|
driver-class-name: com.mysql.jdbc.Driver
|
||||||
url: jdbc:mysql://127.0.0.1:3306/crmeb_java_beta?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimeZone=GMT+8
|
url: jdbc:mysql://127.0.0.1:3306/crmeb_java_beta?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimeZone=GMT+8
|
||||||
username: root
|
username: root
|
||||||
password: z2003m10L15
|
password: 123456
|
||||||
redis:
|
redis:
|
||||||
host: 127.0.0.1 #地址
|
host: 127.0.0.1 #地址
|
||||||
port: 6379 #端口
|
port: 6379 #端口
|
||||||
|
|||||||
@ -15,7 +15,7 @@ spring:
|
|||||||
driver-class-name: com.mysql.jdbc.Driver
|
driver-class-name: com.mysql.jdbc.Driver
|
||||||
url: jdbc:mysql://127.0.0.1:3306/crmeb_java_dev?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimeZone=GMT+8
|
url: jdbc:mysql://127.0.0.1:3306/crmeb_java_dev?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimeZone=GMT+8
|
||||||
username: root
|
username: root
|
||||||
password: z2003m10L15
|
password: 123456
|
||||||
redis:
|
redis:
|
||||||
host: 127.0.0.1 #地址
|
host: 127.0.0.1 #地址
|
||||||
port: 6379 #端口
|
port: 6379 #端口
|
||||||
|
|||||||
@ -15,7 +15,7 @@ spring:
|
|||||||
driver-class-name: com.mysql.jdbc.Driver
|
driver-class-name: com.mysql.jdbc.Driver
|
||||||
url: jdbc:mysql://127.0.0.1:3306/crmeb_java?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimeZone=GMT+8
|
url: jdbc:mysql://127.0.0.1:3306/crmeb_java?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimeZone=GMT+8
|
||||||
username: root
|
username: root
|
||||||
password: z2003m10L15
|
password: 123456
|
||||||
redis:
|
redis:
|
||||||
host: 127.0.0.1 #地址
|
host: 127.0.0.1 #地址
|
||||||
port: 6379 #端口
|
port: 6379 #端口
|
||||||
|
|||||||
@ -32,7 +32,7 @@ public interface StoreCartService extends IService<StoreCart> {
|
|||||||
* @param isValid 是否失效
|
* @param isValid 是否失效
|
||||||
* @return 购物车列表
|
* @return 购物车列表
|
||||||
*/
|
*/
|
||||||
PageInfo<CartInfoResponse> getList(PageParamRequest pageParamRequest, boolean isValid);
|
PageInfo<CartInfoResponse> getList(PageParamRequest pageParamRequest, boolean isValid,String keyword);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取当前购物车数量
|
* 获取当前购物车数量
|
||||||
|
|||||||
@ -160,7 +160,7 @@ public interface StoreProductService extends IService<StoreProduct> {
|
|||||||
* @param pageParamRequest
|
* @param pageParamRequest
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<StoreProduct> getFruitList(String searchStatus, PageParamRequest pageParamRequest);
|
List<StoreProduct> getFruitList(String searchStatus,String keyword, PageParamRequest pageParamRequest);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取商品移动端列表
|
* 获取商品移动端列表
|
||||||
|
|||||||
@ -75,73 +75,67 @@ public class StoreCartServiceImpl extends ServiceImpl<StoreCartDao, StoreCart> i
|
|||||||
private RedisUtil redisUtil;
|
private RedisUtil redisUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 列表
|
* 购物车分页查询
|
||||||
* @param pageParamRequest 分页类参数
|
* @param pageParam
|
||||||
* @param isValid 是否失效
|
* @param isValid
|
||||||
* @return List<CartInfoResponse>
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public PageInfo<CartInfoResponse> getList(PageParamRequest pageParamRequest, boolean isValid) {
|
public PageInfo<CartInfoResponse> getList(PageParamRequest pageParam, boolean isValid,String keyword) {
|
||||||
|
// 1. 当前用户ID
|
||||||
Integer userId = userService.getUserIdException();
|
Integer userId = userService.getUserIdException();
|
||||||
Page<StoreCart> page = PageHelper.startPage(pageParamRequest.getPage(), pageParamRequest.getLimit());
|
// 2. 构建查询条件
|
||||||
//带 StoreCart 类的多条件查询
|
LambdaQueryWrapper<StoreCart> query = new LambdaQueryWrapper<StoreCart>()
|
||||||
LambdaQueryWrapper<StoreCart> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
.eq(StoreCart::getUid, userId) //where userid = #{userid}
|
||||||
lambdaQueryWrapper.eq(StoreCart::getUid, userId);
|
.orderByDesc(StoreCart::getId);//购物车表里商品id
|
||||||
lambdaQueryWrapper.eq(StoreCart::getStatus, isValid);
|
// 3. 按有效性筛选(可选)
|
||||||
lambdaQueryWrapper.eq(StoreCart::getIsNew, false);
|
// if (isValid != null) {
|
||||||
lambdaQueryWrapper.orderByDesc(StoreCart::getId);
|
// query.eq(StoreCart::getStatus, isValid);//筛选有效和失效商品
|
||||||
List<StoreCart> storeCarts = dao.selectList(lambdaQueryWrapper);
|
// }
|
||||||
if (CollUtil.isEmpty(storeCarts)) {
|
// 4. 关键词搜索(支持商品名称模糊查询)
|
||||||
return CommonPage.copyPageInfo(page, new ArrayList<>());
|
if (StrUtil.isNotBlank(keyword)) {
|
||||||
|
query.exists(
|
||||||
|
"SELECT 1 FROM store_cart sc WHERE sc.product_id = id AND " +
|
||||||
|
"(sc.product_id LIKE '%" + keyword + "%' OR " + // 按ID模糊查询
|
||||||
|
"EXISTS (SELECT 1 FROM store_product sp WHERE sp.id = sc.product_id AND sp.store_name LIKE '%" + keyword + "%'))"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
// 5. 执行分页查询
|
||||||
User user = userService.getInfo();
|
Page<StoreCart> page = PageHelper.startPage(pageParam.getPage(), pageParam.getLimit());
|
||||||
SystemUserLevel userLevel = null;
|
List<StoreCart> cartItems = dao.selectList(query);
|
||||||
if (ObjectUtil.isNotNull(user) && user.getLevel() > 0) {
|
// 6. 转换为响应对象
|
||||||
userLevel = systemUserLevelService.getByLevelId(user.getLevel());
|
List<CartInfoResponse> result = cartItems.stream().map(item -> {
|
||||||
|
CartInfoResponse resp = new CartInfoResponse();
|
||||||
|
BeanUtils.copyProperties(item, resp);
|
||||||
|
// 设置商品基本信息
|
||||||
|
StoreProduct product = storeProductService.getById(item.getProductId());
|
||||||
|
if (product != null) {
|
||||||
|
resp.setStoreName(product.getStoreName())
|
||||||
|
.setImage(product.getImage());
|
||||||
}
|
}
|
||||||
|
// 处理商品有效性
|
||||||
List<CartInfoResponse> response = new ArrayList<>();
|
if (Boolean.FALSE.equals(item.getStatus())) {
|
||||||
for (StoreCart storeCart : storeCarts) {
|
resp.setAttrStatus(false); // 标记为失效商品
|
||||||
CartInfoResponse cartInfoResponse = new CartInfoResponse();
|
return resp;
|
||||||
BeanUtils.copyProperties(storeCart, cartInfoResponse);
|
|
||||||
// 获取商品信息
|
|
||||||
StoreProduct storeProduct = storeProductService.getCartByProId(storeCart.getProductId());
|
|
||||||
cartInfoResponse.setImage(storeProduct.getImage());
|
|
||||||
cartInfoResponse.setStoreName(storeProduct.getStoreName());
|
|
||||||
|
|
||||||
if (!isValid) {// 失效商品直接掠过
|
|
||||||
cartInfoResponse.setAttrStatus(false);
|
|
||||||
response.add(cartInfoResponse);
|
|
||||||
continue ;
|
|
||||||
}
|
}
|
||||||
|
// 有效商品设置规格信息
|
||||||
// 获取对应的商品规格信息(只会有一条信息)
|
StoreProductAttrValue spec = storeProductAttrValueService.getOne(
|
||||||
List<StoreProductAttrValue> attrValueList = storeProductAttrValueService.getListByProductIdAndAttrId(storeCart.getProductId(),
|
new LambdaQueryWrapper<StoreProductAttrValue>()
|
||||||
storeCart.getProductAttrUnique(), Constants.PRODUCT_TYPE_NORMAL);
|
.eq(StoreProductAttrValue::getProductId, item.getProductId())
|
||||||
// 规格不存在即失效
|
.eq(StoreProductAttrValue::getUnique, item.getProductAttrUnique())
|
||||||
if (CollUtil.isEmpty(attrValueList)) {
|
);
|
||||||
cartInfoResponse.setAttrStatus(false);
|
if (spec != null) {
|
||||||
response.add(cartInfoResponse);
|
resp.setAttrStatus(spec.getStock() > 0)
|
||||||
continue ;
|
.setStock(spec.getStock())
|
||||||
|
.setPrice(spec.getPrice())
|
||||||
|
.setSuk(spec.getSuk())
|
||||||
|
.setImage(StrUtil.isBlank(spec.getImage()) ? resp.getImage() : spec.getImage());
|
||||||
|
} else {
|
||||||
|
resp.setAttrStatus(false); // 规格不存在则标记失效
|
||||||
}
|
}
|
||||||
StoreProductAttrValue attrValue = attrValueList.get(0);
|
return resp;
|
||||||
if (StrUtil.isNotBlank(attrValue.getImage())) {
|
}).collect(Collectors.toList());
|
||||||
cartInfoResponse.setImage(attrValue.getImage());
|
return CommonPage.copyPageInfo(page, result);
|
||||||
}
|
|
||||||
cartInfoResponse.setAttrId(attrValue.getId());
|
|
||||||
cartInfoResponse.setSuk(attrValue.getSuk());
|
|
||||||
cartInfoResponse.setPrice(attrValue.getPrice());
|
|
||||||
cartInfoResponse.setAttrId(attrValue.getId());
|
|
||||||
cartInfoResponse.setAttrStatus(attrValue.getStock() > 0);
|
|
||||||
cartInfoResponse.setStock(attrValue.getStock());
|
|
||||||
if (ObjectUtil.isNotNull(userLevel)) {
|
|
||||||
BigDecimal vipPrice = attrValue.getPrice().multiply(new BigDecimal(userLevel.getDiscount())).divide(new BigDecimal(100), 2 ,BigDecimal.ROUND_HALF_UP);
|
|
||||||
cartInfoResponse.setVipPrice(vipPrice);
|
|
||||||
}
|
|
||||||
response.add(cartInfoResponse);
|
|
||||||
}
|
|
||||||
return CommonPage.copyPageInfo(page, response);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -1156,16 +1156,22 @@ public class StoreProductServiceImpl extends ServiceImpl<StoreProductDao, StoreP
|
|||||||
* @param pageParamRequest
|
* @param pageParamRequest
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public List<StoreProduct> getFruitList(String searchStatus, PageParamRequest pageParamRequest) {
|
public List<StoreProduct> getFruitList(String searchStatus, String keyword, PageParamRequest pageParamRequest) {
|
||||||
PageHelper.startPage(pageParamRequest.getPage(), pageParamRequest.getLimit());
|
PageHelper.startPage(pageParamRequest.getPage(), pageParamRequest.getLimit());//分页
|
||||||
//使用 MyBatis-Plus 的 Lambda 表达式构建动态查询条件,避免硬编码字段名。
|
LambdaQueryWrapper<StoreProduct> lambdaQueryWrapper = Wrappers.lambdaQuery();//使用 MyBatis-Plus 的 Lambda 表达式构建动态查询条件,避免硬编码字段名。
|
||||||
LambdaQueryWrapper<StoreProduct> lambdaQueryWrapper = Wrappers.lambdaQuery();
|
// 选择返回字段(其他字段不返回),减少数据传输量。
|
||||||
//选择返回字段,(其他字段不返回),减少数据传输量。
|
|
||||||
lambdaQueryWrapper.select(StoreProduct::getId, StoreProduct::getImage, StoreProduct::getStoreName,
|
lambdaQueryWrapper.select(StoreProduct::getId, StoreProduct::getImage, StoreProduct::getStoreName,
|
||||||
StoreProduct::getPrice, StoreProduct::getOtPrice, StoreProduct::getActivity,StoreProduct::getSize,StoreProduct::getDimensions);
|
StoreProduct::getPrice, StoreProduct::getOtPrice, StoreProduct::getActivity,
|
||||||
//根据 type 的值,添加不同的筛选条件(如 is_best=true 表示精品推荐商品)。
|
StoreProduct::getSize, StoreProduct::getDimensions);
|
||||||
lambdaQueryWrapper.eq(StoreProduct::getSearchStatus, searchStatus); // where searchStatus = ${searchStatus}
|
// 基础条件:按searchStatus筛选
|
||||||
//排序
|
lambdaQueryWrapper.eq(StoreProduct::getSearchStatus, searchStatus);//where searchStatus = ${searchStatus}
|
||||||
|
// 添加关键词搜索条件(如果keyword不为空)
|
||||||
|
if (StrUtil.isNotBlank(keyword)) {
|
||||||
|
lambdaQueryWrapper.and(wrapper -> wrapper
|
||||||
|
.like(StoreProduct::getStoreName, keyword) // 商品名称模糊匹配
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// 排序
|
||||||
lambdaQueryWrapper.orderByDesc(StoreProduct::getBeginTime);
|
lambdaQueryWrapper.orderByDesc(StoreProduct::getBeginTime);
|
||||||
return dao.selectList(lambdaQueryWrapper);
|
return dao.selectList(lambdaQueryWrapper);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user