环境2
This commit is contained in:
@@ -13,7 +13,12 @@ import com.chaozhanggui.system.cashierservice.redis.RedisUtil;
|
|||||||
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
|
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
|
||||||
import com.chaozhanggui.system.cashierservice.sign.Result;
|
import com.chaozhanggui.system.cashierservice.sign.Result;
|
||||||
import com.chaozhanggui.system.cashierservice.socket.AppWebSocketServer;
|
import com.chaozhanggui.system.cashierservice.socket.AppWebSocketServer;
|
||||||
|
import com.chaozhanggui.system.cashierservice.util.DateUtils;
|
||||||
|
import com.chaozhanggui.system.cashierservice.util.RedisUtils;
|
||||||
import com.chaozhanggui.system.cashierservice.util.SnowFlakeUtil;
|
import com.chaozhanggui.system.cashierservice.util.SnowFlakeUtil;
|
||||||
|
import com.github.pagehelper.PageHelper;
|
||||||
|
import com.github.pagehelper.PageInfo;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
@@ -24,7 +29,10 @@ import java.io.IOException;
|
|||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author 12847
|
* @author 12847
|
||||||
@@ -33,7 +41,7 @@ import java.util.List;
|
|||||||
public class OrderService {
|
public class OrderService {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private TbCashierCartMapper cashierCartMapper;
|
private TbShopUserMapper shopUserMapper;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private TbOrderInfoMapper orderInfoMapper;
|
private TbOrderInfoMapper orderInfoMapper;
|
||||||
@@ -48,13 +56,26 @@ public class OrderService {
|
|||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private TbUserInfoMapper userInfoMapper;
|
private TbUserInfoMapper userInfoMapper;
|
||||||
|
@Autowired
|
||||||
|
private TbWiningUserMapper tbWiningUserMapper;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private TbOrderDetailMapper tbOrderDetailMapper;
|
private TbOrderDetailMapper tbOrderDetailMapper;
|
||||||
|
@Autowired
|
||||||
|
private TbIntegralMapper tbIntegralMapper;
|
||||||
|
@Resource
|
||||||
|
private TbParamsMapper paramsMapper;
|
||||||
@Resource
|
@Resource
|
||||||
private RedisUtil redisUtil;
|
private RedisUtil redisUtil;
|
||||||
|
@Resource
|
||||||
|
private RedisUtils redisUtils;
|
||||||
|
@Resource
|
||||||
|
private TbUserCouponsMapper userCouponsMapper;
|
||||||
|
@Resource
|
||||||
|
private TbSystemCouponsMapper systemCouponsMapper;
|
||||||
/**
|
/**
|
||||||
* 创建订单
|
* 创建订单
|
||||||
|
*
|
||||||
* @param tableId
|
* @param tableId
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@@ -149,7 +170,6 @@ public class OrderService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TbShopInfo tbShopInfo = tbShopInfoMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getShopId()));
|
TbShopInfo tbShopInfo = tbShopInfoMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getShopId()));
|
||||||
if (tbShopInfo == null) {
|
if (tbShopInfo == null) {
|
||||||
return Result.fail("未找到订单");
|
return Result.fail("未找到订单");
|
||||||
@@ -230,4 +250,57 @@ public class OrderService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public Result tradeIntegral(String userId, String id) {
|
||||||
|
updateIntegral(userId, id);
|
||||||
|
return Result.success(CodeEnum.ENCRYPT);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateIntegral(String userId, String id) {
|
||||||
|
|
||||||
|
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")) {
|
||||||
|
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);
|
||||||
|
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);
|
||||||
|
// }
|
||||||
|
|
||||||
|
public Result mineCoupons(String userId, String status, Integer page, Integer size) {
|
||||||
|
PageHelper.startPage(page, size);
|
||||||
|
List<TbUserCoupons> list = userCouponsMapper.selectByUserId(userId,status);
|
||||||
|
PageInfo pageInfo = new PageInfo(list);
|
||||||
|
return Result.success(CodeEnum.SUCCESS, pageInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Result findCoupons(Integer page, Integer size) {
|
||||||
|
PageHelper.startPage(page, size);
|
||||||
|
List<TbSystemCoupons> list = systemCouponsMapper.selectAll();
|
||||||
|
PageInfo pageInfo = new PageInfo(list);
|
||||||
|
return Result.success(CodeEnum.SUCCESS, pageInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Result findWiningUser() {
|
||||||
|
String day = DateUtils.getDay();
|
||||||
|
List<TbWiningUser> list = tbWiningUserMapper.selectAllByTrade(day);
|
||||||
|
return Result.success(CodeEnum.SUCCESS, list);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user