diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/MallCouponController.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/MallCouponController.java new file mode 100644 index 00000000..0c67edfd --- /dev/null +++ b/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 addCoupon(@RequestBody MallCoupon coupon) { + mallCouponService.save(coupon); + return ResultUtil.success("发行成功"); + } + + @PostMapping("/receive") + @ApiOperation(value = "用户领取优惠券") + public Result receiveCoupon(@RequestParam String userId, @RequestParam String couponId) { + mallUserCouponService.receiveCoupon(userId, couponId); + return ResultUtil.success("领取成功"); + } + + @GetMapping("/available") + @ApiOperation(value = "获取可用优惠券列表(下单时调用)") + public Result> 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>().setData(mallUserCouponService.getAvailableCoupons(userId, applyScene, amount, merchantId, regionId)); + } +} diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/MallDeliveryOrderController.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/MallDeliveryOrderController.java index 0c7ad296..cf559d18 100644 --- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/MallDeliveryOrderController.java +++ b/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 insert(@RequestBody MallDeliveryOrder mallDeliveryOrder) { + try { + mallDeliveryOrder.setStatus(STATUS_WAIT); + return new ResultUtil().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); diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/MallOrderController.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/MallOrderController.java index 0b0eb7a6..e260817d 100644 --- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/MallOrderController.java +++ b/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 { diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/ShopController.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/ShopController.java index 420a296e..9347e760 100644 --- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/ShopController.java +++ b/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; } diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/WechatPayController.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/WechatPayController.java index f00058db..8f0128e5 100644 --- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/WechatPayController.java +++ b/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; diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/dao/mapper/MallCouponMapper.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/dao/mapper/MallCouponMapper.java new file mode 100644 index 00000000..b9760fad --- /dev/null +++ b/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 { + int deductStock(@Param("id") String id); +} diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/dao/mapper/MallUserCouponMapper.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/dao/mapper/MallUserCouponMapper.java new file mode 100644 index 00000000..4fa0c9f7 --- /dev/null +++ b/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 { +} diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/entity/MallCoupon.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/entity/MallCoupon.java new file mode 100644 index 00000000..30b12065 --- /dev/null +++ b/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; +} diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/entity/MallDeliveryOrder.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/entity/MallDeliveryOrder.java index a5e9fcbc..fc14a034 100644 --- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/entity/MallDeliveryOrder.java +++ b/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 goodsList; + @TableField(exist = false) + @ApiModelProperty(value = "使用的优惠券ID(提交订单时传入)") + private String userCouponId; + @Transient + @TableField(exist = false) + @ApiModelProperty(value = "优惠券抵扣金额") + private BigDecimal couponDiscountFee; } diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/entity/MallOrder.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/entity/MallOrder.java index 447effe0..ad4ceaed 100644 --- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/entity/MallOrder.java +++ b/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; } diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/entity/MallUserCoupon.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/entity/MallUserCoupon.java new file mode 100644 index 00000000..e20304ed --- /dev/null +++ b/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; +} diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/dto/CreateOrderDTO.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/dto/CreateOrderDTO.java index 0c9098ed..3bdc3237 100644 --- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/dto/CreateOrderDTO.java +++ b/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 diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/mybatis/MallCouponService.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/mybatis/MallCouponService.java new file mode 100644 index 00000000..eaa36ba6 --- /dev/null +++ b/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 { +} diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/mybatis/MallDeliveryOrderService.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/mybatis/MallDeliveryOrderService.java index 0f265c75..196249a5 100644 --- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/mybatis/MallDeliveryOrderService.java +++ b/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 { void reassignWorker(String deliveryId, String newWorkerId, String newWorkerName, String newWorkerPhone); MallDeliveryOrder selectByGroupId(String orderId); + + MallOrder insertDeliveryOrder(MallDeliveryOrder deliveryOrder); } diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/mybatis/MallUserCouponService.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/mybatis/MallUserCouponService.java new file mode 100644 index 00000000..bbc658b8 --- /dev/null +++ b/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 { + void receiveCoupon(String userId, String couponId); + List 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); +} diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/ShopServiceImpl.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/ShopServiceImpl.java index 3354dfab..ef3fc25c 100644 --- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/ShopServiceImpl.java +++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/ShopServiceImpl.java @@ -112,6 +112,7 @@ public class ShopServiceImpl implements ShopService { final Path ShopNameField = root.get("shopName"); final Path regionField = root.get("regionId"); final Path shopAreaField = root.get("shopArea"); + final Path isStudentField = root.get("isStudent"); final List 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()]; diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/MallCouponServiceImpl.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/MallCouponServiceImpl.java new file mode 100644 index 00000000..4e492ff8 --- /dev/null +++ b/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 implements MallCouponService { +} diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/MallDeliveryOrderServiceImpl.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/MallDeliveryOrderServiceImpl.java index cb6a9b20..740bce06 100644 --- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/MallDeliveryOrderServiceImpl.java +++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/MallDeliveryOrderServiceImpl.java @@ -63,6 +63,9 @@ public class MallDeliveryOrderServiceImpl extends ServiceImpl pageDelivery(MallDeliveryOrderPageQuery q) { if (Boolean.TRUE.equals(q.getHallOnly())) { @@ -456,4 +459,57 @@ public class MallDeliveryOrderServiceImpl extends ServiceImpl 0) { + mallUserCouponService.lockCoupon(deliveryOrder.getUserCouponId(), order.getId()); + } + + deliveryOrder.setCreateTime(date); + deliveryOrder.setOrderId(order.getId()); + this.baseMapper.insert(deliveryOrder); + return order; + } } diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/MallOrderServiceImpl.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/MallOrderServiceImpl.java index 3bfebad7..1e7e78c6 100644 --- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/MallOrderServiceImpl.java +++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/MallOrderServiceImpl.java @@ -103,6 +103,9 @@ public class MallOrderServiceImpl extends ServiceImpl= 1) { // 配送员已接单 → 走商家或者配送员同意流程 - applyMerchantRefund(delivery.getWorkerId(),order, "用户申请取消订单,待同意", refundType, refundTypeStatus); + applyMerchantRefund(delivery.getWorkerId(),order, "用户申请取消订单", refundType, refundTypeStatus); } else { // 未接单 → 直接取消并退款 cancelDeliveryOrderByOrderId(order.getId()); @@ -917,21 +932,19 @@ public class MallOrderServiceImpl extends ServiceImpl rq = new LambdaQueryWrapper<>(); - rq.eq(MallRefundRecord::getOrderId, orderId); - List sallRefundRecord = mallRefundRecordMapper.selectList(rq); - if(sallRefundRecord != null){ - sallRefundRecord.forEach(item -> { - if(item.getRefundType() == 1){ - //售后商品详情 - item.setItems(mallReturnOrderGoodsMapper.selectList(new LambdaQueryWrapper() - .eq(MallReturnOrderGoods::getOrderId, orderId))); + LambdaQueryWrapper rq = new LambdaQueryWrapper<>(); + rq.eq(MallRefundRecord::getOrderId, orderId); + List sallRefundRecord = mallRefundRecordMapper.selectList(rq); + if(sallRefundRecord != null){ + sallRefundRecord.forEach(item -> { + if(item.getRefundType() == 1){ + //售后商品详情 + item.setItems(mallReturnOrderGoodsMapper.selectList(new LambdaQueryWrapper() + .eq(MallReturnOrderGoods::getOrderId, orderId))); - } - }); - vo.setMallRefundRecord(sallRefundRecord); - } + } + }); + vo.setMallRefundRecord(sallRefundRecord); } return vo; } @@ -982,7 +995,25 @@ public class MallOrderServiceImpl extends ServiceImpl 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 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 getAvailableCoupons(String userId, Integer applyScene, BigDecimal amount, String merchantId,String regionId) { + QueryWrapper 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 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 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 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); + } +} diff --git a/hiver-modules/hiver-mall/src/main/resources/mapper/MallCouponMapper.xml b/hiver-modules/hiver-mall/src/main/resources/mapper/MallCouponMapper.xml new file mode 100644 index 00000000..b5b2fd71 --- /dev/null +++ b/hiver-modules/hiver-mall/src/main/resources/mapper/MallCouponMapper.xml @@ -0,0 +1,11 @@ + + + + + + UPDATE t_mall_coupon + SET remain_count = remain_count - 1 + WHERE id = #{id} AND remain_count > 0 AND del_flag = 0 + + + diff --git a/hiver-modules/hiver-mall/src/main/resources/mapper/MallDeliveryOrderMapper.xml b/hiver-modules/hiver-mall/src/main/resources/mapper/MallDeliveryOrderMapper.xml index b57878aa..08b0b814 100644 --- a/hiver-modules/hiver-mall/src/main/resources/mapper/MallDeliveryOrderMapper.xml +++ b/hiver-modules/hiver-mall/src/main/resources/mapper/MallDeliveryOrderMapper.xml @@ -37,6 +37,7 @@ + diff --git a/hiver-modules/hiver-mall/src/main/resources/mapper/MallOrderMapper.xml b/hiver-modules/hiver-mall/src/main/resources/mapper/MallOrderMapper.xml index e189d45c..7709a075 100644 --- a/hiver-modules/hiver-mall/src/main/resources/mapper/MallOrderMapper.xml +++ b/hiver-modules/hiver-mall/src/main/resources/mapper/MallOrderMapper.xml @@ -29,6 +29,7 @@ + @@ -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 @@ -62,13 +63,13 @@ AND o.order_type = #{q.orderType} - AND o.order_type in (1,2,3) + AND o.order_type in (1,2,3) AND o.other_order is null - AND o.order_type in (4,5) + AND o.other_order = 1 - AND o.order_type = 6 + AND o.other_order = 2 AND o.status = 0 diff --git a/hiver-modules/hiver-mall/src/main/resources/mapper/MallUserCouponMapper.xml b/hiver-modules/hiver-mall/src/main/resources/mapper/MallUserCouponMapper.xml new file mode 100644 index 00000000..e8917c05 --- /dev/null +++ b/hiver-modules/hiver-mall/src/main/resources/mapper/MallUserCouponMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/hiver-modules/hiver-mall/src/main/resources/mapper/WorkerRelaPriceMapper.xml b/hiver-modules/hiver-mall/src/main/resources/mapper/WorkerRelaPriceMapper.xml index dac9b79b..c08221e4 100644 --- a/hiver-modules/hiver-mall/src/main/resources/mapper/WorkerRelaPriceMapper.xml +++ b/hiver-modules/hiver-mall/src/main/resources/mapper/WorkerRelaPriceMapper.xml @@ -96,7 +96,9 @@ AND p.put_area_id = #{putAreaId} - AND p.order_type = #{orderType} + + AND p.order_type = #{orderType} + /* 关联配送订单表:LEFT JOIN 保留无任何订单的配送员 */ LEFT JOIN mall_delivery_order d ON d.worker_id = w.worker_id