Commit df29a37c authored by wlx@33.cn's avatar wlx@33.cn

提交盲盒下单

parent db3f3bf9
...@@ -158,4 +158,10 @@ public interface UserAssetMapper extends BaseMapper<UserAsset> { ...@@ -158,4 +158,10 @@ public interface UserAssetMapper extends BaseMapper<UserAsset> {
@Select("select * from user_asset where uid = #{uid} and coin = #{coin}") @Select("select * from user_asset where uid = #{uid} and coin = #{coin}")
UserAsset getCoin(@Param("uid") String uid, @Param("coin") String value); UserAsset getCoin(@Param("uid") String uid, @Param("coin") String value);
@Update("update user_asset set amount = amount -#{number},frozen = frozen + #{number},update_time = #{time} where id = #{id} and update_time = #{updateTime} and amount >= #{number}")
int useToFrozen(@Param("id") Long id,
@Param("number") BigDecimal number,
@Param("updateTime") Long updateTime,
@Param("time") long currentTimeMillis);
} }
...@@ -156,4 +156,7 @@ public interface IUserAssetService extends IService<UserAsset> { ...@@ -156,4 +156,7 @@ public interface IUserAssetService extends IService<UserAsset> {
int addReward(String uid, String commentId, BigDecimal evaluationRefund); int addReward(String uid, String commentId, BigDecimal evaluationRefund);
int deleteAmount(Long id, BigDecimal amount); int deleteAmount(Long id, BigDecimal amount);
//可用变冻结
int useToFrozen(Long id, BigDecimal number, Long updateTime, long currentTimeMillis);
} }
...@@ -578,4 +578,9 @@ public class UserAssetServiceImpl extends ServiceImpl<UserAssetMapper, UserAsset ...@@ -578,4 +578,9 @@ public class UserAssetServiceImpl extends ServiceImpl<UserAssetMapper, UserAsset
public int deleteAmount(Long id, BigDecimal amount) { public int deleteAmount(Long id, BigDecimal amount) {
return coinDao.deleteAmount(id, amount); return coinDao.deleteAmount(id, amount);
} }
@Override
public int useToFrozen(Long id, BigDecimal number, Long updateTime, long currentTimeMillis) {
return coinDao.useToFrozen(id, number, updateTime, currentTimeMillis);
}
} }
package com.fzm.mall.server.front.constant; package com.fzm.mall.server.front.constant;
import java.math.BigDecimal;
public class CommonConst { public class CommonConst {
public static final String USER = "user"; public static final String USER = "user";
public static final String SIGNATURE = "signature"; public static final String SIGNATURE = "signature";
public static final String NONCE = "nonce"; public static final String NONCE = "nonce";
public static final BigDecimal NEGATIVE_ONE = new BigDecimal("-1");
/**
* a = b
*/
public static final int BIEDICIMAL_EQUAL_RESULT = 0;
/**
* a < b
*/
public static final int BIEDICIMAL_LEFT_LESS = -1;
/**
* a > b
*/
public static final int BIEDICIMAL_LEFT_GREATER = 1;
public CommonConst() { public CommonConst() {
} }
} }
package com.fzm.mall.server.front.constant; package com.fzm.mall.server.front.constant;
import java.math.BigDecimal;
/** /**
* @author tdz * @author tdz
* @date 2021/03/02 14:51 * @date 2021/03/02 14:51
...@@ -16,4 +18,15 @@ public class GoodMainConst { ...@@ -16,4 +18,15 @@ public class GoodMainConst {
*/ */
public final static String ORDER_BY_CART = "1"; public final static String ORDER_BY_CART = "1";
/**
* 盲盒商品单次下单的购买数量:一次只能买一个
*/
public final static Integer BLIND_BOX_ORDER_SKU_NUM = 1;
public final static BigDecimal BLIND_BOX_ORDER_SKU_NUM_BIGDECIMAL = new BigDecimal("1");
/**
* 盲盒商品的待支付订单回显规格属性值的默认值
*/
public final static String DEFAULT_PROP_VALUE = "默认";
} }
...@@ -68,6 +68,8 @@ public enum MallResponseEnum { ...@@ -68,6 +68,8 @@ public enum MallResponseEnum {
NOT_SUPPORT_BUY_MYSELF("200221","NOT_SUPPORT_BUY_MYSELF"), NOT_SUPPORT_BUY_MYSELF("200221","NOT_SUPPORT_BUY_MYSELF"),
ONLY_SUPPORT_MAIL("200222","ONLY_SUPPORT_MAIL"), ONLY_SUPPORT_MAIL("200222","ONLY_SUPPORT_MAIL"),
SEND_CODE_ERR("200223","SEND_CODE_ERR"), SEND_CODE_ERR("200223","SEND_CODE_ERR"),
HOT_ACTIVITY("200237","HOT_ACTIVITY"),
// 系统参数配置 // 系统参数配置
QUERY_SUCCESS("200200", "query_success"), QUERY_SUCCESS("200200", "query_success"),
......
package com.fzm.mall.server.front.enums;
public enum AssetRecordTypeEnum {
//积分充值
INTEGRAL_RECHARGE(7),
//积分抵扣
INTEGRAL_DEDUCTION(9),
//退款
RETURN_MONEY(10),
//商品币购买
BUY_GOODS(11),
//扣除积分
DEDUCT_INTEGRAL(17),
//提货
DRAW_GOODS(18),
//评论奖励
COMMENT_REWARD(19),
//转赠-转入
PRESENT_IN(20),
//转赠—转出
PRESENT_OUT(21),
//注册奖励
REGISTER_REWARD(22),
//外部token转入
OUT_TOKEN_IN(23),
//外部NFT转入
OUT_NFT_IN(24),
//向外划转
TRANSFER_OUT(25),
//退货
RETURN_GOODS(26),
//邀请注册奖励
INVITE_REGISTER_REWARD(27),
//发布转让
RELEASE_TRANSFER(28),
//商品币退还
GOODS_COIN_REFUND(29),
//积分抵扣退还
INTEGRAL_DEDUCTION_RETURN(30),
//31.slg数字资产发行 32.slg数字资产增发 33.slg数字资产减发 34.slg数字资产回收 35.slc防伪NFT转入
//物物交换转让转入
BARTER_TRANSFER_IN(36),
//物物交换转让转出
BARTER_TRANSFER_OUT(37),
;
private Integer type;
AssetRecordTypeEnum(Integer type){
this.type = type;
}
public Integer getType() {
return type;
}
}
package com.fzm.mall.server.front.enums;
public enum GoodSpuSalesTypeEnum {
/**
* 普通商品
*/
GENERAL(1),
/**
* 盲盒商品
*/
BLIND_BOX(4),
;
private Integer type;
GoodSpuSalesTypeEnum(Integer type){
this.type = type;
}
public Integer getType() {
return type;
}
}
package com.fzm.mall.server.front.enums;
public enum OrderPayStateEnum {
/**
* 6->待付款
*/
PAY_STATE_TO_PAY(6),
;
private Integer state;
OrderPayStateEnum(Integer state){
this.state = state;
}
public Integer getState() {
return state;
}
}
package com.fzm.mall.server.front.enums;
public enum OrderPayTypeEnum {
//积分支付
INTEGRAL(4),
;
private Integer type;
OrderPayTypeEnum(Integer type){
this.type = type;
}
public Integer getType() {
return type;
}
}
package com.fzm.mall.server.front.enums;
public enum OrderStateEnum {
/**
* 7->待支付
*/
ORDER_STATE_TO_PAY(7),
;
private Integer state;
OrderStateEnum(Integer state){
this.state = state;
}
public Integer getState() {
return state;
}
}
package com.fzm.mall.server.front.enums;
public enum OrderTypeEnum {
/**
* 普通商品
*/
GENERAL(1),
;
private Integer type;
OrderTypeEnum(Integer type){
this.type = type;
}
public Integer getType() {
return type;
}
}
...@@ -2,6 +2,7 @@ package com.fzm.mall.server.front.goods.mapper; ...@@ -2,6 +2,7 @@ package com.fzm.mall.server.front.goods.mapper;
import com.fzm.mall.server.front.goods.model.DistributionTemplateItem; import com.fzm.mall.server.front.goods.model.DistributionTemplateItem;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Select;
...@@ -13,6 +14,7 @@ import org.apache.ibatis.annotations.Select; ...@@ -13,6 +14,7 @@ import org.apache.ibatis.annotations.Select;
* @author fzm * @author fzm
* @since 2021-03-19 * @since 2021-03-19
*/ */
@Mapper
public interface DistributionTemplateItemMapper extends BaseMapper<DistributionTemplateItem> { public interface DistributionTemplateItemMapper extends BaseMapper<DistributionTemplateItem> {
@Select("select * from distribution_template_item where template_id = #{templateId} and delivery_area like #{province}") @Select("select * from distribution_template_item where template_id = #{templateId} and delivery_area like #{province}")
DistributionTemplateItem getByTemplateIdAndProvince(@Param("templateId") String templateId, @Param("province") String province); DistributionTemplateItem getByTemplateIdAndProvince(@Param("templateId") String templateId, @Param("province") String province);
......
...@@ -2,6 +2,7 @@ package com.fzm.mall.server.front.goods.mapper; ...@@ -2,6 +2,7 @@ package com.fzm.mall.server.front.goods.mapper;
import com.fzm.mall.server.front.goods.model.DistributionTemplate; import com.fzm.mall.server.front.goods.model.DistributionTemplate;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
/** /**
* <p> * <p>
...@@ -11,6 +12,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; ...@@ -11,6 +12,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
* @author fzm * @author fzm
* @since 2021-03-19 * @since 2021-03-19
*/ */
@Mapper
public interface DistributionTemplateMapper extends BaseMapper<DistributionTemplate> { public interface DistributionTemplateMapper extends BaseMapper<DistributionTemplate> {
} }
...@@ -66,8 +66,8 @@ public interface GoodSkuMapper extends BaseMapper<GoodSku> { ...@@ -66,8 +66,8 @@ public interface GoodSkuMapper extends BaseMapper<GoodSku> {
@Select("select a.merchant_id as merchantId,a.template_id as templateId,a.name as name,a.goods_id as goodsId,b.* from goods_spu a left join goods_sku b on a.goods_id = b.goods_id where b.sku_id = #{skuId}") @Select("select a.merchant_id as merchantId,a.template_id as templateId,a.name as name,a.goods_id as goodsId,b.* from goods_spu a left join goods_sku b on a.goods_id = b.goods_id where b.sku_id = #{skuId}")
SkuVo getSkuVoBySkuId(@Param("skuId") String skuId); SkuVo getSkuVoBySkuId(@Param("skuId") String skuId);
@Update("update goods_sku set stock =stock - #{num} where sku_id = #{skuId} and stock >= #{num}") // @Update("update goods_sku set stock =stock - #{num} where sku_id = #{skuId} and stock >= #{num}")
int delStock(@Param("skuId") String skuId, @Param("num") Integer num); // int delStock(@Param("skuId") String skuId, @Param("num") Integer num);
@Update("update goods_sku set stock =stock + #{num} where sku_id = #{skuId}") @Update("update goods_sku set stock =stock + #{num} where sku_id = #{skuId}")
void addStock(@Param("skuId") String skuId, @Param("num") Integer number); void addStock(@Param("skuId") String skuId, @Param("num") Integer number);
...@@ -84,4 +84,13 @@ public interface GoodSkuMapper extends BaseMapper<GoodSku> { ...@@ -84,4 +84,13 @@ public interface GoodSkuMapper extends BaseMapper<GoodSku> {
String getGoodsName(@Param("goodsId") String goodsId); String getGoodsName(@Param("goodsId") String goodsId);
SaleHotVo count(String goodsId); SaleHotVo count(String goodsId);
/**
* 获取库存大于0的sku列表
*/
List<SkuVo> listAvailableSku(@Param("goodsId") String goodsId);
int delStock(@Param("skuId") String skuId,
@Param("num") Integer num,
@Param("updateTime")Long updateTime);
} }
...@@ -144,6 +144,9 @@ public class GoodSpu implements Serializable { ...@@ -144,6 +144,9 @@ public class GoodSpu implements Serializable {
@ApiModelProperty(value = "溯源hash") @ApiModelProperty(value = "溯源hash")
private String hash; private String hash;
@ApiModelProperty(value = "(销售方式)1.普通 4.盲盒")
private Integer salesType;
public void initTokenId() { public void initTokenId() {
if (commodityPass.equals(COMMODITY_PASS_OUT)){ if (commodityPass.equals(COMMODITY_PASS_OUT)){
setTokenId(Long.valueOf(tokenIdStr)); setTokenId(Long.valueOf(tokenIdStr));
......
...@@ -66,4 +66,15 @@ public class SkuVo { ...@@ -66,4 +66,15 @@ public class SkuVo {
private String commodityPassId; private String commodityPassId;
@ApiModelProperty(value = "盲盒商品的销售难度系数(1-10)")
private Integer difficulty;
@ApiModelProperty(value = "盲盒商品的规格是否为隐藏款")
private Boolean isHide;
@ApiModelProperty(value = "更新时间")
private Long updateTime;
@ApiModelProperty(value = "盲盒商品价格")
private BigDecimal blindBoxprice;
} }
...@@ -19,7 +19,7 @@ public interface IDistributionTemplateService extends IService<DistributionTempl ...@@ -19,7 +19,7 @@ public interface IDistributionTemplateService extends IService<DistributionTempl
DistributionTemplate getTemplateId(String templateId); DistributionTemplate getTemplateId(String templateId);
BigDecimal getPrice(String templateId, String province, BigDecimal bigDecimal, Integer integer, BigDecimal bigDecimal1); BigDecimal getPrice(String templateId, String province, BigDecimal postFeeTotal, Integer merchantGoodSize, BigDecimal merchantGoodWeight);
DistributionTemplate getByMerchantId(String merchantId); DistributionTemplate getByMerchantId(String merchantId);
} }
...@@ -15,6 +15,9 @@ import java.util.Map; ...@@ -15,6 +15,9 @@ import java.util.Map;
* @since 2021-03-02 * @since 2021-03-02
*/ */
public interface IGoodSkuPropService extends IService<GoodSkuProp> { public interface IGoodSkuPropService extends IService<GoodSkuProp> {
List<Map<String, Object>> getSkuPropListBySkuId (String skuId, boolean hideSku);
List<Map<String, Object>> getSkuPropListBySkuId (String skuId); List<Map<String, Object>> getSkuPropListBySkuId (String skuId);
List<GoodSkuProp> getList(String string); List<GoodSkuProp> getList(String string);
......
...@@ -19,7 +19,7 @@ public interface IGoodSkuService extends IService<GoodSku> { ...@@ -19,7 +19,7 @@ public interface IGoodSkuService extends IService<GoodSku> {
SkuVo getSkuVoBySkuId(String skuId); SkuVo getSkuVoBySkuId(String skuId);
int delStock(String skuId,Integer num); int delStock(String skuId,Integer num, Long updateTime);
void addStock(String skuId, Integer number); void addStock(String skuId, Integer number);
......
package com.fzm.mall.server.front.goods.service.impl; package com.fzm.mall.server.front.goods.service.impl;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.enums.SqlLike;
import com.fzm.mall.server.front.goods.mapper.DistributionTemplateItemMapper; import com.fzm.mall.server.front.goods.mapper.DistributionTemplateItemMapper;
import com.fzm.mall.server.front.goods.model.DistributionTemplate; import com.fzm.mall.server.front.goods.model.DistributionTemplate;
import com.fzm.mall.server.front.goods.mapper.DistributionTemplateMapper; import com.fzm.mall.server.front.goods.mapper.DistributionTemplateMapper;
...@@ -28,9 +26,6 @@ public class DistributionTemplateServiceImpl extends ServiceImpl<DistributionTem ...@@ -28,9 +26,6 @@ public class DistributionTemplateServiceImpl extends ServiceImpl<DistributionTem
@Autowired @Autowired
private DistributionTemplateItemMapper distributionTemplateItemMapper; private DistributionTemplateItemMapper distributionTemplateItemMapper;
@Autowired
private DistributionTemplateMapper distributionTemplateMapper;
@Override @Override
public DistributionTemplate getTemplateId(String templateId) { public DistributionTemplate getTemplateId(String templateId) {
QueryWrapper<DistributionTemplate> q = new QueryWrapper<>(); QueryWrapper<DistributionTemplate> q = new QueryWrapper<>();
...@@ -39,7 +34,7 @@ public class DistributionTemplateServiceImpl extends ServiceImpl<DistributionTem ...@@ -39,7 +34,7 @@ public class DistributionTemplateServiceImpl extends ServiceImpl<DistributionTem
} }
@Override @Override
public BigDecimal getPrice(String templateId, String province, BigDecimal bigDecimal,Integer size,BigDecimal weight) { public BigDecimal getPrice(String templateId, String province, BigDecimal postFeeTotal,Integer size,BigDecimal weight) {
province = "%"+province+"%"; province = "%"+province+"%";
DistributionTemplateItem distributionTemplateItem = distributionTemplateItemMapper.getByTemplateIdAndProvince(templateId,province); DistributionTemplateItem distributionTemplateItem = distributionTemplateItemMapper.getByTemplateIdAndProvince(templateId,province);
if(distributionTemplateItem == null){ if(distributionTemplateItem == null){
...@@ -55,7 +50,7 @@ public class DistributionTemplateServiceImpl extends ServiceImpl<DistributionTem ...@@ -55,7 +50,7 @@ public class DistributionTemplateServiceImpl extends ServiceImpl<DistributionTem
return BigDecimal.ZERO; return BigDecimal.ZERO;
} }
}else if(distributionTemplateItem.getPricingType()==3){ }else if(distributionTemplateItem.getPricingType()==3){
if(distributionTemplateItem.getFreeShippingAmount().compareTo(bigDecimal)==1){ if(distributionTemplateItem.getFreeShippingAmount().compareTo(postFeeTotal)==1){
return getBigDecimal(templateId, size, weight); return getBigDecimal(templateId, size, weight);
}else{ }else{
return BigDecimal.ZERO; return BigDecimal.ZERO;
......
...@@ -2,6 +2,7 @@ package com.fzm.mall.server.front.goods.service.impl; ...@@ -2,6 +2,7 @@ package com.fzm.mall.server.front.goods.service.impl;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fzm.mall.server.front.constant.GoodMainConst;
import com.fzm.mall.server.front.goods.model.GoodSkuProp; import com.fzm.mall.server.front.goods.model.GoodSkuProp;
import com.fzm.mall.server.front.goods.mapper.GoodSkuPropMapper; import com.fzm.mall.server.front.goods.mapper.GoodSkuPropMapper;
import com.fzm.mall.server.front.goods.service.IGoodSkuPropService; import com.fzm.mall.server.front.goods.service.IGoodSkuPropService;
...@@ -38,7 +39,8 @@ public class GoodSkuPropServiceImpl extends ServiceImpl<GoodSkuPropMapper, GoodS ...@@ -38,7 +39,8 @@ public class GoodSkuPropServiceImpl extends ServiceImpl<GoodSkuPropMapper, GoodS
System.out.println(skuProp); System.out.println(skuProp);
} }
public List<Map<String, Object>> getSkuPropListBySkuId(String skuId) { @Override
public List<Map<String, Object>> getSkuPropListBySkuId(String skuId, boolean hideSku) {
List<Map<String, Object>> skuProp = goodRedis.getSkuProp(skuId); List<Map<String, Object>> skuProp = goodRedis.getSkuProp(skuId);
if (skuProp != null) { if (skuProp != null) {
return skuProp; return skuProp;
...@@ -53,7 +55,14 @@ public class GoodSkuPropServiceImpl extends ServiceImpl<GoodSkuPropMapper, GoodS ...@@ -53,7 +55,14 @@ public class GoodSkuPropServiceImpl extends ServiceImpl<GoodSkuPropMapper, GoodS
for (GoodSkuProp prop : list) { for (GoodSkuProp prop : list) {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("name", prop.getPropKey()); map.put("name", prop.getPropKey());
map.put("value", prop.getPropVal()); /**
* 待支付的盲盒订单需要隐藏规格信息
*/
if (hideSku){
map.put("value", GoodMainConst.DEFAULT_PROP_VALUE);
}else{
map.put("value", prop.getPropVal());
}
skuProp.add(map); skuProp.add(map);
} }
goodRedis.setSkuProp(skuId, skuProp); goodRedis.setSkuProp(skuId, skuProp);
...@@ -61,6 +70,11 @@ public class GoodSkuPropServiceImpl extends ServiceImpl<GoodSkuPropMapper, GoodS ...@@ -61,6 +70,11 @@ public class GoodSkuPropServiceImpl extends ServiceImpl<GoodSkuPropMapper, GoodS
return skuProp; return skuProp;
} }
@Override
public List<Map<String, Object>> getSkuPropListBySkuId(String skuId) {
return getSkuPropListBySkuId(skuId, false);
}
@Override @Override
public List<GoodSkuProp> getList(String string) { public List<GoodSkuProp> getList(String string) {
......
...@@ -61,8 +61,8 @@ public class GoodSkuServiceImpl extends ServiceImpl<GoodSkuMapper, GoodSku> impl ...@@ -61,8 +61,8 @@ public class GoodSkuServiceImpl extends ServiceImpl<GoodSkuMapper, GoodSku> impl
} }
@Override @Override
public int delStock(String skuId, Integer num) { public int delStock(String skuId, Integer num, Long updateTime) {
return skuMapper.delStock(skuId,num); return skuMapper.delStock(skuId,num,updateTime);
} }
@Override @Override
......
...@@ -2,6 +2,10 @@ package com.fzm.mall.server.front.merchant.mapper; ...@@ -2,6 +2,10 @@ package com.fzm.mall.server.front.merchant.mapper;
import com.fzm.mall.server.front.merchant.model.Merchant; import com.fzm.mall.server.front.merchant.model.Merchant;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.math.BigDecimal;
/** /**
* <p> * <p>
...@@ -11,6 +15,8 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; ...@@ -11,6 +15,8 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
* @author fzm * @author fzm
* @since 2021-03-02 * @since 2021-03-02
*/ */
@Mapper
public interface MerchantMapper extends BaseMapper<Merchant> { public interface MerchantMapper extends BaseMapper<Merchant> {
BigDecimal getPrice(@Param("coin") String coin);
} }
...@@ -3,6 +3,8 @@ package com.fzm.mall.server.front.merchant.service; ...@@ -3,6 +3,8 @@ package com.fzm.mall.server.front.merchant.service;
import com.fzm.mall.server.front.merchant.model.Merchant; import com.fzm.mall.server.front.merchant.model.Merchant;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import java.math.BigDecimal;
/** /**
* <p> * <p>
* 服务类 * 服务类
...@@ -12,6 +14,9 @@ import com.baomidou.mybatisplus.extension.service.IService; ...@@ -12,6 +14,9 @@ import com.baomidou.mybatisplus.extension.service.IService;
* @since 2021-03-02 * @since 2021-03-02
*/ */
public interface IMerchantService extends IService<Merchant> { public interface IMerchantService extends IService<Merchant> {
Merchant info(String merchantId) ; Merchant info(String merchantId) ;
BigDecimal getPrice(String coin);
} }
...@@ -10,6 +10,8 @@ import com.fzm.mall.server.front.redis.MerchantRedis; ...@@ -10,6 +10,8 @@ import com.fzm.mall.server.front.redis.MerchantRedis;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.math.BigDecimal;
/** /**
* <p> * <p>
* 服务实现类 * 服务实现类
...@@ -20,9 +22,13 @@ import org.springframework.stereotype.Service; ...@@ -20,9 +22,13 @@ import org.springframework.stereotype.Service;
*/ */
@Service @Service
public class MerchantServiceImpl extends ServiceImpl<MerchantMapper, Merchant> implements IMerchantService { public class MerchantServiceImpl extends ServiceImpl<MerchantMapper, Merchant> implements IMerchantService {
@Autowired @Autowired
private MerchantRedis merchantRedis; private MerchantRedis merchantRedis;
@Autowired
private MerchantMapper merchantMapper;
@Override @Override
public Merchant info(String merchantId) { public Merchant info(String merchantId) {
/*Merchant merchant = merchantRedis.getMerchant(merchantId); /*Merchant merchant = merchantRedis.getMerchant(merchantId);
...@@ -38,4 +44,8 @@ public class MerchantServiceImpl extends ServiceImpl<MerchantMapper, Merchant> i ...@@ -38,4 +44,8 @@ public class MerchantServiceImpl extends ServiceImpl<MerchantMapper, Merchant> i
return getOne(queryWrapper); return getOne(queryWrapper);
} }
@Override
public BigDecimal getPrice(String coin) {
return merchantMapper.getPrice(coin);
}
} }
...@@ -34,8 +34,11 @@ import io.netty.util.internal.StringUtil; ...@@ -34,8 +34,11 @@ import io.netty.util.internal.StringUtil;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import jdk.nashorn.internal.ir.annotations.Ignore; import jdk.nashorn.internal.ir.annotations.Ignore;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
...@@ -93,7 +96,6 @@ public class OrderController { ...@@ -93,7 +96,6 @@ public class OrderController {
String pid = ""; String pid = "";
try { try {
pid = orderService.createOrder(header.getUid(), orderVo, header.getType()); pid = orderService.createOrder(header.getUid(), orderVo, header.getType());
msgProducer.sendTTL(pid, QueueTTLTypeEnum.ORDER_CLOSE_TTL, configService.getConfig().getOrderCloseLimit());
} catch (Exception e) { } catch (Exception e) {
String msg = e.getMessage(); String msg = e.getMessage();
if (("商品不存在或下架").equals(msg)) { if (("商品不存在或下架").equals(msg)) {
...@@ -118,6 +120,46 @@ public class OrderController { ...@@ -118,6 +120,46 @@ public class OrderController {
return new ResponseVO<>(MallResponseEnum.SUCCESS, pid); return new ResponseVO<>(MallResponseEnum.SUCCESS, pid);
} }
@ApiOperation(value = "盲盒下单")
@PostMapping("/blindBox/createOrder")
public ResponseVO<String> blindBoxCreateOrder(@Ignore @RequestAttribute Header header, @RequestBody @Valid OrderBlindBoxVo orderVo) {
/**
* 參數校驗
*/
if(ObjectUtils.isEmpty(orderVo.getDelivery()) || StringUtils.isEmpty(orderVo.getGoodsId())){
return new ResponseVO<>(MallResponseEnum.PARAMETER_ERR);
}
String pid = "";
try {
pid = orderService.blindBoxCreateOrder(header.getUid(), header.getType(), orderVo);
} catch (Exception e) {
String msg = e.getMessage();
if (("商品不存在或下架").equals(msg)) {
return new ResponseVO<>(MallResponseEnum.GOODS_NOT_BUY);
} else if (("库存不足!!!").equals(msg)) {
return new ResponseVO<>(MallResponseEnum.GOOD_STOCK_NOT_ENOUGH);
} else if (("存在无效优惠券!!!").equals(msg)) {
return new ResponseVO<>(MallResponseEnum.GOOD_COUPON_NOT_EXIST);
} else if (("一个商品只能使用一个优惠券!!!").equals(msg)) {
return new ResponseVO<>(MallResponseEnum.GOOD_COUPON_NOT_EXIST);
} else if (("商品数量错误").equals(msg)) {
return new ResponseVO<>(MallResponseEnum.GOOD_NUM_ERR);
} else if (("当前地区不支持快递").equals(msg)) {
return new ResponseVO<>(MallResponseEnum.NOT_SUPPORT_MAIL);
}else if("活动火爆".equals(msg)){
return new ResponseVO<>(MallResponseEnum.HOT_ACTIVITY);
} else{
e.printStackTrace();
//数据库异常
return new ResponseVO<>(MallResponseEnum.DB_ERROR);
}
}
return new ResponseVO<>(MallResponseEnum.SUCCESS, pid);
}
@ApiOperation(value = "支付 参数 pid") @ApiOperation(value = "支付 参数 pid")
@PostMapping("/pay") @PostMapping("/pay")
public ResponseVO<String> pay(@Ignore @RequestAttribute Header header, @RequestBody PayVo payVo) { public ResponseVO<String> pay(@Ignore @RequestAttribute Header header, @RequestBody PayVo payVo) {
......
...@@ -26,6 +26,11 @@ import lombok.EqualsAndHashCode; ...@@ -26,6 +26,11 @@ import lombok.EqualsAndHashCode;
@ApiModel(value="Pay对象", description="支付订单结果表") @ApiModel(value="Pay对象", description="支付订单结果表")
public class Pay implements Serializable { public class Pay implements Serializable {
/**
* 支付状态:6->待付款
*/
public static final Integer PAY_STATE_TO_PAY = 6;
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "主键自增编号") @ApiModelProperty(value = "主键自增编号")
...@@ -50,7 +55,7 @@ public class Pay implements Serializable { ...@@ -50,7 +55,7 @@ public class Pay implements Serializable {
@ApiModelProperty(value = "待支付金额") @ApiModelProperty(value = "待支付金额")
private BigDecimal unpaidAmount; private BigDecimal unpaidAmount;
@ApiModelProperty(value = "支付方式, 1->支付宝,2->微信 , 3->ccny") @ApiModelProperty(value = "支付方式, 1->支付宝,2->微信 , 3->ccny 4:积分")
private Integer payType; private Integer payType;
@ApiModelProperty(value = "订单号") @ApiModelProperty(value = "订单号")
...@@ -73,5 +78,11 @@ public class Pay implements Serializable { ...@@ -73,5 +78,11 @@ public class Pay implements Serializable {
private String outBizNo; private String outBizNo;
@ApiModelProperty(value = "用于抵扣的积分名称")
@TableField(exist = false)
private String coin;
@ApiModelProperty(value = "用于抵扣的积分数量")
@TableField(exist = false)
private BigDecimal integralDeduction;
} }
package com.fzm.mall.server.front.order.model.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
import java.util.List;
@Data
public class OrderBlindBoxVo {
private static final long serialVersionUID = 1L;
/**
* 是否直接提货,1->是
*/
public static final Integer DELIVERY_IMMEDIATELY = 1;
@ApiModelProperty(value = "是否直接提货,0->否,1->是", required = true)
private Integer delivery;
@ApiModelProperty(value = "收货人名称")
private String uname;
@ApiModelProperty(value = "收人手机号")
private String phone;
@ApiModelProperty(value = "提货地址")
private String address;
@ApiModelProperty(value = "省份名字或直辖市")
private String province;
@ApiModelProperty(value = "盲盒商品id", required = true)
private String goodsId;
@ApiModelProperty(value = "用于抵扣的积分的名称")
private String coin;
@ApiModelProperty(value = "用于抵扣的积分的数量")
private BigDecimal coinNumber;
@ApiModelProperty(value = "备注")
private String vNote;
@ApiModelProperty(value = "优惠券列表")
private List<String> goodsIdCouponIdList;
}
package com.fzm.mall.server.front.order.service;
import com.fzm.mall.server.front.goods.model.vo.SkuVo;
/**
* <p>
* 盲盒
* </p>
*
* @author wulixian
* @since 2022-02-23
*/
public interface IOrderBindBoxService {
/**
* 随机抽取盲盒sku
* @param goodsId
* @return
*/
SkuVo genRandomSku(String goodsId);
}
...@@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.extension.service.IService; ...@@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
import com.fzm.mall.server.front.order.model.OrderDetail; import com.fzm.mall.server.front.order.model.OrderDetail;
import com.fzm.mall.server.front.order.model.po.NftOrderPo; import com.fzm.mall.server.front.order.model.po.NftOrderPo;
import com.fzm.mall.server.front.order.model.po.PreSaleOrderVo; import com.fzm.mall.server.front.order.model.po.PreSaleOrderVo;
import com.fzm.mall.server.front.order.model.vo.OrderBlindBoxVo;
import com.fzm.mall.server.front.order.model.vo.OrderVo; import com.fzm.mall.server.front.order.model.vo.OrderVo;
import com.fzm.mall.server.front.order.model.vo.ReturnMoneyDetail; import com.fzm.mall.server.front.order.model.vo.ReturnMoneyDetail;
...@@ -54,4 +55,13 @@ public interface IOrderService extends IService<Order> { ...@@ -54,4 +55,13 @@ public interface IOrderService extends IService<Order> {
String createPreSaleOrder(String uid, PreSaleOrderVo preSaleOrderVo); String createPreSaleOrder(String uid, PreSaleOrderVo preSaleOrderVo);
String createNftOrder(String uid, List<NftOrderPo> nftOrderPos); String createNftOrder(String uid, List<NftOrderPo> nftOrderPos);
/**
* 盲盒下单
* @param uid
* @param type
* @param orderVo
* @return
*/
String blindBoxCreateOrder(String uid, Integer type, OrderBlindBoxVo orderVo);
} }
package com.fzm.mall.server.front.order.service.impl;
import com.fzm.mall.server.front.constant.GoodMainConst;
import com.fzm.mall.server.front.goods.mapper.GoodSkuMapper;
import com.fzm.mall.server.front.goods.model.vo.SkuVo;
import com.fzm.mall.server.front.order.service.IOrderBindBoxService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
/**
* @author wulixian
* @since 2022/2/23
*/
@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class IOrderBindBoxServiceImpl implements IOrderBindBoxService {
private final GoodSkuMapper goodSkuMapper;
@Override
public SkuVo genRandomSku(String goodsId) {
SkuVo result = null;
/**
* 从数据库获取库存大于0的盲盒sku列表
*/
List<SkuVo> skuList = goodSkuMapper.listAvailableSku(goodsId);
if (!CollectionUtils.isEmpty(skuList)) {
int difficulty = skuList.stream().map(SkuVo::getDifficulty).findFirst().get();
result = genRandomSku(skuList, difficulty);
}
if (result == null) {
throw new RuntimeException("库存不足!!!");
}
//加时间锁
int i = goodSkuMapper.delStock(result.getSkuId(), GoodMainConst.BLIND_BOX_ORDER_SKU_NUM, result.getUpdateTime());
if (i == 0) {
throw new RuntimeException("活动火爆");
}
return result;
}
/**
* @param prodList 从数据库获取的库存大于0的盲盒产品列表
* @param difficulty 正整数[1,10]
* @return 随机产品规格
* @descprition 随机获得产品
* @author lyz
* @create 2022/2/14 9:42
*/
public static SkuVo genRandomSku(List<SkuVo> prodList, int difficulty) {
int hiddenWeight = difficulty == 10 ? 1 : (10 - difficulty);
List<SkuVo> baseList = new ArrayList<>();
for (SkuVo prodItem : prodList) {
if (prodItem.getIsHide()) {
for (int i = 0; i < hiddenWeight; i++) {
baseList.add(prodItem);
}
} else {
for (int i = 0; i < difficulty; i++) {
baseList.add(prodItem);
}
}
}
//为了增加随机度,可以打开
//Collections.shuffle(baseList);
int base = baseList.size();
int randomNum = ThreadLocalRandom.current().nextInt(base);
return baseList.get(randomNum);
}
}
...@@ -7,4 +7,15 @@ ...@@ -7,4 +7,15 @@
from goods_sku from goods_sku
where goods_id = #{goodsId} where goods_id = #{goodsId}
</select> </select>
<select id="listAvailableSku" resultType="com.fzm.mall.server.front.goods.model.vo.SkuVo">
select sk.*, sp.difficulty, sp.merchant_id, sp.blind_box_price as blindBoxprice
from goods_sku sk
left join goods_spu sp on sk.goods_id = sp.goods_id
where sk.goods_id = #{goodsId} and sk.status = '1' and sk.stock > 0
</select>
<update id="delStock">
update goods_sku set stock =stock - #{num} where sku_id = #{skuId} and stock >= #{num} and update_time = #{updateTime}
</update>
</mapper> </mapper>
...@@ -2,4 +2,9 @@ ...@@ -2,4 +2,9 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.fzm.mall.server.front.merchant.mapper.MerchantMapper"> <mapper namespace="com.fzm.mall.server.front.merchant.mapper.MerchantMapper">
<select id="getPrice" resultType="decimal">
select price
from merchant_integral
where label = #{coin}
</select>
</mapper> </mapper>
...@@ -58,4 +58,5 @@ NOT_SUPPORT_BUY_MYSELF=\u6682\u4E0D\u652F\u6301\u81EA\u5DF1\u4E70\u81EA\u5DF1\u7 ...@@ -58,4 +58,5 @@ NOT_SUPPORT_BUY_MYSELF=\u6682\u4E0D\u652F\u6301\u81EA\u5DF1\u4E70\u81EA\u5DF1\u7
ONLY_SUPPORT_MAIL=\u5F53\u524D\u5546\u54C1\u4EC5\u652F\u6301\u63D0\u8D27 ONLY_SUPPORT_MAIL=\u5F53\u524D\u5546\u54C1\u4EC5\u652F\u6301\u63D0\u8D27
RECORD_EXIST=\u76F8\u5173\u4EA4\u6613\u8BB0\u5F55\u5DF2\u5B58\u5728\uFF0C\u53D6\u6D88\u5931\u8D25 RECORD_EXIST=\u76F8\u5173\u4EA4\u6613\u8BB0\u5F55\u5DF2\u5B58\u5728\uFF0C\u53D6\u6D88\u5931\u8D25
ADDR_INVALID=\u65E0\u6548\u5730\u5740 ADDR_INVALID=\u65E0\u6548\u5730\u5740
SEND_CODE_ERR=\u77ED\u4FE1\u53D1\u9001\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5 SEND_CODE_ERR=\u77ED\u4FE1\u53D1\u9001\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5
\ No newline at end of file HOT_ACTIVITY=\u6D3B\u52A8\u592A\u8FC7\u706B\u7206\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5
\ No newline at end of file
package com.fzm.mall.server.front;
import lombok.Builder;
import lombok.Data;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
/**
* @author lyz
* @mail lyz@disanbo.com
* @create 2022/2/10 14:20
* @description
*/
public class BlindBoxTest {
public static void main(String[] args) {
ProdItem prod1 = ProdItem.builder().prodId("111111").isHidden(false).build();
ProdItem prod2 = ProdItem.builder().prodId("222222").isHidden(false).build();
ProdItem prod3 = ProdItem.builder().prodId("333333").isHidden(false).build();
ProdItem prod4 = ProdItem.builder().prodId("444444").isHidden(false).build();
ProdItem prod5 = ProdItem.builder().prodId("555555").isHidden(true).build();
ProdItem prod6 = ProdItem.builder().prodId("666666").isHidden(false).build();
List<ProdItem> prodList = new ArrayList<>();
prodList.add(prod1);
prodList.add(prod6);
prodList.add(prod3);
prodList.add(prod2);
prodList.add(prod5);
prodList.add(prod4);
System.out.println(genRandomProd(prodList, 1));
}
/**
* @descprition 随机获得产品
* @author lyz
* @create 2022/2/14 9:42
* @param prodList 从数据库获取的库存大于0的盲盒产品列表
* @param difficulty 正整数[1,10]
* @return 随机产品编号
*/
public static String genRandomProd(List<ProdItem> prodList, int difficulty){
int hiddenWeight = difficulty == 10 ? 1 : (10 - difficulty);
List<String> baseList = new ArrayList<>();
for(ProdItem prodItem : prodList){
if(prodItem.isHidden){
for(int i=0;i<hiddenWeight;i++){
baseList.add(prodItem.prodId);
}
}else{
for(int i=0;i<difficulty;i++){
baseList.add(prodItem.prodId);
}
}
}
//为了增加随机度,可以打开
//Collections.shuffle(baseList);
int base = baseList.size();
int randomNum = ThreadLocalRandom.current().nextInt(base);
return baseList.get(randomNum);
}
@Data
@Builder
static class ProdItem {
private String prodId;
private boolean isHidden;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment