| | |
| | | import org.springframework.web.context.request.ServletRequestAttributes; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.math.BigDecimal; |
| | | import java.math.BigInteger; |
| | | import java.math.RoundingMode; |
| | | import java.net.InetAddress; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | |
| | | if(token.length() > 16){ |
| | | key = token.substring(token.length() - 16); |
| | | } |
| | | redisUtil.setStrValue(key, appUser.getId().toString(), 7 * 24 * 60 * 60); |
| | | redisUtil.setStrValue("USER_" + appUser.getPhone(), key, 7 * 24 * 60 * 60); |
| | | redisUtil.setStrValue(key, appUser.getId().toString(), 94608000); |
| | | redisUtil.setStrValue("USER_" + appUser.getPhone(), key, 94608000); |
| | | return token; |
| | | } |
| | | return null; |
| | |
| | | appUser.setStatus(1); |
| | | appUser.setCreateTime(new Date()); |
| | | appUser.setIsException(1); |
| | | appUser.setInviterId(signInToRegister.getInviterId()); |
| | | appUser.setInviterType(signInToRegister.getInviterType()); |
| | | if(null != signInToRegister.getInviterId()){ |
| | | appUser.setInviterId(signInToRegister.getInviterId()); |
| | | 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++; |
| | | } |
| | | } |
| | | } |
| | | if(lock){ |
| | | List<CouponWarpper> list = pushCoupon(appUser.getId()); |
| | | redisUtil.unlock(); |
| | |
| | | Transfer transfer = new Transfer(); |
| | | transfer.setDepositMerOrderId(merOrderId); |
| | | transfer.setToUserId(toUserId); |
| | | transfer.setAmount(String.valueOf(Double.valueOf(amount * 100).intValue())); |
| | | transfer.setAmount(new BigDecimal(amount).multiply(new BigDecimal(100)).setScale(0, RoundingMode.HALF_EVEN).longValue() + ""); |
| | | transfer.setOrderName("补贴"); |
| | | transfer.setNotifyUrl(notifyUrl); |
| | | transfer.setParameter1(id.toString()); |
| | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 发送优惠券 |
| | | * @param userId |
| | |
| | | .eq("coupon_state", 1).eq("status", 1).gt("remaining_quantity", 0)); |
| | | List<CouponWarpper> list = new ArrayList<>(); |
| | | for (Coupon coupon : coupons) { |
| | | UserToCoupon userToCoupon = new UserToCoupon(); |
| | | userToCoupon.setCouponId(coupon.getId()); |
| | | userToCoupon.setCreateTime(new Date()); |
| | | userToCoupon.setUserId(userId); |
| | | userToCoupon.setStatus(1); |
| | | 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))); |
| | | userToCouponService.insert(userToCoupon); |
| | | Long num = coupon.getCouponSendQuantity() > coupon.getRemainingQuantity() ? |
| | | coupon.getRemainingQuantity() : coupon.getCouponSendQuantity(); |
| | | for (int i = 0; i < num; i++) { |
| | | UserToCoupon userToCoupon = new UserToCoupon(); |
| | | userToCoupon.setCouponId(coupon.getId()); |
| | | userToCoupon.setCreateTime(new Date()); |
| | | userToCoupon.setUserId(userId); |
| | | userToCoupon.setStatus(1); |
| | | userToCoupon.setCouponTotal(1); |
| | | userToCoupon.setValidCount(1); |
| | | userToCoupon.setExpireTime(new Date(System.currentTimeMillis() + (coupon.getCouponValidity().longValue() * 24L * 60L * 60L * 1000L))); |
| | | userToCouponService.insert(userToCoupon); |
| | | |
| | | CouponWarpper couponWarpper = new CouponWarpper(); |
| | | couponWarpper.setCouponConditionalAmount(coupon.getCouponConditionalAmount()); |
| | | couponWarpper.setCouponPreferentialAmount(coupon.getCouponPreferentialAmount()); |
| | | couponWarpper.setCouponName(coupon.getCouponName()); |
| | | couponWarpper.setNumber(userToCoupon.getValidCount()); |
| | | couponWarpper.setExpirationDate(userToCoupon.getExpireTime().getTime()); |
| | | list.add(couponWarpper); |
| | | } |
| | | coupon.setRemainingQuantity(coupon.getCouponSendQuantity() > coupon.getRemainingQuantity() ? 0 : |
| | | coupon.getRemainingQuantity() - coupon.getCouponSendQuantity()); |
| | | couponService.updateById(coupon); |
| | | |
| | | CouponWarpper couponWarpper = new CouponWarpper(); |
| | | couponWarpper.setCouponConditionalAmount(coupon.getCouponConditionalAmount()); |
| | | couponWarpper.setCouponPreferentialAmount(coupon.getCouponPreferentialAmount()); |
| | | couponWarpper.setCouponName(coupon.getCouponName()); |
| | | couponWarpper.setNumber(userToCoupon.getValidCount()); |
| | | couponWarpper.setExpirationDate(userToCoupon.getExpireTime().getTime()); |
| | | list.add(couponWarpper); |
| | | } |
| | | return list; |
| | | } |
| | |
| | | return ResultUtil.error("充值金额必须大于0"); |
| | | } |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); |
| | | String out_trade_no = sdf.format(new Date()) + UUIDUtil.getNumberRandom(3); |
| | | String out_trade_no = sdf.format(new Date()) + UUIDUtil.getNumberRandom(5); |
| | | AppUser appUser = this.selectById(uid); |
| | | RechargeRecord rechargeRecord = new RechargeRecord(); |
| | | rechargeRecord.setType(1); |
| | |
| | | |
| | | PaymentOrder paymentOrder = new PaymentOrder(); |
| | | paymentOrder.setBizOrderId(out_trade_no); |
| | | paymentOrder.setAmount(String.valueOf(Double.valueOf(amount * 100).intValue())); |
| | | paymentOrder.setAmount(new BigDecimal(amount).multiply(new BigDecimal(100)).setScale(0, RoundingMode.HALF_EVEN).longValue() + ""); |
| | | paymentOrder.setOrderName("账户充值"); |
| | | paymentOrder.setPayType("WX_MINI"); |
| | | paymentOrder.setTransferType("0"); |
| | |
| | | AccountChangeDetail accountChangeDetail = new AccountChangeDetail(); |
| | | accountChangeDetail.setUserType(1); |
| | | accountChangeDetail.setUserId(appUser1.getId()); |
| | | accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3)); |
| | | accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(5)); |
| | | accountChangeDetail.setChangeType(3); |
| | | accountChangeDetail.setType(1); |
| | | accountChangeDetail.setCreateTime(new Date()); |
| | | accountChangeDetail.setExplain("账户充值"); |
| | | accountChangeDetail.setOldData(appUser1.getAccountBalance()); |
| | | appUser1.setAccountBalance(appUser1.getAccountBalance() + rechargeRecord1.getAmount()); |
| | | appUser1.setAccountBalance(new BigDecimal(appUser1.getAccountBalance()).add(new BigDecimal(rechargeRecord1.getAmount())).setScale(2, RoundingMode.HALF_EVEN).doubleValue()); |
| | | accountChangeDetail.setNewData(appUser1.getAccountBalance()); |
| | | AppUserServiceImpl.this.updateById(appUser1); |
| | | accountChangeDetailService.saveData(accountChangeDetail); |
| | | SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 6)); |
| | | Double num2 = JSON.parseObject(systemConfig.getContent()).getDouble("num2"); |
| | | if(appUser1.getHavDiscount() == 0 && rechargeRecord1.getAmount().compareTo(num2) >= 0){ |
| | | appUser1.setHavDiscount(1); |
| | | } |
| | | AppUserServiceImpl.this.updateById(appUser1); |
| | | |
| | | rechargeRecord1.setPayTime(new Date()); |
| | | rechargeRecord1.setPayStatus(2); |
| | |
| | | AccountChangeDetail accountChangeDetail = new AccountChangeDetail(); |
| | | accountChangeDetail.setUserType(1); |
| | | accountChangeDetail.setUserId(rechargeRecord1.getUserId()); |
| | | accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3)); |
| | | accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(5)); |
| | | accountChangeDetail.setChangeType(3); |
| | | accountChangeDetail.setType(1); |
| | | accountChangeDetail.setCreateTime(new Date()); |
| | | accountChangeDetail.setExplain("余额充值"); |
| | | accountChangeDetail.setOldData(appUser.getAccountBalance()); |
| | | appUser.setAccountBalance(appUser.getAccountBalance() + rechargeRecord1.getAmount()); |
| | | appUser.setAccountBalance(new BigDecimal(appUser.getAccountBalance()).add(new BigDecimal(rechargeRecord1.getAmount())).setScale(2, RoundingMode.HALF_EVEN).doubleValue()); |
| | | accountChangeDetail.setNewData(appUser.getAccountBalance()); |
| | | this.updateById(appUser); |
| | | accountChangeDetailService.saveData(accountChangeDetail); |
| | | SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 6)); |
| | | Double num2 = JSON.parseObject(systemConfig.getContent()).getDouble("num2"); |
| | | if(appUser.getHavDiscount() == 0 && rechargeRecord1.getAmount().compareTo(num2) >= 0){ |
| | | appUser.setHavDiscount(1); |
| | | } |
| | | this.updateById(appUser); |
| | | |
| | | rechargeRecord1.setPayTime(new Date()); |
| | | rechargeRecord1.setPayStatus(2); |