|
@@ -219,6 +219,9 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
@Value("${oldStudySys.createExamPath}")
|
|
|
private String CREATE_EXAM_PATH;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IOrderHandleService iOrderHandleService;
|
|
|
+
|
|
|
@Override
|
|
|
public OrderVo queryById(Long orderId) {
|
|
|
Order db = this.baseMapper.selectById(orderId);
|
|
@@ -867,6 +870,220 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> placePlatHandleOrder(OrderAddBo bo) {
|
|
|
+ List<OrderGoodsAddBo> goodsList = bo.getGoodsList();
|
|
|
+ if (goodsList == null || goodsList.size() < 1) {
|
|
|
+ throw new CustomException("商品列表为空", 510);
|
|
|
+ }
|
|
|
+ if (Validator.isEmpty(bo.getUserId())) {
|
|
|
+ throw new CustomException("用户ID缺失", 510);
|
|
|
+ }
|
|
|
+ if (Validator.isEmpty(bo.getInputOrderSn())) {
|
|
|
+ throw new CustomException("录单单号为空", 510);
|
|
|
+ }
|
|
|
+ OrderHandle orderHandle = iOrderHandleService.queryBySn(bo.getHandleOrderSn());
|
|
|
+ if (Validator.isEmpty(orderHandle)) {
|
|
|
+ throw new CustomException("录单单号不存在", 510);
|
|
|
+ }
|
|
|
+ Order add = BeanUtil.toBean(bo, Order.class);
|
|
|
+ validEntityBeforeSave(add);
|
|
|
+ add.setCreateTime(DateUtils.getNowTime());
|
|
|
+ add.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ add.setOrderType(Order.CONSUME_ORDER);
|
|
|
+ add.setOrderFrom(11);
|
|
|
+ add.setHandleOrderSn(bo.getHandleOrderSn());
|
|
|
+ if(orderHandle.getPayType()==1){
|
|
|
+ add.setPayType(1);
|
|
|
+ }else if(orderHandle.getPayType()==2){
|
|
|
+ add.setPayType(7);
|
|
|
+ }
|
|
|
+ //订单运营类型
|
|
|
+ String tenantId = ServletUtils.getRequest().getHeader("TenantId");
|
|
|
+ SysOldOrg oldOrg = iSysOldOrgService.getOne(new LambdaQueryWrapper<SysOldOrg>().eq(SysOldOrg::getTenantId, Long.valueOf(tenantId)).last("limit 1"));
|
|
|
+ if (ObjectUtils.isNotNull(oldOrg)){
|
|
|
+ add.setOperationType(oldOrg.getOperationType());
|
|
|
+ }
|
|
|
+ //生成订单号
|
|
|
+ String out_trade_no = DateUtils.getDateOrderSn();
|
|
|
+
|
|
|
+ BigDecimal totalPrice = new BigDecimal(0);
|
|
|
+ BigDecimal payPrice = new BigDecimal(0);
|
|
|
+ BigDecimal receivedPrice = new BigDecimal(0);
|
|
|
+ //收费的商品列表,不含免费
|
|
|
+ List<OrderGoods> payList = new ArrayList<>();
|
|
|
+ List<OrderGoods> freeList = new ArrayList<>();
|
|
|
+ //生成订单
|
|
|
+ for (OrderGoodsAddBo g : goodsList) {
|
|
|
+ //订单商品
|
|
|
+ Goods goods = iGoodsService.getOne(new LambdaQueryWrapper<Goods>().eq(Goods::getGoodsId, g.getGoodsId()));
|
|
|
+ if (Validator.isEmpty(goods)) {
|
|
|
+ throw new CustomException("商品不存在", 510);
|
|
|
+ }
|
|
|
+ //校验是否有重复商品
|
|
|
+ if (StringUtils.isNotBlank(g.getSevenYear())){
|
|
|
+ Long count = iOrderGoodsService.countOrderGoodsByYear(g.getSevenYear(),g.getGoodsId(),bo.getUserId());
|
|
|
+ if (count > 0){
|
|
|
+ throw new CustomException(goods.getGoodsName() + ",请勿重复购买相同年份的商品");
|
|
|
+ }
|
|
|
+ }
|
|
|
+// if (goods.getGoodsStatus() != 1) {
|
|
|
+// throw new CustomException(goods.getGoodsName()+"商品已下架,请重新选择商品下单", 510);
|
|
|
+// }
|
|
|
+ OrderGoods orderGoods = BeanUtil.toBean(g, OrderGoods.class);
|
|
|
+ orderGoods.setOrderSn(out_trade_no);
|
|
|
+ if (g.getGoodsInputData() != null) {
|
|
|
+ orderGoods.setGoodsInputData(JSON.toJSONString(g.getGoodsInputData()));
|
|
|
+ }
|
|
|
+ if (g.getGoodsReceived().compareTo(g.getGoodsRealPrice()) == 1) {
|
|
|
+ throw new CustomException("已收费大于成交价", 510);
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(goods.getSevenYear())){
|
|
|
+ orderGoods.setSevenYear(goods.getSevenYear());
|
|
|
+ }
|
|
|
+ //成交价
|
|
|
+ orderGoods.setGoodsRealPrice(g.getGoodsRealPrice());
|
|
|
+ orderGoods.setGoodsYear(goods.getYear().toString());
|
|
|
+ orderGoods.setCreateTime(DateUtils.getNowTime());
|
|
|
+ orderGoods.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ orderGoods.setGoodsReceived(g.getGoodsReceived());
|
|
|
+ if (ObjectUtils.isNotNull(g.getSubOrderGoodsId())){
|
|
|
+ //补充考试次数订单商品ID
|
|
|
+ orderGoods.setSubOrderGoodsId(g.getSubOrderGoodsId());
|
|
|
+ orderGoods.setOpenQuestionSign(bo.getOpenQuestionSign());
|
|
|
+ }
|
|
|
+ //订单标准价格不计算优惠
|
|
|
+ totalPrice = totalPrice.add(goods.getStandPrice());
|
|
|
+ //实际应收价格
|
|
|
+ payPrice = payPrice.add(g.getGoodsRealPrice());
|
|
|
+ //已收价格
|
|
|
+ receivedPrice = receivedPrice.add(g.getGoodsReceived());
|
|
|
+ boolean orderGoodsRs = iOrderGoodsService.save(orderGoods);
|
|
|
+ boolean canRepeatBuy = false;
|
|
|
+ validUserBeforeBuy(goods, bo.getUserId());
|
|
|
+ //判断是否有购买过
|
|
|
+ Long oldOrderGoodsId = getHaveBuyGoods(g.getGoodsId(), bo.getUserId());
|
|
|
+ //视频商品安排班级
|
|
|
+ if (goods.getGoodsType() == 1) {
|
|
|
+ if (Validator.isNotEmpty(goods.getStudyCount())) {
|
|
|
+ orderGoods.setStudyCount(goods.getStudyCount() - 1); //默认消耗一次学习机会
|
|
|
+ } else {
|
|
|
+ orderGoods.setStudyCount(0L);//没配置则为0
|
|
|
+ }
|
|
|
+
|
|
|
+ Long gradeId = null;
|
|
|
+ //判断是否购买历史班级都过期
|
|
|
+ canRepeatBuy = this.canBuyRepeatGoods(g.getGoodsId(), bo.getUserId(),g.getSevenYear());
|
|
|
+ if (g.getGoodsInputData() != null) {
|
|
|
+ gradeId = g.getGoodsInputData().getGradeId();
|
|
|
+ if (Validator.isNotEmpty(oldOrderGoodsId)) {
|
|
|
+ //有指定选班模板且视频商品班级已过期,记录复购状态
|
|
|
+ orderGoods.setRebuyOrderGoodsId(oldOrderGoodsId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String requestId = IdUtil.simpleUUID();
|
|
|
+ RedisLockEntity redisLockEntity = new RedisLockEntity();
|
|
|
+ redisLockEntity.setLockKey(RedisLockEntity.KEY_LOCK_GRADE);
|
|
|
+ redisLockEntity.setRequestId(requestId);
|
|
|
+ boolean isArrange = false;
|
|
|
+ if (redisCache.lock(redisLockEntity)) {
|
|
|
+ isArrange = arrangeGrade(goods.getGoodsName(), goods.getGoodsId(), orderGoods.getOrderGoodsId(), gradeId, add.getUserId(), out_trade_no, goods.getBusinessId());
|
|
|
+ redisCache.unlockLua(redisLockEntity);
|
|
|
+ }
|
|
|
+ if (!isArrange) {
|
|
|
+ throw new CustomException("分班错误", 510);
|
|
|
+ }
|
|
|
+ iOrderGoodsService.updateById(orderGoods);
|
|
|
+ newFreeBankGoods(goods.getGoodsId(), orderGoods.getOrderGoodsId());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!canRepeatBuy && goods.getGoodsType() != 3 && goods.getGoodsType() != 4) {
|
|
|
+ this.checkBuyGoods(g.getGoodsId(), bo.getUserId(), goods.getGoodsType());
|
|
|
+ }
|
|
|
+ if (goods.getGoodsType() == 6) {
|
|
|
+ //直播商品
|
|
|
+ if (Validator.isNotEmpty(oldOrderGoodsId) && oldOrderGoodsId.longValue() > 0) {
|
|
|
+ throw new CustomException("直播商品不允许复购");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //商品0元或已收费加入收费商品列表
|
|
|
+ if (g.getGoodsRealPrice().compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+ //免费的
|
|
|
+ freeList.add(orderGoods);
|
|
|
+ } else if (g.getGoodsRealPrice().compareTo(BigDecimal.ZERO) > 0 && g.getGoodsReceived().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ //有收费的
|
|
|
+ payList.add(orderGoods);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ add.setOrderSn(out_trade_no);
|
|
|
+ if (Validator.isNotEmpty(bo.getOrderFrom()) && bo.getOrderFrom() == 6) {
|
|
|
+ add.setOrderFrom(bo.getOrderFrom());
|
|
|
+ } else {
|
|
|
+ add.setOrderFrom(Order.FROM_INPUT);
|
|
|
+ }
|
|
|
+ add.setPayPrice(payPrice);//需要支付价格
|
|
|
+ add.setOrderPrice(totalPrice);//标准价格
|
|
|
+ orderHandle.setPayPrice(orderHandle.getPayPrice().add(payPrice));
|
|
|
+ orderHandle.setOrderPrice(orderHandle.getOrderPrice().add(totalPrice));
|
|
|
+ orderHandle.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ iOrderHandleService.updateById(orderHandle);
|
|
|
+ //有已收费的商品,修改订单支付状态
|
|
|
+ if ((freeList.size() + payList.size()) > 0) {
|
|
|
+ add.setOrderStatus(Order.ORDER_STATUS_PAY);
|
|
|
+ if (payPrice.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+ //总订单0元
|
|
|
+ add.setPayStatus(Order.PAY_FREE);
|
|
|
+ } else if (payPrice.compareTo(receivedPrice) == 0) {
|
|
|
+ //完全收费
|
|
|
+ add.setPayStatus(Order.PAY_FULL);
|
|
|
+ } else {
|
|
|
+ //部分收费
|
|
|
+ add.setPayStatus(Order.PAY_PART);
|
|
|
+ }
|
|
|
+ add.setStatus(1);
|
|
|
+ }
|
|
|
+ if (bo.getOrderFrom() != 6){
|
|
|
+ orderCostHandle(add,1);
|
|
|
+ }
|
|
|
+ this.save(add);
|
|
|
+ //处理收费商品,生成计费单
|
|
|
+ Map<String, Object> billRs = null;
|
|
|
+ if (payList.size() > 0) {
|
|
|
+ OrderBillSheetAddBo billSheetAddBo = new OrderBillSheetAddBo();
|
|
|
+ billSheetAddBo.setInputOrderSn(bo.getInputOrderSn());
|
|
|
+ List<OrderBillGoodsAddBo> billGoodsList = new ArrayList<>();
|
|
|
+ for (OrderGoods orderGoods : payList) {
|
|
|
+ OrderBillGoodsAddBo billGoodsAddBo = new OrderBillGoodsAddBo();
|
|
|
+ billGoodsAddBo.setOrderSn(add.getOrderSn());
|
|
|
+ billGoodsAddBo.setGoodsId(orderGoods.getGoodsId());
|
|
|
+ billGoodsAddBo.setOrderGoodsId(orderGoods.getOrderGoodsId());
|
|
|
+ billGoodsAddBo.setAmount(orderGoods.getGoodsReceived());
|
|
|
+ billGoodsList.add(billGoodsAddBo);
|
|
|
+// //商品是否有活动模考
|
|
|
+// iUserMockSubscribeService.addActivityMock(orderGoods.getGoodsId(),add.getUserId());
|
|
|
+ }
|
|
|
+ billSheetAddBo.setGoodsList(billGoodsList);
|
|
|
+ billRs = iOrderBillSheetService.placeBillInputOrder(billSheetAddBo);
|
|
|
+ }
|
|
|
+
|
|
|
+ //处理免费商品
|
|
|
+ for (OrderGoods orderGoods : freeList) {
|
|
|
+ dealFreeGoods(orderGoods, add);
|
|
|
+ }
|
|
|
+ instTimeSettleOrder(add,DateUtils.getNowTime());
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ result.put("orderId", add.getOrderId());
|
|
|
+ result.put("orderSn", out_trade_no);
|
|
|
+ result.put("sheetId", null);
|
|
|
+ result.put("sheetSn", null);
|
|
|
+ if (Validator.isNotEmpty(billRs)) {
|
|
|
+ result.put("sheetId", billRs.get("sheetId"));
|
|
|
+ result.put("sheetSn", billRs.get("sheetSn"));
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
private void instTimeSettleOrder(Order order, Long checkTime) {
|
|
|
String tenantId = ServletUtils.getRequest().getHeader("TenantId");
|
|
|
SysOldOrg sysOldOrg = sysOldOrgService.getOne(new LambdaQueryWrapper<SysOldOrg>()
|