|
|
@@ -1,19 +1,34 @@
|
|
|
package com.poteviohealth.ym.ipos.service.impl;
|
|
|
|
|
|
+import cn.binarywang.wx.miniapp.api.WxMaService;
|
|
|
+import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
import com.poteviohealth.cgp.common.filter.TokenContext;
|
|
|
+import com.poteviohealth.cgp.common.integrated.EntityIdParams;
|
|
|
+import com.poteviohealth.cgp.common.integrated.partner.PartnerFeignClient;
|
|
|
+import com.poteviohealth.cgp.common.integrated.partner.model.OperatorDTO;
|
|
|
import com.poteviohealth.cgp.common.model.CommonPage;
|
|
|
+import com.poteviohealth.cgp.common.model.VaultsResponse;
|
|
|
import com.poteviohealth.cgp.common.utils.MyBatisConvertUtils;
|
|
|
import com.poteviohealth.ym.ipos.mapper.SplitWithdrawMapper;
|
|
|
import com.poteviohealth.ym.ipos.model.split.SplitWithdraw;
|
|
|
import com.poteviohealth.ym.ipos.model.split.dto.SplitWithdrawDto;
|
|
|
import com.poteviohealth.ym.ipos.service.ISplitWithdrawService;
|
|
|
+import com.poteviohealth.ym.ipos.utils.WechatServiceApi;
|
|
|
+import me.chanjar.weixin.common.error.WxErrorException;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
+import org.apache.commons.lang3.time.DateFormatUtils;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
/**
|
|
|
* 分账提现记录
|
|
|
* @author Qin
|
|
|
@@ -23,6 +38,8 @@ public class SplitWithdrawServiceImpl extends ServiceImpl<SplitWithdrawMapper, S
|
|
|
|
|
|
@Value("${sync.dbName}")
|
|
|
private String dbName;
|
|
|
+ @Resource
|
|
|
+ private PartnerFeignClient partnerFeignClient;
|
|
|
@Override
|
|
|
public CommonPage<SplitWithdraw> pageList(SplitWithdrawDto dto) {
|
|
|
Page<SplitWithdraw> page = MyBatisConvertUtils.convert2Page(dto);
|
|
|
@@ -60,8 +77,84 @@ public class SplitWithdrawServiceImpl extends ServiceImpl<SplitWithdrawMapper, S
|
|
|
baseMapper.updateWithdrawSuccess(operatorId,dbName,withdrawId);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void successSend(SplitWithdraw splitWithdraw) {
|
|
|
+ try {
|
|
|
+ WxMaService service = this.getWechatService(splitWithdraw.getOperatorId());
|
|
|
+ WxMaSubscribeMessage message = new WxMaSubscribeMessage();
|
|
|
+ //接收者(用户)的 openid.
|
|
|
+ message.setToUser(splitWithdraw.getOpenid());
|
|
|
+ //所需下发的模板消息的id
|
|
|
+ message.setTemplateId("FVqI5DhBzQiCm5TAssmhASRFe9YKioW_MFllqQQ_m_k");
|
|
|
+ List<WxMaSubscribeMessage.MsgData> dataList = Lists.newArrayList();
|
|
|
+ WxMaSubscribeMessage.MsgData data = new WxMaSubscribeMessage.MsgData();
|
|
|
+ data.setName("提现金额");
|
|
|
+ data.setValue(new BigDecimal(splitWithdraw.getAmount()).divide(new BigDecimal(100),2,BigDecimal.ROUND_HALF_UP).toString()+"元");
|
|
|
+ dataList.add(data);
|
|
|
+ WxMaSubscribeMessage.MsgData data1 = new WxMaSubscribeMessage.MsgData();
|
|
|
+ data1.setName("审核结果");
|
|
|
+ data1.setValue("已通过");
|
|
|
+ dataList.add(data1);
|
|
|
+ WxMaSubscribeMessage.MsgData data3 = new WxMaSubscribeMessage.MsgData();
|
|
|
+ data3.setName("审核时间");
|
|
|
+ data3.setValue(DateFormatUtils.format(new Date(),"yyyy-MM-dd HH:mm:ss"));
|
|
|
+ dataList.add(data3);
|
|
|
+ //模板内容,不填则下发空模板.
|
|
|
+ message.setData(dataList);
|
|
|
+ service.getSubscribeService().sendSubscribeMsg(message);
|
|
|
+ } catch (WxErrorException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public void withdrawFail(Integer operatorId, Integer withdrawId) {
|
|
|
baseMapper.updateWithdrawFail(operatorId,dbName,withdrawId);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void failSend(SplitWithdraw splitWithdraw) {
|
|
|
+ try {
|
|
|
+ WxMaService service = this.getWechatService(splitWithdraw.getOperatorId());
|
|
|
+ WxMaSubscribeMessage message = new WxMaSubscribeMessage();
|
|
|
+ //接收者(用户)的 openid.
|
|
|
+ message.setToUser(splitWithdraw.getOpenid());
|
|
|
+ //所需下发的模板消息的id
|
|
|
+ message.setTemplateId("FVqI5DhBzQiCm5TAssmhASRFe9YKioW_MFllqQQ_m_k");
|
|
|
+ List<WxMaSubscribeMessage.MsgData> dataList = Lists.newArrayList();
|
|
|
+ WxMaSubscribeMessage.MsgData data = new WxMaSubscribeMessage.MsgData();
|
|
|
+ data.setName("提现金额");
|
|
|
+ data.setValue(new BigDecimal(splitWithdraw.getAmount()).divide(new BigDecimal(100),2,BigDecimal.ROUND_HALF_UP).toString()+"元");
|
|
|
+ dataList.add(data);
|
|
|
+ WxMaSubscribeMessage.MsgData data1 = new WxMaSubscribeMessage.MsgData();
|
|
|
+ data1.setName("审核结果");
|
|
|
+ data1.setValue("已驳回");
|
|
|
+ dataList.add(data1);
|
|
|
+ WxMaSubscribeMessage.MsgData data2 = new WxMaSubscribeMessage.MsgData();
|
|
|
+ data2.setName("驳回原因");
|
|
|
+ data2.setValue(splitWithdraw.getErrorMsg());
|
|
|
+ dataList.add(data2);
|
|
|
+ WxMaSubscribeMessage.MsgData data3 = new WxMaSubscribeMessage.MsgData();
|
|
|
+ data3.setName("审核时间");
|
|
|
+ data3.setValue(DateFormatUtils.format(new Date(),"yyyy-MM-dd HH:mm:ss"));
|
|
|
+ dataList.add(data3);
|
|
|
+ //模板内容,不填则下发空模板.
|
|
|
+ message.setData(dataList);
|
|
|
+ service.getSubscribeService().sendSubscribeMsg(message);
|
|
|
+ } catch (WxErrorException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private WxMaService getWechatService (Integer operationId){
|
|
|
+ WxMaService service = WechatServiceApi.getInstance(operationId);
|
|
|
+ if (service == null){
|
|
|
+ EntityIdParams entityIdParams = new EntityIdParams();
|
|
|
+ entityIdParams.setId(operationId);
|
|
|
+ VaultsResponse<OperatorDTO> vaultsResponse = partnerFeignClient.getOperator(entityIdParams);
|
|
|
+ OperatorDTO dto = vaultsResponse.getData();
|
|
|
+ service = WechatServiceApi.initInstance(dto.getId(), dto.getAppId(), dto.getAppSecret());
|
|
|
+ }
|
|
|
+ return service;
|
|
|
+ }
|
|
|
}
|