修改优惠券包赠送问题

new-dev
袁野 1 year ago
parent b68ca163ac
commit f06272ddcc
  1. 2
      hai-bweb/src/main/java/com/bweb/controller/HighTestController.java
  2. 11
      hai-order/src/main/java/com/web/controller/OrderController.java
  3. 10
      hai-service/src/main/java/com/hai/service/HighDiscountPackageService.java
  4. 93
      hai-service/src/main/java/com/hai/service/impl/HighDiscountPackageServiceImpl.java
  5. 8
      hai-service/src/main/java/com/hai/service/impl/OutRechargeOrderServiceImpl.java
  6. 1
      v1/src/main/java/com/v1/config/AuthConfig.java
  7. 114
      v1/src/main/java/com/v1/controller/business/DiscountController.java

File diff suppressed because one or more lines are too long

@ -7,7 +7,6 @@ import com.hai.common.exception.ErrorCode;
import com.hai.common.exception.ErrorHelp;
import com.hai.common.exception.SysCode;
import com.hai.common.security.UserCenter;
import com.hai.common.utils.BaiduUtils;
import com.hai.common.utils.ResponseMsgUtil;
import com.hai.entity.*;
import com.hai.goods.service.DeliveryAddressService;
@ -18,30 +17,20 @@ import com.hai.model.HighUserModel;
import com.hai.model.ResponseData;
import com.hai.order.model.CreateOrderChildModel;
import com.hai.order.model.CreateOrderModel;
import com.hai.order.model.GoodsChildOrderExtModel;
import com.hai.order.service.OrderPaySuccessService;
import com.hai.order.service.OrderService;
import com.hai.order.type.OrderChildGoodsType;
import com.hai.order.type.OrderChildStatus;
import com.hai.order.type.OrderPayType;
import com.hai.order.type.OrderStatus;
import com.hai.order.utils.OrderUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Controller

@ -107,4 +107,14 @@ public interface HighDiscountPackageService {
*/
String giveAway(Long packageId, List<String> phoneList) throws Exception;
/**
* @Author Sum1Dream
* @Name giveAway
* @Description // 单个手机号赠送优惠券包
* @Date 20:01 2023/6/5
* @Param [packageId, phone, sourceType, sourceId]
* @Return java.lang.String
*/
String giveAway(Long packageId, String phone , Integer sourceType , String sourceId) throws Exception;
}

@ -448,4 +448,97 @@ public class HighDiscountPackageServiceImpl implements HighDiscountPackageServic
return serialNum;
}
@Override
public String giveAway(Long packageId, String phone, Integer sourceType, String sourceId) {
// 查询优惠券包
HighDiscountPackage discountPackage = findDiscountPackageById(packageId.intValue());
if (discountPackage == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "没有找到券包信息");
}
if (!discountPackage.getStatus().equals(1)) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "券包状态错误");
}
// 查询卷包库存
Long stockCount = discountPackageActualService.getDiscountPackageNum(packageId.intValue());
if (stockCount.intValue() < 1) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "卷包库存不足");
}
// 赠送记录流水
String serialNum = System.currentTimeMillis()+"";
HighDiscountPackageDeliver discountPackageDeliver = new HighDiscountPackageDeliver();
discountPackageDeliver.setPackageId(packageId);
discountPackageDeliver.setPackageName(discountPackage.getTitle());
discountPackageDeliver.setSerialNumber(serialNum);
discountPackageDeliver.setSourceId(sourceId);
discountPackageDeliver.setSourceType(sourceType);
discountPackageDeliverService.insertDeliver(discountPackageDeliver);
new Thread(() -> {
int alreadyProcessedNum = 0;
try {
// 根据手机号查询用户
HighUser highUser = highUserService.findByPhone(phone);
if (highUser != null) {
Map<String, Object> freeMap = new HashMap<>();
freeMap.put("discountPackageId", packageId);
freeMap.put("userId", highUser.getId());
freeMap.put("userPhone", highUser.getPhone());
HighDiscountPackageActual packageActual = freeUserDiscountPackage(freeMap);
HighDiscountPackageDeliverUser deliverUser = new HighDiscountPackageDeliverUser();
deliverUser.setPackageDeliverId(discountPackageDeliver.getId());
deliverUser.setSerialNumber(System.currentTimeMillis()+"");
deliverUser.setPackageId(packageId);
deliverUser.setPackageName(discountPackage.getTitle());
deliverUser.setPackageActualId(packageActual.getId().longValue());
deliverUser.setUserId(highUser.getId());
deliverUser.setUserPhone(highUser.getPhone());
deliverUser.setStatus(2);
discountPackageDeliverService.insertDeliverUser(deliverUser);
} else {
// 注册用户信息
HighUser user = new HighUser();
user.setName("用户" + IDGenerator.nextId(5));
user.setPhone(phone);
user.setRegTime(new Date());
user.setGold(0);
user.setStatus(1);
user.setInfoCompleteStatus(1); // 用户信息完整状态 0:完整 1:需要填写用户信息 2:需要填写手机号
highUserService.insertUser(user , null);
// 赠送卷包
Map<String, Object> freeMap = new HashMap<>();
freeMap.put("discountPackageId", packageId);
freeMap.put("userId", user.getId());
freeMap.put("userPhone", user.getPhone());
HighDiscountPackageActual packageActual = freeUserDiscountPackage(freeMap);
HighDiscountPackageDeliverUser deliverUser = new HighDiscountPackageDeliverUser();
deliverUser.setPackageDeliverId(discountPackageDeliver.getId());
deliverUser.setSerialNumber(System.currentTimeMillis()+"");
deliverUser.setPackageId(packageId);
deliverUser.setPackageName(discountPackage.getTitle());
deliverUser.setPackageActualId(packageActual.getId().longValue());
deliverUser.setUserId(user.getId());
deliverUser.setUserPhone(user.getPhone());
deliverUser.setStatus(2);
discountPackageDeliverService.insertDeliverUser(deliverUser);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
alreadyProcessedNum++;
redisUtil.set(serialNum, alreadyProcessedNum);
}
discountPackageDeliver.setStatus(2);
discountPackageDeliverService.updateDeliver(discountPackageDeliver);
redisUtil.del(serialNum);
}).start();
return serialNum;
}
}

@ -1014,6 +1014,14 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService {
outRechargeOrderMapper.updateByPrimaryKey(order);
return true;
}
if (secConfigService.isConfig("RECHARGE_ORDER" , order.getLaborUnionCard())) {
highOrder.setExceptionStatus(true);
highOrder.setExceptionContent("当前订单存在以前多充值!");
order.setRechargeStatus(204);
orderService.updateOrderData(highOrder);
outRechargeOrderMapper.updateByPrimaryKey(order);
return true;
}
return false;
}

@ -96,6 +96,7 @@ public class AuthConfig implements WebMvcConfigurer {
.excludePathPatterns("/selfOilStation/*")
.excludePathPatterns("/order/*")
.excludePathPatterns("/wxMsg/*")
.excludePathPatterns("/discount/*")
.excludePathPatterns("/orderRebate/*")
.excludePathPatterns("/refuelOnline/*")
;

@ -0,0 +1,114 @@
package com.v1.controller.business;
import com.alibaba.fastjson.JSONObject;
import com.hai.common.exception.ErrorCode;
import com.hai.common.exception.ErrorHelp;
import com.hai.common.exception.SysCode;
import com.hai.common.utils.ResponseMsgUtil;
import com.hai.entity.ApiKfcStores;
import com.hai.entity.ApiMerchants;
import com.hai.model.ResponseData;
import com.hai.openApi.config.PriceComputeConfig;
import com.hai.openApi.service.ApiMchProductService;
import com.hai.order.type.OrderProductType;
import com.hai.service.*;
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.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Controller
@RequestMapping(value = "/discount")
@Api(value = "优惠券业务")
public class DiscountController {
private static Logger log = LoggerFactory.getLogger(KfcController.class);
@Resource
private ApiMerchantsService apiMerchantsService;
@Resource
private SecConfigService secConfigService;
@Resource
private ApiIpAddressService apiIpAddressService;
@Resource
private HighDiscountPackageService highDiscountPackageService;
@RequestMapping(value = "/presentDiscount", method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "赠送优惠券")
public ResponseData presentDiscount(@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, ",请联系管理人员!");
}
if (
StringUtils.isBlank(object.getString("merchId")) ||
StringUtils.isBlank(object.getString("packageId")) ||
StringUtils.isBlank(object.getString("phone")) ||
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);
}
if (!secConfigService.isConfig(OrderProductType.PRODUCT_TYPE2.getApiCode(), object.getString("merchId"))) {
log.error("getAllCities error!", "当前帐户无权限查询!");
throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOT_AUTHORIZED, "");
}
Map<String , Object> map = new HashMap<>();
map.put("apiKey" , apiMerchants.getApiKey());
map.put("packageId" , object.getString("packageId"));
map.put("phone" , object.getString("phone"));
map.put("merchId" , object.getString("merchId"));
if (!secConfigService.isSignVerify(map , object.getString("sign"))) {
log.error("getRechargeProduct error!", "签名校验失败!");
throw ErrorHelp.genException(SysCode.System, ErrorCode.SIGN_VERIFY);
}
highDiscountPackageService.giveAway(object.getLong("packageId"), object.getString("phone") , 2 , object.getString("merchId"));
return ResponseMsgUtil.success("赠送成功");
} catch (Exception e) {
log.error("HighOpenApiController --> getRechargeProduct() error!", e);
return ResponseMsgUtil.exception(e);
}
}
}
Loading…
Cancel
Save