|
@@ -6,6 +6,8 @@ import com.platform.yijia.service.*;
|
|
|
import com.platform.yijia.utils.CodeMsg;
|
|
|
import com.platform.yijia.utils.ResultData;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
@@ -14,10 +16,11 @@ import javax.annotation.Resource;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.Random;
|
|
|
|
|
|
/*
|
|
|
- * <Title> IntegralWaresController </Title>
|
|
|
+ * <Title> IntegralOrderController </Title>
|
|
|
* <Description> 油站积分商城 </Description>
|
|
|
* @Author JK
|
|
|
* @Date 2021年2月24日
|
|
@@ -25,12 +28,15 @@ import java.util.Random;
|
|
|
@Controller
|
|
|
@RequestMapping("/api")
|
|
|
public class IntegralOrderController {
|
|
|
+ private static Logger logger =(Logger) LoggerFactory.getLogger(IntegralOrderController.class);
|
|
|
@Resource
|
|
|
private IntegralWaresService integralWaresService;
|
|
|
@Resource
|
|
|
private IntegralOrderService integralOrderService;
|
|
|
@Resource
|
|
|
private CustomerPointsService customerPointsService;
|
|
|
+ @Resource
|
|
|
+ private StationService stationService;
|
|
|
|
|
|
//获取油站积分商品信息
|
|
|
@RequestMapping(value = "/getIntegralWaresInfoList", method = RequestMethod.GET)
|
|
@@ -51,10 +57,10 @@ public class IntegralOrderController {
|
|
|
}
|
|
|
|
|
|
//生成积分订单
|
|
|
- @RequestMapping(value = "/insertIntegralOrder", method = RequestMethod.GET)
|
|
|
+ @RequestMapping(value = "/insertIntegralOrder", method = RequestMethod.POST)
|
|
|
@ResponseBody
|
|
|
@Transactional
|
|
|
- public String insertIntegralOrder(@RequestParam IntegralOrder request){
|
|
|
+ public String insertIntegralOrder(@RequestBody IntegralOrder request){
|
|
|
Gson gson =new Gson();
|
|
|
//返回结果集
|
|
|
ResultData resultData = null;
|
|
@@ -68,29 +74,58 @@ public class IntegralOrderController {
|
|
|
if(request.getExchangeNum() != null){
|
|
|
integralOrder.setExchangeNum(request.getExchangeNum());
|
|
|
}
|
|
|
+ if(request.getStationId() != null){
|
|
|
+ integralOrder.setStationId(request.getStationId());
|
|
|
+ }
|
|
|
+ if(request.getWaresId() !=null){
|
|
|
+ integralOrder.setWaresId(request.getWaresId());
|
|
|
+ }
|
|
|
if(StringUtils.isNotBlank(request.getUnionId())){
|
|
|
integralOrder.setUnionId(request.getUnionId());
|
|
|
}
|
|
|
+ if(request.getIntegral() !=null){
|
|
|
+ integralOrder.setIntegral(request.getIntegral());
|
|
|
+ }
|
|
|
+
|
|
|
+ integralOrder.setStatus("1"); //订单状态
|
|
|
+
|
|
|
//订单规则 时间+6位随机数
|
|
|
Random random = new Random();
|
|
|
String str="";
|
|
|
for(int i=0; i<6; i++){
|
|
|
str+=random.nextInt(10);
|
|
|
}
|
|
|
- integralOrder.setIntegralOrderNo(Integer.valueOf(System.nanoTime()+str));
|
|
|
+ integralOrder.setIntegralOrderNo(System.nanoTime()+str);
|
|
|
integralOrder.setExchangeTime(new Date());
|
|
|
|
|
|
//更新用户积分
|
|
|
CustomerPoints customerPoints = new CustomerPoints();
|
|
|
customerPoints.setUnionId(request.getUnionId());
|
|
|
CustomerPoints customerPointsInfo = customerPointsService.getCustomerPointsInfo(customerPoints);
|
|
|
- //用户剩余积分
|
|
|
- BigDecimal points = new BigDecimal(customerPointsInfo.getPoints()).subtract(new BigDecimal(request.getIntegral()));
|
|
|
- customerPoints.setPoints(Integer.valueOf(points.toString()));
|
|
|
- //用户已消费积分累积
|
|
|
- BigDecimal consumptionPoints = new BigDecimal(customerPointsInfo.getConsumptionPoints()).add(new BigDecimal(request.getIntegral()));
|
|
|
- customerPoints.setConsumptionPoints(Integer.valueOf(consumptionPoints.toString()));
|
|
|
- customerPointsService.updateCustomerPointsInfo(customerPoints);
|
|
|
+ if(customerPointsInfo !=null){
|
|
|
+ //用户剩余积分
|
|
|
+ BigDecimal points = new BigDecimal(customerPointsInfo.getPoints()).subtract(new BigDecimal(request.getIntegral()));
|
|
|
+ customerPoints.setPoints(Integer.valueOf(points.toString()));
|
|
|
+ //用户已消费积分累积
|
|
|
+ BigDecimal consumptionPoints = new BigDecimal(customerPointsInfo.getConsumptionPoints()).add(new BigDecimal(request.getIntegral()));
|
|
|
+ customerPoints.setConsumptionPoints(Integer.valueOf(consumptionPoints.toString()));
|
|
|
+ customerPointsService.updateCustomerPointsInfo(customerPoints);
|
|
|
+ }
|
|
|
+
|
|
|
+ //油站名称
|
|
|
+ Map<String, String> m = stationService.getStationAppIdAndAppSecret(request.getStationId());
|
|
|
+ if(m !=null && m.containsKey("stationName")){
|
|
|
+ integralOrder.setStationName(m.get("stationName"));
|
|
|
+ }
|
|
|
+
|
|
|
+ IntegralWares integralWares = new IntegralWares();
|
|
|
+ integralWares.setId(request.getWaresId());
|
|
|
+ List<IntegralWares> integralWaresInfoList = integralWaresService.getIntegralWaresInfoList(integralWares);
|
|
|
+ if(integralWaresInfoList !=null && integralWaresInfoList.size() ==1){
|
|
|
+ //更新商品已售数量
|
|
|
+ integralWares.setWaresOutCount(integralWaresInfoList.get(0).getWaresOutCount()+1);
|
|
|
+ integralWaresService.updateIntegralWaresInfo(integralWares);
|
|
|
+ }
|
|
|
|
|
|
boolean b = integralOrderService.insertIntegralOrder(integralOrder);
|
|
|
if (b){
|