优惠券+异常全局处理
This commit is contained in:
@@ -213,7 +213,7 @@ public class CartService {
|
||||
BigDecimal packAMount = BigDecimal.ZERO;
|
||||
BigDecimal originAmount = BigDecimal.ZERO;
|
||||
BigDecimal saleAmount = BigDecimal.ZERO;
|
||||
String couponId = "";
|
||||
String couponId = jsonObject.getString("couponsId");
|
||||
BigDecimal couponAmount = BigDecimal.ZERO;
|
||||
Map<Integer, TbProductSku> skuMap = new HashMap<>();
|
||||
List<TbOrderDetail> orderDetails = new ArrayList<>();
|
||||
@@ -270,12 +270,12 @@ public class CartService {
|
||||
//生成订单
|
||||
TbOrderInfo orderInfo = orderInfoMapper.selectByPrimaryKey(orderId);
|
||||
String isBuyYhq = "false";
|
||||
if (jsonObject.containsKey("isYhq")){
|
||||
if (jsonObject.containsKey("isYhq") && jsonObject.getString("isYhq").equals("1")) {
|
||||
//1:购买优惠券,0:自己持有优惠券
|
||||
Integer couponsId = jsonObject.getInteger("couponsId");
|
||||
if (jsonObject.getString("isBuyYhq").equals("1")){
|
||||
if (jsonObject.getString("isBuyYhq").equals("1")) {
|
||||
TbSystemCoupons systemCoupons = systemCouponsMapper.selectByPrimaryKey(couponsId);
|
||||
if (Objects.isNull(systemCoupons) || !systemCoupons.getStatus().equals("0")){
|
||||
if (Objects.isNull(systemCoupons) || !systemCoupons.getStatus().equals("0")) {
|
||||
log.info("开始处理订单");
|
||||
JSONObject jsonObject1 = new JSONObject();
|
||||
jsonObject1.put("status", "fail");
|
||||
@@ -286,7 +286,7 @@ public class CartService {
|
||||
log.info("消息推送");
|
||||
return;
|
||||
}
|
||||
if (N.gt(systemCoupons.getCouponsAmount(),totalAmount)){
|
||||
if (N.gt(systemCoupons.getCouponsAmount(), totalAmount)) {
|
||||
log.info("开始处理订单");
|
||||
JSONObject jsonObject1 = new JSONObject();
|
||||
jsonObject1.put("status", "fail");
|
||||
@@ -299,21 +299,22 @@ public class CartService {
|
||||
}
|
||||
totalAmount = totalAmount.add(systemCoupons.getCouponsPrice()).subtract(systemCoupons.getCouponsAmount());
|
||||
originAmount = originAmount.add(systemCoupons.getCouponsPrice());
|
||||
couponAmount = systemCoupons.getCouponsAmount();
|
||||
systemCoupons.setStatus("1");
|
||||
systemCouponsMapper.updateByPrimaryKeySelective(systemCoupons);
|
||||
TbUserCoupons userCoupons = new TbUserCoupons();
|
||||
userCoupons.setEndTime(DateUtils.getNewDate(new Date(),3,systemCoupons.getDayNum()));
|
||||
userCoupons.setEndTime(DateUtils.getNewDate(new Date(), 3, systemCoupons.getDayNum()));
|
||||
userCoupons.setCouponsAmount(systemCoupons.getCouponsAmount());
|
||||
userCoupons.setCouponsPrice(systemCoupons.getCouponsPrice());
|
||||
userCoupons.setStatus("1");
|
||||
userCoupons.setUserId(userId);
|
||||
userCoupons.setCreateTime(new Date());
|
||||
userCouponsMapper.insert(userCoupons);
|
||||
couponId = userCoupons.getId()+"";
|
||||
couponId = userCoupons.getId() + "";
|
||||
couponAmount = userCoupons.getCouponsAmount();
|
||||
}else {
|
||||
} else {
|
||||
TbUserCoupons userCoupons = userCouponsMapper.selectByPrimaryKey(couponsId);
|
||||
if (Objects.isNull(userCoupons) || !userCoupons.getStatus().equals("0")){
|
||||
if (Objects.isNull(userCoupons) || !userCoupons.getStatus().equals("0")) {
|
||||
log.info("开始处理订单");
|
||||
JSONObject jsonObject1 = new JSONObject();
|
||||
jsonObject1.put("status", "fail");
|
||||
@@ -324,7 +325,7 @@ public class CartService {
|
||||
log.info("消息推送");
|
||||
return;
|
||||
}
|
||||
if (N.gt(userCoupons.getCouponsAmount(),totalAmount)){
|
||||
if (N.gt(userCoupons.getCouponsAmount(), totalAmount)) {
|
||||
log.info("开始处理订单");
|
||||
JSONObject jsonObject1 = new JSONObject();
|
||||
jsonObject1.put("status", "fail");
|
||||
@@ -337,93 +338,94 @@ public class CartService {
|
||||
}
|
||||
totalAmount = totalAmount.subtract(userCoupons.getCouponsAmount());
|
||||
userCoupons.setStatus("1");
|
||||
userCoupons.setEndTime(DateUtils.getNewDate(new Date(),5,30));
|
||||
userCoupons.setEndTime(DateUtils.getNewDate(new Date(), 5, 30));
|
||||
userCouponsMapper.updateByPrimaryKeySelective(userCoupons);
|
||||
couponAmount = userCoupons.getCouponsAmount();
|
||||
}
|
||||
}else {
|
||||
if (Objects.nonNull(orderInfo)) {
|
||||
log.info("订单状态:" + orderInfo.getStatus());
|
||||
if (!"unpaid".equals(orderInfo.getStatus())) {
|
||||
log.info("开始处理订单");
|
||||
JSONObject jsonObject1 = new JSONObject();
|
||||
jsonObject1.put("status", "fail");
|
||||
jsonObject1.put("msg", "订单正在支付中,请稍后再试");
|
||||
jsonObject1.put("type", jsonObject.getString("type"));
|
||||
jsonObject1.put("data", "");
|
||||
AppWebSocketServer.AppSendInfo(jsonObject1, jsonObject.getString("userId"), true);
|
||||
log.info("消息推送");
|
||||
return;
|
||||
}
|
||||
|
||||
orderDetailMapper.deleteByOUrderId(orderId);
|
||||
orderInfo.setUpdatedAt(System.currentTimeMillis());
|
||||
orderInfo.setSettlementAmount(totalAmount);
|
||||
orderInfo.setUserCouponId(couponId);
|
||||
orderInfo.setUserCouponAmount(couponAmount);
|
||||
orderInfo.setAmount(totalAmount);
|
||||
orderInfo.setOriginAmount(originAmount);
|
||||
orderInfo.setOrderAmount(totalAmount.add(packAMount));
|
||||
orderInfo.setFreightAmount(BigDecimal.ZERO);
|
||||
orderInfo.setProductAmount(saleAmount);
|
||||
orderInfo.setUserCouponId(couponId);
|
||||
orderInfo.setIsBuyCoupon(isBuyYhq);
|
||||
orderInfo.setUserCouponAmount(couponAmount);
|
||||
orderInfoMapper.updateByPrimaryKeySelective(orderInfo);
|
||||
} else {
|
||||
orderInfo.setMerchantId(String.valueOf(tbMerchantAccount.getId()));
|
||||
orderInfo = getOrder(totalAmount,packAMount,shopTable,tbMerchantAccount.getId().toString(),jsonObject,originAmount);
|
||||
orderInfo.setUserCouponId(couponId);
|
||||
orderInfo.setOriginAmount(originAmount);
|
||||
orderInfo.setIsBuyCoupon(isBuyYhq);
|
||||
orderInfo.setUserCouponAmount(couponAmount);
|
||||
orderInfoMapper.insert(orderInfo);
|
||||
orderId = orderInfo.getId();
|
||||
}
|
||||
for (TbOrderDetail orderDetail : orderDetails) {
|
||||
orderDetail.setOrderId(orderId);
|
||||
orderDetailMapper.insert(orderDetail);
|
||||
}
|
||||
for (int i = 0; i < array.size(); i++) {
|
||||
JSONObject object = array.getJSONObject(i);
|
||||
TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(object.toJSONString(), TbCashierCart.class);
|
||||
cashierCart.setUpdatedAt(System.currentTimeMillis());
|
||||
cashierCart.setOrderId(orderId + "");
|
||||
cashierCart.setStatus("closed");
|
||||
cashierCartMapper.updateByPrimaryKeySelective(cashierCart);
|
||||
object.put("updatedAt", System.currentTimeMillis());
|
||||
object.put("orderId", orderId + "");
|
||||
}
|
||||
redisUtil.saveMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId")).concat("-").concat(shopId), array.toJSONString());
|
||||
orderInfo.setDetailList(orderDetails);
|
||||
JSONObject jsonObject1 = new JSONObject();
|
||||
jsonObject1.put("status", "success");
|
||||
jsonObject1.put("msg", "成功");
|
||||
jsonObject1.put("type", jsonObject.getString("type"));
|
||||
jsonObject1.put("data", orderInfo);
|
||||
redisUtil.deleteByKey(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId")).concat("-").concat(shopId));
|
||||
AppWebSocketServer.AppSendInfo(jsonObject1, jsonObject.getString("userId"), true);
|
||||
JSONObject jsonObject12 = new JSONObject();
|
||||
jsonObject12.put("status", "success");
|
||||
jsonObject12.put("msg", "成功");
|
||||
jsonObject12.put("type", "order");
|
||||
jsonObject12.put("amount", BigDecimal.ZERO);
|
||||
|
||||
jsonObject12.put("data", new JSONArray());
|
||||
AppWebSocketServer.AppSendInfo(jsonObject12, jsonObject.getString("tableId").concat("-").concat(shopId), false);
|
||||
}
|
||||
if (Objects.nonNull(orderInfo)) {
|
||||
log.info("订单状态:" + orderInfo.getStatus());
|
||||
if (!"unpaid".equals(orderInfo.getStatus())) {
|
||||
log.info("开始处理订单");
|
||||
JSONObject jsonObject1 = new JSONObject();
|
||||
jsonObject1.put("status", "fail");
|
||||
jsonObject1.put("msg", "订单正在支付中,请稍后再试");
|
||||
jsonObject1.put("type", jsonObject.getString("type"));
|
||||
jsonObject1.put("data", "");
|
||||
AppWebSocketServer.AppSendInfo(jsonObject1, jsonObject.getString("userId"), true);
|
||||
log.info("消息推送");
|
||||
return;
|
||||
}
|
||||
|
||||
orderDetailMapper.deleteByOUrderId(orderId);
|
||||
orderInfo.setUpdatedAt(System.currentTimeMillis());
|
||||
orderInfo.setSettlementAmount(totalAmount);
|
||||
orderInfo.setUserCouponId(couponId);
|
||||
orderInfo.setUserCouponAmount(couponAmount);
|
||||
orderInfo.setAmount(totalAmount);
|
||||
orderInfo.setOriginAmount(originAmount);
|
||||
orderInfo.setOrderAmount(totalAmount.add(packAMount));
|
||||
orderInfo.setFreightAmount(BigDecimal.ZERO);
|
||||
orderInfo.setProductAmount(saleAmount);
|
||||
orderInfo.setIsBuyCoupon(isBuyYhq);
|
||||
orderInfoMapper.updateByPrimaryKeySelective(orderInfo);
|
||||
} else {
|
||||
orderInfo = getOrder(totalAmount, packAMount, shopTable, tbMerchantAccount.getId().toString(), jsonObject, originAmount);
|
||||
orderInfo.setMerchantId(String.valueOf(tbMerchantAccount.getId()));
|
||||
orderInfo.setUserCouponId(couponId);
|
||||
orderInfo.setOriginAmount(originAmount);
|
||||
orderInfo.setIsBuyCoupon(isBuyYhq);
|
||||
orderInfo.setUserCouponAmount(couponAmount);
|
||||
orderInfoMapper.insert(orderInfo);
|
||||
orderId = orderInfo.getId();
|
||||
}
|
||||
for (TbOrderDetail orderDetail : orderDetails) {
|
||||
orderDetail.setOrderId(orderId);
|
||||
orderDetailMapper.insert(orderDetail);
|
||||
}
|
||||
for (int i = 0; i < array.size(); i++) {
|
||||
JSONObject object = array.getJSONObject(i);
|
||||
TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(object.toJSONString(), TbCashierCart.class);
|
||||
cashierCart.setUpdatedAt(System.currentTimeMillis());
|
||||
cashierCart.setOrderId(orderId + "");
|
||||
cashierCart.setStatus("closed");
|
||||
cashierCartMapper.updateByPrimaryKeySelective(cashierCart);
|
||||
object.put("updatedAt", System.currentTimeMillis());
|
||||
object.put("orderId", orderId + "");
|
||||
}
|
||||
redisUtil.saveMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId")).concat("-").concat(shopId), array.toJSONString());
|
||||
orderInfo.setDetailList(orderDetails);
|
||||
JSONObject jsonObject1 = new JSONObject();
|
||||
jsonObject1.put("status", "success");
|
||||
jsonObject1.put("msg", "成功");
|
||||
jsonObject1.put("type", jsonObject.getString("type"));
|
||||
jsonObject1.put("data", orderInfo);
|
||||
redisUtil.deleteByKey(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId")).concat("-").concat(shopId));
|
||||
AppWebSocketServer.AppSendInfo(jsonObject1, jsonObject.getString("userId"), true);
|
||||
JSONObject jsonObject12 = new JSONObject();
|
||||
jsonObject12.put("status", "success");
|
||||
jsonObject12.put("msg", "成功");
|
||||
jsonObject12.put("type", "order");
|
||||
jsonObject12.put("amount", BigDecimal.ZERO);
|
||||
|
||||
jsonObject12.put("data", new JSONArray());
|
||||
AppWebSocketServer.AppSendInfo(jsonObject12, jsonObject.getString("tableId").concat("-").concat(shopId), false);
|
||||
} catch (Exception e) {
|
||||
e.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
private TbOrderInfo getOrder(BigDecimal totalAmount, BigDecimal packAMount,
|
||||
TbShopTable shopTable, String merchantId, JSONObject jsonObject, BigDecimal originAmount){
|
||||
TbShopTable shopTable, String merchantId, JSONObject jsonObject, BigDecimal originAmount) {
|
||||
TbOrderInfo orderInfo = new TbOrderInfo();
|
||||
String orderNo = generateOrderNumber();
|
||||
orderInfo.setOrderNo(orderNo);
|
||||
orderInfo.setSettlementAmount(totalAmount);
|
||||
orderInfo.setPackFee(packAMount);
|
||||
orderInfo.setOriginAmount(originAmount);
|
||||
orderInfo.setProductAmount(totalAmount);
|
||||
orderInfo.setProductAmount(originAmount);
|
||||
orderInfo.setAmount(totalAmount);
|
||||
orderInfo.setOrderAmount(totalAmount.add(packAMount));
|
||||
orderInfo.setPayAmount(BigDecimal.ZERO);
|
||||
@@ -445,12 +447,14 @@ public class CartService {
|
||||
orderInfo.setMerchantId(merchantId);
|
||||
return orderInfo;
|
||||
}
|
||||
|
||||
public String generateOrderNumber() {
|
||||
String date = DateUtils.getSdfTimes();
|
||||
Random random = new Random();
|
||||
int randomNum = random.nextInt(900) + 100;
|
||||
return "WX" + date + randomNum;
|
||||
}
|
||||
|
||||
public void clearCart(JSONObject jsonObject) throws IOException {
|
||||
String shopId = jsonObject.getString("shopId");
|
||||
if (redisUtil.exists(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId)))) {
|
||||
|
||||
@@ -156,6 +156,11 @@ public class LoginService {
|
||||
}
|
||||
return Result.fail("登录失败");
|
||||
}
|
||||
public static void main(String[] args) throws Exception {
|
||||
String token = TokenUtil.generateToken(19, "or1l8654IFK6GIBQjK1ZKaPH3x0M",
|
||||
"19191703856", "微信用户");
|
||||
System.out.println(token);
|
||||
}
|
||||
|
||||
public TbUserInfo register(String phone, String password, String nickName) {
|
||||
|
||||
@@ -304,9 +309,5 @@ public class LoginService {
|
||||
return Result.success(CodeEnum.ENCRYPT, map);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
System.out.println(RandomUtil.randomNumbers(10));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,17 +3,20 @@ package com.chaozhanggui.system.cashierservice.service;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.chaozhanggui.system.cashierservice.dao.*;
|
||||
import com.chaozhanggui.system.cashierservice.entity.*;
|
||||
import com.chaozhanggui.system.cashierservice.entity.vo.CashierCarVo;
|
||||
import com.chaozhanggui.system.cashierservice.entity.vo.OrderVo;
|
||||
import com.chaozhanggui.system.cashierservice.exception.MsgException;
|
||||
import com.chaozhanggui.system.cashierservice.rabbit.RabbitProducer;
|
||||
import com.chaozhanggui.system.cashierservice.redis.RedisCst;
|
||||
import com.chaozhanggui.system.cashierservice.redis.RedisUtil;
|
||||
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
|
||||
import com.chaozhanggui.system.cashierservice.sign.Result;
|
||||
import com.chaozhanggui.system.cashierservice.socket.AppWebSocketServer;
|
||||
import com.chaozhanggui.system.cashierservice.util.DateUtils;
|
||||
import com.chaozhanggui.system.cashierservice.util.N;
|
||||
import com.chaozhanggui.system.cashierservice.util.RedisUtils;
|
||||
import com.chaozhanggui.system.cashierservice.util.SnowFlakeUtil;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
@@ -27,6 +30,7 @@ import javax.annotation.Resource;
|
||||
import java.awt.print.Pageable;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.text.ParseException;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
@@ -41,7 +45,7 @@ import java.util.concurrent.TimeUnit;
|
||||
public class OrderService {
|
||||
|
||||
@Resource
|
||||
private TbShopUserMapper shopUserMapper;
|
||||
private RabbitProducer producer;
|
||||
|
||||
@Resource
|
||||
private TbOrderInfoMapper orderInfoMapper;
|
||||
@@ -62,7 +66,7 @@ public class OrderService {
|
||||
@Resource
|
||||
private TbOrderDetailMapper tbOrderDetailMapper;
|
||||
@Autowired
|
||||
private TbIntegralMapper tbIntegralMapper;
|
||||
private TbReleaseFlowMapper releaseFlowMapper;
|
||||
@Resource
|
||||
private TbParamsMapper paramsMapper;
|
||||
@Resource
|
||||
@@ -73,6 +77,8 @@ public class OrderService {
|
||||
private TbUserCouponsMapper userCouponsMapper;
|
||||
@Resource
|
||||
private TbSystemCouponsMapper systemCouponsMapper;
|
||||
@Autowired
|
||||
private TbYhqParamsMapper yhqParamsMapper;
|
||||
/**
|
||||
* 创建订单
|
||||
*
|
||||
@@ -253,37 +259,62 @@ public class OrderService {
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Result tradeIntegral(String userId, String id) {
|
||||
public Result tradeIntegral(String userId, String id) throws ParseException {
|
||||
updateIntegral(userId, id);
|
||||
return Result.success(CodeEnum.ENCRYPT);
|
||||
}
|
||||
|
||||
private void updateIntegral(String userId, String id) {
|
||||
private void updateIntegral(String userId, String id) throws ParseException {
|
||||
|
||||
boolean lock_coin = redisUtils.lock(RedisCst.INTEGRAL_COIN_KEY + userId, 5000, TimeUnit.MILLISECONDS);
|
||||
if (lock_coin) {
|
||||
TbIntegral integral = tbIntegralMapper.selectByPrimaryKey(Integer.valueOf(id));
|
||||
if (Objects.isNull(integral) || !integral.getStatus().equals("1")) {
|
||||
TbUserCoupons userCoupons = userCouponsMapper.selectByPrimaryKey(Integer.valueOf(id));
|
||||
if (Objects.isNull(userCoupons) || !userCoupons.getStatus().equals("0")) {
|
||||
throw new MsgException("该优惠券已被使用");
|
||||
}
|
||||
TbParams params = paramsMapper.selectByPrimaryKey(1);
|
||||
BigDecimal jfAmount = params.getTradeRatio().multiply(integral.getNum());
|
||||
TbShopUser tbShopUser = shopUserMapper.selectByUserId(userId);
|
||||
tbShopUser.setLevelConsume(tbShopUser.getLevelConsume().add(jfAmount));
|
||||
shopUserMapper.updateByPrimaryKeySelective(tbShopUser);
|
||||
integral.setStatus("TRADE");
|
||||
integral.setUpdateTime(new Date());
|
||||
tbIntegralMapper.updateByPrimaryKeySelective(integral);
|
||||
BigDecimal jfAmount = params.getTradeRatio().multiply(userCoupons.getCouponsAmount());
|
||||
TbUserInfo tbShopUser = userInfoMapper.selectByPrimaryKey(Integer.valueOf(userId));
|
||||
tbShopUser.setTotalScore(tbShopUser.getTotalScore()+jfAmount.intValue());
|
||||
userInfoMapper.updateByPrimaryKeySelective(tbShopUser);
|
||||
userCoupons.setStatus("2");
|
||||
userCoupons.setUpdateTime(new Date());
|
||||
userCouponsMapper.updateByPrimaryKeySelective(userCoupons);
|
||||
TbSystemCoupons systemCoupons = new TbSystemCoupons();
|
||||
systemCoupons.setEndTime(DateUtils.getNewDate(new Date(),3,30));
|
||||
systemCoupons.setCouponsAmount(userCoupons.getCouponsAmount());
|
||||
systemCoupons.setCouponsPrice(userCoupons.getCouponsPrice());
|
||||
systemCoupons.setStatus("0");
|
||||
systemCoupons.setName(userCoupons.getCouponsAmount()+"无门槛优惠券");
|
||||
systemCoupons.setCreateTime(new Date());
|
||||
String typeName = findName(userCoupons.getCouponsAmount());
|
||||
systemCoupons.setTypeName(typeName);
|
||||
systemCouponsMapper.insert(systemCoupons);
|
||||
TbReleaseFlow releaseFlow = new TbReleaseFlow();
|
||||
releaseFlow.setNum(jfAmount);
|
||||
releaseFlow.setCreateTime(new Date());
|
||||
releaseFlow.setFromSource("OWER");
|
||||
releaseFlow.setUserId(userId);
|
||||
releaseFlow.setType("EXCHANGEADD");
|
||||
releaseFlowMapper.insert(releaseFlow);
|
||||
redisUtils.releaseLock(RedisCst.INTEGRAL_COIN_KEY + userId);
|
||||
} else {
|
||||
updateIntegral(userId, id);
|
||||
}
|
||||
}
|
||||
|
||||
// public Result mineYhq(String userId) {
|
||||
// List<TbIntegral> list = tbIntegralMapper.selectAllByUserId(userId);
|
||||
// return Result.success(CodeEnum.ENCRYPT, list);
|
||||
// }
|
||||
private String findName(BigDecimal amount) {
|
||||
List<TbYhqParams> list = yhqParamsMapper.selectAll();
|
||||
String typeName = "";
|
||||
for (TbYhqParams yhqParams:list){
|
||||
if (N.egt(amount,yhqParams.getMinPrice()) && N.gt(yhqParams.getMaxPrice(),amount)){
|
||||
typeName = yhqParams.getName();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return typeName;
|
||||
}
|
||||
|
||||
|
||||
public Result mineCoupons(String userId, String status, Integer page, Integer size) {
|
||||
PageHelper.startPage(page, size);
|
||||
@@ -292,9 +323,9 @@ public class OrderService {
|
||||
return Result.success(CodeEnum.SUCCESS, pageInfo);
|
||||
}
|
||||
|
||||
public Result findCoupons(Integer page, Integer size) {
|
||||
public Result findCoupons(String type, Integer page, Integer size) {
|
||||
PageHelper.startPage(page, size);
|
||||
List<TbSystemCoupons> list = systemCouponsMapper.selectAll();
|
||||
List<TbSystemCoupons> list = systemCouponsMapper.selectAll(type);
|
||||
PageInfo pageInfo = new PageInfo(list);
|
||||
return Result.success(CodeEnum.SUCCESS, pageInfo);
|
||||
}
|
||||
@@ -304,4 +335,28 @@ public class OrderService {
|
||||
List<TbWiningUser> list = tbWiningUserMapper.selectAllByTrade(day);
|
||||
return Result.success(CodeEnum.SUCCESS, list);
|
||||
}
|
||||
|
||||
public Result getYhqPara() {
|
||||
List<TbYhqParams> list = yhqParamsMapper.selectAll();
|
||||
return Result.success(CodeEnum.SUCCESS, list);
|
||||
}
|
||||
|
||||
public Result testPay(Integer orderId) {
|
||||
TbOrderInfo orderInfo = orderInfoMapper.selectByPrimaryKey(orderId);
|
||||
orderInfo.setStatus("closed");
|
||||
orderInfo.setPayType("wx_lite");
|
||||
orderInfo.setPayOrderNo("test");
|
||||
orderInfo.setPayAmount(orderInfo.getOrderAmount());
|
||||
orderInfoMapper.updateByPrimaryKeySelective(orderInfo);
|
||||
JSONObject jsonObject=new JSONObject();
|
||||
jsonObject.put("token",0);
|
||||
jsonObject.put("type","wxcreate");
|
||||
jsonObject.put("orderId",orderId.toString());
|
||||
producer.putOrderCollect(jsonObject.toJSONString());
|
||||
JSONObject coupons = new JSONObject();
|
||||
coupons.put("type","buy");
|
||||
coupons.put("orderId",orderId);
|
||||
producer.printCoupons(coupons.toJSONString());
|
||||
return Result.success(CodeEnum.SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -246,7 +246,11 @@ public class PayService {
|
||||
|
||||
log.info("发送打印数据");
|
||||
producer.printMechine(orderInfo.getId() + "");
|
||||
|
||||
log.info("发送赠送购物券");
|
||||
JSONObject coupons = new JSONObject();
|
||||
coupons.put("type","buy");
|
||||
coupons.put("orderId",orderId);
|
||||
producer.printCoupons(coupons.toJSONString());
|
||||
return Result.success(CodeEnum.SUCCESS,orderId);
|
||||
case "2": //退款成功
|
||||
cartStatus="refund";
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.chaozhanggui.system.cashierservice.dao.*;
|
||||
import com.chaozhanggui.system.cashierservice.entity.*;
|
||||
import com.chaozhanggui.system.cashierservice.entity.vo.IntegralFlowVo;
|
||||
import com.chaozhanggui.system.cashierservice.entity.vo.IntegralVo;
|
||||
import com.chaozhanggui.system.cashierservice.exception.MsgException;
|
||||
import com.chaozhanggui.system.cashierservice.redis.RedisCst;
|
||||
@@ -13,6 +14,7 @@ import com.chaozhanggui.system.cashierservice.redis.RedisUtil;
|
||||
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 org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -106,23 +108,17 @@ public class UserService {
|
||||
tbShopUser.setLevelConsume(tbShopUser.getLevelConsume().add(num));
|
||||
}
|
||||
if (flag) {
|
||||
TbReleaseFlow releaseFlow = new TbReleaseFlow();
|
||||
releaseFlow.setNum(num);
|
||||
releaseFlow.setCreateTime(new Date());
|
||||
releaseFlow.setFromSource("OWER");
|
||||
releaseFlow.setUserId(userId);
|
||||
if (type.equals("sub")) {
|
||||
TbReleaseFlow releaseFlow = new TbReleaseFlow();
|
||||
releaseFlow.setNum(num);
|
||||
releaseFlow.setCreateTime(new Date());
|
||||
releaseFlow.setFromSource("OWER");
|
||||
releaseFlow.setType("BUYSUB");
|
||||
releaseFlow.setUserId(userId);
|
||||
releaseFlowMapper.insert(releaseFlow);
|
||||
}else if (type.equals("sub")){
|
||||
TbReleaseFlow releaseFlow = new TbReleaseFlow();
|
||||
releaseFlow.setNum(num);
|
||||
releaseFlow.setCreateTime(new Date());
|
||||
releaseFlow.setFromSource("OWER");
|
||||
releaseFlow.setType("THREEADD");
|
||||
releaseFlow.setUserId(userId);
|
||||
releaseFlowMapper.insert(releaseFlow);
|
||||
}
|
||||
releaseFlowMapper.insert(releaseFlow);
|
||||
shopUserMapper.updateByPrimaryKeySelective(tbShopUser);
|
||||
}
|
||||
redisUtils.releaseLock(RedisCst.INTEGRAL_COIN_KEY + userId);
|
||||
@@ -131,4 +127,35 @@ public class UserService {
|
||||
return updateIntegral(userId, num, type);
|
||||
}
|
||||
}
|
||||
|
||||
public JSONObject userIntegral(IntegralFlowVo integralFlowVo, String userSign) {
|
||||
JSONObject object = (JSONObject) JSONObject.toJSON(integralFlowVo);
|
||||
object.put("userSign", userSign);
|
||||
JSONObject jsonObject = JSONUtil.sortJSONObject(object, CacheMap.map);
|
||||
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;
|
||||
}
|
||||
TbShopUser shopUser = shopUserMapper.selectByOpenId(integralFlowVo.getOpenId());
|
||||
if (Objects.isNull(shopUser)) {
|
||||
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.selectByUserId(shopUser.getId());
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("status", "success");
|
||||
result.put("msg", "成功");
|
||||
result.put("data",list);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user