Commit 02637fd9b7f3eef09237bb3fb626a808906f593e

Authored by cfl
1 parent 450d87f4a1
Exists in dev

收费功能开发

Showing 21 changed files with 635 additions and 57 deletions

talkonlineweb/src/main/java/com/lyms/talkonlineweb/controller/OrderController.java View file @ 02637fd
... ... @@ -4,13 +4,14 @@
4 4 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
5 5 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
6 6 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  7 +import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
7 8 import com.lyms.talkonlineweb.annotation.Resubmit;
8 9 import com.lyms.talkonlineweb.annotation.TokenRequired;
9   -import com.lyms.talkonlineweb.domain.LymsGoods;
10   -import com.lyms.talkonlineweb.domain.LymsOrder;
11   -import com.lyms.talkonlineweb.domain.LymsPatient;
  10 +import com.lyms.talkonlineweb.domain.*;
12 11 import com.lyms.talkonlineweb.enums.PayStatus;
  12 +import com.lyms.talkonlineweb.request.OrderRequest;
13 13 import com.lyms.talkonlineweb.result.BaseResponse;
  14 +import com.lyms.talkonlineweb.result.OrderListResponse;
14 15 import com.lyms.talkonlineweb.service.*;
15 16 import com.lyms.talkonlineweb.util.*;
16 17 import lombok.extern.log4j.Log4j2;
17 18  
... ... @@ -18,16 +19,14 @@
18 19 import org.apache.commons.io.IOUtils;
19 20 import org.springframework.beans.factory.annotation.Autowired;
20 21 import org.springframework.beans.factory.annotation.Value;
21   -import org.springframework.web.bind.annotation.PostMapping;
22   -import org.springframework.web.bind.annotation.RequestBody;
23   -import org.springframework.web.bind.annotation.RequestMapping;
24   -import org.springframework.web.bind.annotation.RestController;
  22 +import org.springframework.web.bind.annotation.*;
25 23 import sun.security.provider.MD5;
26 24  
27 25 import javax.servlet.http.HttpServletRequest;
28 26 import javax.servlet.http.HttpServletResponse;
29 27 import java.io.IOException;
30 28 import java.io.PrintWriter;
  29 +import java.math.BigDecimal;
31 30 import java.util.*;
32 31  
33 32 /**
34 33  
35 34  
... ... @@ -62,13 +61,28 @@
62 61 @Autowired
63 62 private LymsOrderService lymsOrderService;
64 63  
  64 + @Autowired
  65 + private LymsTcardService lymsTcardService;
  66 +
65 67 /**
66 68 * 微信回调通知接口
67 69 */
68 70 @Value("${notify.url}")
69 71 private String notifyUrl;
70 72  
  73 + @GetMapping("/queryGoods")
  74 + public BaseResponse getGoods(String type){
  75 + QueryWrapper<LymsGoods> queryWrapper = new QueryWrapper<>();
  76 + queryWrapper.eq("type",type);
  77 + List<LymsGoods> list = lymsGoodsService.list(queryWrapper);
  78 + if(CollectionUtils.isNotEmpty(list)){
  79 + return BaseResponse.ok().setObject(list.get(0));
  80 + }
  81 + return BaseResponse.error("无此类型商品");
71 82  
  83 + }
  84 +
  85 +
72 86 /**
73 87 * 创建支付订单,并把订单提交到微信平台
74 88 * 传入患者id和购买数量
... ... @@ -102,10 +116,7 @@
102 116 return baseResponse;
103 117 }
104 118  
105   -
106   - LambdaQueryWrapper<LymsGoods> wrapper = new QueryWrapper().lambda();
107   - wrapper.eq(LymsGoods::getType, "card");
108   - LymsGoods goods = lymsGoodsService.getOne(wrapper);
  119 + LymsGoods goods = lymsGoodsService.getById(lymsOrder.getGid());
109 120 if (goods == null || goods.getPrice() <= 0)
110 121 {
111 122 baseResponse.setErrorcode(1);
... ... @@ -118,6 +129,7 @@
118 129 baseResponse.setErrormsg("支付价格不一致!");
119 130 return baseResponse;
120 131 }
  132 +
121 133 try
122 134 {
123 135 //生成系统订单号
124 136  
... ... @@ -125,8 +137,10 @@
125 137 log.info("create order pid {} ,orderNo {}",lymsOrder.getPid(),orderNo);
126 138 lymsOrder.setCreatedtime(new Date());
127 139 lymsOrder.setOrderno(orderNo);
  140 + lymsOrder.setAmount(lymsOrder.getPrice()*lymsOrder.getCnt());
128 141 lymsOrder.setStatus(PayStatus.CREATED.getCode());
129 142 lymsOrder.setOpenid(patient.getOpenid());
  143 + lymsOrder.setRefundStatus(0);
130 144 lymsOrderService.save(lymsOrder);
131 145 //创建微信订单
132 146 Map<String,String> data = createWxOrder(lymsOrder);
133 147  
... ... @@ -150,7 +164,59 @@
150 164 return baseResponse;
151 165 }
152 166  
  167 +
153 168 /**
  169 + * PC端查询订单列表
  170 + * @param orderRequest
  171 + * @param current
  172 + * @param size
  173 + * @return
  174 + */
  175 + @PostMapping("queryOrderList")
  176 + @TokenRequired
  177 + public BaseResponse queryOrderList(@RequestBody OrderRequest orderRequest,Integer current,Integer size){
  178 +
  179 + if(StringUtil.isNotEmpty(orderRequest.getPayTimeEnd())){
  180 + orderRequest.setPayTimeEnd(orderRequest.getPayTimeEnd() + " 23:59:59");
  181 + }
  182 + Page<OrderListResponse> page= new Page<>(current,size);
  183 +
  184 + Page<OrderListResponse> orderListResponses = lymsOrderService.queryOrderList(page, orderRequest);
  185 +
  186 + if(CollectionUtils.isNotEmpty(orderListResponses.getRecords())){
  187 + for(OrderListResponse response: orderListResponses.getRecords()){
  188 + response.setOrderType(response.getPcid() != null ? 2 : 1);
  189 + response.setOrderTypeName(response.getPcid() != null ? "续费" : "初次购买");
  190 + response.setSex("1".equals(response.getSex())?"男":"女");
  191 + }
  192 + }
  193 +
  194 + return BaseResponse.ok(orderListResponses);
  195 + }
  196 +
  197 + @GetMapping("queryOrderLimit")
  198 + @TokenRequired
  199 + public BaseResponse queryOrderLimit(Integer pid,Integer pcid){
  200 + QueryWrapper<LymsTcard> query = new QueryWrapper<>();
  201 + query.eq("pid",pid);
  202 + query.eq("pcid",pcid);
  203 + query.orderByDesc("end_time");
  204 + query.last(" limit 1");
  205 + LymsTcard lymsTcard = lymsTcardService.getOne(query);
  206 + if(lymsTcard != null){
  207 + Map<String,String> m = new HashMap<>();
  208 + m.put("expireDate",DateUtil.getDateTime(lymsTcard.getEndTime(),DateUtil.YYYY_MM_DD));
  209 + m.put("expireDays",DateUtil.daysBetween(new Date(),lymsTcard.getEndTime())+"");
  210 + return BaseResponse.ok().setObject(m);
  211 + }else{
  212 + return BaseResponse.error("未查询到就诊卡");
  213 + }
  214 +
  215 +
  216 + }
  217 +
  218 +
  219 + /**
154 220 * 创建微信订单
155 221 */
156 222 private Map<String,String> createWxOrder(LymsOrder lymsOrder) throws Exception
157 223  
... ... @@ -272,16 +338,21 @@
272 338 //验证支付通知的参数合法性
273 339 if (!verifyPayNotify(paramMap)) {
274 340 //微信支付订单号
275   - String payOrderId = paramMap.get("transaction_id");
  341 + String transactionId = paramMap.get("transaction_id");
276 342 //商户订单号
277 343 String mchOrderNo = paramMap.get("out_trade_no");
278 344 LambdaQueryWrapper<LymsOrder> wrapper = new QueryWrapper().lambda();
279 345 wrapper.eq(LymsOrder::getOrderno, mchOrderNo);
280 346 LymsOrder order=new LymsOrder();
281   - order.setPayorderid(payOrderId);
282   - boolean f=lymsOrderService.update(order, wrapper);
283   -
284   - boolean flag = lymsOrderService.handleOrder(payOrderId,mchOrderNo);
  347 + order.setTransactionId(transactionId);
  348 + order.setPayTime(new Date());
  349 + boolean f= lymsOrderService.update(order, wrapper);
  350 + //处理业务逻辑
  351 + LambdaQueryWrapper<LymsOrder> lymsOrderWrapper = new QueryWrapper().lambda();
  352 + lymsOrderWrapper.eq(LymsOrder::getOrderno, mchOrderNo);
  353 + lymsOrderWrapper.eq(LymsOrder::getTransactionId, transactionId);
  354 + LymsOrder lymsOrders = lymsOrderService.getOne(lymsOrderWrapper);
  355 + boolean flag = lymsOrderService.handleOrder(lymsOrders);
285 356 if (flag)
286 357 {
287 358 result.put("return_code","<![CDATA[SUCCESS]]>");
talkonlineweb/src/main/java/com/lyms/talkonlineweb/controller/OrderRefundController.java View file @ 02637fd
  1 +package com.lyms.talkonlineweb.controller;
  2 +
  3 +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  4 +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  5 +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
  6 +import com.lyms.talkonlineweb.annotation.Resubmit;
  7 +import com.lyms.talkonlineweb.annotation.TokenRequired;
  8 +import com.lyms.talkonlineweb.domain.LymsGoods;
  9 +import com.lyms.talkonlineweb.domain.LymsOrder;
  10 +import com.lyms.talkonlineweb.domain.LymsPatient;
  11 +import com.lyms.talkonlineweb.enums.PayStatus;
  12 +import com.lyms.talkonlineweb.result.BaseResponse;
  13 +import com.lyms.talkonlineweb.service.LymsGoodsService;
  14 +import com.lyms.talkonlineweb.service.LymsOrderService;
  15 +import com.lyms.talkonlineweb.service.LymsPatientService;
  16 +import com.lyms.talkonlineweb.util.*;
  17 +import lombok.extern.log4j.Log4j2;
  18 +import org.apache.commons.io.IOUtils;
  19 +import org.springframework.beans.factory.annotation.Autowired;
  20 +import org.springframework.beans.factory.annotation.Value;
  21 +import org.springframework.web.bind.annotation.*;
  22 +
  23 +import javax.servlet.http.HttpServletRequest;
  24 +import javax.servlet.http.HttpServletResponse;
  25 +import java.io.IOException;
  26 +import java.io.PrintWriter;
  27 +import java.util.*;
  28 +
  29 +/**
  30 + *
  31 + */
  32 +@RestController
  33 +@RequestMapping("order/refund")
  34 +@Log4j2
  35 +public class OrderRefundController {
  36 +
  37 + /**
  38 + *
  39 + * @return
  40 + */
  41 + @GetMapping("/queryUncompleteOrders")
  42 + @TokenRequired
  43 + public BaseResponse queryUncompleteOrders(@RequestHeader String authorization){
  44 +
  45 + return null;
  46 + }
  47 +
  48 +}
talkonlineweb/src/main/java/com/lyms/talkonlineweb/controller/PatientController.java View file @ 02637fd
... ... @@ -1002,7 +1002,13 @@
1002 1002 if(StringUtil.isNotEmpty(patient.getPpasswd())){
1003 1003 patient.setPpasswd(DigestUtils.md5DigestAsHex(patient.getPpasswd().getBytes()));
1004 1004 }
  1005 + //注册过程中
  1006 + if (StringUtils.isEmpty(patient.getCode())) {
  1007 + patient.setOpenid(WeiXinUtil.getWxOpenId(patient.getCode()));
  1008 + }
1005 1009 boolean f = lymsPatientService.save(patient);
  1010 +
  1011 + baseResponse.setObject(patient);
1006 1012 baseResponse.setErrorcode(f?0:1);
1007 1013 baseResponse.setErrormsg(f?"注册成功!":"注册失败!");
1008 1014 try{
talkonlineweb/src/main/java/com/lyms/talkonlineweb/domain/LymsHisInfo.java View file @ 02637fd
... ... @@ -62,7 +62,7 @@
62 62 * 身份证号码
63 63 */
64 64 @TableField(value = "idCard")
65   - @NotNull(message = "idcard不能为空")
  65 + //@NotNull(message = "idcard不能为空")
66 66 private String idcard;
67 67  
68 68 /**
talkonlineweb/src/main/java/com/lyms/talkonlineweb/domain/LymsOrder.java View file @ 02637fd
... ... @@ -8,6 +8,7 @@
8 8 import lombok.ToString;
9 9  
10 10 import java.io.Serializable;
  11 +import java.math.BigDecimal;
11 12 import java.util.Date;
12 13  
13 14 /**
14 15  
... ... @@ -42,7 +43,14 @@
42 43 @TableField(value = "pid")
43 44 private Integer pid;
44 45  
  46 +
45 47 /**
  48 + * 患者病例ID
  49 + */
  50 + @TableField(value = "pcid")
  51 + private Integer pcid;
  52 +
  53 + /**
46 54 * 商品编号
47 55 */
48 56 @TableField(value = "gid")
49 57  
50 58  
51 59  
... ... @@ -61,23 +69,56 @@
61 69 private Integer cnt;
62 70  
63 71 /**
  72 + * 总金额
  73 + */
  74 + @TableField(value = "amount")
  75 + private Integer amount;
  76 +
  77 + /**
64 78 * 订单状态 订单生成(0),支付成功(1),处理完成(2),处理失败(-1)
65 79 */
66 80 @TableField(value = "status")
67 81 private Integer status;
68 82  
69 83 /**
70   - * 支付订单
  84 + * 微信预下单支付
71 85 */
72 86 @TableField(value = "payorderid")
73 87 private String payorderid;
74 88  
75 89 /**
  90 + * 微信支付订单号 回调时返回
  91 + */
  92 + @TableField(value = "transaction_id")
  93 + private String transactionId;
  94 +
  95 + /**
76 96 * 用户微信openid
77 97 */
78 98 @TableField(value = "openid")
79 99 private String openid;
80 100  
  101 + /**
  102 + * 主要为了计算退费
  103 + * 订单服务周期开始
  104 + */
  105 + @TableField(value = "service_start_time")
  106 + private Date serviceStartTime;
  107 +
  108 + /**
  109 + * 订单服务周期结束
  110 + */
  111 + @TableField(value = "service_end_time")
  112 + private Date serviceEndTime;
  113 +
  114 + /**
  115 + * 0 正常 1申请退款中 2 退款通过 3 退款拒绝
  116 + */
  117 + @TableField(value = "refund_status")
  118 + private Integer refundStatus;
  119 +
  120 + @TableField(value = "pay_time")
  121 + private Date payTime;
81 122  
82 123  
83 124 /**
talkonlineweb/src/main/java/com/lyms/talkonlineweb/domain/LymsOrderRefund.java View file @ 02637fd
  1 +package com.lyms.talkonlineweb.domain;
  2 +
  3 +import com.baomidou.mybatisplus.annotation.IdType;
  4 +import com.baomidou.mybatisplus.annotation.TableField;
  5 +import com.baomidou.mybatisplus.annotation.TableId;
  6 +import com.baomidou.mybatisplus.annotation.TableName;
  7 +import lombok.Data;
  8 +import lombok.ToString;
  9 +
  10 +import java.io.Serializable;
  11 +import java.util.Date;
  12 +
  13 +/**
  14 + * 退款申请
  15 + */
  16 +@TableName(value ="lyms_order_refund")
  17 +@Data
  18 +@ToString
  19 +public class LymsOrderRefund extends BaseModel implements Serializable {
  20 +
  21 + /**
  22 + *
  23 + */
  24 + @TableId(value = "id", type = IdType.AUTO)
  25 + private Integer id;
  26 +
  27 + /**
  28 + * 患者ID
  29 + */
  30 + @TableField(value = "pid")
  31 + private Integer pid;
  32 +
  33 + /**
  34 + * 订单编号
  35 + */
  36 + @TableField(value = "orderno")
  37 + private String orderno;
  38 +
  39 + @TableField(value = "out_fund_no")
  40 + private String outFundNo;
  41 +
  42 + @TableField(value = "reason")
  43 + private String reason;
  44 +
  45 + @TableField(value = "can_return_money")
  46 + private Integer canReturnMoney;
  47 +
  48 + @TableField(value = "real_return_money")
  49 + private Integer realReturnMoney;
  50 +
  51 + @TableField(value = "remark")
  52 + private String remark;
  53 +
  54 + /**
  55 + * 退款单状态 0 申请 1 同意 2 驳回
  56 + */
  57 + @TableField(value = "status")
  58 + private Integer status;
  59 +
  60 + /**
  61 + * 微信退款订单号
  62 + */
  63 + @TableField(value = "refund_id")
  64 + private String refundId;
  65 +
  66 + /**
  67 + * 创建人
  68 + */
  69 + @TableField(value = "createdby")
  70 + private Integer createdby;
  71 +
  72 + /**
  73 + * 创建时间
  74 + */
  75 + @TableField(value = "createdtime")
  76 + private Date createdtime;
  77 +
  78 + /**
  79 + * 更新人
  80 + */
  81 + @TableField(value = "updatedby")
  82 + private String updatedby;
  83 +
  84 + /**
  85 + * 更新时间
  86 + */
  87 + @TableField(value = "updatedtime")
  88 + private Date updatedtime;
  89 +}
talkonlineweb/src/main/java/com/lyms/talkonlineweb/domain/LymsTcard.java View file @ 02637fd
... ... @@ -48,6 +48,24 @@
48 48 private Integer price;
49 49  
50 50 /**
  51 + * 问诊卡开始时间
  52 + */
  53 + @TableField(value = "start_time")
  54 + private Date startTime;
  55 +
  56 + /**
  57 + * 问诊卡结束时间
  58 + */
  59 + @TableField(value = "end_time")
  60 + private Date endTime;
  61 +
  62 + /**
  63 + * 订单编号
  64 + */
  65 + @TableField(value = "order_no")
  66 + private String orderNo;
  67 +
  68 + /**
51 69 * 创建人
52 70 */
53 71 @TableField(value = "createdby")
talkonlineweb/src/main/java/com/lyms/talkonlineweb/mapper/LymsOrderMapper.java View file @ 02637fd
1 1 package com.lyms.talkonlineweb.mapper;
2 2  
3 3 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4   -import com.lyms.talkonlineweb.domain.LymsAttention;
  4 +import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
5 5 import com.lyms.talkonlineweb.domain.LymsOrder;
  6 +import com.lyms.talkonlineweb.request.OrderRequest;
  7 +import com.lyms.talkonlineweb.result.OrderListResponse;
  8 +import org.apache.ibatis.annotations.Param;
6 9  
  10 +import java.util.List;
  11 +
7 12 /**
8 13 * @Entity com.lyms.talkonlineweb.domain.LymsOrder
9 14 */
10 15 public interface LymsOrderMapper extends BaseMapper<LymsOrder> {
  16 +
  17 +
  18 + /**
  19 + * 订单列表查询
  20 + * @param orderRequest
  21 + * @return
  22 + */
  23 + List<OrderListResponse> queryOrderList(OrderRequest orderRequest);
  24 +
  25 + Page<OrderListResponse> queryOrderList(Page<OrderListResponse> page, @Param("orderRequest") OrderRequest orderRequest);
11 26  
12 27 }
talkonlineweb/src/main/java/com/lyms/talkonlineweb/mapper/LymsOrderRefundMapper.java View file @ 02637fd
  1 +package com.lyms.talkonlineweb.mapper;
  2 +
  3 +import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  4 +import com.lyms.talkonlineweb.domain.LymsOrderRefund;
  5 +
  6 +public interface LymsOrderRefundMapper extends BaseMapper<LymsOrderRefund> {
  7 +}
talkonlineweb/src/main/java/com/lyms/talkonlineweb/request/OrderRequest.java View file @ 02637fd
  1 +package com.lyms.talkonlineweb.request;
  2 +
  3 +import lombok.Data;
  4 +
  5 +@Data
  6 +public class OrderRequest {
  7 +
  8 + private String key; //姓名 手机号 身份证号
  9 +
  10 + private Integer orderType; // 1续费 2 初次购买
  11 +
  12 + private String payTimeStart; //付款时间
  13 +
  14 + private String payTimeEnd; //付款时间
  15 +}
talkonlineweb/src/main/java/com/lyms/talkonlineweb/result/OrderListResponse.java View file @ 02637fd
  1 +package com.lyms.talkonlineweb.result;
  2 +
  3 +import lombok.Data;
  4 +
  5 +import java.util.Date;
  6 +
  7 +@Data
  8 +public class OrderListResponse {
  9 +
  10 + private String pname;
  11 +
  12 + private String sex;
  13 +
  14 + private String idno;
  15 +
  16 + private String birth;
  17 +
  18 + private String orderno;
  19 +
  20 + private String payTime;
  21 +
  22 + private Integer cnt;
  23 +
  24 + private String goodName;
  25 +
  26 + private Integer pcid;
  27 +
  28 + private Integer refundStatus;
  29 +
  30 + private Integer orderType;
  31 +
  32 + private String orderTypeName;
  33 +
  34 +}
talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/LymsOrderRefundService.java View file @ 02637fd
  1 +package com.lyms.talkonlineweb.service;
  2 +
  3 +import com.baomidou.mybatisplus.extension.service.IService;
  4 +import com.lyms.talkonlineweb.domain.LymsOrderRefund;
  5 +
  6 +/**
  7 + *
  8 + */
  9 +public interface LymsOrderRefundService extends IService<LymsOrderRefund> {
  10 +
  11 +}
talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/LymsOrderService.java View file @ 02637fd
1 1 package com.lyms.talkonlineweb.service;
2 2  
  3 +import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
3 4 import com.baomidou.mybatisplus.extension.service.IService;
4 5 import com.lyms.talkonlineweb.domain.LymsAttention;
5 6 import com.lyms.talkonlineweb.domain.LymsOrder;
  7 +import com.lyms.talkonlineweb.request.OrderRequest;
  8 +import com.lyms.talkonlineweb.result.OrderListResponse;
6 9  
  10 +import java.util.List;
  11 +
7 12 /**
8 13 *
9 14 */
10 15 public interface LymsOrderService extends IService<LymsOrder> {
11 16  
12   - boolean handleOrder(String payOrderId, String mchOrderNo);
  17 + boolean handleOrder(LymsOrder lymsOrder);
  18 +
  19 + List<OrderListResponse> queryOrderList(OrderRequest orderRequest);
  20 +
  21 + Page<OrderListResponse> queryOrderList(Page<OrderListResponse> page, OrderRequest orderRequest);
13 22 }
talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/LymsPatientService.java View file @ 02637fd
... ... @@ -20,5 +20,7 @@
20 20 List<Map<String,Object>> getPcInfoList();
21 21  
22 22 LymsPatient addPatientHxId(LymsPatient patient);
  23 +
  24 + LymsPatient getPatientByToken(String token);
23 25 }
talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/impl/LymsHisInfoServiceImpl.java View file @ 02637fd
... ... @@ -10,6 +10,7 @@
10 10 import com.lyms.talkonlineweb.service.*;
11 11 import com.lyms.talkonlineweb.mapper.LymsHisInfoMapper;
12 12 import com.lyms.talkonlineweb.util.Constant;
  13 +import com.lyms.talkonlineweb.util.DateUtil;
13 14 import com.lyms.talkonlineweb.util.StringUtil;
14 15 import com.lyms.talkonlineweb.util.WeiXinUtil;
15 16 import lombok.extern.log4j.Log4j2;
16 17  
... ... @@ -49,7 +50,10 @@
49 50 @Autowired
50 51 private LymsDictCodeOrmService lymsDictCodeOrmService;
51 52  
  53 + @Autowired
  54 + private LymsOrderService lymsOrderService;
52 55  
  56 +
53 57 @Override
54 58 @Transactional(rollbackFor = {Exception.class,RuntimeException.class})
55 59 public String upHisInfo(LymsHisInfo lymsHisInfo) throws Exception,RuntimeException {
... ... @@ -195,6 +199,20 @@
195 199 //患者(身份证)
196 200 String idCard = lymsHisInfo.getIdcard();
197 201 if (StringUtil.isEmpty(idCard)) {
  202 + QueryWrapper<LymsPatient> queryWrapper = new QueryWrapper<>();
  203 + queryWrapper.eq("pname",lymsHisInfo.getName());
  204 + queryWrapper.eq("enrolment_phone",lymsHisInfo.getPhone());
  205 + List<LymsPatient> list = lymsPatientService.list(queryWrapper);
  206 + /*if(CollectionUtils.isNotEmpty(list)){
  207 + String idno = list.get(0).getIdno();
  208 + //是否需要去查询订单 todo
  209 + lymsHisInfo.setIdcard(idno);
  210 + this.updateById(lymsHisInfo);
  211 +
  212 + }else{
  213 + return "患者身份证号不存在,请等待患者注册补全身份证信息后再上传。";
  214 + }*/
  215 +
198 216 return "患者身份证号不存在,请等待患者注册补全身份证信息后再上传。";
199 217 //idCard=lymsHisInfo.getVccardno();
200 218 }
... ... @@ -276,7 +294,7 @@
276 294 patient.setOpenid(WeiXinUtil.getWxOpenId(patient.getCode()));
277 295 }
278 296 //his患者上传默认给4张问诊卡
279   - patient.setCcnt(4);
  297 + patient.setCcnt(Constant.CARD_COUNT_MONTH);
280 298 boolean f = lymsPatientService.saveOrUpdate(patient);
281 299  
282 300 // 添加病例
283 301  
284 302  
... ... @@ -314,18 +332,33 @@
314 332  
315 333  
316 334 Date instDate = new Date();
317   - //需要添问诊卡记录
318   - for (int i = 0; i < patient.getCcnt() && Objects.nonNull(patient.getCcnt()); i++) {
319   - LymsTcard tcard = new LymsTcard();
320   - tcard.setCnt(1);
321   - tcard.setPcid(pcase.getPcid());
322   - tcard.setPid(patient.getId());
323   - tcard.setFid(2);
324   - tcard.setCreatedby(patient.getCreatedby());
325   - tcard.setCreatedtime(instDate);
326 335  
327   - lymsTcardService.saveOrUpdate(tcard);
  336 + //查找两天内支付的订单
  337 + QueryWrapper<LymsOrder> queryWrapper = new QueryWrapper<>();
  338 + queryWrapper.eq("pid",patient.getIdno());
  339 + queryWrapper.gt("status",0);
  340 + queryWrapper.gt("createdtime", DateUtil.addDay(instDate,-2));
  341 + List<LymsOrder> list = lymsOrderService.list(queryWrapper);
  342 +
  343 + if(CollectionUtils.isNotEmpty(list)){
  344 + lymsOrderService.handleOrder(list.get(0));
  345 + }else{
  346 + //不是通过订单生成的问诊卡
  347 + for (int i = 0; i < patient.getCcnt() && Objects.nonNull(patient.getCcnt()); i++) {
  348 + LymsTcard tcard = new LymsTcard();
  349 + tcard.setCnt(1);
  350 + tcard.setPcid(pcase.getPcid());
  351 + tcard.setPid(patient.getId());
  352 + tcard.setFid(2);
  353 + tcard.setStartTime(instDate);
  354 + tcard.setEndTime(DateUtil.addMonth(instDate,1));
  355 + tcard.setCreatedby(patient.getCreatedby());
  356 + tcard.setCreatedtime(instDate);
  357 + lymsTcardService.saveOrUpdate(tcard);
  358 + }
328 359 }
  360 +
  361 +
329 362 baseResponse.setObject(patient);
330 363 baseResponse.setErrorcode(f == true ? 0 : 1);
331 364 return baseResponse;
talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/impl/LymsOrderRefundServiceImpl.java View file @ 02637fd
  1 +package com.lyms.talkonlineweb.service.impl;
  2 +
  3 +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  4 +import com.lyms.talkonlineweb.domain.LymsOrderRefund;
  5 +import com.lyms.talkonlineweb.mapper.LymsOrderRefundMapper;
  6 +import com.lyms.talkonlineweb.service.LymsOrderRefundService;
  7 +import org.springframework.stereotype.Service;
  8 +
  9 +
  10 +/**
  11 + *
  12 + * @author Administrator
  13 + */
  14 +@Service
  15 +public class LymsOrderRefundServiceImpl extends ServiceImpl<LymsOrderRefundMapper, LymsOrderRefund>
  16 + implements LymsOrderRefundService {
  17 +
  18 +
  19 +}
talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/impl/LymsOrderServiceImpl.java View file @ 02637fd
... ... @@ -2,6 +2,7 @@
2 2  
3 3 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
4 4 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  5 +import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
5 6 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
6 7 import com.lyms.talkonlineweb.domain.LymsAttention;
7 8 import com.lyms.talkonlineweb.domain.LymsOrder;
8 9  
9 10  
10 11  
... ... @@ -12,13 +13,19 @@
12 13 import com.lyms.talkonlineweb.mapper.LymsOrderMapper;
13 14 import com.lyms.talkonlineweb.mapper.LymsPatientMapper;
14 15 import com.lyms.talkonlineweb.mapper.LymsTcardMapper;
  16 +import com.lyms.talkonlineweb.request.OrderRequest;
  17 +import com.lyms.talkonlineweb.result.OrderListResponse;
15 18 import com.lyms.talkonlineweb.service.LymsAttentionService;
16 19 import com.lyms.talkonlineweb.service.LymsOrderService;
  20 +import com.lyms.talkonlineweb.util.Constant;
  21 +import com.lyms.talkonlineweb.util.DateUtil;
17 22 import org.springframework.beans.factory.annotation.Autowired;
18 23 import org.springframework.stereotype.Service;
19 24 import org.springframework.transaction.annotation.Transactional;
20 25  
  26 +import javax.annotation.Resource;
21 27 import java.util.Date;
  28 +import java.util.List;
22 29  
23 30 /**
24 31 *
25 32  
26 33  
27 34  
28 35  
29 36  
30 37  
31 38  
... ... @@ -28,48 +35,74 @@
28 35 public class LymsOrderServiceImpl extends ServiceImpl<LymsOrderMapper, LymsOrder>
29 36 implements LymsOrderService {
30 37  
31   - @Autowired
  38 + @Resource
32 39 private LymsPatientMapper lymsPatientMapper;
33 40  
34   - @Autowired
  41 + @Resource
35 42 private LymsTcardMapper lymsTcardMapper;
36 43  
  44 + @Resource
  45 + private LymsOrderMapper lymsOrderMapper;
  46 +
37 47 @Override
38 48 @Transactional(rollbackFor = Exception.class)
39   - public boolean handleOrder(String payOrderId, String mchOrderNo) {
40   -
41   - //处理业务逻辑
42   - LambdaQueryWrapper<LymsOrder> wrapper = new QueryWrapper().lambda();
43   - wrapper.eq(LymsOrder::getOrderno, mchOrderNo);
44   - wrapper.eq(LymsOrder::getPayorderid, payOrderId);
45   - LymsOrder lymsOrders = getOne(wrapper);
  49 + public boolean handleOrder(LymsOrder lymsOrders) {
  50 + Date currentTime = new Date();
  51 + //说明是
46 52 if (lymsOrders != null) {
47 53 LymsPatient patient = lymsPatientMapper.selectById(lymsOrders.getPid());
48 54 if (patient == null)
49 55 {
50 56 return false;
51 57 }
52   -
53   - Date createTime = new Date();
54   - for (int i = 0; i < lymsOrders.getCnt(); i++)
55   - {
56   - LymsTcard tcard = new LymsTcard();
57   - tcard.setPid(lymsOrders.getPid());
58   - tcard.setFid(1);
59   - tcard.setPrice(lymsOrders.getPrice());
60   - tcard.setCreatedtime(createTime);
61   - lymsTcardMapper.insert(tcard);
62   - }
63   - //更新患者的卡的数量
64   - lymsPatientMapper.updatePatientCcnt(lymsOrders.getCnt(),patient.getId());
65   -
66 58 lymsOrders.setStatus(PayStatus.SUCCESS.getCode());
  59 + lymsOrders.setServiceStartTime(currentTime);
  60 + lymsOrders.setServiceEndTime(DateUtil.addMonth(currentTime,lymsOrders.getCnt()));
67 61 lymsOrders.setUpdatedtime(new Date());
68 62 updateById(lymsOrders);
  63 + //pcid不为空,说明是续期购买,直接生成生成问诊卡
  64 + if(lymsOrders.getPcid() != null){
  65 +
  66 + //数量代表购买几个月
  67 + int months = lymsOrders.getCnt();
  68 + for(int j = 0 ;j < months ; j++){
  69 + Date startTime = DateUtil.addMonth(currentTime,j);
  70 + Date endTime = DateUtil.addMonth(currentTime,j+1);
  71 + for (int i = 0; i < Constant.CARD_COUNT_MONTH; i++)
  72 + {
  73 + LymsTcard tcard = new LymsTcard();
  74 + tcard.setPid(lymsOrders.getPid());
  75 + tcard.setPcid(lymsOrders.getPcid());
  76 + tcard.setFid(1);
  77 + tcard.setStartTime(startTime);
  78 + tcard.setEndTime(endTime);
  79 + tcard.setOrderNo(lymsOrders.getOrderno());
  80 + tcard.setPrice(lymsOrders.getPrice());
  81 + tcard.setCreatedtime(currentTime);
  82 + lymsTcardMapper.insert(tcard);
  83 + }
  84 + }
  85 +
  86 +
  87 + }
  88 + //更新患者的卡的数量,患者信息上的问诊卡数量其实没啥意义了
  89 + lymsPatientMapper.updatePatientCcnt(lymsOrders.getCnt()*Constant.CARD_COUNT_MONTH,patient.getId());
69 90 return true;
70 91 }
71 92  
72 93 return false;
73 94 }
  95 +
  96 + @Override
  97 + public List<OrderListResponse> queryOrderList(OrderRequest orderRequest) {
  98 + return lymsOrderMapper.queryOrderList(orderRequest);
  99 + }
  100 +
  101 + @Override
  102 + public Page<OrderListResponse> queryOrderList(Page<OrderListResponse> page, OrderRequest orderRequest) {
  103 + return lymsOrderMapper.queryOrderList(page,orderRequest);
  104 + }
  105 +
  106 +
74 107 }
talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/impl/LymsPatientServiceImpl.java View file @ 02637fd
... ... @@ -3,12 +3,15 @@
3 3 import com.alibaba.fastjson.JSONArray;
4 4 import com.alibaba.fastjson.JSONObject;
5 5 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  6 +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
6 7 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
7 8 import com.lyms.talkonlineweb.domain.LymsPatient;
8 9 import com.lyms.talkonlineweb.service.LymsPatientService;
9 10 import com.lyms.talkonlineweb.mapper.LymsPatientMapper;
10 11 import com.lyms.talkonlineweb.util.Constant;
11 12 import com.lyms.talkonlineweb.util.HXService;
  13 +import com.lyms.talkonlineweb.util.JwtUtils;
  14 +import io.jsonwebtoken.Claims;
12 15 import org.springframework.beans.factory.annotation.Autowired;
13 16 import org.springframework.stereotype.Service;
14 17  
... ... @@ -60,6 +63,25 @@
60 63 }
61 64  
62 65 return patient;
  66 + }
  67 +
  68 + @Override
  69 + public LymsPatient getPatientByToken(String token) {
  70 + Claims claims = null;
  71 + try {
  72 + claims = JwtUtils.parseJWT(token);
  73 + } catch (Exception e) {
  74 + log.error("根据token获取信息异常",e);
  75 + }
  76 + String idno = claims.getSubject();
  77 +
  78 + QueryWrapper<LymsPatient> query = new QueryWrapper<>();
  79 + query.eq("idno",idno);
  80 + List<LymsPatient> list = this.list(query);
  81 + if(CollectionUtils.isNotEmpty(list)){
  82 + return list.get(0);
  83 + }
  84 + throw new RuntimeException("查询患者信息异常");
63 85 }
64 86 }
talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/Constant.java View file @ 02637fd
... ... @@ -10,6 +10,11 @@
10 10 public static final String COMMON_PASSWD = "123456";//通用密码
11 11  
12 12 /**
  13 + * 每月问诊卡数量
  14 + */
  15 + public static final int CARD_COUNT_MONTH = 6;
  16 +
  17 + /**
13 18 * 患者端商户id
14 19 */
15 20 public static final String MCHID = "1426009502";
talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/DateUtil.java View file @ 02637fd
... ... @@ -200,6 +200,25 @@
200 200 lock.unlock();
201 201 }
202 202 }
  203 +
  204 + /**
  205 + * 增加月份
  206 + * @param srcDate
  207 + * @param months
  208 + * @return
  209 + */
  210 + public static Date addMonth(Date srcDate, int months) {
  211 + lock.lock();
  212 + try {
  213 +
  214 + Calendar rightNow = Calendar.getInstance();
  215 + rightNow.setTime(srcDate);
  216 + rightNow.add(Calendar.MONTH, months);
  217 + return rightNow.getTime();
  218 + } finally {
  219 + lock.unlock();
  220 + }
  221 + }
203 222 public static Integer getAge(Date birth) {
204 223 if (null == birth) {
205 224 return null;
... ... @@ -235,8 +254,8 @@
235 254  
236 255 /**
237 256 * 时间差
238   - * @param start
239   - * @param end
  257 + * @param smdate
  258 + * @param bdate
240 259 * @return
241 260 */
242 261 public static int daysBetween(Date smdate, Date bdate) {
... ... @@ -288,6 +307,11 @@
288 307 calendar.set(Calendar.MINUTE, 59);
289 308 calendar.set(Calendar.SECOND, 59);
290 309 return calendar.getTime();
  310 + }
  311 +
  312 +
  313 + public static void main(String[] args) {
  314 + System.out.println(addMonth(new Date(),-1));
291 315 }
292 316  
293 317 }
talkonlineweb/src/main/resources/mapper/LymsOrderMapper.xml View file @ 02637fd
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<!DOCTYPE mapper
  3 + PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4 + "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5 +<mapper namespace="com.lyms.talkonlineweb.mapper.LymsOrderMapper">
  6 +
  7 + <resultMap id="BaseResultMap" type="com.lyms.talkonlineweb.domain.LymsOrder">
  8 + <id property="id" column="id" jdbcType="INTEGER"/>
  9 + <result property="orderno" column="orderno" jdbcType="VARCHAR"/>
  10 + <result property="pid" column="pid" jdbcType="INTEGER"/>
  11 + <result property="pcid" column="pcid" jdbcType="INTEGER"/>
  12 + <result property="gid" column="gid" jdbcType="INTEGER"/>
  13 + <result property="price" column="price" jdbcType="INTEGER"/>
  14 + <result property="cnt" column="cnt" jdbcType="INTEGER"/>
  15 + <result property="amount" column="amount" jdbcType="INTEGER"/>
  16 + <result property="status" column="status" jdbcType="INTEGER"/>
  17 + <result property="payorderid" column="payorderid" jdbcType="VARCHAR"/>
  18 + <result property="transactionId" column="transaction_id" jdbcType="VARCHAR"/>
  19 + <result property="openid" column="openid" jdbcType="VARCHAR"/>
  20 + <result property="serviceStartTime" column="service_start_time" jdbcType="TIMESTAMP"/>
  21 + <result property="serviceEndTime" column="service_end_time" jdbcType="TIMESTAMP"/>
  22 + <result property="refundStatus" column="refund_status" jdbcType="INTEGER"/>
  23 + <result property="payTime" column="pay_time" jdbcType="TIMESTAMP"/>
  24 +
  25 + <result property="createdby" column="createdby" jdbcType="INTEGER"/>
  26 + <result property="createdtime" column="createdtime" jdbcType="TIMESTAMP"/>
  27 + <result property="updatedby" column="updatedby" jdbcType="INTEGER"/>
  28 + <result property="updatedtime" column="updatedtime" jdbcType="TIMESTAMP"/>
  29 +
  30 + </resultMap>
  31 +
  32 + <select id="queryOrderList" parameterType="com.lyms.talkonlineweb.request.OrderRequest"
  33 + resultType="com.lyms.talkonlineweb.result.OrderListResponse">
  34 +
  35 + select
  36 + p.pname,
  37 + p.sex,
  38 + p.birth,
  39 + p.idno,
  40 + o.orderno,
  41 + o.pay_time as payTime,
  42 + goods.name as goodName,
  43 + o.refund_status as refundStatus,
  44 + o.cnt,
  45 + o.pcid
  46 + from lyms_patient p,
  47 + lyms_order o ,
  48 + lyms_goods goods
  49 + where p.id = o.pid
  50 + and o.gid = goods.id
  51 + and o.status = 1
  52 + <if test="orderRequest.key != null and orderRequest.key != '' ">
  53 + and (p.pname = #{orderRequest.key} or p.enrolment_phone = #{orderRequest.key} or p.idno= #{orderRequest.key})
  54 + </if>
  55 + <if test="orderRequest.orderType != null and orderRequest.orderType == 1">
  56 + and ( o.pcid is not null)
  57 + </if>
  58 + <if test="orderRequest.orderType != null and orderRequest.orderType == 2">
  59 + and ( o.pcid is null)
  60 + </if>
  61 + <if test="orderRequest.payTimeStart != null and orderRequest.payTimeStart != ''">
  62 + and ( o.pay_time > #{orderRequest.payTimeStart})
  63 + </if>
  64 +
  65 + <if test="orderRequest.payTimeEnd != null and orderRequest.payTimeEnd != ''">
  66 + and ( o.pay_time &lt; #{orderRequest.payTimeEnd})
  67 + </if>
  68 +
  69 + order by o.pay_time desc
  70 +
  71 + </select>
  72 +</mapper>