|
|
@@ -5,14 +5,13 @@ import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
-import shop.alien.entity.store.StoreAliPayLog;
|
|
|
-import shop.alien.entity.store.StoreCashOutRecord;
|
|
|
-import shop.alien.entity.store.StoreIncomeDetailsRecord;
|
|
|
-import shop.alien.entity.store.StoreUser;
|
|
|
+import shop.alien.entity.store.*;
|
|
|
import shop.alien.entity.store.vo.StoreIncomeDetailsRecordVo;
|
|
|
import shop.alien.mapper.StoreCashOutRecordMapper;
|
|
|
import shop.alien.mapper.StoreIncomeDetailsRecordMapper;
|
|
|
@@ -50,6 +49,7 @@ public class StoreIncomeDetailsRecordServiceImpl extends ServiceImpl<StoreIncome
|
|
|
|
|
|
private final StoreIncomeDetailsRecordMapper storeIncomeDetailsRecordMapper;
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 提现-提现全部-手续费一单一算
|
|
|
*
|
|
|
@@ -119,6 +119,109 @@ public class StoreIncomeDetailsRecordServiceImpl extends ServiceImpl<StoreIncome
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 提现申请-提现全部-手续费一单一算
|
|
|
+ *
|
|
|
+ * @param storeId 门店id
|
|
|
+ * @return 是否成功
|
|
|
+ */
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public String applyCashOut(Integer storeId, String payPassword) {
|
|
|
+ StoreUser storeUser = storeUserMapper.selectOne(new LambdaQueryWrapper<StoreUser>().eq(StoreUser::getStoreId, storeId).eq(StoreUser::getPayPassword, payPassword));
|
|
|
+ if (storeUser != null) {
|
|
|
+ //查询可用账单(大于创建时间3天)
|
|
|
+ LambdaQueryWrapper<StoreIncomeDetailsRecord> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ //当前时间-3天大于创建时间
|
|
|
+ wrapper.lt(StoreIncomeDetailsRecord::getCreatedTime, DateUtils.calcDays(new Date(), -3))
|
|
|
+ //未绑定提现记录的
|
|
|
+ .isNull(StoreIncomeDetailsRecord::getCashOutId).eq(StoreIncomeDetailsRecord::getStoreId, storeId);
|
|
|
+ List<StoreIncomeDetailsRecord> list = this.list(wrapper);
|
|
|
+ if (!list.isEmpty()) {
|
|
|
+ //总金额
|
|
|
+ Integer availableAmount = 0;
|
|
|
+ //手续费
|
|
|
+ Integer commission = 0;
|
|
|
+ for (StoreIncomeDetailsRecord record : list) {
|
|
|
+ availableAmount += record.getMoney();
|
|
|
+ commission += record.getCommission();
|
|
|
+ }
|
|
|
+ int money = availableAmount - commission;
|
|
|
+ list = list.stream().sorted(Comparator.comparing(StoreIncomeDetailsRecord::getCreatedTime)).collect(Collectors.toList());
|
|
|
+ Date startDate = list.get(0).getCreatedTime();
|
|
|
+ Date endDate = list.get(list.size() - 1).getCreatedTime();
|
|
|
+ //增加提现申请记录
|
|
|
+ StoreCashOutRecord storeCashOutRecord = new StoreCashOutRecord();
|
|
|
+ storeCashOutRecord.setStoreId(storeId);
|
|
|
+ storeCashOutRecord.setMoney(money);
|
|
|
+ storeCashOutRecord.setCommission(commission);
|
|
|
+ storeCashOutRecord.setCashOutType(0);
|
|
|
+ storeCashOutRecord.setPaymentStatus(3);
|
|
|
+ storeCashOutRecord.setDeleteFlag(0);
|
|
|
+ storeCashOutRecord.setIncomeStartTime(startDate);
|
|
|
+ storeCashOutRecord.setIncomeEndTime(endDate);
|
|
|
+ storeCashOutRecord.setStoreUserId(storeUser.getId());
|
|
|
+ storeCashOutRecordMapper.insert(storeCashOutRecord);
|
|
|
+ //关联提现记录
|
|
|
+ list.forEach(record -> record.setCashOutId(storeCashOutRecord.getId()));
|
|
|
+ this.saveOrUpdateBatch(list);
|
|
|
+ return "申请成功";
|
|
|
+ }
|
|
|
+ return "账单未到可提现时间";
|
|
|
+ }
|
|
|
+ return "支付密码错误";
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public String approveCashOut(Integer cashOutId, String approveStatus, String failReason) {
|
|
|
+ if (cashOutId != null && cashOutId > 0 && StringUtils.isNotBlank(approveStatus)) {
|
|
|
+ StoreCashOutRecord storeCashOutRecord = storeCashOutRecordMapper.selectById(cashOutId);
|
|
|
+ if (approveStatus.equals("0")) {
|
|
|
+ //同意,开始提现
|
|
|
+ Integer storeUserId = storeCashOutRecord.getStoreUserId();
|
|
|
+ StoreUser storeUser = storeUserMapper.selectById(storeUserId);
|
|
|
+ int money = storeCashOutRecord.getMoney();
|
|
|
+ BigDecimal decimal = new BigDecimal(money);
|
|
|
+ BigDecimal divide = decimal.divide(new BigDecimal(100), 2, RoundingMode.HALF_UP);
|
|
|
+ if (Double.parseDouble(divide.toString()) < 0.10) {
|
|
|
+ return "金额不能小于0.1元";
|
|
|
+ }
|
|
|
+ // StoreAliPayLog pay = aliApi.pay(storeUser.getName(), storeUser.getIdCard(), storeUser.getPhone(), divide.toString());
|
|
|
+ StoreAliPayLog pay = new StoreAliPayLog();
|
|
|
+ if (pay != null) {
|
|
|
+ // 提现成功,更新提现申请相关状态
|
|
|
+ storeCashOutRecord.setOrderNo(pay.getOutBizNo());
|
|
|
+ storeCashOutRecord.setAliOrderNo(pay.getOrderId());
|
|
|
+ storeCashOutRecord.setPaymentStatus(1);//提现成功
|
|
|
+ storeCashOutRecord.setApproveTime(new Date());// 审批时间
|
|
|
+ storeCashOutRecord.setPayDate(new Date());//支付时间
|
|
|
+
|
|
|
+ //减少账户余额
|
|
|
+ storeUserMapper.updateById(new StoreUser(storeCashOutRecord.getStoreId(), storeUser.getMoney() - storeCashOutRecord.getMoney() - storeCashOutRecord.getCommission()));
|
|
|
+ } else {
|
|
|
+ // 提现失败
|
|
|
+ storeCashOutRecord.setPaymentStatus(2);
|
|
|
+ storeCashOutRecord.setApproveTime(new Date());// 审批时间
|
|
|
+ storeCashOutRecord.setFailReason("支付失败");
|
|
|
+ }
|
|
|
+ storeCashOutRecordMapper.updateById(storeCashOutRecord);
|
|
|
+ } else {
|
|
|
+ storeCashOutRecord.setPaymentStatus(4);
|
|
|
+ storeCashOutRecord.setFailReason(failReason);
|
|
|
+ storeCashOutRecordMapper.updateById(storeCashOutRecord);
|
|
|
+ // 拒绝将账单中的提现记录置空
|
|
|
+ LambdaUpdateWrapper<StoreIncomeDetailsRecord> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
|
|
+ lambdaUpdateWrapper.eq(StoreIncomeDetailsRecord::getStoreId, storeCashOutRecord.getStoreId())
|
|
|
+ .eq(StoreIncomeDetailsRecord::getCashOutId, storeCashOutRecord.getId())
|
|
|
+ .set(StoreIncomeDetailsRecord::getCashOutId, "");
|
|
|
+ int result = storeIncomeDetailsRecordMapper.updateByCashOutId(storeCashOutRecord.getStoreId(), storeCashOutRecord.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return "审批成功";
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
* 今日收益
|
|
|
*
|
|
|
* @param storeId 门店id
|