|  | @@ -1,74 +1,30 @@
 | 
	
		
			
				|  |  |  package com.fs.app.controller;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -import cn.binarywang.wx.miniapp.api.WxMaService;
 | 
	
		
			
				|  |  | -import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -import cn.hutool.core.util.IdUtil;
 | 
	
		
			
				|  |  |  import cn.hutool.core.util.ObjectUtil;
 | 
	
		
			
				|  |  | -import cn.hutool.core.util.StrUtil;
 | 
	
		
			
				|  |  | -import cn.hutool.json.JSONUtil;
 | 
	
		
			
				|  |  | -import com.alibaba.fastjson.JSON;
 | 
	
		
			
				|  |  | -import com.alibaba.fastjson.JSONArray;
 | 
	
		
			
				|  |  | -import com.alibaba.fastjson.JSONObject;
 | 
	
		
			
				|  |  |  import com.fs.app.annotation.Login;
 | 
	
		
			
				|  |  |  import com.fs.common.annotation.RepeatSubmit;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -import com.fs.common.config.FSSysConfig;
 | 
	
		
			
				|  |  |  import com.fs.common.core.domain.R;
 | 
	
		
			
				|  |  |  import com.fs.common.exception.CustomException;
 | 
	
		
			
				|  |  | -import com.fs.common.utils.*;
 | 
	
		
			
				|  |  | -import com.fs.huifuPay.domain.HuiFuCreateOrder;
 | 
	
		
			
				|  |  | -import com.fs.huifuPay.domain.HuifuCreateOrderResult;
 | 
	
		
			
				|  |  | -import com.fs.huifuPay.dto.*;
 | 
	
		
			
				|  |  | -import com.fs.huifuPay.service.HuiFuService;
 | 
	
		
			
				|  |  | -import com.fs.store.service.handler.PaymentHandler;
 | 
	
		
			
				|  |  | -import com.fs.store.service.handler.PaymentHandlerHolder;
 | 
	
		
			
				|  |  | -import com.fs.store.service.handler.param.PayProcessContext;
 | 
	
		
			
				|  |  | -import com.fs.tzBank.TzBankService;
 | 
	
		
			
				|  |  | -import com.fs.pay.pay.domain.CreateWxOrderResult;
 | 
	
		
			
				|  |  | -import com.fs.pay.pay.dto.OrderQueryDTO;
 | 
	
		
			
				|  |  | -import com.fs.pay.pay.dto.WxJspayDTO;
 | 
	
		
			
				|  |  | -import com.fs.pay.pay.service.PayService;
 | 
	
		
			
				|  |  | -import com.fs.store.constants.StoreConstants;
 | 
	
		
			
				|  |  |  import com.fs.store.domain.*;
 | 
	
		
			
				|  |  | -import com.fs.system.domain.SysConfig;
 | 
	
		
			
				|  |  | -import com.fs.system.mapper.SysConfigMapper;
 | 
	
		
			
				|  |  | -import com.fs.tzBank.utils.TzConfigUtils;
 | 
	
		
			
				|  |  | -import com.fs.wx.miniapp.config.WxMaConfiguration;
 | 
	
		
			
				|  |  | -import com.fs.wx.miniapp.config.WxMaProperties;
 | 
	
		
			
				|  |  | -import com.fs.wx.pay.config.WxPayProperties;
 | 
	
		
			
				|  |  | -import com.fs.erp.service.IErpOrderService;
 | 
	
		
			
				|  |  | -import com.fs.store.config.StoreConfig;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |  import com.fs.store.dto.FsStoreOrderComputeDTO;
 | 
	
		
			
				|  |  | -import com.fs.store.enums.OrderInfoEnum;
 | 
	
		
			
				|  |  | -import com.fs.store.mapper.FsStorePaymentMapper;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  import com.fs.store.param.*;
 | 
	
		
			
				|  |  |  import com.fs.store.service.*;
 | 
	
		
			
				|  |  |  import com.fs.store.vo.FsMyStoreOrderListQueryVO;
 | 
	
		
			
				|  |  | -import com.fs.store.vo.FsStoreOrderItemVO;
 | 
	
		
			
				|  |  | -import com.fs.pay.service.IPayService;
 | 
	
		
			
				|  |  | -import com.fs.system.service.ISysConfigService;
 | 
	
		
			
				|  |  | -import com.github.binarywang.wxpay.service.WxPayService;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  import com.github.pagehelper.PageHelper;
 | 
	
		
			
				|  |  |  import com.github.pagehelper.PageInfo;
 | 
	
		
			
				|  |  | -import com.google.gson.Gson;
 | 
	
		
			
				|  |  |  import io.swagger.annotations.Api;
 | 
	
		
			
				|  |  |  import io.swagger.annotations.ApiOperation;
 | 
	
		
			
				|  |  | -import me.chanjar.weixin.common.error.WxErrorException;
 | 
	
		
			
				|  |  | -import org.apache.commons.collections4.CollectionUtils;
 | 
	
		
			
				|  |  |  import org.slf4j.Logger;
 | 
	
		
			
				|  |  |  import org.slf4j.LoggerFactory;
 | 
	
		
			
				|  |  |  import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  | -import org.springframework.transaction.annotation.Transactional;
 | 
	
		
			
				|  |  |  import org.springframework.validation.annotation.Validated;
 | 
	
		
			
				|  |  |  import org.springframework.web.bind.annotation.*;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import javax.servlet.http.HttpServletRequest;
 | 
	
		
			
				|  |  | -import java.math.BigDecimal;
 | 
	
		
			
				|  |  | -import java.text.SimpleDateFormat;
 | 
	
		
			
				|  |  |  import java.util.*;
 | 
	
		
			
				|  |  | -import java.util.concurrent.TimeUnit;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  @Api("商城接口")
 | 
	
	
		
			
				|  | @@ -81,33 +37,13 @@ public class StoreOrderController extends  AppBaseController {
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      private IFsStoreOrderService orderService;
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  | -    private FsStorePaymentMapper fsStorePaymentMapper;
 | 
	
		
			
				|  |  | -    @Autowired
 | 
	
		
			
				|  |  | -    private HuiFuService huiFuService;
 | 
	
		
			
				|  |  | -    @Autowired
 | 
	
		
			
				|  |  | -    private IFsStoreOrderItemService itemService;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    @Autowired
 | 
	
		
			
				|  |  | -    private IFsUserService userService;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    @Autowired
 | 
	
		
			
				|  |  | -    private IFsPrescribeService prescribeService;
 | 
	
		
			
				|  |  | -    @Autowired
 | 
	
		
			
				|  |  | -    private ISysConfigService configService;
 | 
	
		
			
				|  |  | -    @Autowired
 | 
	
		
			
				|  |  |      private IFsStoreAfterSalesService afterSalesService;
 | 
	
		
			
				|  |  | -    @Autowired
 | 
	
		
			
				|  |  | -    private IFsStoreProductPackageService productPackageService;
 | 
	
		
			
				|  |  | -    @Autowired
 | 
	
		
			
				|  |  | -    PayService ybPayService;
 | 
	
		
			
				|  |  | -    @Autowired
 | 
	
		
			
				|  |  | -    TzBankService tzBankService;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Login
 | 
	
		
			
				|  |  |      @ApiOperation("获取我的订单列表")
 | 
	
		
			
				|  |  |      @GetMapping("/getMyStoreOrderList")
 | 
	
		
			
				|  |  | -        public R getMyStoreOrderList(FsMyStoreOrderQueryParam param, HttpServletRequest request){
 | 
	
		
			
				|  |  | +        public R getMyStoreOrderList(FsMyStoreOrderQueryParam param){
 | 
	
		
			
				|  |  |          PageHelper.startPage(param.getPage(), param.getPageSize());
 | 
	
		
			
				|  |  |          param.setUserId(Long.parseLong(getUserId()));
 | 
	
		
			
				|  |  |          List<FsMyStoreOrderListQueryVO> list=orderService.selectFsMyStoreOrderListVO(param);
 | 
	
	
		
			
				|  | @@ -118,7 +54,7 @@ public class StoreOrderController extends  AppBaseController {
 | 
	
		
			
				|  |  |      @Login
 | 
	
		
			
				|  |  |      @ApiOperation("获取销售公司订单列表")
 | 
	
		
			
				|  |  |      @GetMapping("/getCompanyStoreOrderList")
 | 
	
		
			
				|  |  | -    public R getCompanyStoreOrderList(FsMyStoreOrderQueryParam param, HttpServletRequest request){
 | 
	
		
			
				|  |  | +    public R getCompanyStoreOrderList(FsMyStoreOrderQueryParam param){
 | 
	
		
			
				|  |  |          PageHelper.startPage(param.getPage(), param.getPageSize());
 | 
	
		
			
				|  |  |          List<FsMyStoreOrderListQueryVO> list=orderService.selectFsCompanyStoreOrderListVO(param);
 | 
	
		
			
				|  |  |          PageInfo<FsMyStoreOrderListQueryVO> listPageInfo=new PageInfo<>(list);
 | 
	
	
		
			
				|  | @@ -128,77 +64,17 @@ public class StoreOrderController extends  AppBaseController {
 | 
	
		
			
				|  |  |      @Login
 | 
	
		
			
				|  |  |      @ApiOperation("获取我的订单详情")
 | 
	
		
			
				|  |  |      @GetMapping("/getMyStoreOrderById")
 | 
	
		
			
				|  |  | -    public R getMyStoreOrderById(@RequestParam("orderId") Long orderId, HttpServletRequest request){
 | 
	
		
			
				|  |  | -        FsStoreOrder order=orderService.selectFsStoreOrderById(orderId);
 | 
	
		
			
				|  |  | -//        if(order.getUserId()-Long.parseLong(getUserId())!=0){
 | 
	
		
			
				|  |  | -//            return R.error("非法操作");
 | 
	
		
			
				|  |  | -//        }
 | 
	
		
			
				|  |  | -        order.setUserPhone(ParseUtils.parsePhone(order.getUserPhone()));
 | 
	
		
			
				|  |  | -        order.setUserAddress(ParseUtils.parseIdCard(order.getUserAddress()));
 | 
	
		
			
				|  |  | -        List<FsStoreOrderItemVO> list=itemService.selectFsStoreOrderItemListByOrderId(orderId);
 | 
	
		
			
				|  |  | -        Calendar calendar = Calendar.getInstance();
 | 
	
		
			
				|  |  | -        calendar.setTime(order.getCreateTime());
 | 
	
		
			
				|  |  | -        String json=configService.selectConfigByKey("store.config");
 | 
	
		
			
				|  |  | -        StoreConfig config=JSONUtil.toBean(json,StoreConfig.class);
 | 
	
		
			
				|  |  | -        calendar.add(Calendar.MINUTE,config.getUnPayTime());
 | 
	
		
			
				|  |  | -        SimpleDateFormat format = new   SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 | 
	
		
			
				|  |  | -        String payLimitTime = format.format(calendar.getTime() );
 | 
	
		
			
				|  |  | -        FsPrescribe prescribe=null;
 | 
	
		
			
				|  |  | -        if(order.getPrescribeId()!=null){
 | 
	
		
			
				|  |  | -            prescribe=prescribeService.selectFsPrescribeById(order.getPrescribeId());
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        //处理是否可以申请售后
 | 
	
		
			
				|  |  | -        Integer isAfterSales=0;
 | 
	
		
			
				|  |  | -        if(order.getStatus().equals(OrderInfoEnum.STATUS_3.getValue())) {
 | 
	
		
			
				|  |  | -            //已完成订单 如果是私域用户就不允许售后
 | 
	
		
			
				|  |  | -            if(ObjectUtil.isNotNull(order.getCompanyId())){
 | 
	
		
			
				|  |  | -                isAfterSales=0;
 | 
	
		
			
				|  |  | -            } else {
 | 
	
		
			
				|  |  | -                isAfterSales=1;
 | 
	
		
			
				|  |  | -                if (order.getFinishTime() != null) {
 | 
	
		
			
				|  |  | -                    if (config.getStoreAfterSalesDay() != null && config.getStoreAfterSalesDay() > 0) {
 | 
	
		
			
				|  |  | -                        //判断完成时间是否超过指定时间
 | 
	
		
			
				|  |  | -                        Calendar calendarAfterSales = new GregorianCalendar();
 | 
	
		
			
				|  |  | -                        calendarAfterSales.setTime(order.getFinishTime());
 | 
	
		
			
				|  |  | -                        calendarAfterSales.add(calendarAfterSales.DATE, config.getStoreAfterSalesDay()); //把日期往后增加一天,整数  往后推,负数往前移动
 | 
	
		
			
				|  |  | -                        if (calendarAfterSales.getTime().getTime() < new Date().getTime()) {
 | 
	
		
			
				|  |  | -                            isAfterSales = 0;
 | 
	
		
			
				|  |  | -                        }
 | 
	
		
			
				|  |  | -                    }
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        else if(order.getStatus()==1||order.getStatus()==2){
 | 
	
		
			
				|  |  | -            isAfterSales=1;
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        return R.ok().put("isAfterSales",isAfterSales).put("order",order).put("items",list).put("payLimitTime",payLimitTime).put("prescribe",prescribe);
 | 
	
		
			
				|  |  | +    public R getMyStoreOrderById(@RequestParam("orderId") Long orderId){
 | 
	
		
			
				|  |  | +        logger.info("获取我的订单详情, 订单ID: {}", orderId);
 | 
	
		
			
				|  |  | +        return orderService.getMyStoreOrderById(orderId);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Login
 | 
	
		
			
				|  |  |      @ApiOperation("获取订单")
 | 
	
		
			
				|  |  |      @GetMapping("/getStoreOrderById")
 | 
	
		
			
				|  |  | -    public R getStoreOrderById(@RequestParam("orderId") Long orderId, HttpServletRequest request){
 | 
	
		
			
				|  |  | +    public R getStoreOrderById(@RequestParam("orderId") Long orderId){
 | 
	
		
			
				|  |  |          logger.info("开始处理获取订单请求, 订单ID: {}", orderId);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        FsStoreOrder order=orderService.selectFsStoreOrderById(orderId);
 | 
	
		
			
				|  |  | -        if(ObjectUtil.isNull(order)){
 | 
	
		
			
				|  |  | -            return R.error("订单不存在");
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        order.setUserPhone(ParseUtils.parsePhone(order.getUserPhone()));
 | 
	
		
			
				|  |  | -        order.setUserAddress(ParseUtils.parseIdCard(order.getUserAddress()));
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        String json=configService.selectConfigByKey("store.config");
 | 
	
		
			
				|  |  | -        StoreConfig config=JSONUtil.toBean(json,StoreConfig.class);
 | 
	
		
			
				|  |  | -        Calendar calendar = Calendar.getInstance();
 | 
	
		
			
				|  |  | -        calendar.setTime(order.getCreateTime());
 | 
	
		
			
				|  |  | -        calendar.add(Calendar.MINUTE,config.getUnPayTime());
 | 
	
		
			
				|  |  | -        SimpleDateFormat format = new   SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 | 
	
		
			
				|  |  | -        String payLimitTime = format.format(calendar.getTime() );
 | 
	
		
			
				|  |  | -        FsStoreProductPackage productPackage=null;
 | 
	
		
			
				|  |  | -        if(order.getIsPackage()!=null&&order.getIsPackage()==1){
 | 
	
		
			
				|  |  | -            productPackage= productPackageService.selectFsStoreProductPackageById(order.getPackageId());
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        return R.ok().put("order",order).put("productPackage",productPackage).put("payLimitTime",payLimitTime);
 | 
	
		
			
				|  |  | +        return orderService.getStoreOrderById(orderId);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Login
 | 
	
	
		
			
				|  | @@ -206,7 +82,6 @@ public class StoreOrderController extends  AppBaseController {
 | 
	
		
			
				|  |  |      @GetMapping("/getStoreOrderByOrderIdTz")
 | 
	
		
			
				|  |  |      public R getStoreOrderByIdRemote(@RequestParam(value = "orderId",required = false) Long orderId,
 | 
	
		
			
				|  |  |                                       @RequestParam(value = "payCode",required = false) String payCode){
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |          logger.info("获取订单-轮询获取信息, 订单ID: {}, payCode: {}", orderId,payCode);
 | 
	
		
			
				|  |  |          return orderService.getStoreOrderByOrderIdTz(orderId,payCode);
 | 
	
		
			
				|  |  |      }
 | 
	
	
		
			
				|  | @@ -216,12 +91,16 @@ public class StoreOrderController extends  AppBaseController {
 | 
	
		
			
				|  |  |      @ApiOperation("确认订单")
 | 
	
		
			
				|  |  |      @PostMapping("/confirm")
 | 
	
		
			
				|  |  |      public R confirm(@Validated @RequestBody FsStoreConfirmOrderParam param){
 | 
	
		
			
				|  |  | +        logger.info("开始处理确认订单请求, 订单ID: {}", param);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          return orderService.confirmOrder(Long.parseLong(getUserId()),param);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |      @Login
 | 
	
		
			
				|  |  |      @ApiOperation("计算订单金额")
 | 
	
		
			
				|  |  |      @PostMapping("/computed")
 | 
	
		
			
				|  |  |      public R computed(@Validated @RequestBody FsStoreOrderComputedParam param){
 | 
	
		
			
				|  |  | +        logger.info("开始处理计算订单金额请求, 参数: {}", param);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          FsStoreOrderComputeDTO dto=orderService.computedOrder(Long.parseLong(getUserId()),param);
 | 
	
		
			
				|  |  |          return R.ok().put("data",dto);
 | 
	
		
			
				|  |  |      }
 | 
	
	
		
			
				|  | @@ -230,6 +109,8 @@ public class StoreOrderController extends  AppBaseController {
 | 
	
		
			
				|  |  |      @ApiOperation("创建订单")
 | 
	
		
			
				|  |  |      @PostMapping("/create")
 | 
	
		
			
				|  |  |      public R create(@Validated @RequestBody FsStoreOrderCreateParam param){
 | 
	
		
			
				|  |  | +        logger.info("开始处理创建订单请求, 参数: {}", param);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          return orderService.createOrder(Long.parseLong(getUserId()),param);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -260,194 +141,20 @@ public class StoreOrderController extends  AppBaseController {
 | 
	
		
			
				|  |  |      @Login
 | 
	
		
			
				|  |  |      @ApiOperation("修改支付类型")
 | 
	
		
			
				|  |  |      @PostMapping("/editPayType")
 | 
	
		
			
				|  |  | -    @Transactional
 | 
	
		
			
				|  |  |      public R editPayType(@Validated @RequestBody FsStoreOrderPayParam param) {
 | 
	
		
			
				|  |  | -        FsStoreOrder order=orderService.selectFsStoreOrderById(param.getOrderId());
 | 
	
		
			
				|  |  | -        if(order==null){
 | 
	
		
			
				|  |  | -            return R.error("订单不存在");
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        if(order.getStatus()!= OrderInfoEnum.STATUS_0.getValue()){
 | 
	
		
			
				|  |  | -            return R.error("订单状态不正确");
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        String orderId=redisCache.getCacheObject("isPaying:"+order.getId());
 | 
	
		
			
				|  |  | -        if(StringUtils.isNotEmpty(orderId)&&orderId.equals(order.getId().toString())){
 | 
	
		
			
				|  |  | -            return R.error("正在支付中...");
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        List<FsStorePayment>  payments=fsStorePaymentMapper.selectFsStorePaymentByOrder(order.getId());
 | 
	
		
			
				|  |  | -        if(payments.size()>0){
 | 
	
		
			
				|  |  | -            for(FsStorePayment payment : payments){
 | 
	
		
			
				|  |  | -                if(StringUtils.isEmpty(payment.getTradeNo())){
 | 
	
		
			
				|  |  | -                    continue;
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | -                OrderQueryDTO orderQueryDTO = new OrderQueryDTO();
 | 
	
		
			
				|  |  | -                orderQueryDTO.setLowOrderId("store-"+payment.getPayCode());
 | 
	
		
			
				|  |  | -                RequestDTO<QueryOrderRestDTO> requestDTO = new RequestDTO<>();
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -                QueryOrderRestDTO queryOrderRestDTO = new QueryOrderRestDTO();
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -                queryOrderRestDTO.setOrderFlowNo(payment.getTradeNo());
 | 
	
		
			
				|  |  | -                TzConfigInfoDTO tzConfigInfoDTO = TzConfigUtils.getConfig();
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -                queryOrderRestDTO.setPlatMerCstNo(tzConfigInfoDTO.getPlatMerCstNo());
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -                requestDTO.setReqBody(queryOrderRestDTO);
 | 
	
		
			
				|  |  | -                requestDTO.setReqHeader(TzReqHeaderDTO.getInstance(payment.getPayCode()));
 | 
	
		
			
				|  |  | -                try {
 | 
	
		
			
				|  |  | -                    TzReqResultDTO<QueryOrderInfoDTO> resultDTO = tzBankService.payQueryOrder(requestDTO);
 | 
	
		
			
				|  |  | -                    if(ObjectUtil.isNotNull(resultDTO)){
 | 
	
		
			
				|  |  | -                        QueryOrderInfoDTO body = resultDTO.getBody();
 | 
	
		
			
				|  |  | -                        if(ObjectUtil.isNotNull(body)){
 | 
	
		
			
				|  |  | -                            if("80".equals(body.getStatus()) || "90".equals(body.getStatus())){
 | 
	
		
			
				|  |  | -                                // 更新订单状态和支付状态
 | 
	
		
			
				|  |  | -                                payment.setStatus(1);
 | 
	
		
			
				|  |  | -                                fsStorePaymentMapper.updateFsStorePayment(payment);
 | 
	
		
			
				|  |  | -                                orderService.payConfirm(1, order.getId(), payment.getPayCode(),
 | 
	
		
			
				|  |  | -                                        payment.getTradeNo(),
 | 
	
		
			
				|  |  | -                                        body.getChlTrxId(),
 | 
	
		
			
				|  |  | -                                        payment.getTradeNo());
 | 
	
		
			
				|  |  | -                                return R.error("订单已支付");
 | 
	
		
			
				|  |  | -                            }
 | 
	
		
			
				|  |  | -                        }
 | 
	
		
			
				|  |  | -                    }
 | 
	
		
			
				|  |  | -                } catch (Exception e) {
 | 
	
		
			
				|  |  | -                    throw new RuntimeException(e);
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        FsUser user=userService.selectFsUserById(order.getUserId());
 | 
	
		
			
				|  |  | -        if(user!=null&& StringUtils.isNotEmpty(user.getMaOpenId())){
 | 
	
		
			
				|  |  | -            //已改价处理
 | 
	
		
			
				|  |  | -            if(order.getIsEditMoney()!=null&&order.getIsEditMoney()==1){
 | 
	
		
			
				|  |  | -                //改过价不做处理
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -            else{
 | 
	
		
			
				|  |  | -                String config=configService.selectConfigByKey("store.config");
 | 
	
		
			
				|  |  | -                StoreConfig storeConfig= JSONUtil.toBean(config,StoreConfig.class);
 | 
	
		
			
				|  |  | -                if(param.getPayType().equals(1)){
 | 
	
		
			
				|  |  | -                    order.setPayType("1");
 | 
	
		
			
				|  |  | -                    order.setPayMoney(order.getPayPrice());
 | 
	
		
			
				|  |  | -                    order.setPayDelivery(BigDecimal.ZERO);
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | -                else if(param.getPayType().equals(2)){
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -                    order.setPayType("2");
 | 
	
		
			
				|  |  | -                    BigDecimal payMoney=order.getPayPrice().multiply(new BigDecimal(storeConfig.getPayRate())).divide(new BigDecimal(100));
 | 
	
		
			
				|  |  | -                    payMoney=new BigDecimal(payMoney.setScale(0, BigDecimal.ROUND_HALF_UP).longValue());
 | 
	
		
			
				|  |  | -                    order.setPayDelivery(order.getPayPrice().subtract(payMoney));
 | 
	
		
			
				|  |  | -                    order.setPayMoney(payMoney);
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | -                else if(param.getPayType().equals(3)){
 | 
	
		
			
				|  |  | -                    //货到付款
 | 
	
		
			
				|  |  | -                    order.setPayType("3");
 | 
	
		
			
				|  |  | -                    order.setPayDelivery(order.getPayPrice() );
 | 
	
		
			
				|  |  | -                    order.setPayMoney(BigDecimal.ZERO);
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | -                orderService.updateFsStoreOrder(order);
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -            return R.ok().put("order",order);
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        else{
 | 
	
		
			
				|  |  | -            return R.error("用户OPENID不存在");
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | +        logger.info("开始处理修改支付类型请求, 参数: {}", param);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +        return orderService.editPayType(param);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Login
 | 
	
		
			
				|  |  |      @ApiOperation("支付尾款")
 | 
	
		
			
				|  |  |      @PostMapping("/payRemain")
 | 
	
		
			
				|  |  | -    @Transactional
 | 
	
		
			
				|  |  |      public R payRemain(@Validated @RequestBody FsStoreOrderPayParam param) {
 | 
	
		
			
				|  |  | -        FsStoreOrder order=orderService.selectFsStoreOrderById(param.getOrderId());
 | 
	
		
			
				|  |  | -        if(order==null){
 | 
	
		
			
				|  |  | -            return R.error("订单不存在");
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        if(order.getStatus()!= OrderInfoEnum.STATUS_2.getValue()){
 | 
	
		
			
				|  |  | -            return R.error("待收货订单可申请支付尾款");
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        if(order.getPayType().equals(1)){
 | 
	
		
			
				|  |  | -            return R.error("此订单已支付");
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        //只有顺风才可以付尾
 | 
	
		
			
				|  |  | -        if(!order.getDeliverySn().trim().equals("SF")){
 | 
	
		
			
				|  |  | -            return R.error("只有顺丰物流支持尾款支付");
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | +        logger.info("开始处理支付尾款请求, 参数: {}", param);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        if(!order.getIsPayRemain().equals(0)){
 | 
	
		
			
				|  |  | -            return R.error("此订单已支付");
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        FsUser user=userService.selectFsUserById(order.getUserId());
 | 
	
		
			
				|  |  | -        if(user!=null&& StringUtils.isNotEmpty(user.getMaOpenId())){
 | 
	
		
			
				|  |  | -            String payCode = IdUtil.getSnowflake(0, 0).nextIdStr();
 | 
	
		
			
				|  |  | -            String json = configService.selectConfigByKey("store.pay");
 | 
	
		
			
				|  |  | -            FsPayConfig fsPayConfig = JSON.parseObject(json, FsPayConfig.class);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -            FsStorePayment storePayment=new FsStorePayment();
 | 
	
		
			
				|  |  | -            storePayment.setCompanyId(order.getCompanyId());
 | 
	
		
			
				|  |  | -            storePayment.setCompanyUserId(order.getCompanyUserId());
 | 
	
		
			
				|  |  | -            storePayment.setStatus(0);
 | 
	
		
			
				|  |  | -            storePayment.setPayMode(fsPayConfig.getType());
 | 
	
		
			
				|  |  | -            storePayment.setPayCode(payCode);
 | 
	
		
			
				|  |  | -            storePayment.setPayMoney(order.getPayDelivery());
 | 
	
		
			
				|  |  | -            storePayment.setCreateTime(new Date());
 | 
	
		
			
				|  |  | -            storePayment.setPayTypeCode("weixin");
 | 
	
		
			
				|  |  | -            storePayment.setBusinessType(2);
 | 
	
		
			
				|  |  | -            storePayment.setRemark("商城订单尾款支付");
 | 
	
		
			
				|  |  | -            storePayment.setOpenId(user.getRealName());
 | 
	
		
			
				|  |  | -            storePayment.setUserId(user.getUserId());
 | 
	
		
			
				|  |  | -            storePayment.setBusinessOrderId(order.getId().toString());
 | 
	
		
			
				|  |  | -            storePayment.setOrderId(order.getId());
 | 
	
		
			
				|  |  | -            storePayment.setIsPayRemain(1);
 | 
	
		
			
				|  |  | -            fsStorePaymentMapper.insertFsStorePayment(storePayment);
 | 
	
		
			
				|  |  | -            if (fsPayConfig.getType().equals("hf")){
 | 
	
		
			
				|  |  | -                HuiFuCreateOrder o = new HuiFuCreateOrder();
 | 
	
		
			
				|  |  | -                o.setTradeType("T_MINIAPP");
 | 
	
		
			
				|  |  | -                o.setOpenid(user.getMaOpenId());
 | 
	
		
			
				|  |  | -                o.setReqSeqId("store_remain-"+storePayment.getPayCode());
 | 
	
		
			
				|  |  | -                o.setTransAmt(storePayment.getPayMoney().toString());
 | 
	
		
			
				|  |  | -                o.setGoodsDesc("商城订单尾款支付");
 | 
	
		
			
				|  |  | -                HuifuCreateOrderResult result = huiFuService.createOrder(o);
 | 
	
		
			
				|  |  | -                //创建订单
 | 
	
		
			
				|  |  | -                if(result.getResp_code()!=null&&(result.getResp_code().equals("00000000")||result.getResp_code().equals("00000100"))){
 | 
	
		
			
				|  |  | -                    FsStorePayment mt=new FsStorePayment();
 | 
	
		
			
				|  |  | -                    mt.setPaymentId(storePayment.getPaymentId());
 | 
	
		
			
				|  |  | -                    mt.setTradeNo(result.getHf_seq_id());
 | 
	
		
			
				|  |  | -                    fsStorePaymentMapper.updateFsStorePayment(mt);
 | 
	
		
			
				|  |  | -                    redisCache.setCacheObject("isPaying:"+order.getId(),order.getId().toString(),1, TimeUnit.MINUTES);
 | 
	
		
			
				|  |  | -                    return R.ok().put("result",result.getPay_info());
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | -                else{
 | 
	
		
			
				|  |  | -                    return R.error(result.getResp_desc());
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | -            }else if(fsPayConfig.getType().equals("yb")){
 | 
	
		
			
				|  |  | -                WxJspayDTO p = new WxJspayDTO();
 | 
	
		
			
				|  |  | -            // 使用setter方法为对象赋值
 | 
	
		
			
				|  |  | -                p.setPayMoney(order.getPayDelivery().toString());
 | 
	
		
			
				|  |  | -                p.setLowOrderId("store_remain-"+payCode);
 | 
	
		
			
				|  |  | -                p.setBody("商城订单尾款支付");
 | 
	
		
			
				|  |  | -                p.setIsMinipg("1");
 | 
	
		
			
				|  |  | -                p.setReturnUrl(fsPayConfig.getYbNotifyUrl());
 | 
	
		
			
				|  |  | -                p.setOpenId(user.getMaOpenId());
 | 
	
		
			
				|  |  | -                p.setAttach("");
 | 
	
		
			
				|  |  | -                p.setStoreid("0");
 | 
	
		
			
				|  |  | -                CreateWxOrderResult wxOrder = ybPayService.createWxOrder(p);
 | 
	
		
			
				|  |  | -                if(wxOrder.getStatus().equals("100")){
 | 
	
		
			
				|  |  | -                    FsStorePayment ment=new FsStorePayment();
 | 
	
		
			
				|  |  | -                    ment.setPaymentId(storePayment.getPaymentId());
 | 
	
		
			
				|  |  | -                    ment.setTradeNo(wxOrder.getUpOrderId());
 | 
	
		
			
				|  |  | -                    fsStorePaymentMapper.updateFsStorePayment(ment);
 | 
	
		
			
				|  |  | -                    return R.ok().put("result",wxOrder.getPay_info());
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | -            else{
 | 
	
		
			
				|  |  | -                return R.error(wxOrder.getMessage());
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        else{
 | 
	
		
			
				|  |  | -            return R.error("用户OPENID不存在");
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        return R.error("无支付类型");
 | 
	
		
			
				|  |  | +        return orderService.payRemain(param);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -476,7 +183,6 @@ public class StoreOrderController extends  AppBaseController {
 | 
	
		
			
				|  |  |      @Login
 | 
	
		
			
				|  |  |      @ApiOperation("亲友支付")
 | 
	
		
			
				|  |  |      @PostMapping("/otherPaymentRemain")
 | 
	
		
			
				|  |  | -    @Transactional
 | 
	
		
			
				|  |  |      public R otherPaymentRemain(@Validated @RequestBody FsStoreOrderOtherPayParam param, HttpServletRequest request){
 | 
	
		
			
				|  |  |          return orderService.otherPaymentRemain(param);
 | 
	
		
			
				|  |  |      }
 | 
	
	
		
			
				|  | @@ -567,5 +273,4 @@ public class StoreOrderController extends  AppBaseController {
 | 
	
		
			
				|  |  |          return R.ok().put("count0",count0).put("count1",count1).put("count2",count2).put("afterSalesCount",afterSalesCount);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |  }
 |