package com.matrix.system.shopXcx.action; 
 | 
  
 | 
import com.matrix.component.wechat.externalInterface.common.WechatConfigure; 
 | 
import com.matrix.core.anotations.RemoveRequestToken; 
 | 
import com.matrix.core.anotations.SaveRequestToken; 
 | 
import com.matrix.core.constance.MatrixConstance; 
 | 
import com.matrix.core.constance.SystemErrorCode; 
 | 
import com.matrix.core.constance.SystemMessageCode; 
 | 
import com.matrix.core.exception.GlobleException; 
 | 
import com.matrix.core.pojo.AjaxResult; 
 | 
import com.matrix.core.pojo.PaginationVO; 
 | 
import com.matrix.core.tools.*; 
 | 
import com.matrix.component.redis.RedisUserLoginUtils; 
 | 
import com.matrix.system.common.bean.SysUsers; 
 | 
import com.matrix.system.common.constance.AppConstance; 
 | 
  
 | 
import com.matrix.component.wechat.externalInterface.weixinUtil.WeixinServiceUtil; 
 | 
import com.matrix.system.hive.action.util.QueryUtil; 
 | 
import com.matrix.system.shopXcx.api.service.WxShopRefundRecordService; 
 | 
import com.matrix.system.shopXcx.bean.*; 
 | 
import com.matrix.system.shopXcx.dao.ShopCouponRecordDao; 
 | 
import com.matrix.system.shopXcx.dao.ShopDeliveryInfoDao; 
 | 
import com.matrix.system.shopXcx.dao.ShopOrderDao; 
 | 
import com.matrix.system.shopXcx.dao.ShopRefundRecordDao; 
 | 
import com.matrix.component.tools.WxTempLateMsgUtil; 
 | 
import com.matrix.system.shopXcx.api.service.WXShopOrderService; 
 | 
import org.apache.commons.collections.CollectionUtils; 
 | 
import org.springframework.beans.factory.annotation.Autowired; 
 | 
import org.springframework.beans.factory.annotation.Value; 
 | 
import org.springframework.beans.propertyeditors.CustomDateEditor; 
 | 
import org.springframework.stereotype.Controller; 
 | 
import org.springframework.transaction.annotation.Transactional; 
 | 
import org.springframework.web.bind.WebDataBinder; 
 | 
import org.springframework.web.bind.annotation.InitBinder; 
 | 
import org.springframework.web.bind.annotation.RequestMapping; 
 | 
import org.springframework.web.bind.annotation.ResponseBody; 
 | 
import org.springframework.web.servlet.ModelAndView; 
 | 
  
 | 
import java.math.BigDecimal; 
 | 
import java.text.SimpleDateFormat; 
 | 
import java.util.*; 
 | 
  
 | 
/** 
 | 
 * @description 退款记录表 
 | 
 * @author jiangyouyao 
 | 
 * @date 2019-06-16 15:34 
 | 
 */ 
 | 
@Controller 
 | 
@RequestMapping(value = "admin/shopRefundRecord") 
 | 
public class ShopRefundRecordAction { 
 | 
  
 | 
    @Autowired 
 | 
    private ShopRefundRecordDao shopRefundRecordDao; 
 | 
    @Autowired 
 | 
    private ShopOrderDao shopOrderDao; 
 | 
    @Autowired 
 | 
    private WeixinServiceUtil weixinServiceUtil; 
 | 
    @Autowired 
 | 
    private WXShopOrderService wxShopOrderService; 
 | 
    @Autowired 
 | 
    private ShopDeliveryInfoDao shopDeliveryInfoDao; 
 | 
    @Autowired 
 | 
    private RedisUserLoginUtils redisUserLoginUtils; 
 | 
  
 | 
    @Autowired 
 | 
    private ShopCouponRecordDao shopCouponRecordDao; 
 | 
  
 | 
    @Autowired 
 | 
    private WxShopRefundRecordService refundRecordService; 
 | 
  
 | 
    //记录编辑前的值Before_Edit_Value 
 | 
    public static final String BEV="ShopRefundRecord_BEV"; 
 | 
  
 | 
    @Value("${wx_pay_debug_onoff}") 
 | 
    private boolean isDebug; 
 | 
  
 | 
    /** 
 | 
     * 列表显示 
 | 
     */ 
 | 
    @RequestMapping(value =  "/showList") 
 | 
    public @ResponseBody AjaxResult showList(ShopRefundRecord shopRefundRecord, PaginationVO pageVo) { 
 | 
        QueryUtil.setQueryLimitCom(shopRefundRecord); 
 | 
        List<ShopRefundRecord> dataList = shopRefundRecordDao.selectInPage(shopRefundRecord, pageVo); 
 | 
        AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS, dataList, 
 | 
                shopRefundRecordDao.selectTotalRecord(shopRefundRecord)); 
 | 
        return result; 
 | 
    } 
 | 
        
 | 
    /** 
 | 
     * 新增 
 | 
     */    
 | 
    @RemoveRequestToken     
 | 
       @RequestMapping(value =  "/addShopRefundRecord") 
 | 
    public @ResponseBody AjaxResult addShopRefundRecord(ShopRefundRecord shopRefundRecord) { 
 | 
        SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); 
 | 
        shopRefundRecord.setCreateBy(user.getSuName()); 
 | 
        shopRefundRecord.setUpdateBy(user.getSuName()); 
 | 
        shopRefundRecord.setCompanyId(user.getCompanyId()); 
 | 
         int i=shopRefundRecordDao.insert(shopRefundRecord); 
 | 
         if(i > 0){ 
 | 
             return new AjaxResult(AjaxResult.STATUS_SUCCESS, SystemMessageCode.ADD_SUCCES, "退款记录表"); 
 | 
         }else { 
 | 
            throw new GlobleException(SystemErrorCode.DATA_ADD_FAIL); 
 | 
        } 
 | 
    } 
 | 
  
 | 
  
 | 
    /** 
 | 
     * 
 | 
     * @Description (TODO 自定义数据绑定, 解决此问题) 
 | 
     * @param binder 
 | 
     */ 
 | 
    @InitBinder 
 | 
    public void initBinder(WebDataBinder binder) { 
 | 
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); 
 | 
        dateFormat.setLenient(false); 
 | 
        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false)); 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 同意退款按钮 
 | 
     */ 
 | 
    @RequestMapping(value = "/agreeRefund") 
 | 
    public @ResponseBody AjaxResult agreeRefund(ShopRefundRecord shopRefundRecord) { 
 | 
        //将申请退款状态改为等待用户填写物流单号 
 | 
        Map<String, Object> modifyMap = new HashMap<>(); 
 | 
        SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); 
 | 
        String suName = user.getSuName(); 
 | 
        modifyMap.put("id", shopRefundRecord.getId()); 
 | 
        modifyMap.put("refundStatus", AppConstance.WAIT_USER_WRITE_WAYBILLNO); 
 | 
        modifyMap.put("auditStatus", AppConstance.REFUND_AUDITED_PASS); 
 | 
        modifyMap.put("handler", suName); 
 | 
        modifyMap.put("handingTime", new Date()); 
 | 
        int i = shopRefundRecordDao.updateByMap(modifyMap); 
 | 
        if (i > 0) { 
 | 
            //同意退款后发送微信提醒填写物流单号 
 | 
            ShopRefundRecord fundRecord = shopRefundRecordDao.selectById(shopRefundRecord.getId()); 
 | 
            sendRefundLogisticsInfoToUser(fundRecord); 
 | 
            return new AjaxResult(AjaxResult.STATUS_SUCCESS, "操作成功", "退款记录表"); 
 | 
        } else { 
 | 
            throw new GlobleException("操作失败"); 
 | 
        } 
 | 
  
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 拒绝退款 
 | 
     */ 
 | 
    @Transactional(rollbackFor = Exception.class) 
 | 
    @RequestMapping(value = "/refundRefuse") 
 | 
    public @ResponseBody AjaxResult refundRefuse(ShopRefundRecord shopRefundRecord) { 
 | 
        //将拒绝理由加入退款表,将审核状态改为审核不通过 
 | 
        Map<String, Object> modifyMap = new HashMap<>(); 
 | 
        SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); 
 | 
        String suName = user.getSuName(); 
 | 
        modifyMap.put("id", shopRefundRecord.getId()); 
 | 
        modifyMap.put("refundRefuseReason", shopRefundRecord.getRefundRefuseReason()); 
 | 
        modifyMap.put("auditStatus", AppConstance.REFUND_AUDITED_FAILED); 
 | 
        modifyMap.put("handler", suName); 
 | 
        modifyMap.put("handingTime", new Date()); 
 | 
        int i = shopRefundRecordDao.updateByMap(modifyMap); 
 | 
        //将申请退款状态改为退款失败 
 | 
        shopRefundRecordDao.updateRefundStatusByFail(shopRefundRecord.getId(), AppConstance.REFUND_FAIL); 
 | 
        //如果运单号不等于null就将订单状态改为待收货3,为null就改为待配送2 
 | 
        ShopRefundRecord record = new ShopRefundRecord(); 
 | 
        record = shopRefundRecordDao.selectById(shopRefundRecord.getId()); 
 | 
        Map<String, Object> modifyOrder = new HashMap<>(); 
 | 
        //如果运单号不等于null就将订单状态改为待收货3,为null就改为待配送2 
 | 
        ShopDeliveryInfo shopDeliveryInfo = shopDeliveryInfoDao.selectByOrderId(record.getOrderId()); 
 | 
        ShopOrder order = shopOrderDao.selectById(record.getOrderId()); 
 | 
        if(null != order){ 
 | 
            //如果是门店自提就将订单状态改为待收货3 
 | 
            if(AppConstance.SHIPPING_METHOD_SELF .equals(order.getShippingMethod()) ){ 
 | 
                modifyOrder.put("orderStatus", ShopOrder.ORDER_STATUS_WAIT_RECEIVE); 
 | 
            } 
 | 
            if(AppConstance.SHIPPING_METHOD_LOGISTING .equals(order.getShippingMethod()) && null != shopDeliveryInfo.getWaybillNo()){ 
 | 
                modifyOrder.put("orderStatus", ShopOrder.ORDER_STATUS_WAIT_RECEIVE); 
 | 
            } 
 | 
            if(AppConstance.SHIPPING_METHOD_LOGISTING .equals(order.getShippingMethod()) && null == shopDeliveryInfo.getWaybillNo()){ 
 | 
                modifyOrder.put("orderStatus", ShopOrder.ORDER_STATUS_WAIT_SEND); 
 | 
            } 
 | 
            modifyOrder.put("id", record.getOrderId()); 
 | 
            shopOrderDao.updateByMap(modifyOrder); 
 | 
        } 
 | 
        //退款拒绝后发送微信提醒 
 | 
        sendFailedRefundInfoToUser(record); 
 | 
        if (i > 0) { 
 | 
            return new AjaxResult(AjaxResult.STATUS_SUCCESS, "操作成功", "退款记录表"); 
 | 
        } else { 
 | 
            throw new GlobleException("拒绝失败"); 
 | 
        } 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 确认退款(退款审核) 
 | 
     */ 
 | 
    @Transactional(rollbackFor = Exception.class) 
 | 
    @RemoveRequestToken 
 | 
    @RequestMapping(value =  "/modifyShopRefundRecord") 
 | 
    public @ResponseBody AjaxResult modifyShopRefundRecord(ShopRefundRecord newShopRefundRecord) { 
 | 
        if(null != newShopRefundRecord.getRefundRefuseReason()){ 
 | 
            newShopRefundRecord.setRefundRefuseReason(""); 
 | 
        } 
 | 
        ShopRefundRecord oldShopRefundRecord = WebUtil.getSessionAttribute(BEV); 
 | 
            int i = 0; 
 | 
            Map<String, Object> modifyMap = new HashMap<>(); 
 | 
            try { 
 | 
                if (!ModelUtils.isModified(oldShopRefundRecord, newShopRefundRecord)) { 
 | 
                    i = MatrixConstance.DML_SUCCESSS; 
 | 
                } 
 | 
                modifyMap = ModelUtils.comparePojo2Map(oldShopRefundRecord, newShopRefundRecord); 
 | 
  
 | 
            } catch (Exception e) { 
 | 
                throw new GlobleException(SystemErrorCode.DATA_UPDATE_FAIL, e, newShopRefundRecord); 
 | 
            } 
 | 
            if (modifyMap.size() > 0) { 
 | 
                //如果修改退款金额就判断是否超过了订单金额 
 | 
                ShopRefundRecord cord = new ShopRefundRecord(); 
 | 
                cord = shopRefundRecordDao.selectById(oldShopRefundRecord.getId()); 
 | 
                ShopOrder shopOrder = shopOrderDao.selectById(cord.getOrderId()); 
 | 
                BigDecimal orderMoney = shopOrder.getOrderMoney(); 
 | 
                if(null != modifyMap.get("refundMoney")){ 
 | 
                    BigDecimal refundMoney = new BigDecimal(modifyMap.get("refundMoney").toString()); 
 | 
                    if(refundMoney.compareTo( orderMoney)>0){ 
 | 
                        throw new GlobleException("退款金额不能大于订单金额"); 
 | 
                    } 
 | 
                } 
 | 
  
 | 
                SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); 
 | 
                String suName = user.getSuName(); 
 | 
                modifyMap.put("id", oldShopRefundRecord.getId()); 
 | 
                modifyMap.put("handler", suName); 
 | 
                modifyMap.put("handingTime", new Date()); 
 | 
                shopRefundRecordDao.updateByMap(modifyMap); 
 | 
  
 | 
            } 
 | 
            Boolean flag = false; 
 | 
            ShopRefundRecord shopRefundRecord = new ShopRefundRecord(); 
 | 
            shopRefundRecord = shopRefundRecordDao.selectById(oldShopRefundRecord.getId()); 
 | 
            //仅退款 
 | 
            if(AppConstance.REFUND .equals(shopRefundRecord.getRefundType())){ 
 | 
                LogUtil.debug("进入确认退款(仅退款)流程。。。", shopRefundRecord.getId()); 
 | 
                    //满足条件进行退款 
 | 
                    Boolean aBoolean = refundToUser(oldShopRefundRecord.getId().toString(), shopRefundRecord); 
 | 
                    flag = aBoolean; 
 | 
                    if(flag){ 
 | 
                        //退款成功后发送微信提醒 
 | 
                        ShopRefundRecord fundRecord = shopRefundRecordDao.selectById(oldShopRefundRecord.getId()); 
 | 
                        sendRefundInfoToUser(fundRecord); 
 | 
                    } 
 | 
                } 
 | 
  
 | 
            //退货退款 
 | 
            if(AppConstance.REFUND_GOODS .equals(shopRefundRecord.getRefundType())){ 
 | 
                //只有审核通过的数据才能进行退款 
 | 
                if(!AppConstance.REFUND_AUDITED_PASS .equals(shopRefundRecord.getAuditStatus())){ 
 | 
                    throw new GlobleException("此条数据"+shopRefundRecord.getRefundNo()+":只有审核通过的数据才能进行退款"); 
 | 
                } 
 | 
                //只有已收货的数据才能进行退款 
 | 
                if(!AppConstance.GOODS_RECEIVED .equals(shopRefundRecord.getRefundGoodsStatus())){ 
 | 
                    throw new GlobleException("此条数据"+shopRefundRecord.getRefundNo()+":只有已收货的数据才能进行退款"); 
 | 
                } 
 | 
                //退款成功的状态不能重复退款 
 | 
                if(AppConstance.REFUND_SUCCESS.equals(shopRefundRecord.getRefundStatus())){ 
 | 
                    throw new GlobleException("此条数据"+shopRefundRecord.getRefundNo()+":该条订单已退款成功,不能重复退款"); 
 | 
                } 
 | 
                //满足条件进行退款 
 | 
                Boolean aBoolean = refundToUser(oldShopRefundRecord.getId().toString(), shopRefundRecord); 
 | 
                flag = aBoolean; 
 | 
                if(flag){ 
 | 
                    //退款成功后发送微信提醒 
 | 
                    ShopRefundRecord fundRecord = shopRefundRecordDao.selectById(oldShopRefundRecord.getId()); 
 | 
                    sendRefundInfoToUser(fundRecord); 
 | 
                } 
 | 
            } 
 | 
  
 | 
            i = MatrixConstance.DML_SUCCESSS; 
 | 
            WebUtil.removeSessionAttribute(BEV); 
 | 
            if (flag) { 
 | 
                return new AjaxResult(AjaxResult.STATUS_SUCCESS, "操作成功", "退款记录表"); 
 | 
            } else { 
 | 
                throw new GlobleException("操作失败"); 
 | 
            } 
 | 
  
 | 
    } 
 | 
     
 | 
     
 | 
       /** 
 | 
     * 进入修改界面 
 | 
     */    
 | 
    @SaveRequestToken 
 | 
       @RequestMapping(value =  "/editForm") 
 | 
    public ModelAndView editForm(Integer id) { 
 | 
        ShopRefundRecord shopRefundRecord = new ShopRefundRecord(); 
 | 
        List<ShopRefundRecordDetails> shopRefundRecordDetails = new ArrayList<ShopRefundRecordDetails>(); 
 | 
        ModelAndView modelAndView = new ModelAndView("admin/shop/shopRefundRecord-form"); 
 | 
        if (id != null) { 
 | 
            shopRefundRecord = shopRefundRecordDao.selectById(id); 
 | 
            Integer orderId = shopRefundRecord.getOrderId(); 
 | 
            shopRefundRecordDetails = shopRefundRecordDao.selectDetailsById(orderId); 
 | 
            WebUtil.setSessionAttribute(BEV, shopRefundRecord); 
 | 
        } 
 | 
        modelAndView.addObject("obj",shopRefundRecord); 
 | 
        modelAndView.addObject("objDetails",shopRefundRecordDetails); 
 | 
        return modelAndView; 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 进入退款详情界面 
 | 
     */ 
 | 
    @SaveRequestToken 
 | 
    @RequestMapping(value =  "/detailsForm") 
 | 
    public ModelAndView detailsForm(Integer id) { 
 | 
        ShopRefundRecord shopRefundRecord = new ShopRefundRecord(); 
 | 
        List<ShopRefundRecordDetails> shopRefundRecordDetails = new ArrayList<ShopRefundRecordDetails>(); 
 | 
        ModelAndView modelAndView = new ModelAndView("admin/shop/shopRefundRecord-details"); 
 | 
        if (id != null) { 
 | 
            shopRefundRecord = shopRefundRecordDao.selectById(id); 
 | 
            Integer orderId = shopRefundRecord.getOrderId(); 
 | 
            shopRefundRecordDetails = shopRefundRecordDao.selectDetailsById(orderId); 
 | 
            WebUtil.setSessionAttribute(BEV, shopRefundRecord); 
 | 
        } 
 | 
        modelAndView.addObject("obj",shopRefundRecord); 
 | 
        modelAndView.addObject("objDetails",shopRefundRecordDetails); 
 | 
        return modelAndView; 
 | 
    } 
 | 
  
 | 
  
 | 
    /** 
 | 
     * 删除 
 | 
     */   
 | 
     @RequestMapping(value = "/del") 
 | 
    public @ResponseBody AjaxResult del(String keys) { 
 | 
        List<String> ids = StringUtils.strToCollToString(keys, ","); 
 | 
        int i =  shopRefundRecordDao.deleteByIds(ids); 
 | 
        if (i > 0) { 
 | 
            return new AjaxResult(AjaxResult.STATUS_SUCCESS, SystemMessageCode.DELETE_SUCCES, i); 
 | 
        } else { 
 | 
            throw new GlobleException(SystemErrorCode.DATA_DELETE_FAIL); 
 | 
        } 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 确认收货 
 | 
     */ 
 | 
    @RequestMapping(value = "/confirmReceivingGoods") 
 | 
    public @ResponseBody AjaxResult confirmReceivingGoods(String keys) { 
 | 
        List<String> ids = StringUtils.strToCollToString(keys, ","); 
 | 
        ShopRefundRecord shopRefundRecord = new ShopRefundRecord(); 
 | 
        for(String id : ids){ 
 | 
            shopRefundRecord = shopRefundRecordDao.selectById(Integer.valueOf(id)); 
 | 
            if(!AppConstance.REFUND_GOODS .equals(shopRefundRecord.getRefundType())){ 
 | 
                throw new GlobleException("此条数据"+shopRefundRecord.getRefundNo()+":不是退货退款类型,不能确认收货"); 
 | 
            } 
 | 
            if(!AppConstance.REFUND_AUDITED_PASS .equals(shopRefundRecord.getAuditStatus())){ 
 | 
                throw new GlobleException("此条数据"+shopRefundRecord.getRefundNo()+":审核通过的数据才能确认收货"); 
 | 
            } 
 | 
        } 
 | 
        int i =  shopRefundRecordDao.updateRefundTypeByIds(ids, AppConstance.GOODS_RECEIVED); 
 | 
        if (i > 0) { 
 | 
            return new AjaxResult(AjaxResult.STATUS_SUCCESS, "成功收货", i); 
 | 
        } else { 
 | 
            throw new GlobleException(SystemErrorCode.DATA_UPDATE_FAIL); 
 | 
        } 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 退款 
 | 
     */ 
 | 
    @RequestMapping(value = "/confirmRefund") 
 | 
    public @ResponseBody AjaxResult confirmRefund(String keys) { 
 | 
        List<String> ids = StringUtils.strToCollToString(keys, ","); 
 | 
        ShopRefundRecord shopRefundRecord = new ShopRefundRecord(); 
 | 
        Boolean flag = false; 
 | 
        for(String id : ids){ 
 | 
            shopRefundRecord = shopRefundRecordDao.selectById(Integer.valueOf(id)); 
 | 
            //仅退款 
 | 
            if(AppConstance.REFUND .equals(shopRefundRecord.getRefundType())){ 
 | 
                if(!AppConstance.REFUND_AUDITED_PASS .equals(shopRefundRecord.getAuditStatus())){ 
 | 
                    throw new GlobleException("此条数据"+shopRefundRecord.getRefundNo()+":只有审核通过的数据才能进行退款"); 
 | 
                } 
 | 
                //退款成功的状态不能重复退款 
 | 
                if(AppConstance.REFUND_SUCCESS.equals(shopRefundRecord.getRefundStatus())){ 
 | 
                    throw new GlobleException("此条数据"+shopRefundRecord.getRefundNo()+":该条订单已退款成功,不能重复退款"); 
 | 
                } 
 | 
                else{ 
 | 
                    //满足条件进行退款 
 | 
                    Boolean aBoolean = refundToUser(id, shopRefundRecord); 
 | 
                    flag = aBoolean; 
 | 
                    if(flag){ 
 | 
                        //退款成功后发送微信提醒 
 | 
                        ShopRefundRecord fundRecord = shopRefundRecordDao.selectById(Integer.valueOf(id)); 
 | 
                        sendRefundInfoToUser(fundRecord); 
 | 
                        refundRecordService.updateGroupBuyStatus(Long.parseLong(id)); 
 | 
                    } 
 | 
                } 
 | 
            } 
 | 
  
 | 
            //退货退款 
 | 
            if(AppConstance.REFUND_GOODS.equals(shopRefundRecord.getRefundType())){ 
 | 
                //只有审核通过的数据才能进行退款 
 | 
                if(AppConstance.REFUND_AUDITED_PASS.equals(shopRefundRecord.getAuditStatus())){ 
 | 
                    throw new GlobleException("此条数据"+shopRefundRecord.getRefundNo()+":只有审核通过的数据才能进行退款"); 
 | 
                } 
 | 
                //只有已收货的数据才能进行退款 
 | 
                if(AppConstance.GOODS_RECEIVED.equals(shopRefundRecord.getRefundGoodsStatus()) ){ 
 | 
                    throw new GlobleException("此条数据"+shopRefundRecord.getRefundNo()+":只有已收货的数据才能进行退款"); 
 | 
                } 
 | 
                //退款成功的状态不能重复退款 
 | 
                if(AppConstance.REFUND_SUCCESS.equals(shopRefundRecord.getRefundStatus()) ){ 
 | 
                    throw new GlobleException("此条数据"+shopRefundRecord.getRefundNo()+":该条订单已退款成功,不能重复退款"); 
 | 
                } 
 | 
                //满足条件进行退款 
 | 
                Boolean aBoolean = refundToUser(id, shopRefundRecord); 
 | 
                flag = aBoolean; 
 | 
                if(flag){ 
 | 
                    //退款成功后发送微信提醒 
 | 
                    ShopRefundRecord fundRecord = shopRefundRecordDao.selectById(Integer.valueOf(id)); 
 | 
                    sendRefundInfoToUser(fundRecord); 
 | 
                    refundRecordService.updateGroupBuyStatus(Long.parseLong(id)); 
 | 
                } 
 | 
            } 
 | 
        } 
 | 
  
 | 
        if (flag) { 
 | 
            return new AjaxResult(AjaxResult.STATUS_SUCCESS, "退款成功"); 
 | 
        } else { 
 | 
            throw new GlobleException("退款失败"); 
 | 
        } 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 调用退款接口进行退款 
 | 
     * @param id 
 | 
     * @param shopRefundRecord 
 | 
     */ 
 | 
    public Boolean refundToUser(String id,ShopRefundRecord shopRefundRecord){ 
 | 
        LogUtil.info("进入退款接口进行退款。。。", id); 
 | 
        Boolean flag = false; 
 | 
        //调用退款接口,将钱返给用户 
 | 
        ShopOrder shopOrder = shopOrderDao.selectById(shopRefundRecord.getOrderId()); 
 | 
        if(null == shopOrder){ 
 | 
            throw new GlobleException("没有找到需要退款的订单信息"); 
 | 
        } 
 | 
        //商户订单编号(原订单编号) 
 | 
        String orderNo = shopOrder.getOrderNo(); 
 | 
        LogUtil.info("退款商户订单编号为{}", orderNo); 
 | 
        //退款编号 
 | 
        String refundNo = shopRefundRecord.getRefundNo(); 
 | 
        LogUtil.info("退款退款编号为{}", refundNo); 
 | 
        //订单金额 
 | 
        BigDecimal orderMoney = shopOrder.getOrderMoney(); 
 | 
        LogUtil.info("订单金额{}。", orderMoney); 
 | 
        BigDecimal a1 = new BigDecimal(orderMoney.toString()); 
 | 
        BigDecimal aa = new BigDecimal(100); 
 | 
        int orMoney = a1.multiply(aa).intValue(); 
 | 
        LogUtil.info("退款订单金额{}", orMoney); 
 | 
        //Double orderMoney = 0.1 * 100; 
 | 
        //退款金额 
 | 
        BigDecimal refundMoney = shopRefundRecord.getRefundMoney(); 
 | 
        LogUtil.info("退款金额{}。", refundMoney); 
 | 
        BigDecimal b1 = new BigDecimal(refundMoney.toString()); 
 | 
        BigDecimal bb = new BigDecimal(100); 
 | 
        int reMoney = b1.multiply(bb).intValue(); 
 | 
        LogUtil.info("退款退款金额{}", reMoney); 
 | 
  
 | 
  
 | 
  
 | 
        if (isDebug) { 
 | 
            boolean b = weixinServiceUtil.comRefund(orderNo, refundNo, 1, 1, null); 
 | 
            flag = b; 
 | 
        } else { 
 | 
            LogUtil.info("开始调用退款接口。。。退款编号为{}", refundNo); 
 | 
            boolean b = weixinServiceUtil.comRefund(orderNo, refundNo, orMoney, reMoney, null); 
 | 
            flag = b; 
 | 
        } 
 | 
  
 | 
        if(flag){ 
 | 
            try{ 
 | 
                LogUtil.debug("退款成功,开始修改退款表和订单表状态。。。", id); 
 | 
                //将申请退款状态改为成功退款 
 | 
                shopRefundRecordDao.updateRefundStatusByIds(Integer.valueOf(id), AppConstance.REFUND_SUCCESS); 
 | 
                //将审核状态改为审核通过 
 | 
                Map<String, Object> modifyRefund = new HashMap<>(); 
 | 
                modifyRefund.put("id", Integer.valueOf(id)); 
 | 
                modifyRefund.put("auditStatus", AppConstance.REFUND_AUDITED_PASS); 
 | 
                shopRefundRecordDao.updateByMap(modifyRefund); 
 | 
                //退款成功后同时把优惠券退回到用户的账号中 
 | 
                if (shopOrder.getDiscountAmount() != null && shopOrder.getDiscountAmount().compareTo(BigDecimal.ZERO) == 0) { 
 | 
                    ShopCouponRecord shopCouponRecord = new ShopCouponRecord(); 
 | 
                    String userIds = shopRefundRecord.getUserId(); 
 | 
                    shopCouponRecord.setUserId(userIds); 
 | 
                    shopCouponRecord.setOrderId(shopOrder.getId()); 
 | 
                    List<ShopCouponRecord> recordList = shopCouponRecordDao.selectByModel(shopCouponRecord); 
 | 
                    if (CollectionUtils.isNotEmpty(recordList)) { 
 | 
                        for (ShopCouponRecord record : recordList) { 
 | 
                            Map<String, Object> modifyMap = new HashMap<>(); 
 | 
                            modifyMap.put("id", record.getId()); 
 | 
                            modifyMap.put("isUsing", AppConstance.MY_COUPON_NOT_USE); 
 | 
                            modifyMap.put("orderId", 0); 
 | 
                            shopCouponRecordDao.updateByMap(modifyMap); 
 | 
                        } 
 | 
                    } 
 | 
                } 
 | 
  
 | 
                //退款成功后加库存减销量 
 | 
                shopRefundRecord = shopRefundRecordDao.selectById(Integer.valueOf(id)); 
 | 
                Integer orderId = shopRefundRecord.getOrderId(); 
 | 
                Integer orderStatus = shopOrder.getOrderStatus(); 
 | 
                Integer refundType = shopRefundRecord.getRefundType(); 
 | 
                //----当订单是物流、待配送、仅退款状态就不要加库存减销量 
 | 
                //物流、待收货、仅退款不要加库存减销量 
 | 
                ShopDeliveryInfo shopDeliveryInfo = shopDeliveryInfoDao.selectByOrderId(orderId); 
 | 
                Boolean refundFlag = AppConstance.SHIPPING_METHOD_LOGISTING.equals("物流配送") && null != shopDeliveryInfo.getWaybillNo() && AppConstance.REFUND .equals(refundType) ; 
 | 
                if(!refundFlag){ 
 | 
                    wxShopOrderService.updateStockAndVolumeById(orderId); 
 | 
                } 
 | 
  
 | 
                //将订单表的订单状态改为退款成功,更新退款费用 
 | 
                Map<String, Object> modifyMap = new HashMap<>(); 
 | 
                modifyMap.put("id", shopRefundRecord.getOrderId()); 
 | 
                modifyMap.put("orderStatus", ShopOrder.ORDER_STATUS_MONEYBACK_SUCCESS); 
 | 
                modifyMap.put("refundCharge", shopRefundRecord.getRefundMoney()); 
 | 
                shopOrderDao.updateByMap(modifyMap); 
 | 
            }catch (Exception e){ 
 | 
                LogUtil.debug("退款成功,修改退款表和订单表状态出错。。。", id); 
 | 
                e.printStackTrace(); 
 | 
            } 
 | 
        } 
 | 
        return flag; 
 | 
    } 
 | 
  
 | 
    //退款成功后发送微信提醒 
 | 
    private int sendRefundInfoToUser(ShopRefundRecord shopRefundRecord) { 
 | 
        ShopOrder order = shopOrderDao.selectById(shopRefundRecord.getOrderId()); 
 | 
        if (order == null) { 
 | 
            throw new GlobleException("没有找到需要退款的订单信息"); 
 | 
        } 
 | 
        List<String> msg = new ArrayList<>(); 
 | 
        //退款说明 
 | 
        String refundExplain = "退款已经原路返回,具体到账时间可能会有1-3天延迟"; 
 | 
        msg.add(order.getOrderNo()); 
 | 
        msg.add(DateUtil.dateToString(shopRefundRecord.getRefundTime(),DateUtil.DATE_FORMAT_SS)); 
 | 
        msg.add(refundExplain); 
 | 
        msg.add("商品名称"); 
 | 
        String formId = null; 
 | 
        if(AppConstance.REFUND_GOODS.equals(shopRefundRecord.getRefundType()) && null != shopRefundRecord.getRefundTransactionNo()){ 
 | 
            formId = shopRefundRecord.getRefundTransactionNo(); 
 | 
        }else { 
 | 
            formId = order.getWxOrderNo().split("=")[1]; 
 | 
        } 
 | 
        String page = "pages/refunDetail/refunDetail?id=" + shopRefundRecord.getId() + "&&status=1" + "&&inform=1"; 
 | 
        int res = WxTempLateMsgUtil.sendWxTemplateMsg(msg, order.getUserId(), 
 | 
                page, WxTempLateMsgUtil.REFUND_SUCCESS, formId); 
 | 
        return res; 
 | 
    } 
 | 
  
 | 
    //退款拒绝后发送微信提醒 
 | 
    private int sendFailedRefundInfoToUser(ShopRefundRecord shopRefundRecord) { 
 | 
        ShopOrder order = shopOrderDao.selectById(shopRefundRecord.getOrderId()); 
 | 
        if (order == null) { 
 | 
            throw new GlobleException("没有找到拒绝退款的订单信息"); 
 | 
        } 
 | 
        List<String> msg = new ArrayList<>(); 
 | 
        //退款说明 
 | 
        String remarks = "如有疑问请联系客服"; 
 | 
        msg.add(order.getOrderNo()); 
 | 
        msg.add("商品名称"); 
 | 
        msg.add(shopRefundRecord.getRefundRefuseReason()); 
 | 
        msg.add(shopRefundRecord.getRefundCause()); 
 | 
        String formId = null; 
 | 
        if(AppConstance.REFUND_GOODS .equals(shopRefundRecord.getRefundType()) && null != shopRefundRecord.getRefundTransactionNo()){ 
 | 
            formId = shopRefundRecord.getRefundTransactionNo(); 
 | 
        }else { 
 | 
            formId = order.getWxOrderNo().split("=")[1]; 
 | 
        } 
 | 
        String page = "pages/refunDetail/refunDetail?id=" + shopRefundRecord.getId() + "&&status=2" + "&&inform=1"; 
 | 
        int res = WxTempLateMsgUtil.sendWxTemplateMsg(msg, order.getUserId(), 
 | 
                page, WxTempLateMsgUtil.REFUND_FAILED, formId); 
 | 
        return res; 
 | 
    } 
 | 
  
 | 
    //同意退款后发送微信提醒填写物流单号 
 | 
    private int sendRefundLogisticsInfoToUser(ShopRefundRecord shopRefundRecord) { 
 | 
        ShopOrder order = shopOrderDao.selectById(shopRefundRecord.getOrderId()); 
 | 
        if (order == null) { 
 | 
            throw new GlobleException("没有找到发送微信提醒的订单信息"); 
 | 
        } 
 | 
        List<String> msg = new ArrayList<>(); 
 | 
        //退款说明 
 | 
        String remarks = "申请退款已审核通过,请尽快填写退货物流信息"; 
 | 
        msg.add(order.getOrderNo()); 
 | 
        msg.add("商品名称"); 
 | 
        msg.add("待退回"); 
 | 
        msg.add(remarks); 
 | 
        String formId = order.getWxOrderNo().split("=")[1]; 
 | 
        String page = "pages/refunding/refunding?id=" + shopRefundRecord.getId() + "&&inform=1"; 
 | 
        int res = WxTempLateMsgUtil.sendWxTemplateMsg(msg, order.getUserId(), 
 | 
                page, WxTempLateMsgUtil.WRITE_LOGISTICS, formId); 
 | 
        return res; 
 | 
    } 
 | 
} 
 |