领取优惠券操作
This commit is contained in:
@@ -7,6 +7,7 @@ import com.chaozhanggui.system.cashierservice.exception.MsgException;
|
||||
import com.chaozhanggui.system.cashierservice.redis.RedisUtil;
|
||||
import com.chaozhanggui.system.cashierservice.util.DateUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -40,7 +41,8 @@ public class IntegralService {
|
||||
private TbReleaseFlowMapper integralFlowMapper;
|
||||
@Autowired
|
||||
private TbUserCouponsMapper userCouponsMapper;
|
||||
|
||||
@Autowired
|
||||
private TbSplitAccountsMapper splitAccountsMapper;
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void integralAdd(JSONObject jsonObject) throws ParseException {
|
||||
@@ -66,18 +68,37 @@ public class IntegralService {
|
||||
}else {
|
||||
Integer orderId = jsonObject.getInteger("orderId");
|
||||
TbOrderInfo orderInfo = orderInfoMapper.selectByPrimaryKey(orderId);
|
||||
if (StringUtils.isNotBlank(orderInfo.getUserCouponId())){
|
||||
TbUserCoupons userCoupons = userCouponsMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getUserCouponId()));
|
||||
if (Objects.nonNull(userCoupons)){
|
||||
TbShopInfo shopInfo = shopInfoMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getShopId()));
|
||||
TbSplitAccounts splitAccounts = new TbSplitAccounts();
|
||||
splitAccounts.setConponsAmount(userCoupons.getCouponsAmount());
|
||||
splitAccounts.setCreateTime(new Date());
|
||||
splitAccounts.setIsSplit("false");
|
||||
splitAccounts.setMerchantId(Integer.valueOf(shopInfo.getMerchantId()));
|
||||
splitAccounts.setShopId(shopInfo.getId());
|
||||
splitAccounts.setOrderAmount(orderInfo.getPayAmount());
|
||||
splitAccounts.setTradeDay(DateUtils.getDay());
|
||||
splitAccounts.setOriginAmount(orderInfo.getOriginAmount());
|
||||
splitAccountsMapper.insert(splitAccounts);
|
||||
}
|
||||
}
|
||||
if (Objects.isNull(orderInfo)) {
|
||||
throw new MsgException("该订单不存在");
|
||||
log.error("该订单不存在");
|
||||
return;
|
||||
}
|
||||
TbShopInfo shopInfo = shopInfoMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getShopId()));
|
||||
if (Objects.isNull(shopInfo) || !"true".equals(shopInfo.getIsOpenYhq())){
|
||||
throw new MsgException("该店铺未开启优惠券功能");
|
||||
log.error("该店铺未开启优惠券功能");
|
||||
return;
|
||||
}
|
||||
TbParams params = tbShopUserMapper.selectParams();
|
||||
TbUserCoupons userCoupons = new TbUserCoupons();
|
||||
userCoupons.setUserId(orderInfo.getUserId());
|
||||
userCoupons.setCouponsAmount(orderInfo.getPayAmount().multiply(params.getIntegralRatio()));
|
||||
userCoupons.setStatus("0");
|
||||
userCoupons.setOrderId(orderId);
|
||||
userCoupons.setCouponsPrice(userCoupons.getCouponsAmount().multiply(new BigDecimal("0.5")));
|
||||
userCoupons.setCreateTime(new Date());
|
||||
userCoupons.setEndTime(DateUtils.getNewDate(new Date(),3,30));
|
||||
|
||||
@@ -79,6 +79,8 @@ public class OrderService {
|
||||
private TbSystemCouponsMapper systemCouponsMapper;
|
||||
@Autowired
|
||||
private TbYhqParamsMapper yhqParamsMapper;
|
||||
@Autowired
|
||||
private TbShopUserMapper shopUserMapper;
|
||||
/**
|
||||
* 创建订单
|
||||
*
|
||||
@@ -295,7 +297,9 @@ public class OrderService {
|
||||
releaseFlow.setCreateTime(new Date());
|
||||
releaseFlow.setFromSource("OWER");
|
||||
releaseFlow.setUserId(userId);
|
||||
releaseFlow.setOperationType("ADD");
|
||||
releaseFlow.setType("EXCHANGEADD");
|
||||
releaseFlow.setRemark("兑换增加");
|
||||
releaseFlowMapper.insert(releaseFlow);
|
||||
redisUtils.releaseLock(RedisCst.INTEGRAL_COIN_KEY + userId);
|
||||
} else {
|
||||
@@ -359,4 +363,38 @@ public class OrderService {
|
||||
producer.printCoupons(coupons.toJSONString());
|
||||
return Result.success(CodeEnum.SUCCESS);
|
||||
}
|
||||
|
||||
public Result getYhqDouble(Integer orderId) {
|
||||
TbUserCoupons userCoupons = userCouponsMapper.selectByOrderId(orderId);
|
||||
return Result.success(CodeEnum.SUCCESS,userCoupons);
|
||||
}
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Result yhqDouble(Integer conponsId) {
|
||||
TbUserCoupons userCoupons = userCouponsMapper.selectByPrimaryKey(conponsId);
|
||||
if (Objects.isNull(userCoupons) || userCoupons.getIsDouble().equals("true")){
|
||||
throw new MsgException("该优惠券翻倍已领取");
|
||||
}
|
||||
return Result.success(CodeEnum.SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
private void modityDouble(Integer conponsId) throws ParseException {
|
||||
|
||||
boolean lock_coin = redisUtils.lock(RedisCst.COUPONS_COIN_KEY + conponsId, 5000, TimeUnit.MILLISECONDS);
|
||||
if (lock_coin) {
|
||||
TbUserCoupons userCoupons = userCouponsMapper.selectByPrimaryKey(conponsId);
|
||||
if (Objects.isNull(userCoupons) || !userCoupons.getStatus().equals("0") || userCoupons.getIsDouble().equals("true")) {
|
||||
throw new MsgException("该优惠券已翻倍");
|
||||
}
|
||||
TbParams params = shopUserMapper.selectParams();
|
||||
userCoupons.setIsDouble("true");
|
||||
userCoupons.setCouponsAmount(userCoupons.getCouponsAmount().multiply(params.getTwoRatio()));
|
||||
userCoupons.setCouponsPrice(userCoupons.getCouponsPrice().multiply(params.getTwoRatio()));
|
||||
userCoupons.setUpdateTime(new Date());
|
||||
userCouponsMapper.updateByPrimaryKeySelective(userCoupons);
|
||||
redisUtils.releaseLock(RedisCst.COUPONS_COIN_KEY + conponsId);
|
||||
} else {
|
||||
modityDouble(conponsId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
|
||||
import com.chaozhanggui.system.cashierservice.sign.Result;
|
||||
import com.chaozhanggui.system.cashierservice.util.*;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -32,7 +33,8 @@ public class UserService {
|
||||
private TbShopUserMapper shopUserMapper;
|
||||
@Autowired
|
||||
private TbReleaseFlowMapper releaseFlowMapper;
|
||||
|
||||
@Autowired
|
||||
private TbUserInfoMapper userInfoMapper;
|
||||
@Autowired
|
||||
RedisUtils redisUtils;
|
||||
|
||||
@@ -65,7 +67,7 @@ public class UserService {
|
||||
result.put("data", "");
|
||||
return result;
|
||||
}
|
||||
boolean falg = updateIntegral(shopUser.getId(), integralVo.getNum(), integralVo.getType());
|
||||
boolean falg = updateIntegral(shopUser.getUserId(), integralVo.getNum(), integralVo.getType());
|
||||
if (!falg) {
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("status", "fail");
|
||||
@@ -96,16 +98,16 @@ public class UserService {
|
||||
|
||||
boolean lock_coin = redisUtils.lock(RedisCst.INTEGRAL_COIN_KEY + userId, 5000, TimeUnit.MILLISECONDS);
|
||||
if (lock_coin) {
|
||||
TbShopUser tbShopUser = shopUserMapper.selectByPrimaryKey(userId);
|
||||
TbUserInfo tbShopUser = userInfoMapper.selectByPrimaryKey(Integer.valueOf(userId));
|
||||
boolean flag = true;
|
||||
if (type.equals("sub")) {
|
||||
if (N.gt(num, tbShopUser.getLevelConsume())) {
|
||||
if (num.intValue() < tbShopUser.getTotalScore()) {
|
||||
flag = false;
|
||||
} else {
|
||||
tbShopUser.setLevelConsume(tbShopUser.getLevelConsume().subtract(num));
|
||||
tbShopUser.setTotalScore(tbShopUser.getTotalScore() - num.intValue());
|
||||
}
|
||||
} else if (type.equals("add")) {
|
||||
tbShopUser.setLevelConsume(tbShopUser.getLevelConsume().add(num));
|
||||
tbShopUser.setTotalScore(tbShopUser.getTotalScore() - num.intValue());
|
||||
}
|
||||
if (flag) {
|
||||
TbReleaseFlow releaseFlow = new TbReleaseFlow();
|
||||
@@ -115,11 +117,15 @@ public class UserService {
|
||||
releaseFlow.setUserId(userId);
|
||||
if (type.equals("sub")) {
|
||||
releaseFlow.setType("BUYSUB");
|
||||
}else if (type.equals("sub")){
|
||||
releaseFlow.setOperationType("SUB");
|
||||
releaseFlow.setRemark("购买商品扣除");
|
||||
} else if (type.equals("sub")) {
|
||||
releaseFlow.setType("THREEADD");
|
||||
releaseFlow.setOperationType("ADD");
|
||||
releaseFlow.setRemark("退货增加");
|
||||
}
|
||||
releaseFlowMapper.insert(releaseFlow);
|
||||
shopUserMapper.updateByPrimaryKeySelective(tbShopUser);
|
||||
userInfoMapper.updateByPrimaryKeySelective(tbShopUser);
|
||||
}
|
||||
redisUtils.releaseLock(RedisCst.INTEGRAL_COIN_KEY + userId);
|
||||
return flag;
|
||||
@@ -141,7 +147,7 @@ public class UserService {
|
||||
result.put("data", "");
|
||||
return result;
|
||||
}
|
||||
TbShopUser shopUser = shopUserMapper.selectByOpenId(integralFlowVo.getOpenId());
|
||||
TbUserInfo shopUser = userInfoMapper.selectByOpenId(integralFlowVo.getOpenId());
|
||||
if (Objects.isNull(shopUser)) {
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("status", "fail");
|
||||
@@ -151,11 +157,65 @@ public class UserService {
|
||||
}
|
||||
PageHelper.startPage(integralFlowVo.getPage(), integralFlowVo.getPageSize());
|
||||
PageHelper.orderBy("id DESC");
|
||||
List<TbReleaseFlow> list = releaseFlowMapper.selectByUserId(shopUser.getId());
|
||||
List<TbReleaseFlow> list = releaseFlowMapper.selectByUserId(shopUser.getId().toString());
|
||||
for (TbReleaseFlow tbReleaseFlow:list){
|
||||
tbReleaseFlow.setCreateTr(DateUtils.getStrTime(tbReleaseFlow.getCreateTime()));
|
||||
}
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("status", "success");
|
||||
result.put("msg", "成功");
|
||||
result.put("data",list);
|
||||
result.put("data", list);
|
||||
return result;
|
||||
}
|
||||
|
||||
public JSONObject userAllIntegral(IntegralFlowVo integralFlowVo, String userSign) {
|
||||
// JSONObject object = (JSONObject) JSONObject.toJSON(integralFlowVo);
|
||||
// object.put("userSign", userSign);
|
||||
// JSONObject jsonObject = JSONUtil.sortJSONObject(object, CacheMap.notOpenMap);
|
||||
// System.out.println(jsonObject.toJSONString());
|
||||
// String sign = MD5Util.encrypt(jsonObject.toJSONString());
|
||||
// if (!sign.equals(integralFlowVo.getSign())) {
|
||||
// JSONObject result = new JSONObject();
|
||||
// result.put("status", "fail");
|
||||
// result.put("msg", "签名验证失败");
|
||||
// result.put("data", "");
|
||||
// return result;
|
||||
// }
|
||||
PageHelper.startPage(integralFlowVo.getPage(), integralFlowVo.getPageSize());
|
||||
PageHelper.orderBy("id DESC");
|
||||
List<TbReleaseFlow> list = releaseFlowMapper.selectAll();
|
||||
for (TbReleaseFlow tbReleaseFlow:list){
|
||||
tbReleaseFlow.setCreateTr(DateUtils.getStrTime(tbReleaseFlow.getCreateTime()));
|
||||
}
|
||||
PageInfo pageInfo = new PageInfo(list);
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("status", "success");
|
||||
result.put("msg", "成功");
|
||||
result.put("data", pageInfo);
|
||||
return result;
|
||||
}
|
||||
|
||||
public JSONObject userAll(IntegralFlowVo integralFlowVo, String userSign) {
|
||||
// JSONObject object = (JSONObject) JSONObject.toJSON(integralFlowVo);
|
||||
// object.put("userSign", userSign);
|
||||
// JSONObject jsonObject = JSONUtil.sortJSONObject(object, CacheMap.notOpenMap);
|
||||
// System.out.println(jsonObject.toJSONString());
|
||||
// String sign = MD5Util.encrypt(jsonObject.toJSONString());
|
||||
// if (!sign.equals(integralFlowVo.getSign())) {
|
||||
// JSONObject result = new JSONObject();
|
||||
// result.put("status", "fail");
|
||||
// result.put("msg", "签名验证失败");
|
||||
// result.put("data", "");
|
||||
// return result;
|
||||
// }
|
||||
PageHelper.startPage(integralFlowVo.getPage(), integralFlowVo.getPageSize());
|
||||
PageHelper.orderBy("id DESC");
|
||||
List<TbUserInfo> list = userInfoMapper.selectAll();
|
||||
PageInfo pageInfo = new PageInfo(list);
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("status", "success");
|
||||
result.put("msg", "成功");
|
||||
result.put("data", pageInfo);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user