Commit d518c25f authored by hezhen's avatar hezhen

拥金功能

parent eb5aeade
......@@ -48,7 +48,7 @@ public class AppUserSellingWaterBiz extends BaseBiz<AppUserSellingWaterMapper,Ap
AppUserDetailBiz detailBiz;
@Autowired
MyWalletDetailMapper walletDetailMapper;
MyWaterBiz myWaterBiz;
......@@ -150,24 +150,48 @@ public class AppUserSellingWaterBiz extends BaseBiz<AppUserSellingWaterMapper,Ap
}
log.info("订单完成计算用户拥金----finishOrderWater----orderId===="+orderId+"---amount=="+amount);
int r=amount.compareTo(BigDecimal.ZERO);
//更新钱包
if(r==1&&userId>0){
MyWalletDetail walletDetail=new MyWalletDetail();
walletDetail.setUserId(userId);
walletDetail.setSource(1);
walletDetail.setCono(orderId);
walletDetail.setItype(1);
walletDetail.setAmount(amount);
walletDetailMapper.insertSelective(walletDetail);
myWaterBiz.updMyWater(userId,orderId,amount);
}
}
//订单退款计算用户拥金
public void refundOrderWater(OrderWaterDTO orderWaterDTO){
//订单id
Integer orderId=orderWaterDTO.getOrderId();
log.info("订单完成计算用户拥金----refundOrderWater----orderId===="+orderId);
if(orderId==null||orderId==0){
return;
}
List<AppUserSellingWater> list=getWaterList(orderId);
BigDecimal amount=new BigDecimal("0.00");
Integer userId=0;
if (list.size()>0){
for (AppUserSellingWater sellingWater:list){
Integer id=sellingWater.getId();
userId=sellingWater.getUserId();
sellingWater.setWaiting(1);
updateById(sellingWater);
sellingWater.setId(null);
sellingWater.setStatus(1);
insertSelective(sellingWater);
BigDecimal commission=sellingWater.getCommission();
log.info("订单完成计算用户拥金----refundOrderWater----id===="+id+"---commission=="+commission);
}
}
log.info("订单完成计算用户拥金----refundOrderWater----orderId===="+orderId+"---amount=="+amount);
int r=amount.compareTo(BigDecimal.ZERO);
//更新钱包
if(r==1&&userId>0){
myWaterBiz.updMyWater(userId,orderId,amount);
}
}
//获取拥金列表
public List<AppUserSellingWater> getWaterList(Integer orderId){
Example example=new Example(AppUserSellingWater.class);
......
package com.github.wxiaoqi.security.admin.biz;
import cn.hutool.core.date.DateTime;
import com.github.wxiaoqi.security.admin.entity.MyWallet;
import com.github.wxiaoqi.security.admin.entity.MyWalletDetail;
import com.github.wxiaoqi.security.admin.mapper.MyWalletDetailMapper;
......@@ -10,6 +11,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* 钱包
......@@ -27,16 +31,15 @@ public class MyWaterBiz extends BaseBiz<MyWalletMapper, MyWallet>{
MyWalletDetailMapper walletDetailMapper;
//更新我的钱包
//我的钱包入账
public void updMyWater(Integer userId, Integer orderId,BigDecimal amount){
log.info("---更新我的钱包----userId==="+userId+"----orderId===="+orderId+"----amount===="+amount);
log.info("---我的钱包入账----userId==="+userId+"----orderId===="+orderId+"----amount===="+amount);
MyWallet wallet=new MyWallet();
wallet.setUserId(userId);
wallet=selectOne(wallet);
//进账之前余额
BigDecimal oldBalance=new BigDecimal("0.00");
BigDecimal balance=new BigDecimal("0.00");
//已提现金额
BigDecimal withdrawals=new BigDecimal("0.00");
//进账总额(元)
BigDecimal totalAmount=new BigDecimal("0.00");
//今日收益
......@@ -49,19 +52,60 @@ public class MyWaterBiz extends BaseBiz<MyWalletMapper, MyWallet>{
wallet.setUserId(userId);
totalAmount=amount;
todayAmount=amount;
balance=amount;
}else {
id=wallet.getId();
balance=wallet.getBalance();
wallet.setBalance(balance.add(amount));
oldBalance=wallet.getBalance();
balance=wallet.getBalance().add(amount);
totalAmount=wallet.getTotalAmount().add(amount);
Long lastTime=wallet.getLastIntime();
todayAmount=amount;
if (lastTime!=null&&isToday(lastTime)){
todayAmount=wallet.getTodayAmount().add(amount);
}
unbooked=wallet.getUnbooked().subtract(unbooked);
}
log.info("---我的钱包入账----userId==="+userId+"----balance===="+balance+"----totalAmount===="+totalAmount+"---todayAmount==="+todayAmount+"---unbooked=="+unbooked);
MyWalletDetail walletDetail=new MyWalletDetail();
walletDetail.setUserId(userId);
walletDetail.setSource(1);
walletDetail.setCono(orderId);
walletDetail.setItype(1);
walletDetail.setAmount(amount);
walletDetail.setBalance(balance);
walletDetail.setBalance(oldBalance);
walletDetailMapper.insertSelective(walletDetail);
Long time=System.currentTimeMillis();
wallet.setBalance(balance);
wallet.setTodayAmount(todayAmount);
wallet.setTotalAmount(totalAmount);
wallet.setUnbooked(unbooked);
wallet.setLastIntime(time);
wallet.setUpdTime(time);
if(id>0){
mapper.updMyWater(wallet);
}else {
wallet.setCrtTime(time);
insertSelective(wallet);
}
log.info("---我的钱包入账----userId==="+userId+"----成功");
}
// 这个时间戳是不是今天
public boolean isToday(long time) {
boolean isToday = false;
Date date;
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
date = sdf.parse(sdf.format(new Date()));
if (time < date.getTime() && time > date.getTime()) {
isToday = true;
}
} catch (ParseException e) {
e.printStackTrace();
}
return isToday;
}
}
\ No newline at end of file
......@@ -11,5 +11,9 @@ import tk.mybatis.mapper.common.Mapper;
* @date 2019-07-11 14:14:54
*/
public interface MyWalletMapper extends Mapper<MyWallet> {
public void updMyWater(MyWallet myWallet);
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.github.wxiaoqi.security.admin.mapper.MyWalletMapper">
<update id="updMyWater" parameterType="com.github.wxiaoqi.security.admin.entity.MyWallet">
update my_wallet
<set>
<if test="userId!=null AND userId>0">
user_id=#{userId},
</if>
<if test="balance!=null AND balance>0">
balance=#{balance},
</if>
<if test="balance!=null AND balance>0">
withdrawals=#{withdrawals},
</if>
<if test="totalAmount!=null AND totalAmount>0">
total_amount=#{totalAmount},
</if>
<if test="todayAmount!=null AND todayAmount>0">
today_amount=#{todayAmount},
</if>
<if test="unbooked!=null AND unbooked>0">
unbooked=#{unbooked},
</if>
<if test="isFrozen!=null">
is_frozen=#{isFrozen},
</if>
<if test="lastIntime!=null AND lastIntime>0">
last_intime=#{lastIntime},
</if>
<if test="crtTime!=null AND crtTime>0">
crt_time=#{crtTime},
</if>
<if test="updTime!=null AND updTime>0">
upd_time=#{updTime},
</if>
<if test="version!=null ">
version=version+1,
</if>
</set>
<where>
id=#{id} and version=#{version}
</where>
</update>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment