|
@@ -1,6 +1,7 @@
|
|
|
package com.ylx.massage.service.impl;
|
|
package com.ylx.massage.service.impl;
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
@@ -9,9 +10,14 @@ import com.ylx.massage.domain.TWxUser;
|
|
|
import com.ylx.massage.domain.vo.TWxUserVo;
|
|
import com.ylx.massage.domain.vo.TWxUserVo;
|
|
|
import com.ylx.massage.mapper.TWxUserMapper;
|
|
import com.ylx.massage.mapper.TWxUserMapper;
|
|
|
import com.ylx.massage.service.TWxUserService;
|
|
import com.ylx.massage.service.TWxUserService;
|
|
|
|
|
+import com.ylx.shopingfundsdetail.service.ShoppingFundsDetailService;
|
|
|
|
|
+import com.ylx.shoppingfunds.domain.dto.MyShoppingFundsUpdateDto;
|
|
|
|
|
+import com.ylx.shoppingfunds.domain.vo.MyShoppingFundsQueryVo;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
-import java.util.Collection;
|
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Optional;
|
|
import java.util.Optional;
|
|
|
|
|
|
|
@@ -21,7 +27,8 @@ import java.util.Optional;
|
|
|
*/
|
|
*/
|
|
|
@Service
|
|
@Service
|
|
|
public class TWxUserServiceImpl extends ServiceImpl<TWxUserMapper, TWxUser> implements TWxUserService {
|
|
public class TWxUserServiceImpl extends ServiceImpl<TWxUserMapper, TWxUser> implements TWxUserService {
|
|
|
-
|
|
|
|
|
|
|
+ @Resource(name = "shoppingFundsDetailService")
|
|
|
|
|
+ private ShoppingFundsDetailService shoppingFundsDetailService;
|
|
|
@Override
|
|
@Override
|
|
|
public TWxUser getByOpenId(String openId) {
|
|
public TWxUser getByOpenId(String openId) {
|
|
|
LambdaQueryWrapper<TWxUser> wrapper = new LambdaQueryWrapper<>();
|
|
LambdaQueryWrapper<TWxUser> wrapper = new LambdaQueryWrapper<>();
|
|
@@ -80,4 +87,47 @@ public class TWxUserServiceImpl extends ServiceImpl<TWxUserMapper, TWxUser> impl
|
|
|
}
|
|
}
|
|
|
return user;
|
|
return user;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 查询我的购物金余额
|
|
|
|
|
+ * @param userId
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public MyShoppingFundsQueryVo queryMyShoppingFunds(String userId) {
|
|
|
|
|
+ TWxUser user = this.getById(userId);
|
|
|
|
|
+ if (ObjectUtil.isNull(user)) {
|
|
|
|
|
+ throw new IllegalArgumentException("参数有误,用户不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ MyShoppingFundsQueryVo myShoppingFundsVo = new MyShoppingFundsQueryVo();
|
|
|
|
|
+ myShoppingFundsVo.setWxUserId(user.getId());
|
|
|
|
|
+ myShoppingFundsVo.setDBalance(user.getdBalance());
|
|
|
|
|
+ return myShoppingFundsVo;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 更新我的购物金余额
|
|
|
|
|
+ * @param userId
|
|
|
|
|
+ * @param amount
|
|
|
|
|
+ * @param expenseType
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public void updateMyShoppingFunds(String userId, BigDecimal amount, Integer expenseType) {
|
|
|
|
|
+ TWxUser user = this.getById(userId);
|
|
|
|
|
+ if (ObjectUtil.isNull(user)){
|
|
|
|
|
+ throw new IllegalArgumentException("参数有误,用户不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ //表示购卡
|
|
|
|
|
+ if(expenseType.equals(0)){
|
|
|
|
|
+ user.setdBalance(user.getdBalance().add(amount));
|
|
|
|
|
+ }else if(expenseType.equals(1)){
|
|
|
|
|
+ //表示消费购物金
|
|
|
|
|
+ if(user.getdBalance().compareTo(amount)<0) {
|
|
|
|
|
+ throw new IllegalArgumentException("参数有误,余额不足");
|
|
|
|
|
+ }
|
|
|
|
|
+ user.setdBalance(user.getdBalance().subtract(amount));
|
|
|
|
|
+ }
|
|
|
|
|
+ this.updateById(user);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|