|
|
@@ -0,0 +1,858 @@
|
|
|
+package com.poyee.auctionorder.service.impl;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.poyee.auctionorder.dto.*;
|
|
|
+import com.poyee.auctionorder.entity.AuctionOrder;
|
|
|
+import com.poyee.auctionorder.entity.AuctionOrderList;
|
|
|
+import com.poyee.auctionorder.mapper.AuctionOrderMapper;
|
|
|
+import com.poyee.auctionorder.mq.MqService;
|
|
|
+import com.poyee.auctionorder.mq.dto.PointOrderInfo;
|
|
|
+import com.poyee.auctionorder.service.IAuctionOrderListService;
|
|
|
+import com.poyee.auctionorder.service.OrderService;
|
|
|
+import com.poyee.base.dto.AppBaseUser;
|
|
|
+import com.poyee.base.dto.OrderBaseInfoDto;
|
|
|
+import com.poyee.base.dto.Pays;
|
|
|
+import com.poyee.base.dto.Result;
|
|
|
+import com.poyee.base.entity.UserBankInfo;
|
|
|
+import com.poyee.base.service.IUserBankInfoService;
|
|
|
+import com.poyee.base.service.SysBaseService;
|
|
|
+import com.poyee.base.service.impl.BaseServiceImpl;
|
|
|
+import com.poyee.common.constant.Constants;
|
|
|
+import com.poyee.common.exception.ServiceException;
|
|
|
+import com.poyee.courier.dto.entry.AuctionCourierOrderEntry;
|
|
|
+import com.poyee.courier.service.IOrderCourierRecordService;
|
|
|
+import com.poyee.mq.MqConstans;
|
|
|
+import com.poyee.util.DateUtils;
|
|
|
+import com.poyee.util.IpUtils;
|
|
|
+import com.poyee.util.RandomUtil;
|
|
|
+import com.poyee.util.http.HttpClientUtil;
|
|
|
+import com.tzy.sportcard.api.dto.ResourceData;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.beanutils.BeanUtils;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.lang.reflect.InvocationTargetException;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ *
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class OrderServiceImpl extends BaseServiceImpl<AuctionOrderMapper, AuctionOrder, AuctionOrderDto> implements OrderService {
|
|
|
+
|
|
|
+ @Value("${pay.unified:http://localhost:8082/pay/p1/unified}")
|
|
|
+ private String unified;
|
|
|
+ @Value("${pay.walletInfo:http://localhost:8082/pay/p1/sycnWalletInfo}")
|
|
|
+ private String walletInfo;
|
|
|
+ @Value("${pay.query:http://localhost:8082/pay/p1/query}")
|
|
|
+ private String query;
|
|
|
+ @Value("${pay.refund:http://localhost:8082/pay/p1/refund}")
|
|
|
+ private String refund;
|
|
|
+ @Value("${auc.internal_lot:http://auction-auc/internal/lot/paid}")
|
|
|
+ private String internalLot;
|
|
|
+ @Value("${recharge.sycnWalletInfo:http://localhost:8082/pay/p1/sycnWalletInfo}")
|
|
|
+ private String sycnWalletInfoUrl;//同步接口
|
|
|
+ @Autowired
|
|
|
+ @Qualifier("threadPoolTaskExecutor")
|
|
|
+ private ThreadPoolTaskExecutor pools;
|
|
|
+ @Autowired
|
|
|
+ private MqService mqService;
|
|
|
+ @Autowired
|
|
|
+ private SysBaseService sysBaseService;
|
|
|
+ @Autowired
|
|
|
+ private IAuctionOrderListService auctionOrderListService;
|
|
|
+ @Autowired
|
|
|
+ private IOrderCourierRecordService orderCourierRecordService;
|
|
|
+ @Autowired
|
|
|
+ private IUserBankInfoService userBankInfoService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建订单
|
|
|
+ *
|
|
|
+ * @param auctionOrderDto
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Result createOrder(AuctionOrderDto auctionOrderDto) {
|
|
|
+ AuctionOrder auctionOrder = new AuctionOrder();
|
|
|
+ try {
|
|
|
+ BeanUtils.copyProperties(auctionOrder, auctionOrderDto);
|
|
|
+ } catch (IllegalAccessException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (InvocationTargetException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ boolean save = save(auctionOrder);
|
|
|
+ if (save) {
|
|
|
+ Result<AuctionOrderDto> info = info(auctionOrder.getId());
|
|
|
+ AuctionOrderDto retEntity = info.getData();
|
|
|
+ //保存子表信息
|
|
|
+ List<AuctionOrderList> goods = auctionOrderDto.getGoods();
|
|
|
+// BigDecimal totalPrice = new BigDecimal(0);
|
|
|
+ final StringBuffer[] stb = {new StringBuffer()};
|
|
|
+ final String[] eventId = {""};
|
|
|
+ if (null != goods && goods.size() > 0) {
|
|
|
+ goods.forEach(good -> {
|
|
|
+ good.setOrderId(retEntity.getId());
|
|
|
+ good.setOrderNo(retEntity.getOrderNo());
|
|
|
+ good.setMerchantId(retEntity.getShopId());
|
|
|
+ good.setUserId(retEntity.getAccountId());
|
|
|
+ good.setEventId(StringUtils.isEmpty(auctionOrder.getEventId()) ? good.getGoodsId() : auctionOrder.getEventId());
|
|
|
+ if (null == good.getTotalAmount()) {
|
|
|
+ throw new ServiceException("价格为空!");
|
|
|
+ }
|
|
|
+ stb[0] = stb[0].append(good.getName()).append("*").append(good.getNum()).append(",");
|
|
|
+// totalPrice.add(good.getTotalAmount());
|
|
|
+ eventId[0] = good.getGoodsId();
|
|
|
+ });
|
|
|
+ auctionOrderListService.saveBatch(goods);
|
|
|
+ if (StringUtils.isEmpty(auctionOrder.getEventId())) {
|
|
|
+ //如果拍品id为空则取goods的id
|
|
|
+ auctionOrder.setEventId(eventId[0]);
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(auctionOrder.getAuctionName())) {
|
|
|
+ //如果 拍品名称为空 则 设置商品的名称
|
|
|
+ auctionOrder.setAuctionName(stb[0].toString());
|
|
|
+ updateById(auctionOrder);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Result.ok(retEntity);
|
|
|
+ }
|
|
|
+ return Result.error("创建订单失败[001]!");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建订单
|
|
|
+ *
|
|
|
+ * @param auctionOrderDto
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Result createToPay(AuctionOrderDto auctionOrderDto) {
|
|
|
+ Result order = createOrder(auctionOrderDto);
|
|
|
+ if (order.isSuccess()) {
|
|
|
+ AuctionOrderDto data = (AuctionOrderDto) order.getData(AuctionOrderDto.class);
|
|
|
+ //如果下单成功
|
|
|
+ Result result = pay(new OrderBayInfoEntry(data.getId(), data.getPaymentType(), data.getOrderType()));
|
|
|
+ if (result.isSuccess()) {
|
|
|
+ result.addData("orderInfo", data);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ return order;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建订单[钱包充值]
|
|
|
+ *
|
|
|
+ * @param rechargeOrderDto
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Result createToRecharge(RechargeOrderDto rechargeOrderDto) {
|
|
|
+ AuctionOrderDto auctionOrderDto = new AuctionOrderDto();
|
|
|
+ AppBaseUser appUserInfo = getAppUserInfo();
|
|
|
+ try {
|
|
|
+ BeanUtils.copyProperties(auctionOrderDto, rechargeOrderDto);
|
|
|
+ } catch (IllegalAccessException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ } catch (InvocationTargetException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(rechargeOrderDto.getAccountType()) && "merchant".equals(rechargeOrderDto.getAccountType())) {
|
|
|
+ //设置商家id
|
|
|
+ auctionOrderDto.setShopId(getAppUserMerchantId());
|
|
|
+ } else {//如果不是商家提现
|
|
|
+ auctionOrderDto.setAccountId(appUserInfo.getId());
|
|
|
+ }
|
|
|
+ String goodsName = "";
|
|
|
+ String orderNo = "";
|
|
|
+ //判断订单类型
|
|
|
+ if ("recharge".equals(auctionOrderDto.getOrderCategory())) {//充值
|
|
|
+ //判断用户是否是高频支付用户
|
|
|
+ List<Pays> pays = appUserInfo.getPays();
|
|
|
+ if(null == pays || pays.isEmpty()){
|
|
|
+ throw new ServiceException(-1, "操作失败[未达到充值标准]!");
|
|
|
+ }
|
|
|
+ goodsName = "钱包充值";
|
|
|
+ orderNo = RandomUtil.getRandom(RandomUtil.RECHARGE);
|
|
|
+ //查询钱包余额
|
|
|
+ Map<String, String> header = new HashMap<>();
|
|
|
+ header.put("Content-Type", "application/json");
|
|
|
+ JSONObject param = new JSONObject();
|
|
|
+ param.put("type", rechargeOrderDto.getOrderType());
|
|
|
+// param.put("payWay",rechargeOrderDto.getPayWay());
|
|
|
+ param.put("payWay", "recharge-baofoo");
|
|
|
+ param.put("userId", appUserInfo.getId());
|
|
|
+ String ret = null;
|
|
|
+ if (walletInfo.startsWith("https:")) {
|
|
|
+ ret = HttpClientUtil.httpsRequest(walletInfo, "POST", JSONObject.toJSONString(param), header);
|
|
|
+ } else {
|
|
|
+ ret = HttpClientUtil.httpRequest(walletInfo, "POST", JSONObject.toJSONString(param), header);
|
|
|
+ }
|
|
|
+ Result result = JSONObject.parseObject(ret, Result.class);
|
|
|
+ log.info(" 查询返回数据:》》》 {}", result);
|
|
|
+ if (null != result) {
|
|
|
+ if (result.isSuccess()) {
|
|
|
+ try {
|
|
|
+ String balance = String.valueOf(result.get("balance"));
|
|
|
+ if (StringUtils.isNotEmpty(balance)) {
|
|
|
+ BigDecimal i = new BigDecimal(balance);
|
|
|
+ //查询钱包充值记录
|
|
|
+ BigDecimal totalPrice = baseMapper.selectOrderPriceSum(appUserInfo.getId(), "recharge", "recharge-baofoo");
|
|
|
+ if(totalPrice.compareTo(Constants.BIG_ONE_HUNDRED) >= 0){
|
|
|
+ throw new ServiceException(-1, "充值失败!钱包余额消费限额为100000元/年");
|
|
|
+ }
|
|
|
+ //判断充值总额
|
|
|
+ if ((null != totalPrice && null != auctionOrderDto.getTotalPrice()
|
|
|
+ && totalPrice.add(auctionOrderDto.getTotalPrice()).compareTo(Constants.BIG_ONE_HUNDRED) > 0)) {
|
|
|
+ //未达到充值总额
|
|
|
+ if (Constants.BIG_TEN_THOUSAND.compareTo(i.add(auctionOrderDto.getTotalPrice())) >= 0) {
|
|
|
+ throw new ServiceException(-1, "充值失败!您当前钱包可充值额度为[" + Constants.BIG_ONE_HUNDRED.subtract(totalPrice) + "]");
|
|
|
+ }
|
|
|
+ //可充值金额
|
|
|
+ BigDecimal rechargeablePrice = Constants.BIG_TEN_THOUSAND.subtract(i).compareTo(Constants.BIG_ONE_HUNDRED.subtract(totalPrice)) > 0 ? Constants.BIG_ONE_HUNDRED.subtract(totalPrice) : Constants.BIG_TEN_THOUSAND.subtract(i);
|
|
|
+ throw new ServiceException(-1, "充值失败!您当前钱包可充值额度为[" + rechargeablePrice + "]");
|
|
|
+ }
|
|
|
+ //判断余额是否符合
|
|
|
+ if(Constants.BIG_TEN_THOUSAND.compareTo(i.add(auctionOrderDto.getTotalPrice())) < 0){
|
|
|
+ throw new ServiceException(-1, "充值失败!您当前钱包可充值额度为[" + Constants.BIG_TEN_THOUSAND.subtract(i) + "]");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(" 获取余额信息异常! ,{}", e);
|
|
|
+ throw new ServiceException(-1, StringUtils.isNotEmpty(e.getMessage()) ? e.getMessage() : "操作失败[获取余额信息异常]!");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new ServiceException(-1, result.getMsg());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new ServiceException(-1, "操作失败[未查到开户信息]!");
|
|
|
+ }
|
|
|
+ } else if ("withdraw".equals(auctionOrderDto.getOrderCategory())) {//提现
|
|
|
+ goodsName = "钱包提现";
|
|
|
+ orderNo = RandomUtil.getRandom(RandomUtil.RECHARGE_WITHDRAW);
|
|
|
+ //近14天可提现1次 根据配置
|
|
|
+ String cycle = sysBaseService.selectDictValue("withdraw_config", "cycle");//周期
|
|
|
+ String times = sysBaseService.selectDictValue("withdraw_config", "times");//次数
|
|
|
+ if(StringUtils.isEmpty(cycle) || StringUtils.isEmpty(times)){
|
|
|
+ throw new ServiceException(-1, "提现失败[401]!");
|
|
|
+ }
|
|
|
+ //查询是否符合资格
|
|
|
+ AuctionOrder auctionOrder = new AuctionOrder();
|
|
|
+ auctionOrder.setOrderCategory("withdraw");//提现
|
|
|
+ auctionOrder.setStatus(101);//提现成功
|
|
|
+ //指定时间
|
|
|
+ Date date = DateUtils.addCalendar(new Date(), DateUtils.day, -Integer.parseInt(cycle));
|
|
|
+ //查询指定条件范围内的数据
|
|
|
+ QueryWrapper<AuctionOrder> auctionOrderQueryWrapper = checkWrapper(auctionOrder, true)
|
|
|
+ .gt("create_time",date)
|
|
|
+ .orderBy(false,false,"id")
|
|
|
+ ;
|
|
|
+ Result<AuctionOrderDto> dtoResult = listPage(auctionOrderQueryWrapper, auctionOrder);
|
|
|
+// Result<AuctionOrderDto> dtoResult = getOneDto(auctionOrder, true, "id", false);
|
|
|
+ if (dtoResult.isSuccess()) {
|
|
|
+ List<AuctionOrderDto> dataList = dtoResult.getDataList();
|
|
|
+// AuctionOrderDto dtoData = dtoResult.getData();
|
|
|
+ if(null != dataList && dataList.size() > 0){
|
|
|
+ if(dataList.size() >= Integer.parseInt(times) ){
|
|
|
+ int wtimes = Integer.parseInt(times) - dataList.size();
|
|
|
+ wtimes = wtimes < 0 ? 0 : wtimes;
|
|
|
+ return Result.error("提现失败!近" + cycle + "日内可提现" + wtimes + "次")
|
|
|
+ .put("lastWithdrawTime",DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, dataList.get(0).getCreateTime()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return Result.error("设置订单类型错误!");
|
|
|
+ }
|
|
|
+ auctionOrderDto.setOrderNo(orderNo);
|
|
|
+ auctionOrderDto.setAuctionName(goodsName);
|
|
|
+ auctionOrderDto.setPaymentType(rechargeOrderDto.getPayWay());
|
|
|
+ Result order = createOrder(auctionOrderDto);
|
|
|
+ if (order.isSuccess()) {
|
|
|
+ AuctionOrderDto data = (AuctionOrderDto) order.getData(AuctionOrderDto.class);
|
|
|
+ //如果下单成功
|
|
|
+ OrderBayInfoEntry orderBayInfoEntry = new OrderBayInfoEntry(data.getId(), data.getPaymentType(), data.getOrderType());
|
|
|
+ orderBayInfoEntry.setBankId(rechargeOrderDto.getBankId());
|
|
|
+ orderBayInfoEntry.setType(rechargeOrderDto.getType());
|
|
|
+ orderBayInfoEntry.setOrderCategory(auctionOrderDto.getOrderCategory());
|
|
|
+ orderBayInfoEntry.setAccountType(rechargeOrderDto.getAccountType());
|
|
|
+ Result result = pay(orderBayInfoEntry);
|
|
|
+ if (result.isSuccess()) {
|
|
|
+ result.addData("orderInfo", data);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ return Result.error();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 支付
|
|
|
+ *
|
|
|
+ * @param orderBayInfoEntry
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Result pay(OrderBayInfoEntry orderBayInfoEntry) {
|
|
|
+ Result<AuctionOrder> info = detail(orderBayInfoEntry.getId());
|
|
|
+ if (info.isSuccess()) {
|
|
|
+ AuctionOrder auctionOrderDto = info.getData();
|
|
|
+// AuctionOrder auctionOrderDto = info.getData(AuctionOrder.class);
|
|
|
+ //计算需要支付的金额(商品订单金额+运费-优惠券)
|
|
|
+ BigDecimal totalPrice = auctionOrderDto.getTotalPrice();
|
|
|
+ if (null == totalPrice) {
|
|
|
+ return Result.error("订单支付金额异常,请确认订单金额!");
|
|
|
+ }
|
|
|
+ if (null != orderBayInfoEntry.getAddressId() && 0 != orderBayInfoEntry.getAddressId()) {
|
|
|
+ //保存订单的物流信息
|
|
|
+ AuctionCourierOrderEntry entry = new AuctionCourierOrderEntry();
|
|
|
+ entry.setId(orderBayInfoEntry.getId());
|
|
|
+ entry.setAddressId(orderBayInfoEntry.getAddressId());
|
|
|
+ entry.setOrderNo( auctionOrderDto.getOrderNo());
|
|
|
+ entry.setOrderType( auctionOrderDto.getOrderType());
|
|
|
+ entry.setAccountId(auctionOrderDto.getAccountId());
|
|
|
+ entry.setFreightAmount(auctionOrderDto.getFreightAmount());
|
|
|
+ entry.setShopId(auctionOrderDto.getShopId());
|
|
|
+ Result orderCourierRecord = orderCourierRecordService.holdOrderCourierRecord(entry);
|
|
|
+ if (!orderCourierRecord.isSuccess()) {
|
|
|
+ return orderCourierRecord;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (null != auctionOrderDto && StringUtils.isNotEmpty(auctionOrderDto.getPaymentType())
|
|
|
+ && auctionOrderDto.getPaymentType().equals(orderBayInfoEntry.getPayType()) && StringUtils.isNotEmpty(auctionOrderDto.getPayData())
|
|
|
+ ) {
|
|
|
+ //判断支付时间是否当前时间 如果是 则重新生成订单
|
|
|
+ if (new Date().before(auctionOrderDto.getPaymentTime())) {
|
|
|
+ return Result.ok(JSONObject.parseObject(auctionOrderDto.getPayData()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ BigDecimal freightAmount = null == auctionOrderDto.getFreightAmount() ? new BigDecimal(0) : auctionOrderDto.getFreightAmount();
|
|
|
+ BigDecimal discount = null == auctionOrderDto.getDiscount() ? new BigDecimal(0) : auctionOrderDto.getDiscount();
|
|
|
+ BigDecimal parPrice = totalPrice.add(freightAmount).subtract(discount);
|
|
|
+ JSONObject payRequestBody = new JSONObject();
|
|
|
+ payRequestBody.put("userType", "APP");
|
|
|
+ payRequestBody.put("category", orderBayInfoEntry.getCategory());//支付模块
|
|
|
+ payRequestBody.put("orderCategory", orderBayInfoEntry.getOrderCategory());//支付模块
|
|
|
+ payRequestBody.put("orderNo", auctionOrderDto.getOrderNo()); //订单编码
|
|
|
+ payRequestBody.put("totalAmount", parPrice);//支付金额
|
|
|
+ payRequestBody.put("body", StringUtils.isEmpty(auctionOrderDto.getAuctionName()) ? "球星卡片" : auctionOrderDto.getAuctionName());//支付商品描述
|
|
|
+ payRequestBody.put("payWay", orderBayInfoEntry.getPayType()); //支付方式
|
|
|
+ payRequestBody.put("createip", IpUtils.getHostIp()); //请求ip
|
|
|
+ payRequestBody.put("createOrderTime", auctionOrderDto.getCreateTime()); //订单创建时间
|
|
|
+ if (Constants.rechargeOrderType.contains(orderBayInfoEntry.getOrderCategory())) {
|
|
|
+ setRechargeInfo(payRequestBody, orderBayInfoEntry, null);
|
|
|
+ }
|
|
|
+ Date expireTime = (null == auctionOrderDto.getPayTimeLimit() || auctionOrderDto.getPayTimeLimit().before(new Date())) ? DateUtils.addCalendar(new Date(), DateUtils.day, 3) : auctionOrderDto.getPayTimeLimit();
|
|
|
+ //如果没有支付过期时间 则默认3天后过期
|
|
|
+ payRequestBody.put("expireTime", expireTime);//订单过期时间 如果为空则设置为付款期限
|
|
|
+ try {
|
|
|
+ String ret = null;
|
|
|
+ if (unified.contains("http:")) {
|
|
|
+ ret = HttpClientUtil.httpRequestJSON(unified, "POST", JSONObject.toJSONString(payRequestBody), null);
|
|
|
+ } else {
|
|
|
+ Map<String, String> header = new HashMap<>();
|
|
|
+ header.put("Content-Type", "application/json");
|
|
|
+ ret = HttpClientUtil.httpsRequest(unified, "POST", JSONObject.toJSONString(payRequestBody), header);
|
|
|
+ }
|
|
|
+ Result result = JSONObject.parseObject(ret, Result.class);
|
|
|
+ log.info(" 下单返回数据:》》》 {}", result);
|
|
|
+ if (null != result) {
|
|
|
+ if (result.isSuccess()) {
|
|
|
+ //更新订单信息
|
|
|
+ auctionOrderDto.setPaymentType(orderBayInfoEntry.getPayType());//支付方式
|
|
|
+ auctionOrderDto.setPaymentSubType(result.getString("paymentSubType"));//支付子类型
|
|
|
+ auctionOrderDto.setPayData(JSONObject.toJSONString(result.getResult()));//支付参数
|
|
|
+ auctionOrderDto.setTradeNo(String.valueOf(result.getResult().get("merOrderId")));//支付编码
|
|
|
+ auctionOrderDto.setPaymentTime(new Date());
|
|
|
+ auctionOrderDto.setStatus(100);//待付款
|
|
|
+ boolean b = updateById(auctionOrderDto);
|
|
|
+ log.info(" 支付下单 更新订单信息:{} ", b);
|
|
|
+ Map map = result.getResult();
|
|
|
+ map.remove("paymentSubType");
|
|
|
+ if ("recharge".equals(orderBayInfoEntry.getCategory())) {
|
|
|
+ JSONObject jsonResult = (JSONObject) result.getResult().get("result");
|
|
|
+ jsonResult.remove("payParam");
|
|
|
+ map.putAll(jsonResult);
|
|
|
+ }
|
|
|
+ result.setResult(null);
|
|
|
+ result.setData(map);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ } else {
|
|
|
+ throw new ServiceException(-1, "支付下单失败[001]!");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ throw new ServiceException(-1, "系统错误,支付下单失败!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return info;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setRechargeInfo(JSONObject payRequestBody, OrderBayInfoEntry orderBayInfoEntry, Integer merchantId) {
|
|
|
+ //获取机构/平台号 默认 HS
|
|
|
+ if (null == merchantId) {
|
|
|
+ merchantId = Integer.valueOf(sysBaseService.selectDictValue("baofoo_recharge_default", "merchantId"));
|
|
|
+ }
|
|
|
+ if (null == merchantId) {
|
|
|
+ throw new ServiceException(-1, "支付下单失败[004]!");
|
|
|
+ }
|
|
|
+ payRequestBody.put("merchantId", merchantId);
|
|
|
+ JSONObject userInfo = new JSONObject();
|
|
|
+ UserBankInfo bankInfo = userBankInfoService.getById(orderBayInfoEntry.getBankId());
|
|
|
+ userInfo.put("agreementNo", bankInfo.getMsgId());
|
|
|
+ userInfo.put("loginNo", bankInfo.getAccount());
|
|
|
+ userInfo.put("customerType", StringUtils.isNotEmpty(orderBayInfoEntry.getAccountType()) ? orderBayInfoEntry.getAccountType().toUpperCase() : orderBayInfoEntry.getAccountType());
|
|
|
+ payRequestBody.put("rechargeUserInfoDto", userInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 支付成功回调
|
|
|
+ *
|
|
|
+ * @param resourceData
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Result payBackOrder(ResourceData resourceData) {
|
|
|
+ String out_trade_no = resourceData.getOut_trade_no();
|
|
|
+ AuctionOrder auctionOrder = new AuctionOrder();
|
|
|
+ auctionOrder.setTradeNo(out_trade_no);
|
|
|
+ //判断是否已经支付成功
|
|
|
+ auctionOrder = getOne(checkWrapper(auctionOrder, false), false);
|
|
|
+ if (null != auctionOrder) {
|
|
|
+ if (101 == auctionOrder.getStatus() || (101 != auctionOrder.getStatus() && Constants.TRADE_SUCCESS_EN.equals(auctionOrder.getPaymentStatus()))) {
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+ auctionOrder.setPaymentSuccessTime(DateUtils.parseDate(resourceData.getSuccess_time()));
|
|
|
+ auctionOrder.setStatus(101);//101 支付成功
|
|
|
+ auctionOrder.setPaymentMsg(JSONObject.toJSONString(resourceData));
|
|
|
+ auctionOrder.setPaymentStatus(resourceData.getTrade_state());
|
|
|
+ auctionOrder.setPaymentNum(resourceData.getTransaction_id());
|
|
|
+ auctionOrder.setActualPayable(new BigDecimal(resourceData.getAmount().getPayer_total()).divide(new BigDecimal(100)));
|
|
|
+ boolean b = updateById(auctionOrder);
|
|
|
+ if (b) {
|
|
|
+ //添加财务对账
|
|
|
+ AuctionOrder finalAuctionOrder = auctionOrder;
|
|
|
+ Thread t = new Thread() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ try {
|
|
|
+ OrderBaseInfoDto orderBaseInfoDto = new OrderBaseInfoDto();
|
|
|
+ BeanUtils.copyProperties(orderBaseInfoDto, finalAuctionOrder);
|
|
|
+ orderBaseInfoDto.setMerchantId(Long.valueOf(finalAuctionOrder.getShopId()));//商家id
|
|
|
+ orderBaseInfoDto.setTradeNo(finalAuctionOrder.getTradeNo());//tradeNo
|
|
|
+ orderBaseInfoDto.setUserId(Long.valueOf(finalAuctionOrder.getAccountId()));//用户id
|
|
|
+ orderBaseInfoDto.setPaymentSubType(finalAuctionOrder.getPaymentSubType());//支付子类型
|
|
|
+ orderBaseInfoDto.setPaymentType(finalAuctionOrder.getPaymentType());//支付类型
|
|
|
+ orderBaseInfoDto.setActualPayment(finalAuctionOrder.getActualPayable());//实付金额
|
|
|
+ orderBaseInfoDto.setAccountsPayable(finalAuctionOrder.getTotalPrice());//应付金额
|
|
|
+ orderBaseInfoDto.setPurchaseCount(Long.valueOf(finalAuctionOrder.getNum()));//数量
|
|
|
+ sysBaseService.insertSysFinceByOrder(orderBaseInfoDto, "支付");
|
|
|
+ //拍品支付回传
|
|
|
+ AuctionOrderList auctionOrderList = new AuctionOrderList();
|
|
|
+ auctionOrderList.setOrderId(Math.toIntExact(orderBaseInfoDto.getId()));
|
|
|
+ List<AuctionOrderListDto> list = auctionOrderListService.list(auctionOrderList);
|
|
|
+ log.info(" 查询子表数据:{}", list);
|
|
|
+ if (null != list && list.size() > 0) {
|
|
|
+ List<String> collect = list.stream().map(item -> {
|
|
|
+ AuctionOrderListDto auctionOrderListDto = JSONObject.parseObject(JSONObject.toJSONString(item), AuctionOrderListDto.class);
|
|
|
+ return auctionOrderListDto.getGoodsId();
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ JSONArray array = (JSONArray) JSONArray.toJSON(collect);
|
|
|
+ log.info(" 传入数据:{}", array);
|
|
|
+ String ret = HttpClientUtil.httpRequestJSON(internalLot, "POST", JSONArray.toJSONString(array), null);
|
|
|
+ log.info(" 请求接口:{} 返回结果:{}", internalLot, ret);
|
|
|
+ }
|
|
|
+ /*JSONArray array = new JSONArray();
|
|
|
+ array.add(finalAuctionOrder.getEventId());
|
|
|
+ String ret = HttpClientUtil.httpRequestJSON(internalLot, "POST", JSONArray.toJSONString(array), null);
|
|
|
+ log.info(" 请求接口:{} 返回结果:{}",internalLot,ret);*/
|
|
|
+ } catch (IllegalAccessException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (InvocationTargetException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ pools.execute(t);
|
|
|
+ return Result.ok("操作成功");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Result.error("更新出错!");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存钱包消费记录
|
|
|
+ *
|
|
|
+ * @param resourceData
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Result rechargeExpendCallBack(ResourceData resourceData) {
|
|
|
+ String out_trade_no = resourceData.getOut_trade_no();
|
|
|
+ AuctionOrder auctionOrder = selectGroupOrderInfo(out_trade_no);
|
|
|
+ String orderCategory = "未知";
|
|
|
+ if ("PAY".equals(resourceData.getTrade_state())) {
|
|
|
+ orderCategory = "expend";
|
|
|
+ auctionOrder.setPaymentNum(resourceData.getTransaction_id());
|
|
|
+ } else if ("REFUND".equals(resourceData.getTrade_state())) {
|
|
|
+ orderCategory = "income";
|
|
|
+ auctionOrder.setAuctionName("退款");
|
|
|
+ auctionOrder.setOrderNo(out_trade_no);
|
|
|
+ auctionOrder.setRefundNo(out_trade_no);
|
|
|
+ }
|
|
|
+ //如果查询到数据
|
|
|
+ if (null != auctionOrder) {
|
|
|
+ auctionOrder.setStatus(null);
|
|
|
+ Result<AuctionOrderDto> oneDto = getOneDto(auctionOrder);
|
|
|
+ if ("PAY".equals(resourceData.getTrade_state())) {
|
|
|
+ auctionOrder.setPaymentMsg(JSONObject.toJSONString(resourceData));
|
|
|
+ } else if ("REFUND".equals(resourceData.getTrade_state())) {
|
|
|
+ auctionOrder.setRefundMsg(JSONObject.toJSONString(resourceData));
|
|
|
+ auctionOrder.setRefundSuccessTime(new Date());
|
|
|
+ }
|
|
|
+ auctionOrder.setStatus(101);//操作成功
|
|
|
+ auctionOrder.setTradeNo(out_trade_no);
|
|
|
+ auctionOrder.setOrderType("recharge");
|
|
|
+ auctionOrder.setPayCategory(resourceData.getBank_type());
|
|
|
+ auctionOrder.setPaymentType("recharge");
|
|
|
+ auctionOrder.setOrderCategory(orderCategory);
|
|
|
+ auctionOrder.setTotalPrice(new BigDecimal(resourceData.getAmount().getTotal()).divide(Constants.big_one_hundred).setScale(BigDecimal.ROUND_FLOOR));
|
|
|
+ auctionOrder.setNum(1);
|
|
|
+ //判断是否已经有记录
|
|
|
+ if (oneDto.isSuccess()) {
|
|
|
+ AuctionOrderDto auctionOrderDto = oneDto.getData();
|
|
|
+ auctionOrder.setId(auctionOrderDto.getId());
|
|
|
+ log.info(" 更新钱包消费记录:{} ", auctionOrder);
|
|
|
+ updateById(auctionOrder);
|
|
|
+ } else {
|
|
|
+ log.info(" 添加钱包消费记录:{} ", auctionOrder);
|
|
|
+ save(auctionOrder);
|
|
|
+ }
|
|
|
+ saveOrUpdate(auctionOrder);
|
|
|
+ //同步用户钱包余额
|
|
|
+ Map<String, String> param = new HashMap<>();
|
|
|
+ param.put("type", "recharge");
|
|
|
+ param.put("payWay", resourceData.getSubPaymentType());
|
|
|
+ param.put("userId", String.valueOf(auctionOrder.getAccountId()));
|
|
|
+ //调用接口
|
|
|
+ String post = null;
|
|
|
+ if (sycnWalletInfoUrl.contains("http:")) {
|
|
|
+ post = HttpClientUtil.httpRequestJSON(sycnWalletInfoUrl, "POST", JSONObject.toJSONString(param), null);
|
|
|
+ } else {
|
|
|
+ Map<String, String> header = new HashMap<>();
|
|
|
+ header.put("Content-Type", "application/json");
|
|
|
+ post = HttpClientUtil.httpsRequest(sycnWalletInfoUrl, "POST", JSONObject.toJSONString(param), header);
|
|
|
+ }
|
|
|
+ log.info(" 同步用户钱包余额结果:{} ", post);
|
|
|
+ return Result.ok();
|
|
|
+ } else {
|
|
|
+ return Result.error();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 退款
|
|
|
+ *
|
|
|
+ * @param orderBayInfoEntry
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Result refund(OrderBayInfoEntry orderBayInfoEntry) {
|
|
|
+ AuctionOrder auctionOrder = getById(orderBayInfoEntry.getId());//订单信息
|
|
|
+ //判断订单状态
|
|
|
+ if (Constants.refund_status.contains(auctionOrder.getStatus())) {
|
|
|
+ return Result.error("退款失败【" + sysBaseService.selectDictLabel("order_status", String.valueOf(auctionOrder.getStatus())) + "】!");
|
|
|
+ }
|
|
|
+ Result queryInfo = Result.error();
|
|
|
+ if (((auctionOrder.getActualPayable() == null || Constants.big_zero.compareTo(auctionOrder.getActualPayable()) == 0)
|
|
|
+ && auctionOrder.getPoint() > 0)) {
|
|
|
+ queryInfo = Result.success();
|
|
|
+ } else {
|
|
|
+ queryInfo = queryPayInfo(auctionOrder);
|
|
|
+ }
|
|
|
+ if (queryInfo.isSuccess()) {
|
|
|
+ if (Constants.refund_freight.equals(orderBayInfoEntry.getRefundType()) &&
|
|
|
+ (null == auctionOrder.getFreightAmount() || Constants.big_zero.compareTo(auctionOrder.getFreightAmount()) > -1)) {
|
|
|
+ return Result.error("退款失败【该订单无快递费可退】请确认订单信息!");
|
|
|
+ }
|
|
|
+ if (Constants.refund_order.equals(orderBayInfoEntry.getRefundType()) &&
|
|
|
+ (null == auctionOrder.getActualPayable() || Constants.big_zero.compareTo(auctionOrder.getActualPayable()) == 0)) {
|
|
|
+ return Result.error("退款失败【该订单无费用可退】请确认订单信息!");
|
|
|
+ }
|
|
|
+ //进行退款
|
|
|
+ BigDecimal refundFee = Constants.big_zero;
|
|
|
+ //如果退款金额为空 则直接退订单可退金额
|
|
|
+ BigDecimal actualPayable = null != auctionOrder.getActualPayable() ? auctionOrder.getActualPayable() : Constants.big_zero;//实际支付金额
|
|
|
+ BigDecimal freightAmount = null != auctionOrder.getFreightAmount() ? auctionOrder.getFreightAmount() : Constants.big_zero;//快递费
|
|
|
+ BigDecimal refundFeed = null == auctionOrder.getRefundFee() ? Constants.big_zero : auctionOrder.getRefundFee();//已退款金额
|
|
|
+ //传入退款金额
|
|
|
+ BigDecimal inRefundFee = StringUtils.isEmpty(orderBayInfoEntry.getRefundFee()) ? Constants.big_zero : new BigDecimal(orderBayInfoEntry.getRefundFee());
|
|
|
+ //如果退运费
|
|
|
+ if (Constants.refund_freight.equals(orderBayInfoEntry.getRefundType())) {
|
|
|
+ refundFee = StringUtils.isEmpty(orderBayInfoEntry.getRefundFee()) ? freightAmount : inRefundFee;
|
|
|
+ } else
|
|
|
+ //如果退订单
|
|
|
+ if (Constants.refund_order.equals(orderBayInfoEntry.getRefundType())) {
|
|
|
+ refundFee = StringUtils.isEmpty(orderBayInfoEntry.getRefundFee()) ? actualPayable.subtract(refundFeed) : inRefundFee;
|
|
|
+ if (refundFee.compareTo(actualPayable.subtract(refundFeed)) > 1) {
|
|
|
+ return Result.error("退款失败【超过该订单可退金额:" + actualPayable.subtract(refundFeed) + "】请确认订单信息!");
|
|
|
+ }
|
|
|
+ } else // if(Constants.refund_order.equals(orderBayInfoEntry.getRefundType())) //如果 全部退款:包含订单和快递费
|
|
|
+ {
|
|
|
+ //如果 全部退款:包含订单和快递费(默认) 直接退款,不取所传金额
|
|
|
+ refundFee = actualPayable.subtract(refundFeed).add(freightAmount);
|
|
|
+ }
|
|
|
+ //如果是保证金订单 退回保证金及积分
|
|
|
+ boolean refundPoint = false;
|
|
|
+ if (null != auctionOrder.getPoint() && 0 != auctionOrder.getPoint()) {
|
|
|
+ changeUserPoint(auctionOrder, auctionOrder.getPoint() * 100);
|
|
|
+ refundPoint = true;
|
|
|
+ }
|
|
|
+ //退款操作 1 > 0 = -1 <
|
|
|
+ if (Constants.big_zero.compareTo(refundFee) > -1) {
|
|
|
+ if (refundPoint) {
|
|
|
+ auctionOrder.setStatus(205);//已经完全退款
|
|
|
+ auctionOrder.setRefundSuccessTime(new Date());
|
|
|
+ boolean b = updateById(auctionOrder);
|
|
|
+ return Result.success("已完成退款!");
|
|
|
+ }
|
|
|
+ return Result.error("退款失败【该订单无可退金额:" + refundFee + "】请确认订单信息!");
|
|
|
+ }
|
|
|
+ //调用接口查询是否已经支付成功
|
|
|
+ JSONObject refundRequestBody = new JSONObject();
|
|
|
+ refundRequestBody.put("payWay", auctionOrder.getPaymentSubType()); //支付方式
|
|
|
+ refundRequestBody.put("orderNo", auctionOrder.getTradeNo());//支付编码
|
|
|
+ refundRequestBody.put("refundAmount", refundFee);//需要退款金额
|
|
|
+ refundRequestBody.put("refundMsg", orderBayInfoEntry.getRefundMsg());//退款描述
|
|
|
+ String ret = null;
|
|
|
+ if (refund.contains("http:")) {
|
|
|
+ ret = HttpClientUtil.httpRequestJSON(refund, "POST", JSONObject.toJSONString(refundRequestBody), null);
|
|
|
+ } else {
|
|
|
+ Map<String, String> header = new HashMap<>();
|
|
|
+ header.put("Content-Type", "application/json");
|
|
|
+ ret = HttpClientUtil.httpsRequest(refund, "POST", JSONObject.toJSONString(refundRequestBody), header);
|
|
|
+ }
|
|
|
+ Result result = JSONObject.parseObject(ret, Result.class);
|
|
|
+ log.info(" 退款返回数据:》》》 {}", result);
|
|
|
+ if (null != result) {
|
|
|
+ if (result.isSuccess()) {
|
|
|
+ Map map = result.getResult();
|
|
|
+ JSONObject jsonResult = new JSONObject(map);
|
|
|
+ //根据退款状态修改订单状态:
|
|
|
+ JSONObject data = jsonResult.getJSONObject("data");
|
|
|
+ String refundChange = data.getString("fund_change");
|
|
|
+ /*if(!Constants.refund_order.equals(orderBayInfoEntry.getRefundType())){
|
|
|
+ //退款配送费
|
|
|
+// auctionOrder.setFreightAmount(freightAmount.subtract(refundFee));
|
|
|
+ }*/
|
|
|
+ auctionOrder.setRefundStatus(data.getString("refund_status"));//退款状态
|
|
|
+ auctionOrder.setRefundFee(refundFeed.add(refundFee));//总退款金额
|
|
|
+ auctionOrder.setRefundNo(data.getString("out_refund_no"));
|
|
|
+ auctionOrder.setRefundTime(new Date());
|
|
|
+ auctionOrder.setRefundMsg(StringUtils.isNotEmpty(auctionOrder.getMsg()) ? auctionOrder.getMsg() + "," + data.toJSONString() : data.toJSONString());//退款返回数据
|
|
|
+ if (refundChange.equals("Y")) {//退款操作成功
|
|
|
+ if (auctionOrder.getRefundFee().compareTo(actualPayable) == 0) {
|
|
|
+ auctionOrder.setStatus(205);//已经完全退款
|
|
|
+ auctionOrder.setRefundSuccessTime(new Date());
|
|
|
+ }
|
|
|
+ } else if (refundChange.equals("P")) {//退款中,等待退款回调
|
|
|
+ auctionOrder.setStatus(204);//退款中
|
|
|
+ }
|
|
|
+ boolean b = updateById(auctionOrder);
|
|
|
+ if (b && refundChange.equals("Y")) {
|
|
|
+ //财务对账记录
|
|
|
+ AuctionOrder finalAuctionOrder = auctionOrder;
|
|
|
+ Thread t = new Thread() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ try {
|
|
|
+ OrderBaseInfoDto orderBaseInfoDto = new OrderBaseInfoDto();
|
|
|
+ BeanUtils.copyProperties(orderBaseInfoDto, finalAuctionOrder);
|
|
|
+ orderBaseInfoDto.setMerchantId(Long.valueOf(finalAuctionOrder.getShopId()));//商家id
|
|
|
+ orderBaseInfoDto.setTradeNo(finalAuctionOrder.getTradeNo());//tradeNo
|
|
|
+ orderBaseInfoDto.setUserId(Long.valueOf(finalAuctionOrder.getAccountId()));//用户id
|
|
|
+ orderBaseInfoDto.setPaymentSubType(finalAuctionOrder.getPaymentSubType());//支付子类型
|
|
|
+ orderBaseInfoDto.setPaymentType(finalAuctionOrder.getPaymentType());//支付类型
|
|
|
+ orderBaseInfoDto.setActualPayment(finalAuctionOrder.getActualPayable());//实付金额
|
|
|
+ orderBaseInfoDto.setAccountsPayable(finalAuctionOrder.getTotalPrice());//应付金额
|
|
|
+ orderBaseInfoDto.setPurchaseCount(Long.valueOf(finalAuctionOrder.getNum()));//数量
|
|
|
+ orderBaseInfoDto.setOutRefundNo(data.getString("out_refund_no"));
|
|
|
+ sysBaseService.insertSysFinceByOrder(orderBaseInfoDto, "退款");
|
|
|
+ //如果是保证金订单 退回保证金及积分
|
|
|
+ /*if(null != auctionOrder.getPoint() && 0 != auctionOrder.getPoint()){
|
|
|
+ changeUserPoint(auctionOrder,auctionOrder.getPoint());
|
|
|
+ }*/
|
|
|
+ } catch (IllegalAccessException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (InvocationTargetException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ pools.execute(t);
|
|
|
+ }
|
|
|
+ return Result.success("操作成功!");
|
|
|
+ }
|
|
|
+ return Result.success(result.getMsg());
|
|
|
+ } else {
|
|
|
+ throw new ServiceException(-1, "退款失败[未查到支付信息]!");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if ("TRADE_REFUND".equals(queryInfo.getMsg())) {
|
|
|
+ //已经退款
|
|
|
+ auctionOrder.setStatus(205);//已经完全退款
|
|
|
+ boolean b = updateById(auctionOrder);
|
|
|
+ log.info(" 已经完成退款>>{} ", auctionOrder);
|
|
|
+ return Result.success("已完成退款[000]!");
|
|
|
+ }
|
|
|
+ return queryInfo;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用户积分变更
|
|
|
+ *
|
|
|
+ * @param auctionOrder
|
|
|
+ * @param point 负为扣除,正为增加
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void changeUserPoint(AuctionOrder auctionOrder, int point) {
|
|
|
+ //扣除用户积分到拍卖积分订单
|
|
|
+ PointOrderInfo orderInfo = new PointOrderInfo();
|
|
|
+ orderInfo.setId(Long.valueOf(auctionOrder.getId()));
|
|
|
+ orderInfo.setUserId(Long.valueOf(auctionOrder.getAccountId()));
|
|
|
+ orderInfo.setOrderNo(auctionOrder.getOrderNo());
|
|
|
+ mqService.sendPointMq(orderInfo, MqConstans.POINT_AUCTION, point);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询订单支付情况
|
|
|
+ *
|
|
|
+ * @param auctionOrder
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private Result queryPayInfo(AuctionOrder auctionOrder) {
|
|
|
+ //调用接口查询是否已经支付成功
|
|
|
+ JSONObject payRequestBody = new JSONObject();
|
|
|
+ payRequestBody.put("payWay", auctionOrder.getPaymentSubType()); //支付方式
|
|
|
+ payRequestBody.put("orderNo", auctionOrder.getTradeNo());//支付编码
|
|
|
+ String ret = null;
|
|
|
+ if (query.contains("http:")) {
|
|
|
+ ret = HttpClientUtil.httpRequestJSON(query, "POST", JSONObject.toJSONString(payRequestBody), null);
|
|
|
+ } else {
|
|
|
+ Map<String, String> header = new HashMap<>();
|
|
|
+ header.put("Content-Type", "application/json");
|
|
|
+ ret = HttpClientUtil.httpsRequest(query, "POST", JSONObject.toJSONString(payRequestBody), header);
|
|
|
+ }
|
|
|
+ Result result = JSONObject.parseObject(ret, Result.class);
|
|
|
+ log.info(" 查询返回数据:》》》 {}", result);
|
|
|
+ if (null != result) {
|
|
|
+ if (result.isSuccess()) {
|
|
|
+ JSONObject jsonResult = (JSONObject) result.getData();
|
|
|
+ return Result.success(jsonResult);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new ServiceException(-1, "操作失败[未查到支付信息]!");
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询钱包订单列表
|
|
|
+ *
|
|
|
+ * @param orderBaseEntity
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Result searchRechargeOrders(OrderBaseEntity orderBaseEntity) {
|
|
|
+ AuctionOrder auctionOrder = new AuctionOrder();
|
|
|
+ try {
|
|
|
+ BeanUtils.copyProperties(auctionOrder, orderBaseEntity);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(" 设置参数异常:{} ", e);
|
|
|
+ }
|
|
|
+ boolean checkUser = true;
|
|
|
+ if ("merchant".equals(orderBaseEntity.getAccountType())) {
|
|
|
+ auctionOrder.setShopId(getAppUserMerchantId());
|
|
|
+ checkUser = false;
|
|
|
+ }
|
|
|
+ auctionOrder.setSord("desc");
|
|
|
+ auctionOrder.setSidx("create_time");
|
|
|
+ if ("expend".equals(auctionOrder.getOrderCategory()) || "withdraw".equals(auctionOrder.getOrderCategory())) {
|
|
|
+ auctionOrder.setOrderCategory(null);
|
|
|
+ QueryWrapper<AuctionOrder> auctionOrderQueryWrapper = checkWrapper(auctionOrder, true)
|
|
|
+ .in("order_category", "expend", "withdraw");
|
|
|
+ return listPage(auctionOrderQueryWrapper, auctionOrder);
|
|
|
+ } else if ("income".equals(auctionOrder.getOrderCategory()) || "recharge".equals(auctionOrder.getOrderCategory())) {
|
|
|
+ auctionOrder.setOrderCategory(null);
|
|
|
+ QueryWrapper<AuctionOrder> auctionOrderQueryWrapper = checkWrapper(auctionOrder, true)
|
|
|
+ .in("order_category", "recharge", "income");
|
|
|
+ return listPage(auctionOrderQueryWrapper, auctionOrder);
|
|
|
+ }
|
|
|
+ return listPage(auctionOrder, checkUser);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询钱包订单列表
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Result searchOrderById(Integer id, boolean checkUser) {
|
|
|
+ AuctionOrder auctionOrder = new AuctionOrder();
|
|
|
+ auctionOrder.setId(id);
|
|
|
+ return getOneDto(auctionOrder, checkUser);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public AuctionOrder selectGroupOrderInfo(String tradeNo) {
|
|
|
+ return baseMapper.selectGroupOrderInfo(tradeNo);
|
|
|
+ }
|
|
|
+ //查询下次提现时间
|
|
|
+ @Override
|
|
|
+ public Result searchWithdrawalTime(){
|
|
|
+ //近14天可提现1次 根据配置
|
|
|
+ String cycle = sysBaseService.selectDictValue("withdraw_config", "cycle");//周期
|
|
|
+ String times = sysBaseService.selectDictValue("withdraw_config", "times");//次数
|
|
|
+ if(StringUtils.isEmpty(cycle) || StringUtils.isEmpty(times)){
|
|
|
+ throw new ServiceException(-1, "提现失败[401]!");
|
|
|
+ }
|
|
|
+ //查询是否符合资格
|
|
|
+ AuctionOrder auctionOrder = new AuctionOrder();
|
|
|
+ auctionOrder.setOrderCategory("withdraw");//提现
|
|
|
+ auctionOrder.setStatus(101);//提现成功
|
|
|
+ //指定时间
|
|
|
+ Date date = DateUtils.addCalendar(new Date(), DateUtils.day, -Integer.parseInt(cycle));
|
|
|
+ //查询指定条件范围内的数据
|
|
|
+ QueryWrapper<AuctionOrder> auctionOrderQueryWrapper = checkWrapper(auctionOrder, true)
|
|
|
+ .gt("create_time",date)
|
|
|
+ .orderBy(false,false,"id")
|
|
|
+ ;
|
|
|
+ Result<AuctionOrderDto> dtoResult = listPage(auctionOrderQueryWrapper, auctionOrder);
|
|
|
+ if (dtoResult.isSuccess()) {
|
|
|
+ List<AuctionOrderDto> dataList = dtoResult.getDataList();
|
|
|
+ if(null != dataList && dataList.size() > 0){
|
|
|
+ if(dataList.size() >= Integer.parseInt(times) ){
|
|
|
+ Date nextDate = DateUtils.addCalendar(dataList.get(0).getCreateTime(), DateUtils.day, Integer.parseInt(cycle));
|
|
|
+ return Result.error("提现失败!近" + cycle + "日内可提现" +(dataList.size() - Integer.parseInt(times)) + "次")
|
|
|
+ .put("nextWithdrawTime",DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, nextDate));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+}
|