فهرست منبع

Merge branch 'dev' of http://192.168.1.220:10080/Amoy2/wlyy2.0 into dev

liubing 3 سال پیش
والد
کامیت
f3c8dc4484

+ 1 - 1
common/common-entity/sql记录

@ -1069,7 +1069,7 @@ CREATE TABLE `base_service_news` (
-- 2021-06-29 ysj
CREATE TABLE `base_wx_pay_http_log` (
  `id` varchar(50) NOT NULL,
  `type` varchar(1) DEFAULT NULL COMMENT '类型1 统一下单 2支付回调',
  `type` varchar(1) DEFAULT NULL COMMENT '类型1 统一下单 2支付回调 3退款 4 退款回调',
  `order_no` varchar(50) DEFAULT NULL COMMENT '订单号',
  `order_res` text,
  `order_req` text,

+ 3 - 0
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/dao/doorCoach/BaseDoorCoachFeeDetailDao.java

@ -1,6 +1,7 @@
package com.yihu.jw.care.dao.doorCoach;
import com.yihu.jw.entity.care.doorCoach.BaseDoorCoachFeeDetailDO;
import com.yihu.jw.entity.care.lifeCare.LifeCareFeeDetailDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
@ -24,6 +25,8 @@ import java.util.Map;
 */
public interface BaseDoorCoachFeeDetailDao extends PagingAndSortingRepository<BaseDoorCoachFeeDetailDO, String>, JpaSpecificationExecutor<BaseDoorCoachFeeDetailDO>  {
    List<BaseDoorCoachFeeDetailDO> findByOrderId(String orderId);
    @Query("select d from BaseDoorCoachFeeDetailDO d where d.orderId = ?1 and d.type=?2 and d.status <> 3")
    List<BaseDoorCoachFeeDetailDO> findByOrderIdAndType(String orderId, Integer type);

+ 4 - 0
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/dao/lifeCare/LifeCareFeeDetailDao.java

@ -4,8 +4,12 @@ import com.yihu.jw.entity.care.lifeCare.LifeCareFeeDetailDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * Created by yeshijie on 2021/3/26.
 */
public interface LifeCareFeeDetailDao extends PagingAndSortingRepository<LifeCareFeeDetailDO, String>, JpaSpecificationExecutor<LifeCareFeeDetailDO> {
    List<LifeCareFeeDetailDO> findByOrderId(String orderId);
}

+ 92 - 15
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/endpoint/patient/PayEndpoint.java

@ -1,14 +1,19 @@
package com.yihu.jw.care.endpoint.patient;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.care.exception.BusinessException;
import com.yihu.jw.care.service.doorCoach.PatientDoorCoachOrderService;
import com.yihu.jw.care.service.pay.PayService;
import com.yihu.jw.care.util.XMLUtil;
import com.yihu.jw.entity.order.BusinessOrderDO;
import com.yihu.jw.order.dao.BusinessOrderDao;
import com.yihu.jw.restmodel.ResponseContant;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.ObjEnvelop;
import com.yihu.jw.restmodel.web.PageEnvelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.utils.StringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
@ -19,6 +24,7 @@ import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
/**
@ -40,40 +46,111 @@ public class PayEndpoint extends EnvelopRestEndpoint {
    @Autowired
    private BusinessOrderDao businessOrderDao;
    @GetMapping("topStatusBarNum")
    @ApiOperation(value = "顶部状态栏订单分类tab")
    public ObjEnvelop topStatusBarNum(
            @ApiParam(name = "patient", value = "居民code")
            @RequestParam(value = "patient", required = true) String patient) {
        try {
            Map<String, Integer> map = payService.topStatusBarNum(patient);
            return ObjEnvelop.getSuccess("获取成功",map);
        } catch (Exception e) {
            return failedObjEnvelopException2(e);
        }
    }
    @GetMapping(value = "orderList")
    @ApiOperation(value = "我的订单列表")
    public PageEnvelop orderList(
            @ApiParam(name = "patient", value = "patient") @RequestParam(value = "patient", required = true) String patient,
            @ApiParam(name = "status", value = "工单状态") @RequestParam(value = "status", required = false) String status,
            @ApiParam(name = "page", value = "分页大小", required = true, defaultValue = "1") @RequestParam(value = "page") int page,
            @ApiParam(name = "size", value = "页码", required = true, defaultValue = "15") @RequestParam(value = "size") int size) {
        try{
            JSONObject result = payService.orderList(patient, status, page, size);
            if (result.getIntValue(ResponseContant.resultFlag) == ResponseContant.fail) {
                return PageEnvelop.getError(result.getString(ResponseContant.resultMsg));
            }
            Long count = result.getLongValue(ResponseContant.count);
            return PageEnvelop.getSuccessListWithPage("查询成功",(List<Map<String,Object>>)result.get(ResponseContant.resultMsg),page,size,count);
        }catch (Exception e){
            return failedPageEnvelopException2(e);
        }
    }
    @GetMapping("orderInfo")
    @ApiOperation(value = "订单详情")
    public ObjEnvelop orderInfo(@ApiParam(name = "id", value = "订单id") @RequestParam(value = "id", required = true) Integer id) {
        try {
            JSONObject json = payService.orderInfo(id);
            return ObjEnvelop.getSuccess("获取成功",json);
        } catch (Exception e) {
            return failedObjEnvelopException2(e);
        }
    }
    @GetMapping(value = "wxWapPay")
    @PostMapping(value = "applyRefund")
    @ApiOperation(value = "申请退款")
    public Envelop applyRefund(
            @ApiParam(name = "id", value = "订单id")
            @RequestParam(value = "id", required = true) Integer id) {
        try{
            String res = payService.cancleOrder(id);
            if(StringUtil.isBlank(res)){
                return success("取消成功");
            }
            return Envelop.getError(res,-1);
        }catch (Exception e){
            return failedException2(e);
        }
    }
    @PostMapping(value = "cancleOrder")
    @ApiOperation(value = "取消订单")
    public Envelop cancleOrder(
            @ApiParam(name = "id", value = "订单id")
            @RequestParam(value = "id", required = true) Integer id) {
        try{
            String res = payService.cancleOrder(id);
            if(StringUtil.isBlank(res)){
                return success("取消成功");
            }
            return Envelop.getError(res,-1);
        }catch (Exception e){
            return failedException2(e);
        }
    }
    @PostMapping(value = "wxWapPay")
    @ApiOperation(value = "微信wap支付")
    public ObjEnvelop wxWapPay(
            @ApiParam(name = "relationId", value = "业务id,如生活照料id 上面辅导id")
            @RequestParam(value = "relationId", required = false) String relationId,
            @ApiParam(name = "orderId", value = "订单id")
            @RequestParam(value = "orderId", required = false) Integer orderId,
            @ApiParam(name = "patientId", value = "居民id")
            @RequestParam(value = "patientId", required = true) String patientId,HttpServletRequest request) {
            @RequestParam(value = "orderId", required = false) Integer orderId,HttpServletRequest request) {
        try{
            return  payService.wxWapPay(relationId, orderId, patientId, request);
            return  payService.wxWapPay(relationId, orderId, request);
        }catch (Exception e){
            return failedObjEnvelopException2(e);
        }
    }
    @GetMapping(value = "wxRefund")
    @PostMapping(value = "wxRefund")
    @ApiOperation(value = "微信发起退款")
    public ObjEnvelop wxRefund(
            @ApiParam(name = "relationId", value = "业务id,如生活照料id 上面辅导id")
            @RequestParam(value = "relationId", required = false) String relationId,
            @ApiParam(name = "orderId", value = "订单id")
            @RequestParam(value = "orderId", required = false) Integer orderId,
            @ApiParam(name = "patientId", value = "居民id")
            @RequestParam(value = "patientId", required = true) String patientId,HttpServletRequest request) {
    public Envelop wxRefund(
            @ApiParam(name = "desc", value = "退款说明")
            @RequestParam(value = "desc", required = true) String desc,
            @ApiParam(name = "orderNo", value = "订单id")
            @RequestParam(value = "orderNo", required = true) String orderNo) {
        try{
            return  payService.wxWapPay(relationId, orderId, patientId, request);
              payService.orderRefund(orderNo, desc);
            return success("发起退款成功");
        }catch (Exception e){
            return failedObjEnvelopException2(e);
        }
    }
    @GetMapping(value = "wxNativePay")
    @PostMapping(value = "wxNativePay")
    @ApiOperation(value = "微信native支付")
    public ObjEnvelop wxNativePay(
            @ApiParam(name = "relationId", value = "业务id,如生活照料id 上面辅导id")

+ 189 - 15
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/pay/PayService.java

@ -4,6 +4,10 @@ package com.yihu.jw.care.service.pay;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.yihu.fastdfs.FastDFSUtil;
import com.yihu.jw.care.dao.doorCoach.BaseDoorCoachFeeDetailDao;
import com.yihu.jw.care.dao.doorCoach.BaseDoorCoachOrderDao;
import com.yihu.jw.care.dao.lifeCare.LifeCareFeeDetailDao;
import com.yihu.jw.care.dao.lifeCare.LifeCareOrderDao;
import com.yihu.jw.care.dao.pay.WxPayHttpLogDao;
import com.yihu.jw.care.service.doorCoach.PatientDoorCoachOrderService;
import com.yihu.jw.care.service.lifeCare.LifeCareOrderService;
@ -12,31 +16,35 @@ import com.yihu.jw.care.util.XMLUtil;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.base.wx.WxWechatDO;
import com.yihu.jw.entity.care.common.WxPayHttpLogDO;
import com.yihu.jw.entity.care.doorCoach.BaseDoorCoachFeeDetailDO;
import com.yihu.jw.entity.care.doorCoach.BaseDoorCoachOrderDO;
import com.yihu.jw.entity.care.lifeCare.LifeCareFeeDetailDO;
import com.yihu.jw.entity.care.lifeCare.LifeCareOrderDO;
import com.yihu.jw.entity.order.BusinessOrderDO;
import com.yihu.jw.entity.order.BusinessOrderRefundDO;
import com.yihu.jw.order.BusinessOrderService;
import com.yihu.jw.order.dao.BusinessOrderDao;
import com.yihu.jw.order.dao.BusinessOrderRefundDao;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.restmodel.ResponseContant;
import com.yihu.jw.restmodel.web.ObjEnvelop;
import com.yihu.jw.util.common.IpUtil;
import com.yihu.jw.util.common.QrcodeUtil;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.utils.StringUtil;
import com.yihu.jw.wechat.dao.WechatDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import javax.servlet.http.HttpServletRequest;
import java.io.InputStream;
import java.util.Date;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.*;
import static jxl.biff.FormatRecord.logger;
@ -78,17 +86,174 @@ public class PayService {
    @Autowired
    private LifeCareOrderService lifeCareOrderService;
    @Autowired
    private LifeCareOrderDao lifeCareOrderDao;
    @Autowired
    private PatientDoorCoachOrderService doorCoachOrderService;
    @Autowired
    private BaseDoorCoachOrderDao baseDoorCoachOrderDao;
    @Value("${fastDFS.fastdfs_file_url}")
    private String fastdfs_file_url;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private LifeCareFeeDetailDao lifeCareFeeDetailDao;
    @Autowired
    private BaseDoorCoachFeeDetailDao doorCoachFeeDetailDao;
    /**
     * 微信退款
     * 顶部状态栏订单各分类总条数
     * 0待支付、1已支付、2已取消、3申请退款中、4已售后
     * @param patient
     * @return
     */
    public Map<String, Integer> topStatusBarNum(String patient) {
        String sql = "SELECT a.`status`,COUNT(*) num from base_business_order_pay a  where patient = '"+patient+"' " +
                "GROUP BY a.`status` " ;
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
        Map<String, Integer> map = new HashMap<>();
        //状态 0待支付、1已支付、2已取消、3申请退款中、4已售后
        map.put("0",0);
        map.put("1",0);
        map.put("2",0);
        map.put("3",0);
        map.put("4",0);
        int total = 0;
        if(list.size()>0){
            for (Map<String, Object> one:list){
                map.put(String.valueOf(one.get("status")), Integer.valueOf(String.valueOf(one.get("num"))));
                total+=Integer.valueOf(String.valueOf(one.get("num")));
            }
        }
        map.put("total", total);
        return map;
    }
    /**
     * 居民我的订单列表
     * @param patient
     * @param status
     * @param page
     * @param size
     * @return
     */
    public JSONObject orderList(String patient, String status, int page, int size) {
        JSONObject result = new JSONObject();
        int start = 0 == page ? page++ : (page - 1) * size;
        int end = 0 == size ? 15 : size;
        String filter = " where patient = '"+patient+"' ";
        if(!StringUtil.isEmpty(status)){
            filter += " and status = "+ status +" ";
        }
        String sql = "select a.id,a.patient,a.patient_name patientName,a.order_no orderNo,a.status, " +
                "DATE_FORMAT(a.create_time,'%Y-%m-%d %H:%i:%s') createTime " +
                ",a.order_category orderCategory,a.relation_code relationCode,a.relation_name relationName " +
                ",a.pay_type payType,a.pay_price payPrice from base_business_order_pay a " + filter ;
         sql += " ORDER BY a.create_time desc " +
                " LIMIT {start},{end};";
        String finalSql = sql.replace("{start}", String.valueOf(start))
                .replace("{end}", String.valueOf(end));
        String countSql = "SELECT  count(a.id)  FROM  base_business_order_pay a" + filter ;
        List<Map<String,Object>> sqlResultlist;
        try {
            sqlResultlist = jdbcTemplate.queryForList(finalSql);
        } catch (Exception e) {
            result.put(ResponseContant.resultFlag, ResponseContant.fail);
            result.put(ResponseContant.resultMsg, "从数据库查询工单列表信息失败");
            return result;
        }
        Long count;
        try {
            count = jdbcTemplate.queryForObject(countSql, Long.class);
        } catch (Exception e) {
            result.put(ResponseContant.resultFlag, ResponseContant.fail);
            result.put(ResponseContant.resultMsg, "从数据库统计工单数量失败" );
            return result;
        }
        result.put(ResponseContant.resultFlag, ResponseContant.success);
        result.put(ResponseContant.resultMsg, sqlResultlist);
        JSONObject countItem = new JSONObject();
        countItem.put("count", count);
        result.putAll(countItem);
        return result;
    }
    /**
     * 订单详情接口
     * @param id
     */
    public JSONObject orderInfo(Integer id){
        JSONObject resJson = new JSONObject();
        resJson.put("id",id);
        BusinessOrderDO businessOrderDO = businessOrderDao.findOne(id);
        String type = businessOrderDO.getOrderCategory();
        resJson.put("orderCategory",type);
        resJson.put("orderNo",businessOrderDO.getOrderNo());
        resJson.put("payPrice",businessOrderDO.getPayPrice());
        resJson.put("payTime", DateUtil.dateToStrLong(businessOrderDO.getPayTime()));
        resJson.put("createTime",DateUtil.dateToStrLong(businessOrderDO.getCreateTime()));
        resJson.put("status",businessOrderDO.getStatus());
        resJson.put("updateTime",DateUtil.dateToStrLong(businessOrderDO.getUpdateTime()));
        if("3".equals(type)){
            List<BaseDoorCoachFeeDetailDO> feeDetailDOList = doorCoachFeeDetailDao.findByOrderId(businessOrderDO.getRelationCode());
            resJson.put("fees",feeDetailDOList);
        }else if("4".equals(type)){
            List<LifeCareFeeDetailDO> feeDetailDOList = lifeCareFeeDetailDao.findByOrderId(businessOrderDO.getRelationCode());
            resJson.put("fees",feeDetailDOList);
        }
        return resJson;
    }
    public void applyRefund(Integer id,String content,String imgs){
    }
    /**
     * 取消订单
     * @param id
     */
    public String cancleOrder(Integer id){
        BusinessOrderDO businessOrderDO = businessOrderDao.findOne(id);
        if(businessOrderDO.getStatus()==0){
            String type = businessOrderDO.getOrderCategory();
            String orderId = businessOrderDO.getRelationCode();
            if("3".equals(type)){
                BaseDoorCoachOrderDO orderDO = baseDoorCoachOrderDao.findOne(orderId);
                if(orderDO.getStatus()==0){
                    orderDO.setStatus(-1);
                    baseDoorCoachOrderDao.save(orderDO);
                }
            }else if("4".equals(type)){
                LifeCareOrderDO orderDO = lifeCareOrderDao.findOne(orderId);
                if(orderDO.getStatus()==0){
                    orderDO.setStatus(-1);
                    lifeCareOrderDao.save(orderDO);
                }
            }
            businessOrderDO.setUpdateTime(new Date());
            businessOrderDao.save(businessOrderDO);
        }else{
            return "只有待支付的订单才能取消";
        }
        return null;
    }
    /**
     * 微信退款
     * @param orderNo
     * @param description
     * @return
     * @throws Exception
     */
    public Map<String,Object> orderRefund(String patient,String orderNo,String description) throws Exception {
    public void orderRefund(String orderNo,String description) throws Exception {
        WxWechatDO wxWechatDO = wechatDao.findById(wechatId);
        if (wxWechatDO==null){
            throw new Exception("this wechatId is null");
@ -97,7 +262,7 @@ public class PayService {
        if (businessOrderDO==null){
            throw new Exception("this orderId not exit");
        }
        BasePatientDO patientDO = patientDao.findById(patient);
        BasePatientDO patientDO = patientDao.findById(businessOrderDO.getPatient());
        if (patientDO==null){
            throw new Exception("this patient not exit");
        }
@ -115,7 +280,7 @@ public class PayService {
        orderRefundDO.setAppId(wxWechatDO.getAppId());
        orderRefundDO.setMchId(wxWechatDO.getMchId());
        orderRefundDO.setOutRefundNo("CARE"+businessOrderDO.getOrderType()+System.currentTimeMillis()+(int)(Math.random()*900)+100);
        orderRefundDO.setPatient(patient);
        orderRefundDO.setPatient(businessOrderDO.getPatient());
        orderRefundDO.setPatientName(patientDO.getName());
        orderRefundDO.setRefundDesc(description);
        orderRefundDO = orderRefundDao.save(orderRefundDO);
@ -123,11 +288,11 @@ public class PayService {
        Integer refundPrice1 = orderRefundDO.getRefundPrice().intValue();
        Map<String,Object> map = businessOrderService.refund(wechatId,orderRefundDO.getOrderNo(),orderRefundDO.getOutRefundNo(),orderPrice.toString(),refundPrice1.toString(),orderRefundDO.getRefundDesc());
        logger.info("map"+map);
        addHttpLog("1",businessOrderDO.getOrderNo(),null,map.toString());
        if (map.get("return_code").toString().equalsIgnoreCase("SUCCESS")){
            //退款申请提交成功
            throw new Exception(map.get("return_msg").toString());
        }
        return map;
    }
@ -180,6 +345,8 @@ public class PayService {
        }
        orderDO.setStatus(1);
        orderDO.setPayType(1);
        orderDO.setPayTime(new Date());
        businessOrderDao.save(orderDO);
    }
@ -232,7 +399,7 @@ public class PayService {
        if (businessOrderDO.getStatus()!=0) {
            return ObjEnvelop.getError("待支付订单才能支付",-1);
        }
        businessOrderDO.setOrderNo(getOrderNo());
        String noceStr = WxpayUtil.getNonceStr();
        // 组装统一下单信息
        SortedMap<String, String> reqMap = new TreeMap<>();
@ -277,7 +444,8 @@ public class PayService {
            } catch (Exception e) {
                e.printStackTrace();
            }
            return ObjEnvelop.getSuccess("下单成功",serverUrl+fileUrl);
            businessOrderDao.save(businessOrderDO);
            return ObjEnvelop.getSuccess("下单成功",fastdfs_file_url+fileUrl);
        } else {
            return ObjEnvelop.getError(map.get("return_msg"),-1);
        }
@ -290,7 +458,7 @@ public class PayService {
     * @throws Exception
     */
    @Transactional(rollbackFor = Exception.class)
    public ObjEnvelop wxWapPay(String relationId,Integer orderId,String patientId,HttpServletRequest request) throws Exception {
    public ObjEnvelop wxWapPay(String relationId,Integer orderId,HttpServletRequest request) throws Exception {
        BusinessOrderDO businessOrderDO;
        if(StringUtil.isBlank(relationId)){
            businessOrderDO = businessOrderDao.findOne(orderId);
@ -301,7 +469,8 @@ public class PayService {
        if (businessOrderDO.getStatus()!=0) {
            return ObjEnvelop.getError("待支付订单才能支付",-1);
        }
        BasePatientDO patientDO = patientDao.findById(patientId);
        BasePatientDO patientDO = patientDao.findById(businessOrderDO.getPatient());
        businessOrderDO.setOrderNo(getOrderNo());
        String noceStr = WxpayUtil.getNonceStr();
        // 组装统一下单信息
@ -352,6 +521,7 @@ public class PayService {
        String paySign = WxpayUtil.createSign(payMap, apiKey);
        payMap.put("paySign", paySign);
        log.error("【微信支付】WAP支付订单信息:{}", payMap);
        businessOrderDao.save(businessOrderDO);
        return ObjEnvelop.getSuccess("下单成功",payMap);
    }
@ -401,11 +571,15 @@ public class PayService {
        businessOrderDO.setCreateTime(new Date());
        businessOrderDO.setUpdateTime(new Date());
        businessOrderDO.setStatus(0);
        businessOrderDO.setOrderNo(""+System.currentTimeMillis()+(int)(Math.random()*900)+100);
        businessOrderDO.setOrderNo(getOrderNo());
        businessOrderDO.setUploadStatus(0);
        businessOrderDO.setPayType(1);
        businessOrderDO.setPayPrice(Double.valueOf(price));
        businessOrderService.save(businessOrderDO);
        return businessOrderDO;
    }
    public String getOrderNo(){
        return ""+System.currentTimeMillis()+(int)(Math.random()*900)+100;
    }
}

+ 1 - 1
svr/svr-cloud-care/src/main/resources/application.yml

@ -422,7 +422,7 @@ spring:
    port: 6379  # Redis server port.
    password: Kb6wKDQP1W4
fastDFS:
  fastdfs_file_url: http://10.18.43.40:8888/
  fastdfs_file_url: https://zhyzh.hzxc.gov.cn/fastdfs/
fast-dfs:
  tracker-server: 10.18.43.40:22122 #服务器地址
# 短信验证码发送的客户端标识,居民端