|
@ -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,9 +86,165 @@ 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;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 微信退款
|
|
@ -181,6 +345,8 @@ public class PayService {
|
|
|
}
|
|
|
|
|
|
orderDO.setStatus(1);
|
|
|
orderDO.setPayType(1);
|
|
|
orderDO.setPayTime(new Date());
|
|
|
businessOrderDao.save(orderDO);
|
|
|
}
|
|
|
|