This commit is contained in:
Cauchy
2023-10-18 13:02:54 +08:00
parent 113243e918
commit 5dee4b619e
27 changed files with 386 additions and 216 deletions

View File

@@ -10,6 +10,8 @@ import com.peanut.config.Constants;
import com.peanut.config.DelayQueueConfig; import com.peanut.config.DelayQueueConfig;
import com.peanut.modules.book.entity.*; import com.peanut.modules.book.entity.*;
import com.peanut.modules.book.service.*; import com.peanut.modules.book.service.*;
import com.peanut.modules.book.vo.ExpressQueryResponseVo;
import com.peanut.modules.book.vo.ShippingAddressRequestVo;
import com.peanut.modules.pay.weChatPay.dto.WechatPaymentInfo; import com.peanut.modules.pay.weChatPay.dto.WechatPaymentInfo;
import com.peanut.modules.pay.weChatPay.service.WxpayService; import com.peanut.modules.pay.weChatPay.service.WxpayService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@@ -35,7 +37,7 @@ import java.util.stream.Collectors;
*/ */
@Slf4j @Slf4j
@RestController @RestController
@RequestMapping("book/buyorder") @RequestMapping("book/buyOrder")
public class BuyOrderController { public class BuyOrderController {
@Autowired @Autowired
private BuyOrderService buyOrderService; private BuyOrderService buyOrderService;
@@ -56,8 +58,6 @@ public class BuyOrderController {
@Autowired @Autowired
private UserEbookBuyService userEbookBuyService; private UserEbookBuyService userEbookBuyService;
@Autowired @Autowired
private UserRecordService userRecordService;
@Autowired
private WxpayService wxpayService; private WxpayService wxpayService;
@Autowired @Autowired
private RabbitTemplate rabbitTemplate; private RabbitTemplate rabbitTemplate;
@@ -65,6 +65,9 @@ public class BuyOrderController {
@Autowired @Autowired
private ShopProductBookService shopProductBookService; private ShopProductBookService shopProductBookService;
@Autowired
private ExpressOrderService expressOrderService;
/** /**
* 列表 * 列表
*/ */
@@ -86,7 +89,7 @@ public class BuyOrderController {
*/ */
@RequestMapping("/buySave") @RequestMapping("/buySave")
@Transactional @Transactional
public R buySave(@RequestBody BuyOrderEntity buyOrder) throws IOException { public R buySave(@RequestBody BuyOrder buyOrder) throws IOException {
// 获取订单详情 // 获取订单详情
List<BuyOrderDetail> products = buyOrder.getProducts(); List<BuyOrderDetail> products = buyOrder.getProducts();
// 订单总金额 // 订单总金额
@@ -165,7 +168,7 @@ public class BuyOrderController {
* 修改 * 修改
*/ */
@RequestMapping("/update") @RequestMapping("/update")
public R update(@RequestBody BuyOrderEntity buyOrder) { public R update(@RequestBody BuyOrder buyOrder) {
buyOrderService.updateById(buyOrder); buyOrderService.updateById(buyOrder);
return R.ok(); return R.ok();
} }
@@ -180,68 +183,61 @@ public class BuyOrderController {
} }
/** /**
* 信息 * 获取订单详情
*
* @param orderId 订单 ID
* @return R
*/ */
@RequestMapping("/appGetOrderInfo/{type}") @RequestMapping(value = "/getOrderInfo", method = RequestMethod.GET)
public R appGetOrderInfo(@PathVariable String type, @RequestParam("orderId") Integer orderId) { public R appGetOrderInfo(@RequestParam("orderId") Integer orderId) {
BuyOrderEntity buyOrder = buyOrderService.getById(orderId); BuyOrder buyOrder = buyOrderService.getById(orderId);
buyOrder.setTimestamp(buyOrder.getCreateTime().getTime() / 1000); QueryWrapper<BuyOrderDetail> queryWrapper = new QueryWrapper<>();
List<BuyOrderDetail> orderDetail = null; queryWrapper.eq("order_id", orderId);
if ("1".equals(type)) { List<BuyOrderDetail> buyOrderDetailList = buyOrderDetailService.list(queryWrapper);
orderDetail = buyOrderDetailService.getBaseMapper().selectList(new QueryWrapper<BuyOrderDetail>()
.eq("order_id", orderId));
} else {
orderDetail = buyOrderDetailService.getBaseMapper().selectList(new QueryWrapper<BuyOrderDetail>()
.eq("order_id", orderId));
}
for (BuyOrderDetail buyOrderDetail : orderDetail) {
for (BuyOrderDetail buyOrderDetail : buyOrderDetailList) {
ShopProductEntity prod = shopProductService.getById(buyOrderDetail.getProductId()); ShopProductEntity prod = shopProductService.getById(buyOrderDetail.getProductId());
if (prod != null) { if (prod != null) {
buyOrderDetail.setImage(prod.getProductImages()); buyOrderDetail.setImage(prod.getProductImages());
} }
} }
return R.ok().put("result", buyOrder);
}
List<BuyOrderDetail> resultOrder = new ArrayList<BuyOrderDetail>(); @RequestMapping(value = "/modifyOrderAddress", method = RequestMethod.POST)
Set<String> sn_no = new HashSet<String>(); public R modifyOrderAddress(@RequestBody ShippingAddressRequestVo addressRequestVo) {
for (BuyOrderDetail buyOrderDetail : orderDetail) { BuyOrder buyOrder = buyOrderService.getById(addressRequestVo.getOrderId());
resultOrder.add(buyOrderDetail); buyOrder.setProvince(addressRequestVo.getProvince());
// sn_no.add(buyOrderDetail.getExpressOrderId()); buyOrder.setCity(addressRequestVo.getCity());
} buyOrder.setDistrict(addressRequestVo.getCounty());
buyOrder.setShippingUser(addressRequestVo.getName());
UserRecordEntity userRecordEntity = userRecordService.getBaseMapper().selectOne(new QueryWrapper<UserRecordEntity>() buyOrder.setUserPhone(addressRequestVo.getMobile());
.eq("orderSn", buyOrder.getOrderSn()) buyOrderService.updateById(buyOrder);
.eq("userid", buyOrder.getUserId()) return R.ok();
.eq("orderdid", buyOrder.getOrderId())
.last("LIMIT 1"));
Integer id = null;
if (userRecordEntity != null) {
id = userRecordEntity.getId();
}
buyOrder.setProducts(resultOrder);
Date createDate = buyOrder.getCreateTime();
return R.ok().put("buyOrder", buyOrder).put("CreateTime", createDate).put("userRecordid", id);
} }
/** /**
* 及时查询快递信息 * 查询订单快递
*
* @param orderId 订单号
* @return R
*/ */
// @RequestMapping("/queryFMS") @RequestMapping(value = "/queryExpress", method = RequestMethod.GET)
// public R queryFMS(@RequestParam Map<String, String> params) { public R queryExpress(@RequestParam("orderId") Integer orderId) {
// List<BuyOrderDetailEntity> detailList = this.buyOrderDetailService.getBaseMapper().selectList(new QueryWrapper<BuyOrderDetailEntity>().eq("order_id", params.get("orderId"))); QueryWrapper<BuyOrderDetail> queryWrapper = new QueryWrapper<>();
// List<JSONObject> jsonList = new ArrayList<>(); queryWrapper.eq("order_id", orderId);
// JSONObject jsonObj = null; List<BuyOrderDetail> buyOrderDetailList = buyOrderDetailService.list(queryWrapper);
// for (BuyOrderDetailEntity detail : detailList) { List<ExpressQueryResponseVo> result = new ArrayList<>();
// jsonObj = buyOrderService.queryFMS(detail.getShipperCode(), detail.getShippingSn()); for (BuyOrderDetail buyOrderDetail : buyOrderDetailList) {
// if (Objects.isNull(jsonObj)) { ExpressQueryResponseVo vo = new ExpressQueryResponseVo();
// return R.ok("暂未查到物流信息!"); vo.setOrderDetailId(buyOrderDetail.getId());
// } ExpressQueryResponse expressQueryResponse = expressOrderService.queryExpressOrder(buyOrderDetail.getExpressCompanyCode(), buyOrderDetail.getExpressBillNo());
// jsonObj.put("ShipperName", detail.getShipperName()); vo.setLogisticCode(expressQueryResponse.getLogisticCode());
// jsonList.add(jsonObj); vo.setTraces(expressQueryResponse.getTraces());
// result.add(vo);
// } }
// return R.ok().put("rntStr", jsonList); return R.ok().put("result", result);
// } }
/** /**
* 检查可合并的订单信息 * 检查可合并的订单信息
@@ -270,15 +266,13 @@ public class BuyOrderController {
* 分包发货 * 分包发货
* *
* @param expressCompanyCode 快递公司编码 * @param expressCompanyCode 快递公司编码
* @param userAddressId 用户地址 ID
* @param buyOrderDetailId 订单详情列表 * @param buyOrderDetailId 订单详情列表
* @return R * @return R
*/ */
@RequestMapping(value = "/createSplitPackages", method = RequestMethod.POST) @RequestMapping(value = "/createSplitPackages", method = RequestMethod.POST)
public R createSplitPackageOrder(@RequestParam("expressCompanyCode") String expressCompanyCode, public R createSplitPackageOrder(@RequestParam("expressCompanyCode") String expressCompanyCode,
@RequestParam("userAddressId") Integer userAddressId,
@RequestBody List<Integer> buyOrderDetailId) throws Exception { @RequestBody List<Integer> buyOrderDetailId) throws Exception {
buyOrderService.createSplitPackageOrder(expressCompanyCode, userAddressId, buyOrderDetailId); buyOrderService.createSplitPackageOrder(expressCompanyCode, buyOrderDetailId);
return R.ok(); return R.ok();
} }
@@ -318,7 +312,7 @@ public class BuyOrderController {
* @param buyOrder * @param buyOrder
* @return * @return
*/ */
private BigDecimal useCouponAmount(BuyOrderEntity buyOrder) { private BigDecimal useCouponAmount(BuyOrder buyOrder) {
Integer couponId = buyOrder.getCouponId(); Integer couponId = buyOrder.getCouponId();
if (couponId != null) { if (couponId != null) {
CouponHistoryEntity couponHistory = couponHistoryService.getById(couponId); CouponHistoryEntity couponHistory = couponHistoryService.getById(couponId);
@@ -339,7 +333,7 @@ public class BuyOrderController {
* @param buyOrder * @param buyOrder
* @return * @return
*/ */
private BigDecimal getShoppingAmount(BuyOrderEntity buyOrder) { private BigDecimal getShoppingAmount(BuyOrder buyOrder) {
return buyOrder.getOrderMoney() == null ? BigDecimal.ZERO : buyOrder.getShippingMoney(); return buyOrder.getOrderMoney() == null ? BigDecimal.ZERO : buyOrder.getShippingMoney();
} }
@@ -366,7 +360,7 @@ public class BuyOrderController {
* @param user * @param user
* @param totalPrice * @param totalPrice
*/ */
private void recordTransaction(BuyOrderEntity buyOrder, MyUserEntity user, BigDecimal totalPrice) { private void recordTransaction(BuyOrder buyOrder, MyUserEntity user, BigDecimal totalPrice) {
TransactionDetailsEntity transactionDetailsEntity = new TransactionDetailsEntity(); TransactionDetailsEntity transactionDetailsEntity = new TransactionDetailsEntity();
transactionDetailsEntity.setRemark("订单编号为 - " + buyOrder.getOrderSn()); transactionDetailsEntity.setRemark("订单编号为 - " + buyOrder.getOrderSn());
transactionDetailsEntity.setUserId(user.getId()); transactionDetailsEntity.setUserId(user.getId());
@@ -384,7 +378,7 @@ public class BuyOrderController {
* @param products * @param products
* @param buyOrder * @param buyOrder
*/ */
private void addEbookToUser(List<BuyOrderDetail> products, BuyOrderEntity buyOrder) { private void addEbookToUser(List<BuyOrderDetail> products, BuyOrder buyOrder) {
List<Integer> productIds = products.stream().map(BuyOrderDetail::getProductId).collect(Collectors.toList()); List<Integer> productIds = products.stream().map(BuyOrderDetail::getProductId).collect(Collectors.toList());
for (Integer productId : productIds) { for (Integer productId : productIds) {
List<Integer> collect = shopProductBookService.getBaseMapper().selectList(new LambdaQueryWrapper<ShopProductBookEntity>() List<Integer> collect = shopProductBookService.getBaseMapper().selectList(new LambdaQueryWrapper<ShopProductBookEntity>()
@@ -400,7 +394,7 @@ public class BuyOrderController {
* @param buyOrder * @param buyOrder
* @param buyOrderDetail * @param buyOrderDetail
*/ */
private void handleBuyCart(BuyOrderEntity buyOrder, BuyOrderDetail buyOrderDetail) { private void handleBuyCart(BuyOrder buyOrder, BuyOrderDetail buyOrderDetail) {
List<OrderCartEntity> orderCartList = orderCartService.getBaseMapper().selectList(new QueryWrapper<OrderCartEntity>() List<OrderCartEntity> orderCartList = orderCartService.getBaseMapper().selectList(new QueryWrapper<OrderCartEntity>()
.eq("user_id", buyOrder.getUserId()).eq("product_id", buyOrderDetail.getProductId())); .eq("user_id", buyOrder.getUserId()).eq("product_id", buyOrderDetail.getProductId()));
if (orderCartList.size() > 0) { if (orderCartList.size() > 0) {

View File

@@ -117,11 +117,11 @@ public class UserFollowUpController {
return R.error("请先评论再追评"); return R.error("请先评论再追评");
} }
String orderSn = userRecord.getOrderSn(); String orderSn = userRecord.getOrderSn();
BuyOrderEntity buyOrderEntity =buyOrderService.getBaseMapper().selectOne(new QueryWrapper<BuyOrderEntity>() BuyOrder buyOrder =buyOrderService.getBaseMapper().selectOne(new QueryWrapper<BuyOrder>()
.eq("order_sn",orderSn).last("LIMIT 1") .eq("order_sn",orderSn).last("LIMIT 1")
); );
Integer orderId = buyOrderEntity.getOrderId(); Integer orderId = buyOrder.getOrderId();
Integer bookid = userRecord.getBookid(); Integer bookid = userRecord.getBookid();
Integer userid = userRecord.getUserid(); Integer userid = userRecord.getUserid();
Integer id1 = userRecord.getId(); Integer id1 = userRecord.getId();
@@ -134,8 +134,8 @@ public class UserFollowUpController {
// return R.error("您已评价过"); // return R.error("您已评价过");
// } // }
buyOrderEntity.setRecordId(2); buyOrder.setRecordId(2);
buyOrderService.saveOrUpdate(buyOrderEntity); buyOrderService.saveOrUpdate(buyOrder);
if (userFollowUpEntity.getImages()!=null) { if (userFollowUpEntity.getImages()!=null) {
List<Map<String,String>> imageList = (ArrayList<Map<String,String>>)userFollowUpEntity.getImages(); List<Map<String,String>> imageList = (ArrayList<Map<String,String>>)userFollowUpEntity.getImages();

View File

@@ -164,7 +164,7 @@ public class UserRecordController {
public Object commodityComments(Integer userid, String orderSn, Integer bookid, String comment) { public Object commodityComments(Integer userid, String orderSn, Integer bookid, String comment) {
BuyOrderEntity buyOrderEntity = buyOrderService.getBaseMapper().selectOne(new QueryWrapper<BuyOrderEntity>() BuyOrder buyOrder = buyOrderService.getBaseMapper().selectOne(new QueryWrapper<BuyOrder>()
.eq("order_sn", orderSn).last("LIMIT 1").eq("order_status", "3") .eq("order_sn", orderSn).last("LIMIT 1").eq("order_status", "3")
//状态3为已收货 //状态3为已收货
// .eq("order_status","3") // .eq("order_status","3")
@@ -172,11 +172,11 @@ public class UserRecordController {
UserRecordEntity userRecordEntity = new UserRecordEntity(); UserRecordEntity userRecordEntity = new UserRecordEntity();
if (!ToolObject.isNullOrEmpty(buyOrderEntity)) { if (!ToolObject.isNullOrEmpty(buyOrder)) {
return error("您已评价过了,请勿重复评论"); return error("您已评价过了,请勿重复评论");
// //
} else { } else {
userRecordEntity.setId(buyOrderEntity.getOrderId()); userRecordEntity.setId(buyOrder.getOrderId());
userRecordEntity.setContent(comment); userRecordEntity.setContent(comment);
//商品评价 //商品评价
userRecordEntity.setBookid(bookid); userRecordEntity.setBookid(bookid);
@@ -199,11 +199,11 @@ public class UserRecordController {
@RequestMapping("/UserRecordcomment") @RequestMapping("/UserRecordcomment")
public R commodity(@RequestBody UserRecordEntity recordEntity) { public R commodity(@RequestBody UserRecordEntity recordEntity) {
//todo 已收货限制字段,只可评价一次 //todo 已收货限制字段,只可评价一次
BuyOrderEntity buyOrderEntity = buyOrderService.getBaseMapper().selectOne(new QueryWrapper<BuyOrderEntity>() BuyOrder buyOrder = buyOrderService.getBaseMapper().selectOne(new QueryWrapper<BuyOrder>()
.eq("order_sn", recordEntity.getOrderSn()) .eq("order_sn", recordEntity.getOrderSn())
); );
Integer orderId = buyOrderEntity.getOrderId(); Integer orderId = buyOrder.getOrderId();
BuyOrderDetail detailEntity = buyOrderDetailService.getBaseMapper().selectOne(new QueryWrapper<BuyOrderDetail>().eq("Order_id", orderId).eq("product_id", recordEntity.getBookid())); BuyOrderDetail detailEntity = buyOrderDetailService.getBaseMapper().selectOne(new QueryWrapper<BuyOrderDetail>().eq("Order_id", orderId).eq("product_id", recordEntity.getBookid()));
Integer orderId1 = detailEntity.getOrderId(); Integer orderId1 = detailEntity.getOrderId();
UserRecordEntity userRecordEntity = userRecordService.getBaseMapper().selectOne(new QueryWrapper<UserRecordEntity>().eq("orderSn", recordEntity.getOrderSn()).eq("userid", recordEntity.getUserid()).eq("orderdid", orderId1).last("LIMIT 1")); UserRecordEntity userRecordEntity = userRecordService.getBaseMapper().selectOne(new QueryWrapper<UserRecordEntity>().eq("orderSn", recordEntity.getOrderSn()).eq("userid", recordEntity.getUserid()).eq("orderdid", orderId1).last("LIMIT 1"));

View File

@@ -1,10 +1,8 @@
package com.peanut.modules.book.dao; package com.peanut.modules.book.dao;
import com.alibaba.fastjson.JSONObject; import com.peanut.modules.book.entity.BuyOrder;
import com.peanut.modules.book.entity.BuyOrderEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.poi.ss.formula.functions.T;
import java.util.List; import java.util.List;
@@ -16,8 +14,8 @@ import java.util.List;
* @date 2022-08-29 15:27:44 * @date 2022-08-29 15:27:44
*/ */
@Mapper @Mapper
public interface BuyOrderDao extends BaseMapper<BuyOrderEntity> { public interface BuyOrderDao extends BaseMapper<BuyOrder> {
public List<BuyOrderEntity> queryListByOrderIds(Integer[] ids); public List<BuyOrder> queryListByOrderIds(Integer[] ids);
} }

View File

@@ -18,7 +18,7 @@ import lombok.Data;
*/ */
@Data @Data
@TableName("buy_order") @TableName("buy_order")
public class BuyOrderEntity implements Serializable { public class BuyOrder implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@TableId @TableId

View File

@@ -83,7 +83,7 @@ public class BuyOrderDetail implements Serializable {
/** /**
* 面单html * 面单html
*/ */
private String expressBill; private String expressBillTemplate;
/** /**
* 商品图片地址 * 商品图片地址
*/ */
@@ -96,4 +96,8 @@ public class BuyOrderDetail implements Serializable {
* 快递单号 * 快递单号
*/ */
private String expressBillNo; private String expressBillNo;
/**
* 快递公司编码
*/
private String expressCompanyCode;
} }

View File

@@ -24,9 +24,29 @@ public class ExpressOrder {
*/ */
private int userId; private int userId;
/** /**
* 用户地址 ID * 省份
*/ */
private int userAddressId; private String province;
/**
* 城市
*/
private String city;
/**
* 区县
*/
private String county;
/**
* 收件人姓名
*/
private String name;
/**
* 收件人电话
*/
private String mobile;
/**
* 收件人详细地址
*/
private String address;
/** /**
* 订单号 * 订单号
*/ */

View File

@@ -0,0 +1,51 @@
package com.peanut.modules.book.entity;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
* @Description: 快递查询返回结果 Value Object
* @Author: Cauchy
* @CreateTime: 2023/10/17
*/
@Data
public class ExpressQueryResponse implements Serializable {
/**
* 用户 ID
*/
private String EBusinessID;
/**
* 快递公司编码
*/
private String ShipperCode;
/**
* 快递单号
*/
private String LogisticCode;
/**
* 是否成功
*/
private boolean Success;
/**
* 原因
*/
private String Reason;
/**
* 状态
* 普通物流状态:
* 0-暂无轨迹信息
* 1-已揽收
* 2-在途中
* 3-签收
* 4-问题件
* 5-转寄
* 6-清关
*/
private String State;
/**
* 轨迹
*/
private List<Trace> Traces;
}

View File

@@ -0,0 +1,17 @@
package com.peanut.modules.book.entity;
import lombok.Data;
import java.util.Date;
@Data
public class Trace {
/**
* 轨迹时间
*/
private Date AcceptTime;
/**
* 轨迹描述
*/
private String AcceptStation;
}

View File

@@ -1,13 +1,9 @@
package com.peanut.modules.book.service; package com.peanut.modules.book.service;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.peanut.common.utils.PageUtils; import com.peanut.common.utils.PageUtils;
import com.peanut.modules.book.entity.ActivityEntity; import com.peanut.modules.book.entity.ActivityEntity;
import com.peanut.modules.book.entity.BuyOrderEntity;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**

View File

@@ -3,7 +3,7 @@ package com.peanut.modules.book.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.peanut.common.utils.PageUtils; import com.peanut.common.utils.PageUtils;
import com.peanut.modules.book.entity.BuyOrderEntity; import com.peanut.modules.book.entity.BuyOrder;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -15,7 +15,7 @@ import java.util.Map;
* @email yl328572838@163.com * @email yl328572838@163.com
* @date 2022-08-29 15:27:44 * @date 2022-08-29 15:27:44
*/ */
public interface BuyOrderService extends IService<BuyOrderEntity> { public interface BuyOrderService extends IService<BuyOrder> {
PageUtils queryPage(Map<String, Object> params) throws Exception; PageUtils queryPage(Map<String, Object> params) throws Exception;
@@ -32,9 +32,7 @@ public interface BuyOrderService extends IService<BuyOrderEntity> {
* 订单拆分发货 * 订单拆分发货
* *
* @param expressCompanyCode 快递公司代码 * @param expressCompanyCode 快递公司代码
* @param userAddressId 用户地址 ID
* @param buyOrderDetailId 订单详情 ID 列表 * @param buyOrderDetailId 订单详情 ID 列表
* @throws Exception exception
*/ */
void createSplitPackageOrder(String expressCompanyCode, Integer userAddressId, List<Integer> buyOrderDetailId) throws Exception; void createSplitPackageOrder(String expressCompanyCode, List<Integer> buyOrderDetailId);
} }

View File

@@ -2,22 +2,19 @@ package com.peanut.modules.book.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.peanut.modules.book.entity.ExpressOrder; import com.peanut.modules.book.entity.ExpressOrder;
import com.peanut.modules.book.entity.UserAddress; import com.peanut.modules.book.vo.ExpressOrderResponseVo;
import com.peanut.modules.book.vo.ExpressQueryResponseVo; import com.peanut.modules.book.entity.ExpressQueryResponse;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Map;
@Service @Service
public interface ExpressOrderService extends IService<ExpressOrder> { public interface ExpressOrderService extends IService<ExpressOrder> {
/** /**
* 下单生成面单 * 下单生成面单
* *
* @param userAddress
* @param expressOrder * @param expressOrder
* @throws Exception * @throws Exception
*/ */
Map<String, String> placeExpressOrder(UserAddress userAddress, ExpressOrder expressOrder); ExpressOrderResponseVo placeExpressOrder(ExpressOrder expressOrder);
ExpressQueryResponseVo queryExpressOrder(String ShipperCode, String LogisticCode); ExpressQueryResponse queryExpressOrder(String ShipperCode, String LogisticCode);
} }

View File

@@ -12,6 +12,7 @@ import com.peanut.modules.book.dao.BuyOrderDao;
import com.peanut.modules.book.entity.*; import com.peanut.modules.book.entity.*;
import com.peanut.modules.book.service.*; import com.peanut.modules.book.service.*;
import com.peanut.modules.book.entity.ExpressCommodity; import com.peanut.modules.book.entity.ExpressCommodity;
import com.peanut.modules.book.vo.ExpressOrderResponseVo;
import com.peanut.modules.book.vo.UserOrderVo; import com.peanut.modules.book.vo.UserOrderVo;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -26,22 +27,22 @@ import java.util.stream.Collectors;
@Service("buyOrderService") @Service("buyOrderService")
public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrderEntity> implements BuyOrderService { public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrder> implements BuyOrderService {
@Autowired @Autowired
private BuyOrderDetailService buyOrderDetailService; private BuyOrderDetailService buyOrderDetailService;
@Autowired @Autowired
private MyUserService myUserService; private MyUserService myUserService;
@Autowired
private UserAddressService userAddressService;
@Autowired @Autowired
private ExpressFeeService expressFeeService; private ExpressFeeService expressFeeService;
@Autowired @Autowired
private ExpressOrderService expressOrderService; private ExpressOrderService expressOrderService;
@Autowired
CountyService countyService;
protected Logger logger = LoggerFactory.getLogger(BuyOrderServiceImpl.class); protected Logger logger = LoggerFactory.getLogger(BuyOrderServiceImpl.class);
@@ -51,7 +52,7 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrderEntity
@Override @Override
public PageUtils queryPage(Map<String, Object> params) throws Exception { public PageUtils queryPage(Map<String, Object> params) throws Exception {
IPage<BuyOrderEntity> page; IPage<BuyOrder> page;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String startTime = null; String startTime = null;
String endTime = null; String endTime = null;
@@ -61,8 +62,8 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrderEntity
} }
if (ObjectUtils.isEmpty(params.get("orderStatus"))) { if (ObjectUtils.isEmpty(params.get("orderStatus"))) {
page = this.page( page = this.page(
new Query<BuyOrderEntity>().getPage(params), new Query<BuyOrder>().getPage(params),
new ExcludeEmptyQueryWrapper<BuyOrderEntity>().eq("user_phone", params.get("key")). new ExcludeEmptyQueryWrapper<BuyOrder>().eq("user_phone", params.get("key")).
or().like("order_sn", params.get("key")).or().like("shipping_user", params.get("key")) or().like("order_sn", params.get("key")).or().like("shipping_user", params.get("key"))
.apply(startTime != null, "date_format (create_time,'%Y-%m-%d') >= date_format ({0},'%Y-%m-%d')", startTime) .apply(startTime != null, "date_format (create_time,'%Y-%m-%d') >= date_format ({0},'%Y-%m-%d')", startTime)
.apply(endTime != null, "date_format (create_time,'%Y-%m-%d') <= date_format ({0},'%Y-%m-%d')", endTime).orderByDesc("create_time") .apply(endTime != null, "date_format (create_time,'%Y-%m-%d') <= date_format ({0},'%Y-%m-%d')", endTime).orderByDesc("create_time")
@@ -70,8 +71,8 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrderEntity
); );
} else { } else {
page = this.page( page = this.page(
new Query<BuyOrderEntity>().getPage(params), new Query<BuyOrder>().getPage(params),
new ExcludeEmptyQueryWrapper<BuyOrderEntity>().eq("order_status", params.get("orderStatus")).eq("user_phone", params.get("key")) new ExcludeEmptyQueryWrapper<BuyOrder>().eq("order_status", params.get("orderStatus")).eq("user_phone", params.get("key"))
.or().like("order_sn", params.get("key")).or().like("shipping_user", params.get("key")) .or().like("order_sn", params.get("key")).or().like("shipping_user", params.get("key"))
.apply(startTime != null, "date_format (create_time,'%Y-%m-%d') >= date_format ({0},'%Y-%m-%d')", startTime) .apply(startTime != null, "date_format (create_time,'%Y-%m-%d') >= date_format ({0},'%Y-%m-%d')", startTime)
.apply(endTime != null, "date_format (create_time,'%Y-%m-%d') <= date_format ({0},'%Y-%m-%d')", endTime).orderByDesc("create_time") .apply(endTime != null, "date_format (create_time,'%Y-%m-%d') <= date_format ({0},'%Y-%m-%d')", endTime).orderByDesc("create_time")
@@ -79,8 +80,8 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrderEntity
} }
List<BuyOrderEntity> records = page.getRecords(); List<BuyOrder> records = page.getRecords();
for (BuyOrderEntity record : records) { for (BuyOrder record : records) {
Integer userId = record.getUserId(); Integer userId = record.getUserId();
MyUserEntity myUserEntity = myUserService.getById(userId); MyUserEntity myUserEntity = myUserService.getById(userId);
if (!ObjectUtils.isEmpty(myUserEntity)) { if (!ObjectUtils.isEmpty(myUserEntity)) {
@@ -105,7 +106,7 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrderEntity
// 交易成功 2 // 交易成功 2
// 交易失败 9 // 交易失败 9
BuyOrderEntity orderEntity = this.getOne(new QueryWrapper<BuyOrderEntity>().eq("user_id", userId) BuyOrder orderEntity = this.getOne(new QueryWrapper<BuyOrder>().eq("user_id", userId)
.eq("order_sn", orderSn)); .eq("order_sn", orderSn));
if (type.equals("0")) { if (type.equals("0")) {
orderEntity.setOrderStatus("1"); orderEntity.setOrderStatus("1");
@@ -130,18 +131,18 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrderEntity
public List checkOrder(Integer[] orderIds) { public List checkOrder(Integer[] orderIds) {
// 查询出所有的订单信息(携带订单商品) // 查询出所有的订单信息(携带订单商品)
List<BuyOrderEntity> orderList = new ArrayList<>(); List<BuyOrder> orderList = new ArrayList<>();
List<BuyOrderEntity> buyOrderList = this.list( List<BuyOrder> buyOrderList = this.list(
new QueryWrapper<BuyOrderEntity>().eq("del_flag", "0").eq("order_status", "1") new QueryWrapper<BuyOrder>().eq("del_flag", "0").eq("order_status", "1")
); );
for (BuyOrderEntity order : buyOrderList) { for (BuyOrder order : buyOrderList) {
order.setProducts(buyOrderDetailService.list(new QueryWrapper<BuyOrderDetail>() order.setProducts(buyOrderDetailService.list(new QueryWrapper<BuyOrderDetail>()
.eq("order_id", order.getOrderId()))); .eq("order_id", order.getOrderId())));
orderList.add(order); orderList.add(order);
} }
// 清洗数据 (与前端传来的id对比后) // 清洗数据 (与前端传来的id对比后)
List<BuyOrderEntity> washOrderList = new ArrayList<>(); List<BuyOrder> washOrderList = new ArrayList<>();
for (BuyOrderEntity order : orderList) { for (BuyOrder order : orderList) {
for (int o : orderIds) { for (int o : orderIds) {
if (o == order.getOrderId()) { if (o == order.getOrderId()) {
washOrderList.add(order); washOrderList.add(order);
@@ -151,7 +152,7 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrderEntity
Map<Integer, Object> map = new HashMap<>(); Map<Integer, Object> map = new HashMap<>();
// 使用清洗后的List获得其中有多少个用户 // 使用清洗后的List获得其中有多少个用户
for (BuyOrderEntity o : washOrderList) { for (BuyOrder o : washOrderList) {
map.put(o.getUserId(), o); map.put(o.getUserId(), o);
} }
//获取map的所有key转为list //获取map的所有key转为list
@@ -159,8 +160,8 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrderEntity
List<UserOrderVo> userOrderVoList = new ArrayList<>(); List<UserOrderVo> userOrderVoList = new ArrayList<>();
for (int key : keys) { for (int key : keys) {
UserOrderVo userOrderVo = new UserOrderVo(); UserOrderVo userOrderVo = new UserOrderVo();
List<BuyOrderEntity> orderEntityList = new ArrayList<>(); List<BuyOrder> orderEntityList = new ArrayList<>();
for (BuyOrderEntity o : buyOrderList) { for (BuyOrder o : buyOrderList) {
if (o.getUserId().equals(key)) { if (o.getUserId().equals(key)) {
userOrderVo.setTel(o.getUserPhone()); userOrderVo.setTel(o.getUserPhone());
userOrderVo.setUserName(o.getShippingUser()); userOrderVo.setUserName(o.getShippingUser());
@@ -195,16 +196,16 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrderEntity
public Page checkOrder(Map<String, Object> params) { public Page checkOrder(Map<String, Object> params) {
// 查询所有订单信息 // 查询所有订单信息
List<BuyOrderEntity> orderList = new ArrayList<>(); List<BuyOrder> orderList = new ArrayList<>();
List<UserOrderVo> userOrderVoList = new ArrayList<>(); List<UserOrderVo> userOrderVoList = new ArrayList<>();
// 返回的list // 返回的list
List<UserOrderVo> rntList = new ArrayList<>(); List<UserOrderVo> rntList = new ArrayList<>();
Page<UserOrderVo> rntPage = new Page<>(); Page<UserOrderVo> rntPage = new Page<>();
IPage<BuyOrderEntity> buyOrderList = this.page( IPage<BuyOrder> buyOrderList = this.page(
new Query<BuyOrderEntity>().getPage(params), new Query<BuyOrder>().getPage(params),
new QueryWrapper<BuyOrderEntity>().eq("del_flag", "0").eq("order_status", "1").eq("is_send", "0") new QueryWrapper<BuyOrder>().eq("del_flag", "0").eq("order_status", "1").eq("is_send", "0")
); );
for (BuyOrderEntity order : buyOrderList.getRecords()) { for (BuyOrder order : buyOrderList.getRecords()) {
order.setProducts(buyOrderDetailService.list(new QueryWrapper<BuyOrderDetail>() order.setProducts(buyOrderDetailService.list(new QueryWrapper<BuyOrderDetail>()
.eq("order_id", order.getOrderId()))); .eq("order_id", order.getOrderId())));
orderList.add(order); orderList.add(order);
@@ -212,7 +213,7 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrderEntity
// 获取有订单的所有用户 // 获取有订单的所有用户
Map<Integer, Object> map = new HashMap<>(); Map<Integer, Object> map = new HashMap<>();
for (BuyOrderEntity order : orderList) { for (BuyOrder order : orderList) {
map.put(order.getUserId(), order); map.put(order.getUserId(), order);
} }
//获取map的所有key转为list //获取map的所有key转为list
@@ -220,8 +221,8 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrderEntity
for (int key : keys) { for (int key : keys) {
UserOrderVo userOrderVo = new UserOrderVo(); UserOrderVo userOrderVo = new UserOrderVo();
List<BuyOrderEntity> orderEntityList = new ArrayList<>(); List<BuyOrder> orderEntityList = new ArrayList<>();
for (BuyOrderEntity o : buyOrderList.getRecords()) { for (BuyOrder o : buyOrderList.getRecords()) {
if (o.getUserId().equals(key)) { if (o.getUserId().equals(key)) {
userOrderVo.setUserName(o.getShippingUser()); userOrderVo.setUserName(o.getShippingUser());
userOrderVo.setTel(o.getUserPhone()); userOrderVo.setTel(o.getUserPhone());
@@ -244,7 +245,7 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrderEntity
} }
@Override @Override
public void createSplitPackageOrder(String expressCompanyCode, Integer userAddressId, List<Integer> buyOrderDetailId) { public void createSplitPackageOrder(String expressCompanyCode, List<Integer> buyOrderDetailId) {
QueryWrapper<BuyOrderDetail> queryWrapper = new QueryWrapper<>(); QueryWrapper<BuyOrderDetail> queryWrapper = new QueryWrapper<>();
queryWrapper.in("id", buyOrderDetailId); queryWrapper.in("id", buyOrderDetailId);
List<BuyOrderDetail> buyOrderDetailList = buyOrderDetailService.list(queryWrapper); List<BuyOrderDetail> buyOrderDetailList = buyOrderDetailService.list(queryWrapper);
@@ -262,9 +263,13 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrderEntity
} }
// 获取用户地址 // 获取用户地址
UserAddress address = userAddressService.getById(userAddressId); Integer orderId = buyOrderDetailList.get(0).getOrderId();
BuyOrder buyOrder = getById(orderId);
QueryWrapper<CountyEntity> countyQueryWrapper = new QueryWrapper<>();
countyQueryWrapper.eq("county_name", buyOrder.getDistrict());
CountyEntity county = countyService.getOne(countyQueryWrapper);
// 计算快递费用 // 计算快递费用
BigDecimal expressFee = expressFeeService.calculateExpressFee(expressCompanyCode, totalWeight, address.getRegionCode()); BigDecimal expressFee = expressFeeService.calculateExpressFee(expressCompanyCode, totalWeight, county.getRegionCode());
ExpressOrder expressOrder = new ExpressOrder(); ExpressOrder expressOrder = new ExpressOrder();
expressOrder.setOrderId(buyOrderDetailList.get(0).getOrderId()); expressOrder.setOrderId(buyOrderDetailList.get(0).getOrderId());
expressOrder.setExpressFee(expressFee); expressOrder.setExpressFee(expressFee);
@@ -272,11 +277,20 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrderEntity
expressOrder.setTotalWeight(totalWeight); expressOrder.setTotalWeight(totalWeight);
expressOrder.setCommodity(commodityList); expressOrder.setCommodity(commodityList);
expressOrder.setExpressCompanyCode(expressCompanyCode); expressOrder.setExpressCompanyCode(expressCompanyCode);
expressOrder.setName(buyOrder.getShippingUser());
expressOrder.setMobile(buyOrder.getUserPhone());
expressOrder.setProvince(buyOrder.getProvince());
expressOrder.setCity(buyOrder.getCity());
expressOrder.setCounty(buyOrder.getDistrict());
expressOrder.setAddress(buyOrder.getAddress());
// 生成快递面单 // 生成快递面单
Map<String, String> result = expressOrderService.placeExpressOrder(address, expressOrder); ExpressOrderResponseVo response = expressOrderService.placeExpressOrder(expressOrder);
String expressBillNo = response.getOrder().getLogisticCode();
String expressBillTemplate = response.getPrintTemplate();
for (BuyOrderDetail buyOrderDetail : buyOrderDetailList) { for (BuyOrderDetail buyOrderDetail : buyOrderDetailList) {
buyOrderDetail.setExpressBill(result.get("expressBill")); buyOrderDetail.setExpressBillNo(expressBillNo);
buyOrderDetail.setExpressBillNo(result.get("expressBillNo")); buyOrderDetail.setExpressBillTemplate(expressBillTemplate);
buyOrderDetail.setExpressCompanyCode(expressCompanyCode);
} }
buyOrderDetailService.saveBatch(buyOrderDetailList); buyOrderDetailService.saveBatch(buyOrderDetailList);
} }

View File

@@ -1,19 +1,15 @@
package com.peanut.modules.book.service.impl; package com.peanut.modules.book.service.impl;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.peanut.common.utils.HttpClientUtils; import com.peanut.common.utils.HttpClientUtils;
import com.peanut.common.utils.KdUtils; import com.peanut.common.utils.KdUtils;
import com.peanut.config.Constants; import com.peanut.config.Constants;
import com.peanut.modules.book.dao.ExpressOrderDao; import com.peanut.modules.book.dao.ExpressOrderDao;
import com.peanut.modules.book.entity.*; import com.peanut.modules.book.entity.ExpressOrder;
import com.peanut.modules.book.service.*; import com.peanut.modules.book.entity.ExpressQueryResponse;
import com.peanut.modules.book.vo.ExpressOrderRequestVo; import com.peanut.modules.book.service.ExpressOrderService;
import com.peanut.modules.book.vo.ExpressOrderResponseVo; import com.peanut.modules.book.vo.*;
import com.peanut.modules.book.vo.ExpressQueryResponseVo;
import com.peanut.modules.book.vo.ExpressUserInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@@ -41,18 +37,9 @@ public class ExpressOrderServiceImpl extends ServiceImpl<ExpressOrderDao, Expres
@Value("${express.sender.address}") @Value("${express.sender.address}")
private String senderAddress; private String senderAddress;
@Autowired
private CountyService countyService;
@Autowired
private CityService cityService;
@Autowired
private ProvinceService provinceService;
@Override @Override
public Map<String, String> placeExpressOrder(UserAddress userAddress, ExpressOrder expressOrder) { public ExpressOrderResponseVo placeExpressOrder(ExpressOrder expressOrder) {
ExpressOrderRequestVo orderRequestVo = new ExpressOrderRequestVo(); ExpressOrderRequestVo orderRequestVo = new ExpressOrderRequestVo();
// 订单号 // 订单号
orderRequestVo.setOrderCode(expressOrder.getOrderId().toString()); orderRequestVo.setOrderCode(expressOrder.getOrderId().toString());
@@ -74,20 +61,25 @@ public class ExpressOrderServiceImpl extends ServiceImpl<ExpressOrderDao, Expres
sender.setExpAreaName(senderExpAreaName); sender.setExpAreaName(senderExpAreaName);
sender.setAddress(senderAddress); sender.setAddress(senderAddress);
// 收货人 // 收货人
ExpressUserInfoVo receiver = buildReceiverBasedOnUserAddress(userAddress); ExpressUserInfoVo receiver = new ExpressUserInfoVo();
receiver.setName(expressOrder.getName());
receiver.setMobile(expressOrder.getMobile());
receiver.setProvinceName(expressOrder.getProvince());
receiver.setCityName(expressOrder.getCity());
receiver.setAddress(expressOrder.getAddress());
orderRequestVo.setSender(sender); orderRequestVo.setSender(sender);
orderRequestVo.setReceiver(receiver); orderRequestVo.setReceiver(receiver);
orderRequestVo.setCommodity(expressOrder.getCommodity()); orderRequestVo.setCommodity(expressOrder.getCommodity());
orderRequestVo.setWeight(expressOrder.getTotalWeight().doubleValue()); orderRequestVo.setWeight(expressOrder.getTotalWeight().doubleValue());
orderRequestVo.setRemark(expressOrder.getRemark()); orderRequestVo.setRemark(expressOrder.getRemark());
String RequestData = JSONObject.toJSONString(orderRequestVo); String requestData = JSONObject.toJSONString(orderRequestVo);
Map<String, String> params = new HashMap<>(); Map<String, String> params = new HashMap<>();
params.put("RequestData", RequestData); params.put("RequestData", requestData);
params.put("EBusinessID", Constants.EXPRESS_BUSINESS_ID); params.put("EBusinessID", Constants.EXPRESS_BUSINESS_ID);
params.put("RequestType", Constants.EXPRESS_REQUEST_TYPE_PLACE_ORDER); params.put("RequestType", Constants.EXPRESS_REQUEST_TYPE_PLACE_ORDER);
try { try {
String dataSign = KdUtils.encrypt(RequestData, Constants.EXPRESS_API_KEY, "UTF-8"); String dataSign = KdUtils.encrypt(requestData, Constants.EXPRESS_API_KEY, "UTF-8");
params.put("DataSign", KdUtils.urlEncoder(dataSign, "UTF-8")); params.put("DataSign", KdUtils.urlEncoder(dataSign, "UTF-8"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@@ -96,44 +88,29 @@ public class ExpressOrderServiceImpl extends ServiceImpl<ExpressOrderDao, Expres
params.put("DataType", "2"); params.put("DataType", "2");
String response = HttpClientUtils.kdSendPost(Constants.EXPRESS_PLACE_ORDER_URL, params); String response = HttpClientUtils.kdSendPost(Constants.EXPRESS_PLACE_ORDER_URL, params);
ExpressOrderResponseVo responseVo = JSONObject.parseObject(response, ExpressOrderResponseVo.class); ExpressOrderResponseVo responseVo = JSONObject.parseObject(response, ExpressOrderResponseVo.class);
String expressBillNo = responseVo.getOrder().getLogisticCode(); return responseVo;
Map<String, String> result = new HashMap<>();
result.put("expressBillNo", expressBillNo);
result.put("template", responseVo.getPrintTemplate());
return result;
} }
@Override @Override
public ExpressQueryResponseVo queryExpressOrder(String ShipperCode, String LogisticCode) { public ExpressQueryResponse queryExpressOrder(String shipperCode, String logisticCode) {
return null; ExpressQueryRequestVo requestVo = new ExpressQueryRequestVo();
} requestVo.setLogisticCode(logisticCode);
requestVo.setShipperCode(shipperCode);
private ExpressUserInfoVo buildReceiverBasedOnUserAddress(UserAddress userAddress) { String requestData = JSONObject.toJSONString(requestVo);
ExpressUserInfoVo vo = new ExpressUserInfoVo(); Map<String, String> params = new HashMap<>();
vo.setName(userAddress.getConsigneeName()); params.put("RequestData", requestData);
vo.setMobile(userAddress.getConsigneePhone()); params.put("EBusinessID", Constants.EXPRESS_BUSINESS_ID);
vo.setAddress(userAddress.getDetailAddress()); params.put("RequestType", Constants.EXPRESS_REQUEST_TYPE_QUERY);
String regionCode = userAddress.getRegionCode(); try {
QueryWrapper<CountyEntity> countyQueryWrapper = new QueryWrapper<>(); String dataSign = KdUtils.encrypt(requestData, Constants.EXPRESS_API_KEY, "UTF-8");
countyQueryWrapper.eq("region_code", regionCode); params.put("DataSign", KdUtils.urlEncoder(dataSign, "UTF-8"));
CountyEntity county = countyService.getOne(countyQueryWrapper); } catch (Exception e) {
vo.setExpAreaName(county.getCountyName()); e.printStackTrace();
String cityRegionCode; log.error(e.getMessage());
if (regionCode.startsWith("11") || regionCode.startsWith("12") || regionCode.startsWith("31") || regionCode.startsWith("50")) {
cityRegionCode = regionCode.substring(0, 2).concat("0000");
} else {
cityRegionCode = regionCode.substring(0, 4).concat("00");
} }
QueryWrapper<CityEntity> cityQueryWrapper = new QueryWrapper<>(); params.put("DateType", "2");
cityQueryWrapper.eq("region_code", cityRegionCode); String response = HttpClientUtils.kdSendPost(Constants.EXPRESS_QUERY_URL, params);
CityEntity city = cityService.getOne(cityQueryWrapper); return JSONObject.parseObject(response, ExpressQueryResponse.class);
vo.setCityName(city.getCityName());
String provinceRegionCode = regionCode.substring(0, 2).concat("0000");
QueryWrapper<ProvinceEntity> provinceQueryWrapper = new QueryWrapper<>();
provinceQueryWrapper.eq("region_code", provinceRegionCode);
ProvinceEntity province = provinceService.getOne(provinceQueryWrapper);
vo.setProvinceName(province.getProvName());
return vo;
} }
} }

View File

@@ -6,7 +6,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.peanut.common.utils.PageUtils; import com.peanut.common.utils.PageUtils;
import com.peanut.common.utils.Query; import com.peanut.common.utils.Query;
import com.peanut.modules.book.dao.PayWechatOrderDao; import com.peanut.modules.book.dao.PayWechatOrderDao;
import com.peanut.modules.book.entity.BuyOrderEntity; import com.peanut.modules.book.entity.BuyOrder;
import com.peanut.modules.book.entity.PayWechatOrderEntity; import com.peanut.modules.book.entity.PayWechatOrderEntity;
import com.peanut.modules.book.service.BuyOrderService; import com.peanut.modules.book.service.BuyOrderService;
import com.peanut.modules.book.service.PayWechatOrderService; import com.peanut.modules.book.service.PayWechatOrderService;
@@ -35,9 +35,9 @@ public class PayWechatOrderServiceImpl extends ServiceImpl<PayWechatOrderDao, Pa
@Override @Override
public void add(String orderSn, String prepayId) { public void add(String orderSn, String prepayId) {
QueryWrapper<BuyOrderEntity> wrapper = new QueryWrapper<>(); QueryWrapper<BuyOrder> wrapper = new QueryWrapper<>();
wrapper.eq("order_sn", orderSn); wrapper.eq("order_sn", orderSn);
BuyOrderEntity buyOrder = buyOrderService.getOne(wrapper); BuyOrder buyOrder = buyOrderService.getOne(wrapper);
PayWechatOrderEntity entity = new PayWechatOrderEntity(); PayWechatOrderEntity entity = new PayWechatOrderEntity();
entity.setCustomerId(buyOrder.getUserId()); entity.setCustomerId(buyOrder.getUserId());
entity.setCreateTime(new Date()); entity.setCreateTime(new Date());

View File

@@ -1,12 +1,27 @@
package com.peanut.modules.book.vo; package com.peanut.modules.book.vo;
import com.peanut.modules.book.entity.Trace;
import lombok.Data; import lombok.Data;
import java.util.List;
/** /**
* @Description: TODO * @Description: TODO
* @Author: Cauchy * @Author: Cauchy
* @CreateTime: 2023/10/17 * @CreateTime: 2023/10/18
*/ */
@Data @Data
public class ExpressQueryResponseVo { public class ExpressQueryResponseVo {
/**
* 订单详情 ID
*/
private Long orderDetailId;
/**
* 快递单号
*/
private String LogisticCode;
/**
* 轨迹
*/
private List<Trace> Traces;
} }

View File

@@ -13,4 +13,60 @@ public class ExpressResponseOrderVo {
* 快递单号 * 快递单号
*/ */
private String LogisticCode; private String LogisticCode;
/**
* 订单号
*/
private String OrderCode;
/**
* 快递公司代码
*/
private String ShipperCode;
/**
* 大头笔(官网文档)
*/
private String MarkDestination;
/**
* 签回单单号
*/
private String SignWaybillCode;
/**
* 始发地区域编码
*/
private String OriginCode;
/**
* 事发地名称
*/
private String OriginName;
/**
* 目的地区域编码
*/
private String DestinatioCode;
/**
* 目的地名称
*/
private String DestinatioName;
/**
* 分拣编码
*/
private String SortingCode;
/**
* 邮包编码
*/
private String PackageCode;
/**
* 集包地
*/
private String PackageName;
/**
* 目的地分拨
*/
private String DestinationAllocationCentre;
/**
* 配送产品类型
*/
private String TransType;
/**
* 运输方式
*/
private String TransportType;
} }

View File

@@ -0,0 +1,40 @@
package com.peanut.modules.book.vo;
import lombok.Data;
/**
* @Description: 修改地址 Vo
* @Author: Cauchy
* @CreateTime: 2023/10/18
*/
@Data
public class ShippingAddressRequestVo {
/**
* 订单 ID
*/
private Integer orderId;
/**
* 省份
*/
private String province;
/**
* 城市
*/
private String city;
/**
* 县
*/
private String county;
/**
* 地址
*/
private String address;
/**
* 收货人姓名
*/
private String name;
/**
* 电话
*/
private String mobile;
}

View File

@@ -1,7 +1,7 @@
package com.peanut.modules.book.vo; package com.peanut.modules.book.vo;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.peanut.modules.book.entity.BuyOrderEntity; import com.peanut.modules.book.entity.BuyOrder;
import lombok.Data; import lombok.Data;
import java.util.List; import java.util.List;
@@ -32,5 +32,5 @@ public class UserOrderVo {
private String isMerge = ""; private String isMerge = "";
public List<BuyOrderEntity> orderList; public List<BuyOrder> orderList;
} }

View File

@@ -2,7 +2,7 @@ package com.peanut.modules.mq.Consumer;
import com.peanut.config.Constants; import com.peanut.config.Constants;
import com.peanut.config.DelayQueueConfig; import com.peanut.config.DelayQueueConfig;
import com.peanut.modules.book.entity.BuyOrderEntity; import com.peanut.modules.book.entity.BuyOrder;
import com.peanut.modules.book.service.BuyOrderService; import com.peanut.modules.book.service.BuyOrderService;
import org.springframework.amqp.rabbit.annotation.RabbitListener; import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -21,7 +21,7 @@ public class OrderCancelConsumer {
@RabbitListener(queues = DelayQueueConfig.ORDER_CANCEL_DEAD_LETTER_QUEUE) @RabbitListener(queues = DelayQueueConfig.ORDER_CANCEL_DEAD_LETTER_QUEUE)
public void orderConsumer(String orderId) { public void orderConsumer(String orderId) {
BuyOrderEntity buyOrder = buyOrderService.getById(orderId); BuyOrder buyOrder = buyOrderService.getById(orderId);
if(buyOrder == null){ if(buyOrder == null){
return; return;
} }

View File

@@ -13,13 +13,11 @@ import com.peanut.modules.pay.IOSPay.model.entities.IosPayOrderEntity;
import com.peanut.modules.pay.IOSPay.service.IapVerifyReceiptService; import com.peanut.modules.pay.IOSPay.service.IapVerifyReceiptService;
import com.peanut.modules.pay.IOSPay.service.OrderService; import com.peanut.modules.pay.IOSPay.service.OrderService;
import com.peanut.modules.pay.IOSPay.vo.FailureVo;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.experimental.FieldDefaults; import lombok.experimental.FieldDefaults;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.math.BigDecimal; import java.math.BigDecimal;
@@ -88,7 +86,7 @@ public class AppController {
return Result.error("凭证不能为空"); return Result.error("凭证不能为空");
IapResponseDTO receipt = iapVerifyReceiptService.verifyIapReceipt(dto.getReceiptData(), dto.isSandBox()); IapResponseDTO receipt = iapVerifyReceiptService.verifyIapReceipt(dto.getReceiptData(), dto.isSandBox());
BuyOrderEntity order2 = this.buyOrderService.getOne(new QueryWrapper<BuyOrderEntity>().eq("order_sn", dto.getOrderId()).eq("del_flag", "0")); BuyOrder order2 = this.buyOrderService.getOne(new QueryWrapper<BuyOrder>().eq("order_sn", dto.getOrderId()).eq("del_flag", "0"));
order2.setPaymentDate(new Date()); order2.setPaymentDate(new Date());

View File

@@ -1,9 +1,6 @@
package com.peanut.modules.pay.IOSPay.service; package com.peanut.modules.pay.IOSPay.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.peanut.common.utils.PageUtils; import com.peanut.common.utils.PageUtils;
import com.peanut.common.utils.R;
import com.peanut.modules.book.entity.BuyOrderEntity;
import com.peanut.modules.pay.IOSPay.model.dto.IapRequestDTO;
import com.peanut.modules.pay.IOSPay.model.entities.IosPayOrderEntity; import com.peanut.modules.pay.IOSPay.model.entities.IosPayOrderEntity;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;

View File

@@ -8,7 +8,7 @@ import com.peanut.common.utils.PageUtils;
import com.peanut.common.utils.Query; import com.peanut.common.utils.Query;
import com.peanut.modules.app.service.UserService; import com.peanut.modules.app.service.UserService;
import com.peanut.modules.book.entity.BookBuyConfigEntity; import com.peanut.modules.book.entity.BookBuyConfigEntity;
import com.peanut.modules.book.entity.BuyOrderEntity; import com.peanut.modules.book.entity.BuyOrder;
import com.peanut.modules.book.entity.MyUserEntity; import com.peanut.modules.book.entity.MyUserEntity;
import com.peanut.modules.book.service.BookBuyConfigService; import com.peanut.modules.book.service.BookBuyConfigService;
import com.peanut.modules.book.service.BuyOrderService; import com.peanut.modules.book.service.BuyOrderService;
@@ -129,7 +129,7 @@ public class OrderServiceImpl extends ServiceImpl<PayIOSOrderMapper,IosPayOrderE
BookBuyConfigEntity bookBuyConfigEntity = this.bookBuyConfigService.getById(Integer.valueOf(null == order.getProductID() ? "0" : order.getProductID())); BookBuyConfigEntity bookBuyConfigEntity = this.bookBuyConfigService.getById(Integer.valueOf(null == order.getProductID() ? "0" : order.getProductID()));
vo.setRealMoney(null == bookBuyConfigEntity ? "0" : bookBuyConfigEntity.getRealMoney()); vo.setRealMoney(null == bookBuyConfigEntity ? "0" : bookBuyConfigEntity.getRealMoney());
BuyOrderEntity orderEntity = buyOrderService.getBaseMapper().selectOne(new QueryWrapper<BuyOrderEntity>().eq("order_sn", order.getOrderid())); BuyOrder orderEntity = buyOrderService.getBaseMapper().selectOne(new QueryWrapper<BuyOrder>().eq("order_sn", order.getOrderid()));
if (null != orderEntity) { if (null != orderEntity) {
vo.setPaymentMethod(orderEntity.getPaymentMethod()); vo.setPaymentMethod(orderEntity.getPaymentMethod());
} }

View File

@@ -14,11 +14,9 @@ import com.peanut.modules.pay.alipay.config.AliPayUtil;
import com.peanut.modules.pay.alipay.dto.AlipayDTO; import com.peanut.modules.pay.alipay.dto.AlipayDTO;
import com.peanut.modules.pay.alipay.service.AliPayService; import com.peanut.modules.pay.alipay.service.AliPayService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal; import java.math.BigDecimal;
@@ -74,7 +72,7 @@ public class AliPayServiceImpl implements AliPayService {
aliNotifyDto.setCustomerid(payDto.getCustomerId()); aliNotifyDto.setCustomerid(payDto.getCustomerId());
aliNotifyDto.setRelevanceoid(payDto.getRelevanceoid()); aliNotifyDto.setRelevanceoid(payDto.getRelevanceoid());
payZfbOrderService.save(aliNotifyDto); payZfbOrderService.save(aliNotifyDto);
BuyOrderEntity order = this.buyOrderService.getOne(new QueryWrapper<BuyOrderEntity>().eq("order_sn",payDto.getRelevanceoid()).eq("del_flag","0")); BuyOrder order = this.buyOrderService.getOne(new QueryWrapper<BuyOrder>().eq("order_sn",payDto.getRelevanceoid()).eq("del_flag","0"));
order.setPaymentDate(new Date()); order.setPaymentDate(new Date());
this.buyOrderService.updateById(order); this.buyOrderService.updateById(order);
@@ -184,7 +182,7 @@ public class AliPayServiceImpl implements AliPayService {
if ("order".equals(subject)) { if ("order".equals(subject)) {
System.out.println("=====到order更新字段=================================================================================================================="); System.out.println("=====到order更新字段==================================================================================================================");
BuyOrderEntity orderEntity = buyOrderService.getBaseMapper().selectOne(new QueryWrapper<BuyOrderEntity>().eq("order_sn", oldPayZfbOrderEntity.getRelevanceoid())); BuyOrder orderEntity = buyOrderService.getBaseMapper().selectOne(new QueryWrapper<BuyOrder>().eq("order_sn", oldPayZfbOrderEntity.getRelevanceoid()));
System.out.println("======orderEntity=========="+orderEntity); System.out.println("======orderEntity=========="+orderEntity);
BigDecimal realMoney = orderEntity.getRealMoney(); BigDecimal realMoney = orderEntity.getRealMoney();
System.out.println("======realMoney=========="+realMoney); System.out.println("======realMoney=========="+realMoney);

View File

@@ -137,7 +137,7 @@ public class ApplePayServiceImpl implements ApplePayService {
//如果验证后的订单号与app端传来的订单号一致并且状态为已支付状态则处理自己的业务 //如果验证后的订单号与app端传来的订单号一致并且状态为已支付状态则处理自己的业务
if (transactionID.equals(transactionId) && "PURCHASED".equals(in_app_ownership_type)) { if (transactionID.equals(transactionId) && "PURCHASED".equals(in_app_ownership_type)) {
//===================处理自己的业务 ============================ //===================处理自己的业务 ============================
BuyOrderEntity order = this.buyOrderService.getOne(new QueryWrapper<BuyOrderEntity>().eq("order_sn", transactionId )); BuyOrder order = this.buyOrderService.getOne(new QueryWrapper<BuyOrder>().eq("order_sn", transactionId ));
PayWechatOrderEntity wechat = new PayWechatOrderEntity(); PayWechatOrderEntity wechat = new PayWechatOrderEntity();
@@ -155,7 +155,7 @@ public class ApplePayServiceImpl implements ApplePayService {
} }
if ("order".equals(order.getOrderType())) { if ("order".equals(order.getOrderType())) {
BuyOrderEntity orderEntity = buyOrderService.getBaseMapper().selectOne(new QueryWrapper<BuyOrderEntity>().eq("order_sn", wechat.getOrderId())); BuyOrder orderEntity = buyOrderService.getBaseMapper().selectOne(new QueryWrapper<BuyOrder>().eq("order_sn", wechat.getOrderId()));
BigDecimal realMoney = orderEntity.getRealMoney(); BigDecimal realMoney = orderEntity.getRealMoney();
//更新 订单 记录 //更新 订单 记录

View File

@@ -71,9 +71,9 @@ public class WeChatPayController {
@RequestMapping(value = "/placeAnOrder/shoppingPay") @RequestMapping(value = "/placeAnOrder/shoppingPay")
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public R newShoppingPay(@RequestBody WechatPaymentInfo paymentInfo) { public R newShoppingPay(@RequestBody WechatPaymentInfo paymentInfo) {
QueryWrapper<BuyOrderEntity> queryWrapper = new QueryWrapper<>(); QueryWrapper<BuyOrder> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("order_sn", paymentInfo.getOrderSn()); queryWrapper.eq("order_sn", paymentInfo.getOrderSn());
BuyOrderEntity order = buyOrderService.getOne(queryWrapper); BuyOrder order = buyOrderService.getOne(queryWrapper);
// 判断订单是否已经过期 // 判断订单是否已经过期
if (order.getOrderStatus().equals("5")) { if (order.getOrderStatus().equals("5")) {
return R.error("订单支付超时"); return R.error("订单支付超时");
@@ -121,10 +121,10 @@ public class WeChatPayController {
Map<String, Object> resourceMap = WechatPayValidator.decryptFromResource(resource, wechatPayConfig.getApiV3Key(), 1); Map<String, Object> resourceMap = WechatPayValidator.decryptFromResource(resource, wechatPayConfig.getApiV3Key(), 1);
String orderNo = resourceMap.get("out_trade_no").toString(); String orderNo = resourceMap.get("out_trade_no").toString();
// 根据订单号,做幂等处理,并且在对业务数据进行状态检查和处理之前,要采用数据锁进行并发控制,以避免函数重入造成的数据混乱 // 根据订单号,做幂等处理,并且在对业务数据进行状态检查和处理之前,要采用数据锁进行并发控制,以避免函数重入造成的数据混乱
BuyOrderEntity order = this.buyOrderService.getOne(new QueryWrapper<BuyOrderEntity>().eq("order_sn", orderNo)); BuyOrder order = this.buyOrderService.getOne(new QueryWrapper<BuyOrder>().eq("order_sn", orderNo));
// 1.根据订单id获取订单信息 // 1.根据订单id获取订单信息
if ("order".equals(order.getOrderType())) { if ("order".equals(order.getOrderType())) {
BuyOrderEntity orderEntity = buyOrderService.getBaseMapper().selectOne(new QueryWrapper<BuyOrderEntity>().eq("order_sn", orderNo)); BuyOrder orderEntity = buyOrderService.getBaseMapper().selectOne(new QueryWrapper<BuyOrder>().eq("order_sn", orderNo));
BigDecimal realMoney = orderEntity.getRealMoney(); BigDecimal realMoney = orderEntity.getRealMoney();
// 查询订单的所有 book_id // 查询订单的所有 book_id
List<Integer> orderBookIdList = shopProductBookService.getOrderBookId(order.getOrderSn()); List<Integer> orderBookIdList = shopProductBookService.getOrderBookId(order.getOrderSn());

View File

@@ -4,7 +4,7 @@
<mapper namespace="com.peanut.modules.book.dao.BuyOrderDao"> <mapper namespace="com.peanut.modules.book.dao.BuyOrderDao">
<!-- 可根据自己的需求,是否要使用 --> <!-- 可根据自己的需求,是否要使用 -->
<resultMap type="com.peanut.modules.book.entity.BuyOrderEntity" id="buyOrderMap"> <resultMap type="com.peanut.modules.book.entity.BuyOrder" id="buyOrderMap">
<result property="orderId" column="order_id" /> <result property="orderId" column="order_id" />
<result property="orderSn" column="order_sn" /> <result property="orderSn" column="order_sn" />
<result property="userId" column="user_id" /> <result property="userId" column="user_id" />
@@ -51,7 +51,7 @@
<!-- </resultMap>--> <!-- </resultMap>-->
<select id="queryListByOrderIds" resultType="com.peanut.modules.book.entity.BuyOrderEntity"> <select id="queryListByOrderIds" resultType="com.peanut.modules.book.entity.BuyOrder">
select select
*, *,
buy_order_detail.order_id, buy_order_detail.order_id,