Browse Source

对接拼团数据1

master
wangfukang 2 days ago
parent
commit
b89232b11a
  1. 52
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/MallCouponController.java
  2. 20
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/MallDeliveryOrderController.java
  3. 4
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/MallOrderController.java
  4. 7
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/ShopController.java
  5. 6
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/WechatPayController.java
  6. 9
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/dao/mapper/MallCouponMapper.java
  7. 7
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/dao/mapper/MallUserCouponMapper.java
  8. 67
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/entity/MallCoupon.java
  9. 7
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/entity/MallDeliveryOrder.java
  10. 14
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/entity/MallOrder.java
  11. 61
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/entity/MallUserCoupon.java
  12. 3
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/dto/CreateOrderDTO.java
  13. 7
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/mybatis/MallCouponService.java
  14. 3
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/mybatis/MallDeliveryOrderService.java
  15. 15
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/mybatis/MallUserCouponService.java
  16. 4
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/ShopServiceImpl.java
  17. 11
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/MallCouponServiceImpl.java
  18. 56
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/MallDeliveryOrderServiceImpl.java
  19. 41
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/MallOrderServiceImpl.java
  20. 121
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/MallUserCouponServiceImpl.java
  21. 11
      hiver-modules/hiver-mall/src/main/resources/mapper/MallCouponMapper.xml
  22. 1
      hiver-modules/hiver-mall/src/main/resources/mapper/MallDeliveryOrderMapper.xml
  23. 9
      hiver-modules/hiver-mall/src/main/resources/mapper/MallOrderMapper.xml
  24. 5
      hiver-modules/hiver-mall/src/main/resources/mapper/MallUserCouponMapper.xml
  25. 2
      hiver-modules/hiver-mall/src/main/resources/mapper/WorkerRelaPriceMapper.xml

52
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/MallCouponController.java

@ -0,0 +1,52 @@
package cc.hiver.mall.controller;
import cc.hiver.core.common.utils.ResultUtil;
import cc.hiver.core.common.vo.Result;
import cc.hiver.mall.entity.MallCoupon;
import cc.hiver.mall.entity.MallUserCoupon;
import cc.hiver.mall.service.mybatis.MallCouponService;
import cc.hiver.mall.service.mybatis.MallUserCouponService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.math.BigDecimal;
import java.util.List;
@RestController
@RequestMapping("/hiver/mall/coupon")
@Api(tags = "优惠券接口")
public class MallCouponController {
@Autowired
private MallCouponService mallCouponService;
@Autowired
private MallUserCouponService mallUserCouponService;
@PostMapping("/add")
@ApiOperation(value = "添加/发行优惠券")
public Result<Object> addCoupon(@RequestBody MallCoupon coupon) {
mallCouponService.save(coupon);
return ResultUtil.success("发行成功");
}
@PostMapping("/receive")
@ApiOperation(value = "用户领取优惠券")
public Result<Object> receiveCoupon(@RequestParam String userId, @RequestParam String couponId) {
mallUserCouponService.receiveCoupon(userId, couponId);
return ResultUtil.success("领取成功");
}
@GetMapping("/available")
@ApiOperation(value = "获取可用优惠券列表(下单时调用)")
public Result<List<MallUserCoupon>> getAvailableCoupons(
@RequestParam String userId,
@RequestParam Integer applyScene,
@RequestParam BigDecimal amount,
@RequestParam(required = false, defaultValue = "0") String merchantId,
@RequestParam(required = true) String regionId) {
return new ResultUtil<List<MallUserCoupon>>().setData(mallUserCouponService.getAvailableCoupons(userId, applyScene, amount, merchantId, regionId));
}
}

20
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/MallDeliveryOrderController.java

@ -9,6 +9,7 @@ import cc.hiver.core.entity.Worker;
import cc.hiver.core.service.WorkerService;
import cc.hiver.core.serviceimpl.JPushServiceImpl;
import cc.hiver.mall.entity.MallDeliveryOrder;
import cc.hiver.mall.entity.MallOrder;
import cc.hiver.mall.pojo.query.MallDeliveryOrderPageQuery;
import cc.hiver.mall.service.mybatis.MallDeliveryOrderService;
import cn.hutool.core.util.StrUtil;
@ -32,6 +33,8 @@ import java.util.Map;
@RequestMapping("/hiver/mall/delivery")
public class MallDeliveryOrderController {
private static final int STATUS_WAIT = -1;
@Autowired
private MallDeliveryOrderService mallDeliveryOrderService;
@ -185,6 +188,21 @@ public class MallDeliveryOrderController {
}
}
/**
* 快递跑腿下单
*/
@PostMapping("/insert")
@ApiOperation("快递跑腿下单)")
public Result<MallOrder> insert(@RequestBody MallDeliveryOrder mallDeliveryOrder) {
try {
mallDeliveryOrder.setStatus(STATUS_WAIT);
return new ResultUtil<MallOrder>().setData(mallDeliveryOrderService.insertDeliveryOrder(mallDeliveryOrder));
} catch (Exception e) {
log.error("下单失败: {}", e.getMessage(), e);
return ResultUtil.error(e.getMessage());
}
}
/**
* 配送员取货
*/
@ -194,7 +212,7 @@ public class MallDeliveryOrderController {
@RequestParam String workerId) {
try {
mallDeliveryOrderService.workerPickup(deliveryId, workerId);
//jPushService.sendPushNotification("1507bfd3f6e2c0dbc0a", "您有一笔新的订单");
jPushService.sendPushNotification("1507bfd3f6e2c0dbc0a", "您有一笔新的订单");
return ResultUtil.success("取货成功");
} catch (Exception e) {
log.error("取货失败: {}", e.getMessage(), e);

4
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/MallOrderController.java

@ -159,7 +159,7 @@ public class MallOrderController {
* 商家同意退款
*/
@PostMapping("/agreeRefund")
@ApiOperation("商家同意退款")
@ApiOperation("商家或者配送员同意退款")
public Result agreeRefund(@RequestParam String orderId) {
try {
mallOrderService.agreeRefund(orderId);
@ -174,7 +174,7 @@ public class MallOrderController {
* 商家拒绝退款
*/
@PostMapping("/rejectRefund")
@ApiOperation("商家拒绝退款")
@ApiOperation("商家或者配送员拒绝退款")
public Result rejectRefund(@RequestParam String orderId,
@RequestParam(required = false) String reason) {
try {

7
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/ShopController.java

@ -241,6 +241,13 @@ public class ShopController {
continue;
}
}
if (shop.getIsStudent() != null) {
if (!(shop.getIsStudent() == s.getIsStudent())) {
continue;
}
}
if(s.getStatus() != 1){
continue;
}

6
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/WechatPayController.java

@ -1,6 +1,7 @@
package cc.hiver.mall.controller;
import cc.hiver.mall.entity.MallOrder;
import cc.hiver.mall.service.mybatis.MallDeliveryOrderService;
import cc.hiver.mall.service.mybatis.MallOrderService;
import cc.hiver.mall.serviceimpl.UnifiedOrderService;
import cc.hiver.mall.utils.KeyUtils;
@ -37,6 +38,8 @@ import java.util.UUID;
@RequestMapping("/hiver/api/wechat/pay")
public class WechatPayController {
private static final int STATUS_PAY = 0;
private static final Logger log = LoggerFactory.getLogger(WechatPayController.class);
@Autowired
@ -48,6 +51,9 @@ public class WechatPayController {
@Autowired
private MallOrderService mallOrderService;
@Autowired
private MallDeliveryOrderService mallDeliveryOrderService;
@Autowired
private WechatPaySigner signer;

9
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/dao/mapper/MallCouponMapper.java

@ -0,0 +1,9 @@
package cc.hiver.mall.dao.mapper;
import cc.hiver.mall.entity.MallCoupon;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
public interface MallCouponMapper extends BaseMapper<MallCoupon> {
int deductStock(@Param("id") String id);
}

7
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/dao/mapper/MallUserCouponMapper.java

@ -0,0 +1,7 @@
package cc.hiver.mall.dao.mapper;
import cc.hiver.mall.entity.MallUserCoupon;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
public interface MallUserCouponMapper extends BaseMapper<MallUserCoupon> {
}

67
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/entity/MallCoupon.java

@ -0,0 +1,67 @@
package cc.hiver.mall.entity;
import cc.hiver.core.base.HiverBaseEntity;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.math.BigDecimal;
import java.util.Date;
@Data
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "优惠券模板配置表")
@TableName(value = "t_mall_coupon", autoResultMap = true)
public class MallCoupon extends HiverBaseEntity {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "优惠券名称")
private String name;
@ApiModelProperty(value = "发放方:1-平台,2-商家")
private Integer issuerType;
@ApiModelProperty(value = "发放方ID")
private String issuerId;
@ApiModelProperty(value = "适用场景:0-通用,1-外卖/买饭,2-快递/跑腿,3-二手物品交易")
private Integer applyScene;
@ApiModelProperty(value = "优惠券类型:1-满减券,2-无门槛直减券")
private Integer type;
@ApiModelProperty(value = "使用门槛金额")
private BigDecimal minAmount;
@ApiModelProperty(value = "抵扣面额")
private BigDecimal discountAmount;
@ApiModelProperty(value = "发行总数")
private Integer totalCount;
@ApiModelProperty(value = "剩余领取数量")
private Integer remainCount;
@ApiModelProperty(value = "每人最多限领张数")
private Integer limitPerUser;
@ApiModelProperty(value = "有效期类型:1-绝对时间段有效,2-领取后相对天数有效")
private Integer validType;
@ApiModelProperty(value = "有效期开始时间")
private Date validStartTime;
@ApiModelProperty(value = "有效期结束时间")
private Date validEndTime;
@ApiModelProperty(value = "自领取之日起有效天数")
private Integer validDays;
@ApiModelProperty(value = "状态:0-已下架/停发,1-发放中")
private Integer status;
@ApiModelProperty(value = "学校id")
private String regionId;
}

7
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/entity/MallDeliveryOrder.java

@ -97,5 +97,12 @@ public class MallDeliveryOrder implements Serializable {
@TableField(exist = false)
@ApiModelProperty(value = "商品信息")
private List<MallOrderGoods> goodsList;
@TableField(exist = false)
@ApiModelProperty(value = "使用的优惠券ID(提交订单时传入)")
private String userCouponId;
@Transient
@TableField(exist = false)
@ApiModelProperty(value = "优惠券抵扣金额")
private BigDecimal couponDiscountFee;
}

14
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/entity/MallOrder.java

@ -31,8 +31,10 @@ public class MallOrder implements Serializable {
private String userId;
@ApiModelProperty(value = "店铺ID")
private String shopId;
@ApiModelProperty(value = "订单类型 1:直接购买 2:拼团购买 3:面对面团 4:快递 5:跑腿 6:二手")
@ApiModelProperty(value = "订单类型 1:直接购买 2:拼团购买 3:面对面团")
private Integer orderType;
@ApiModelProperty(value = "订单类型 null:外卖 1:快递跑腿 2:二手")
private Integer otherOrder;
@ApiModelProperty(value = "配送方式 1:外卖配送 2:到店自取")
private Integer deliveryType;
@ApiModelProperty(value = "订单状态 0:待支付 1:待商家接单 10:待成团 2待配送员接单 3:待取货(配送)/待消费(自取) 4:配送中 5:已完成 6:已取消 7:待商家同意退款 8:已退款 11: 售后中 12已售后")
@ -82,4 +84,14 @@ public class MallOrder implements Serializable {
@Transient
@TableField(exist = false)
private String groupOrderIds;
@Transient
@TableField(exist = false)
@ApiModelProperty(value = "使用的优惠券ID(提交订单时传入)")
private String userCouponId;
@Transient
@TableField(exist = false)
@ApiModelProperty(value = "优惠券抵扣金额")
private BigDecimal couponDiscountFee;
}

61
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/entity/MallUserCoupon.java

@ -0,0 +1,61 @@
package cc.hiver.mall.entity;
import cc.hiver.core.base.HiverBaseEntity;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.math.BigDecimal;
import java.util.Date;
@Data
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "用户领取的优惠券明细表")
@TableName(value = "t_mall_user_coupon", autoResultMap = true)
public class MallUserCoupon extends HiverBaseEntity {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "领取用户ID")
private String userId;
@ApiModelProperty(value = "关联的优惠券模板ID")
private String couponId;
@ApiModelProperty(value = "发放方(1平台/2商家)")
private Integer issuerType;
@ApiModelProperty(value = "发放方ID")
private String issuerId;
@ApiModelProperty(value = "适用场景")
private Integer applyScene;
@ApiModelProperty(value = "使用门槛")
private BigDecimal minAmount;
@ApiModelProperty(value = "抵扣金额")
private BigDecimal discountAmount;
@ApiModelProperty(value = "状态:0-未使用,1-已挂起,2-已使用,3-已过期")
private Integer status;
@ApiModelProperty(value = "领取时间")
private Date receiveTime;
@ApiModelProperty(value = "实际可使用生效时间")
private Date validStartTime;
@ApiModelProperty(value = "实际可使用失效时间")
private Date validEndTime;
@ApiModelProperty(value = "真实核销时间")
private Date useTime;
@ApiModelProperty(value = "核销时使用的订单ID")
private String orderId;
@ApiModelProperty(value = "学校id")
private String regionId;
}

3
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/dto/CreateOrderDTO.java

@ -57,6 +57,9 @@ public class CreateOrderDTO {
@ApiModelProperty(value = "指定配送员参数(不指定则进入抢单大厅)")
private WorkerParam workerParam;
@ApiModelProperty(value = "使用的优惠券ID")
private String userCouponId;
// ===================== 内嵌类 =====================
@Data

7
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/mybatis/MallCouponService.java

@ -0,0 +1,7 @@
package cc.hiver.mall.service.mybatis;
import cc.hiver.mall.entity.MallCoupon;
import com.baomidou.mybatisplus.extension.service.IService;
public interface MallCouponService extends IService<MallCoupon> {
}

3
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/mybatis/MallDeliveryOrderService.java

@ -1,6 +1,7 @@
package cc.hiver.mall.service.mybatis;
import cc.hiver.mall.entity.MallDeliveryOrder;
import cc.hiver.mall.entity.MallOrder;
import cc.hiver.mall.pojo.query.MallDeliveryOrderPageQuery;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
@ -81,4 +82,6 @@ public interface MallDeliveryOrderService extends IService<MallDeliveryOrder> {
void reassignWorker(String deliveryId, String newWorkerId, String newWorkerName, String newWorkerPhone);
MallDeliveryOrder selectByGroupId(String orderId);
MallOrder insertDeliveryOrder(MallDeliveryOrder deliveryOrder);
}

15
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/mybatis/MallUserCouponService.java

@ -0,0 +1,15 @@
package cc.hiver.mall.service.mybatis;
import cc.hiver.mall.entity.MallUserCoupon;
import com.baomidou.mybatisplus.extension.service.IService;
import java.math.BigDecimal;
import java.util.List;
public interface MallUserCouponService extends IService<MallUserCoupon> {
void receiveCoupon(String userId, String couponId);
List<MallUserCoupon> getAvailableCoupons(String userId, Integer applyScene, BigDecimal amount, String merchantId,String regionId);
boolean lockCoupon(String userCouponId, String orderId);
boolean useCoupon(String orderId);
boolean refundCoupon(String orderId);
}

4
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/ShopServiceImpl.java

@ -112,6 +112,7 @@ public class ShopServiceImpl implements ShopService {
final Path<String> ShopNameField = root.get("shopName");
final Path<String> regionField = root.get("regionId");
final Path<String> shopAreaField = root.get("shopArea");
final Path<String> isStudentField = root.get("isStudent");
final List<Predicate> list = new ArrayList<>();
@ -148,6 +149,9 @@ public class ShopServiceImpl implements ShopService {
if (CharSequenceUtil.isNotBlank(shop.getShopArea())) {
list.add(cb.equal(shopAreaField, shop.getShopArea()));
}
if (shop.getIsStudent() != null) {
list.add(cb.equal(isStudentField, shop.getIsStudent()));
}
final Predicate[] arr = new Predicate[list.size()];

11
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/MallCouponServiceImpl.java

@ -0,0 +1,11 @@
package cc.hiver.mall.serviceimpl.mybatis;
import cc.hiver.mall.dao.mapper.MallCouponMapper;
import cc.hiver.mall.entity.MallCoupon;
import cc.hiver.mall.service.mybatis.MallCouponService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
@Service
public class MallCouponServiceImpl extends ServiceImpl<MallCouponMapper, MallCoupon> implements MallCouponService {
}

56
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/MallDeliveryOrderServiceImpl.java

@ -63,6 +63,9 @@ public class MallDeliveryOrderServiceImpl extends ServiceImpl<MallDeliveryOrderM
@Autowired
private MerchantOrderSeqUtil merchantOrderSeqUtil;
@Autowired
private cc.hiver.mall.service.mybatis.MallUserCouponService mallUserCouponService;
@Override
public IPage<MallDeliveryOrder> pageDelivery(MallDeliveryOrderPageQuery q) {
if (Boolean.TRUE.equals(q.getHallOnly())) {
@ -456,4 +459,57 @@ public class MallDeliveryOrderServiceImpl extends ServiceImpl<MallDeliveryOrderM
public MallDeliveryOrder selectByGroupId(String orderId) {
return this.baseMapper.selectByGroupId(orderId);
}
@Override
@Transactional(rollbackFor = Exception.class)
public MallOrder insertDeliveryOrder(MallDeliveryOrder deliveryOrder) {
MallOrder order = new MallOrder();
order.setRegionId(deliveryOrder.getRegionId());
Date date = new Date();
order.setCreateTime(date);
order.setDeliveryType(1);
order.setDeliveryFee(deliveryOrder.getDeliveryFee());
order.setUserId(deliveryOrder.getShopId());
order.setOtherOrder(1);
order.setStatus(0);
order.setOrderType(1);
java.math.BigDecimal finalTotal = deliveryOrder.getDeliveryFee();
java.math.BigDecimal discount = java.math.BigDecimal.ZERO;
if (StringUtils.isNotBlank(deliveryOrder.getUserCouponId())) {
cc.hiver.mall.entity.MallUserCoupon coupon = mallUserCouponService.getById(deliveryOrder.getUserCouponId());
if (coupon != null && coupon.getStatus() == 0) {
discount = coupon.getDiscountAmount();
if (discount != null) {
finalTotal = finalTotal.subtract(discount);
if (finalTotal.compareTo(java.math.BigDecimal.ZERO) < 0) {
finalTotal = java.math.BigDecimal.ZERO;
}
order.setCouponDiscountFee(discount);
order.setUserCouponId(deliveryOrder.getUserCouponId());
}
}
}
order.setTotalAmount(finalTotal);
order.setGetAreaId(deliveryOrder.getGetAreaId());
order.setPutAreaId(deliveryOrder.getPutAreaId());
order.setRemark(deliveryOrder.getRemark());
order.setReceiverAddress(deliveryOrder.getReceiverAddress());
order.setReceiverPhone(deliveryOrder.getReceiverPhone());
order.setReceiverName(deliveryOrder.getReceiverName());
order.setShopAddress(deliveryOrder.getShopAddress());
order.setShopName(deliveryOrder.getShopName());
order.setShopPhone(deliveryOrder.getShopPhone());
mallOrderService.save(order);
if (discount.compareTo(java.math.BigDecimal.ZERO) > 0) {
mallUserCouponService.lockCoupon(deliveryOrder.getUserCouponId(), order.getId());
}
deliveryOrder.setCreateTime(date);
deliveryOrder.setOrderId(order.getId());
this.baseMapper.insert(deliveryOrder);
return order;
}
}

41
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/MallOrderServiceImpl.java

@ -103,6 +103,9 @@ public class MallOrderServiceImpl extends ServiceImpl<MallOrderMapper, MallOrder
@Autowired
private cc.hiver.mall.dao.mapper.ShopMapper shopMapper;
@Autowired
private cc.hiver.mall.service.mybatis.MallUserCouponService mallUserCouponService;
// ================================================================
// 核心下单逻辑
// ================================================================
@ -190,6 +193,10 @@ public class MallOrderServiceImpl extends ServiceImpl<MallOrderMapper, MallOrder
order.setRegionId(dto.getRegionId());
this.save(order);
if (StringUtils.isNotBlank(order.getUserCouponId()) && order.getCouponDiscountFee() != null) {
mallUserCouponService.lockCoupon(order.getUserCouponId(), order.getId());
}
// 保存商品快照
saveGoodsSnapshots(goodsSnapshots, order.getId());
@ -250,6 +257,10 @@ public class MallOrderServiceImpl extends ServiceImpl<MallOrderMapper, MallOrder
order.setStatus(STATUS_WAIT_PAY);
order.setRegionId(dto.getRegionId());
this.save(order);
if (StringUtils.isNotBlank(order.getUserCouponId()) && order.getCouponDiscountFee() != null) {
mallUserCouponService.lockCoupon(order.getUserCouponId(), order.getId());
}
// 创建拼团主记录
MallOrderGroup group = new MallOrderGroup();
if(isFace2Face){
@ -359,6 +370,10 @@ public class MallOrderServiceImpl extends ServiceImpl<MallOrderMapper, MallOrder
order.setRegionId(dto.getRegionId());
this.save(order);
if (StringUtils.isNotBlank(order.getUserCouponId()) && order.getCouponDiscountFee() != null) {
mallUserCouponService.lockCoupon(order.getUserCouponId(), order.getId());
}
saveGoodsSnapshots(goodsSnapshots, order.getId());
// 更新拼团人数和成员列表
int newMembers = group.getCurrentMembers() + 1;
@ -736,7 +751,7 @@ public class MallOrderServiceImpl extends ServiceImpl<MallOrderMapper, MallOrder
if (subOrder != null && subOrder.getStatus() != STATUS_CANCELLED
&& subOrder.getStatus() != STATUS_REFUNDED) {
subOrder.setGroupOrderIds(group.getGroupOrderIds());
applyMerchantRefund(delivery.getWorkerId(),subOrder, "面对面团团长申请取消,待商家同意",refundType,refundTypeStatus);
applyMerchantRefund(delivery.getWorkerId(),subOrder, "面对面团团长申请取消",refundType,refundTypeStatus);
}
}
}
@ -771,7 +786,7 @@ public class MallOrderServiceImpl extends ServiceImpl<MallOrderMapper, MallOrder
MallDeliveryOrder delivery = findDeliveryByOrderId(order.getId());
if (delivery != null && delivery.getStatus() != null && delivery.getStatus() >= 1) {
// 配送员已接单 → 走商家或者配送员同意流程
applyMerchantRefund(delivery.getWorkerId(),order, "用户申请取消订单,待同意", refundType, refundTypeStatus);
applyMerchantRefund(delivery.getWorkerId(),order, "用户申请取消订单", refundType, refundTypeStatus);
} else {
// 未接单 → 直接取消并退款
cancelDeliveryOrderByOrderId(order.getId());
@ -917,7 +932,6 @@ public class MallOrderServiceImpl extends ServiceImpl<MallOrderMapper, MallOrder
vo.setGroupInfo(group);
}
// 售后、退款信息
if(order.getStatus() == STATUS_REFUNDED || order.getStatus() == STATUS_DONE || order.getStatus() == STATUS_WAIT_REFUND || order.getStatus() == STATUS_WAIT_RETURN || order.getStatus() == STATUS__RETURNED){
LambdaQueryWrapper<MallRefundRecord> rq = new LambdaQueryWrapper<>();
rq.eq(MallRefundRecord::getOrderId, orderId);
List<MallRefundRecord> sallRefundRecord = mallRefundRecordMapper.selectList(rq);
@ -932,7 +946,6 @@ public class MallOrderServiceImpl extends ServiceImpl<MallOrderMapper, MallOrder
});
vo.setMallRefundRecord(sallRefundRecord);
}
}
return vo;
}
@ -982,7 +995,25 @@ public class MallOrderServiceImpl extends ServiceImpl<MallOrderMapper, MallOrder
order.setGoodsAmount(goodsAmount);
order.setDeliveryFee(deliveryFee);
order.setPackageFee(packageFee);
order.setTotalAmount(goodsAmount.add(deliveryFee).add(packageFee));
java.math.BigDecimal finalTotal = goodsAmount.add(deliveryFee).add(packageFee);
java.math.BigDecimal discount = java.math.BigDecimal.ZERO;
if (StringUtils.isNotBlank(dto.getUserCouponId())) {
cc.hiver.mall.entity.MallUserCoupon coupon = mallUserCouponService.getById(dto.getUserCouponId());
if (coupon != null && coupon.getStatus() == 0) {
discount = coupon.getDiscountAmount();
if (discount != null) {
finalTotal = finalTotal.subtract(discount);
if (finalTotal.compareTo(java.math.BigDecimal.ZERO) < 0) {
finalTotal = java.math.BigDecimal.ZERO;
}
order.setCouponDiscountFee(discount);
order.setUserCouponId(dto.getUserCouponId());
}
}
}
order.setTotalAmount(finalTotal);
order.setRemark(dto.getRemark());
order.setCreateTime(new Date());

121
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/MallUserCouponServiceImpl.java

@ -0,0 +1,121 @@
package cc.hiver.mall.serviceimpl.mybatis;
import cc.hiver.core.common.exception.HiverException;
import cc.hiver.mall.dao.mapper.MallCouponMapper;
import cc.hiver.mall.dao.mapper.MallUserCouponMapper;
import cc.hiver.mall.entity.MallCoupon;
import cc.hiver.mall.entity.MallUserCoupon;
import cc.hiver.mall.service.mybatis.MallUserCouponService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
@Service
public class MallUserCouponServiceImpl extends ServiceImpl<MallUserCouponMapper, MallUserCoupon> implements MallUserCouponService {
@Autowired
private MallCouponMapper mallCouponMapper;
@Override
@Transactional(rollbackFor = Exception.class)
public void receiveCoupon(String userId, String couponId) {
MallCoupon coupon = mallCouponMapper.selectById(couponId);
if (coupon == null || coupon.getStatus() != 1) {
throw new HiverException("优惠券不存在或已下架");
}
// 检查限领
QueryWrapper<MallUserCoupon> checkQr = new QueryWrapper<>();
checkQr.eq("user_id", userId).eq("coupon_id", couponId);
if (this.count(checkQr) >= coupon.getLimitPerUser()) {
throw new HiverException("您已达到该优惠券领取上限");
}
// 扣库存
if (coupon.getTotalCount() != -1) {
int row = mallCouponMapper.deductStock(couponId);
if (row <= 0) {
throw new HiverException("优惠券已被抢光");
}
}
// 发放
MallUserCoupon userCoupon = new MallUserCoupon();
userCoupon.setUserId(userId);
userCoupon.setCouponId(couponId);
userCoupon.setIssuerType(coupon.getIssuerType());
userCoupon.setIssuerId(coupon.getIssuerId());
userCoupon.setApplyScene(coupon.getApplyScene());
userCoupon.setMinAmount(coupon.getMinAmount());
userCoupon.setDiscountAmount(coupon.getDiscountAmount());
userCoupon.setStatus(0);
userCoupon.setReceiveTime(new Date());
// 计算有效期
if (coupon.getValidType() == 1) {
userCoupon.setValidStartTime(coupon.getValidStartTime());
userCoupon.setValidEndTime(coupon.getValidEndTime());
} else {
userCoupon.setValidStartTime(new Date());
long end = System.currentTimeMillis() + (long) coupon.getValidDays() * 24 * 3600 * 1000;
userCoupon.setValidEndTime(new Date(end));
}
this.save(userCoupon);
}
@Override
public List<MallUserCoupon> getAvailableCoupons(String userId, Integer applyScene, BigDecimal amount, String merchantId,String regionId) {
QueryWrapper<MallUserCoupon> qw = new QueryWrapper<>();
qw.eq("user_id", userId).eq("region_id", regionId)
.eq("status", 0)
.le("valid_start_time", new Date())
.ge("valid_end_time", new Date())
.le("min_amount", amount);
// 场景兼容
qw.and(wrapper -> wrapper.eq("apply_scene", 0).or().eq("apply_scene", applyScene));
// 商家兼容
if (merchantId != null && !merchantId.equals("0")) {
qw.and(wrapper -> wrapper.eq("issuer_type", 1).or().eq("issuer_id", merchantId));
}
return this.list(qw);
}
@Override
public boolean lockCoupon(String userCouponId, String orderId) {
UpdateWrapper<MallUserCoupon> uw = new UpdateWrapper<>();
uw.eq("id", userCouponId).eq("status", 0)
.set("status", 1)
.set("order_id", orderId);
return this.update(uw);
}
@Override
public boolean useCoupon(String orderId) {
UpdateWrapper<MallUserCoupon> uw = new UpdateWrapper<>();
uw.eq("order_id", orderId).eq("status", 1)
.set("status", 2)
.set("use_time", new Date());
return this.update(uw);
}
@Override
public boolean refundCoupon(String orderId) {
UpdateWrapper<MallUserCoupon> uw = new UpdateWrapper<>();
uw.eq("order_id", orderId).in("status", 1, 2)
.set("status", 0)
.set("order_id", null)
.set("use_time", null);
return this.update(uw);
}
}

11
hiver-modules/hiver-mall/src/main/resources/mapper/MallCouponMapper.xml

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cc.hiver.mall.dao.mapper.MallCouponMapper">
<update id="deductStock">
UPDATE t_mall_coupon
SET remain_count = remain_count - 1
WHERE id = #{id} AND remain_count > 0 AND del_flag = 0
</update>
</mapper>

1
hiver-modules/hiver-mall/src/main/resources/mapper/MallDeliveryOrderMapper.xml

@ -37,6 +37,7 @@
<result column="is_return" property="isReturn"/>
<result column="worker_name" property="workerName"/>
<result column="arrive_time" property="arriveTime"/>
<result column="arrive_time" property="arriveTime"/>
</resultMap>
<!-- 分页查询配送单,支持多条件过滤(抢单大厅:hallOnly=true时只查workerId为空的) -->

9
hiver-modules/hiver-mall/src/main/resources/mapper/MallOrderMapper.xml

@ -29,6 +29,7 @@
<result column="region_id" property="regionId"/>
<result column="settlement_status" property="settlementStatus"/>
<result column="shop_make_time" property="shopMakeTime"/>
<result column="other_order" property="otherOrder"/>
</resultMap>
<!-- 分页查询订单(不挂载商品明细,由Service层补填) -->
@ -38,7 +39,7 @@
o.status, o.total_amount, o.goods_amount, o.delivery_fee,
o.package_fee, o.address_id, o.remark, o.create_time, o.pay_time,
o.receiver_name, o.receiver_phone, o.receiver_address,
o.shop_name, o.shop_phone, o.shop_address,o.number_code,o.region_id,o.settlement_status,o.shop_make_time
o.shop_name, o.shop_phone, o.shop_address,o.number_code,o.region_id,o.settlement_status,o.shop_make_time,o.other_order
FROM mall_order o
<where>
<if test="q.userId != null and q.userId != ''">
@ -62,13 +63,13 @@
AND o.order_type = #{q.orderType}
</if>
<if test="q.searchType != null and q.searchType == 1">
AND o.order_type in (1,2,3)
AND o.order_type in (1,2,3) AND o.other_order is null
</if>
<if test="q.searchType != null and q.searchType == 2">
AND o.order_type in (4,5)
AND o.other_order = 1
</if>
<if test="q.searchType != null and q.searchType == 3">
AND o.order_type = 6
AND o.other_order = 2
</if>
<if test="q.searchStatus != null and q.searchStatus == 0">
AND o.status = 0

5
hiver-modules/hiver-mall/src/main/resources/mapper/MallUserCouponMapper.xml

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cc.hiver.mall.dao.mapper.MallUserCouponMapper">
</mapper>

2
hiver-modules/hiver-mall/src/main/resources/mapper/WorkerRelaPriceMapper.xml

@ -96,7 +96,9 @@
<if test="putAreaId != null and putAreaId != ''">
AND p.put_area_id = #{putAreaId}
</if>
<if test="orderType != null">
AND p.order_type = #{orderType}
</if>
/* 关联配送订单表:LEFT JOIN 保留无任何订单的配送员 */
LEFT JOIN mall_delivery_order d
ON d.worker_id = w.worker_id

Loading…
Cancel
Save