|
@@ -15,6 +15,7 @@ import com.leromro.core.utils.DateTimeUtil;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.time.Duration;
|
|
@@ -60,45 +61,53 @@ public class MainOrderServiceImpl extends ServiceImpl<MainOrdersMapper, MainOrde
|
|
|
* @param orderRequest
|
|
|
*/
|
|
|
@Override
|
|
|
+ @Transactional
|
|
|
/*@Transactional*/
|
|
|
public void createOrders(OrderRequestDTO orderRequest) {
|
|
|
MainOrders orders = orderRequest.getOrders();
|
|
|
List<VolunteerWorkDate> workDateList = orderRequest.getWorkDateList();
|
|
|
Long userId = SecurityUtils.getUserId();
|
|
|
- //把地址信息也添加到数据里面
|
|
|
- Address address = addressMapper.selectAddressByAddressId(orders.getAddressId());
|
|
|
- orders.setAddress(address.getAddress());
|
|
|
- orders.setClientName(address.getName());
|
|
|
- orders.setClientTelephone(address.getTelephone());
|
|
|
+
|
|
|
//获取志愿者信息,同时服务时长和价格也都在志愿者id中进行获取
|
|
|
VolunteerInfo info = volunteerInfoMapper.selectOne(new LambdaQueryWrapper<VolunteerInfo>()
|
|
|
.eq(VolunteerInfo::getVolunteerInfoId, orders.getVolunteerInfoId()));
|
|
|
BigDecimal serviceOnePrice = info.getBusinessPrice();
|
|
|
Integer businessDurationMin = info.getBusinessDuration();
|
|
|
+ // 判断支付方式,余额扣减余额。 1 余额 2 微信
|
|
|
+ if (orders.getPaymentMethod().equals("1")){
|
|
|
+ // 查看余额够不够 修改用户余额表
|
|
|
+ BigDecimal totalPrice = orders.getServiceTotalPrice();
|
|
|
+ ClientAccount clientAccount = clientAccountMapper.selectBalanceByuserID(userId);
|
|
|
+ BigDecimal balanceOld = clientAccount.getBalance();
|
|
|
+ int compared = totalPrice.compareTo(balanceOld);
|
|
|
+ if (compared>0){
|
|
|
+ throw new RuntimeException("余额不足,支付失败");
|
|
|
+ }else {
|
|
|
+ BigDecimal balanceNew = balanceOld.subtract(totalPrice);
|
|
|
+ clientAccount.setBalance(balanceNew);
|
|
|
+ clientAccountMapper.updateClientBalance(clientAccount);
|
|
|
+ }
|
|
|
+ }else if (orders.getPaymentMethod().equals("2")){
|
|
|
+ //待完成 微信支付
|
|
|
+ System.out.println("微信支付");
|
|
|
|
|
|
- // 查看余额够不够 修改用户余额表
|
|
|
- BigDecimal totalPrice = orders.getServiceTotalPrice();
|
|
|
- ClientAccount clientAccount = clientAccountMapper.selectBalanceByuserID(userId);
|
|
|
- BigDecimal balanceOld = clientAccount.getBalance();
|
|
|
- int compared = totalPrice.compareTo(balanceOld);
|
|
|
- if (compared>0){
|
|
|
- throw new RuntimeException("余额不足,支付失败");
|
|
|
}else {
|
|
|
- BigDecimal balanceNew = balanceOld.subtract(totalPrice);
|
|
|
- clientAccount.setBalance(balanceNew);
|
|
|
- clientAccountMapper.updateClientBalance(clientAccount);
|
|
|
+ throw new RuntimeException("支付方式错误");
|
|
|
}
|
|
|
//创建订单主表
|
|
|
+ //把地址信息也添加到数据里面
|
|
|
+ Address address = addressMapper.selectAddressByAddressId(orders.getAddressId());
|
|
|
+ orders.setAddress(address.getAddress());
|
|
|
+ orders.setClientName(address.getName());
|
|
|
+ orders.setClientTelephone(address.getTelephone());
|
|
|
long orderId = snowflake.nextId();
|
|
|
orders.setMainOrderId(String.valueOf(orderId));
|
|
|
orders.setOrderStatus("1");
|
|
|
orders.setFinishTimes(0L);
|
|
|
- orders.setPaymentMethod("0");
|
|
|
orders.setUserId(userId);
|
|
|
orders.setCreateTime(DateTimeUtil.getNowTime());
|
|
|
orders.setServiceOnePrice(serviceOnePrice);
|
|
|
orders.setServiceDuration(businessDurationMin);
|
|
|
-// mainOrdersMapper.insertMainOrders(orders);
|
|
|
this.save(orders);
|
|
|
|
|
|
//修改志愿者预约时间表
|