|
@@ -1,23 +1,45 @@
|
|
|
package com.miaxis.wx.service.impl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.github.wxpay.sdk.WXPay;
|
|
|
+import com.github.wxpay.sdk.WXPayConfig;
|
|
|
+import com.github.wxpay.sdk.WXPayConstants;
|
|
|
+import com.github.wxpay.sdk.WXPayUtil;
|
|
|
+import com.miaxis.common.config.WxPayConfigImpl;
|
|
|
+import com.miaxis.common.config.WxpayConfig;
|
|
|
import com.miaxis.common.core.domain.entity.UserInfo;
|
|
|
import com.miaxis.common.enums.OrderStatusEnum;
|
|
|
+import com.miaxis.common.exception.CustomException;
|
|
|
+import com.miaxis.common.utils.RSAUtils;
|
|
|
import com.miaxis.common.utils.SecurityUtils;
|
|
|
+import com.miaxis.common.utils.XmlUtil;
|
|
|
import com.miaxis.system.service.ISysConfigService;
|
|
|
import com.miaxis.user.service.IUserInfoService;
|
|
|
+import com.miaxis.wx.domain.WxExtract;
|
|
|
+import com.miaxis.wx.domain.WxExtractBank;
|
|
|
import com.miaxis.wx.domain.WxOrder;
|
|
|
import com.miaxis.wx.dto.PcWxOrderListDTO;
|
|
|
import com.miaxis.wx.dto.QuerySchoolOrderListDTO;
|
|
|
+import com.miaxis.wx.dto.WxExtractBankDTO;
|
|
|
import com.miaxis.wx.mapper.WxOrderMapper;
|
|
|
-import com.miaxis.wx.service.IRefundRecordService;
|
|
|
+import com.miaxis.wx.service.IWxExtractBankService;
|
|
|
+import com.miaxis.wx.service.IWxExtractService;
|
|
|
import com.miaxis.wx.service.IWxOrderService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.RandomStringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.TreeMap;
|
|
|
+
|
|
|
+import static com.miaxis.common.utils.OrderCodeFactory.getOrderCode;
|
|
|
|
|
|
/**
|
|
|
* 电影订单Service业务层处理
|
|
@@ -31,29 +53,45 @@ public class WxOrderServiceImpl extends ServiceImpl<WxOrderMapper, WxOrder> impl
|
|
|
@Resource
|
|
|
private WxOrderMapper wxOrderMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IWxExtractService wxExtractService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private RSAUtils rsaUtils;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private WxpayConfig wxpayConfig;
|
|
|
@Autowired
|
|
|
private ISysConfigService configService;
|
|
|
|
|
|
@Autowired
|
|
|
private IUserInfoService userInfoService;
|
|
|
+ @Autowired
|
|
|
+ private IWxExtractBankService wxExtractBankService;
|
|
|
|
|
|
+ @Value("${zzgzh.appid}")
|
|
|
+ private String appid;
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public void createVipOrder(WxOrder wxOrder) {
|
|
|
+ public void createVipOrder(WxOrder wxOrder, Integer type) {
|
|
|
String price = null ;
|
|
|
+ if (type == 1){
|
|
|
+ price = configService.selectConfigByKey("vip_price");
|
|
|
+ }
|
|
|
UserInfo student = SecurityUtils.getLoginUser().getStudent();
|
|
|
UserInfo userInfo = userInfoService.getById(student.getId());
|
|
|
- if (userInfo.getBindRecommendCode()!=null){
|
|
|
- price = configService.selectConfigByKey("vip_price_recommend");
|
|
|
- }else{
|
|
|
- if (wxOrder.getReferralUserId() == null){
|
|
|
- price = configService.selectConfigByKey("vip_price");
|
|
|
- }else {
|
|
|
- price = configService.selectConfigByKey("vip_price_referral");
|
|
|
+ if (type == 2){
|
|
|
+ if (userInfo.getBindRecommendCode()!=null){
|
|
|
+ price = configService.selectConfigByKey("vip_price_recommend");
|
|
|
+ }else{
|
|
|
+ throw new CustomException("该学员未绑定推荐码,不能使用此套餐");
|
|
|
}
|
|
|
}
|
|
|
+ if (type == 3){
|
|
|
+ price = configService.selectConfigByKey("vip_price_upgrade");
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
Double dprice = Double.valueOf(price);
|
|
|
Double v =dprice* 100;
|
|
@@ -76,5 +114,116 @@ public class WxOrderServiceImpl extends ServiceImpl<WxOrderMapper, WxOrder> impl
|
|
|
return wxOrderMapper.QuerySchoolOrderList(dto);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public String wxwithdrawal(Integer amount) throws Exception {
|
|
|
+ UserInfo student = SecurityUtils.getLoginUser().getStudent();
|
|
|
+ UserInfo dbUserInfo = userInfoService.getById(student.getId());
|
|
|
+ if (dbUserInfo.getProfitPrice() < amount){
|
|
|
+ throw new CustomException("提现金额不能大于可提现金额");
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, String> sortMap = new TreeMap<String, String>();
|
|
|
+ sortMap.put("mch_appid",appid);
|
|
|
+ sortMap.put("mchid",wxpayConfig.getMerchantId());
|
|
|
+ sortMap.put("nonce_str", RandomStringUtils.randomAlphanumeric(32));
|
|
|
+ sortMap.put("partner_trade_no",getOrderCode(null));
|
|
|
+ sortMap.put("openid",student.getGzhOpenid());
|
|
|
+ sortMap.put("check_name","NO_CHECK");
|
|
|
+ sortMap.put("amount",String.valueOf(amount));
|
|
|
+ sortMap.put("desc","用户提现");
|
|
|
+
|
|
|
+ WXPayConfig config = new WxPayConfigImpl();
|
|
|
+ String sign = WXPayUtil.generateSignature(sortMap, config.getKey(), WXPayConstants.SignType.MD5);
|
|
|
+ sortMap.put("sign", sign);
|
|
|
+ WXPay pay = new WXPay(config);
|
|
|
+
|
|
|
+ String url = "https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers";
|
|
|
+ Map<String, String> resMap;
|
|
|
+ String xmlStr = pay.requestWithCert(url, sortMap, config.getHttpConnectTimeoutMs(), config.getHttpReadTimeoutMs());
|
|
|
+ resMap = XmlUtil.xmlToMap(xmlStr);
|
|
|
+ if (!"SUCCESS".equals(resMap.get("return_code"))||!"SUCCESS".equals(resMap.get("result_code"))){
|
|
|
+ throw new CustomException(resMap.get("return_msg"));
|
|
|
+ }
|
|
|
+ //新增提现记录
|
|
|
+ WxExtract wxExtract = new WxExtract();
|
|
|
+ wxExtract.setOpenid(student.getGzhOpenid());
|
|
|
+ wxExtract.setExtractPrice(amount);
|
|
|
+ wxExtract.setPartnerTradeNo(resMap.get("partner_trade_no"));
|
|
|
+ wxExtract.setStatus("1");
|
|
|
+ wxExtractService.save(wxExtract);
|
|
|
+
|
|
|
+ //更新余额
|
|
|
+ dbUserInfo.setProfitPrice(dbUserInfo.getProfitPrice()-amount);
|
|
|
+ userInfoService.updateById(dbUserInfo);
|
|
|
+
|
|
|
+ return resMap.get("return_msg");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public String wxwithbankdrawal(WxExtractBankDTO dto) throws Exception {
|
|
|
+ UserInfo student = SecurityUtils.getLoginUser().getStudent();
|
|
|
+ UserInfo dbUserInfo = userInfoService.getById(student.getId());
|
|
|
+ if (dbUserInfo.getProfitPrice() < dto.getAmount()){
|
|
|
+ throw new CustomException("提现金额不能大于可提现金额");
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, String> sortMap = new TreeMap<String, String>();
|
|
|
+ sortMap.put("mch_id",wxpayConfig.getMerchantId());
|
|
|
+ sortMap.put("nonce_str", RandomStringUtils.randomAlphanumeric(32));
|
|
|
+ sortMap.put("partner_trade_no",getOrderCode(null));
|
|
|
+ sortMap.put("amount",String.valueOf(dto.getAmount()));
|
|
|
+ sortMap.put("desc","用户银行卡提现");
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // 进行签名服务
|
|
|
+
|
|
|
+ sortMap.put("enc_true_name",rsaUtils.encryptData(dto.getEncTrueName()) );
|
|
|
+ sortMap.put("enc_bank_no",rsaUtils.encryptData(dto.getEncBankNo()));
|
|
|
+ sortMap.put("bank_code",dto.getBankCode().toString());
|
|
|
+
|
|
|
+
|
|
|
+ WXPayConfig config = new WxPayConfigImpl();
|
|
|
+ String sign = WXPayUtil.generateSignature(sortMap, config.getKey(), WXPayConstants.SignType.MD5);
|
|
|
+ sortMap.put("sign", sign);
|
|
|
+ WXPay pay = new WXPay(config);
|
|
|
+
|
|
|
+ String url = "https://api.mch.weixin.qq.com/mmpaysptrans/pay_bank";
|
|
|
+ Map<String, String> resMap;
|
|
|
+ String xmlStr = pay.requestWithCert(url, sortMap, config.getHttpConnectTimeoutMs(), config.getHttpReadTimeoutMs());
|
|
|
+ resMap = XmlUtil.xmlToMap(xmlStr);
|
|
|
+ if (!"SUCCESS".equals(resMap.get("return_code"))||!"SUCCESS".equals(resMap.get("result_code"))){
|
|
|
+ throw new CustomException(resMap.get("return_msg"));
|
|
|
+ }
|
|
|
+ //新增提现记录
|
|
|
+ WxExtract wxExtract = new WxExtract();
|
|
|
+ wxExtract.setOpenid(student.getGzhOpenid());
|
|
|
+ wxExtract.setExtractPrice(dto.getAmount());
|
|
|
+ wxExtract.setPartnerTradeNo(resMap.get("partner_trade_no"));
|
|
|
+ wxExtract.setStatus("1");
|
|
|
+ wxExtractService.save(wxExtract);
|
|
|
+
|
|
|
+ //如果此卡之前未存储,则加入到银行卡列表
|
|
|
+ List<WxExtractBank> bankList = wxExtractBankService.list(new QueryWrapper<WxExtractBank>().eq("enc_bank_no", dto.getEncBankNo()));
|
|
|
+ if (CollectionUtils.isEmpty(bankList)){
|
|
|
+ WxExtractBank wxExtractBank = new WxExtractBank();
|
|
|
+ wxExtractBank.setBankCode(dto.getBankCode());
|
|
|
+ wxExtractBank.setEncBankNo(dto.getEncBankNo());
|
|
|
+ wxExtractBank.setEncTrueName(dto.getEncTrueName());
|
|
|
+ wxExtractBank.setOpenid(SecurityUtils.getLoginUser().getStudent().getGzhOpenid());
|
|
|
+ wxExtractBankService.save(wxExtractBank);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //更新余额
|
|
|
+ dbUserInfo.setProfitPrice(dbUserInfo.getProfitPrice()-dto.getAmount());
|
|
|
+ userInfoService.updateById(dbUserInfo);
|
|
|
+
|
|
|
+ return resMap.get("return_msg");
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|