From c2babeab2f6ab6d3f3be507862c3d815880576e1 Mon Sep 17 00:00:00 2001 From: Sum1Dream <418471657@qq.com> Date: Thu, 27 Apr 2023 16:49:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E5=AE=9E=E7=89=A9=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/bweb/controller/CommonController.java | 39 +++++- .../com/cweb/controller/CommonController.java | 20 +++ .../java/com/hai/config/CommonSysConfig.java | 1 + .../com/hai/entity/HighMerchantStore.java | 22 ++- .../goods/service/GoodsPresentService.java | 25 +++- .../service/impl/GoodsPresentServiceImpl.java | 28 ++++ .../java/com/hai/model/MapStoreModel.java | 116 +++++++++++++++ .../impl/OrderCancelHandleServiceImpl.java | 1 + .../impl/OrderCreateHandleServiceImpl.java | 21 +++ .../impl/OrderPaySuccessServiceImpl.java | 49 ++++++- .../java/com/hai/service/CommonService.java | 7 +- .../com/hai/service/HighCouponService.java | 3 + .../service/HighDiscountAgentCodeService.java | 4 +- .../impl/BsOrderRebateServiceImpl.java | 10 +- .../hai/service/impl/CommonServiceImpl.java | 132 ++++++++++++++++++ .../service/impl/HighCouponServiceImpl.java | 2 + .../HighDiscountAgentCodeServiceImpl.java | 81 ++++++++++- .../impl/HighMerchantStoreServiceImpl.java | 7 + .../resources/dev/commonConfig.properties | 5 +- .../business/OrderRebateController.java | 86 +++++++++++- 20 files changed, 629 insertions(+), 30 deletions(-) create mode 100644 hai-service/src/main/java/com/hai/model/MapStoreModel.java diff --git a/hai-bweb/src/main/java/com/bweb/controller/CommonController.java b/hai-bweb/src/main/java/com/bweb/controller/CommonController.java index 753e520b..c17fbcb3 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/CommonController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/CommonController.java @@ -1,5 +1,6 @@ package com.bweb.controller; +import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.hai.common.exception.ErrorCode; import com.hai.common.exception.ErrorHelp; @@ -10,6 +11,7 @@ import com.hai.common.utils.ResponseMsgUtil; import com.hai.config.CommonConfig; import com.hai.config.TuanYouConfig; import com.hai.entity.GoodsLogistics; +import com.hai.entity.HighGoodsType; import com.hai.entity.SecConfig; import com.hai.entity.SecDictionary; import com.hai.goods.service.GoodsLogisticsService; @@ -25,10 +27,7 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.math.BigDecimal; -import java.util.Comparator; -import java.util.Date; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; @@ -423,8 +422,36 @@ public class CommonController { public ResponseData getIndustry() { try { - JSONObject object = commonService.getIndustry(); - return ResponseMsgUtil.success(object); + JSONArray object = commonService.getIndustry().getJSONArray("return_data"); + + List list = new ArrayList<>(); + + + for (Object firstObject : object) { + JSONObject jsonObject = new JSONObject(); + JSONObject firstData = (JSONObject) firstObject; + jsonObject.put("title" , firstData.getString("name")); + jsonObject.put("key" , firstData.getLong("id")); + + + // 判断是否存在子类 + if (firstData.getJSONArray("childIndustry").size() > 0) { + List listChild = new ArrayList<>(); + for (Object childObject : firstData.getJSONArray("childIndustry")) { + JSONObject objectChild = new JSONObject(); + JSONObject childData = (JSONObject) childObject; + objectChild.put("title" , childData.getString("name")); + objectChild.put("key" , childData.getString("id")); + objectChild.put("isLeaf" , true); + listChild.add(objectChild); + } + + jsonObject.put("children" , listChild); + jsonObject.put("selectable" , false); + list.add(jsonObject); + } + } + return ResponseMsgUtil.success(list); } catch (Exception e) { log.error("HighOrderController --> unionStagingPay() error!", e); diff --git a/hai-cweb/src/main/java/com/cweb/controller/CommonController.java b/hai-cweb/src/main/java/com/cweb/controller/CommonController.java index 1a3caff8..cf59b1ff 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/CommonController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/CommonController.java @@ -421,4 +421,24 @@ public class CommonController { } } + @RequestMapping(value = "/getMapStore", method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "获取地图门店") + public ResponseData getMapStore( + @RequestParam(name = "distance", required = true) Double distance, + @RequestParam(name = "name", required = false) String name, + @RequestParam(name = "childId", required = false) Long childId, + @RequestParam(name = "longitude", required = true) String longitude, + @RequestParam(name = "latitude", required = true) String latitude + ) { + try { + + return ResponseMsgUtil.success(commonService.getMapStore(name , childId , latitude , longitude , distance)); + + } catch (Exception e) { + log.error("HighOrderController --> unionStagingPay() error!", e); + return ResponseMsgUtil.exception(e); + } + } + } diff --git a/hai-service/src/main/java/com/hai/config/CommonSysConfig.java b/hai-service/src/main/java/com/hai/config/CommonSysConfig.java index 1f3d41e9..83cf27a1 100644 --- a/hai-service/src/main/java/com/hai/config/CommonSysConfig.java +++ b/hai-service/src/main/java/com/hai/config/CommonSysConfig.java @@ -131,5 +131,6 @@ public class CommonSysConfig { private String logisticsAppSecret; private String payPostUrl; + private String filesystem; } diff --git a/hai-service/src/main/java/com/hai/entity/HighMerchantStore.java b/hai-service/src/main/java/com/hai/entity/HighMerchantStore.java index 89f0f1b2..75fdb467 100644 --- a/hai-service/src/main/java/com/hai/entity/HighMerchantStore.java +++ b/hai-service/src/main/java/com/hai/entity/HighMerchantStore.java @@ -159,6 +159,26 @@ public class HighMerchantStore implements Serializable { private String ext3; + private Double distance; + + private HighMerchant highMerchant; + + public Double getDistance() { + return distance; + } + + public void setDistance(Double distance) { + this.distance = distance; + } + + public HighMerchant getHighMerchant() { + return highMerchant; + } + + public void setHighMerchant(HighMerchant highMerchant) { + this.highMerchant = highMerchant; + } + private static final long serialVersionUID = 1L; public Long getId() { @@ -533,4 +553,4 @@ public class HighMerchantStore implements Serializable { sb.append("]"); return sb.toString(); } -} \ No newline at end of file +} diff --git a/hai-service/src/main/java/com/hai/goods/service/GoodsPresentService.java b/hai-service/src/main/java/com/hai/goods/service/GoodsPresentService.java index 7d6fdc85..55bd9b4e 100644 --- a/hai-service/src/main/java/com/hai/goods/service/GoodsPresentService.java +++ b/hai-service/src/main/java/com/hai/goods/service/GoodsPresentService.java @@ -1,6 +1,7 @@ package com.hai.goods.service; import com.hai.entity.GoodsPresent; +import com.hai.entity.GoodsPresentRecord; import java.util.List; import java.util.Map; @@ -44,6 +45,8 @@ public interface GoodsPresentService { */ List getPresentList(Map map); + List getPresentList(Long goodsId); + /** * @Author Sum1Dream @@ -64,5 +67,25 @@ public interface GoodsPresentService { * @Return void */ void deletePresent(Long id); - + + + /** + * @Author Sum1Dream + * @Name insertPresentRecord + * @Description //TODO + * @Date 14:46 2023/4/27 + * @Param [record] + * @Return void + */ + void insertPresentRecord(GoodsPresentRecord record); + + /** + * @Author Sum1Dream + * @Name getPresentRecord + * @Description //TODO + * @Date 14:46 2023/4/27 + * @Param [map] + * @Return java.util.List + */ + List getPresentRecord(Map map); } diff --git a/hai-service/src/main/java/com/hai/goods/service/impl/GoodsPresentServiceImpl.java b/hai-service/src/main/java/com/hai/goods/service/impl/GoodsPresentServiceImpl.java index 91698ddf..9fb901a5 100644 --- a/hai-service/src/main/java/com/hai/goods/service/impl/GoodsPresentServiceImpl.java +++ b/hai-service/src/main/java/com/hai/goods/service/impl/GoodsPresentServiceImpl.java @@ -1,8 +1,10 @@ package com.hai.goods.service.impl; import com.hai.dao.GoodsPresentMapper; +import com.hai.dao.GoodsPresentRecordMapper; import com.hai.entity.GoodsPresent; import com.hai.entity.GoodsPresentExample; +import com.hai.entity.GoodsPresentRecord; import com.hai.entity.GoodsRegionFreight; import com.hai.goods.service.GoodsPresentService; import org.apache.commons.collections4.MapUtils; @@ -18,6 +20,9 @@ public class GoodsPresentServiceImpl implements GoodsPresentService { @Resource private GoodsPresentMapper goodsPresentMapper; + @Resource + private GoodsPresentRecordMapper goodsPresentRecordMapper; + @Override public void insertPresent(GoodsPresent present) { goodsPresentMapper.insert(present); @@ -41,6 +46,19 @@ public class GoodsPresentServiceImpl implements GoodsPresentService { return goodsPresentMapper.selectByExample(example); } + @Override + public List getPresentList(Long goodsId) { + GoodsPresentExample example = new GoodsPresentExample(); + GoodsPresentExample.Criteria criteria = example.createCriteria(); + + if (goodsId != null) { + criteria.andGoodsIdEqualTo(goodsId); + } + criteria.andStatusNotEqualTo(String.valueOf(0)); + + return goodsPresentMapper.selectByExample(example); + } + @Override public GoodsPresent findPresentById(Long id) { return goodsPresentMapper.selectByPrimaryKey(id); @@ -50,4 +68,14 @@ public class GoodsPresentServiceImpl implements GoodsPresentService { public void deletePresent(Long id) { goodsPresentMapper.deleteByPrimaryKey(id); } + + @Override + public void insertPresentRecord(GoodsPresentRecord record) { + goodsPresentRecordMapper.insert(record); + } + + @Override + public List getPresentRecord(Map map) { + return null; + } } diff --git a/hai-service/src/main/java/com/hai/model/MapStoreModel.java b/hai-service/src/main/java/com/hai/model/MapStoreModel.java new file mode 100644 index 00000000..9fa495fe --- /dev/null +++ b/hai-service/src/main/java/com/hai/model/MapStoreModel.java @@ -0,0 +1,116 @@ +package com.hai.model; + +import com.alibaba.fastjson.JSONObject; + +public class MapStoreModel { + + private Long id; + private Integer sourceType; + private String logo; + private String latitude; + private String longitude; + private String iconPath; + private Integer rotate; + private Integer width; + private Integer height; + private JSONObject callout; + private double alpha; + + private double distance; + + public double getDistance() { + return distance; + } + + public void setDistance(double distance) { + this.distance = distance; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Integer getSourceType() { + return sourceType; + } + + public void setSourceType(Integer sourceType) { + this.sourceType = sourceType; + } + + public String getLatitude() { + return latitude; + } + + public void setLatitude(String latitude) { + this.latitude = latitude; + } + + public String getLongitude() { + return longitude; + } + + public void setLongitude(String longitude) { + this.longitude = longitude; + } + + public String getIconPath() { + return iconPath; + } + + public void setIconPath(String iconPath) { + this.iconPath = iconPath; + } + + public Integer getRotate() { + return rotate; + } + + public void setRotate(Integer rotate) { + this.rotate = rotate; + } + + public Integer getWidth() { + return width; + } + + public void setWidth(Integer width) { + this.width = width; + } + + public Integer getHeight() { + return height; + } + + public void setHeight(Integer height) { + this.height = height; + } + + public JSONObject getCallout() { + return callout; + } + + public void setCallout(JSONObject callout) { + this.callout = callout; + } + + public double getAlpha() { + return alpha; + } + + public void setAlpha(double alpha) { + this.alpha = alpha; + } + + public String getLogo() { + return logo; + } + + public void setLogo(String logo) { + this.logo = logo; + } +} diff --git a/hai-service/src/main/java/com/hai/order/service/impl/OrderCancelHandleServiceImpl.java b/hai-service/src/main/java/com/hai/order/service/impl/OrderCancelHandleServiceImpl.java index 95ed1470..12083c6d 100644 --- a/hai-service/src/main/java/com/hai/order/service/impl/OrderCancelHandleServiceImpl.java +++ b/hai-service/src/main/java/com/hai/order/service/impl/OrderCancelHandleServiceImpl.java @@ -56,6 +56,7 @@ public class OrderCancelHandleServiceImpl implements OrderCancelHandleService { @Override public void goodsHandle(HighChildOrder childOrder) { + GoodsSku goodsSku = goodsSkuService.findGoodsSkuById(childOrder.getSkuId()); goodsSku.setStock(goodsSku.getStock() + childOrder.getSaleCount()); goodsSkuService.updateGoodsSku(goodsSku); diff --git a/hai-service/src/main/java/com/hai/order/service/impl/OrderCreateHandleServiceImpl.java b/hai-service/src/main/java/com/hai/order/service/impl/OrderCreateHandleServiceImpl.java index 0f621312..2b28b6ba 100644 --- a/hai-service/src/main/java/com/hai/order/service/impl/OrderCreateHandleServiceImpl.java +++ b/hai-service/src/main/java/com/hai/order/service/impl/OrderCreateHandleServiceImpl.java @@ -12,6 +12,7 @@ import com.hai.dao.OutRechargeOrderMapper; import com.hai.entity.*; import com.hai.enum_type.*; import com.hai.goods.service.GoodsDetailService; +import com.hai.goods.service.GoodsPresentService; import com.hai.goods.service.GoodsSkuService; import com.hai.goods.service.ShoppingCartService; import com.hai.model.GasPayPriceModel; @@ -76,6 +77,9 @@ public class OrderCreateHandleServiceImpl implements OrderCreateHandleService { @Resource private HighMerchantStoreService storeService; + @Resource + private GoodsPresentService goodsPresentService; + @Resource private HighMerchantService merchantService; @@ -948,6 +952,23 @@ public class OrderCreateHandleServiceImpl implements OrderCreateHandleService { goodsSkuService.decreaseStockNum(createOrderChild.getSkuId(), createOrderChild.getSaleCount()); + + List goodsPresents = goodsPresentService.getPresentList(childOrder.getGoodsId()); + + + if (goodsPresents.size() > 0) { + for (GoodsPresent present : goodsPresents) { + GoodsPresentRecord presentRecord = new GoodsPresentRecord(); + presentRecord.setStatus("0"); + if (present.getType() == 1) { + for (int i = 0; i < present.getNum(); i++) { + couponService.assignOrderStock(present.getSourceId(), childOrder.getChildOrderNo()); + } + } + + } + } + return childOrder; } } diff --git a/hai-service/src/main/java/com/hai/order/service/impl/OrderPaySuccessServiceImpl.java b/hai-service/src/main/java/com/hai/order/service/impl/OrderPaySuccessServiceImpl.java index 1285dd3f..2677bcb9 100644 --- a/hai-service/src/main/java/com/hai/order/service/impl/OrderPaySuccessServiceImpl.java +++ b/hai-service/src/main/java/com/hai/order/service/impl/OrderPaySuccessServiceImpl.java @@ -10,6 +10,7 @@ import com.hai.dao.HighGasOrderPushMapper; import com.hai.entity.*; import com.hai.enum_type.*; import com.hai.goods.service.GoodsOrderExtService; +import com.hai.goods.service.GoodsPresentService; import com.hai.msg.entity.MsgTopic; import com.hai.order.service.OrderPaySuccessService; import com.hai.order.service.OrderService; @@ -73,6 +74,9 @@ public class OrderPaySuccessServiceImpl implements OrderPaySuccessService { @Resource private JinZhuJiaYouService jinZhuJiaYouService; + @Resource + private HighDiscountAgentCodeService highDiscountAgentCodeService; + @Resource private PayloService payloService; @@ -103,6 +107,12 @@ public class OrderPaySuccessServiceImpl implements OrderPaySuccessService { @Resource private OutRechargeOrderService outRechargeOrderService; + @Resource + private GoodsPresentService goodsPresentService; + + @Resource + private HighCouponService highCouponService; + @Override public HighOrder orderPaySuccessHandle(String orderNo, OrderPayType payType, String paySerialNo, BigDecimal payRealPrice, HighUserCard userCard) { HighOrder order = orderService.getOrderDetailByNo(orderNo); @@ -218,7 +228,7 @@ public class OrderPaySuccessServiceImpl implements OrderPaySuccessService { } else if (childOrder.getGoodsType().equals(OrderChildGoodsType.TYPE10.getNumber())) { thirdOrderHandle(order); } else if (childOrder.getGoodsType().equals(OrderChildGoodsType.TYPE11.getNumber())) { - goodsRecharge(order); + goodsRecharge(order , childOrder); } } } @@ -506,11 +516,46 @@ public class OrderPaySuccessServiceImpl implements OrderPaySuccessService { * @Param [order] * @Return void */ - private void goodsRecharge(HighOrder order) { + private void goodsRecharge(HighOrder order , HighChildOrder highChildOrder) throws Exception { GoodsOrder goodsOrder = goodsOrderExtService.findGoodsOrder(order.getOrderNo()); goodsOrder.setUpdateTime(new Date()); goodsOrder.setStatus("1"); goodsOrderExtService.updateGoodsOrder(goodsOrder); + + List goodsPresents = goodsPresentService.getPresentList(highChildOrder.getGoodsId()); + + if (goodsPresents.size() > 0) { + for (GoodsPresent present : goodsPresents) { + GoodsPresentRecord presentRecord = new GoodsPresentRecord(); + presentRecord.setStatus("0"); + if (present.getType() == 1) { + for (int i = 0; i < present.getNum(); i++) { + HighCoupon coupon = highCouponService.getCouponById(present.getSourceId()); + // 支付购买卡券 + couponCodeService.payCoupon(order,highChildOrder,coupon); + } + } + if (present.getType() == 2) { + highDiscountAgentCodeService.giveDiscount(present.getSourceId() , Long.valueOf(present.getNum()), order.getMemId()); + } + + presentRecord.setOrderNo(order.getOrderNo()); + presentRecord.setOrderId(order.getId()); + presentRecord.setChildOrderId(highChildOrder.getOrderId()); + presentRecord.setCreateTime(new Date()); + presentRecord.setNum(presentRecord.getNum()); + presentRecord.setUpdateTime(new Date()); + presentRecord.setType(present.getType()); + presentRecord.setStatus("1"); + presentRecord.setSourceId(present.getSourceId()); + presentRecord.setSourceName(present.getSourceName()); + presentRecord.setOpName("系统赠送"); + presentRecord.setPresentId(present.getId()); + + goodsPresentService.insertPresentRecord(presentRecord); + } + } + } } diff --git a/hai-service/src/main/java/com/hai/service/CommonService.java b/hai-service/src/main/java/com/hai/service/CommonService.java index fc87321f..252c4beb 100644 --- a/hai-service/src/main/java/com/hai/service/CommonService.java +++ b/hai-service/src/main/java/com/hai/service/CommonService.java @@ -12,10 +12,7 @@ import com.hai.entity.ApiCity; import com.hai.entity.SecConfig; import com.hai.entity.SecDictionary; import com.hai.entity.SecRegion; -import com.hai.model.IndexCountModel; -import com.hai.model.LineCountModel; -import com.hai.model.OrderCountModel; -import com.hai.model.OrderSumModel; +import com.hai.model.*; import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket; import org.apache.ibatis.type.BigDecimalTypeHandler; @@ -338,4 +335,6 @@ public interface CommonService { * @Return com.alibaba.fastjson.JSONObject */ JSONObject getIndustry(); + + List getMapStore(String name , Long childId , String latitude , String longitude , Double distance); } diff --git a/hai-service/src/main/java/com/hai/service/HighCouponService.java b/hai-service/src/main/java/com/hai/service/HighCouponService.java index 2ff10e01..8b434316 100644 --- a/hai-service/src/main/java/com/hai/service/HighCouponService.java +++ b/hai-service/src/main/java/com/hai/service/HighCouponService.java @@ -163,4 +163,7 @@ public interface HighCouponService { * @return */ int getMonthlySales(Long couponId); + + + } diff --git a/hai-service/src/main/java/com/hai/service/HighDiscountAgentCodeService.java b/hai-service/src/main/java/com/hai/service/HighDiscountAgentCodeService.java index 3e20f95c..cc217431 100644 --- a/hai-service/src/main/java/com/hai/service/HighDiscountAgentCodeService.java +++ b/hai-service/src/main/java/com/hai/service/HighDiscountAgentCodeService.java @@ -92,7 +92,7 @@ public interface HighDiscountAgentCodeService { */ Integer getSalesDiscount(Long discountAgentId); - List getDiscountAgentCodByLimit(Long discountAgentId , Long num); + List getDiscountAgentCodByLimit(Long discountAgentId , Long num) throws Exception; /** * 优惠券前往使用 @@ -100,4 +100,6 @@ public interface HighDiscountAgentCodeService { * @throws Exception */ void useDiscount(Long discountAgentCodeId) throws Exception; + + void giveDiscount(Long discountAgentId , Long num , Long userId) throws Exception; } diff --git a/hai-service/src/main/java/com/hai/service/impl/BsOrderRebateServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/BsOrderRebateServiceImpl.java index 8d1eafa8..5679074b 100644 --- a/hai-service/src/main/java/com/hai/service/impl/BsOrderRebateServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/BsOrderRebateServiceImpl.java @@ -123,7 +123,7 @@ public class BsOrderRebateServiceImpl implements BsOrderRebateService { public void insertOrderRebate(JSONObject jsonObject) { if (jsonObject.getInteger("productType") ==null - || jsonObject.getLong("userId") == null + || jsonObject.getString("phone") == null || jsonObject.getString("orderNo") == null || jsonObject.getLong("orderId") == null || jsonObject.getString("title") == null @@ -133,7 +133,7 @@ public class BsOrderRebateServiceImpl implements BsOrderRebateService { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "缺少参数!"); } - HighUser highUser = highUserService.findByUserId(jsonObject.getLong("userId")); + HighUser highUser = highUserService.findByPhone(jsonObject.getString("phone")); // 计算返利积分数量 // 查询是否配置返利 Map map = new HashMap<>(); @@ -178,7 +178,7 @@ public class BsOrderRebateServiceImpl implements BsOrderRebateService { } // 拼接分销返利对象 - object.put("userId" , jsonObject.getLong("userId")); + object.put("userId" , highUser.getId()); object.put("orderNo" , jsonObject.getString("orderNo")); object.put("companyId", 2); @@ -187,7 +187,7 @@ public class BsOrderRebateServiceImpl implements BsOrderRebateService { object.put("logoImg" , OrderProductType.getDataByType(jsonObject.getInteger("productType")).getImgUrl()); bsDistributionUserRelService.distributionRebate(object); - highUserService.goldHandle(jsonObject.getLong("userId"), integralNum.intValue(), 1, jsonObject.getInteger("productType"), jsonObject.getLong("orderId"), object.getString("remark") + integralNum); + highUserService.goldHandle(highUser.getId(), integralNum.intValue(), 1, jsonObject.getInteger("productType"), jsonObject.getLong("orderId"), object.getString("remark") + integralNum); // 查询积分返利记录 BsOrderRebate orderRebate = new BsOrderRebate(); @@ -202,8 +202,6 @@ public class BsOrderRebateServiceImpl implements BsOrderRebateService { bsOrderRebateMapper.insert(orderRebate); } - } else { - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "当前未配置积分返利规则!"); } } } diff --git a/hai-service/src/main/java/com/hai/service/impl/CommonServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/CommonServiceImpl.java index 2e84edcc..2b16ec94 100644 --- a/hai-service/src/main/java/com/hai/service/impl/CommonServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/CommonServiceImpl.java @@ -8,6 +8,7 @@ import com.google.gson.JsonObject; import com.hai.common.exception.ErrorCode; import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.SysCode; +import com.hai.common.utils.CoordCommonUtil; import com.hai.common.utils.HttpsUtils; import com.hai.config.CommonSysConst; import com.hai.dao.*; @@ -15,6 +16,7 @@ import com.hai.dao.order.OrderStatisticsMapperExt; import com.hai.entity.*; import com.hai.model.IndexCountModel; import com.hai.model.LineCountModel; +import com.hai.model.MapStoreModel; import com.hai.service.*; import org.apache.commons.lang3.StringUtils; @@ -27,6 +29,7 @@ import javax.annotation.Resource; import java.math.BigDecimal; import java.util.*; import java.util.concurrent.locks.ReentrantLock; +import java.util.stream.Collectors; @Service("iCommonService") @@ -72,6 +75,9 @@ public class CommonServiceImpl implements CommonService { @Resource private SecConfigMapper secConfigMapper; + @Resource + private HighMerchantStoreService merchantStoreService; + @@ -799,4 +805,130 @@ public class CommonServiceImpl implements CommonService { public JSONObject getIndustry() { return HttpsUtils.doGet(CommonSysConst.getSysConfig().getPayPostUrl() + "/common/getIndustry"); } + + @Override + public List getMapStore(String name, Long childId , String latitude , String longitude , Double distance) { + + // 获取支付门店 + Map params = new HashMap<>(); + if (name != null) { + params.put("name", name); + } + if (childId != null) { + params.put("childId", childId); + } + + List list = new ArrayList<>(); + + JSONObject payObject = HttpsUtils.doGet(CommonSysConst.getSysConfig().getPayPostUrl() + "/common/getStoreList", params); + + if (payObject != null) { + JSONArray payArray = payObject.getJSONArray("return_data"); + + + for (Object object : payArray) { + MapStoreModel storeModel = new MapStoreModel(); + JSONObject payData = (JSONObject) object; + storeModel.setId(payData.getLong("id")); + storeModel.setSourceType(1); + storeModel.setLatitude(payData.getString("latitude")); + storeModel.setLongitude(payData.getString("longitude")); +// if (payData.getString("iconPath") == null) { +// storeModel.setLogo(CommonSysConst.getSysConfig().getFilesystem() + "/img/store.png"); +// } else { +// storeModel.setLogo(payData.getString("iconPath")); +// } + storeModel.setIconPath(CommonSysConst.getSysConfig().getFilesystem() + "/img/location.png"); + storeModel.setLogo(CommonSysConst.getSysConfig().getFilesystem() + "/img/store.png"); + storeModel.setRotate(1); + storeModel.setWidth(20); + storeModel.setHeight(20); + storeModel.setAlpha(0.5); + + + JSONObject callout = new JSONObject(); + callout.put("content" , payData.getString("storeName")); + callout.put("address" , payData.getString("address")); + callout.put("color" , "#ffffff"); + callout.put("fontSize" , 14); + callout.put("borderRadius" , 15); + callout.put("borderWidth" , "10"); + callout.put("bgColor" , "#e51860"); + callout.put("display" , "ALWAYS"); + storeModel.setCallout(callout); + + if (payData.getString("latitude") != null && payData.getString("longitude") != null) { + double distanceS = CoordCommonUtil.getDistance(Double.valueOf(payData.getString("latitude")), Double.valueOf(payData.getString("longitude")), Double.valueOf(latitude), Double.valueOf(longitude)); + + double storeDistance = Math.round(distanceS/100d)/10d; + + if (storeDistance <= distance) { + storeModel.setDistance(storeDistance); + list.add(storeModel); + } + + } + } + } + + + + Map map = new HashMap<>(); + map.put("storeName", name); + map.put("industryType", childId); + + // 获取门店列表 + List merchantStores = merchantStoreService.getMerchantStoreList(map); + + if (merchantStores != null) { + for (HighMerchantStore store : merchantStores) { + MapStoreModel storeModel = new MapStoreModel(); + storeModel.setId(store.getId()); + // 1:支付 2:嗨森逛 + storeModel.setSourceType(2); + storeModel.setLatitude(store.getLatitude()); + storeModel.setLongitude(store.getLongitude()); + storeModel.setIconPath(store.getStoreLogo()); + if (store.getStoreLogo() == null) { + storeModel.setLogo(CommonSysConst.getSysConfig().getFilesystem() + "/img/store.png"); + } else { + storeModel.setLogo(store.getStoreLogo()); + } + storeModel.setIconPath(CommonSysConst.getSysConfig().getFilesystem() + "/img/location.png"); + storeModel.setRotate(1); + storeModel.setWidth(20); + storeModel.setHeight(20); + storeModel.setAlpha(0.5); + + JSONObject callout = new JSONObject(); + callout.put("content" , store.getStoreName()); + callout.put("address" , store.getAddress()); + callout.put("color" , "#ffffff"); + callout.put("fontSize" , 14); + callout.put("borderRadius" , 15); + callout.put("borderWidth" , "10"); + callout.put("bgColor" , "#e51860"); + callout.put("display" , "ALWAYS"); + + storeModel.setCallout(callout); + + if (store.getLatitude() != null && store.getLongitude() != null) { + + double distanceS = CoordCommonUtil.getDistance(Double.valueOf(store.getLatitude()), Double.valueOf(store.getLongitude()), Double.valueOf(latitude), Double.valueOf(longitude)); + double storeDistance = Math.round(distanceS/100d)/10d; + if (storeDistance <= distance) { + storeModel.setDistance(storeDistance); + list.add(storeModel); + } + + } + } + + list = list.stream().sorted(Comparator.comparing(MapStoreModel::getDistance)).collect(Collectors.toList()); + + } + + + return list; + } } diff --git a/hai-service/src/main/java/com/hai/service/impl/HighCouponServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighCouponServiceImpl.java index 641e9c8d..e97e7a09 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighCouponServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighCouponServiceImpl.java @@ -597,4 +597,6 @@ public class HighCouponServiceImpl implements HighCouponService { public int getMonthlySales(Long couponId) { return highCouponMapper.getMonthlySales(couponId); } + + } diff --git a/hai-service/src/main/java/com/hai/service/impl/HighDiscountAgentCodeServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighDiscountAgentCodeServiceImpl.java index 49c5b38d..3b0d2322 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighDiscountAgentCodeServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighDiscountAgentCodeServiceImpl.java @@ -11,6 +11,7 @@ import com.hai.config.ChongQingCNPCService; import com.hai.dao.HighCouponCodeMapper; import com.hai.dao.HighCouponCodeOtherMapper; import com.hai.dao.HighDiscountAgentCodeMapper; +import com.hai.dao.HighDiscountUserRelMapper; import com.hai.entity.*; import com.hai.model.DiscountUseConditionModel; import com.hai.model.HighUserModel; @@ -24,6 +25,7 @@ import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import java.util.Calendar; import java.util.Date; import java.util.List; import java.util.Map; @@ -40,6 +42,9 @@ public class HighDiscountAgentCodeServiceImpl implements HighDiscountAgentCodeSe @Resource private HighDiscountAgentCodeMapper highDiscountAgentCodeMapper; + @Resource + private HighDiscountUserRelMapper highDiscountUserRelMapper; + @Resource private HighDiscountAgentRelService highDiscountAgentRelService; @@ -178,8 +183,33 @@ public class HighDiscountAgentCodeServiceImpl implements HighDiscountAgentCodeSe } @Override - public List getDiscountAgentCodByLimit(Long discountAgentId, Long num) { - return highDiscountAgentCodeMapper.getDiscountAgentCodByLimit(discountAgentId,num); + public List getDiscountAgentCodByLimit(Long discountAgentId, Long num) throws Exception { + String key = "give_discount" + discountAgentId; + try { + // 分布式锁占坑 + Boolean lock = redisTemplate.opsForValue().setIfAbsent(key, discountAgentId); + if(lock) { + + List list = highDiscountAgentCodeMapper.getDiscountAgentCodByLimit(discountAgentId,num); + + if (list.size() < num) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "库存不足!"); + } + + return highDiscountAgentCodeMapper.getDiscountAgentCodByLimit(discountAgentId,num); + } else { + // 加锁失败,重试 + Thread.sleep(100); + getDiscountAgentCodByLimit(discountAgentId , num); + } + }catch (Exception e) { + throw e; + } finally { + // 删除key,释放锁 + redisTemplate.delete(key); + } + + return null; } @Override @@ -272,4 +302,51 @@ public class HighDiscountAgentCodeServiceImpl implements HighDiscountAgentCodeSe } } + @Override + public void giveDiscount(Long discountAgentId, Long num, Long userId) throws Exception { + // 查询可以使用的优惠券 + List discountAgentCodeList = getDiscountAgentCodByLimit(discountAgentId , num); + + if (discountAgentCodeList == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "库存不足!"); + } + + HighDiscountAgentRel discountAgentRel = highDiscountAgentRelService.getRelById(discountAgentId); + + HighDiscount discount = highDiscountService.getDiscountById(discountAgentRel.getDiscountId()); + // 优惠券 + for (HighDiscountAgentCode discountAgentCode : discountAgentCodeList) { + + HighDiscountUserRel highDiscountUserRel = new HighDiscountUserRel(); + highDiscountUserRel.setDiscountId(discountAgentRel.getDiscountId()); + highDiscountUserRel.setUserId(userId); + highDiscountUserRel.setAgentId(discountAgentRel.getAgentId()); + highDiscountUserRel.setDiscountAgentCodeId(discountAgentCode.getId()); + highDiscountUserRel.setStatus(1); + highDiscountUserRel.setCreateTime(new Date()); + highDiscountUserRel.setDiscountCompanyId(discount.getCompanyId()); + highDiscountUserRel.setDiscountImg(discount.getDiscountImg()); + highDiscountUserRel.setDiscountName(discount.getDiscountName()); + highDiscountUserRel.setDiscountCondition(discount.getDiscountCondition()); + highDiscountUserRel.setDiscountPrice(discount.getDiscountPrice()); + + // 计算使用有效期 + Calendar userEndTime = Calendar.getInstance(); + userEndTime.setTime(new Date()); + userEndTime.set(Calendar.HOUR_OF_DAY, 23); + userEndTime.set(Calendar.MINUTE, 59); + userEndTime.set(Calendar.SECOND, 59); + userEndTime.add(Calendar.DATE, discount.getEffectiveDay()); + highDiscountUserRel.setUseEndTime(userEndTime.getTime()); + + // 新增优惠券与用户的绑定关系 + highDiscountUserRelMapper.insert(highDiscountUserRel); + + // 修改优惠券二维码状态 + discountAgentCode.setStatus(2); + updateCode(discountAgentCode); + + } + + } } diff --git a/hai-service/src/main/java/com/hai/service/impl/HighMerchantStoreServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighMerchantStoreServiceImpl.java index 51ee9bf0..361087de 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighMerchantStoreServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighMerchantStoreServiceImpl.java @@ -218,6 +218,11 @@ public class HighMerchantStoreServiceImpl implements HighMerchantStoreService { criteria.andStoreKeyEqualTo(MapUtils.getString(map, "storeKey")); } + + if (StringUtils.isNotBlank(MapUtils.getString(map, "industryType"))) { + criteria.andIndustryTypeEqualTo(MapUtils.getInteger(map, "industryType")); + } + if (StringUtils.isNotBlank(MapUtils.getString(map, "storeName"))) { criteria.andStoreNameLike("%" + MapUtils.getString(map, "storeName") + "%"); } @@ -234,6 +239,8 @@ public class HighMerchantStoreServiceImpl implements HighMerchantStoreService { @Override public List getStoreListByLongitude(Map map) { + + List storeList = getMerchantStoreList(map); for (HighMerchantStore store : storeList) { double distance = CoordCommonUtil.getDistance(Double.valueOf(store.getLatitude()), Double.valueOf(store.getLongitude()), Double.valueOf(map.get("latitude").toString()), Double.valueOf(map.get("longitude").toString())); diff --git a/hai-service/src/main/resources/dev/commonConfig.properties b/hai-service/src/main/resources/dev/commonConfig.properties index 6918a75b..c4022fe8 100644 --- a/hai-service/src/main/resources/dev/commonConfig.properties +++ b/hai-service/src/main/resources/dev/commonConfig.properties @@ -124,5 +124,6 @@ logisticsAppKey=5d806a99fbcc48e19717beef11fa1700 logisticsAppSecret=5ba7552b194e4147b7db1c34143e3317 #PAY -#payPostUrl=https://gratia-pay.dctpay.com/crest/ -payPostUrl=http://localhost:9601//crest/ +payPostUrl=https://gratia-pay.dctpay.com/crest/ +filesystem=https://hsgcs.dctpay.com/filesystem/ +#payPostUrl=http://localhost:9601/crest/ diff --git a/v1/src/main/java/com/v1/controller/business/OrderRebateController.java b/v1/src/main/java/com/v1/controller/business/OrderRebateController.java index 37d4e8f8..8fda36af 100644 --- a/v1/src/main/java/com/v1/controller/business/OrderRebateController.java +++ b/v1/src/main/java/com/v1/controller/business/OrderRebateController.java @@ -6,11 +6,9 @@ import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.SysCode; import com.hai.common.utils.ResponseMsgUtil; import com.hai.entity.ApiMerchants; +import com.hai.entity.HighGoldRec; import com.hai.model.ResponseData; -import com.hai.service.ApiIpAddressService; -import com.hai.service.ApiMerchantsService; -import com.hai.service.BsOrderRebateService; -import com.hai.service.SecConfigService; +import com.hai.service.*; import com.hai.service.impl.OutRechargeOrderServiceImpl; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -27,6 +25,7 @@ import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import java.util.Date; import java.util.HashMap; +import java.util.List; import java.util.Map; @Controller @@ -42,9 +41,15 @@ public class OrderRebateController { @Resource private ApiMerchantsService apiMerchantsService; + @Resource + private HighUserService highUserService; + @Resource private SecConfigService secConfigService; + @Resource + private HighGoldRecService highGoldRecService; + @Resource private ApiIpAddressService apiIpAddressService; @@ -85,7 +90,7 @@ public class OrderRebateController { Map map = new HashMap<>(); map.put("apiKey" , object.getString("apiKey")); map.put("merchId" , object.getString("merchId")); - map.put("userId" , object.getString("userId")); + map.put("phone" , object.getString("phone")); map.put("productType" , object.getInteger("productType")); map.put("orderNo" , object.getString("orderNo")); map.put("orderId" , object.getLong("orderId")); @@ -107,4 +112,75 @@ public class OrderRebateController { } } + @RequestMapping(value = "/recycleIntegral", method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "退款回收积分") + public ResponseData recycleIntegral(@RequestBody JSONObject object , HttpServletRequest request ) { + try { + + String ip = ""; + // 有的user可能使用代理,为处理用户使用代理的情况,使用x-forwarded-for + if (request.getHeader("x-forwarded-for") == null) { + ip = request.getRemoteAddr(); + } else { + ip = request.getHeader("x-forwarded-for"); + } + + if (!apiIpAddressService.validationIpAddressLegal(object.getString("merchId") , ip)) { + log.error("getRechargeProduct error!", "非法ip地址,请联系管理人员!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.IP_ERROR, "非法ip地址,请联系管理人员!"); + } + + if (StringUtils.isBlank(object.getString("apiKey")) || + StringUtils.isBlank(object.getString("merchId")) || + StringUtils.isBlank(object.getString("orderId")) || + StringUtils.isBlank(object.getString("orderNo")) || + StringUtils.isBlank(object.getString("productType")) || + StringUtils.isBlank(object.getString("sign")) + ) { + log.error("getRechargeProduct error!", "请求参数校验失败!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR); + } + + ApiMerchants apiMerchants = apiMerchantsService.findByMchId(object.getString("merchId")); + + if (apiMerchants == null) { + log.error("getRechargeProduct error!", "商户号错误!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_NOT_EXIST); + } + + Map map = new HashMap<>(); + map.put("apiKey" , object.getString("apiKey")); + map.put("merchId" , object.getString("merchId")); + map.put("productType" , object.getInteger("productType")); + map.put("orderId" , object.getLong("orderId")); + map.put("orderNo" , object.getString("orderNo")); + + + if (!secConfigService.isSignVerify(map , object.getString("sign"))) { + log.error("getRechargeProduct error!", "签名校验失败!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.SIGN_VERIFY); + } + + + Map mapGold = new HashMap<>(); + mapGold.put("goldType", 1); + mapGold.put("resType", object.getInteger("productType")); + mapGold.put("resId", object.getLong("orderId")); + + List goldRecs = highGoldRecService.getGoldRec(mapGold); + + for (HighGoldRec goldRec : goldRecs) { + String remark = "订单" + object.getString("orderNo") + "退款,退还积分:" + goldRec.getGold(); + // 积分退款 + highUserService.goldHandle(goldRec.getUserId(), goldRec.getGold(),1, object.getInteger("productType"), object.getLong("orderId") , remark); + } + + return ResponseMsgUtil.success("操作成功"); + } catch (Exception e) { + log.error("HighOrderController --> getBackendToken() error!", e); + return ResponseMsgUtil.exception(e); + } + } + }