diff --git a/mallinkCallback/src/main/java/com/iformall/controller/callback/WxBusinessOrderController.java b/mallinkCallback/src/main/java/com/iformall/controller/callback/WxBusinessOrderController.java index bd169373a..5fc4bce6c 100644 --- a/mallinkCallback/src/main/java/com/iformall/controller/callback/WxBusinessOrderController.java +++ b/mallinkCallback/src/main/java/com/iformall/controller/callback/WxBusinessOrderController.java @@ -147,8 +147,11 @@ public class WxBusinessOrderController extends BaseController { logger.error("微信商圈通知---时间转换异常"); resultMap.put("code","FAIL"); return resultMap; + } catch (Exception e){ + e.printStackTrace(); + resultMap.put("code","FAIL"); + return resultMap; } - } diff --git a/mallinkPublicApi/src/main/java/com/iformall/controller/BaseController.java b/mallinkPublicApi/src/main/java/com/iformall/controller/BaseController.java index 56a157ed5..fb8f2f2a6 100644 --- a/mallinkPublicApi/src/main/java/com/iformall/controller/BaseController.java +++ b/mallinkPublicApi/src/main/java/com/iformall/controller/BaseController.java @@ -1,5 +1,7 @@ package com.iformall.controller; +import com.iformall.domain.po.base.TenantEntity; +import com.iformall.utils.Constant; import com.iformall.utils.IPUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -49,6 +51,22 @@ public class BaseController { }); } + public String getAppId() { + HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); + String appId = (String) request.getAttribute(Constant.APP_Id); + return appId; + } + + public TenantEntity getTenantInfo() { + HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); + String tenantId = (String) request.getAttribute(Constant.TENANT_ID); + String parentTenantId = (String) request.getAttribute(Constant.PARENT_TENANT_ID); + TenantEntity tenantEntity = new TenantEntity() ; + tenantEntity.setTenantId(tenantId); + tenantEntity.setParentTenantId(parentTenantId); + return tenantEntity; + } + public String getIpAddr() { HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); String ipaddress = IPUtil.getIpAddr(request); diff --git a/mallinkPublicApi/src/main/java/com/iformall/controller/UserBasicInfoController.java b/mallinkPublicApi/src/main/java/com/iformall/controller/UserBasicInfoController.java index 216968e5a..0f6b90c6f 100644 --- a/mallinkPublicApi/src/main/java/com/iformall/controller/UserBasicInfoController.java +++ b/mallinkPublicApi/src/main/java/com/iformall/controller/UserBasicInfoController.java @@ -4,8 +4,10 @@ import com.alibaba.fastjson.JSON; import com.iformall.common.ErrorCode; import com.iformall.common.ResultData; import com.iformall.domain.po.WxCUserBasicInfo; +import com.iformall.domain.po.WxLevelConfig; import com.iformall.domain.po.base.TenantEntity; import com.iformall.service.WxCUserBasicInfoService; +import com.iformall.service.WxLevelConfigService; import com.iformall.utils.HttpUtil; import com.iformall.utils.sign.SignUtils; import io.swagger.annotations.Api; @@ -19,6 +21,7 @@ import org.springframework.web.bind.annotation.*; import java.util.Date; import java.util.HashMap; +import java.util.List; import java.util.Map; @RestController @@ -31,6 +34,9 @@ public class UserBasicInfoController extends BaseController { @Autowired private WxCUserBasicInfoService wxCUserBasicInfoService; + @Autowired + private WxLevelConfigService wxLevelConfigService; + /** * * @param @@ -47,14 +53,28 @@ public class UserBasicInfoController extends BaseController { if(!phone.matches("^1[0-9]{10}$")){ return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"手机号格式不正确"); } - TenantEntity tenantEntity = new TenantEntity(); + + TenantEntity tenantEntity = getTenantInfo(); + WxCUserBasicInfo userBasicInfo = wxCUserBasicInfoService.registerByPhone(tenantEntity, phone); + List levelList = wxLevelConfigService.getByTenantInfo(tenantEntity); + userBasicInfo.setLecelList(levelList); + userBasicInfo.setLevel(WxLevelConfigService.DEFAULT_LEVEL); + if(userBasicInfo.getPoins() != null && userBasicInfo.getPoins() > 0){ + for (WxLevelConfig levelConfig : levelList) { + if (userBasicInfo.getPoins() >= levelConfig.getPoints()) { + userBasicInfo.setLevel(levelConfig.getLevel()); + } + } + } + return new ResultData(userBasicInfo); } + diff --git a/mallinkPublicApi/src/main/java/com/iformall/controller/UserBusinessOrderController.java b/mallinkPublicApi/src/main/java/com/iformall/controller/UserBusinessOrderController.java deleted file mode 100644 index 868b10da1..000000000 --- a/mallinkPublicApi/src/main/java/com/iformall/controller/UserBusinessOrderController.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.iformall.controller; - -import com.iformall.common.ResultData; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import java.util.Map; - -@RestController -@RequestMapping("api/userBusiness") -@Api(description = "会员交易相关接口") -public class UserBusinessOrderController extends BaseController { - - private final Logger logger = LoggerFactory.getLogger(this.getClass()); - - - /** - * - * @param - * @return - */ - @PostMapping("/order") - @ApiOperation(value = "订单", notes = "") - public ResultData createOrder(@RequestBody Map map) { - logger.info("UserBusinessOrderController >>>>>>>>>>>> createOrder >>>>>>>>>>>>>"+map.toString()); - - - return new ResultData(); - } - - /** - * - * @param - * @return - */ - @PostMapping("/orderRefund") - @ApiOperation(value = "取消订单", notes = "") - public ResultData orderRefund(@RequestBody Map map) { - logger.info("UserBusinessOrderController >>>>>>>>>>>> orderRefund >>>>>>>>>>>>>"+map.toString()); - - - return new ResultData(); - } - - - /** - * - * @param - * @return - */ - @PostMapping("/pointDeduction") - @ApiOperation(value = "积分抵扣", notes = "") - public ResultData pointDeduction(@RequestBody Map map) { - logger.info("UserBusinessOrderController >>>>>>>>>>>> pointDeduction >>>>>>>>>>>>>"+map.toString()); - - - return new ResultData(); - } - -} diff --git a/mallinkPublicApi/src/main/java/com/iformall/controller/UserThirdCircleOrderController.java b/mallinkPublicApi/src/main/java/com/iformall/controller/UserThirdCircleOrderController.java new file mode 100644 index 000000000..498baf010 --- /dev/null +++ b/mallinkPublicApi/src/main/java/com/iformall/controller/UserThirdCircleOrderController.java @@ -0,0 +1,229 @@ +package com.iformall.controller; + +import com.iformall.common.ErrorCode; +import com.iformall.common.ResultData; +import com.iformall.domain.po.WxThirdPartyOrders; +import com.iformall.enums.EnumThirdOrderType; +import com.iformall.exception.MallinkException; +import com.iformall.service.WxThirdPartyOrdersService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Map; + +@RestController +@RequestMapping("api/thirdCircle") +@Api(description = "会员交易相关接口") +public class UserThirdCircleOrderController extends BaseController { + + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + + private final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + + @Autowired + WxThirdPartyOrdersService thirdPartyOrdersService; + + /** + * + * @param + * @return + */ + @PostMapping("/order") + @ApiOperation(value = "订单", notes = "") + public ResultData createOrder(@RequestBody Map map) { + logger.info("UserThirdCircleOrderController >>>>>>>>>>>> createOrder >>>>>>>>>>>>>"+map.toString()); + + String transactionId = (String) map.get("transactionId");//***订单Id + Long shopNumber = (Long) map.get("shopNumber");//***门店唯一标识 对应双方平台门店 + String shopName = (String) map.get("shopName");//门店名称 + Long userNumber = (Long) map.get("userNumber");//***会员Id + String userPhone = (String) map.get("userPhone");//会员手机号 + String timeEnd = (String) map.get("timeEnd");//***付款时间(yyyy-MM-dd HH:mm:ss) + Integer amount = (Integer) map.get("amount");//***付款金额(分) + String summary = (String) map.get("summary");//付款摘要 + + if(StringUtils.isBlank(transactionId)){ + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"transactionId为空"); + } + if(shopNumber == null){ + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"shopNumber为空"); + } + if(userNumber == null){ + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"userNumber为空"); + } + if(StringUtils.isNotBlank(userPhone) && !userPhone.matches("^1[0-9]{10}$")){ + return new ResultData(ErrorCode.SYS_PARAMETER_ERROR,"userPhone格式不正确"); + } + if(timeEnd == null){ + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"timeEnd为空"); + } + Date timeEndDate = null; + try { + timeEndDate = sdf.parse(timeEnd); + } catch (ParseException e) { + return new ResultData(ErrorCode.SYS_PARAMETER_ERROR,"timeEnd格式不正确"); + } + if(amount == null){ + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"amount为空"); + } + + WxThirdPartyOrders thirdPartyOrders = new WxThirdPartyOrders(); + thirdPartyOrders.updateTenantInfo(getTenantInfo()); + thirdPartyOrders.setSourceAppId(getAppId()); + + thirdPartyOrders.setTransactionId(transactionId); + thirdPartyOrders.setShopNumber(String.valueOf(shopNumber)); + thirdPartyOrders.setShopName(shopName); + thirdPartyOrders.setUserNumber(String.valueOf(userNumber)); + thirdPartyOrders.setUserPhone(userPhone); + thirdPartyOrders.setTimeEnd(timeEndDate); + thirdPartyOrders.setAmount(amount); + thirdPartyOrders.setSummary(summary); + try{ + thirdPartyOrdersService.createOrder(thirdPartyOrders); + }catch(MallinkException e){ + logger.error(e.getMessage()); + return new ResultData(e.getErrorCode(), e.getMessage()); + }catch(Exception e){ + e.printStackTrace(); + return new ResultData(ErrorCode.SYS_SERVER_ERROR); + } + + return new ResultData(); + } + + /** + * + * @param + * @return + */ + @PostMapping("/orderRefund") + @ApiOperation(value = "退款", notes = "") + public ResultData orderRefund(@RequestBody Map map) { + logger.info("UserThirdCircleOrderController >>>>>>>>>>>> orderRefund >>>>>>>>>>>>>"+map.toString()); + + String transactionId = (String) map.get("transactionId");//***订单Id + String refundTime = (String) map.get("refundTime");//***退款时间(yyyy-MM-dd HH:mm:ss) + String refundSummary = (String) map.get("refundSummary");//退款摘要 + Integer refundAmount = (Integer) map.get("refundAmount");//退款金额(分) + String refundId = (String) map.get("refundId");//退款Id + + if(StringUtils.isBlank(transactionId)){ + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"transactionId为空"); + } + if(refundTime == null){ + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"refundTime为空"); + } + Date refundTimeDate = null; + try { + refundTimeDate = sdf.parse(refundTime); + } catch (ParseException e) { + return new ResultData(ErrorCode.SYS_PARAMETER_ERROR,"timeEnd格式不正确"); + } + + WxThirdPartyOrders thirdPartyOrders = new WxThirdPartyOrders(); + thirdPartyOrders.updateTenantInfo(getTenantInfo()); + thirdPartyOrders.setSourceAppId(getAppId()); + thirdPartyOrders.setSourceType(EnumThirdOrderType.RMB_PAY.getCode()); + + thirdPartyOrders.setTransactionId(transactionId); + thirdPartyOrders.setRefundTime(refundTimeDate); + thirdPartyOrders.setRefundSummary(refundSummary); + thirdPartyOrders.setRefundAmount(refundAmount); + thirdPartyOrders.setRefundId(refundId); + + try{ + thirdPartyOrdersService.updateRefundOrder(thirdPartyOrders); + }catch(MallinkException e){ + logger.error(e.getMessage()); + return new ResultData(e.getErrorCode(), e.getMessage()); + }catch(Exception e){ + e.printStackTrace(); + return new ResultData(ErrorCode.SYS_SERVER_ERROR); + } + + return new ResultData(); + } + + + /** + * + * @param + * @return + */ + @PostMapping("/pointDeduction") + @ApiOperation(value = "积分抵扣", notes = "") + public ResultData pointDeduction(@RequestBody Map map) { + logger.info("UserThirdCircleOrderController >>>>>>>>>>>> pointDeduction >>>>>>>>>>>>>"+map.toString()); + + String transactionId = (String) map.get("transactionId");//***订单Id + Long shopNumber = (Long) map.get("shopNumber");//***门店唯一标识 对应双方平台门店 + String shopName = (String) map.get("shopName");//门店名称 + Long userNumber = (Long) map.get("userNumber");//***会员Id + String userPhone = (String) map.get("userPhone");//会员手机号 + String timeEnd = (String) map.get("timeEnd");//***抵扣时间 + Integer amount = (Integer) map.get("amount");//***积分数量 + String summary = (String) map.get("summary");//付款摘要 + + if(StringUtils.isBlank(transactionId)){ + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"transactionId为空"); + } + if(shopNumber == null){ + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"shopNumber为空"); + } + if(userNumber == null){ + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"userNumber为空"); + } + if(StringUtils.isNotBlank(userPhone) && !userPhone.matches("^1[0-9]{10}$")){ + return new ResultData(ErrorCode.SYS_PARAMETER_ERROR,"userPhone格式不正确"); + } + if(timeEnd == null){ + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"timeEnd为空"); + } + Date timeEndDate = null; + try { + timeEndDate = sdf.parse(timeEnd); + } catch (ParseException e) { + return new ResultData(ErrorCode.SYS_PARAMETER_ERROR,"timeEnd格式不正确"); + } + if(amount == null){ + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"amount为空"); + } + + WxThirdPartyOrders thirdPartyOrders = new WxThirdPartyOrders(); + thirdPartyOrders.updateTenantInfo(getTenantInfo()); + thirdPartyOrders.setSourceAppId(getAppId()); + + thirdPartyOrders.setTransactionId(transactionId); + thirdPartyOrders.setShopNumber(String.valueOf(shopNumber)); + thirdPartyOrders.setShopName(shopName); + thirdPartyOrders.setUserNumber(String.valueOf(userNumber)); + thirdPartyOrders.setUserPhone(userPhone); + thirdPartyOrders.setTimeEnd(timeEndDate); + thirdPartyOrders.setAmount(amount); + thirdPartyOrders.setSummary(summary); + try{ + thirdPartyOrdersService.pointDeduction(thirdPartyOrders); + return new ResultData(); + }catch(MallinkException e){ + logger.error(e.getMessage()); + return new ResultData(e.getErrorCode(), e.getMessage()); + }catch(Exception e){ + e.printStackTrace(); + return new ResultData(ErrorCode.SYS_SERVER_ERROR); + } + } + +} diff --git a/mallinkPublicApi/src/main/java/com/iformall/interceptor/AuthorizationInterceptor.java b/mallinkPublicApi/src/main/java/com/iformall/interceptor/AuthorizationInterceptor.java index 77c4af044..a35f0e1f1 100644 --- a/mallinkPublicApi/src/main/java/com/iformall/interceptor/AuthorizationInterceptor.java +++ b/mallinkPublicApi/src/main/java/com/iformall/interceptor/AuthorizationInterceptor.java @@ -56,6 +56,7 @@ public class AuthorizationInterceptor extends HandlerInterceptorAdapter { if(apiConfig == null){ throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"非法请求"); } + request.setAttribute(Constant.APP_Id, apiConfig.getAppId()); request.setAttribute(Constant.TENANT_ID, apiConfig.getTenantId()); request.setAttribute(Constant.PARENT_TENANT_ID, apiConfig.getParentTenantId()); diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxThirdPartyOrders.java b/mallinkService/src/main/java/com/iformall/domain/po/WxThirdPartyOrders.java index 4b416f66a..63083c1c8 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxThirdPartyOrders.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxThirdPartyOrders.java @@ -21,6 +21,9 @@ public class WxThirdPartyOrders extends TenantEntity { @io.swagger.annotations.ApiModelProperty(value="来源(wx_third_party_api)",name="sourceAppId") private String sourceAppId; + @io.swagger.annotations.ApiModelProperty(value="1:RMB订单;2:积分订单",name="sourceType") + private Integer sourceType; + @io.swagger.annotations.ApiModelProperty(value="门店名称",name="shopName") private String shopName; diff --git a/mallinkService/src/main/java/com/iformall/enums/EnumThirdOrderType.java b/mallinkService/src/main/java/com/iformall/enums/EnumThirdOrderType.java new file mode 100644 index 000000000..9bf5e65b4 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/enums/EnumThirdOrderType.java @@ -0,0 +1,38 @@ +package com.iformall.enums; + + +/** + * @author gongbiao + */ + +public enum EnumThirdOrderType { + + RMB_PAY(1,"rmb订单"), + CREDIT_PAY(2,"积分订单") + ; + + public static EnumThirdOrderType getEnum(Integer code) { + for (EnumThirdOrderType value : values()) { + if (value.getCode().equals(code)) { + return value; + } + } + return null; + } + + private Integer code; + private String message; + + EnumThirdOrderType(Integer code, String message) { + this.code = code; + this.message = message; + } + + public Integer getCode() { + return code; + } + + public String getMessage() { + return message; + } +} diff --git a/mallinkService/src/main/java/com/iformall/service/WxThirdPartyOrdersService.java b/mallinkService/src/main/java/com/iformall/service/WxThirdPartyOrdersService.java index 5683ed324..8cced583d 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxThirdPartyOrdersService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxThirdPartyOrdersService.java @@ -46,5 +46,9 @@ public interface WxThirdPartyOrdersService { */ void updateRefundPoints(WxThirdPartyOrders record); - + /** + * 积分抵扣 + * @param record + */ + void pointDeduction(WxThirdPartyOrders record); } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxBusinessCircleOrderServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxBusinessCircleOrderServiceImpl.java index c675720ae..74d4007de 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxBusinessCircleOrderServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxBusinessCircleOrderServiceImpl.java @@ -90,7 +90,6 @@ public class WxBusinessCircleOrderServiceImpl implements WxBusinessCircleOrderSe wxBusinessCircleOrderMapper.insertNoticeOrder(record); this.sendMessage(record,EnumYesOrNo.NO.getCode()); - } } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCUserBasicInfoServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCUserBasicInfoServiceImpl.java index 684c839f5..d5cc3aabb 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCUserBasicInfoServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCUserBasicInfoServiceImpl.java @@ -650,16 +650,6 @@ public class WxCUserBasicInfoServiceImpl implements WxCUserBasicInfoService,IExc basicInfo.setPhone(phone); this.save(basicInfo); } - List levelList = wxLevelConfigService.getByTenantInfo(tenantEntity); - basicInfo.setLecelList(levelList); - basicInfo.setLevel(WxLevelConfigService.DEFAULT_LEVEL); - if(basicInfo.getPoins() != null && basicInfo.getPoins() > 0){ - for (WxLevelConfig levelConfig : levelList) { - if (basicInfo.getPoins() >= levelConfig.getPoints()) { - basicInfo.setLevel(levelConfig.getLevel()); - } - } - } return basicInfo; diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCreditHistoryServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCreditHistoryServiceImpl.java index 9c2bc5332..7d1e81245 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCreditHistoryServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCreditHistoryServiceImpl.java @@ -248,7 +248,7 @@ public class WxCreditHistoryServiceImpl implements WxCreditHistoryService { } if (wxCUserBasicInfo != null && EnumCreditLockedStatus.CLOSE.getCode().equals(wxCUserBasicInfo.getStatus())) { logger.info(ErrorCode.MEMBER_IS_LOCKED.getMessage()); - return record; + throw new MallinkException(ErrorCode.MEMBER_IS_LOCKED); } if (StringUtils.isNotEmpty(record.getSpendStr())) { record.setSpend(new BigDecimal(record.getSpendStr()).multiply(new BigDecimal(100)).intValue()); diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxGameServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxGameServiceImpl.java index 0d8dd703c..a723be87c 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxGameServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxGameServiceImpl.java @@ -36,6 +36,7 @@ import org.springframework.transaction.annotation.Transactional; import java.util.*; import java.util.concurrent.TimeUnit; +import static org.springframework.transaction.annotation.Propagation.REQUIRED; import static org.springframework.transaction.annotation.Propagation.REQUIRES_NEW; @Service @@ -507,7 +508,7 @@ public class WxGameServiceImpl implements WxGameService { } - @Transactional(propagation = REQUIRES_NEW ,rollbackFor = Exception.class) + @Transactional(propagation = REQUIRED ,rollbackFor = Exception.class) @Override public ResultData cridetLuckDraw(Long gameId, Long userId) { WxGame wxGame = wxGameMapper.selectById(gameId); diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxThirdPartyOrdersServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxThirdPartyOrdersServiceImpl.java index f72a1b71f..3d0eb4518 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxThirdPartyOrdersServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxThirdPartyOrdersServiceImpl.java @@ -2,25 +2,29 @@ package com.iformall.service.impl; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; +import com.iformall.common.ErrorCode; import com.iformall.common.IdWorker; import com.iformall.domain.po.WxCUserBasicInfo; +import com.iformall.domain.po.WxCreditHistory; import com.iformall.domain.po.WxMerchant; import com.iformall.domain.po.WxThirdPartyOrders; import com.iformall.domain.po.msg.FmInsideCircleOrderMsg; import com.iformall.enums.*; +import com.iformall.exception.MallinkException; import com.iformall.mapper.WxThirdPartyOrdersMapper; import com.iformall.mq.MqBaseProducer; -import com.iformall.service.WxCUserBasicInfoService; -import com.iformall.service.WxCUserService; -import com.iformall.service.WxMerchantService; -import com.iformall.service.WxThirdPartyOrdersService; +import com.iformall.service.*; +import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.util.Date; +import static org.springframework.transaction.annotation.Propagation.REQUIRED; + @Service public class WxThirdPartyOrdersServiceImpl implements WxThirdPartyOrdersService { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @@ -40,6 +44,9 @@ public class WxThirdPartyOrdersServiceImpl implements WxThirdPartyOrdersService @Autowired MqBaseProducer mqBaseProducer; + @Autowired + WxCreditHistoryService wxCreditHistoryService; + @Override public PageInfo listAsPage(WxThirdPartyOrders record, Integer pageIndex, Integer pageSize) { @@ -67,6 +74,7 @@ public class WxThirdPartyOrdersServiceImpl implements WxThirdPartyOrdersService WxThirdPartyOrders byTransactionId = wxThirdPartyOrdersMapper.getByTransactionId(record); if(byTransactionId != null){ logger.error("--第三方付款--通知消息已存在---byTransactionId="+byTransactionId.getTransactionId()); + throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "订单数据已存在"); }else{ Date now = new Date(); final IdWorker idWorker = IdWorker.get(); @@ -74,21 +82,21 @@ public class WxThirdPartyOrdersServiceImpl implements WxThirdPartyOrdersService record.setCreateTime(now); record.setUpdateTime(now); + record.setSourceType(EnumThirdOrderType.RMB_PAY.getCode()); + //TODO 第三方获取门店(标识可能发生变化) WxMerchant wxMerchant = wxMerchantService.getById(Long.parseLong(record.getShopNumber())); if(wxMerchant != null){ record.setMerchantId(wxMerchant.getId()); }else{ - logger.error("--第三方付款通知消息未找到门店--shopName="+record.getShopName()+"&shopNumber="+record.getShopNumber()); + logger.info("--第三方付款通知消息未找到门店--shopName="+record.getShopName()+"&shopNumber="+record.getShopNumber()); } WxCUserBasicInfo basicInfo = null; - try{ - basicInfo = wxCUserBasicInfoService.getById(Long.parseLong(record.getUserNumber()), record.getFinalTenantId()); - if(basicInfo == null){ - basicInfo = wxCUserBasicInfoService.registerByPhone(record, record.getUserPhone()); - } - }catch(Exception e){} + basicInfo = wxCUserBasicInfoService.getById(Long.parseLong(record.getUserNumber()), record.getFinalTenantId()); + if(basicInfo == null){ + basicInfo = wxCUserBasicInfoService.registerByPhone(record, record.getUserPhone()); + } if(basicInfo != null){ record.setCUserId(basicInfo.getId()); @@ -126,8 +134,10 @@ public class WxThirdPartyOrdersServiceImpl implements WxThirdPartyOrdersService WxThirdPartyOrders byTransactionId = this.getByTransactionId(record.getTransactionId(),record.getTenantId()); if(byTransactionId == null){ logger.error("--第三方退款--付款消息未找到--transactionId="+record.getTransactionId()); + throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "付款消息未找到"); }else if(byTransactionId.getIsRefund().equals(EnumYesOrNo.YES.getCode())){ logger.error("--第三方退款--已是退款状态--transactionId="+record.getTransactionId()); + throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "已是退款状态"); }else{ Date now = new Date(); record.setId(byTransactionId.getId()); @@ -150,5 +160,57 @@ public class WxThirdPartyOrdersServiceImpl implements WxThirdPartyOrdersService wxThirdPartyOrdersMapper.updateRefundPoints(record); } + @Transactional(propagation = REQUIRED ,rollbackFor = Exception.class) + @Override + public void pointDeduction(WxThirdPartyOrders record) { + + WxCUserBasicInfo basicInfo = null; + if(StringUtils.isNotBlank(record.getUserNumber())){ + basicInfo = wxCUserBasicInfoService.getById(Long.parseLong(record.getUserNumber()), record.getFinalTenantId()); + } + if(basicInfo == null){ + logger.error("--第三方积分订单--未找到用户---userId="+record.getUserNumber()); + throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "未找到用户"); + } + + record.setCUserId(basicInfo.getId()); + + WxThirdPartyOrders byTransactionId = wxThirdPartyOrdersMapper.getByTransactionId(record); + if(byTransactionId != null){ + logger.error("--第三方积分订单--数据已存在---byTransactionId="+byTransactionId.getTransactionId()); + throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "订单数据已存在"); + }else{ + Date now = new Date(); + final IdWorker idWorker = IdWorker.get(); + record.setId(idWorker.nextId()); + record.setCreateTime(now); + record.setUpdateTime(now); + + record.setSourceType(EnumThirdOrderType.CREDIT_PAY.getCode()); + + //TODO 第三方获取门店(标识可能发生变化) + WxMerchant wxMerchant = wxMerchantService.getById(Long.parseLong(record.getShopNumber())); + if(wxMerchant != null){ + record.setMerchantId(wxMerchant.getId()); + }else{ + logger.info("--第三方付款通知消息未找到门店--shopName="+record.getShopName()+"&shopNumber="+record.getShopNumber()); + } + + WxCreditHistory wxCreditHistory = new WxCreditHistory(); + wxCreditHistory.setTenantId(record.getFinalTenantId()); + wxCreditHistory.setCUserId(basicInfo.getId()); + wxCreditHistory.setOperatorId(basicInfo.getId()); + wxCreditHistory.setOperatorType(EnumUserType.THIRD_CIRCLE.getCode()); + wxCreditHistory.setCreditNum(record.getAmount()); + wxCreditHistory.setCreditType(EnumScoreType.CHANGE_CREDIT.getCode()); + wxCreditHistory.setChangePurpose("第三方消费抵扣{}"+record.getSummary()); + wxCreditHistory.setCouponId(record.getId()); + wxCreditHistoryService.saveOrUpdate(wxCreditHistory,record.getTenantId()); + + wxThirdPartyOrdersMapper.insertNoticeOrder(record); + } + + } + } diff --git a/mallinkService/src/main/java/com/iformall/utils/Constant.java b/mallinkService/src/main/java/com/iformall/utils/Constant.java index 9ca94a7ec..3dc6d858b 100644 --- a/mallinkService/src/main/java/com/iformall/utils/Constant.java +++ b/mallinkService/src/main/java/com/iformall/utils/Constant.java @@ -50,6 +50,8 @@ public class Constant { public static final String TENANT_ID = "TENANT_ID"; public static final String PARENT_TENANT_ID = "PARENT_TENANT_ID"; public static final String REQUEST_C_USER_KEY = "REQUEST_C_USER"; + + public static final String APP_Id = "APP_Id"; public static final String LOGIN_B_USER_KEY = "LOGIN_B_USER_KEY"; diff --git a/mallinkService/src/main/resources/mapper/WxThirdPartyOrdersMapper.xml b/mallinkService/src/main/resources/mapper/WxThirdPartyOrdersMapper.xml index 509a66a76..a2d12ef39 100644 --- a/mallinkService/src/main/resources/mapper/WxThirdPartyOrdersMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxThirdPartyOrdersMapper.xml @@ -6,6 +6,8 @@ + + @@ -37,7 +39,7 @@ - `id`, `tenant_id`, `parent_tenant_id`, `source_app_id`, `shop_name`, `shop_number`, + `id`, `tenant_id`, `parent_tenant_id`, `source_app_id`, `source_type`, `shop_name`, `shop_number`, `user_phone`, `user_number`, `time_end`, `amount`, `transaction_id`, `summary`, `create_time`, `update_time`, `merchant_id`, `c_user_id`, `earn_points`, `increased_points`, `points_update_time`, @@ -63,6 +65,10 @@ and `source_app_id` = #{sourceAppId} + + and `source_type` = #{sourceType} + + and `shop_name` like concat('%', #{shopName},'%') @@ -148,12 +154,12 @@ INSERT INTO wx_business_circle_order ( - `id`, `tenant_id`, `parent_tenant_id`, `source_app_id`,`shop_name`, `shop_number`, + `id`, `tenant_id`, `parent_tenant_id`, `source_app_id`,`source_type`,`shop_name`, `shop_number`, `user_phone`, `user_number`, `time_end`, `amount`, `transaction_id`, `summary`, `create_time`, `update_time`, `merchant_id`, `c_user_id`, `earn_points`, `is_refund` ) VALUES( - #{id},#{tenantId},#{parentTenantId},#{sourceAppId},#{shopName},#{shopNumber}, + #{id},#{tenantId},#{parentTenantId},#{sourceAppId},#{sourceType},#{shopName},#{shopNumber}, #{userPhone},#{userNumber},#{timeEnd},#{amount},#{transactionId},#{summary}, #{createTime},#{updateTime}, #{merchantId},#{cUserId},0,0 );