提交
This commit is contained in:
@ -16,7 +16,7 @@ public class StoreCartBaseVO {
|
||||
|
||||
@Schema(description = "用户ID", required = true, example = "10667")
|
||||
@NotNull(message = "用户ID不能为空")
|
||||
private Long uid;
|
||||
private Long userId;
|
||||
|
||||
@Schema(description = "类型", required = true, example = "1")
|
||||
@NotNull(message = "类型不能为空")
|
||||
|
||||
@ -15,8 +15,8 @@ import static co.yixiang.yshop.framework.common.util.date.DateUtils.FORMAT_YEAR_
|
||||
@ToString(callSuper = true)
|
||||
public class StoreCartPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "用户ID", example = "10667")
|
||||
private Long uid;
|
||||
@Schema(description = "用户昵称", example = "李四")
|
||||
private String nickname;
|
||||
|
||||
@Schema(description = "类型", example = "1")
|
||||
private String type;
|
||||
@ -24,29 +24,5 @@ public class StoreCartPageReqVO extends PageParam {
|
||||
@Schema(description = "商品ID", example = "1696")
|
||||
private Long productId;
|
||||
|
||||
@Schema(description = "商品属性")
|
||||
private String productAttrUnique;
|
||||
|
||||
@Schema(description = "商品数量")
|
||||
private Short cartNum;
|
||||
|
||||
@Schema(description = "0 = 未购买 1 = 已购买")
|
||||
private Boolean isPay;
|
||||
|
||||
@Schema(description = "是否为立即购买")
|
||||
private Boolean isNew;
|
||||
|
||||
@Schema(description = "拼团id", example = "13847")
|
||||
private Integer combinationId;
|
||||
|
||||
@Schema(description = "秒杀产品ID", example = "8790")
|
||||
private Integer seckillId;
|
||||
|
||||
@Schema(description = "砍价id", example = "21581")
|
||||
private Integer bargainId;
|
||||
|
||||
@Schema(description = "添加时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] createTime;
|
||||
|
||||
}
|
||||
|
||||
@ -10,16 +10,16 @@ import java.time.LocalDateTime;
|
||||
@ToString(callSuper = true)
|
||||
public class StoreCartRespVO extends StoreCartBaseVO {
|
||||
|
||||
@Schema(description = "购物车表ID", required = true, example = "11256")
|
||||
@Schema(description = "购物车表ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "11256")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "添加时间", required = true)
|
||||
@Schema(description = "添加时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@Schema(description = "商品名称", required = true)
|
||||
private String StoreName;
|
||||
@Schema(description = "商品名称", requiredMode = Schema.RequiredMode.REQUIRED )
|
||||
private String storeName;
|
||||
|
||||
@Schema(description = "用户昵称", required = true)
|
||||
@Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private String nickname;
|
||||
|
||||
}
|
||||
|
||||
@ -10,11 +10,15 @@ package co.yixiang.yshop.module.cart.controller.app.cart;
|
||||
|
||||
import co.yixiang.yshop.framework.common.pojo.CommonResult;
|
||||
import co.yixiang.yshop.framework.security.core.annotations.PreAuthenticated;
|
||||
import co.yixiang.yshop.module.cart.controller.app.cart.param.AppCartChangeSkuParam;
|
||||
import co.yixiang.yshop.module.cart.controller.app.cart.param.AppCartIdsParm;
|
||||
import co.yixiang.yshop.module.cart.controller.app.cart.param.AppCartNumParam;
|
||||
import co.yixiang.yshop.module.cart.controller.app.cart.param.AppCartParam;
|
||||
import co.yixiang.yshop.module.cart.service.storecart.AppStoreCartService;
|
||||
import co.yixiang.yshop.module.product.controller.app.couponrelation.vo.CartCouponVO;
|
||||
import co.yixiang.yshop.module.product.controller.app.couponrelation.vo.UserCouponVO;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -23,6 +27,7 @@ import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static co.yixiang.yshop.framework.common.pojo.CommonResult.success;
|
||||
@ -110,6 +115,24 @@ public class AppCartController {
|
||||
return success(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 购物车更换sku
|
||||
*/
|
||||
@PreAuthenticated
|
||||
@PostMapping("/cart/changeSku")
|
||||
@Operation(summary = "购物车更换产品规格")
|
||||
public CommonResult<Boolean> changeSku(@Validated @RequestBody AppCartChangeSkuParam param){
|
||||
Long uid = getLoginUserId();
|
||||
appStoreCartService.changeSku(uid,param);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/coupon")
|
||||
@Operation(summary = "查询购物车可用优惠券")
|
||||
@Parameter(name = "cartIds", description = "购物车id合集,用,隔开", required = true, example = "1,2")
|
||||
public CommonResult<List<CartCouponVO>> searchCartAvailableCoupon(@RequestParam String cartIds) {
|
||||
return success(appStoreCartService.searchCartAvailableCoupon(cartIds));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,28 @@
|
||||
package co.yixiang.yshop.module.cart.controller.app.cart.param;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* @ClassName CartIds
|
||||
* @Author hupeng <610796224@qq.com>
|
||||
* @Date 2023/6/17
|
||||
**/
|
||||
@Data
|
||||
@Schema(description = "用户 APP - 购物车更换商品sku")
|
||||
public class AppCartChangeSkuParam {
|
||||
|
||||
@NotNull(message = "购物车信息id参数有误")
|
||||
@Schema(description = "购物车ID", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
Long id;
|
||||
|
||||
@NotNull(message = "购物车商品id参数有误")
|
||||
@Schema(description = "商品ID", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
Long productId;
|
||||
|
||||
@NotNull(message = "购物车商品规格unique参数有误")
|
||||
@Schema(description = "商品sku规格unique", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
String productAttrUnique;
|
||||
}
|
||||
@ -1,21 +1,21 @@
|
||||
package co.yixiang.yshop.module.cart.controller.app.cart.param;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassName CartIds
|
||||
* @Author hupeng <610796224@qq.com>
|
||||
* @Date 2023/6/17
|
||||
**/
|
||||
@Data
|
||||
@Schema(description = "用户 APP - 购物车CartIds参数")
|
||||
public class AppCartIdsParm {
|
||||
|
||||
@NotNull(message = "参数有误")
|
||||
@Schema(description = "购物车ID,多个用,分隔开", required = true)
|
||||
List<String> ids;
|
||||
}
|
||||
package co.yixiang.yshop.module.cart.controller.app.cart.param;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassName CartIds
|
||||
* @Author hupeng <610796224@qq.com>
|
||||
* @Date 2023/6/17
|
||||
**/
|
||||
@Data
|
||||
@Schema(description = "用户 APP - 购物车CartIds参数")
|
||||
public class AppCartIdsParm {
|
||||
|
||||
@NotNull(message = "参数有误")
|
||||
@Schema(description = "购物车ID,多个用,分隔开", required = true)
|
||||
List<String> ids;
|
||||
}
|
||||
|
||||
@ -1,30 +1,30 @@
|
||||
package co.yixiang.yshop.module.cart.controller.app.cart.param;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import javax.validation.constraints.Max;
|
||||
import javax.validation.constraints.Min;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* @ClassName 购物车数量CartNumParam
|
||||
* @Author hupeng <610796224@qq.com>
|
||||
* @Date 2023/6/17
|
||||
**/
|
||||
@Getter
|
||||
@Setter
|
||||
@Schema(description = "用户 APP - 购物车数量参数")
|
||||
public class AppCartNumParam {
|
||||
|
||||
@Min(value = 1,message = "数量不在合法范围内")
|
||||
@Max(value = 9999,message = "数量不在合法范围内")
|
||||
@Schema(description = "购物车数量", required = true)
|
||||
private Integer number;
|
||||
|
||||
@NotNull(message = "参数有误")
|
||||
@Schema(description = "购物车ID", required = true)
|
||||
private Long id;
|
||||
|
||||
}
|
||||
package co.yixiang.yshop.module.cart.controller.app.cart.param;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import javax.validation.constraints.Max;
|
||||
import javax.validation.constraints.Min;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* @ClassName 购物车数量CartNumParam
|
||||
* @Author hupeng <610796224@qq.com>
|
||||
* @Date 2023/6/17
|
||||
**/
|
||||
@Getter
|
||||
@Setter
|
||||
@Schema(description = "用户 APP - 购物车数量参数")
|
||||
public class AppCartNumParam {
|
||||
|
||||
@Min(value = 1,message = "数量不在合法范围内")
|
||||
@Max(value = 9999,message = "数量不在合法范围内")
|
||||
@Schema(description = "购物车数量", required = true)
|
||||
private Integer number;
|
||||
|
||||
@NotNull(message = "参数有误")
|
||||
@Schema(description = "购物车ID", required = true)
|
||||
private Long id;
|
||||
|
||||
}
|
||||
|
||||
@ -1,46 +1,46 @@
|
||||
package co.yixiang.yshop.module.cart.controller.app.cart.param;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import javax.validation.constraints.Max;
|
||||
import javax.validation.constraints.Min;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* @ClassName 添加购物车CartParam
|
||||
* @Author hupeng <610796224@qq.com>
|
||||
* @Date 2023/6/16
|
||||
**/
|
||||
@Getter
|
||||
@Setter
|
||||
@Schema(description = "用户 APP - 添加购物车参数")
|
||||
public class AppCartParam {
|
||||
|
||||
@Min(value = 1,message = "数量不在合法范围内")
|
||||
@Max(value = 9999,message = "数量不在合法范围内")
|
||||
@Schema(description = "购物车数量", required = true)
|
||||
private Integer cartNum;
|
||||
|
||||
@JsonProperty(value = "new")
|
||||
@Schema(description = "是否立即购买1-是 0-否表示加入购物车列表", required = true)
|
||||
private Integer isNew = 0;
|
||||
|
||||
@NotNull(message = "参数有误")
|
||||
@Schema(description = "产品ID", required = true)
|
||||
private Long productId;
|
||||
|
||||
@Schema(description = "商品属性sku的unique值", required = true)
|
||||
private String uniqueId;
|
||||
|
||||
@Schema(description = "产品拼团ID", required = true)
|
||||
private Long combinationId = 0L;
|
||||
|
||||
@Schema(description = "产品秒杀ID", required = true)
|
||||
private Long secKillId = 0L;
|
||||
|
||||
@Schema(description = "产品砍价ID", required = true)
|
||||
private Long bargainId = 0L;
|
||||
}
|
||||
package co.yixiang.yshop.module.cart.controller.app.cart.param;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import javax.validation.constraints.Max;
|
||||
import javax.validation.constraints.Min;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* @ClassName 添加购物车CartParam
|
||||
* @Author hupeng <610796224@qq.com>
|
||||
* @Date 2023/6/16
|
||||
**/
|
||||
@Getter
|
||||
@Setter
|
||||
@Schema(description = "用户 APP - 添加购物车参数")
|
||||
public class AppCartParam {
|
||||
|
||||
@Min(value = 1,message = "数量不在合法范围内")
|
||||
@Max(value = 9999,message = "数量不在合法范围内")
|
||||
@Schema(description = "购物车数量", required = true)
|
||||
private Integer cartNum;
|
||||
|
||||
@JsonProperty(value = "new")
|
||||
@Schema(description = "是否立即购买1-是 0-否表示加入购物车列表", required = true)
|
||||
private Integer isNew = 0;
|
||||
|
||||
@NotNull(message = "参数有误")
|
||||
@Schema(description = "产品ID", required = true)
|
||||
private Long productId;
|
||||
|
||||
@Schema(description = "商品属性sku的unique值", required = true)
|
||||
private String uniqueId;
|
||||
|
||||
@Schema(description = "产品拼团ID", required = true)
|
||||
private Long combinationId = 0L;
|
||||
|
||||
@Schema(description = "产品秒杀ID", required = true)
|
||||
private Long secKillId = 0L;
|
||||
|
||||
@Schema(description = "产品砍价ID", required = true)
|
||||
private Long bargainId = 0L;
|
||||
}
|
||||
|
||||
@ -6,6 +6,7 @@ import co.yixiang.yshop.framework.common.pojo.PageResult;
|
||||
import co.yixiang.yshop.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import co.yixiang.yshop.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import co.yixiang.yshop.module.cart.dal.dataobject.storecart.StoreCartDO;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import co.yixiang.yshop.module.cart.controller.admin.storecart.vo.*;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
@ -21,24 +22,35 @@ public interface StoreCartMapper extends BaseMapperX<StoreCartDO> {
|
||||
|
||||
default PageResult<StoreCartDO> selectPage(StoreCartPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<StoreCartDO>()
|
||||
.eqIfPresent(StoreCartDO::getUid, reqVO.getUid())
|
||||
.eqIfPresent(StoreCartDO::getType, reqVO.getType())
|
||||
.eqIfPresent(StoreCartDO::getProductId, reqVO.getProductId())
|
||||
.eqIfPresent(StoreCartDO::getProductAttrUnique, reqVO.getProductAttrUnique())
|
||||
.eqIfPresent(StoreCartDO::getCartNum, reqVO.getCartNum())
|
||||
.eqIfPresent(StoreCartDO::getIsPay, reqVO.getIsPay())
|
||||
.eqIfPresent(StoreCartDO::getIsNew, reqVO.getIsNew())
|
||||
.eqIfPresent(StoreCartDO::getCombinationId, reqVO.getCombinationId())
|
||||
.eqIfPresent(StoreCartDO::getSeckillId, reqVO.getSeckillId())
|
||||
.eqIfPresent(StoreCartDO::getBargainId, reqVO.getBargainId())
|
||||
.betweenIfPresent(StoreCartDO::getCreateTime, reqVO.getCreateTime())
|
||||
.orderByDesc(StoreCartDO::getId));
|
||||
}
|
||||
|
||||
@Select("<script>select sc.id,sc.type,su.id as userId,su.nickname,sc.cart_num,sc.is_pay," +
|
||||
"sc.create_time,sp.store_name,sc.product_id as productId\n" +
|
||||
"from yshop_store_cart sc \n" +
|
||||
"left join yshop_user su on sc.uid = su.id\n" +
|
||||
"left join yshop_store_product sp on sc.product_id = sp.id " +
|
||||
"where sc.deleted = 0 " +
|
||||
"<if test =\"nickname !='' and nickname != null \">and su.nickname like CONCAT('%', #{nickname}, '%')</if>" +
|
||||
"order by sc.create_time desc</script>")
|
||||
List<StoreCartRespVO> pageList(Page page, @Param("nickname") String nickname);
|
||||
|
||||
|
||||
@Select("select IFNULL(sum(cart_num),0) from yshop_store_cart " +
|
||||
"where is_pay=0 and deleted=0 and is_new=0 and uid=#{uid}")
|
||||
@Select("<script>select count(*)" +
|
||||
"from yshop_store_cart sc \n" +
|
||||
"left join yshop_user su on sc.uid = su.id\n" +
|
||||
"left join yshop_store_product sp on sc.product_id = sp.id " +
|
||||
"where sc.deleted = 0 " +
|
||||
"<if test =\"nickname !='' and nickname != null \">and su.nickname like CONCAT('%', #{nickname}, '%')</if>" +
|
||||
"order by sc.create_time desc</script>")
|
||||
Long pageListCount( @Param("nickname") String nickname);
|
||||
|
||||
@Select("select IFNULL(sum(ysc.cart_num),0) from yshop_store_cart as ysc " +
|
||||
"inner join yshop_store_product_attr_value as yspav on ysc.product_attr_unique = yspav.`unique` " +
|
||||
"where ysc.is_pay = 0 and ysc.deleted = 0 and ysc.is_new = 0 and ysc.uid= #{uid} " +
|
||||
"and yspav.stock > 0")
|
||||
int cartSum(@Param("uid") Long uid);
|
||||
|
||||
}
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
package co.yixiang.yshop.module.cart.service.storecart;
|
||||
|
||||
import co.yixiang.yshop.module.cart.controller.app.cart.param.AppCartChangeSkuParam;
|
||||
import co.yixiang.yshop.module.cart.dal.dataobject.storecart.StoreCartDO;
|
||||
import co.yixiang.yshop.module.product.controller.app.couponrelation.vo.CartCouponVO;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
@ -75,8 +77,22 @@ public interface AppStoreCartService extends IService<StoreCartDO> {
|
||||
|
||||
/**
|
||||
* 修改购物车支付状态
|
||||
* @param cartIds
|
||||
* @param cartIds 购物车id列表
|
||||
*/
|
||||
void updateCartPayStatus(List<String> cartIds);
|
||||
|
||||
/***
|
||||
* 修改购物车商品sku
|
||||
* @param uid 用户id
|
||||
* @param param 修改参数
|
||||
*/
|
||||
void changeSku(Long uid,AppCartChangeSkuParam param);
|
||||
|
||||
/**
|
||||
* 查询购物车可用优惠券
|
||||
*
|
||||
* @param cartIds
|
||||
* @return
|
||||
*/
|
||||
List<CartCouponVO> searchCartAvailableCoupon(String cartIds);
|
||||
}
|
||||
|
||||
@ -2,31 +2,30 @@ package co.yixiang.yshop.module.cart.service.storecart;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import co.yixiang.yshop.framework.common.constant.ShopConstants;
|
||||
import co.yixiang.yshop.framework.common.enums.OrderInfoEnum;
|
||||
import co.yixiang.yshop.framework.common.enums.ShopCommonEnum;
|
||||
import co.yixiang.yshop.framework.common.exception.ErrorCode;
|
||||
import co.yixiang.yshop.module.cart.controller.app.cart.param.AppCartChangeSkuParam;
|
||||
import co.yixiang.yshop.module.cart.convert.storecart.StoreCartConvert;
|
||||
import co.yixiang.yshop.module.cart.dal.dataobject.storecart.StoreCartDO;
|
||||
import co.yixiang.yshop.module.cart.dal.mysql.storecart.StoreCartMapper;
|
||||
import co.yixiang.yshop.module.cart.enums.CartTypeEnum;
|
||||
import co.yixiang.yshop.module.product.api.product.ProductApi;
|
||||
import co.yixiang.yshop.module.product.controller.app.cart.vo.AppStoreCartQueryVo;
|
||||
import co.yixiang.yshop.module.product.controller.app.couponrelation.vo.CartCouponVO;
|
||||
import co.yixiang.yshop.module.product.controller.app.product.vo.AppStoreProductRespVo;
|
||||
import co.yixiang.yshop.module.product.dal.dataobject.storeproduct.StoreProductDO;
|
||||
import co.yixiang.yshop.module.product.dal.dataobject.storeproductattrvalue.StoreProductAttrValueDO;
|
||||
import co.yixiang.yshop.module.product.enums.product.ProductTypeEnum;
|
||||
import co.yixiang.yshop.module.product.service.productcouponrelation.AppCouponRelationService;
|
||||
import co.yixiang.yshop.module.product.service.productcouponrelation.dto.CartCouponDto;
|
||||
import co.yixiang.yshop.module.product.service.storeproduct.AppStoreProductService;
|
||||
import co.yixiang.yshop.module.product.service.storeproductattrvalue.StoreProductAttrValueService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.redisson.api.RLock;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@ -35,6 +34,7 @@ import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static co.yixiang.yshop.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static co.yixiang.yshop.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||
import static co.yixiang.yshop.module.cart.enums.ErrorCodeConstants.STORE_STOCK_ERROR;
|
||||
import static co.yixiang.yshop.module.product.enums.ErrorCodeConstants.STORE_PRODUCT_NOT_EXISTS;
|
||||
import static co.yixiang.yshop.module.cart.enums.ErrorCodeConstants.STORE_CART_NOT_EXISTS;
|
||||
@ -47,17 +47,18 @@ import static co.yixiang.yshop.module.cart.enums.ErrorCodeConstants.STORE_CART_N
|
||||
@Slf4j
|
||||
@Service
|
||||
@Validated
|
||||
public class AppStoreCartServiceImpl extends ServiceImpl<StoreCartMapper,StoreCartDO> implements AppStoreCartService {
|
||||
public class AppStoreCartServiceImpl extends ServiceImpl<StoreCartMapper, StoreCartDO> implements AppStoreCartService {
|
||||
|
||||
@Resource
|
||||
private StoreCartMapper storeCartMapper;
|
||||
@Resource
|
||||
private ProductApi productApi;
|
||||
@Resource
|
||||
private AppStoreProductService appStoreProductService;
|
||||
@Resource
|
||||
private StoreProductAttrValueService storeProductAttrValueService;
|
||||
|
||||
@Resource
|
||||
private AppCouponRelationService couponRelationService;
|
||||
|
||||
|
||||
/**
|
||||
* 返回当前用户购物车总数量
|
||||
@ -72,6 +73,7 @@ public class AppStoreCartServiceImpl extends ServiceImpl<StoreCartMapper,StoreCa
|
||||
|
||||
/**
|
||||
* 添加购物车
|
||||
*
|
||||
* @param uid 用户id
|
||||
* @param productId 普通产品编号
|
||||
* @param cartNum 购物车数量
|
||||
@ -86,10 +88,9 @@ public class AppStoreCartServiceImpl extends ServiceImpl<StoreCartMapper,StoreCa
|
||||
public long addCart(Long uid, Long productId, Integer cartNum, String productAttrUnique,
|
||||
Integer isNew, Long combinationId, Long seckillId, Long bargainId) {
|
||||
|
||||
this.checkProductStock(uid, productId, cartNum, productAttrUnique);
|
||||
LambdaQueryWrapper<StoreCartDO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(StoreCartDO::getUid, uid)
|
||||
.eq(StoreCartDO::getIsPay, OrderInfoEnum.PAY_STATUS_0.getValue())
|
||||
.eq(StoreCartDO::getIsPay, OrderInfoEnum.PAY_STATUS_UNPAID.getValue())
|
||||
.eq(StoreCartDO::getProductId, productId)
|
||||
.eq(StoreCartDO::getIsNew, isNew)
|
||||
.eq(StoreCartDO::getProductAttrUnique, productAttrUnique)
|
||||
@ -101,6 +102,13 @@ public class AppStoreCartServiceImpl extends ServiceImpl<StoreCartMapper,StoreCa
|
||||
|
||||
StoreCartDO cart = storeCartMapper.selectOne(wrapper);
|
||||
|
||||
//加入购物车才累计,立即购买不用累计
|
||||
if (cart != null && CartTypeEnum.ADD_SHOPPING_CART.getValue().equals(isNew)) {
|
||||
cartNum = cartNum + cart.getCartNum();
|
||||
}
|
||||
this.checkProductStock(uid, productId, cartNum, productAttrUnique);
|
||||
|
||||
|
||||
StoreCartDO storeCart = StoreCartDO.builder()
|
||||
.cartNum(cartNum)
|
||||
.productAttrUnique(productAttrUnique)
|
||||
@ -112,9 +120,6 @@ public class AppStoreCartServiceImpl extends ServiceImpl<StoreCartMapper,StoreCa
|
||||
.uid(uid)
|
||||
.build();
|
||||
if (cart != null) {
|
||||
if (CartTypeEnum.NEW_0.getValue().equals(isNew)) {
|
||||
storeCart.setCartNum(cartNum + cart.getCartNum());
|
||||
}
|
||||
storeCart.setId(cart.getId());
|
||||
storeCartMapper.updateById(storeCart);
|
||||
} else {
|
||||
@ -136,7 +141,7 @@ public class AppStoreCartServiceImpl extends ServiceImpl<StoreCartMapper,StoreCa
|
||||
public void checkProductStock(Long uid, Long productId, Integer cartNum, String productAttrUnique) {
|
||||
StoreProductDO product = appStoreProductService
|
||||
.lambdaQuery().eq(StoreProductDO::getId, productId)
|
||||
.eq(StoreProductDO::getIsShow, ShopCommonEnum.SHOW_1.getValue())
|
||||
.eq(StoreProductDO::getIsShow, ShopCommonEnum.SHOW.getValue())
|
||||
.one();
|
||||
if (product == null) {
|
||||
throw exception(STORE_PRODUCT_NOT_EXISTS);
|
||||
@ -162,10 +167,10 @@ public class AppStoreCartServiceImpl extends ServiceImpl<StoreCartMapper,StoreCa
|
||||
public Map<String, Object> getUserProductCartList(Long uid, String cartIds, Integer status) {
|
||||
LambdaQueryWrapper<StoreCartDO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(StoreCartDO::getUid, uid)
|
||||
.eq(StoreCartDO::getIsPay, OrderInfoEnum.PAY_STATUS_0.getValue())
|
||||
.eq(StoreCartDO::getIsPay, OrderInfoEnum.PAY_STATUS_UNPAID.getValue())
|
||||
.orderByDesc(StoreCartDO::getId);
|
||||
if (status == null) {
|
||||
wrapper.eq(StoreCartDO::getIsNew, CartTypeEnum.NEW_0.getValue());
|
||||
wrapper.eq(StoreCartDO::getIsNew, CartTypeEnum.ADD_SHOPPING_CART.getValue());
|
||||
}
|
||||
if (StrUtil.isNotEmpty(cartIds)) {
|
||||
wrapper.in(StoreCartDO::getId, Arrays.asList(cartIds.split(",")));
|
||||
@ -180,34 +185,36 @@ public class AppStoreCartServiceImpl extends ServiceImpl<StoreCartMapper,StoreCa
|
||||
AppStoreCartQueryVo storeCartQueryVo = StoreCartConvert.INSTANCE.convert01(storeCart);
|
||||
if (ObjectUtil.isNull(storeProduct)) {
|
||||
this.removeById(storeCart.getId());
|
||||
} else if (ShopCommonEnum.SHOW_0.getValue().equals(storeProduct.getIsShow()) || (storeProduct.getStock() == 0 && StrUtil.isEmpty(storeCart.getProductAttrUnique()))) {
|
||||
} else if (ShopCommonEnum.NO_SHOW.getValue().equals(storeProduct.getIsShow())
|
||||
|| (storeProduct.getStock() == 0 && StrUtil.isEmpty(storeCart.getProductAttrUnique()))) {
|
||||
storeCartQueryVo.setProductInfo(storeProduct);
|
||||
invalid.add(storeCartQueryVo);
|
||||
} else {
|
||||
StoreProductAttrValueDO productAttrValue = storeProductAttrValueService.getOne(Wrappers.<StoreProductAttrValueDO>lambdaQuery()
|
||||
.eq(StoreProductAttrValueDO::getUnique,storeCart.getProductAttrUnique()));
|
||||
if (ObjectUtil.isNull(productAttrValue) || productAttrValue.getStock() == 0) {
|
||||
storeCartQueryVo.setProductInfo(storeProduct);
|
||||
invalid.add(storeCartQueryVo);
|
||||
} else {
|
||||
storeProduct.setAttrInfo(productAttrValue);
|
||||
storeCartQueryVo.setProductInfo(storeProduct);
|
||||
//普通商品金额
|
||||
BigDecimal truePrice = storeProduct.getPrice();
|
||||
//设置拼团价格
|
||||
if(storeCart.getCombinationId() > 0 ){
|
||||
truePrice = productAttrValue.getPinkPrice();
|
||||
}
|
||||
//设置秒杀价格
|
||||
if( storeCart.getSeckillId() > 0){
|
||||
truePrice = productAttrValue.getSeckillPrice();
|
||||
}
|
||||
storeCartQueryVo.setTruePrice(truePrice);
|
||||
storeCartQueryVo.setTrueStock(productAttrValue.getStock());
|
||||
valid.add(storeCartQueryVo);
|
||||
|
||||
StoreProductAttrValueDO productAttrValue =
|
||||
storeProductAttrValueService.getOne(Wrappers.<StoreProductAttrValueDO>lambdaQuery()
|
||||
.eq(StoreProductAttrValueDO::getUnique, storeCart.getProductAttrUnique()));
|
||||
if (ObjectUtil.isNull(productAttrValue) || productAttrValue.getStock() == 0) {
|
||||
storeCartQueryVo.setProductInfo(storeProduct);
|
||||
invalid.add(storeCartQueryVo);
|
||||
} else {
|
||||
storeProduct.setAttrInfo(productAttrValue);
|
||||
storeCartQueryVo.setProductInfo(storeProduct);
|
||||
// 普通商品金额
|
||||
BigDecimal truePrice = productAttrValue.getPrice();
|
||||
// 设置拼团价格
|
||||
if (storeCart.getCombinationId() > 0) {
|
||||
truePrice = productAttrValue.getPinkPrice();
|
||||
}
|
||||
// 设置秒杀价格
|
||||
if (storeCart.getSeckillId() > 0) {
|
||||
truePrice = productAttrValue.getSeckillPrice();
|
||||
}
|
||||
storeCartQueryVo.setTruePrice(truePrice);
|
||||
storeCartQueryVo.setTrueStock(productAttrValue.getStock());
|
||||
valid.add(storeCartQueryVo);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -267,15 +274,16 @@ public class AppStoreCartServiceImpl extends ServiceImpl<StoreCartMapper,StoreCa
|
||||
*/
|
||||
@Override
|
||||
public void removeUserCart(Long uid, List<String> ids) {
|
||||
List<Long> newids = ids.stream().map(Long::new).collect(Collectors.toList());
|
||||
List<Long> newIds = ids.stream().map(Long::new).collect(Collectors.toList());
|
||||
storeCartMapper.delete(Wrappers.<StoreCartDO>lambdaQuery()
|
||||
.eq(StoreCartDO::getUid, uid)
|
||||
.in(StoreCartDO::getId, newids));
|
||||
.in(StoreCartDO::getId, newIds));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改购物车支付状态
|
||||
* @param cartIds
|
||||
*
|
||||
* @param cartIds 购物车id列表
|
||||
*/
|
||||
@Async
|
||||
@Override
|
||||
@ -283,11 +291,41 @@ public class AppStoreCartServiceImpl extends ServiceImpl<StoreCartMapper,StoreCa
|
||||
public void updateCartPayStatus(List<String> cartIds) {
|
||||
log.info("==========修改购物车支付状态start===========");
|
||||
StoreCartDO cartObj = new StoreCartDO();
|
||||
cartObj.setIsPay(OrderInfoEnum.PAY_STATUS_1.getValue());
|
||||
cartObj.setIsPay(OrderInfoEnum.PAY_STATUS_HAVE_PAID.getValue());
|
||||
storeCartMapper.update(cartObj, Wrappers.<StoreCartDO>lambdaQuery()
|
||||
.in(StoreCartDO::getId, cartIds));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeSku(Long uid, AppCartChangeSkuParam param) {
|
||||
StoreCartDO cart = this.lambdaQuery()
|
||||
.eq(StoreCartDO::getUid, uid)
|
||||
.eq(StoreCartDO::getId, param.getId())
|
||||
.one();
|
||||
if (cart == null) {
|
||||
throw exception(STORE_CART_NOT_EXISTS);
|
||||
}
|
||||
cart.setProductAttrUnique(param.getProductAttrUnique());
|
||||
storeCartMapper.update(cart, Wrappers.<StoreCartDO>lambdaQuery()
|
||||
.eq(StoreCartDO::getId, param.getId()));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<CartCouponVO> searchCartAvailableCoupon(String cartIds) {
|
||||
Long uid = getLoginUserId();
|
||||
Map<String, Object> cartGroup = getUserProductCartList(uid, cartIds, ShopConstants.YSHOP_ONE_NUM);
|
||||
List<AppStoreCartQueryVo> cartInfo = (List<AppStoreCartQueryVo>) cartGroup.get("valid");
|
||||
List<CartCouponDto> cartCouponDtoList = new ArrayList<>();
|
||||
Map<Long, List<AppStoreCartQueryVo>> cartInfoMap =
|
||||
cartInfo.stream().collect(Collectors.groupingBy(AppStoreCartQueryVo::getProductId));
|
||||
for (List<AppStoreCartQueryVo> queryVos : cartInfoMap.values()) {
|
||||
BigDecimal amount = BigDecimal.ZERO;
|
||||
for (AppStoreCartQueryVo appStoreCartQueryVo : queryVos){
|
||||
amount = amount.add(appStoreCartQueryVo.getTruePrice()
|
||||
.multiply(BigDecimal.valueOf(appStoreCartQueryVo.getCartNum())));
|
||||
}
|
||||
cartCouponDtoList.add(CartCouponDto.builder().productId(queryVos.get(0).getProductId()).price(amount).build());
|
||||
}
|
||||
return couponRelationService.searchCartCoupon(cartCouponDtoList, null);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,24 +1,18 @@
|
||||
package co.yixiang.yshop.module.cart.service.storecart;
|
||||
|
||||
import co.yixiang.yshop.module.member.dal.dataobject.user.MemberUserDO;
|
||||
import co.yixiang.yshop.module.member.dal.mysql.user.MemberUserMapper;
|
||||
import co.yixiang.yshop.module.product.dal.dataobject.storeproduct.StoreProductDO;
|
||||
import co.yixiang.yshop.module.product.dal.mysql.storeproduct.StoreProductMapper;
|
||||
import co.yixiang.yshop.framework.common.pojo.PageResult;
|
||||
import co.yixiang.yshop.module.cart.controller.admin.storecart.vo.StoreCartPageReqVO;
|
||||
import co.yixiang.yshop.module.cart.controller.admin.storecart.vo.StoreCartRespVO;
|
||||
import co.yixiang.yshop.module.cart.dal.mysql.storecart.StoreCartMapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.springframework.stereotype.Service;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.lang.reflect.Member;
|
||||
import java.util.*;
|
||||
import co.yixiang.yshop.module.cart.controller.admin.storecart.vo.*;
|
||||
import co.yixiang.yshop.module.cart.dal.dataobject.storecart.StoreCartDO;
|
||||
import co.yixiang.yshop.framework.common.pojo.PageResult;
|
||||
|
||||
import co.yixiang.yshop.module.cart.convert.storecart.StoreCartConvert;
|
||||
import co.yixiang.yshop.module.cart.dal.mysql.storecart.StoreCartMapper;
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
import static co.yixiang.yshop.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static co.yixiang.yshop.module.cart.enums.ErrorCodeConstants.*;
|
||||
import static co.yixiang.yshop.module.cart.enums.ErrorCodeConstants.STORE_CART_NOT_EXISTS;
|
||||
|
||||
/**
|
||||
* 购物车 Service 实现类
|
||||
@ -31,10 +25,6 @@ public class StoreCartServiceImpl implements StoreCartService {
|
||||
|
||||
@Resource
|
||||
private StoreCartMapper storeCartMapper;
|
||||
@Resource
|
||||
private StoreProductMapper storeProductMapper;
|
||||
@Resource
|
||||
private MemberUserMapper memberUserMapper;
|
||||
|
||||
|
||||
@Override
|
||||
@ -54,17 +44,10 @@ public class StoreCartServiceImpl implements StoreCartService {
|
||||
|
||||
@Override
|
||||
public PageResult<StoreCartRespVO> getStoreCartPage(StoreCartPageReqVO pageReqVO) {
|
||||
PageResult<StoreCartDO> pageResult = storeCartMapper.selectPage(pageReqVO);
|
||||
PageResult<StoreCartRespVO> storeCartRespVO = StoreCartConvert.INSTANCE.convertPage(pageResult);
|
||||
for (StoreCartRespVO storeCartRespVO1 : storeCartRespVO.getList()) {
|
||||
StoreProductDO storeProductDO = storeProductMapper.selectById(storeCartRespVO1.getProductId());
|
||||
MemberUserDO memberUserDO = memberUserMapper.selectById(storeCartRespVO1.getUid());
|
||||
storeCartRespVO1.setNickname(memberUserDO.getNickname());
|
||||
storeCartRespVO1.setStoreName(storeProductDO.getStoreName());
|
||||
}
|
||||
return storeCartRespVO;
|
||||
List<StoreCartRespVO> list = storeCartMapper.pageList(new Page<>(pageReqVO.getPageNo(),pageReqVO.getPageSize()),
|
||||
pageReqVO.getNickname());
|
||||
|
||||
return new PageResult<>(list, storeCartMapper.pageListCount(pageReqVO.getNickname()));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user