You've already forked FrameTour-BE
新增订单添加修改商品状态的逻辑
This commit is contained in:
@ -426,7 +426,7 @@ public enum BizCodeEnum {
|
|||||||
ADVANCE_PAYMENT_REFUND_FAILED(2003, "退款失败"),
|
ADVANCE_PAYMENT_REFUND_FAILED(2003, "退款失败"),
|
||||||
ADVANCE_PAYMENT_CALLBACK_REFUND_FAILED(2004, "退款回调失败"),
|
ADVANCE_PAYMENT_CALLBACK_REFUND_FAILED(2004, "退款回调失败"),
|
||||||
REQUEST_WECHAT_FAIL(2005, "请求微信服务器发生异常"),
|
REQUEST_WECHAT_FAIL(2005, "请求微信服务器发生异常"),
|
||||||
;
|
GOODS_NOT_EXIST(2006, "商品不存在");
|
||||||
|
|
||||||
|
|
||||||
BizCodeEnum(Integer code, String message) {
|
BizCodeEnum(Integer code, String message) {
|
||||||
|
69
src/main/java/com/ycwl/basic/enums/GoodsTypeEnum.java
Normal file
69
src/main/java/com/ycwl/basic/enums/GoodsTypeEnum.java
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
package com.ycwl.basic.enums;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:longbinbin
|
||||||
|
* @Date:2024/12/6 16:46
|
||||||
|
*/
|
||||||
|
public enum GoodsTypeEnum {
|
||||||
|
VIDEO(1,"成片"),
|
||||||
|
SOURCE(2,"源素材")
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
|
public Integer code;
|
||||||
|
|
||||||
|
private String value;
|
||||||
|
public static final Map<Integer, GoodsTypeEnum> cacheMap;
|
||||||
|
|
||||||
|
static {
|
||||||
|
cacheMap = new HashMap<>(GoodsTypeEnum.values().length);
|
||||||
|
for (GoodsTypeEnum value : GoodsTypeEnum.values()) {
|
||||||
|
cacheMap.put(value.code, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static final java.util.Map<String, GoodsTypeEnum> valueMap;
|
||||||
|
|
||||||
|
static {
|
||||||
|
valueMap = new HashMap<>(GoodsTypeEnum.values().length);
|
||||||
|
for (GoodsTypeEnum value : GoodsTypeEnum.values()) {
|
||||||
|
valueMap.put(value.value, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GoodsTypeEnum(Integer code, String value) {
|
||||||
|
this.code = code;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取value值
|
||||||
|
*/
|
||||||
|
public static String getValue(Integer noticeMethod) {
|
||||||
|
if (noticeMethod == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
GoodsTypeEnum GoodsTypeEnum = cacheMap.get(noticeMethod);
|
||||||
|
if (GoodsTypeEnum == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return GoodsTypeEnum.value;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 获取code值
|
||||||
|
*/
|
||||||
|
public static Integer getCode(String noticeMethod) {
|
||||||
|
if (noticeMethod == null) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
GoodsTypeEnum GoodsTypeEnum = valueMap.get(noticeMethod);
|
||||||
|
if (GoodsTypeEnum == null) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return GoodsTypeEnum.code;
|
||||||
|
}
|
||||||
|
}
|
@ -5,6 +5,7 @@ import com.github.pagehelper.PageHelper;
|
|||||||
import com.github.pagehelper.PageInfo;
|
import com.github.pagehelper.PageInfo;
|
||||||
import com.ycwl.basic.constant.NumberConstant;
|
import com.ycwl.basic.constant.NumberConstant;
|
||||||
import com.ycwl.basic.enums.BizCodeEnum;
|
import com.ycwl.basic.enums.BizCodeEnum;
|
||||||
|
import com.ycwl.basic.enums.GoodsTypeEnum;
|
||||||
import com.ycwl.basic.enums.OrderStateEnum;
|
import com.ycwl.basic.enums.OrderStateEnum;
|
||||||
import com.ycwl.basic.enums.SourceTypeNameEnum;
|
import com.ycwl.basic.enums.SourceTypeNameEnum;
|
||||||
import com.ycwl.basic.exception.AppException;
|
import com.ycwl.basic.exception.AppException;
|
||||||
@ -22,7 +23,9 @@ import com.ycwl.basic.model.pc.order.req.OrderReqQuery;
|
|||||||
import com.ycwl.basic.model.pc.order.resp.OrderAppRespVO;
|
import com.ycwl.basic.model.pc.order.resp.OrderAppRespVO;
|
||||||
import com.ycwl.basic.model.pc.order.resp.OrderItemVO;
|
import com.ycwl.basic.model.pc.order.resp.OrderItemVO;
|
||||||
import com.ycwl.basic.model.pc.order.resp.OrderRespVO;
|
import com.ycwl.basic.model.pc.order.resp.OrderRespVO;
|
||||||
|
import com.ycwl.basic.model.pc.source.entity.SourceEntity;
|
||||||
import com.ycwl.basic.model.pc.source.resp.SourceRespVO;
|
import com.ycwl.basic.model.pc.source.resp.SourceRespVO;
|
||||||
|
import com.ycwl.basic.model.pc.video.entity.VideoEntity;
|
||||||
import com.ycwl.basic.model.pc.video.resp.VideoRespVO;
|
import com.ycwl.basic.model.pc.video.resp.VideoRespVO;
|
||||||
import com.ycwl.basic.model.wx.WXPayOrderReqVO;
|
import com.ycwl.basic.model.wx.WXPayOrderReqVO;
|
||||||
import com.ycwl.basic.model.wx.WxPayRespVO;
|
import com.ycwl.basic.model.wx.WxPayRespVO;
|
||||||
@ -94,14 +97,30 @@ public class OrderServiceImpl implements OrderService {
|
|||||||
return ApiResponse.fail("订单添加失败");
|
return ApiResponse.fail("订单添加失败");
|
||||||
} else {
|
} else {
|
||||||
List<GoodsDetailVO> goodsItemList = order.getGoodsItemList();
|
List<GoodsDetailVO> goodsItemList = order.getGoodsItemList();
|
||||||
|
GoodsDetailVO goodsDetailVO = goodsItemList.get(NumberConstant.ZERO);
|
||||||
|
Integer goodsType = goodsDetailVO.getGoodsType();
|
||||||
List<OrderItemEntity> orderItems = new ArrayList<>();
|
List<OrderItemEntity> orderItems = new ArrayList<>();
|
||||||
goodsItemList.forEach(goodsDto -> {
|
goodsItemList.forEach(goodsDto -> {
|
||||||
|
Long goodsId = goodsDto.getGoodsId();
|
||||||
OrderItemEntity orderItemEntity = new OrderItemEntity();
|
OrderItemEntity orderItemEntity = new OrderItemEntity();
|
||||||
orderItemEntity.setId(SnowFlakeUtil.getLongId());
|
orderItemEntity.setId(SnowFlakeUtil.getLongId());
|
||||||
orderItemEntity.setOrderId(orderId);
|
orderItemEntity.setOrderId(orderId);
|
||||||
orderItemEntity.setGoodsType(goodsDto.getGoodsType());
|
orderItemEntity.setGoodsType(goodsDto.getGoodsType());
|
||||||
orderItemEntity.setGoodsId(goodsDto.getGoodsId());
|
orderItemEntity.setGoodsId(goodsId);
|
||||||
orderItems.add(orderItemEntity);
|
orderItems.add(orderItemEntity);
|
||||||
|
|
||||||
|
//修改商品状态
|
||||||
|
if (Objects.equals(goodsType, GoodsTypeEnum.VIDEO.code)) {
|
||||||
|
VideoEntity videoEntity = new VideoEntity();
|
||||||
|
videoEntity.setId(goodsId);
|
||||||
|
videoEntity.setIsBuy(1);
|
||||||
|
videoMapper.update(videoEntity);
|
||||||
|
}else if (Objects.equals(goodsType, GoodsTypeEnum.SOURCE.code)) {
|
||||||
|
SourceEntity sourceEntity = new SourceEntity();
|
||||||
|
sourceEntity.setId(goodsId);
|
||||||
|
sourceEntity.setIsBuy(1);
|
||||||
|
sourceMapper.update(sourceEntity);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
int addOrderItems = orderMapper.addOrderItems(orderItems);
|
int addOrderItems = orderMapper.addOrderItems(orderItems);
|
||||||
if (addOrderItems == NumberConstant.ZERO) {
|
if (addOrderItems == NumberConstant.ZERO) {
|
||||||
@ -109,35 +128,49 @@ public class OrderServiceImpl implements OrderService {
|
|||||||
return ApiResponse.fail("订单添加失败");
|
return ApiResponse.fail("订单添加失败");
|
||||||
}
|
}
|
||||||
|
|
||||||
GoodsDetailVO goodsDetailVO = goodsItemList.get(NumberConstant.ZERO);
|
//封装微信支付请求
|
||||||
Integer goodsType = goodsDetailVO.getGoodsType();
|
WxPayRespVO wxPayRespVO = initiatePayment(orderId, goodsDetailVO);
|
||||||
Long goodsId = goodsDetailVO.getGoodsId();
|
return ApiResponse.success(wxPayRespVO);
|
||||||
|
|
||||||
String goodsName = null;
|
|
||||||
if (goodsType == NumberConstant.ONE) {
|
|
||||||
goodsName = goodsDetailVO.getGoodsName();
|
|
||||||
} else if (goodsType == NumberConstant.TWO) {
|
|
||||||
Integer sourceType = goodsDetailVO.getSourceType();
|
|
||||||
goodsName = SourceTypeNameEnum.getRemark(sourceType);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 成片的时候子订单只会有一个,素材的时候 子订单多个且价格与子订单数量无关,只与子订单商品对应景区定义的价格相同*/
|
|
||||||
GoodsPriceQueryReq goodsPriceQueryReq = new GoodsPriceQueryReq();
|
|
||||||
goodsPriceQueryReq.setGoodsId(goodsId);
|
|
||||||
goodsPriceQueryReq.setGoodsType(goodsType);
|
|
||||||
goodsPriceQueryReq.setScenicId(goodsDetailVO.getScenicId());
|
|
||||||
BigDecimal price = goodsService.queryPrice(goodsPriceQueryReq).getData();
|
|
||||||
|
|
||||||
MemberRespVO memberRespVO = memberService.getUserInfo().getData();
|
|
||||||
WXPayOrderReqVO wxPayOrderReqVO = new WXPayOrderReqVO();
|
|
||||||
wxPayOrderReqVO.setOpenId(memberRespVO.getOpenId())
|
|
||||||
.setOrderSn(orderId)
|
|
||||||
.setTotalPrice(BigDecimalUtil.convertToCents(price))
|
|
||||||
.setGoodsName(goodsName);
|
|
||||||
return ApiResponse.success(wxPayService.createOrder(wxPayOrderReqVO));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发起支付
|
||||||
|
* @param orderId 订单id
|
||||||
|
* @param goodsDetailVO 商品详情
|
||||||
|
* @return 支付请求结果
|
||||||
|
*/
|
||||||
|
private WxPayRespVO initiatePayment(Long orderId,GoodsDetailVO goodsDetailVO) throws Exception {
|
||||||
|
WXPayOrderReqVO wxPayOrderReqVO = new WXPayOrderReqVO();
|
||||||
|
|
||||||
|
Integer goodsType = goodsDetailVO.getGoodsType();
|
||||||
|
Long goodsId = goodsDetailVO.getGoodsId();
|
||||||
|
|
||||||
|
String goodsName = null;
|
||||||
|
if (goodsType == NumberConstant.ONE) {
|
||||||
|
goodsName = goodsDetailVO.getGoodsName();
|
||||||
|
} else if (goodsType == NumberConstant.TWO) {
|
||||||
|
Integer sourceType = goodsDetailVO.getSourceType();
|
||||||
|
goodsName = SourceTypeNameEnum.getRemark(sourceType);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 成片的时候子订单只会有一个,素材的时候 子订单多个且价格与子订单数量无关,只与子订单商品对应景区定义的价格相同*/
|
||||||
|
GoodsPriceQueryReq goodsPriceQueryReq = new GoodsPriceQueryReq();
|
||||||
|
goodsPriceQueryReq.setGoodsId(goodsId);
|
||||||
|
goodsPriceQueryReq.setGoodsType(goodsType);
|
||||||
|
goodsPriceQueryReq.setScenicId(goodsDetailVO.getScenicId());
|
||||||
|
BigDecimal price = goodsService.queryPrice(goodsPriceQueryReq).getData();
|
||||||
|
|
||||||
|
MemberRespVO memberRespVO = memberService.getUserInfo().getData();
|
||||||
|
|
||||||
|
wxPayOrderReqVO.setOpenId(memberRespVO.getOpenId())
|
||||||
|
.setOrderSn(orderId)
|
||||||
|
.setTotalPrice(BigDecimalUtil.convertToCents(price))
|
||||||
|
.setGoodsName(goodsName);
|
||||||
|
|
||||||
|
return wxPayService.createOrder(wxPayOrderReqVO);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ApiResponse<Integer> update(OrderAddOrUpdateReq query) {
|
public ApiResponse<Integer> update(OrderAddOrUpdateReq query) {
|
||||||
int update = orderMapper.update(query);
|
int update = orderMapper.update(query);
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
<if test="taskId!= null">task_id = #{taskId}, </if>
|
<if test="taskId!= null">task_id = #{taskId}, </if>
|
||||||
<if test="workerId!= null">worker_id = #{workerId}, </if>
|
<if test="workerId!= null">worker_id = #{workerId}, </if>
|
||||||
<if test="videoUrl!= null">video_url = #{videoUrl}, </if>
|
<if test="videoUrl!= null">video_url = #{videoUrl}, </if>
|
||||||
|
<if test="isBuy!= null">is_buy = #{isBuy}, </if>
|
||||||
</set>
|
</set>
|
||||||
where id = #{id}
|
where id = #{id}
|
||||||
</update>
|
</update>
|
||||||
@ -42,7 +43,7 @@
|
|||||||
</where>
|
</where>
|
||||||
</select>
|
</select>
|
||||||
<select id="getById" resultType="com.ycwl.basic.model.pc.video.resp.VideoRespVO">
|
<select id="getById" resultType="com.ycwl.basic.model.pc.video.resp.VideoRespVO">
|
||||||
select v.id, scenic_id, member_id, template_id, task_id, worker_id, video_url, v.create_time, v.update_time,
|
select v.id, v.scenic_id, member_id, template_id, task_id, worker_id, video_url, v.create_time, v.update_time,
|
||||||
t.name templateName,t.price templatePrice
|
t.name templateName,t.price templatePrice
|
||||||
from video v
|
from video v
|
||||||
left join template t on v.template_id = t.id
|
left join template t on v.template_id = t.id
|
||||||
|
Reference in New Issue
Block a user