完成我要开团单独购买付款接口

main
whb
parent b9d00eca19
commit f7a634db08

@ -15,6 +15,8 @@ public class Constant {
* Basic
*/
public static final String BASIC = "Basic";
public static final String DANDUGOUMAI = "单独购买";
public static final String PINDUANGOUMAI = "我要开团";

@ -1,6 +1,8 @@
package com.sztzjy.trade.controller.stu;
import com.sztzjy.trade.annotation.AnonymousAccess;
import com.sztzjy.trade.config.Constant;
import com.sztzjy.trade.entity.dto.StuPurchaseGoodsDTO;
import com.sztzjy.trade.service.StuGoodsTradingCenterService;
import com.sztzjy.trade.service.StuGoodsTradingOrderService;
import com.sztzjy.trade.util.ResultEntity;
@ -11,6 +13,7 @@ import com.sztzjy.trade.service.StuGoodsTradingCenterService;
import com.sztzjy.trade.util.ResultEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiOperation;
@ -207,14 +210,37 @@ public class StuGoodsTradingCenterController {
// @ApiOperation("商品详情页面:单独购买/拼单购买")
// @AnonymousAccess
// @GetMapping("/buyGoods")
// public ResultEntity getbuyGoods(String userId,Integer goodsId,) {
//
// return stuGoodsTradingOrderService.getSeeingYouOnAndOn(userId,goodsId,index,size,goodsType);
//
// }
@ApiOperation("商品详情页面:单独购买")
@AnonymousAccess
@PostMapping("/purchaseGoods")
public ResultEntity getpurchaseGoods(StuPurchaseGoodsDTO stuPurchaseGoodsDTO) {
if (Constant.DANDUGOUMAI.equals(stuPurchaseGoodsDTO.getType()))
{
StuSettlementDTO stuSettlementDTO = new StuSettlementDTO();
BeanUtils.copyProperties(stuPurchaseGoodsDTO,stuSettlementDTO);
tradingCenterService.settlement(stuSettlementDTO);
}else
{
//拼团购买
tradingCenterService.groupPurchase(stuPurchaseGoodsDTO);
}
return new ResultEntity(HttpStatus.OK,"下单成功");
}

@ -18,7 +18,7 @@ public class StuSplicingOrdersInfo {
@ApiModelProperty(notes = "创建时间")
private Date createTime;
@ApiModelProperty(notes = "发起者用户ID(多个用户ID用逗号隔开)")
@ApiModelProperty(notes = "发起者用户ID")
private String userId;
@ApiModelProperty(notes = "拼单结束时间")
@ -27,7 +27,7 @@ public class StuSplicingOrdersInfo {
@ApiModelProperty(notes = "商品类型")
private String goodsType;
@ApiModelProperty(notes = "参与拼单")
@ApiModelProperty(notes = "参与拼单(多个用户用逗号隔开)")
private String participateInGroupBuying;
@ApiModelProperty(notes = "是否拼单成功默认未成功为0")
@ -36,6 +36,12 @@ public class StuSplicingOrdersInfo {
@ApiModelProperty(notes = "拼单差人数")
private Integer missManyPeople;
@ApiModelProperty(notes = "发起者拼单数量")
private Integer number;
@ApiModelProperty(notes = "参与者拼单数量(多个用都逗号隔开)")
private String participantNumber;
public Integer getId() {
return id;
}
@ -107,4 +113,20 @@ public class StuSplicingOrdersInfo {
public void setMissManyPeople(Integer missManyPeople) {
this.missManyPeople = missManyPeople;
}
public Integer getNumber() {
return number;
}
public void setNumber(Integer number) {
this.number = number;
}
public String getParticipantNumber() {
return participantNumber;
}
public void setParticipantNumber(String participantNumber) {
this.participantNumber = participantNumber == null ? null : participantNumber.trim();
}
}

@ -486,72 +486,72 @@ public class StuSplicingOrdersInfoExample {
}
public Criteria andParticipateInGroupBuyingIsNull() {
addCriterion("\"participate_in_group buying\" is null");
addCriterion("participate_in_group_buying is null");
return (Criteria) this;
}
public Criteria andParticipateInGroupBuyingIsNotNull() {
addCriterion("\"participate_in_group buying\" is not null");
addCriterion("participate_in_group_buying is not null");
return (Criteria) this;
}
public Criteria andParticipateInGroupBuyingEqualTo(String value) {
addCriterion("\"participate_in_group buying\" =", value, "participateInGroupBuying");
addCriterion("participate_in_group_buying =", value, "participateInGroupBuying");
return (Criteria) this;
}
public Criteria andParticipateInGroupBuyingNotEqualTo(String value) {
addCriterion("\"participate_in_group buying\" <>", value, "participateInGroupBuying");
addCriterion("participate_in_group_buying <>", value, "participateInGroupBuying");
return (Criteria) this;
}
public Criteria andParticipateInGroupBuyingGreaterThan(String value) {
addCriterion("\"participate_in_group buying\" >", value, "participateInGroupBuying");
addCriterion("participate_in_group_buying >", value, "participateInGroupBuying");
return (Criteria) this;
}
public Criteria andParticipateInGroupBuyingGreaterThanOrEqualTo(String value) {
addCriterion("\"participate_in_group buying\" >=", value, "participateInGroupBuying");
addCriterion("participate_in_group_buying >=", value, "participateInGroupBuying");
return (Criteria) this;
}
public Criteria andParticipateInGroupBuyingLessThan(String value) {
addCriterion("\"participate_in_group buying\" <", value, "participateInGroupBuying");
addCriterion("participate_in_group_buying <", value, "participateInGroupBuying");
return (Criteria) this;
}
public Criteria andParticipateInGroupBuyingLessThanOrEqualTo(String value) {
addCriterion("\"participate_in_group buying\" <=", value, "participateInGroupBuying");
addCriterion("participate_in_group_buying <=", value, "participateInGroupBuying");
return (Criteria) this;
}
public Criteria andParticipateInGroupBuyingLike(String value) {
addCriterion("\"participate_in_group buying\" like", value, "participateInGroupBuying");
addCriterion("participate_in_group_buying like", value, "participateInGroupBuying");
return (Criteria) this;
}
public Criteria andParticipateInGroupBuyingNotLike(String value) {
addCriterion("\"participate_in_group buying\" not like", value, "participateInGroupBuying");
addCriterion("participate_in_group_buying not like", value, "participateInGroupBuying");
return (Criteria) this;
}
public Criteria andParticipateInGroupBuyingIn(List<String> values) {
addCriterion("\"participate_in_group buying\" in", values, "participateInGroupBuying");
addCriterion("participate_in_group_buying in", values, "participateInGroupBuying");
return (Criteria) this;
}
public Criteria andParticipateInGroupBuyingNotIn(List<String> values) {
addCriterion("\"participate_in_group buying\" not in", values, "participateInGroupBuying");
addCriterion("participate_in_group_buying not in", values, "participateInGroupBuying");
return (Criteria) this;
}
public Criteria andParticipateInGroupBuyingBetween(String value1, String value2) {
addCriterion("\"participate_in_group buying\" between", value1, value2, "participateInGroupBuying");
addCriterion("participate_in_group_buying between", value1, value2, "participateInGroupBuying");
return (Criteria) this;
}
public Criteria andParticipateInGroupBuyingNotBetween(String value1, String value2) {
addCriterion("\"participate_in_group buying\" not between", value1, value2, "participateInGroupBuying");
addCriterion("participate_in_group_buying not between", value1, value2, "participateInGroupBuying");
return (Criteria) this;
}
@ -674,6 +674,136 @@ public class StuSplicingOrdersInfoExample {
addCriterion("miss_many_people not between", value1, value2, "missManyPeople");
return (Criteria) this;
}
public Criteria andNumberIsNull() {
addCriterion("number is null");
return (Criteria) this;
}
public Criteria andNumberIsNotNull() {
addCriterion("number is not null");
return (Criteria) this;
}
public Criteria andNumberEqualTo(Integer value) {
addCriterion("number =", value, "number");
return (Criteria) this;
}
public Criteria andNumberNotEqualTo(Integer value) {
addCriterion("number <>", value, "number");
return (Criteria) this;
}
public Criteria andNumberGreaterThan(Integer value) {
addCriterion("number >", value, "number");
return (Criteria) this;
}
public Criteria andNumberGreaterThanOrEqualTo(Integer value) {
addCriterion("number >=", value, "number");
return (Criteria) this;
}
public Criteria andNumberLessThan(Integer value) {
addCriterion("number <", value, "number");
return (Criteria) this;
}
public Criteria andNumberLessThanOrEqualTo(Integer value) {
addCriterion("number <=", value, "number");
return (Criteria) this;
}
public Criteria andNumberIn(List<Integer> values) {
addCriterion("number in", values, "number");
return (Criteria) this;
}
public Criteria andNumberNotIn(List<Integer> values) {
addCriterion("number not in", values, "number");
return (Criteria) this;
}
public Criteria andNumberBetween(Integer value1, Integer value2) {
addCriterion("number between", value1, value2, "number");
return (Criteria) this;
}
public Criteria andNumberNotBetween(Integer value1, Integer value2) {
addCriterion("number not between", value1, value2, "number");
return (Criteria) this;
}
public Criteria andParticipantNumberIsNull() {
addCriterion("participant_number is null");
return (Criteria) this;
}
public Criteria andParticipantNumberIsNotNull() {
addCriterion("participant_number is not null");
return (Criteria) this;
}
public Criteria andParticipantNumberEqualTo(String value) {
addCriterion("participant_number =", value, "participantNumber");
return (Criteria) this;
}
public Criteria andParticipantNumberNotEqualTo(String value) {
addCriterion("participant_number <>", value, "participantNumber");
return (Criteria) this;
}
public Criteria andParticipantNumberGreaterThan(String value) {
addCriterion("participant_number >", value, "participantNumber");
return (Criteria) this;
}
public Criteria andParticipantNumberGreaterThanOrEqualTo(String value) {
addCriterion("participant_number >=", value, "participantNumber");
return (Criteria) this;
}
public Criteria andParticipantNumberLessThan(String value) {
addCriterion("participant_number <", value, "participantNumber");
return (Criteria) this;
}
public Criteria andParticipantNumberLessThanOrEqualTo(String value) {
addCriterion("participant_number <=", value, "participantNumber");
return (Criteria) this;
}
public Criteria andParticipantNumberLike(String value) {
addCriterion("participant_number like", value, "participantNumber");
return (Criteria) this;
}
public Criteria andParticipantNumberNotLike(String value) {
addCriterion("participant_number not like", value, "participantNumber");
return (Criteria) this;
}
public Criteria andParticipantNumberIn(List<String> values) {
addCriterion("participant_number in", values, "participantNumber");
return (Criteria) this;
}
public Criteria andParticipantNumberNotIn(List<String> values) {
addCriterion("participant_number not in", values, "participantNumber");
return (Criteria) this;
}
public Criteria andParticipantNumberBetween(String value1, String value2) {
addCriterion("participant_number between", value1, value2, "participantNumber");
return (Criteria) this;
}
public Criteria andParticipantNumberNotBetween(String value1, String value2) {
addCriterion("participant_number not between", value1, value2, "participantNumber");
return (Criteria) this;
}
}
public static class Criteria extends GeneratedCriteria {

@ -114,4 +114,9 @@ public class StuGoodsInfoDTO {
@ApiModelProperty(notes = "商品评价")
private double storeScore;
@ApiModelProperty(notes = "拼团价格")
private BigDecimal groupPrice;
}

@ -71,5 +71,9 @@ public class StuGoodsSalesManageDTO {
private Double price;
@ApiModelProperty(notes = "拼团价格")
private Double groupPrice;
}

@ -0,0 +1,26 @@
package com.sztzjy.trade.entity.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* @author 17803
* @date 2024-11-05 09:48
*/
@Data
public class StuGroupOrderInfoDTO {
private String userId;
@ApiModelProperty("购买数量")
private Integer amount;
@ApiModelProperty("商品类型")
private String goodsType;
@ApiModelProperty("拼单时间")
private Date createTime;
}

@ -0,0 +1,43 @@
package com.sztzjy.trade.entity.dto;
import com.sztzjy.trade.entity.StuShoppingCartInfo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
import java.util.List;
/**
* @author 17803
* @date 2024-11-04 09:01
*/
@Data
public class StuPurchaseGoodsDTO {
@ApiModelProperty(notes = "商品ID")
private Integer goodsId;
@ApiModelProperty(notes = "商品类型")
private String goodsType;
private BigDecimal amount;
private String userId;
@ApiModelProperty(notes = "单独购买/我要开团/拼单")
private String type;
@ApiModelProperty(notes = "店铺名称")
private String shopName;
@ApiModelProperty(notes = "商品链接")
private String goodsUrl;
@ApiModelProperty(notes = "商品名称")
private String goodsName;
@ApiModelProperty(notes = "拼团的ID(拼单时候传参)")
private Integer splicingId;
}

@ -0,0 +1,38 @@
package com.sztzjy.trade.entity.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
/**
* @author 17803
* @date 2024-11-05 10:05
*/
@Data
public class StuPurcreateOrderDTO {
private BigDecimal amount;
private String userId;
@ApiModelProperty(notes = "商品ID")
private Integer goodsId;
@ApiModelProperty(notes = "商品名称")
private String goodsName;
@ApiModelProperty(notes = "商品类型")
private String goodsType;
@ApiModelProperty(notes = "店铺名称")
private String shopName;
@ApiModelProperty(notes = "商品链接")
private String goodsUrl;
}

@ -3,6 +3,7 @@ package com.sztzjy.trade.service;
import com.github.pagehelper.PageInfo;
import com.sztzjy.trade.entity.StuGoodsOrderInfo;
import com.sztzjy.trade.entity.StuShoppingCartInfo;
import com.sztzjy.trade.entity.dto.StuPurchaseGoodsDTO;
import com.sztzjy.trade.entity.dto.StuSettlementDTO;
import org.springframework.security.core.parameters.P;
@ -47,4 +48,7 @@ public interface StuGoodsTradingCenterService {
//商品排序
ResultEntity goodsOrder(String keyword, Integer index, Integer size,Integer type,String search);
//拼团购买
void groupPurchase(StuPurchaseGoodsDTO stuPurchaseGoodsDTO);
}

@ -12,4 +12,5 @@ public interface StuGoodsTradingOrderService {
//商品详情页面:看了又看功能
ResultEntity getSeeingYouOnAndOn(String userId, Integer goodsId,Integer index,Integer size,String goodsType);
}
}

@ -2,14 +2,15 @@ package com.sztzjy.trade.service.impl;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageHelper;
import com.sztzjy.trade.config.Constant;
import com.sztzjy.trade.entity.*;
import com.sztzjy.trade.entity.dto.StuGoodsSalesManageDTO;
import com.sztzjy.trade.entity.dto.*;
import com.sztzjy.trade.mapper.*;
import com.github.pagehelper.PageInfo;
import com.sztzjy.trade.config.exception.handler.ServiceException;
import com.sztzjy.trade.entity.*;
import com.sztzjy.trade.entity.dto.StuSettlementDTO;
import com.sztzjy.trade.mapper.*;
import com.sztzjy.trade.service.StuGoodsTradingCenterService;
import com.sztzjy.trade.util.BigDecimalUtils;
@ -22,6 +23,7 @@ import com.sztzjy.trade.util.PageUtil;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.util.*;
import javax.annotation.Resource;
import java.math.BigDecimal;
@ -68,6 +70,8 @@ public class StuGoodsTradingCenterServiceImpl implements StuGoodsTradingCenterSe
@Resource
StuGoodsOrderInfoMapper orderInfoMapper;
@Autowired
private StuSplicingOrdersInfoMapper stuSplicingOrdersInfoMapper;
//小广告位招租
@Override
public ResultEntity getSmallAdPlacement() {
@ -447,6 +451,9 @@ public class StuGoodsTradingCenterServiceImpl implements StuGoodsTradingCenterSe
PageInfo<StuGoodsSalesManageDTO> goodsSalesManageDTOPageInfo = new PageInfo<>(stuGoodsSalesManageDTOArrayList);
return new ResultEntity(HttpStatus.OK, goodsSalesManageDTOPageInfo);
@ -487,5 +494,187 @@ public class StuGoodsTradingCenterServiceImpl implements StuGoodsTradingCenterSe
}
//拼团购买
@Override
public void groupPurchase(StuPurchaseGoodsDTO stuPurchaseGoodsDTO) {
//判断是否拼团还是单独开团
if (Constant.PINDUANGOUMAI.equals(stuPurchaseGoodsDTO.getType()))
{ //开团
StuSplicingOrdersInfo splicingOrdersInfo = new StuSplicingOrdersInfo();
int id = UUID.randomUUID().hashCode();
id = id > 0 ? id : - id;
splicingOrdersInfo.setId(id);
splicingOrdersInfo.setGoodsId(stuPurchaseGoodsDTO.getGoodsId());
splicingOrdersInfo.setUserId(stuPurchaseGoodsDTO.getUserId());
splicingOrdersInfo.setCreateTime(new Date());
splicingOrdersInfo.setNumber(Convert.toInt(stuPurchaseGoodsDTO.getAmount()));
splicingOrdersInfo.setStopTime(Convert.toDate(LocalDate.now().plusDays(1)));
splicingOrdersInfo.setGoodsType(stuPurchaseGoodsDTO.getGoodsType());
StuGoodsInfo stuGoodsInfo = stuGoodsInfoMapper.selectByPrimaryKey(stuPurchaseGoodsDTO.getGoodsId());
//分享人数
splicingOrdersInfo.setMissManyPeople(stuGoodsInfo.getNumberOfShares());
stuSplicingOrdersInfoMapper.insertSelective(splicingOrdersInfo);
}else {
//拼团 拼团人数是否足够 满足条件 下单
StuSplicingOrdersInfo splicingOrdersInfo = stuSplicingOrdersInfoMapper.selectByPrimaryKey(stuPurchaseGoodsDTO.getSplicingId());
if (splicingOrdersInfo.getStopTime().before(new Date()) || splicingOrdersInfo.getOrderSuccess() == 1)
{
//拼单超时 || 拼单成功
return;
}
if (splicingOrdersInfo.getMissManyPeople()!=0 && splicingOrdersInfo.getMissManyPeople()-1==0) {
//满足拼单条件
List<StuGroupOrderInfoDTO> stuGroupOrderInfoDTOList = JSON.parseArray(splicingOrdersInfo.getParticipateInGroupBuying(), StuGroupOrderInfoDTO.class);
StuGroupOrderInfoDTO stuGroupOrderInfoDTO = new StuGroupOrderInfoDTO();
stuGroupOrderInfoDTO.setUserId(stuPurchaseGoodsDTO.getUserId());
stuGroupOrderInfoDTO.setGoodsType(stuPurchaseGoodsDTO.getGoodsType());
stuGroupOrderInfoDTO.setAmount(Convert.toInt(stuPurchaseGoodsDTO.getAmount()));
stuGroupOrderInfoDTO.setCreateTime(new Date());
stuGroupOrderInfoDTOList.add(stuGroupOrderInfoDTO);
String json = JSON.toJSONString(stuGroupOrderInfoDTOList);
splicingOrdersInfo.setParticipateInGroupBuying(json);
splicingOrdersInfo.setOrderSuccess(1);
splicingOrdersInfo.setMissManyPeople(0);
//拼单成功
stuSplicingOrdersInfoMapper.updateByPrimaryKeySelective(splicingOrdersInfo);
StuGroupOrderInfoDTO infoDTO = new StuGroupOrderInfoDTO();
infoDTO.setAmount(splicingOrdersInfo.getNumber());
infoDTO.setGoodsType(splicingOrdersInfo.getGoodsType());
infoDTO.setUserId(splicingOrdersInfo.getUserId());
stuGroupOrderInfoDTOList.add(infoDTO);
//todo 付款扣钱 发起者和参与拼单的用户扣钱
for (StuGroupOrderInfoDTO groupOrderInfoDTO : stuGroupOrderInfoDTOList) {
StuPurcreateOrderDTO stuPurcreateOrderDTO = new StuPurcreateOrderDTO();
stuPurcreateOrderDTO.setUserId(groupOrderInfoDTO.getUserId());
stuPurcreateOrderDTO.setAmount(BigDecimal.valueOf(groupOrderInfoDTO.getAmount()));
stuPurcreateOrderDTO.setGoodsId(stuPurchaseGoodsDTO.getGoodsId());
stuPurcreateOrderDTO.setGoodsName(stuPurchaseGoodsDTO.getGoodsName());
stuPurcreateOrderDTO.setGoodsType(groupOrderInfoDTO.getGoodsType());
stuPurcreateOrderDTO.setShopName(stuPurchaseGoodsDTO.getShopName());
stuPurcreateOrderDTO.setGoodsUrl(stuPurchaseGoodsDTO.getGoodsUrl());
createOrder(stuPurcreateOrderDTO);
}
}else {
//添加到拼单数据中
List<StuGroupOrderInfoDTO> stuGroupOrderInfoDTOList = JSON.parseArray(splicingOrdersInfo.getParticipateInGroupBuying(), StuGroupOrderInfoDTO.class);
StuGroupOrderInfoDTO stuGroupOrderInfoDTO = new StuGroupOrderInfoDTO();
stuGroupOrderInfoDTO.setUserId(stuPurchaseGoodsDTO.getUserId());
stuGroupOrderInfoDTO.setGoodsType(stuPurchaseGoodsDTO.getGoodsType());
stuGroupOrderInfoDTO.setAmount(Convert.toInt(stuPurchaseGoodsDTO.getAmount()));
stuGroupOrderInfoDTO.setCreateTime(new Date());
stuGroupOrderInfoDTOList.add(stuGroupOrderInfoDTO);
splicingOrdersInfo.setParticipateInGroupBuying(JSON.toJSONString(stuGroupOrderInfoDTOList));
splicingOrdersInfo.setMissManyPeople(splicingOrdersInfo.getMissManyPeople()+1);
stuSplicingOrdersInfoMapper.updateByPrimaryKeySelective(splicingOrdersInfo);
}
}
}
public void createOrder(StuPurcreateOrderDTO stuPurcreateOrderDTO) {
// TODO: 2024/10/28 1、查询账户余额,检验余额是否足够、
StuTradeAccountInfoExample accountInfoExample = new StuTradeAccountInfoExample();
accountInfoExample.createCriteria().andUserIdEqualTo(stuPurcreateOrderDTO.getUserId());
List<StuTradeAccountInfo> stuTradeAccountInfos = accountInfoMapper.selectByExample(accountInfoExample);
if (stuTradeAccountInfos.isEmpty()) { //设置默认值
StuTradeAccountInfo stuTradeAccountInfo = new StuTradeAccountInfo(stuPurcreateOrderDTO.getUserId());
accountInfoMapper.insert(stuTradeAccountInfo);
stuTradeAccountInfos.add(stuTradeAccountInfo);
}
//取到余额,去掉末尾的0比较精度
BigDecimal accountBalance = stuTradeAccountInfos.get(0).getAccountBalance().stripTrailingZeros();
BigDecimal bigDecimal = stuPurcreateOrderDTO.getAmount().stripTrailingZeros();
if (accountBalance.compareTo(bigDecimal) < 0) {
throw new ServiceException(HttpStatus.ACCEPTED, "余额不足");
}
// TODO: 2024/10/28 2、检验商品上架信息和库存信息
//根据商品ID查询商品是否已下架
StuGoodsInfo stuGoodsInfo = stuGoodsInfoMapper.selectByPrimaryKey(stuPurcreateOrderDTO.getGoodsId());
if (stuGoodsInfo.getOnlineState() == 0) {
throw new ServiceException(HttpStatus.ACCEPTED, stuGoodsInfo.getGoodsName() + "商品已下架,请重新选择结算商品");
}
//根据商品ID查询商品库存是否足够
StuGoodsSalesManageExample salesManageExample = new StuGoodsSalesManageExample();
salesManageExample.createCriteria().andGoodsIdEqualTo(stuPurcreateOrderDTO.getGoodsId());
List<StuGoodsSalesManage> stuGoodsSalesManages = goodsSalesManageMapper.selectByExample(salesManageExample);
if (stuGoodsSalesManages.get(0).getOnlineTotal() < Convert.toInt(stuPurcreateOrderDTO.getAmount())) {
throw new ServiceException(HttpStatus.ACCEPTED, stuGoodsInfo.getGoodsName() + "商品已售完,请重新选择结算商品");
}
// TODO: 2024/10/28 3、生成订单信息并删除所结算商品在购物车中的信息
//生成订单信息
StuGoodsOrderInfo stuGoodsOrderInfo = new StuGoodsOrderInfo();
//赋值
Integer uuid = UUID.randomUUID().toString().replaceAll("-", "").hashCode();
uuid = uuid < 0 ? -uuid : uuid;//String.hashCode() 值会为空
stuGoodsOrderInfo.setId(uuid);
stuGoodsOrderInfo.setGoodsId(stuPurcreateOrderDTO.getGoodsId());
stuGoodsOrderInfo.setOrderType(stuPurcreateOrderDTO.getGoodsType());
//生成订单编号,将当前时间戳与随机数相结合,生成相对唯一的订单号。
long timestamp = System.currentTimeMillis();
int randomNum = new Random().nextInt(10000); // 生成0-9999之间的随机数
// 订单号格式:时间戳-随机数
String format = String.format("%d-%04d", timestamp, randomNum);
stuGoodsOrderInfo.setOrderNumber(format);
stuGoodsOrderInfo.setGoodsName(stuGoodsInfo.getGoodsName());
stuGoodsOrderInfo.setShopName(stuPurcreateOrderDTO.getShopName());
stuGoodsOrderInfo.setConsignee(stuTradeAccountInfos.get(0).getAccountName());
stuGoodsOrderInfo.setOrderTime(new Date());
stuGoodsOrderInfo.setGoodsUrl(stuGoodsInfo.getGoodsUrl());
stuGoodsOrderInfo.setNumber(Convert.toInt(stuPurcreateOrderDTO.getAmount()));
stuGoodsOrderInfo.setReceiptStatus(0);
stuGoodsOrderInfo.setCommentStatus(0);
stuGoodsOrderInfo.setUserId(stuPurcreateOrderDTO.getUserId());
orderInfoMapper.insert(stuGoodsOrderInfo);
// TODO: 2024/10/28 4、扣除余额
BigDecimal sub = bigDecimalUtils.sub(accountBalance.toString(), bigDecimal.toString());
stuTradeAccountInfos.get(0).setAccountBalance(sub);
accountInfoMapper.updateByPrimaryKey(stuTradeAccountInfos.get(0));
}
}

@ -1,5 +1,6 @@
package com.sztzjy.trade.service.impl;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.RandomUtil;
import com.github.pagehelper.PageHelper;
@ -126,11 +127,15 @@ public class StuGoodsTradingOrderServiceImpl implements StuGoodsTradingOrderServ
stuGoodsInfoDTO.setStoreScore(average);
}
//拼单分享折扣 单位成本价*分享折扣
stuGoodsInfoDTO.setGroupPrice(stuGoodsInfoDTO.getUnitCostPrice().multiply(Convert.toBigDecimal(stuGoodsInfoDTO.getShareDiscounts())));
return new ResultEntity<>(HttpStatus.OK, stuGoodsInfoDTO);
}
return new ResultEntity<>(HttpStatus.NO_CONTENT);
}
@ -199,4 +204,6 @@ public class StuGoodsTradingOrderServiceImpl implements StuGoodsTradingOrderServ
}
}

@ -8,9 +8,11 @@
<result column="user_id" jdbcType="VARCHAR" property="userId" />
<result column="stop_time" jdbcType="TIMESTAMP" property="stopTime" />
<result column="goods_type" jdbcType="VARCHAR" property="goodsType" />
<result column="participate_in_group buying" jdbcType="VARCHAR" property="participateInGroupBuying" />
<result column="participate_in_group_buying" jdbcType="VARCHAR" property="participateInGroupBuying" />
<result column="order_success" jdbcType="INTEGER" property="orderSuccess" />
<result column="miss_many_people" jdbcType="INTEGER" property="missManyPeople" />
<result column="number" jdbcType="INTEGER" property="number" />
<result column="participant_number" jdbcType="VARCHAR" property="participantNumber" />
</resultMap>
<sql id="Example_Where_Clause">
<where>
@ -71,8 +73,8 @@
</where>
</sql>
<sql id="Base_Column_List">
id, goods_id, create_time, user_id, stop_time, goods_type, "participate_in_group buying",
order_success, miss_many_people
id, goods_id, create_time, user_id, stop_time, goods_type, participate_in_group_buying,
order_success, miss_many_people, number, participant_number
</sql>
<select id="selectByExample" parameterType="com.sztzjy.trade.entity.StuSplicingOrdersInfoExample" resultMap="BaseResultMap">
select
@ -107,12 +109,14 @@
<insert id="insert" parameterType="com.sztzjy.trade.entity.StuSplicingOrdersInfo">
insert into stu_splicing_orders_info (id, goods_id, create_time,
user_id, stop_time, goods_type,
"participate_in_group buying", order_success,
miss_many_people)
participate_in_group_buying, order_success,
miss_many_people, number, participant_number
)
values (#{id,jdbcType=INTEGER}, #{goodsId,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP},
#{userId,jdbcType=VARCHAR}, #{stopTime,jdbcType=TIMESTAMP}, #{goodsType,jdbcType=VARCHAR},
#{participateInGroupBuying,jdbcType=VARCHAR}, #{orderSuccess,jdbcType=INTEGER},
#{missManyPeople,jdbcType=INTEGER})
#{missManyPeople,jdbcType=INTEGER}, #{number,jdbcType=INTEGER}, #{participantNumber,jdbcType=VARCHAR}
)
</insert>
<insert id="insertSelective" parameterType="com.sztzjy.trade.entity.StuSplicingOrdersInfo">
insert into stu_splicing_orders_info
@ -136,7 +140,7 @@
goods_type,
</if>
<if test="participateInGroupBuying != null">
"participate_in_group buying",
participate_in_group_buying,
</if>
<if test="orderSuccess != null">
order_success,
@ -144,6 +148,12 @@
<if test="missManyPeople != null">
miss_many_people,
</if>
<if test="number != null">
number,
</if>
<if test="participantNumber != null">
participant_number,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
@ -173,6 +183,12 @@
<if test="missManyPeople != null">
#{missManyPeople,jdbcType=INTEGER},
</if>
<if test="number != null">
#{number,jdbcType=INTEGER},
</if>
<if test="participantNumber != null">
#{participantNumber,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="com.sztzjy.trade.entity.StuSplicingOrdersInfoExample" resultType="java.lang.Long">
@ -203,7 +219,7 @@
goods_type = #{record.goodsType,jdbcType=VARCHAR},
</if>
<if test="record.participateInGroupBuying != null">
"participate_in_group buying" = #{record.participateInGroupBuying,jdbcType=VARCHAR},
participate_in_group_buying = #{record.participateInGroupBuying,jdbcType=VARCHAR},
</if>
<if test="record.orderSuccess != null">
order_success = #{record.orderSuccess,jdbcType=INTEGER},
@ -211,6 +227,12 @@
<if test="record.missManyPeople != null">
miss_many_people = #{record.missManyPeople,jdbcType=INTEGER},
</if>
<if test="record.number != null">
number = #{record.number,jdbcType=INTEGER},
</if>
<if test="record.participantNumber != null">
participant_number = #{record.participantNumber,jdbcType=VARCHAR},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
@ -224,9 +246,11 @@
user_id = #{record.userId,jdbcType=VARCHAR},
stop_time = #{record.stopTime,jdbcType=TIMESTAMP},
goods_type = #{record.goodsType,jdbcType=VARCHAR},
"participate_in_group buying" = #{record.participateInGroupBuying,jdbcType=VARCHAR},
participate_in_group_buying = #{record.participateInGroupBuying,jdbcType=VARCHAR},
order_success = #{record.orderSuccess,jdbcType=INTEGER},
miss_many_people = #{record.missManyPeople,jdbcType=INTEGER}
miss_many_people = #{record.missManyPeople,jdbcType=INTEGER},
number = #{record.number,jdbcType=INTEGER},
participant_number = #{record.participantNumber,jdbcType=VARCHAR}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
@ -250,7 +274,7 @@
goods_type = #{goodsType,jdbcType=VARCHAR},
</if>
<if test="participateInGroupBuying != null">
"participate_in_group buying" = #{participateInGroupBuying,jdbcType=VARCHAR},
participate_in_group_buying = #{participateInGroupBuying,jdbcType=VARCHAR},
</if>
<if test="orderSuccess != null">
order_success = #{orderSuccess,jdbcType=INTEGER},
@ -258,6 +282,12 @@
<if test="missManyPeople != null">
miss_many_people = #{missManyPeople,jdbcType=INTEGER},
</if>
<if test="number != null">
number = #{number,jdbcType=INTEGER},
</if>
<if test="participantNumber != null">
participant_number = #{participantNumber,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
@ -268,9 +298,11 @@
user_id = #{userId,jdbcType=VARCHAR},
stop_time = #{stopTime,jdbcType=TIMESTAMP},
goods_type = #{goodsType,jdbcType=VARCHAR},
"participate_in_group buying" = #{participateInGroupBuying,jdbcType=VARCHAR},
participate_in_group_buying = #{participateInGroupBuying,jdbcType=VARCHAR},
order_success = #{orderSuccess,jdbcType=INTEGER},
miss_many_people = #{missManyPeople,jdbcType=INTEGER}
miss_many_people = #{missManyPeople,jdbcType=INTEGER},
number = #{number,jdbcType=INTEGER},
participant_number = #{participantNumber,jdbcType=VARCHAR}
where id = #{id,jdbcType=INTEGER}
</update>
</mapper>
Loading…
Cancel
Save