Files
nuttyreading-java/src/main/java/com/peanut/modules/book/controller/BuyOrderController.java
yc13649764453 0b193caa03 -- 新版提交
2023-09-09 13:51:35 +08:00

837 lines
34 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package com.peanut.modules.book.controller;
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.peanut.modules.book.entity.*;
import com.peanut.modules.book.service.*;
import lombok.extern.slf4j.Slf4j;
import lombok.var;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.peanut.common.utils.PageUtils;
import com.peanut.common.utils.R;
/**
* 订单表
*
* @author yl
* @email yl328572838@163.com
* @date 2022-08-29 15:27:44
*/
@Slf4j
@RestController
@RequestMapping("book/buyorder")
public class BuyOrderController {
@Autowired
private BuyOrderService buyOrderService;
@Autowired
private ShopProductService shopProductService;
@Autowired
private BuyOrderDetailService buyOrderDetailService;
@Autowired
private CouponService couponService;
@Autowired
private CouponHistoryService couponHistoryService;
@Autowired
private OrderCartService orderCartService;
@Autowired
private MyUserService myUserService;
@Autowired
private TransactionDetailsService transactionDetailsService;
@Autowired
private AuthorService authorService;
@Autowired
private UserEbookBuyService userEbookBuyService;
@Autowired
private BookService bookService;
@Autowired
private BookShelfService bookShelfService;
@Autowired
private UserRecordService userRecordService;
@Autowired
private UserFollowUpService userFollowUpService;
@Autowired
private PayWechatOrderService payWechatOrderService;
@Autowired
private PayZfbOrderService payZfbOrderService;
// @Autowired
// private
/**
* 列表
*/
@RequestMapping("/list")
// @RequiresPermissions("book:buyorder:list")
public R list(@RequestParam Map<String, Object> params) throws Exception {
if("all".equals(params.get("orderStatus"))){
params.remove("orderStatus");
}
PageUtils page = buyOrderService.queryPage(params);
return R.ok().put("page", page);
}
/**
*
* @param params
* @return 听书未购买页面展示
* (销量最多的书,最先放最前面展示。最新上线的书,预售的书,放最前面展示
* @throws Exception
*/
@RequestMapping("/lists")
// @RequiresPermissions("book:buyorder:list")
public R lists(@RequestParam Map<String, Object> params) throws Exception {
if("all".equals(params.get("orderStatus"))){
params.remove("orderStatus");
}
PageUtils page = buyOrderService.queryPages(params);
return R.ok().put("page", page);
}
/**
* 信息
*/
@RequestMapping("/info/{orderId}")
// @RequiresPermissions("book:buyorder:info")
public R info(@PathVariable("orderId") Integer orderId){
BuyOrderEntity buyOrder = buyOrderService.getById(orderId);
return R.ok().put("buyOrder", buyOrder);
}
/**
* 保存
*/
@RequestMapping("/save")
@Transactional
// @RequiresPermissions("book:buyorder:save")
public R save(@RequestBody BuyOrderEntity buyOrder){
BigDecimal realMoney = new BigDecimal(0);
Lock l = new ReentrantLock();
l.lock();
try {
List<BuyOrderDetailEntity> products = buyOrder.getProducts();
BigDecimal bigDecimal1 = new BigDecimal(0);
ArrayList<BuyOrderDetailEntity> list = new ArrayList<>();
// 遍历商品 查询价格
for (BuyOrderDetailEntity buyOrderDetail : products) {
BuyOrderDetailEntity buyOrderDetailEntity = new BuyOrderDetailEntity();
Integer productId = buyOrderDetail.getProductId();
ShopProductEntity product = shopProductService.getById(productId);
BigDecimal price = product.getPrice();
Integer quantity = buyOrderDetail.getQuantity();
BigDecimal bigDecimal = new BigDecimal(price.doubleValue() * quantity);
bigDecimal1 = bigDecimal1.add(bigDecimal);
if (product.getProductStock() - buyOrderDetail.getQuantity() < 0 ){
return R.error(500,"库存不足");
}
// 改写 商品库存
product.setProductStock(product.getProductStock() - buyOrderDetail.getQuantity());
product.setSumSales(product.getSumSales() + buyOrderDetail.getQuantity());
shopProductService.updateById(product);
BeanUtils.copyProperties(buyOrderDetail,buyOrderDetailEntity);
buyOrderDetailEntity.setProductName(product.getProductName());
buyOrderDetailEntity.setProductPrice(product.getPrice());
buyOrderDetailEntity.setAddressId(buyOrder.getAddressId());
buyOrderDetailEntity.setProductUrl(product.getProductImages());
System.out.println(buyOrder.getAddressId());
buyOrderDetailEntity.setOrderStatus("0");
list.add(buyOrderDetailEntity);
}
Integer couponId = buyOrder.getCouponId();
if (couponId != null) {
CouponHistoryEntity byId = couponHistoryService.getById(couponId);
CouponEntity coupon = couponService.getById(byId.getCouponId());
BigDecimal amount = coupon.getCouponAmount();
bigDecimal1 = bigDecimal1.subtract(amount);
}
if (buyOrder.getShippingMoney() != null) {
bigDecimal1 = bigDecimal1.add(buyOrder.getShippingMoney());
}
// 减去优惠券金额
realMoney = buyOrder.getRealMoney();
if (bigDecimal1.compareTo(realMoney) == 0) {
//特定格式的时间ID
String timeId = IdWorker.getTimeId().substring(0,32);
buyOrder.setOrderSn(timeId);
if("4".equals(buyOrder.getPaymentMethod())){
buyOrder.setOrderStatus("1");
}
//todo 增加结束时间
buyOrder.setPaymentDate(new Date());
buyOrderService.save(buyOrder);
for (BuyOrderDetailEntity buyOrderDetailEntity : list) {
buyOrderDetailEntity.setOrderId(buyOrder.getOrderId());
buyOrderDetailEntity.setUserId(buyOrder.getUserId());
// 判断结算状态 下单 位置 0- 商品页直接下单 1- 购物车结算
String buyType = buyOrder.getBuyType();
if (buyType.equals("1")) {
// 更改购物车 状态
List<OrderCartEntity> list1 = orderCartService.getBaseMapper().selectList(new QueryWrapper<OrderCartEntity>()
.eq("user_id", buyOrder.getUserId()).eq("product_id", buyOrderDetailEntity.getProductId()));
if (list1.size() > 0){
List<Integer> collect = list1.stream().map(orderCartEntity -> {
Integer cartId = orderCartEntity.getCartId();
return cartId;
}).collect(Collectors.toList());
orderCartService.removeByIds(collect);
}
}
}
buyOrderDetailService.saveBatch(list);
if(couponId!=null){
//更改优惠券状态
CouponHistoryEntity one = couponHistoryService.getById(couponId);
one.setUseStatus(1);
one.setUseTime(new Date());
one.setOrderId(Long.valueOf(buyOrder.getOrderId()));
one.setOrderSn(buyOrder.getOrderSn());
couponHistoryService.updateById(one);
}
if("4".equals(buyOrder.getPaymentMethod())){
MyUserEntity user = this.myUserService.getById(buyOrder.getUserId());
if(user.getPeanutCoin().compareTo(realMoney) >= 0){
user.setPeanutCoin(user.getPeanutCoin().subtract(realMoney));
this.myUserService.updateById(user);
// 添加消费信息
TransactionDetailsEntity transactionDetailsEntity = new TransactionDetailsEntity();
transactionDetailsEntity.setRemark("购买健康超市用品!订单编号为《 "+ buyOrder.getOrderSn() + "");
transactionDetailsEntity.setUserId(user.getId());
transactionDetailsEntity.setUserName(user.getNickname());
transactionDetailsEntity.setChangeAmount(realMoney.negate());
transactionDetailsEntity.setUserBalance(user.getPeanutCoin());
transactionDetailsEntity.setTel(user.getTel());
transactionDetailsEntity.setOrderType("购买健康超市用品!");
transactionDetailsService.save(transactionDetailsEntity);
}else{
return R.error("余额不足!");
}
}
}
}catch (Exception e){
e.printStackTrace();
}finally {
l.unlock();
}
return R.ok().put("orderSn",buyOrder.getOrderSn()).put("money",realMoney);
}
/**
* 修改购买书籍(赠送电子书,加鉴权)
* @param buyOrder 订单表
* @return
*/
@RequestMapping("/buysave")
@Transactional
public R buysave(@RequestBody BuyOrderEntity buyOrder) {
BigDecimal realMoney = new BigDecimal(0);
Lock l = new ReentrantLock();
l.lock();
try {
List<BuyOrderDetailEntity> products = buyOrder.getProducts();
BigDecimal bigDecimal1 = new BigDecimal(0);
ArrayList<BuyOrderDetailEntity> list = new ArrayList<>();
// 遍历商品 查询价格
for (BuyOrderDetailEntity buyOrderDetail : products) {
BuyOrderDetailEntity buyOrderDetailEntity = new BuyOrderDetailEntity();
Integer productId = buyOrderDetail.getProductId();
ShopProductEntity product = shopProductService.getById(productId);
BigDecimal price = product.getPrice();
Integer quantity = buyOrderDetail.getQuantity();
//价格*数量 = 单价*购买数量赋值给bigDecimal1
BigDecimal bigDecimal = new BigDecimal(price.doubleValue() * quantity);
bigDecimal1 = bigDecimal1.add(bigDecimal);
if (product.getProductStock() - buyOrderDetail.getQuantity() < 0) {
return R.error(500, "库存不足");
}
// 改写 商品库存
product.setProductStock(product.getProductStock() - buyOrderDetail.getQuantity());
product.setSumSales(product.getSumSales() + buyOrderDetail.getQuantity());
shopProductService.updateById(product);
//buyOrderDetail 对象中的属性值复制到 buyOrderDetailEntity 对象中的属性值中
BeanUtils.copyProperties(buyOrderDetail, buyOrderDetailEntity);
buyOrderDetailEntity.setProductName(product.getProductName());
buyOrderDetailEntity.setProductPrice(product.getPrice());
buyOrderDetailEntity.setAddressId(buyOrder.getAddressId());
buyOrderDetailEntity.setProductUrl(product.getProductImages());
buyOrderDetailEntity.setOrderStatus("0");
list.add(buyOrderDetailEntity);
}
//优惠券Id couponId
Integer couponId = buyOrder.getCouponId();
if (couponId != null) {
CouponHistoryEntity byId = couponHistoryService.getById(couponId);
CouponEntity coupon = couponService.getById(byId.getCouponId());
BigDecimal amount = coupon.getCouponAmount();
bigDecimal1 = bigDecimal1.subtract(amount);
}
if (buyOrder.getShippingMoney() != null) {
bigDecimal1 = bigDecimal1.add(buyOrder.getShippingMoney());
}
// 减去优惠券金额
realMoney = buyOrder.getRealMoney();
if (bigDecimal1.compareTo(realMoney) == 0) {
//特定格式的时间ID
String timeId = IdWorker.getTimeId().substring(0, 32);
buyOrder.setOrderSn(timeId);
if ("4".equals(buyOrder.getPaymentMethod())) {
buyOrder.setOrderStatus("1");
}
//todo 增加结束时间
buyOrder.setPaymentDate(new Date());
buyOrderService.save(buyOrder);
for (BuyOrderDetailEntity buyetailEntity : list) {
buyetailEntity.setOrderId(buyOrder.getOrderId());
buyetailEntity.setUserId(buyOrder.getUserId());
// 判断结算状态 下单 位置 0- 商品页直接下单 1- 购物车结算
String buyType = buyOrder.getBuyType();
if (buyType.equals("1")) {
// 更改购物车 状态
List<OrderCartEntity> list1 = orderCartService.getBaseMapper().selectList(new QueryWrapper<OrderCartEntity>()
.eq("user_id", buyOrder.getUserId()).eq("product_id", buyetailEntity.getProductId()));
//将购物车列表转换为流,并从中提取每个购物车的 cartId。removeByIds() 方法从数据库中删除这些购物车记录。
if (list1.size() > 0) {
List<Integer> collect = list1.stream().map(orderCartEntity -> {
Integer cartId = orderCartEntity.getCartId();
return cartId;
}).collect(Collectors.toList());
orderCartService.removeByIds(collect);
}
}
}
buyOrderDetailService.saveBatch(list);
if (couponId != null) {
//更改优惠券状态
CouponHistoryEntity one = couponHistoryService.getById(couponId);
one.setUseStatus(1);
one.setUseTime(new Date());
one.setOrderId(Long.valueOf(buyOrder.getOrderId()));
one.setOrderSn(buyOrder.getOrderSn());
couponHistoryService.updateById(one);
}
// 购买书籍直接赠送电子书听书
TransactionDetailsEntity transaction = new TransactionDetailsEntity();
//避免重复购买
TransactionDetailsEntity entity = transactionDetailsService.getBaseMapper().selectOne(new QueryWrapper<TransactionDetailsEntity>().eq("user_id", transaction.getUserId())
.eq("relation_id", transaction.getRelationId()));
if (entity != null) {
return R.error("余额不足,请充值!!!!!!!!!!!!!!!!");
}
List<BuyOrderDetailEntity> produ = buyOrder.getProducts();
// 遍历商品 查询价格
for (BuyOrderDetailEntity buyOrdr : produ) {
Integer pId = buyOrdr.getProductId();
ShopProductEntity product1 = shopProductService.getById(pId);
// 如果是虚拟币购买 减少用户的虚拟币数量
if ("4".equals(buyOrder.getPaymentMethod())) {
MyUserEntity user = this.myUserService.getById(buyOrder.getUserId());
if (user.getPeanutCoin().compareTo(realMoney) >= 0) {
user.setPeanutCoin(user.getPeanutCoin().subtract(realMoney));
this.myUserService.updateById(user);
// 添加消费信息
TransactionDetailsEntity transactionDetailsEntity = new TransactionDetailsEntity();
transactionDetailsEntity.setRemark("购买健康超市用品!订单编号为《 " + buyOrder.getOrderSn() + "");
transactionDetailsEntity.setUserId(user.getId());
transactionDetailsEntity.setUserName(user.getNickname());
transactionDetailsEntity.setChangeAmount(realMoney.negate());
transactionDetailsEntity.setUserBalance(user.getPeanutCoin());
transactionDetailsEntity.setTel(user.getTel());
transactionDetailsEntity.setOrderType("赠送本书听书图书");
transactionDetailsService.save(transactionDetailsEntity);
} else {
return R.error("余额不足!");
}
}
}
// }
for (BuyOrderDetailEntity buyOrderDetail : products) {
Integer productId = buyOrderDetail.getProductId();
ShopProductEntity product = shopProductService.getById(productId);
// 如果不等于空 则进行往下走
String authorName = "";
String bookId = product.getBookId();
if(null != bookId && !"".equals(bookId)){
List<String> bkids = new ArrayList<String>();
if(bookId.indexOf(",") == -1){
bkids.add(bookId);
}else {
for(String idObj : bookId.split(",")){
bkids.add(idObj);
}
}
for(String b_id : bkids){
if (b_id != null) {
List<BookEntity> book = bookService.getBaseMapper().selectList(new QueryWrapper<BookEntity>().eq("id", b_id));
for (BookEntity bo : book) {
Integer id = bo.getId();
String name = bo.getName();
String images = bo.getImages();
String authorId = bo.getAuthorId();
if (book != null) {
UserEbookBuyEntity userEbookBuyEntity = new UserEbookBuyEntity();
userEbookBuyEntity.setUserId(Integer.valueOf(buyOrder.getUserId()));
userEbookBuyEntity.setBookId(Integer.valueOf(id));
String[] authorIds = authorId.split(",");
List<String> authorList = Arrays.asList(authorIds);
List<AuthorEntity> authorEntities = authorService.getBaseMapper().selectList(new QueryWrapper<AuthorEntity>().in("id", authorList));
//购买书籍表 userId bookName 商品订单详情表 userId productName
List<UserEbookBuyEntity> userId = userEbookBuyService.getBaseMapper().selectList(new QueryWrapper<UserEbookBuyEntity>()
.eq("user_Id", buyOrder.getUserId())
.eq("book_id", id));
for (AuthorEntity authorEntity : authorEntities) {
authorName += "," + authorEntity.getAuthorName();
}
//查询dengyu则往下执行赠送电子书详情
if (userId != null && !userId.isEmpty()) {
// 如果userId不等于空则不赠送图书不执行任何方法
// return R.ok("此书已存在于您的书架");
} else {
authorName = authorName.startsWith(",") ? authorName.substring(1) : authorName;
userEbookBuyEntity.setAuthor(authorName);
userEbookBuyEntity.setImage(images);
userEbookBuyEntity.setPayStatus("赠送成功");
//这里后期需要修改字段内容
userEbookBuyEntity.setPayType("point");
userEbookBuyEntity.setPayTime(new Date());
userEbookBuyEntity.setBookName(name);
userEbookBuyService.save(userEbookBuyEntity);
//判断是否加入书架如果没有就加入听书书架
Integer integer = bookShelfService.getBaseMapper().selectCount(new QueryWrapper<BookShelfEntity>()
.eq("book_id", id)
.eq("user_id", userId));
//如果integer<0代表数据库没有这条数据则添加有就不执行下面操作
if (integer < 0) {
//保存到书架表中
BookShelfEntity bookShelfEntity = new BookShelfEntity();
bookShelfEntity.setBookId(id);
bookShelfEntity.setBookName(name);
bookShelfEntity.setUserId(buyOrder.getUserId());
bookShelfEntity.setCreateTime(new Date());
bookShelfService.save(bookShelfEntity);
}
// }
// else {
// return R.error().put("赠送失败",buyOrder.getOrderSn());
// }
}
}
}
}
}
}
}
}
}catch (Exception e){
e.printStackTrace();
}finally {
l.unlock();
}
return R.ok().put("orderSn",buyOrder.getOrderSn()).put("money",realMoney);
}
/**
* 修改
*/
@RequestMapping("/update")
// @RequiresPermissions("book:buyorder:update")
public R update(@RequestBody BuyOrderEntity buyOrder){
buyOrderService.updateById(buyOrder);
return R.ok();
}
/**
* 删除
*/
@RequestMapping("/delete")
// @RequiresPermissions("book:buyorder:delete")
public R delete(@RequestBody Integer[] orderIds){
buyOrderService.removeByIds(Arrays.asList(orderIds));
return R.ok();
}
/**
* 列表
*/
@RequestMapping("/appUserGetlist")
// @RequiresPermissions("book:buyorder:list")
public R appUserGetlist(@RequestParam Map<String, Object> params){
PageUtils page = buyOrderService.queryPage1(params);
return R.ok().put("page", page);
}
/**
* app 端 取消订单
*/
@RequestMapping("/appDelete")
// @RequiresPermissions("book:buyorder:delete")
@Transactional
public R appDelete(@RequestParam("orderId") Integer orderId){
//1. 判断订单状态
BuyOrderEntity byId = buyOrderService.getById(orderId);
if (byId != null) {
//2. 判断当前订单是否存在优惠券 进行 回显
Integer couponId = byId.getCouponId();
if (couponId != null) {
CouponHistoryEntity byId1 = couponHistoryService.getById(couponId);
byId1.setUseStatus(0);
couponHistoryService.updateById(byId1);
}
// 库存回滚
List<BuyOrderDetailEntity> buyOrderDetailEntities = buyOrderDetailService.getBaseMapper().selectList(new QueryWrapper<BuyOrderDetailEntity>()
.eq("order_id", byId.getOrderId()));
for (BuyOrderDetailEntity buyOrderDetailEntity : buyOrderDetailEntities) {
Integer productId = buyOrderDetailEntity.getProductId();
ShopProductEntity product = shopProductService.getById(productId);
product.setProductStock(product.getProductStock() + buyOrderDetailEntity.getQuantity());
shopProductService.updateById(product);
}
// //3. 恢复当前订单 的 购物车商品
//
// List<BuyOrderDetailEntity> products = buyOrderDetailService.getBaseMapper().selectList(new QueryWrapper<BuyOrderDetailEntity>()
// .eq("order_id", orderId));
//
// for (BuyOrderDetailEntity product : products) {
//
// Integer productId = product.getProductId();
//
// OrderCartEntity byId1 = orderCartService.getDeteleOrderCarts(byId.getUserId(),productId);
//
// byId1.setDelFlag(0);
//
// orderCartService.updateById(byId1);
//
// }
buyOrderService.removeById(orderId);
}
return R.ok();
}
@RequestMapping("/randomOrderCode")
@Transactional
public R randomOrderCode(@RequestBody BuyOrderEntity buyOrder){
// String re= String.valueOf(buyOrderService.randomOrderCode(buyOrder));
// buyOrderService.save(re);
return R.ok();
}
/**
* 充值专用订单生成接口
*/
@RequestMapping("/rechargeSave")
@Transactional
public R rechargeSave(@RequestBody BuyOrderEntity buyOrder){
String timeId = IdWorker.getTimeId().substring(0,32);
buyOrder.setOrderSn(timeId);
buyOrderService.save(buyOrder);
return R.ok().put("orderSn",timeId);
}
/**
* 信息
*/
@RequestMapping("/appGetOrderInfo/{type}")
// @RequiresPermissions("book:buyorder:info") 就是这个
public R appGetOrderInfo(@PathVariable String type , @RequestParam("orderId") Integer orderId){
BuyOrderEntity buyOrder = buyOrderService.getById(orderId);
List<BuyOrderDetailEntity> orderDetail = null;
if("1".equals(type)){
orderDetail = buyOrderDetailService.getBaseMapper().selectList(new QueryWrapper<BuyOrderDetailEntity>()
.eq("order_id", orderId));
}else{
orderDetail = buyOrderDetailService.getBaseMapper().selectList(new QueryWrapper<BuyOrderDetailEntity>()
.eq("order_id", orderId).groupBy("shipping_sn"));
}
for (BuyOrderDetailEntity buyOrderDetailEntity : orderDetail) {
ShopProductEntity prod = shopProductService.getById(buyOrderDetailEntity.getProductId());
buyOrderDetailEntity.setImage(prod.getProductImages());
}
List<BuyOrderDetailEntity> resultOrder = new ArrayList<BuyOrderDetailEntity>();
Set<String> sn_no = new HashSet<String>();
for(BuyOrderDetailEntity buyOrderDetailEntity : orderDetail){
resultOrder.add(buyOrderDetailEntity);
sn_no.add(buyOrderDetailEntity.getShippingSn());
}
UserRecordEntity userRecordEntity = userRecordService.getBaseMapper().selectOne(new QueryWrapper<UserRecordEntity>()
.eq("orderSn", buyOrder.getOrderSn())
.eq("userid", buyOrder.getUserId())
.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);
}
/**
* 计算快递费用
*/
@RequestMapping("/getTransPrice/{area}")
public R getTransPrice(@PathVariable String area, @RequestParam Map<String, Object> productMap){
Map<String,Object> params = new HashMap<>();
params.put("kdCode","YD");
params.put("area",area);
int price = this.buyOrderService.getProductGoodsType(params,productMap);
return R.ok().put("price", price);
}
/**
* 后台发货按钮
* @Param shipperCode 快递公司编码
* @Param sendType 0订单列表发货 1商品列表发货
* @Param type 合并发货/拆分发货
* @Param ids 订单id串
*/
@RequestMapping("/delivery/{shipperCode}")
public R delivery(@PathVariable("shipperCode") String shipperCode,@RequestParam("shipperName") String shipperName, @RequestBody Integer[] ids){
buyOrderService.sendFMS(ids,shipperCode,shipperName);
return R.ok();
}
/**
* 及时查询快递信息
*/
@RequestMapping("/queryFMS")
public R queryFMS(@RequestParam Map< String,String> params){
List<BuyOrderDetailEntity> detailList = this.buyOrderDetailService.getBaseMapper().selectList(new QueryWrapper<BuyOrderDetailEntity>().eq("order_id", params.get("orderId")));
List<JSONObject> jsonList = new ArrayList<>();
JSONObject jsonObj =null;
for (BuyOrderDetailEntity detail : detailList) {
jsonObj = buyOrderService.queryFMS(detail.getShipperCode(), detail.getShippingSn());
if(Objects.isNull(jsonObj)){
return R.ok("暂未查到物流信息!");
}
jsonObj.put("ShipperName",detail.getShipperName());
jsonList.add(jsonObj);
}
return R.ok().put("rntStr",jsonList);
}
/**
* 检查可合并的订单信息
* @return
*/
@RequestMapping("/checkOrder")
public R checkOrder(@RequestParam Map<String, Object> params){
Page page = buyOrderService.checkOrder(params);
return R.ok().put("page",page);
}
/**
*
* 检查传来的orderId 是否有可合并的其他订单信息
*
* @param orderIds
* @return
*/
@RequestMapping("/checkMerge")
public R checkMerge(@RequestBody Integer[] orderIds){
List list = buyOrderService.checkOrder(orderIds);
return R.ok().put("list",list);
}
/**
*
* 批量发货功能
*
* @param orderDetailIds 订单详情
* @return
*/
@RequestMapping("/blendSendFMS/{shipperCode}")
public R blendSendFMS(@PathVariable("shipperCode") String shipperCode,@RequestParam("shipperName") String shipperName,@RequestBody Integer[] orderDetailIds){
buyOrderService.blendSendFMS(orderDetailIds,shipperCode,shipperName);
return R.ok();
}
/**
* 后台取消订单接口
*/
@RequestMapping("/cancelFMS")
public R cancelFMS(@RequestParam Map<String,Object> params){
buyOrderService.cancelFMS(params.get("orderSn").toString(), params.get("shipperCode").toString(),
params.get("expNo").toString());
// return R.ok()
return R.ok().put("paramsTEXT",params);
}
/**
* 去重查询可打印面单
*
* @param params
* @return
*/
@RequestMapping("/querySheetPage")
public R querySheetPage(@RequestParam Map<String, Object> params){
PageUtils page = buyOrderDetailService.querySheet(params);
return R.ok().put("page", page);
}
}