提交 2198e12b 作者: 张小凤 提交者: 余乾开

Price(update)

上级 1e3600fb
...@@ -404,7 +404,8 @@ public enum ResultEnum implements BaseErrorInfoInterface { ...@@ -404,7 +404,8 @@ public enum ResultEnum implements BaseErrorInfoInterface {
NO_PERMISSION_TEMPORARILY("2016", "当前账号没有权限,只有后台账号拥有权限"), NO_PERMISSION_TEMPORARILY("2016", "当前账号没有权限,只有后台账号拥有权限"),
THERE_IS_NO_SUCH_ORDER("2017", "没有当前订单,请输入正确的订单编号"), THERE_IS_NO_SUCH_ORDER("2017", "没有当前订单,请输入正确的订单编号"),
THE_TOKEN_CANNOT_BE_NULL("2018", "token不能为null"), THE_TOKEN_CANNOT_BE_NULL("2018", "token不能为null"),
THE_CURRENT_ACCOUNT_CANNOT_PLACE_ORDERS("2019", "后台管理账号不能下单"); THE_CURRENT_ACCOUNT_CANNOT_PLACE_ORDERS("2019", "后台管理账号不能下单"),
THIRD_PARTY_ERRORS("2020","第三方接口错误或者第三接口正在更新");
/** /**
* 错误码 * 错误码
......
...@@ -5,6 +5,8 @@ import lombok.AllArgsConstructor; ...@@ -5,6 +5,8 @@ import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import java.util.List;
/** /**
* @Author small * @Author small
* @Date 2023/5/26 14:10 * @Date 2023/5/26 14:10
...@@ -24,6 +26,6 @@ public class PriceAcquisition { ...@@ -24,6 +26,6 @@ public class PriceAcquisition {
private Integer day; private Integer day;
@ApiModelProperty(value = "渠道等级id") @ApiModelProperty(value = "渠道等级id")
private Integer channelLevelId; private List<Integer> channelLevelId;
} }
...@@ -18,6 +18,7 @@ import com.mmc.oms.entity.order.OrderReceiptDO; ...@@ -18,6 +18,7 @@ import com.mmc.oms.entity.order.OrderReceiptDO;
import com.mmc.oms.entity.order.OrderRefundDO; import com.mmc.oms.entity.order.OrderRefundDO;
import com.mmc.oms.entity.order.OrderVcuDO; import com.mmc.oms.entity.order.OrderVcuDO;
import com.mmc.oms.entity.ware.WareInfoDO; import com.mmc.oms.entity.ware.WareInfoDO;
import com.mmc.oms.model.dto.mall.CooperationTagVO;
import com.mmc.oms.model.dto.order.*; import com.mmc.oms.model.dto.order.*;
import com.mmc.oms.model.dto.repo.RepoAccountDTO; import com.mmc.oms.model.dto.repo.RepoAccountDTO;
import com.mmc.oms.model.dto.transtatus.TranStatusDicDTO; import com.mmc.oms.model.dto.transtatus.TranStatusDicDTO;
...@@ -28,6 +29,7 @@ import com.mmc.oms.model.vo.coupon.AppletMsgVO; ...@@ -28,6 +29,7 @@ import com.mmc.oms.model.vo.coupon.AppletMsgVO;
import com.mmc.oms.model.vo.order.*; import com.mmc.oms.model.vo.order.*;
import com.mmc.oms.service.RentalOrdersService; import com.mmc.oms.service.RentalOrdersService;
import com.mmc.oms.wx.WxMsgTemplete; import com.mmc.oms.wx.WxMsgTemplete;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
...@@ -40,9 +42,11 @@ import org.springframework.stereotype.Service; ...@@ -40,9 +42,11 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport; import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.util.MultiValueMap; import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -51,6 +55,7 @@ import java.util.stream.Collectors; ...@@ -51,6 +55,7 @@ import java.util.stream.Collectors;
* @Author small @Date 2023/5/26 10:53 @Version 1.0 * @Author small @Date 2023/5/26 10:53 @Version 1.0
*/ */
@Service @Service
@Slf4j
public class RentalOrdersServiceImpl implements RentalOrdersService { public class RentalOrdersServiceImpl implements RentalOrdersService {
@Autowired @Autowired
...@@ -79,13 +84,20 @@ public class RentalOrdersServiceImpl implements RentalOrdersService { ...@@ -79,13 +84,20 @@ public class RentalOrdersServiceImpl implements RentalOrdersService {
return ResultBody.error(ResultEnum.THE_CURRENT_ACCOUNT_CANNOT_PLACE_ORDERS); return ResultBody.error(ResultEnum.THE_CURRENT_ACCOUNT_CANNOT_PLACE_ORDERS);
} }
//用户信息的远程调用 //用户信息的远程调用
ResponseEntity<String> responseEntity = UserId(user.getUserAccountId(), user.getToken()); ResultBody<ResponseEntity<String>> responseEntityResultBody = UserId(user.getUserAccountId(), user.getToken());
if (ResultEnum.THIRD_PARTY_ERRORS.getResultCode().equals(responseEntityResultBody.getCode())){
return ResultBody.error(ResultEnum.THIRD_PARTY_ERRORS);
}
ResponseEntity<String> responseEntity = responseEntityResultBody.getResult();
UserAccountSimpleDTO account = JSON.parseObject(responseEntity.getBody(), UserAccountSimpleDTO.class); UserAccountSimpleDTO account = JSON.parseObject(responseEntity.getBody(), UserAccountSimpleDTO.class);
//优惠券id获取优惠券面值 //优惠券id获取优惠券面值
OrderInfoDO orderInfo = new OrderInfoDO(param); OrderInfoDO orderInfo = new OrderInfoDO(param);
PriceAcquisition priceAcquisition = getPriceAcquisition(param, account); PriceAcquisition priceAcquisition = getPriceAcquisition(param, account);
BigDecimal unitPrice = getUnitPrice(priceAcquisition); ResultBody<BigDecimal> bigDecimalResultBody = getUnitPrice(priceAcquisition);
if (ResultEnum.THIRD_PARTY_ERRORS.getResultCode().equals(bigDecimalResultBody.getCode())){
return ResultBody.error(ResultEnum.THIRD_PARTY_ERRORS);
}
BigDecimal unitPrice = bigDecimalResultBody.getResult();
//每天单价 //每天单价
orderInfo.setUnitPrice(unitPrice); orderInfo.setUnitPrice(unitPrice);
// 天数 // 天数
...@@ -96,6 +108,11 @@ public class RentalOrdersServiceImpl implements RentalOrdersService { ...@@ -96,6 +108,11 @@ public class RentalOrdersServiceImpl implements RentalOrdersService {
orderInfo.setBuyerName(user.getUserName()); orderInfo.setBuyerName(user.getUserName());
orderInfo.setBuyerPhone(user.getPhoneNum()); orderInfo.setBuyerPhone(user.getPhoneNum());
orderInfo.setNickName(user.getNickName()); orderInfo.setNickName(user.getNickName());
//获取剩余的余额
ResultBody<BigDecimal> remainingBalance = getRemainingBalance(user.getToken(), user.getUserAccountId());
if (ResultEnum.THIRD_PARTY_ERRORS.getResultCode().equals(remainingBalance.getCode())) {
return ResultBody.error(ResultEnum.THIRD_PARTY_ERRORS);
}
rentalOrdersDao.insertOrderInfo(orderInfo); rentalOrdersDao.insertOrderInfo(orderInfo);
// 添加收货地址 // 添加收货地址
Date cdate = new Date(); Date cdate = new Date();
...@@ -104,8 +121,7 @@ public class RentalOrdersServiceImpl implements RentalOrdersService { ...@@ -104,8 +121,7 @@ public class RentalOrdersServiceImpl implements RentalOrdersService {
receipt.setOrderInfoId(orderInfo.getId()); receipt.setOrderInfoId(orderInfo.getId());
receipt.setCreateTime(cdate); receipt.setCreateTime(cdate);
rentalOrdersDao.insertOrderReceipt(receipt); rentalOrdersDao.insertOrderReceipt(receipt);
//获取剩余的余额 orderInfo.setBalance(remainingBalance.getResult());
orderInfo.setBalance(getRemainingBalance(user.getToken(), user.getUserAccountId()));
// 将当前的用户id及订单编号存入redis // 将当前的用户id及订单编号存入redis
OrderInfoDTO dto = orderInfo.buildOrderInfoDTO(); OrderInfoDTO dto = orderInfo.buildOrderInfoDTO();
stringRedisTemplate.opsForValue().set(orderInfo.getOrderNo(), JsonUtil.parseObjToJson(dto)); stringRedisTemplate.opsForValue().set(orderInfo.getOrderNo(), JsonUtil.parseObjToJson(dto));
...@@ -132,25 +148,36 @@ public class RentalOrdersServiceImpl implements RentalOrdersService { ...@@ -132,25 +148,36 @@ public class RentalOrdersServiceImpl implements RentalOrdersService {
//远程设置 //远程设置
private PriceAcquisition getPriceAcquisition(LeaseOrderVO param, UserAccountSimpleDTO account) { private PriceAcquisition getPriceAcquisition(LeaseOrderVO param, UserAccountSimpleDTO account) {
List<CooperationTagVO> cooperationTagVOS = account.getCooperationTagVOS();
List<Integer> list = new ArrayList<>();
if (cooperationTagVOS!=null && !cooperationTagVOS.isEmpty()){
for (CooperationTagVO cooperationTagVO : cooperationTagVOS) {
list.add(cooperationTagVO.getId());
}
}
PriceAcquisition priceAcquisition = new PriceAcquisition(); PriceAcquisition priceAcquisition = new PriceAcquisition();
priceAcquisition.setUserId(account.getId()); priceAcquisition.setUserId(account.getId());
priceAcquisition.setDay(day(param)); priceAcquisition.setDay(day(param));
priceAcquisition.setSpecsId(param.getSpecsId()); priceAcquisition.setSpecsId(param.getSpecsId());
priceAcquisition.setChannelLevelId(account.getCooperationTagId()); priceAcquisition.setChannelLevelId(list);
return priceAcquisition; return priceAcquisition;
} }
private ResponseEntity<String> UserId(Integer repoAccountId, String token) { private ResultBody<ResponseEntity<String>> UserId(Integer repoAccountId, String token) {
ResponseEntity<String> response = null;
try {
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
//封装请求头 //封装请求头
headers.add("token", token); headers.add("token", token);
HttpEntity<MultiValueMap<String, Object>> formEntity = new HttpEntity<MultiValueMap<String, Object>>(headers); HttpEntity<MultiValueMap<String, Object>> formEntity = new HttpEntity<MultiValueMap<String, Object>>(headers);
ResponseEntity<String> response = restTemplate.exchange(userAppUrl + "user-account/feignGetUserSimpleInfo?userAccountId=" + repoAccountId, response = restTemplate.exchange(userAppUrl + "user-account/feignGetUserSimpleInfo?userAccountId=" + repoAccountId,
HttpMethod.GET, formEntity, String.class); HttpMethod.GET, formEntity, String.class);
log.info(String.valueOf(formEntity));
} catch (RestClientException e) {
return ResultBody.error(ResultEnum.THIRD_PARTY_ERRORS);
}
// 用户信息 // 用户信息
/* ResponseEntity<String> response = /* ResponseEntity<String> response =
restTemplate.getForEntity( restTemplate.getForEntity(
...@@ -158,7 +185,7 @@ public class RentalOrdersServiceImpl implements RentalOrdersService { ...@@ -158,7 +185,7 @@ public class RentalOrdersServiceImpl implements RentalOrdersService {
+ "user-account/feignGetUserSimpleInfo?userAccountId=" + "user-account/feignGetUserSimpleInfo?userAccountId="
+ repoAccountId, + repoAccountId,
String.class);*/ String.class);*/
return response; return ResultBody.success(response);
} }
...@@ -168,19 +195,24 @@ public class RentalOrdersServiceImpl implements RentalOrdersService { ...@@ -168,19 +195,24 @@ public class RentalOrdersServiceImpl implements RentalOrdersService {
* @param repoAccountId * @param repoAccountId
* @return * @return
*/ */
public BigDecimal getRemainingBalance(String token, Integer repoAccountId) { public ResultBody<BigDecimal> getRemainingBalance(String token, Integer repoAccountId) {
HttpHeaders headers = new HttpHeaders(); BigDecimal bigDecimal = null;
//封装请求头 try {
headers.add("token", token); HttpHeaders headers = new HttpHeaders();
HttpEntity<MultiValueMap<String, Object>> formEntity = new HttpEntity<MultiValueMap<String, Object>>(headers); //封装请求头
ResponseEntity<String> result4 = restTemplate.exchange(paymentUrl + "repocash/RemainingBalance?repoAccountId=" + repoAccountId, headers.add("token", token);
HttpMethod.GET, formEntity, String.class); HttpEntity<MultiValueMap<String, Object>> formEntity = new HttpEntity<MultiValueMap<String, Object>>(headers);
String body = result4.getBody(); ResponseEntity<String> result4 = restTemplate.exchange(paymentUrl + "repocash/RemainingBalance?repoAccountId=" + repoAccountId,
if (body == null) { HttpMethod.GET, formEntity, String.class);
body = "0"; String body = result4.getBody();
if (body == null) {
body = "0";
}
bigDecimal = new BigDecimal(body);
} catch (RestClientException e) {
return ResultBody.error(ResultEnum.THIRD_PARTY_ERRORS);
} }
BigDecimal bigDecimal = new BigDecimal(body); return ResultBody.success(bigDecimal);
return bigDecimal;
} }
/** /**
...@@ -207,19 +239,24 @@ public class RentalOrdersServiceImpl implements RentalOrdersService { ...@@ -207,19 +239,24 @@ public class RentalOrdersServiceImpl implements RentalOrdersService {
* @param param * @param param
* @return * @return
*/ */
private BigDecimal getUnitPrice(PriceAcquisition param) { private ResultBody<BigDecimal> getUnitPrice(PriceAcquisition param) {
// 需要支付的价格 // 需要支付的价格
ResponseEntity<String> responseEntity = restTemplate.postForEntity(pmsUrl + "/product/spec/feignGetSpecLeaseUnitPrice" BigDecimal bigDecimal = null;
, param, String.class); try {
String body = responseEntity.getBody(); ResponseEntity<String> responseEntity = restTemplate.postForEntity(pmsUrl + "product/spec/feignGetSpecLeaseUnitPrice"
if (null == body) { , param, String.class);
body = "0"; String body = responseEntity.getBody();
if (null == body) {
body = "0";
}
bigDecimal = new BigDecimal(body);
} catch (RestClientException e) {
return ResultBody.error(ResultEnum.THIRD_PARTY_ERRORS);
} }
BigDecimal bigDecimal = new BigDecimal(body);
// 模拟 // 模拟
// int i = 12; // int i = 12;
// BigDecimal bigDecimal = BigDecimal.valueOf(i); // BigDecimal bigDecimal = BigDecimal.valueOf(i);
return bigDecimal; return ResultBody.success(bigDecimal);
} }
public Integer day(LeaseOrderVO param) { public Integer day(LeaseOrderVO param) {
......
...@@ -7,9 +7,8 @@ spring: ...@@ -7,9 +7,8 @@ spring:
password: MMC@2022&MYSQL password: MMC@2022&MYSQL
redis: redis:
database: 1 database: 1
host: r-wz9ke310fs684hacn1pd.redis.rds.aliyuncs.com host: 127.0.0.1
port: 6379 port: 6379
password: MMC@2022&REDIS
jedis: jedis:
pool: pool:
max-active: 2 max-active: 2
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论