|
@@ -1,10 +1,13 @@
|
|
|
package com.fs.patient.service.impl;
|
|
package com.fs.patient.service.impl;
|
|
|
|
|
|
|
|
-import java.util.Collections;
|
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
|
|
import cn.binarywang.wx.miniapp.api.WxMaService;
|
|
import cn.binarywang.wx.miniapp.api.WxMaService;
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.fs.common.core.domain.R;
|
|
import com.fs.common.core.domain.R;
|
|
|
import com.fs.common.exception.CustomException;
|
|
import com.fs.common.exception.CustomException;
|
|
|
import com.fs.common.utils.DateUtils;
|
|
import com.fs.common.utils.DateUtils;
|
|
@@ -12,24 +15,38 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fs.company.domain.CompanyUser;
|
|
import com.fs.company.domain.CompanyUser;
|
|
|
import com.fs.company.mapper.CompanyUserMapper;
|
|
import com.fs.company.mapper.CompanyUserMapper;
|
|
|
import com.fs.core.config.WxMaConfiguration;
|
|
import com.fs.core.config.WxMaConfiguration;
|
|
|
|
|
+import com.fs.course.domain.FsCourseRedPacketLog;
|
|
|
import com.fs.his.domain.FsDoctor;
|
|
import com.fs.his.domain.FsDoctor;
|
|
|
import com.fs.his.domain.FsProject;
|
|
import com.fs.his.domain.FsProject;
|
|
|
|
|
+import com.fs.his.domain.FsUser;
|
|
|
|
|
+import com.fs.his.domain.FsUserWx;
|
|
|
|
|
+import com.fs.his.mapper.FsUserMapper;
|
|
|
import com.fs.his.param.FsPatientBaseInfoListDParam;
|
|
import com.fs.his.param.FsPatientBaseInfoListDParam;
|
|
|
|
|
+import com.fs.his.param.WxSendRedPacketParam;
|
|
|
import com.fs.his.service.IFsDoctorService;
|
|
import com.fs.his.service.IFsDoctorService;
|
|
|
import com.fs.his.service.IFsProjectService;
|
|
import com.fs.his.service.IFsProjectService;
|
|
|
|
|
+import com.fs.his.service.IFsStorePaymentService;
|
|
|
|
|
+import com.fs.his.service.IFsUserWxService;
|
|
|
import com.fs.his.vo.FsPatientBaseInfoListDVO;
|
|
import com.fs.his.vo.FsPatientBaseInfoListDVO;
|
|
|
|
|
+import com.fs.patient.domain.FsProjectRedPacketRecord;
|
|
|
|
|
+import com.fs.patient.mapper.FsProjectRedPacketRecordMapper;
|
|
|
import com.fs.patient.param.BindPatientParam;
|
|
import com.fs.patient.param.BindPatientParam;
|
|
|
|
|
+import com.fs.patient.param.FsProjectSendRewardUParam;
|
|
|
import com.fs.patient.vo.PatientBaseInfoVO;
|
|
import com.fs.patient.vo.PatientBaseInfoVO;
|
|
|
import com.fs.system.oss.CloudStorageService;
|
|
import com.fs.system.oss.CloudStorageService;
|
|
|
import com.fs.system.oss.OSSFactory;
|
|
import com.fs.system.oss.OSSFactory;
|
|
|
|
|
+import com.fs.system.service.ISysConfigService;
|
|
|
|
|
+import com.github.binarywang.wxpay.bean.transfer.TransferBillsResult;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import me.chanjar.weixin.common.error.WxErrorException;
|
|
import me.chanjar.weixin.common.error.WxErrorException;
|
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.fs.patient.mapper.FsPatientBaseInfoMapper;
|
|
import com.fs.patient.mapper.FsPatientBaseInfoMapper;
|
|
|
import com.fs.patient.domain.FsPatientBaseInfo;
|
|
import com.fs.patient.domain.FsPatientBaseInfo;
|
|
|
import com.fs.patient.service.IFsPatientBaseInfoService;
|
|
import com.fs.patient.service.IFsPatientBaseInfoService;
|
|
|
|
|
+import org.springframework.util.ObjectUtils;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 患者基本信息Service业务层处理
|
|
* 患者基本信息Service业务层处理
|
|
@@ -53,6 +70,21 @@ public class FsPatientBaseInfoServiceImpl extends ServiceImpl<FsPatientBaseInfoM
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private IFsProjectService projectService;
|
|
private IFsProjectService projectService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private FsProjectRedPacketRecordMapper projectRedPacketRecordMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private FsUserMapper userMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private ISysConfigService configService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private IFsUserWxService fsUserWxService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private IFsStorePaymentService fsStorePaymentService;
|
|
|
/**
|
|
/**
|
|
|
* 查询患者基本信息
|
|
* 查询患者基本信息
|
|
|
*
|
|
*
|
|
@@ -213,6 +245,25 @@ public class FsPatientBaseInfoServiceImpl extends ServiceImpl<FsPatientBaseInfoM
|
|
|
patientBaseInfoVO.setProject(fsProject);
|
|
patientBaseInfoVO.setProject(fsProject);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ //红包配置信息
|
|
|
|
|
+ BigDecimal amount = new BigDecimal("0.1");
|
|
|
|
|
+ boolean openFlag = false;
|
|
|
|
|
+ String json = getProjectRedPacketConfig();
|
|
|
|
|
+ if(StringUtils.isNotEmpty(json)) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ JSONObject jsonObject = JSON.parseObject(json);
|
|
|
|
|
+ String open = jsonObject.getString("open");
|
|
|
|
|
+ if ("1".equals(open)) {
|
|
|
|
|
+ openFlag = true;
|
|
|
|
|
+ }
|
|
|
|
|
+ amount = jsonObject.getBigDecimal("amount");
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("解析理疗红包配置失败, json={}", json, e);
|
|
|
|
|
+ amount = new BigDecimal("0.1");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ patientBaseInfoVO.setAmount(amount);
|
|
|
|
|
+ patientBaseInfoVO.setOpenFlag(openFlag);
|
|
|
return R.ok().put("data", patientBaseInfoVO);
|
|
return R.ok().put("data", patientBaseInfoVO);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -274,4 +325,144 @@ public class FsPatientBaseInfoServiceImpl extends ServiceImpl<FsPatientBaseInfoM
|
|
|
}
|
|
}
|
|
|
return R.error("诊断失败");
|
|
return R.error("诊断失败");
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public R sendProjectReward(FsProjectSendRewardUParam param) {
|
|
|
|
|
+ FsPatientBaseInfo fsPatientBaseInfo = fsPatientBaseInfoMapper.selectFsPatientBaseInfoById(param.getPatientId());
|
|
|
|
|
+ if (fsPatientBaseInfo == null) {
|
|
|
|
|
+ return R.error("患者信息错误,领取失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ CompanyUser companyUser = companyUserMapper.selectCompanyUserByCompanyUserId(fsPatientBaseInfo.getCompanyUserId());
|
|
|
|
|
+ if (companyUser == null) {
|
|
|
|
|
+ return R.error("销售信息错误,领取失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ FsProject fsProject = projectService.selectFsProjectById(param.getProjectId());
|
|
|
|
|
+ if (fsProject == null) {
|
|
|
|
|
+ return R.error("理疗信息错误,领取失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ //获取今日理疗红包记录
|
|
|
|
|
+ FsProjectRedPacketRecord redPacketRecord = projectRedPacketRecordMapper.selectTodayFsProjectRedPacketRecordByUserId(param.getUserId());
|
|
|
|
|
+ if (!ObjectUtils.isEmpty(redPacketRecord)) {
|
|
|
|
|
+ if (redPacketRecord.getCollectType() == 1) {
|
|
|
|
|
+ return R.error("今日已领取过红包!");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (redPacketRecord.getCollectType() == 0) {
|
|
|
|
|
+ if (!Objects.equals(param.getProjectId(), redPacketRecord.getProjectId())) {
|
|
|
|
|
+ return R.error("当日只能领取一次理疗红包!");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ // 获取用户信息
|
|
|
|
|
+ FsUser user = userMapper.selectFsUserByUserId(param.getUserId());
|
|
|
|
|
+ if (user != null && user.getStatus()==0){
|
|
|
|
|
+ return R.error("会员被停用,无权限,请联系客服!");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ FsProjectRedPacketRecord record = projectRedPacketRecordMapper.selectFsProjectRedPacketByUserIdAndProjectId(param.getUserId(), param.getProjectId());
|
|
|
|
|
+ if (record != null && record.getCollectType() == 1) {
|
|
|
|
|
+ return R.error("已领取过该理疗红包,不可重复领取");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (record != null && record.getCollectType() == 0 && StringUtils.isNotEmpty(record.getResult())) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ //返回已有生成的红包数据
|
|
|
|
|
+ return JSON.parseObject(record.getResult(), R.class);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("理疗红包=====》转换已有红包数据失败:{}",e.getMessage());
|
|
|
|
|
+ return R.error("操作频繁,请稍后再试!");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ //发送红包
|
|
|
|
|
+ return sendProjectRedPacket(param,user,companyUser);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ private R sendProjectRedPacket(FsProjectSendRewardUParam param,FsUser user,CompanyUser companyUser){
|
|
|
|
|
+ //默认0.1红包数据
|
|
|
|
|
+ BigDecimal amount;
|
|
|
|
|
+ String json = getProjectRedPacketConfig();
|
|
|
|
|
+ if(StringUtils.isNotEmpty(json)) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ JSONObject jsonObject = JSON.parseObject(json);
|
|
|
|
|
+ String open = jsonObject.getString("open");
|
|
|
|
|
+ if (!"1".equals(open)) {
|
|
|
|
|
+ return R.error("未开启领取功能,领取失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ amount = jsonObject.getBigDecimal("amount");
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("解析理疗红包配置失败, json={}", json, e);
|
|
|
|
|
+ amount = new BigDecimal("0.1");
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return R.error("获取理疗红包配置错误");
|
|
|
|
|
+ }
|
|
|
|
|
+ // 准备发送红包参数
|
|
|
|
|
+ WxSendRedPacketParam packetParam = new WxSendRedPacketParam();
|
|
|
|
|
+ //处理多小程序问题
|
|
|
|
|
+ FsUserWx fsUserWx = fsUserWxService.selectByAppIdAndUserId(param.getAppId(),user.getUserId(),1);
|
|
|
|
|
+ if (fsUserWx ==null){
|
|
|
|
|
+ try {
|
|
|
|
|
+ handleFsUserWx(user,param.getAppId());
|
|
|
|
|
+ }catch (Exception e){
|
|
|
|
|
+ log.error("【更新或插入用户与小程序的绑定关系失败】:{}", user.getUserId());
|
|
|
|
|
+ }
|
|
|
|
|
+ }else {
|
|
|
|
|
+ packetParam.setOpenId(fsUserWx.getOpenId());
|
|
|
|
|
+ }
|
|
|
|
|
+ packetParam.setRedPacketMode(1);
|
|
|
|
|
+ packetParam.setAppId(param.getAppId());
|
|
|
|
|
+ packetParam.setMpAppId(param.getAppId());
|
|
|
|
|
+ packetParam.setUser(user);
|
|
|
|
|
+ packetParam.setProjectFlag(true);
|
|
|
|
|
+ //小程序
|
|
|
|
|
+ packetParam.setSource(2);
|
|
|
|
|
+ packetParam.setCompanyId(companyUser.getCompanyId());
|
|
|
|
|
+
|
|
|
|
|
+ // 发送红包
|
|
|
|
|
+ R sendRedPacket = fsStorePaymentService.sendRedPacket(packetParam);
|
|
|
|
|
+ if (sendRedPacket.get("code").equals(200)) {
|
|
|
|
|
+ FsProjectRedPacketRecord redPacketRecord = new FsProjectRedPacketRecord();
|
|
|
|
|
+ TransferBillsResult transferBillsResult;
|
|
|
|
|
+ if (sendRedPacket.get("isNew").equals(1)){
|
|
|
|
|
+ transferBillsResult = (TransferBillsResult)sendRedPacket.get("data");
|
|
|
|
|
+ redPacketRecord.setResult(JSON.toJSONString(sendRedPacket));
|
|
|
|
|
+ redPacketRecord.setOutBatchNo(transferBillsResult.getOutBillNo());
|
|
|
|
|
+ }else {
|
|
|
|
|
+ redPacketRecord.setOutBatchNo(sendRedPacket.get("orderCode").toString());
|
|
|
|
|
+ redPacketRecord.setBatchId(sendRedPacket.get("batchId").toString());
|
|
|
|
|
+ }
|
|
|
|
|
+ // 添加红包记录
|
|
|
|
|
+ redPacketRecord.setCompanyId(companyUser.getCompanyId());
|
|
|
|
|
+ redPacketRecord.setCompanyUserId(companyUser.getUserId());
|
|
|
|
|
+ redPacketRecord.setCompanyName(companyUser.getCompanyName());
|
|
|
|
|
+ redPacketRecord.setUserId(param.getUserId());
|
|
|
|
|
+ redPacketRecord.setUserName(user.getNickName());
|
|
|
|
|
+ redPacketRecord.setProjectId(param.getProjectId());
|
|
|
|
|
+ redPacketRecord.setCollectType(0);
|
|
|
|
|
+ redPacketRecord.setSendTime(new Date());
|
|
|
|
|
+ redPacketRecord.setCreateTime(new Date());
|
|
|
|
|
+ redPacketRecord.setAmount(amount);
|
|
|
|
|
+ projectRedPacketRecordMapper.insertFsProjectRedPacketRecord(redPacketRecord);
|
|
|
|
|
+ return sendRedPacket;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return R.error("奖励发送失败,请联系客服");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void handleFsUserWx(FsUser user, String appId) {
|
|
|
|
|
+ FsUserWx fsUserWx = new FsUserWx();
|
|
|
|
|
+ fsUserWx.setType(1);
|
|
|
|
|
+ fsUserWx.setFsUserId(user.getUserId());
|
|
|
|
|
+ fsUserWx.setAppId(appId);
|
|
|
|
|
+ fsUserWx.setOpenId(user.getCourseMaOpenId());
|
|
|
|
|
+ fsUserWx.setUnionId(user.getUnionId());
|
|
|
|
|
+ fsUserWx.setCreateTime(new Date());
|
|
|
|
|
+ fsUserWx.setUpdateTime(new Date());
|
|
|
|
|
+ fsUserWxService.saveOrUpdateByUniqueKey(fsUserWx);
|
|
|
|
|
+
|
|
|
|
|
+ log.info("【更新或插入用户与小程序{}的绑定关系】:{}", appId, user.getUserId());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String getProjectRedPacketConfig(){
|
|
|
|
|
+ return configService.selectConfigByKey("projectRedPacket.config");
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|