Compare commits
2 Commits
f6eb0c40d0
...
ab90c26311
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ab90c26311 | ||
|
|
1fe3cb369e |
@ -68,10 +68,10 @@ public class StorePink implements Serializable {
|
||||
@ApiModelProperty(value = "是否发送模板消息0未发送1已发送")
|
||||
private Boolean isTpl;
|
||||
|
||||
@ApiModelProperty(value = "是否退款 0未退款 1已退款")
|
||||
@ApiModelProperty(value = "是否失效 0未失效 1已失效")
|
||||
private Boolean isRefund;
|
||||
|
||||
@ApiModelProperty(value = "状态1进行中2已完成3未完成")
|
||||
@ApiModelProperty(value = "状态1排队中2已达成待领取3已领取")
|
||||
private Integer status;
|
||||
|
||||
@ApiModelProperty(value = "用户昵称")
|
||||
|
||||
@ -0,0 +1,23 @@
|
||||
package com.yzt.common.request;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* 领取商品请求对象
|
||||
*/
|
||||
@Data
|
||||
@ApiModel("领取商品请求")
|
||||
public class ClaimProductRequest {
|
||||
|
||||
@ApiModelProperty(value = "拼团ID(zp_store_pink表的主键id)", required = true)
|
||||
@NotNull(message = "拼团ID不能为空")
|
||||
private Integer pinkId;
|
||||
|
||||
@ApiModelProperty(value = "收货地址ID(zp_user_address表的主键id)", required = true)
|
||||
@NotNull(message = "收货地址ID不能为空")
|
||||
private Integer addressId;
|
||||
}
|
||||
@ -19,6 +19,6 @@ public class PinkQueryRequest {
|
||||
@NotNull(message = "用户ID不能为空")
|
||||
private Integer uid;
|
||||
|
||||
@ApiModelProperty(value = "队列类型: 1-会员队列, 2-会馆队列")
|
||||
@ApiModelProperty(value = "队列类型: 1-黔行, 2-茅香")
|
||||
private Integer queueType;
|
||||
}
|
||||
|
||||
@ -2,12 +2,17 @@ package com.yzt.front.controller;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.yzt.common.model.combination.StoreCombination;
|
||||
import com.yzt.common.model.combination.StorePink;
|
||||
import com.yzt.common.model.product.StoreProduct;
|
||||
import com.yzt.common.page.CommonPage;
|
||||
import com.yzt.common.request.ClaimProductRequest;
|
||||
import com.yzt.common.request.PageParamRequest;
|
||||
import com.yzt.common.request.StorePinkRequest;
|
||||
import com.yzt.common.response.*;
|
||||
import com.yzt.common.result.CommonResult;
|
||||
import com.yzt.service.service.StoreCombinationService;
|
||||
import com.yzt.service.service.StorePinkService;
|
||||
import com.yzt.service.service.StoreProductService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -28,6 +33,12 @@ public class CombinationController {
|
||||
@Autowired
|
||||
private StoreCombinationService storeCombinationService;
|
||||
|
||||
@Autowired
|
||||
private StorePinkService storePinkService;
|
||||
|
||||
@Autowired
|
||||
private StoreProductService storeProductService;
|
||||
|
||||
/**
|
||||
* 拼团首页
|
||||
*/
|
||||
@ -99,4 +110,45 @@ public class CombinationController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 领取商品(拼团达成后免费送一份商品)
|
||||
*/
|
||||
@ApiOperation(value = "领取商品")
|
||||
@RequestMapping(value = "/claim", method = RequestMethod.POST)
|
||||
public CommonResult<String> claimProduct(@RequestBody @Validated ClaimProductRequest request) {
|
||||
try {
|
||||
String orderNo = storePinkService.claimProduct(request.getPinkId(), request.getAddressId());
|
||||
return CommonResult.success(orderNo).setMessage("领取成功");
|
||||
} catch (Exception e) {
|
||||
log.error("领取商品失败: {}", e.getMessage(), e);
|
||||
return CommonResult.failed(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据拼团ID查询商品详情
|
||||
*/
|
||||
@ApiOperation(value = "根据拼团ID查询商品详情")
|
||||
@RequestMapping(value = "/product/{pinkId}", method = RequestMethod.GET)
|
||||
public CommonResult<StoreProduct> getProductByPinkId(@PathVariable(value = "pinkId") Integer pinkId) {
|
||||
try {
|
||||
// 根据拼团ID查询拼团信息
|
||||
StorePink storePink = storePinkService.getById(pinkId);
|
||||
if (storePink == null) {
|
||||
return CommonResult.failed("拼团信息不存在");
|
||||
}
|
||||
|
||||
// 根据商品ID查询商品基本信息
|
||||
StoreProduct storeProduct = storeProductService.getById(storePink.getPid());
|
||||
if (storeProduct == null) {
|
||||
return CommonResult.failed("商品信息不存在");
|
||||
}
|
||||
|
||||
return CommonResult.success(storeProduct);
|
||||
} catch (Exception e) {
|
||||
log.error("根据拼团ID查询商品详情失败: {}", e.getMessage(), e);
|
||||
return CommonResult.failed(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -118,4 +118,12 @@ public interface StorePinkService extends IService<StorePink> {
|
||||
* @param remark 备注
|
||||
*/
|
||||
void adminGenerateQueueCodes(Integer uid, Integer productId, Integer count, String remark);
|
||||
|
||||
/**
|
||||
* H5端用户领取商品(免费送一份商品)
|
||||
* @param pinkId 拼团ID
|
||||
* @param addressId 收货地址ID
|
||||
* @return 订单编号
|
||||
*/
|
||||
String claimProduct(Integer pinkId, Integer addressId);
|
||||
}
|
||||
|
||||
@ -16,9 +16,12 @@ import com.yzt.common.exception.YztException;
|
||||
import com.yzt.common.model.combination.StoreCombination;
|
||||
import com.yzt.common.model.combination.StorePink;
|
||||
import com.yzt.common.model.order.StoreOrder;
|
||||
import com.yzt.common.model.order.StoreOrderInfo;
|
||||
import com.yzt.common.model.product.StoreProduct;
|
||||
import com.yzt.common.model.product.StoreProductAttr;
|
||||
import com.yzt.common.model.system.SystemNotification;
|
||||
import com.yzt.common.model.user.User;
|
||||
import com.yzt.common.model.user.UserAddress;
|
||||
import com.yzt.common.model.user.UserBrokerageRecord;
|
||||
import com.yzt.common.model.user.UserRechargeApplication;
|
||||
import com.yzt.common.model.user.UserToken;
|
||||
@ -29,6 +32,7 @@ import com.yzt.common.request.StorePinkSearchRequest;
|
||||
import com.yzt.common.response.StorePinkAdminListResponse;
|
||||
import com.yzt.common.response.StorePinkDetailResponse;
|
||||
import com.yzt.common.utils.YztDateUtil;
|
||||
import com.yzt.common.utils.YztUtil;
|
||||
import com.yzt.common.vo.DateLimitUtilVo;
|
||||
import com.yzt.common.vo.MyRecord;
|
||||
import com.yzt.service.mapper.StorePinkMapper;
|
||||
@ -92,6 +96,18 @@ public class StorePinkServiceImpl extends ServiceImpl<StorePinkMapper, StorePink
|
||||
@Autowired
|
||||
private StoreProductAttrService storeProductAttrService;
|
||||
|
||||
@Autowired
|
||||
private UserAddressService userAddressService;
|
||||
|
||||
@Autowired
|
||||
private StoreProductService storeProductService;
|
||||
|
||||
@Autowired
|
||||
private StoreOrderInfoService storeOrderInfoService;
|
||||
|
||||
@Autowired
|
||||
private StoreOrderStatusService storeOrderStatusService;
|
||||
|
||||
|
||||
/**
|
||||
* 列表
|
||||
@ -803,5 +819,137 @@ public class StorePinkServiceImpl extends ServiceImpl<StorePinkMapper, StorePink
|
||||
|
||||
return timeStr + randomStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* H5端用户领取商品(免费送一份商品)
|
||||
* @param pinkId 拼团ID
|
||||
* @param addressId 收货地址ID
|
||||
* @return 订单编号
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public String claimProduct(Integer pinkId, Integer addressId) {
|
||||
// 验证拼团记录
|
||||
StorePink storePink = getById(pinkId);
|
||||
if (ObjectUtil.isNull(storePink)) {
|
||||
throw new YztException("拼团记录不存在");
|
||||
}
|
||||
if (storePink.getIsRefund() != null && storePink.getIsRefund()) {
|
||||
throw new YztException("该拼团记录已取消,无法领取");
|
||||
}
|
||||
if (storePink.getStatus() != 2) {
|
||||
throw new YztException("只有已达成待领取状态的拼团才能领取商品");
|
||||
}
|
||||
|
||||
// 验证收货地址
|
||||
UserAddress userAddress = userAddressService.getById(addressId);
|
||||
if (ObjectUtil.isNull(userAddress) || userAddress.getIsDel()) {
|
||||
throw new YztException("收货地址不存在或已删除");
|
||||
}
|
||||
if (!userAddress.getUid().equals(storePink.getUid())) {
|
||||
throw new YztException("收货地址与拼团用户不匹配");
|
||||
}
|
||||
|
||||
// 获取用户信息
|
||||
User user = userService.getById(storePink.getUid());
|
||||
if (ObjectUtil.isNull(user)) {
|
||||
throw new YztException("用户信息不存在");
|
||||
}
|
||||
|
||||
// 获取商品信息(从拼团记录的pid字段获取)
|
||||
StoreProduct storeProduct = storeProductService.getById(storePink.getPid());
|
||||
if (ObjectUtil.isNull(storeProduct)) {
|
||||
throw new YztException("商品不存在");
|
||||
}
|
||||
|
||||
// 生成订单号
|
||||
String orderNo = YztUtil.getOrderNo("claim");
|
||||
|
||||
// 创建免费订单
|
||||
StoreOrder claimOrder = new StoreOrder();
|
||||
claimOrder.setUid(user.getUid());
|
||||
claimOrder.setTenantId(user.getTenantId());
|
||||
claimOrder.setOrderId(orderNo);
|
||||
claimOrder.setRealName(userAddress.getRealName());
|
||||
claimOrder.setUserPhone(userAddress.getPhone());
|
||||
claimOrder.setUserAddress(userAddress.getProvince() + userAddress.getCity() + userAddress.getDistrict() + userAddress.getDetail());
|
||||
|
||||
// 免费领取
|
||||
claimOrder.setTotalNum(1); // 送一份
|
||||
claimOrder.setTotalPrice(BigDecimal.ZERO);
|
||||
claimOrder.setProTotalPrice(BigDecimal.ZERO);
|
||||
claimOrder.setTotalPostage(BigDecimal.ZERO);
|
||||
claimOrder.setPayPrice(BigDecimal.ZERO);
|
||||
claimOrder.setPayPostage(BigDecimal.ZERO);
|
||||
claimOrder.setDeductionPrice(BigDecimal.ZERO);
|
||||
claimOrder.setCouponId(0);
|
||||
claimOrder.setCouponPrice(BigDecimal.ZERO);
|
||||
claimOrder.setUseIntegral(0);
|
||||
claimOrder.setGainIntegral(0);
|
||||
claimOrder.setBackIntegral(0);
|
||||
claimOrder.setCost(BigDecimal.ZERO);
|
||||
|
||||
// 设置为已支付状态
|
||||
claimOrder.setPaid(true);
|
||||
claimOrder.setPayTime(YztDateUtil.nowDateTime());
|
||||
claimOrder.setPayType("free"); // 标记为免费领取
|
||||
|
||||
claimOrder.setCreateTime(YztDateUtil.nowDateTime());
|
||||
claimOrder.setStatus(0); // 待发货
|
||||
claimOrder.setRefundStatus(0);
|
||||
claimOrder.setShippingType(1); // 快递配送
|
||||
claimOrder.setCombinationId(0);
|
||||
claimOrder.setPinkId(0);
|
||||
claimOrder.setIsDel(false);
|
||||
claimOrder.setIsSystemDel(false);
|
||||
claimOrder.setIsRemind(false);
|
||||
claimOrder.setType(0); // 普通订单
|
||||
claimOrder.setMark("拼团ID:" + pinkId + " 达成后免费领取");
|
||||
|
||||
// 保存订单
|
||||
boolean orderSaved = storeOrderService.create(claimOrder);
|
||||
if (!orderSaved) {
|
||||
throw new YztException("创建领取订单失败");
|
||||
}
|
||||
|
||||
// 创建订单详情
|
||||
StoreOrderInfo orderInfo = new StoreOrderInfo();
|
||||
orderInfo.setOrderId(claimOrder.getId());
|
||||
orderInfo.setProductId(storeProduct.getId());
|
||||
orderInfo.setOrderNo(orderNo);
|
||||
orderInfo.setProductName(storeProduct.getStoreName());
|
||||
orderInfo.setAttrValueId(0); // 无需规格
|
||||
orderInfo.setImage(storeProduct.getImage());
|
||||
orderInfo.setSku("免费领取");
|
||||
orderInfo.setPrice(BigDecimal.ZERO); // 免费
|
||||
orderInfo.setPayNum(1); // 送一份
|
||||
orderInfo.setWeight(BigDecimal.ZERO);
|
||||
orderInfo.setVolume(BigDecimal.ZERO);
|
||||
orderInfo.setGiveIntegral(0);
|
||||
orderInfo.setIsReply(false);
|
||||
orderInfo.setIsSub(false);
|
||||
orderInfo.setVipPrice(BigDecimal.ZERO);
|
||||
orderInfo.setProductType(Constants.PRODUCT_TYPE_NORMAL);
|
||||
orderInfo.setUnique("claim_" + pinkId);
|
||||
|
||||
// 构建详细信息JSON(简化版)
|
||||
orderInfo.setInfo("{\"productId\":" + storeProduct.getId() + ",\"productName\":\"" + storeProduct.getStoreName() + "\",\"price\":0,\"payNum\":1}");
|
||||
|
||||
List<StoreOrderInfo> orderInfoList = new ArrayList<>();
|
||||
orderInfoList.add(orderInfo);
|
||||
storeOrderInfoService.saveOrderInfos(orderInfoList);
|
||||
|
||||
// 更新拼团状态为已领取
|
||||
storePink.setStatus(3);
|
||||
updateById(storePink);
|
||||
|
||||
// 创建订单日志
|
||||
storeOrderStatusService.createLog(claimOrder.getId(), Constants.ORDER_STATUS_CACHE_CREATE_ORDER, "拼团达成免费领取商品订单生成");
|
||||
storeOrderStatusService.createLog(claimOrder.getId(), Constants.ORDER_STATUS_CACHE_CREATE_ORDER, "免费领取,自动标记为已支付");
|
||||
|
||||
logger.info("用户 {} 领取拼团商品成功,拼团ID: {}, 订单号: {}", user.getUid(), pinkId, orderNo);
|
||||
|
||||
return orderNo;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user