package com.sinata.rest.modular.mall.controller;
|
|
import cn.hutool.core.date.DateUtil;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.sinata.common.enums.EnumIsDelete;
|
import com.sinata.common.enums.mall.EnumMallOrderState;
|
import com.sinata.common.util.QRCodeUtils;
|
import com.sinata.rest.common.ApiUtils;
|
import com.sinata.rest.modular.auth.util.ThreadPoolUtil;
|
import com.sinata.rest.modular.mall.controller.body.BodyMallOrder;
|
import com.sinata.rest.modular.mall.controller.body.BodyMallOrderDetail;
|
import com.sinata.rest.modular.mall.controller.body.BodyOrderNo;
|
import com.sinata.rest.modular.mall.controller.vo.VoGoodsSku;
|
import com.sinata.rest.modular.mall.controller.vo.VoMallOrder;
|
import com.sinata.rest.modular.mall.controller.vo.VoMallOrderDetail;
|
import com.sinata.rest.modular.mall.controller.vo.VoMallOrderDetailGroupSpecGoods;
|
import com.sinata.rest.modular.mall.model.MallOrder;
|
import com.sinata.rest.modular.mall.model.MallOrderDetail;
|
import com.sinata.rest.modular.mall.model.MallOrderMain;
|
import com.sinata.rest.modular.mall.service.*;
|
import com.sinata.rest.modular.member.model.MemUser;
|
import com.sinata.rest.modular.member.model.MyCoupon;
|
import com.sinata.rest.modular.member.service.IMyCouponService;
|
import com.sinata.rest.modular.system.service.ISystemSetService;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParams;
|
import io.swagger.annotations.ApiOperation;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.http.ResponseEntity;
|
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.client.RestTemplate;
|
|
import javax.annotation.Resource;
|
import java.math.BigDecimal;
|
import java.util.*;
|
|
/**
|
* 订单接口
|
* @author goku
|
* @date 2023/3/11
|
*/
|
@Slf4j
|
@RestController
|
@RequestMapping("/mall/order")
|
@Api(tags = "商城-订单接口", description = "订单接口")
|
public class MallOrderController {
|
|
@Resource
|
RestTemplate restTemplate;
|
|
@Autowired
|
ISystemSetService systemSetService;
|
|
@Autowired
|
IMallOrderService orderService;
|
|
@Autowired
|
IMallOrderMainService orderMainService;
|
|
@Autowired
|
IMallOrderDetailService orderDetailService;
|
|
@Autowired
|
IMyCouponService myCouponService;
|
|
@Autowired
|
private IMallGoodsService mallGoodsService;
|
|
@Autowired
|
private IMallGoodsSkuService mallGoodsSkuService;
|
|
@Autowired
|
private IMallGroupSpecService mallGroupSpecService;
|
|
@Autowired
|
private IMallOrderDetailGroupSpecService mallOrderDetailGroupSpecService;
|
|
@GetMapping(value = "/list")
|
@ApiOperation(value = "获取订单列表", notes = "获取订单列表")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "current", value = "当前页数", defaultValue = "1", dataType = "Int", paramType = "query"),
|
@ApiImplicitParam(name = "size", value = "每页条数", defaultValue = "10", dataType = "Int", paramType = "query"),
|
@ApiImplicitParam(name = "state", value = "0 待支付 1 待使用 11 待退款 ", defaultValue = "", dataType = "Integer", paramType = "query"),
|
})
|
public List<VoMallOrder> list(Integer current, Integer size, Integer state) {
|
// 获取用户ID
|
Integer userId = ThreadPoolUtil.getUserId();
|
// 分页
|
Page page = new Page<MemUser>(current == null ? 1 : current, size == null ? 10 : size);
|
// 获取订单信息
|
List<VoMallOrder> list = orderService.getOrderByUserIdList(userId, null, state, page);
|
return list;
|
}
|
|
@GetMapping(value = "/shareOrderList")
|
@ApiOperation(value = "推广订单列表", notes = "获取订单列表")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "current", value = "当前页数", defaultValue = "1", dataType = "Int", paramType = "query"),
|
@ApiImplicitParam(name = "size", value = "每页条数", defaultValue = "10", dataType = "Int", paramType = "query"),
|
@ApiImplicitParam(name = "userId", value = "推广用户ID", defaultValue = "", dataType = "Integer", paramType = "query"),
|
})
|
public List<VoMallOrder> shareOrderList(Integer current, Integer size, Integer userId) {
|
// 分页
|
Page page = new Page<MemUser>(current == null ? 1 : current, size == null ? 10 : size);
|
// 获取订单信息
|
List<VoMallOrder> list = orderService.getOrderByUserIdList(null, userId, EnumMallOrderState.SUCCESS.index, page);
|
return list;
|
}
|
|
@GetMapping(value = "/detail")
|
@ApiOperation(value = "获取订单详细", notes = "获取订单详细", response = VoMallOrder.class)
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "orderNo", value = "订单编号", defaultValue = "1", dataType = "String", paramType = "query", required = true),
|
})
|
public ApiUtils<VoMallOrder> detail(String orderNo) {
|
VoMallOrder o = orderService.getOrderByOrderNo(orderNo);
|
if (o == null) {
|
return ApiUtils.returnNG(null, "订单信息不存在");
|
}
|
wrapperVoMallOrder(orderNo, o);
|
return ApiUtils.returnOK(o);
|
}
|
|
public VoMallOrder wrapperVoMallOrder(String orderNo, VoMallOrder voMallOrder) {
|
try {
|
voMallOrder.setOrderCode(QRCodeUtils.crateQRCode(orderNo, 200, 200));
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
List<VoMallOrderDetail> detailList = orderService.getOrderDetailByOrderNoList(orderNo);
|
for (VoMallOrderDetail od : detailList) {
|
List<VoMallOrderDetailGroupSpecGoods> voMallOrderDetailGroupSpecGoodsList = mallOrderDetailGroupSpecService.getListByOrderNo(null, od.getOrderDetailNo());
|
od.setGroupSpecGoodsList(voMallOrderDetailGroupSpecGoodsList);
|
// List<Integer> groupSpecGoodsIdList = new ArrayList<>();
|
// MallGoodsSku goodsSku = mallGoodsSkuService.getById(od.getSkuId());
|
// if (goodsSku != null && StrUtil.isNotBlank(goodsSku.getSpecIds())) {
|
// String[] specIdArray = goodsSku.getSpecIds().split(",");
|
// List<MallGroupSpec> groupSpecList = mallGroupSpecService.list(
|
// Wrappers.<MallGroupSpec>query().lambda()
|
// .in(MallGroupSpec::getId, specIdArray)
|
// );
|
// for (MallGroupSpec mallGroupSpec : groupSpecList) {
|
// groupSpecGoodsIdList.addAll(
|
// Arrays.stream(mallGroupSpec.getGoodsIds().split(",")).map(Integer::parseInt).collect(Collectors.toList())
|
// );
|
// }
|
// }
|
// if (groupSpecGoodsIdList != null && groupSpecGoodsIdList.size() > 0) {
|
// List<MallGoods> groupSpecGoodsList = mallGoodsService.list(
|
// Wrappers.<MallGoods>query().lambda()
|
// .in(MallGoods::getId, groupSpecGoodsIdList)
|
// );
|
// od.setGroupSpecGoodsList(groupSpecGoodsList);
|
// }
|
}
|
voMallOrder.setDetailList(detailList);
|
return voMallOrder;
|
}
|
|
@GetMapping(value = "/getOrderDetailGroupSpecGoods")
|
@ApiOperation(value = "获取订单套餐规格组商品列表", notes = "获取订单套餐规格组商品列表")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "orderNo", value = "订单编号", dataType = "String", paramType = "query", required = true),
|
})
|
public ApiUtils<List<VoMallOrderDetailGroupSpecGoods>> getOrderDetailGroupSpecGoods(String orderNo) {
|
return ApiUtils.returnOK(mallOrderDetailGroupSpecService.getListByOrderNo(orderNo, null));
|
}
|
|
@GetMapping(value = "/getSkuByMerchant")
|
@ApiOperation(value = "获取门店sku信息", notes = "获取门店sku信息")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "skuIds", value = "商品Sku串(逗号分隔)", dataType = "String", paramType = "query", required = true),
|
@ApiImplicitParam(name = "merchantId", value = "门店ID", defaultValue = "1", dataType = "String", paramType = "query", required = true),
|
})
|
public List<VoGoodsSku> getSkuByMerchant(String skuIds, Integer merchantId) {
|
// 查询商品SKU
|
List<VoGoodsSku> skuVoList = mallGoodsService.getGoodsBySkuIdMerchant(skuIds.split(","), merchantId);
|
return skuVoList;
|
}
|
|
@PostMapping(value = "/createOrder")
|
@ApiOperation(value = "下单", notes = "下单", response = MallOrderMain.class)
|
public Object createOrder(@RequestBody BodyMallOrder body) {
|
return orderService.createOrder(Arrays.asList(body));
|
}
|
|
@PostMapping(value = "/createOrderBatch")
|
@ApiOperation(value = "批量下单", notes = "批量下单", response = MallOrderMain.class)
|
public Object createOrderBatch(@RequestBody List<BodyMallOrder> list) {
|
return orderService.createOrder(list);
|
}
|
|
@PutMapping(value = "/cancel")
|
@ApiOperation(value = "取消订单", notes = "取消订单 返回True 或 FALSE", response = ApiUtils.class)
|
public Object cancel(@RequestBody BodyOrderNo body) {
|
return orderService.cancel(body.getOrderNo());
|
}
|
|
|
@PutMapping(value = "/refund")
|
@ApiOperation(value = "申请退款", notes = "申请退款 返回True 或 FALSE", response = ApiUtils.class)
|
public Object refund(@RequestBody BodyOrderNo body) {
|
LambdaQueryWrapper<MallOrder> queryWrapper = new LambdaQueryWrapper<>();
|
queryWrapper.eq(MallOrder::getOrderNo,body.getOrderNo());
|
MallOrder order = orderService.getOne(queryWrapper);
|
if(Objects.isNull(order)){
|
throw new IllegalArgumentException("错误的订单信息");
|
}
|
if(!order.getState().equals(EnumMallOrderState.WAIT_CHECK.index)){
|
throw new IllegalArgumentException("订单状态无法退款");
|
}
|
if(!order.getUseUserId().equals(0)){
|
throw new IllegalArgumentException("订单材料信息已经被转让");
|
}
|
LambdaQueryWrapper<MallOrderDetail> detailWrapper = new LambdaQueryWrapper<>();
|
detailWrapper.eq(MallOrderDetail::getOrderNo,body.getOrderNo());
|
detailWrapper.isNotNull(MallOrderDetail::getUseTime);
|
List<MallOrderDetail> detailList = orderDetailService.list(detailWrapper);
|
if(Objects.nonNull(detailList) && detailList.size() > 0){
|
throw new IllegalArgumentException("订单已经被核销");
|
}
|
MallOrder updateOrder = new MallOrder();
|
updateOrder.setState(EnumMallOrderState.WAIT_REFUND.index);
|
updateOrder.setApplyTime(new Date());
|
UpdateWrapper<MallOrder> updateWrapper = new UpdateWrapper<>();
|
updateWrapper.eq("order_no",body.getOrderNo());
|
updateWrapper.eq("state",EnumMallOrderState.WAIT_CHECK.index);
|
return orderService.update(updateOrder,updateWrapper);
|
}
|
|
@PutMapping(value = "/cancelRefund")
|
@ApiOperation(value = "取消退款", notes = "取消退款 返回True 或 FALSE", response = ApiUtils.class)
|
public Object cancelRefund(@RequestBody BodyOrderNo body) {
|
LambdaQueryWrapper<MallOrder> queryWrapper = new LambdaQueryWrapper<>();
|
queryWrapper.eq(MallOrder::getOrderNo,body.getOrderNo());
|
MallOrder order = orderService.getOne(queryWrapper);
|
if(Objects.isNull(order)){
|
throw new IllegalArgumentException("错误的订单信息");
|
}
|
if(!order.getState().equals(EnumMallOrderState.WAIT_REFUND.index)){
|
throw new IllegalArgumentException("订单状态无法取消退款");
|
}
|
MallOrder updateOrder = new MallOrder();
|
updateOrder.setState(EnumMallOrderState.WAIT_CHECK.index);
|
UpdateWrapper<MallOrder> updateWrapper = new UpdateWrapper<>();
|
updateWrapper.eq("order_no",body.getOrderNo());
|
updateWrapper.eq("state",EnumMallOrderState.WAIT_REFUND.index);
|
return orderService.update(updateOrder,updateWrapper);
|
}
|
|
@GetMapping(value = "/orderCoupon")
|
@ApiOperation(value = "下单可用优惠券", notes = "下单可用优惠券", response = Boolean.class)
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "userId", value = "用户Id", defaultValue = "1", dataType = "Int", paramType = "query", required = true),
|
@ApiImplicitParam(name = "goodsId", value = "商品id", defaultValue = "1", dataType = "Int", paramType = "query"),
|
@ApiImplicitParam(name = "price", value = "订单价格", defaultValue = "1", dataType = "Int", paramType = "query"),
|
@ApiImplicitParam(name = "goodsType", value = "商品类型,1普通,2黄金,3钻石", defaultValue = "1", dataType = "Int", paramType = "query", required = true),
|
})
|
public ApiUtils<List<MyCoupon>> orderCoupon(Integer userId, Integer goodsId,BigDecimal price ,Integer goodsType) {
|
//Integer userId = ThreadPoolUtil.getUserId();
|
return ApiUtils.returnOK(myCouponService.orderCoupon(userId, goodsId,goodsType, price,DateUtil.date().toString()));
|
}
|
|
|
@GetMapping(value = "/orderCouponCount")
|
@ApiOperation(value = "下单可用优惠券统计", notes = "下单可用优惠券", response = Boolean.class)
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "userId", value = "用户Id", defaultValue = "1", dataType = "Int", paramType = "query", required = true),
|
@ApiImplicitParam(name = "goodsId", value = "商品id", defaultValue = "1", dataType = "Int", paramType = "query"),
|
@ApiImplicitParam(name = "price", value = "订单价格", defaultValue = "1", dataType = "Int", paramType = "query"),
|
@ApiImplicitParam(name = "goodsType", value = "商品类型,1普通,2黄金,3钻石", defaultValue = "1", dataType = "Int", paramType = "query", required = true),
|
})
|
public ApiUtils<HashMap> orderCouponCount(Integer userId, Integer goodsId,BigDecimal price ,Integer goodsType) {
|
HashMap<String,Integer> data = new HashMap<>();
|
data.put("count",myCouponService.orderCoupon(userId, null,null,null,DateUtil.date().toString()).size());
|
data.put("canUse",myCouponService.orderCoupon(userId, goodsId,goodsType, price,DateUtil.date().toString()).size());
|
return ApiUtils.returnOK(data);
|
}
|
|
|
@DeleteMapping(value = "/delete")
|
@ApiOperation(value = "删除订单", notes = "删除订单 返回True 或 FALSE", response = ApiUtils.class)
|
public Object delete(@RequestBody BodyOrderNo body) {
|
MallOrder order = orderService.getById(body.getOrderNo());
|
if(order != null && order.getState() == EnumMallOrderState.CANCEL.index) {
|
// 删除订单
|
order.setIsDelete(EnumIsDelete.DELETED.index);
|
orderService.updateById(order);
|
return ApiUtils.returnOK();
|
}
|
return ApiUtils.returnNG();
|
}
|
|
|
// @PostMapping(value = "/test_createOrder")
|
// @ApiOperation(value = "测试-下单", notes = "下单", response = ApiUtils.class)
|
public Object test_createOrder() {
|
List<BodyMallOrder> list = new ArrayList<>();
|
BodyMallOrder o = new BodyMallOrder();
|
o.setMerchantId(1);
|
o.setTakeName("悟空");
|
o.setPhone("1980000000");
|
o.setIdCard("111111111111111111111111");
|
|
List<BodyMallOrderDetail> skuList = new ArrayList<>();
|
BodyMallOrderDetail od = new BodyMallOrderDetail();
|
od.setSkuId(428);
|
od.setGoodsNum(10);
|
skuList.add(od);
|
|
od = new BodyMallOrderDetail();
|
od.setSkuId(437);
|
od.setGoodsNum(1);
|
skuList.add(od);
|
|
o.setSkuList(skuList);
|
list.add(o);
|
|
|
o = new BodyMallOrder();
|
o.setMerchantId(2);
|
o.setGoodsMoney(BigDecimal.TEN);
|
o.setNumber(4);
|
o.setTakeName("悟空");
|
o.setPhone("1980000000");
|
o.setIdCard("111111111111111111111111");
|
|
skuList = new ArrayList<>();
|
od = new BodyMallOrderDetail();
|
od.setSkuId(1);
|
od.setGoodsNum(1);
|
skuList.add(od);
|
|
od = new BodyMallOrderDetail();
|
od.setSkuId(2);
|
od.setGoodsNum(1);
|
skuList.add(od);
|
|
od = new BodyMallOrderDetail();
|
od.setSkuId(3);
|
od.setGoodsNum(1);
|
skuList.add(od);
|
|
od = new BodyMallOrderDetail();
|
od.setSkuId(4);
|
od.setGoodsNum(1);
|
skuList.add(od);
|
|
o.setSkuList(skuList);
|
list.add(o);
|
|
long s = System.currentTimeMillis();
|
for (int i = 0; i < 10; i++) {
|
ResponseEntity<String> stringResponseEntity = restTemplate.postForEntity("http://localhost:8321/rest/mall/order/createOrder", list, String.class);
|
}
|
long e = System.currentTimeMillis();
|
|
log.error("----" + (e - s));
|
return null;
|
}
|
|
}
|