|
@@ -5,15 +5,26 @@ import java.util.Collections;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
import com.fs.common.core.domain.R;
|
|
import com.fs.common.core.domain.R;
|
|
import com.fs.common.utils.DateUtils;
|
|
import com.fs.common.utils.DateUtils;
|
|
|
|
+import com.fs.company.domain.Company;
|
|
|
|
+import com.fs.company.domain.CompanyMoneyLogs;
|
|
|
|
+import com.fs.company.mapper.CompanyMapper;
|
|
|
|
+import com.fs.company.mapper.CompanyMoneyLogsMapper;
|
|
import com.fs.course.param.FsCourseRedPacketLogParam;
|
|
import com.fs.course.param.FsCourseRedPacketLogParam;
|
|
import com.fs.course.vo.FsCourseRedPacketLogListPVO;
|
|
import com.fs.course.vo.FsCourseRedPacketLogListPVO;
|
|
|
|
+import com.fs.his.domain.FsUser;
|
|
|
|
+import com.fs.his.mapper.FsUserMapper;
|
|
|
|
+import com.fs.his.param.WxSendRedPacketParam;
|
|
|
|
+import com.fs.his.service.IFsStorePaymentService;
|
|
|
|
+import com.github.binarywang.wxpay.bean.transfer.TransferBillsResult;
|
|
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.course.mapper.FsCourseRedPacketLogMapper;
|
|
import com.fs.course.mapper.FsCourseRedPacketLogMapper;
|
|
import com.fs.course.domain.FsCourseRedPacketLog;
|
|
import com.fs.course.domain.FsCourseRedPacketLog;
|
|
import com.fs.course.service.IFsCourseRedPacketLogService;
|
|
import com.fs.course.service.IFsCourseRedPacketLogService;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 短链课程看课记录Service业务层处理
|
|
* 短链课程看课记录Service业务层处理
|
|
@@ -146,5 +157,72 @@ public class FsCourseRedPacketLogServiceImpl implements IFsCourseRedPacketLogSer
|
|
public BigDecimal getNewVipRedPackAmountByCompanyUserIdId(Long companyUserId) {
|
|
public BigDecimal getNewVipRedPackAmountByCompanyUserIdId(Long companyUserId) {
|
|
return fsCourseRedPacketLogMapper.getNewVipRedPackAmountByCompanyUserIdId(companyUserId);
|
|
return fsCourseRedPacketLogMapper.getNewVipRedPackAmountByCompanyUserIdId(companyUserId);
|
|
}
|
|
}
|
|
|
|
+ @Autowired
|
|
|
|
+ private IFsStorePaymentService paymentService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private FsUserMapper fsUserMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private CompanyMapper companyMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private CompanyMoneyLogsMapper moneyLogsMapper;
|
|
|
|
+ @Override
|
|
|
|
+ @Transactional
|
|
|
|
+ public int retryCourseRedPacketLog(Long[] logIds) {
|
|
|
|
+ for (int i = 0; i < logIds.length; i++) {
|
|
|
|
+ Long id = logIds[i];
|
|
|
|
+ FsCourseRedPacketLog param = fsCourseRedPacketLogMapper.selectFsCourseRedPacketLogByLogId(id);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if (param!=null&¶m.getStatus()==2){
|
|
|
|
+ Company company = companyMapper.selectCompanyByIdForUpdate(param.getCompanyId());
|
|
|
|
+ BigDecimal amount = param.getAmount();
|
|
|
|
+ BigDecimal money = company.getMoney();
|
|
|
|
+ BigDecimal subtract = money.subtract(amount);
|
|
|
|
+ if (subtract.compareTo(BigDecimal.ZERO)<0){
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ WxSendRedPacketParam packetParam = new WxSendRedPacketParam();
|
|
|
|
+ FsUser user = fsUserMapper.selectFsUserByUserId(param.getUserId());
|
|
|
|
+ packetParam.setOpenId(user.getMaOpenId());
|
|
|
|
+ packetParam.setOpenId(user.getCourseMaOpenId());
|
|
|
|
+ packetParam.setAmount(param.getAmount());
|
|
|
|
+ packetParam.setSource(2);
|
|
|
|
+ packetParam.setRedPacketMode(1);
|
|
|
|
+ packetParam.setCompanyId(param.getCompanyId());
|
|
|
|
+ R sendRedPacket = paymentService.sendRedPacket(packetParam);
|
|
|
|
+ if (sendRedPacket.get("code").equals(200)) {
|
|
|
|
+ FsCourseRedPacketLog redPacketLog = new FsCourseRedPacketLog();
|
|
|
|
+ TransferBillsResult transferBillsResult;
|
|
|
|
+ if (sendRedPacket.get("isNew").equals(1)){
|
|
|
|
+ transferBillsResult = (TransferBillsResult)sendRedPacket.get("data");
|
|
|
|
+ redPacketLog.setResult(JSON.toJSONString(sendRedPacket));
|
|
|
|
+ redPacketLog.setOutBatchNo(transferBillsResult.getOutBillNo());
|
|
|
|
+ }else {
|
|
|
|
+ redPacketLog.setOutBatchNo(sendRedPacket.get("orderCode").toString());
|
|
|
|
+ }
|
|
|
|
+ // 添加红包记录
|
|
|
|
+ redPacketLog.setStatus(0);
|
|
|
|
+ fsCourseRedPacketLogMapper.updateFsCourseRedPacketLog(redPacketLog);
|
|
|
|
+ // 更新观看记录的奖励类型
|
|
|
|
+
|
|
|
|
+ company.setMoney(subtract);
|
|
|
|
+ companyMapper.updateCompany(company);
|
|
|
|
+
|
|
|
|
+ CompanyMoneyLogs logs=new CompanyMoneyLogs();
|
|
|
|
+ logs.setCompanyId(company.getCompanyId());
|
|
|
|
+ logs.setRemark("扣除红包金额");
|
|
|
|
+ logs.setMoney(amount.multiply(new BigDecimal(-1)));
|
|
|
|
+ logs.setLogsType(15);
|
|
|
|
+ logs.setBalance(company.getMoney());
|
|
|
|
+ logs.setCreateTime(new Date());
|
|
|
|
+ moneyLogsMapper.insertCompanyMoneyLogs(logs);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
|
|
}
|
|
}
|