diff --git a/app/config/app.js b/app/config/app.js index 0be16b3..456803d 100644 --- a/app/config/app.js +++ b/app/config/app.js @@ -8,7 +8,7 @@ // | Author: CRMEB Team // +---------------------------------------------------------------------- //移动端商城API -let domain = 'http://192.168.2.123:8084' +let domain = 'http://192.168.2.192:8084' module.exports = { // 请求域名 格式: https://您的域名 diff --git a/crmeb/crmeb-admin/src/main/resources/application-beta.yml b/crmeb/crmeb-admin/src/main/resources/application-beta.yml index 98b9bca..367d16c 100644 --- a/crmeb/crmeb-admin/src/main/resources/application-beta.yml +++ b/crmeb/crmeb-admin/src/main/resources/application-beta.yml @@ -31,12 +31,12 @@ spring: type: com.alibaba.druid.pool.DruidDataSource 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 - username: root - password: z2003m10L15 + username: crmeb + password: 111111 redis: host: 127.0.0.1 #地址 port: 6379 #端口 - password: + password: 111111 timeout: 10000 # 连接超时时间(毫秒) database: 3 #默认数据库 jedis: diff --git a/crmeb/crmeb-admin/src/main/resources/application-dev.yml b/crmeb/crmeb-admin/src/main/resources/application-dev.yml index 0e9e168..404a815 100644 --- a/crmeb/crmeb-admin/src/main/resources/application-dev.yml +++ b/crmeb/crmeb-admin/src/main/resources/application-dev.yml @@ -25,12 +25,12 @@ spring: type: com.alibaba.druid.pool.DruidDataSource 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 - username: root - password: z2003m10L15 + username: crmeb + password: 111111 redis: host: 127.0.0.1 #地址 port: 6379 #端口 - password: + password: 111111 timeout: 10000 # 连接超时时间(毫秒) database: 10 #默认数据库 jedis: diff --git a/crmeb/crmeb-admin/src/main/resources/application-prod.yml b/crmeb/crmeb-admin/src/main/resources/application-prod.yml index bb7370d..e1544e3 100644 --- a/crmeb/crmeb-admin/src/main/resources/application-prod.yml +++ b/crmeb/crmeb-admin/src/main/resources/application-prod.yml @@ -25,12 +25,12 @@ spring: type: com.alibaba.druid.pool.DruidDataSource 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 - username: root - password: z2003m10L15 + username: crmeb + password: 1111111 redis: host: 127.0.0.1 #地址 port: 6379 #端口 - password: + password: 111111 timeout: 10000 # 连接超时时间(毫秒) database: 15 #默认数据库 jedis: diff --git a/crmeb/crmeb-admin/src/main/resources/application.yml b/crmeb/crmeb-admin/src/main/resources/application.yml index 680f029..262e92d 100644 --- a/crmeb/crmeb-admin/src/main/resources/application.yml +++ b/crmeb/crmeb-admin/src/main/resources/application.yml @@ -7,7 +7,7 @@ crmeb: wechat-js-api-beta: true #微信js api是否是beta版本 asyncConfig: false #是否同步config表数据到redis asyncWeChatProgramTempList: false #是否同步小程序公共模板库 - imagePath: /当前项目更根目录的素材文件(绝对路径)/crmebimage/ # 服务器图片路径配置 斜杠结尾 + imagePath: /idea/shopping2/crmeb_java/crmeb/crmeb/crmebimage/ # 服务器图片路径配置 斜杠结尾 database: mysql # 配置端口 @@ -34,14 +34,13 @@ spring: locale: zh_CN time-zone: GMT+8 date-format: yyyy-MM-dd HH:mm:ss - # 数据库配置 + #数据库配置 datasource: type: com.alibaba.druid.pool.DruidDataSource 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 username: root password: z2003m10L15 - redis: host: 127.0.0.1 #地址 port: 6379 #端口 diff --git a/crmeb/crmeb-front/src/main/java/com/zbkj/front/controller/CartController.java b/crmeb/crmeb-front/src/main/java/com/zbkj/front/controller/CartController.java index aa27feb..05335eb 100644 --- a/crmeb/crmeb-front/src/main/java/com/zbkj/front/controller/CartController.java +++ b/crmeb/crmeb-front/src/main/java/com/zbkj/front/controller/CartController.java @@ -52,10 +52,11 @@ public class CartController { @ApiImplicitParams({ @ApiImplicitParam(name="isValid", value="类型,true-有效商品,false-无效商品", 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> getList(@RequestParam Boolean isValid, @Validated PageParamRequest pageParamRequest) { - CommonPage restPage = CommonPage.restPage(storeCartService.getList(pageParamRequest, isValid)); + public CommonResult> getList(@RequestParam Boolean isValid, @RequestParam String keyword,@Validated PageParamRequest pageParamRequest) { + CommonPage restPage = CommonPage.restPage(storeCartService.getList(pageParamRequest, isValid,keyword)); return CommonResult.success(restPage); } diff --git a/crmeb/crmeb-front/src/main/java/com/zbkj/front/controller/IndexController.java b/crmeb/crmeb-front/src/main/java/com/zbkj/front/controller/IndexController.java index 8c7c8cc..9732047 100644 --- a/crmeb/crmeb-front/src/main/java/com/zbkj/front/controller/IndexController.java +++ b/crmeb/crmeb-front/src/main/java/com/zbkj/front/controller/IndexController.java @@ -10,13 +10,11 @@ import com.zbkj.common.response.IndexProductResponse; import com.zbkj.front.service.IndexService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import java.util.HashMap; import java.util.List; @@ -68,9 +66,17 @@ public class IndexController { */ @ApiOperation(value = "首页水果列表") @RequestMapping(value = "/pagelist/product/{searchStatus}", method = RequestMethod.GET) - @ApiImplicitParam(name = "searchStatus", value = "搜索类型 【0 售卖中 1 团购结束 】", dataType = "String", required = true) - public CommonResult> getProductList(@PathVariable(value = "searchStatus") String searchStatus, PageParamRequest pageParamRequest) { - return CommonResult.success(indexService.findIndexFruitList(searchStatus, pageParamRequest)); + @ApiImplicitParams({ + @ApiImplicitParam(name = "searchStatus", value = "搜索类型 【0 售卖中 1 预售 2 结束】", dataType = "String", required = true), + @ApiImplicitParam(name = "keyword", value = "搜索关键词", dataType = "String") + }) + public CommonResult> getProductList( + @PathVariable(value = "searchStatus") String searchStatus, + @RequestParam(value = "keyword", required = false) String keyword, + PageParamRequest pageParamRequest) { + //分页 + CommonPage pageResult = indexService.findIndexFruitList(searchStatus, keyword, pageParamRequest); + return CommonResult.success(pageResult.getList()); } /** diff --git a/crmeb/crmeb-front/src/main/java/com/zbkj/front/service/IndexService.java b/crmeb/crmeb-front/src/main/java/com/zbkj/front/service/IndexService.java index 213b7fa..0405abb 100644 --- a/crmeb/crmeb-front/src/main/java/com/zbkj/front/service/IndexService.java +++ b/crmeb/crmeb-front/src/main/java/com/zbkj/front/service/IndexService.java @@ -55,7 +55,7 @@ public interface IndexService{ * @param pageParamRequest * @return */ - CommonPage findIndexFruitList(String searchStatus, PageParamRequest pageParamRequest); + CommonPage findIndexFruitList(String searchStatus, String keyword,PageParamRequest pageParamRequest); /** * 获取颜色配置 diff --git a/crmeb/crmeb-front/src/main/java/com/zbkj/front/service/impl/IndexServiceImpl.java b/crmeb/crmeb-front/src/main/java/com/zbkj/front/service/impl/IndexServiceImpl.java index 535fe94..b992080 100644 --- a/crmeb/crmeb-front/src/main/java/com/zbkj/front/service/impl/IndexServiceImpl.java +++ b/crmeb/crmeb-front/src/main/java/com/zbkj/front/service/impl/IndexServiceImpl.java @@ -22,6 +22,7 @@ import com.zbkj.common.model.user.User; import com.zbkj.front.service.IndexService; import com.zbkj.service.delete.ProductUtils; import com.zbkj.service.service.*; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -43,6 +44,7 @@ import java.util.stream.Collectors; * | Author: CRMEB Team * +---------------------------------------------------------------------- */ +@Slf4j @Service public class IndexServiceImpl implements IndexService { @@ -197,24 +199,25 @@ public class IndexServiceImpl implements IndexService { * @return */ @Override - public CommonPage findIndexFruitList(String searchStatus, PageParamRequest pageParamRequest) { - //在0,1,2搜索类型范围类 + public CommonPage findIndexFruitList(String searchStatus, String keyword, PageParamRequest pageParamRequest) { + // 验证searchStatus是否在允许的范围内 if (!searchStatus.equals(Constants.INDEX_FRUIT_ONGOING) && !searchStatus.equals(Constants.INDEX_FRUIT_BOOKING) && !searchStatus.equals(Constants.INDEX_FRUIT_SETTLED)) { return CommonPage.restPage(new ArrayList<>()); } - //分页查询 - List fruitList = storeProductService.getFruitList(searchStatus, pageParamRequest); - //查出来为空 + // 分页查询(传入keyword) + List fruitList = storeProductService.getFruitList(searchStatus, keyword, pageParamRequest); + log.info("fruitList: {}", fruitList);//crmebimage/public/maintain/2025/04/25/juzi.jpg + // 查出来为空 if(CollUtil.isEmpty(fruitList)) { return CommonPage.restPage(new ArrayList<>()); } - //转换为响应对象:将 List 转换为 List + // 转换为响应对象 List responseList = fruitList.stream() .map(this::convertToIndexProductResponse) .collect(Collectors.toList()); - // 4. 封装分页响应 + log.info("responseList: {}", responseList); return CommonPage.restPage(responseList); } diff --git a/crmeb/crmeb-front/src/main/resources/application-beta.yml b/crmeb/crmeb-front/src/main/resources/application-beta.yml index 48482ba..007a9b8 100644 --- a/crmeb/crmeb-front/src/main/resources/application-beta.yml +++ b/crmeb/crmeb-front/src/main/resources/application-beta.yml @@ -15,7 +15,7 @@ spring: 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 username: root - password: z2003m10L15 + password: 123456 redis: host: 127.0.0.1 #地址 port: 6379 #端口 diff --git a/crmeb/crmeb-front/src/main/resources/application-dev.yml b/crmeb/crmeb-front/src/main/resources/application-dev.yml index d1ec390..b25f97b 100644 --- a/crmeb/crmeb-front/src/main/resources/application-dev.yml +++ b/crmeb/crmeb-front/src/main/resources/application-dev.yml @@ -15,7 +15,7 @@ spring: 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 username: root - password: z2003m10L15 + password: 123456 redis: host: 127.0.0.1 #地址 port: 6379 #端口 diff --git a/crmeb/crmeb-front/src/main/resources/application-prod.yml b/crmeb/crmeb-front/src/main/resources/application-prod.yml index 529f0de..bee164e 100644 --- a/crmeb/crmeb-front/src/main/resources/application-prod.yml +++ b/crmeb/crmeb-front/src/main/resources/application-prod.yml @@ -15,7 +15,7 @@ spring: 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 username: root - password: z2003m10L15 + password: 123456 redis: host: 127.0.0.1 #地址 port: 6379 #端口 diff --git a/crmeb/crmeb-service/src/main/java/com/zbkj/service/service/StoreCartService.java b/crmeb/crmeb-service/src/main/java/com/zbkj/service/service/StoreCartService.java index 3fac0c6..e75f3df 100644 --- a/crmeb/crmeb-service/src/main/java/com/zbkj/service/service/StoreCartService.java +++ b/crmeb/crmeb-service/src/main/java/com/zbkj/service/service/StoreCartService.java @@ -32,7 +32,7 @@ public interface StoreCartService extends IService { * @param isValid 是否失效 * @return 购物车列表 */ - PageInfo getList(PageParamRequest pageParamRequest, boolean isValid); + PageInfo getList(PageParamRequest pageParamRequest, boolean isValid,String keyword); /** * 获取当前购物车数量 diff --git a/crmeb/crmeb-service/src/main/java/com/zbkj/service/service/StoreProductService.java b/crmeb/crmeb-service/src/main/java/com/zbkj/service/service/StoreProductService.java index 5c4df2e..1c7bac4 100644 --- a/crmeb/crmeb-service/src/main/java/com/zbkj/service/service/StoreProductService.java +++ b/crmeb/crmeb-service/src/main/java/com/zbkj/service/service/StoreProductService.java @@ -160,7 +160,7 @@ public interface StoreProductService extends IService { * @param pageParamRequest * @return */ - List getFruitList(String searchStatus, PageParamRequest pageParamRequest); + List getFruitList(String searchStatus,String keyword, PageParamRequest pageParamRequest); /** * 获取商品移动端列表 diff --git a/crmeb/crmeb-service/src/main/java/com/zbkj/service/service/impl/StoreCartServiceImpl.java b/crmeb/crmeb-service/src/main/java/com/zbkj/service/service/impl/StoreCartServiceImpl.java index ec6094c..b7c99ec 100644 --- a/crmeb/crmeb-service/src/main/java/com/zbkj/service/service/impl/StoreCartServiceImpl.java +++ b/crmeb/crmeb-service/src/main/java/com/zbkj/service/service/impl/StoreCartServiceImpl.java @@ -75,73 +75,67 @@ public class StoreCartServiceImpl extends ServiceImpl i private RedisUtil redisUtil; /** - * 列表 - * @param pageParamRequest 分页类参数 - * @param isValid 是否失效 - * @return List - */ + * 购物车分页查询 + * @param pageParam + * @param isValid + * @return + */ @Override - public PageInfo getList(PageParamRequest pageParamRequest, boolean isValid) { + public PageInfo getList(PageParamRequest pageParam, boolean isValid,String keyword) { + // 1. 当前用户ID Integer userId = userService.getUserIdException(); - Page page = PageHelper.startPage(pageParamRequest.getPage(), pageParamRequest.getLimit()); - //带 StoreCart 类的多条件查询 - LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); - lambdaQueryWrapper.eq(StoreCart::getUid, userId); - lambdaQueryWrapper.eq(StoreCart::getStatus, isValid); - lambdaQueryWrapper.eq(StoreCart::getIsNew, false); - lambdaQueryWrapper.orderByDesc(StoreCart::getId); - List storeCarts = dao.selectList(lambdaQueryWrapper); - if (CollUtil.isEmpty(storeCarts)) { - return CommonPage.copyPageInfo(page, new ArrayList<>()); + // 2. 构建查询条件 + LambdaQueryWrapper query = new LambdaQueryWrapper() + .eq(StoreCart::getUid, userId) //where userid = #{userid} + .orderByDesc(StoreCart::getId);//购物车表里商品id + // 3. 按有效性筛选(可选) +// if (isValid != null) { +// query.eq(StoreCart::getStatus, isValid);//筛选有效和失效商品 +// } + // 4. 关键词搜索(支持商品名称模糊查询) + 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 + "%'))" + ); } - - User user = userService.getInfo(); - SystemUserLevel userLevel = null; - if (ObjectUtil.isNotNull(user) && user.getLevel() > 0) { - userLevel = systemUserLevelService.getByLevelId(user.getLevel()); - } - - List response = new ArrayList<>(); - for (StoreCart storeCart : storeCarts) { - CartInfoResponse cartInfoResponse = new CartInfoResponse(); - 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 ; + // 5. 执行分页查询 + Page page = PageHelper.startPage(pageParam.getPage(), pageParam.getLimit()); + List cartItems = dao.selectList(query); + // 6. 转换为响应对象 + List 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 attrValueList = storeProductAttrValueService.getListByProductIdAndAttrId(storeCart.getProductId(), - storeCart.getProductAttrUnique(), Constants.PRODUCT_TYPE_NORMAL); - // 规格不存在即失效 - if (CollUtil.isEmpty(attrValueList)) { - cartInfoResponse.setAttrStatus(false); - response.add(cartInfoResponse); - continue ; + // 处理商品有效性 + if (Boolean.FALSE.equals(item.getStatus())) { + resp.setAttrStatus(false); // 标记为失效商品 + return resp; } - StoreProductAttrValue attrValue = attrValueList.get(0); - if (StrUtil.isNotBlank(attrValue.getImage())) { - cartInfoResponse.setImage(attrValue.getImage()); + // 有效商品设置规格信息 + StoreProductAttrValue spec = storeProductAttrValueService.getOne( + new LambdaQueryWrapper() + .eq(StoreProductAttrValue::getProductId, item.getProductId()) + .eq(StoreProductAttrValue::getUnique, item.getProductAttrUnique()) + ); + if (spec != null) { + resp.setAttrStatus(spec.getStock() > 0) + .setStock(spec.getStock()) + .setPrice(spec.getPrice()) + .setSuk(spec.getSuk()) + .setImage(StrUtil.isBlank(spec.getImage()) ? resp.getImage() : spec.getImage()); + } else { + resp.setAttrStatus(false); // 规格不存在则标记失效 } - 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); + return resp; + }).collect(Collectors.toList()); + return CommonPage.copyPageInfo(page, result); } /** diff --git a/crmeb/crmeb-service/src/main/java/com/zbkj/service/service/impl/StoreProductServiceImpl.java b/crmeb/crmeb-service/src/main/java/com/zbkj/service/service/impl/StoreProductServiceImpl.java index 4edb3fe..345029d 100644 --- a/crmeb/crmeb-service/src/main/java/com/zbkj/service/service/impl/StoreProductServiceImpl.java +++ b/crmeb/crmeb-service/src/main/java/com/zbkj/service/service/impl/StoreProductServiceImpl.java @@ -1156,16 +1156,22 @@ public class StoreProductServiceImpl extends ServiceImpl getFruitList(String searchStatus, PageParamRequest pageParamRequest) { - PageHelper.startPage(pageParamRequest.getPage(), pageParamRequest.getLimit()); - //使用 MyBatis-Plus 的 Lambda 表达式构建动态查询条件,避免硬编码字段名。 - LambdaQueryWrapper lambdaQueryWrapper = Wrappers.lambdaQuery(); - //选择返回字段,(其他字段不返回),减少数据传输量。 + public List getFruitList(String searchStatus, String keyword, PageParamRequest pageParamRequest) { + PageHelper.startPage(pageParamRequest.getPage(), pageParamRequest.getLimit());//分页 + LambdaQueryWrapper lambdaQueryWrapper = Wrappers.lambdaQuery();//使用 MyBatis-Plus 的 Lambda 表达式构建动态查询条件,避免硬编码字段名。 + // 选择返回字段(其他字段不返回),减少数据传输量。 lambdaQueryWrapper.select(StoreProduct::getId, StoreProduct::getImage, StoreProduct::getStoreName, - StoreProduct::getPrice, StoreProduct::getOtPrice, StoreProduct::getActivity,StoreProduct::getSize,StoreProduct::getDimensions); - //根据 type 的值,添加不同的筛选条件(如 is_best=true 表示精品推荐商品)。 - lambdaQueryWrapper.eq(StoreProduct::getSearchStatus, searchStatus); // where searchStatus = ${searchStatus} - //排序 + StoreProduct::getPrice, StoreProduct::getOtPrice, StoreProduct::getActivity, + StoreProduct::getSize, StoreProduct::getDimensions); + // 基础条件:按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); return dao.selectList(lambdaQueryWrapper); }