|
|
@ -9,10 +9,7 @@ import com.hai.common.utils.BankNumberUtil; |
|
|
|
import com.hai.common.utils.DateUtil; |
|
|
|
import com.hai.common.utils.DateUtil; |
|
|
|
import com.hai.dao.HighOilCardMapper; |
|
|
|
import com.hai.dao.HighOilCardMapper; |
|
|
|
import com.hai.entity.*; |
|
|
|
import com.hai.entity.*; |
|
|
|
import com.hai.enum_type.OilCardBindStatusEnum; |
|
|
|
import com.hai.enum_type.*; |
|
|
|
import com.hai.enum_type.OilCardRecordSourceTypeEnum; |
|
|
|
|
|
|
|
import com.hai.enum_type.OilCardRecordTypeEnum; |
|
|
|
|
|
|
|
import com.hai.enum_type.OilCardStatusEnum; |
|
|
|
|
|
|
|
import com.hai.model.OilCardOrderModel; |
|
|
|
import com.hai.model.OilCardOrderModel; |
|
|
|
import com.hai.model.UserInfoModel; |
|
|
|
import com.hai.model.UserInfoModel; |
|
|
|
import com.hai.service.*; |
|
|
|
import com.hai.service.*; |
|
|
@ -54,6 +51,12 @@ public class HighOilCardServiceImpl implements HighOilCardService { |
|
|
|
@Resource |
|
|
|
@Resource |
|
|
|
private HighUserCardService userCardService; |
|
|
|
private HighUserCardService userCardService; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
|
|
|
private HighUserService userService; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
|
|
|
private HighOrderService orderService; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void editData(HighOilCard oilCard) { |
|
|
|
public void editData(HighOilCard oilCard) { |
|
|
|
if (oilCard.getId() == null) { |
|
|
|
if (oilCard.getId() == null) { |
|
|
@ -73,14 +76,14 @@ public class HighOilCardServiceImpl implements HighOilCardService { |
|
|
|
public synchronized void recharge(String cardNo, BigDecimal price, Long orgId) { |
|
|
|
public synchronized void recharge(String cardNo, BigDecimal price, Long orgId) { |
|
|
|
HighOilCard oilCard = getOilCardByCardNo(cardNo); |
|
|
|
HighOilCard oilCard = getOilCardByCardNo(cardNo); |
|
|
|
if (oilCard == null) { |
|
|
|
if (oilCard == null) { |
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到部门"); |
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "油卡卡号错误"); |
|
|
|
} |
|
|
|
} |
|
|
|
if (!oilCard.getStatus().equals(OilCardStatusEnum.status1.getStatus())) { |
|
|
|
if (!oilCard.getStatus().equals(OilCardStatusEnum.status1.getStatus())) { |
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "油卡不处于正常状态"); |
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "油卡不处于正常状态"); |
|
|
|
} |
|
|
|
} |
|
|
|
// 账户扣款
|
|
|
|
// 账户扣款
|
|
|
|
Map<String, Object> consumeType = new HashMap<>(); |
|
|
|
Map<String, Object> consumeType = new HashMap<>(); |
|
|
|
consumeType.put("sourceType", "2"); |
|
|
|
consumeType.put("sourceType", CompanyAmountSourceTypeEnum.type2); |
|
|
|
consumeType.put("sourceId", oilCard.getId()); |
|
|
|
consumeType.put("sourceId", oilCard.getId()); |
|
|
|
consumeType.put("sourceContent", "油卡:"+oilCard.getCardNo()+",充值:¥"+price.toString()); |
|
|
|
consumeType.put("sourceContent", "油卡:"+oilCard.getCardNo()+",充值:¥"+price.toString()); |
|
|
|
companyAccountService.consume(orgId, price, consumeType); |
|
|
|
companyAccountService.consume(orgId, price, consumeType); |
|
|
@ -110,6 +113,49 @@ public class HighOilCardServiceImpl implements HighOilCardService { |
|
|
|
oilCardRecordService.insertRecord(record); |
|
|
|
oilCardRecordService.insertRecord(record); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
@Transactional(rollbackFor=Exception.class,isolation = Isolation.SERIALIZABLE,propagation= Propagation.REQUIRES_NEW) |
|
|
|
|
|
|
|
public synchronized void recycleAmount(String cardNo) { |
|
|
|
|
|
|
|
HighOilCard oilCard = getOilCardByCardNo(cardNo); |
|
|
|
|
|
|
|
if (oilCard == null) { |
|
|
|
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "油卡卡号错误"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (oilCard.getAmount().compareTo(new BigDecimal("0.01")) == -1) { |
|
|
|
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "油卡余额低于¥0.01,无需回收"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// 账户进账
|
|
|
|
|
|
|
|
Map<String, Object> rechargeType = new HashMap<>(); |
|
|
|
|
|
|
|
rechargeType.put("sourceType", CompanyAmountSourceTypeEnum.type3.getType()); |
|
|
|
|
|
|
|
rechargeType.put("sourceId", oilCard.getId()); |
|
|
|
|
|
|
|
rechargeType.put("sourceContent", "油卡:"+oilCard.getCardNo()+",回收余额:¥" + oilCard.getAmount()); |
|
|
|
|
|
|
|
companyAccountService.recharge(oilCard.getOrgId(), oilCard.getAmount(), rechargeType); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 变更前金额
|
|
|
|
|
|
|
|
BigDecimal beforeAmount = oilCard.getAmount(); |
|
|
|
|
|
|
|
BigDecimal price = oilCard.getAmount(); |
|
|
|
|
|
|
|
// 计算金额
|
|
|
|
|
|
|
|
oilCard.setAmount(new BigDecimal("0")); |
|
|
|
|
|
|
|
editData(oilCard); |
|
|
|
|
|
|
|
// 变更后金额
|
|
|
|
|
|
|
|
BigDecimal afterAmount = oilCard.getAmount(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
HighOilCardRecord record = new HighOilCardRecord(); |
|
|
|
|
|
|
|
record.setOilCardId(oilCard.getId()); |
|
|
|
|
|
|
|
record.setCardNo(oilCard.getCardNo()); |
|
|
|
|
|
|
|
record.setType(OilCardRecordTypeEnum.type2.getType()); |
|
|
|
|
|
|
|
record.setAmount(price); |
|
|
|
|
|
|
|
record.setBeforeAmount(beforeAmount); |
|
|
|
|
|
|
|
record.setAfterAmount(afterAmount); |
|
|
|
|
|
|
|
record.setSourceType(OilCardRecordSourceTypeEnum.type4.getType()); |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
record.setSourceOrderNo(DateUtil.date2String(new Date(), "yyyyMMddHHmmss")); |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
record.setSourceContent("回收油卡余额:" + price); |
|
|
|
|
|
|
|
oilCardRecordService.insertRecord(record); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void consume(String cardNo, BigDecimal amount, Map<String, Object> otherParam) { |
|
|
|
public void consume(String cardNo, BigDecimal amount, Map<String, Object> otherParam) { |
|
|
|
// 油卡
|
|
|
|
// 油卡
|
|
|
@ -148,6 +194,61 @@ public class HighOilCardServiceImpl implements HighOilCardService { |
|
|
|
oilCardRecordService.insertRecord(record); |
|
|
|
oilCardRecordService.insertRecord(record); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
@Transactional(rollbackFor=Exception.class,isolation = Isolation.SERIALIZABLE,propagation= Propagation.REQUIRES_NEW) |
|
|
|
|
|
|
|
public void refund(String orderNo) { |
|
|
|
|
|
|
|
HighOrder order = orderService.getOrderByOrderNo(orderNo); |
|
|
|
|
|
|
|
if (order == null) { |
|
|
|
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的的订单"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!order.getPayType().equals(OrderPayTypeEnum.type7.getType())) { |
|
|
|
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "支付方式,不是油卡"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (StringUtils.isBlank(order.getMemCardNo())) { |
|
|
|
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的油卡卡号"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// 查询油卡卡号
|
|
|
|
|
|
|
|
HighOilCard oilCard = getOilCardByCardNo(order.getMemCardNo()); |
|
|
|
|
|
|
|
if (oilCard == null) { |
|
|
|
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的油卡卡号"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// 订单状态:1 待支付 2 已支付 3.已完成 4. 已退款 5.已取消 6.退款中 7.拒绝退款
|
|
|
|
|
|
|
|
if (order.getOrderStatus() == 2 || order.getOrderStatus() == 3 || order.getOrderStatus() == 6 || order.getOrderStatus() == 7) { |
|
|
|
|
|
|
|
order.setOrderStatus(4); |
|
|
|
|
|
|
|
order.setRefundTime(new Date()); |
|
|
|
|
|
|
|
order.setRefundPrice(order.getPayRealPrice()); |
|
|
|
|
|
|
|
orderService.updateOrderDetail(order); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 变更前金额
|
|
|
|
|
|
|
|
BigDecimal beforeAmount = oilCard.getAmount(); |
|
|
|
|
|
|
|
// 计算金额
|
|
|
|
|
|
|
|
oilCard.setAmount(oilCard.getAmount().add(order.getPayRealPrice())); |
|
|
|
|
|
|
|
oilCard.setAmountConsume(oilCard.getAmountConsume().subtract(order.getPayRealPrice())); |
|
|
|
|
|
|
|
editData(oilCard); |
|
|
|
|
|
|
|
// 变更后金额
|
|
|
|
|
|
|
|
BigDecimal afterAmount = oilCard.getAmount(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
HighOilCardRecord record = new HighOilCardRecord(); |
|
|
|
|
|
|
|
record.setOilCardId(oilCard.getId()); |
|
|
|
|
|
|
|
record.setCardNo(oilCard.getCardNo()); |
|
|
|
|
|
|
|
record.setType(OilCardRecordTypeEnum.type1.getType()); |
|
|
|
|
|
|
|
record.setAmount(order.getPayRealPrice()); |
|
|
|
|
|
|
|
record.setBeforeAmount(beforeAmount); |
|
|
|
|
|
|
|
record.setAfterAmount(afterAmount); |
|
|
|
|
|
|
|
record.setSourceType(OilCardRecordSourceTypeEnum.type3.getType()); |
|
|
|
|
|
|
|
record.setSourceId(order.getId()); |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
record.setSourceOrderNo(orderNo); |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
record.setSourceContent("订单号:" + orderNo + ",退款金额:" + order.getPayRealPrice()); |
|
|
|
|
|
|
|
oilCardRecordService.insertRecord(record); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "订单状态异常"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
@Transactional(propagation= Propagation.REQUIRES_NEW, rollbackFor = Exception.class) |
|
|
|
@Transactional(propagation= Propagation.REQUIRES_NEW, rollbackFor = Exception.class) |
|
|
|
public void generateCard(Long orgId, Integer generateNum) { |
|
|
|
public void generateCard(Long orgId, Integer generateNum) { |
|
|
@ -198,6 +299,17 @@ public class HighOilCardServiceImpl implements HighOilCardService { |
|
|
|
if (StringUtils.isBlank(oilCard.getContactPhone())) { |
|
|
|
if (StringUtils.isBlank(oilCard.getContactPhone())) { |
|
|
|
oilCardContactRecordService.insert(oilCard.getId(), oilCard.getCardNo(), "新设置:联系人【"+contactName+"】,联系电话【"+contactPhone+"】"); |
|
|
|
oilCardContactRecordService.insert(oilCard.getId(), oilCard.getCardNo(), "新设置:联系人【"+contactName+"】,联系电话【"+contactPhone+"】"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 根据手机号查询 用户是否存在;存在:自动绑定油卡
|
|
|
|
|
|
|
|
HighUser user = userService.findByPhone(contactPhone); |
|
|
|
|
|
|
|
if (user != null) { |
|
|
|
|
|
|
|
if (userCardService.getListByUser(user.getId(),UserCardType.type2.getType()).size() > 0) { |
|
|
|
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "联系电话已绑定其他油卡"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
userCardService.bindCard(UserCardType.type2.getType(), oilCard.getCardNo(), user.getId()); |
|
|
|
|
|
|
|
oilCard.setBindStatus(1); |
|
|
|
|
|
|
|
oilCard.setBindTime(new Date()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} else if (StringUtils.isNotBlank(oilCard.getContactPhone()) && !oilCard.getContactPhone().equals(contactPhone)) { |
|
|
|
} else if (StringUtils.isNotBlank(oilCard.getContactPhone()) && !oilCard.getContactPhone().equals(contactPhone)) { |
|
|
|
// 绑定状态 0:未绑定 1:已绑定
|
|
|
|
// 绑定状态 0:未绑定 1:已绑定
|
|
|
|
if (oilCard.getBindStatus().equals(1)) { |
|
|
|
if (oilCard.getBindStatus().equals(1)) { |
|
|
@ -211,6 +323,17 @@ public class HighOilCardServiceImpl implements HighOilCardService { |
|
|
|
userCardService.editCard(userCard); |
|
|
|
userCardService.editCard(userCard); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 根据手机号查询 用户是否存在;存在:自动绑定油卡
|
|
|
|
|
|
|
|
HighUser user = userService.findByPhone(contactPhone); |
|
|
|
|
|
|
|
if (user != null) { |
|
|
|
|
|
|
|
if (userCardService.getListByUser(user.getId(),UserCardType.type2.getType()).size() > 0) { |
|
|
|
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "联系电话已绑定其他油卡"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
userCardService.bindCard(UserCardType.type2.getType(), oilCard.getCardNo(), user.getId()); |
|
|
|
|
|
|
|
oilCard.setBindStatus(1); |
|
|
|
|
|
|
|
oilCard.setBindTime(new Date()); |
|
|
|
|
|
|
|
} |
|
|
|
oilCardContactRecordService.insert(oilCard.getId(), oilCard.getCardNo(), "联系信息变更:原联系人【"+oilCard.getContactName()+"】,联系电话【"+oilCard.getContactPhone()+"】。" + |
|
|
|
oilCardContactRecordService.insert(oilCard.getId(), oilCard.getCardNo(), "联系信息变更:原联系人【"+oilCard.getContactName()+"】,联系电话【"+oilCard.getContactPhone()+"】。" + |
|
|
|
"变跟后联系人【"+contactName+ "】,联系电话【"+contactPhone+"】"); |
|
|
|
"变跟后联系人【"+contactName+ "】,联系电话【"+contactPhone+"】"); |
|
|
|
} |
|
|
|
} |
|
|
|