|
@@ -6,18 +6,22 @@ import com.caimei365.order.mapper.OrderCommonMapper;
|
|
|
import com.caimei365.order.mapper.PayOrderMapper;
|
|
|
import com.caimei365.order.mapper.ReceiptMapper;
|
|
|
import com.caimei365.order.model.ResponseJson;
|
|
|
+import com.caimei365.order.model.bo.ReceiptParamsBo;
|
|
|
import com.caimei365.order.model.dto.ReceiptDto;
|
|
|
import com.caimei365.order.model.enums.OrderStatus;
|
|
|
import com.caimei365.order.model.po.BalanceRecordPo;
|
|
|
import com.caimei365.order.model.po.OrderReceiptRelationPo;
|
|
|
import com.caimei365.order.model.po.ReceiptPo;
|
|
|
import com.caimei365.order.model.vo.OrderVo;
|
|
|
+import com.caimei365.order.model.vo.ReceiptTypeVo;
|
|
|
import com.caimei365.order.model.vo.ReceiptUserVo;
|
|
|
import com.caimei365.order.model.vo.ReceiptVo;
|
|
|
import com.caimei365.order.service.ReceiptService;
|
|
|
import com.caimei365.order.utils.DateUtils;
|
|
|
import com.caimei365.order.utils.MathUtil;
|
|
|
import com.caimei365.order.utils.Md5Util;
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
+import com.github.pagehelper.PageInfo;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
@@ -59,7 +63,6 @@ public class ReceiptServiceImpl implements ReceiptService {
|
|
|
private static final Pattern PATTERN_ORDER = Pattern.compile("#(.*?)#");
|
|
|
private static final Pattern PATTERN_ORDER_ID = Pattern.compile("^[-\\+]?[\\d]*$");
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 线下收款用户微信授权
|
|
|
*
|
|
@@ -84,7 +87,7 @@ public class ReceiptServiceImpl implements ReceiptService {
|
|
|
return ResponseJson.success(receiptUser);
|
|
|
}
|
|
|
}
|
|
|
- return ResponseJson.error("微信授权失败,请尝试账号密码登录!",null);
|
|
|
+ return ResponseJson.error("微信授权失败,请尝试账号密码登录!", null);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -94,7 +97,7 @@ public class ReceiptServiceImpl implements ReceiptService {
|
|
|
* @param password 密码
|
|
|
*/
|
|
|
@Override
|
|
|
- public ResponseJson<ReceiptUserVo> passwordAuthorization(String mobile, String password, String code, String encryptedData, String iv, HttpHeaders headers) {
|
|
|
+ public ResponseJson<ReceiptUserVo> passwordAuthorization(String mobile, String password, String code, String encryptedData, String iv, HttpHeaders headers) {
|
|
|
// 收款用户
|
|
|
ReceiptUserVo receiptUser = receiptMapper.getReceiptUserByMobile(mobile);
|
|
|
if (null != receiptUser) {
|
|
@@ -107,23 +110,35 @@ public class ReceiptServiceImpl implements ReceiptService {
|
|
|
if (appletsInfo.getCode() != -1) {
|
|
|
Map<String, Object> infoData = appletsInfo.getData();
|
|
|
String openid = (String) infoData.get(WeChatService.Keys.OPEN_ID);
|
|
|
- receiptMapper.updateOpenidByMobile(openid, mobile);
|
|
|
+ String unionId = (String) infoData.get(WeChatService.Keys.UNION_ID);
|
|
|
+ receiptMapper.updateOpenidByMobile(openid, unionId, mobile);
|
|
|
receiptUser.setOpenid(openid);
|
|
|
+ receiptUser.setUnionId(unionId);
|
|
|
} else {
|
|
|
return ResponseJson.error(appletsInfo.getMsg(), null);
|
|
|
}
|
|
|
return ResponseJson.success(receiptUser);
|
|
|
}
|
|
|
}
|
|
|
- return ResponseJson.error("登录失败!",null);
|
|
|
+ return ResponseJson.error("登录失败!", null);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取收款类型
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResponseJson<List<ReceiptTypeVo>> getReceiptType() {
|
|
|
+ List<ReceiptTypeVo> list = receiptMapper.getReceiptType();
|
|
|
+ return ResponseJson.success(list);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 识别收款短信
|
|
|
- * @param message 收款短信
|
|
|
+ *
|
|
|
+ * @param smsContent 收款短信
|
|
|
*/
|
|
|
@Override
|
|
|
- public ResponseJson<ReceiptVo> readSmsMessage(String message, String openid) {
|
|
|
+ public ResponseJson<ReceiptVo> readSmsMessage(String smsContent, String openid) {
|
|
|
// 收款用户
|
|
|
ReceiptUserVo receiptUser = checkPermissions(1, openid);
|
|
|
if (null == receiptUser) {
|
|
@@ -131,9 +146,9 @@ public class ReceiptServiceImpl implements ReceiptService {
|
|
|
}
|
|
|
try {
|
|
|
// 识别短信内容
|
|
|
- ResponseJson<ReceiptVo> receipt = identifyMessage(message);
|
|
|
+ ResponseJson<ReceiptVo> receipt = identifyMessage(smsContent);
|
|
|
if (receipt != null) {
|
|
|
- return receipt ;
|
|
|
+ return receipt;
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
log.error("短信识别错误!", e);
|
|
@@ -163,7 +178,7 @@ public class ReceiptServiceImpl implements ReceiptService {
|
|
|
receiptPo.setSmsMd5Code(Md5Util.md5(receiptDto.getSmsContent()));
|
|
|
}
|
|
|
// 收款作废
|
|
|
- if (null != receiptDto.getId() && StringUtils.isNotBlank(receiptDto.getDelFlag())){
|
|
|
+ if (null != receiptDto.getId() && StringUtils.isNotBlank(receiptDto.getDelFlag())) {
|
|
|
// 收款状态receiptStatus:2已确认(待审核)、3审核通过
|
|
|
if ("2".equals(receiptDto.getReceiptStatus()) || "3".equals(receiptDto.getReceiptStatus())) {
|
|
|
// 收款款项类型receiptType:1订单款
|
|
@@ -183,8 +198,7 @@ public class ReceiptServiceImpl implements ReceiptService {
|
|
|
}
|
|
|
// 更新收款记录
|
|
|
receiptMapper.updateReceipt(receiptPo);
|
|
|
- }
|
|
|
- else {
|
|
|
+ } else {
|
|
|
// 如果是添加收款则判断是否存在重复添加
|
|
|
if (StringUtils.isNotBlank(receiptDto.getSmsContent()) && StringUtils.isNotBlank(receiptDto.getPayWay())) {
|
|
|
// 无短信备注内容短信无需判断(payWay传值的话是短信识别来的)
|
|
@@ -352,7 +366,7 @@ public class ReceiptServiceImpl implements ReceiptService {
|
|
|
double userMoney = baseMapper.getUserMoney(order.getUserId());
|
|
|
// 可用余额
|
|
|
Double availableMoney = baseMapper.getAbleUserMoney(order.getUserId());
|
|
|
- log.info("------->userId:" + order.getUserId() +",原余额:" + userMoney + "==原可用余额:" + availableMoney);
|
|
|
+ log.info("------->userId:" + order.getUserId() + ",原余额:" + userMoney + "==原可用余额:" + availableMoney);
|
|
|
if (money < 0d) {
|
|
|
// 待确认状态不需要修改余额,因为本身存在冻结余额不需要重复退回
|
|
|
if (0 != order.getStatus()) {
|
|
@@ -366,7 +380,7 @@ public class ReceiptServiceImpl implements ReceiptService {
|
|
|
}
|
|
|
|
|
|
payOrderMapper.updateMoneyByUserId(userMoney, availableMoney, order.getUserId());
|
|
|
- log.info("------->userId:" + order.getUserId() +",更新余额:" + userMoney + "==更新可用余额:" + availableMoney);
|
|
|
+ log.info("------->userId:" + order.getUserId() + ",更新余额:" + userMoney + "==更新可用余额:" + availableMoney);
|
|
|
log.info("----------->大额抹平金额退回账户:" + order.getUserId());
|
|
|
log.info("----------->大额抹平金额:" + money);
|
|
|
//保存余额到余额收支记录
|
|
@@ -403,11 +417,90 @@ public class ReceiptServiceImpl implements ReceiptService {
|
|
|
return ResponseJson.success(receiptPo);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取收款列表
|
|
|
+ *
|
|
|
+ * @param receiptType 收款款项类型:1订单款,2非订单款,3返佣款 4订单款或者非订单款(因财务阶段无法区分订单非订单), 5供应商退款
|
|
|
+ * @param receiptStatus 收款状态:1待确认、2已确认(待审核)、3审核通过、4审核未通过、5收款撤销【线上支付成功为审核通过】
|
|
|
+ * @param smsContent 收款短信
|
|
|
+ * @param startDate 筛选开始时间
|
|
|
+ * @param endDate 筛选结束时间
|
|
|
+ * @param openid 微信openid
|
|
|
+ * @param pageNum 页码
|
|
|
+ * @param pageSize 每页数量
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResponseJson<PageInfo<ReceiptVo>> getReceiptList(String receiptType, String receiptStatus, String smsContent, String startDate, String endDate, String openid, int pageNum, int pageSize) {
|
|
|
+ ReceiptParamsBo paramsBo = new ReceiptParamsBo();
|
|
|
+ // 获取该收款用户下的机构userIds
|
|
|
+ List<Integer> clubUserIds = getReceiptClubUserIds(openid, receiptStatus);
|
|
|
+ paramsBo.setUserIds(clubUserIds);
|
|
|
+ if (StringUtils.isNotBlank(smsContent)) {
|
|
|
+ // 短信内容隐藏余额
|
|
|
+ String message = hiddenBalance(smsContent);
|
|
|
+ paramsBo.setSmsMd5Code(Md5Util.md5(message));
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(receiptStatus)) {
|
|
|
+ String[] receiptStatusList = null;
|
|
|
+ if ("1".equals(receiptStatus)) {
|
|
|
+ receiptStatusList = "1,4,5".split(",");
|
|
|
+ } else {
|
|
|
+ receiptStatusList = receiptStatus.split(",");
|
|
|
+ }
|
|
|
+ paramsBo.setReceiptStatus(receiptStatus);
|
|
|
+ paramsBo.setReceiptStatusList(receiptStatusList);
|
|
|
+ }
|
|
|
+ // 分页请求数据
|
|
|
+ PageHelper.startPage(pageNum, pageSize);
|
|
|
+ List<ReceiptVo> list = receiptMapper.getReceiptList(paramsBo);
|
|
|
+ PageInfo<ReceiptVo> pageInfo = new PageInfo(list);
|
|
|
+ return ResponseJson.success(pageInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取该收款用户下的机构userIds
|
|
|
+ *
|
|
|
+ * @param openid 微信openid
|
|
|
+ * @param receiptStatus 收款状态:1待确认、2已确认(待审核)、3审核通过、4审核未通过、5收款撤销【线上支付成功为审核通过】
|
|
|
+ */
|
|
|
+ private List<Integer> getReceiptClubUserIds(String openid, String receiptStatus) {
|
|
|
+ // 收款用户
|
|
|
+ ReceiptUserVo receiptUser = receiptMapper.getReceiptUserByOpenid(openid);
|
|
|
+ List<Integer> userIds = null;
|
|
|
+ Integer userType = null;
|
|
|
+ String logTxt = "";
|
|
|
+ if (null != receiptUser) {
|
|
|
+ //用户类型:1协销人员,2客服,3财务,4超级管理员
|
|
|
+ userType = receiptUser.getUserType();
|
|
|
+ if (1 == userType) {
|
|
|
+ // 协销人员
|
|
|
+ Integer spId = receiptMapper.getServiceProviderId(receiptUser.getUnionId());
|
|
|
+ userIds = receiptMapper.getClubUserIdBySpId(spId);
|
|
|
+ logTxt = "协销";
|
|
|
+ } else if (2 == userType) {
|
|
|
+ // 客服,默认协销id:1342
|
|
|
+ userIds = receiptMapper.getClubUserIdBySpId(1342);
|
|
|
+ Integer spId = receiptMapper.getServiceProviderId(receiptUser.getUnionId());
|
|
|
+ if (null != spId && spId > 0) {
|
|
|
+ userIds.addAll(receiptMapper.getClubUserIdBySpId(1342));
|
|
|
+ }
|
|
|
+ logTxt = "客服";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (null == userIds && null != userType && 4 != userType) {
|
|
|
+ userIds = new ArrayList<>();
|
|
|
+ userIds.add(0);
|
|
|
+ }
|
|
|
+ if (null != userType && 2 == userType && "2".equals(receiptStatus)) {
|
|
|
+ // 客服可以查看所有待审核收款
|
|
|
+ userIds = null;
|
|
|
+ }
|
|
|
+ log.info("用户身份:" + logTxt + ">>>用户类型:" + userType + ">>>userIds:" + userIds);
|
|
|
+ return userIds;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 检查收款权限
|
|
|
- * @param permission
|
|
|
- * @param openid
|
|
|
- * @return
|
|
|
*/
|
|
|
private ReceiptUserVo checkPermissions(Integer permission, String openid) {
|
|
|
// 收款用户
|
|
@@ -428,14 +521,14 @@ public class ReceiptServiceImpl implements ReceiptService {
|
|
|
* 以下方法按照短信采样结果实现(新增短信不兼容)
|
|
|
*
|
|
|
* @param message 收款短信
|
|
|
- * 贵公司尾号7297的账户5月23日15时30分往来款收入人民币1800.00元,余额7055.50元。对方户名:哈尔滨爱丽达医疗美容管理有限公司爱建医疗美容诊所。[建设银行]
|
|
|
- * 【广发银行】尊敬的客户,贵司账号后四位0115 的账户于08日13:55收入一笔方芳尾数为8067的账户转账1850.00元,手续费0.00元。账户余额:1000000.00元。
|
|
|
- * 【广发银行】您末四位为0115的企业账户于12日16:09收入人民币5000.00元(深圳同城)。账户余额:8907.21元。
|
|
|
- * 【中信银行】贵公司尾号7172的中信账号于03月15日17:25,二代支付存入人民币3132.30元,当前余额为人民币4373.07元。
|
|
|
- * 【中信银行】您尾号0897的中信卡于03月06日11:44,存入人民币2358.00元,当前余额为人民币1000000.00元。
|
|
|
- * 【中信银行】您尾号0897的中信卡于03月19日13:37,财付通快捷支付存入人民币11348.45元,当前余额为人民币1000000.00元。
|
|
|
- * 【中信银行】您尾号0897的中信卡于03月14日16:01,支付宝存入人民币5994.06元,当前余额为人民币1000000.00元。
|
|
|
- * 【中信银行】您尾号0897的中信卡于05月29日14:42,二代支付存入人民币10000.00元,当前余额为人民币13871.67元。
|
|
|
+ * 贵公司尾号7297的账户5月23日15时30分往来款收入人民币1800.00元,余额7055.50元。对方户名:哈尔滨爱丽达医疗美容管理有限公司爱建医疗美容诊所。[建设银行]
|
|
|
+ * 【广发银行】尊敬的客户,贵司账号后四位0115 的账户于08日13:55收入一笔方芳尾数为8067的账户转账1850.00元,手续费0.00元。账户余额:1000000.00元。
|
|
|
+ * 【广发银行】您末四位为0115的企业账户于12日16:09收入人民币5000.00元(深圳同城)。账户余额:8907.21元。
|
|
|
+ * 【中信银行】贵公司尾号7172的中信账号于03月15日17:25,二代支付存入人民币3132.30元,当前余额为人民币4373.07元。
|
|
|
+ * 【中信银行】您尾号0897的中信卡于03月06日11:44,存入人民币2358.00元,当前余额为人民币1000000.00元。
|
|
|
+ * 【中信银行】您尾号0897的中信卡于03月19日13:37,财付通快捷支付存入人民币11348.45元,当前余额为人民币1000000.00元。
|
|
|
+ * 【中信银行】您尾号0897的中信卡于03月14日16:01,支付宝存入人民币5994.06元,当前余额为人民币1000000.00元。
|
|
|
+ * 【中信银行】您尾号0897的中信卡于05月29日14:42,二代支付存入人民币10000.00元,当前余额为人民币13871.67元。
|
|
|
*/
|
|
|
private ResponseJson<ReceiptVo> identifyMessage(String message) throws Exception {
|
|
|
if (message.contains("银行")) {
|
|
@@ -462,7 +555,7 @@ public class ReceiptServiceImpl implements ReceiptService {
|
|
|
if (message.contains("支付宝")) {
|
|
|
receivableDesc += "-支付宝";
|
|
|
}
|
|
|
- }else if (receivableDesc.contains("广发银行") || receivableDesc.contains("建设银行")) {
|
|
|
+ } else if (receivableDesc.contains("广发银行") || receivableDesc.contains("建设银行")) {
|
|
|
// 匹配的第一组数字为银行卡尾号
|
|
|
Matcher matcherBank = PATTERN_NUMBER.matcher(message);
|
|
|
if (matcherBank.find()) {
|
|
@@ -482,7 +575,7 @@ public class ReceiptServiceImpl implements ReceiptService {
|
|
|
contentTime.add(group);
|
|
|
}
|
|
|
// 建设银行
|
|
|
- if (Arrays.asList(1, 18, 19).contains(typeId)){
|
|
|
+ if (Arrays.asList(1, 18, 19).contains(typeId)) {
|
|
|
time = year + "-" + contentTime.get(1) + "-" + contentTime.get(2) + " " + contentTime.get(3) + ":" + contentTime.get(4) + ":" + "00";
|
|
|
int difference = DateUtils.differentDays(time);
|
|
|
if (difference < 0) {
|
|
@@ -490,7 +583,7 @@ public class ReceiptServiceImpl implements ReceiptService {
|
|
|
}
|
|
|
}
|
|
|
// 广发银行
|
|
|
- else if (Arrays.asList(2, 11).contains(typeId)){
|
|
|
+ else if (Arrays.asList(2, 11).contains(typeId)) {
|
|
|
time = year + "-" + month + "-" + contentTime.get(1) + " " + contentTime.get(2) + ":" + "00";
|
|
|
int difference = DateUtils.differentDays(time);
|
|
|
/* 差距大于30天 减一年, 小于30天 减一个月 */
|
|
@@ -584,7 +677,7 @@ public class ReceiptServiceImpl implements ReceiptService {
|
|
|
*/
|
|
|
private ReceiptVo getReceiptByMd5Msg(String md5Msg) {
|
|
|
List<ReceiptVo> receiptList = receiptMapper.getReceiptBySmsMd5Code(md5Msg);
|
|
|
- if (!CollectionUtils.isEmpty(receiptList)){
|
|
|
+ if (!CollectionUtils.isEmpty(receiptList)) {
|
|
|
receiptList.get(0).setHaveFee(tipFeeType.contains(receiptList.get(0).getPayType()));
|
|
|
return receiptList.get(0);
|
|
|
}
|
|
@@ -593,8 +686,9 @@ public class ReceiptServiceImpl implements ReceiptService {
|
|
|
|
|
|
/**
|
|
|
* 获取未支付金额
|
|
|
+ *
|
|
|
* @param order 订单
|
|
|
- * @param flag (true:计算未审核金额,false:不计算)
|
|
|
+ * @param flag (true:计算未审核金额,false:不计算)
|
|
|
*/
|
|
|
private Double getUnPayMoney(OrderVo order, Boolean flag) {
|
|
|
Double unPayMoney = order.getPayableAmount();
|
|
@@ -607,7 +701,8 @@ public class ReceiptServiceImpl implements ReceiptService {
|
|
|
|
|
|
/**
|
|
|
* 计算已收金额(审核通过金额+(待审核金额))//展示的时候需要加待审核金额 实际计算不需要计算
|
|
|
- * @param order 订单
|
|
|
+ *
|
|
|
+ * @param order 订单
|
|
|
* @param isCountUncheckAmount 是否计算未审核金额
|
|
|
*/
|
|
|
private Double getReceivedAmount(OrderVo order, Boolean isCountUncheckAmount) {
|
|
@@ -637,6 +732,7 @@ public class ReceiptServiceImpl implements ReceiptService {
|
|
|
|
|
|
/**
|
|
|
* 获取退货退款价值(需计算经理折扣存在的情况)(此金额不是指退给用户的金额)
|
|
|
+ *
|
|
|
* @param order 订单
|
|
|
*/
|
|
|
private Double getReturnValue(OrderVo order) {
|