xuhy
2023-06-14 831e3312572cf29dd91cbd882ef3dce809ac852d
user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/impl/AppUserServiceImpl.java
@@ -17,6 +17,7 @@
import com.supersavedriving.user.modular.system.util.MallBook.model.PaymentOrder;
import com.supersavedriving.user.modular.system.util.MallBook.model.PaymentOrderGood;
import com.supersavedriving.user.modular.system.util.MallBook.model.QueryOrder;
import com.supersavedriving.user.modular.system.util.MallBook.util.Transfer;
import com.supersavedriving.user.modular.system.util.MallBook.util.TrhRequest;
import com.supersavedriving.user.modular.system.util.PayMoneyUtil;
import com.supersavedriving.user.modular.system.util.RedisUtil;
@@ -38,6 +39,7 @@
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import java.math.BigInteger;
import java.net.InetAddress;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@@ -73,6 +75,12 @@
    @Autowired
    private IAccountChangeDetailService accountChangeDetailService;
    @Autowired
    private IDriverService driverService;
    @Autowired
    private ISystemConfigService systemConfigService;
    @Value("${callbackPath}")
    private String callbackPath;//支付回调网关地址
@@ -145,6 +153,7 @@
    @Override
    public ResultUtil<SignInToRegisterWarpper> signInToRegister(SignInToRegister signInToRegister) throws Exception {
        SignInToRegisterWarpper warpper = new SignInToRegisterWarpper();
        try {
        if(ToolUtil.isEmpty(signInToRegister.getJscode())){
            return ResultUtil.paranErr("jscode");
        }
@@ -182,12 +191,22 @@
            appUser.setInviterType(signInToRegister.getInviterType());
            this.insert(appUser);
            //发送优惠券
            boolean lock = redisUtil.lock();
                boolean lock = redisUtil.lock(5);
                if(!lock){
                    int num1 = 1;
                    while (num1 <= 10){
                        Thread.sleep(3000);//等待3秒
                        lock = redisUtil.lock(5);
            if(lock){
                            break;
                        }else{
                            num1++;
                        }
                    }
                }
                List<CouponWarpper> list = pushCoupon(appUser.getId());
                redisUtil.unlock();
                warpper.setCoupons(list);
            }
        }
        if(appUser.getStatus() == 2){
            return ResultUtil.error("账号被冻结");
@@ -197,8 +216,49 @@
            return ResultUtil.error("获取身份凭证失败");
        }
        warpper.setToken(token);
        }catch (Exception e){
            e.printStackTrace();
            redisUtil.unlock();
        }
        return ResultUtil.success(warpper);
    }
    /**
     * 转账
     * @param id
     * @param merOrderId
     * @param toUserId
     * @param amount
     * @param notifyUrl
     * @return
     */
    public ResultUtil zhaunzhang(Integer id, String merOrderId, String toUserId, Double amount, String notifyUrl){
        Transfer transfer = new Transfer();
        transfer.setDepositMerOrderId(merOrderId);
        transfer.setToUserId(toUserId);
        transfer.setAmount(String.valueOf(Double.valueOf(amount * 100).intValue()));
        transfer.setOrderName("补贴");
        transfer.setNotifyUrl(notifyUrl);
        transfer.setParameter1(id.toString());
        TrhRequest<Transfer> request = new TrhRequest();
        InterfaceResponse execute = request.execute(transfer, Transfer.SERVICE_CODE);
        if("0000".equals(execute.getCode())){
            JSONObject jsonObject = JSON.parseObject(execute.getResult());
            Integer status = jsonObject.getInteger("status");//0:待处理;1:成功;2:失败
            if(2 == status){
                System.err.println("转账失败");
                return ResultUtil.error("转账失败");
            }
            return ResultUtil.success();
        }else{
            System.err.println("转账失败:" + execute.getMsg());
            return ResultUtil.error(execute.getMsg());
        }
    }
    /**
@@ -218,7 +278,7 @@
            userToCoupon.setCouponTotal(coupon.getCouponSendQuantity() > coupon.getRemainingQuantity() ?
                    coupon.getRemainingQuantity() : coupon.getCouponSendQuantity());
            userToCoupon.setValidCount(userToCoupon.getCouponTotal());
            userToCoupon.setExpireTime(new Date(System.currentTimeMillis() + (coupon.getCouponValidity() * 24 * 60 * 60 * 1000)));
            userToCoupon.setExpireTime(new Date(System.currentTimeMillis() + (coupon.getCouponValidity().longValue() * 24L * 60L * 60L * 1000L)));
            userToCouponService.insert(userToCoupon);
            coupon.setRemainingQuantity(coupon.getCouponSendQuantity() > coupon.getRemainingQuantity() ? 0 :
@@ -320,7 +380,7 @@
        PaymentOrder paymentOrder = new PaymentOrder();
        paymentOrder.setBizOrderId(out_trade_no);
        paymentOrder.setAmount(String.valueOf(amount * 100));
        paymentOrder.setAmount(String.valueOf(Double.valueOf(amount * 100).intValue()));
        paymentOrder.setOrderName("账户充值");
        paymentOrder.setPayType("WX_MINI");
        paymentOrder.setTransferType("0");