|
|
|
|
@ -1,13 +1,26 @@ |
|
|
|
|
package com.hfkj.service.goods.impl; |
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
import com.hfkj.common.exception.ErrorCode; |
|
|
|
|
import com.hfkj.common.exception.ErrorHelp; |
|
|
|
|
import com.hfkj.common.exception.SysCode; |
|
|
|
|
import com.hfkj.common.utils.RandomUtils; |
|
|
|
|
import com.hfkj.dao.GoodPresentMapper; |
|
|
|
|
import com.hfkj.entity.CouponDiscountPackage; |
|
|
|
|
import com.hfkj.entity.GoodPresent; |
|
|
|
|
import com.hfkj.entity.GoodPresentExample; |
|
|
|
|
import com.hfkj.entity.GoodsBrand; |
|
|
|
|
import com.hfkj.entity.*; |
|
|
|
|
import com.hfkj.haioil.HaiOilService; |
|
|
|
|
import com.hfkj.model.order.OrderChildModel; |
|
|
|
|
import com.hfkj.model.order.OrderModel; |
|
|
|
|
import com.hfkj.service.coupon.BsOrderCouponNoService; |
|
|
|
|
import com.hfkj.service.coupon.BsOrderCouponService; |
|
|
|
|
import com.hfkj.service.coupon.channel.HuiLianTongCouponService; |
|
|
|
|
import com.hfkj.service.discount.CouponDiscountPackageService; |
|
|
|
|
import com.hfkj.service.goods.GoodPresentService; |
|
|
|
|
import com.hfkj.service.hlt.HuiLianTongUnionCardService; |
|
|
|
|
import com.hfkj.service.order.BsOrderChildService; |
|
|
|
|
import com.hfkj.sysenum.GoodsVpdSourceEnum; |
|
|
|
|
import com.hfkj.sysenum.order.OrderChildStatusEnum; |
|
|
|
|
import com.hfkj.sysenum.order.OrderCouponNoStatusEnum; |
|
|
|
|
import org.apache.commons.collections4.MapUtils; |
|
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
@ -20,10 +33,17 @@ public class GoodPresentServiceImpl implements GoodPresentService { |
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
private GoodPresentMapper goodPresentMapper; |
|
|
|
|
@Resource |
|
|
|
|
private BsOrderChildService orderChildService; |
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
private CouponDiscountPackageService couponDiscountPackageService; |
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
private BsOrderCouponService orderCouponService; |
|
|
|
|
@Resource |
|
|
|
|
private BsOrderCouponNoService orderCouponNoService; |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void create(GoodPresent goodPresent) { |
|
|
|
|
goodPresentMapper.insert(goodPresent); |
|
|
|
|
@ -66,21 +86,103 @@ public class GoodPresentServiceImpl implements GoodPresentService { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void presentDiscountPackage(Long specsId , String phone) throws Exception { |
|
|
|
|
public void presentDiscountPackage(OrderModel order, BsOrderChild orderChild) throws Exception { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
orderChild.setExt2("1001"); |
|
|
|
|
orderChildService.editData(orderChild); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 创建一个Map对象,用于存储查询条件
|
|
|
|
|
Map<String , Object> map = new HashMap<>(); |
|
|
|
|
map.put("specsId",specsId); |
|
|
|
|
// 向Map中添加商品规格ID作为查询条件
|
|
|
|
|
map.put("specsId",orderChild.getProductSpecId()); |
|
|
|
|
// 根据查询条件获取礼品列表
|
|
|
|
|
List<GoodPresent> list = getList(map); |
|
|
|
|
|
|
|
|
|
// 遍历礼品列表
|
|
|
|
|
for (GoodPresent goodPresent : list) { |
|
|
|
|
|
|
|
|
|
// 创建卡券订单对象
|
|
|
|
|
BsOrderCoupon orderCoupon = new BsOrderCoupon(); |
|
|
|
|
// 设置卡券订单的基本信息
|
|
|
|
|
orderCoupon.setOrderNo(orderChild.getOrderNo()); // 设置订单号
|
|
|
|
|
orderCoupon.setChildOrderNo(orderChild.getChildOrderNo()); // 设置子订单号
|
|
|
|
|
orderCoupon.setMerId(orderChild.getMerId()); // 设置商家ID
|
|
|
|
|
orderCoupon.setUserId(order.getUserId()); // 设置用户ID
|
|
|
|
|
orderCoupon.setGoodsId(orderChild.getProductId()); // 设置商品ID
|
|
|
|
|
orderCoupon.setGoodsName(orderChild.getProductName()); // 设置商品名称
|
|
|
|
|
|
|
|
|
|
// 设置商品规格相关信息
|
|
|
|
|
orderCoupon.setGoodsSpecsId(orderChild.getProductSpecId()); // 设置商品规格ID
|
|
|
|
|
orderCoupon.setGoodsSpecsName(orderChild.getProductSpecName()); // 设置商品规格名称
|
|
|
|
|
orderCoupon.setGoodsSpescOriginalPrice(orderChild.getProductPrice()); // 设置商品规格原价
|
|
|
|
|
orderCoupon.setGoodsSpescSalePrice(orderChild.getProductActualPrice()); // 设置商品规格售价
|
|
|
|
|
orderCoupon.setGoodsVpdKey(goodPresent.getKey()); // 设置商品礼品密钥
|
|
|
|
|
orderCoupon.setGoodsCount(1); // 设置商品数量
|
|
|
|
|
orderCoupon.setStatus(OrderChildStatusEnum.status3.getCode()); // 设置订单状态
|
|
|
|
|
// 创建优惠券折扣包对象
|
|
|
|
|
CouponDiscountPackage discountPackage = new CouponDiscountPackage(); |
|
|
|
|
JSONObject returnParam = new JSONObject(); |
|
|
|
|
// 根据礼品类型处理不同的逻辑
|
|
|
|
|
if (goodPresent.getType() == 1) { |
|
|
|
|
// 类型为1时,处理优惠券折扣包
|
|
|
|
|
discountPackage = couponDiscountPackageService.findDiscountPackageByKey(goodPresent.getKey()); |
|
|
|
|
couponDiscountPackageService.giveDiscountPackage(discountPackage.getId().intValue() , order.getUserPhone() , null); |
|
|
|
|
orderCoupon.setGoodsVpdSource(1); // 设置礼品来源为1
|
|
|
|
|
} else { |
|
|
|
|
// 类型不为1时,处理其他类型的礼品
|
|
|
|
|
Map<String , Object> pushMap = new HashMap<>(); |
|
|
|
|
pushMap.put("discountPkNo" , goodPresent.getKey()); // 添加礼品密钥
|
|
|
|
|
pushMap.put("number" , 1); // 添加数量
|
|
|
|
|
pushMap.put("phone" , order.getUserPhone()); // 添加用户手机号
|
|
|
|
|
returnParam = HaiOilService.pushPk(pushMap); // 调用服务推送礼品
|
|
|
|
|
orderCoupon.setGoodsVpdSource(3); // 设置礼品来源为3
|
|
|
|
|
} |
|
|
|
|
// 保存卡券订单信息
|
|
|
|
|
orderCouponService.editData(orderCoupon); |
|
|
|
|
// 卡券订单卡密
|
|
|
|
|
BsOrderCouponNo orderCouponNo = new BsOrderCouponNo(); |
|
|
|
|
// 设置优惠券订单号关联的订单ID
|
|
|
|
|
orderCouponNo.setCouponOrderId(orderCoupon.getId()); |
|
|
|
|
// 设置订单号,由优惠券ID和6位随机数字组成
|
|
|
|
|
orderCouponNo.setOrderNo(orderCoupon.getId() + RandomUtils.number(6, false)); |
|
|
|
|
// 设置商品VPD键
|
|
|
|
|
orderCouponNo.setGoodsVpdKey(orderCoupon.getGoodsVpdKey()); |
|
|
|
|
// 设置商品VPD来源
|
|
|
|
|
orderCouponNo.setGoodsVpdSource(orderCoupon.getGoodsVpdSource()); |
|
|
|
|
// 设置过期状态为未过期
|
|
|
|
|
orderCouponNo.setExpireStatus(false); |
|
|
|
|
// 设置异常状态为未异常
|
|
|
|
|
orderCouponNo.setExceptionStatus(false); |
|
|
|
|
// 设置优惠券状态为状态2
|
|
|
|
|
orderCouponNo.setStatus(OrderCouponNoStatusEnum.status2.getCode()); |
|
|
|
|
|
|
|
|
|
// 根据商品类型进行不同处理
|
|
|
|
|
if (goodPresent.getType() == 1) { |
|
|
|
|
CouponDiscountPackage discountPackage = couponDiscountPackageService.findDiscountPackageByKey(goodPresent.getKey()); |
|
|
|
|
couponDiscountPackageService.giveDiscountPackage(discountPackage.getId().intValue() , phone , null); |
|
|
|
|
// 如果是类型1,设置过期时间为优惠套餐的有效时间
|
|
|
|
|
orderCouponNo.setExpireTime(discountPackage.getEffectiveTime()); |
|
|
|
|
// 设置交付时间为当前时间
|
|
|
|
|
orderCouponNo.setDeliverTime(new Date()); |
|
|
|
|
// 设置商品VPD来源优惠券号为优惠套餐的键
|
|
|
|
|
orderCouponNo.setGoodsVpdSourceCouNo(discountPackage.getKey()); |
|
|
|
|
} else { |
|
|
|
|
map.put("discountPkNo" , goodPresent.getKey()); |
|
|
|
|
map.put("number" , 1); |
|
|
|
|
map.put("phone" , phone); |
|
|
|
|
HaiOilService.pushPk(map); |
|
|
|
|
// 如果不是类型1,从返回参数中获取数据
|
|
|
|
|
JSONArray dataArray = returnParam.getJSONObject("return_data").getJSONArray("list"); |
|
|
|
|
// 设置过期时间为返回数据中的过期日期
|
|
|
|
|
orderCouponNo.setExpireTime(dataArray.getJSONObject(0).getJSONArray("codeList").getJSONObject(0).getDate("expirationDate")); |
|
|
|
|
// 设置交付时间为当前时间
|
|
|
|
|
orderCouponNo.setDeliverTime(new Date()); |
|
|
|
|
// 设置渠道订单号为返回数据中的请求ID
|
|
|
|
|
orderCouponNo.setChannelOrderNo(returnParam.getJSONObject("return_data").getString("reqId")); |
|
|
|
|
// 设置商品VPD来源优惠券号为返回数据中的折扣库存代码
|
|
|
|
|
orderCouponNo.setGoodsVpdSourceCouNo(dataArray.getJSONObject(0).getString("discountPkStockCode")); |
|
|
|
|
} |
|
|
|
|
// 更新优惠券订单号数据
|
|
|
|
|
orderCouponNoService.editData(orderCouponNo); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|