luodangjia
2024-12-10 31ce6be2d56798d9509e6d90335999064351f7f3
UserNTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/api/UserCallbackController.java
@@ -21,6 +21,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
import java.time.LocalDateTime;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
@@ -120,6 +121,24 @@
    }
    @ResponseBody
    @PostMapping("/get/confirm")
    @ApiOperation(value = "校验当前活动是否过期", tags = {"线下推广页面"}, notes = "")
    @ApiImplicitParams(
            {@ApiImplicitParam(value = "活动Id", name = "acId", required = true, dataType = "int")
    })
    public ResultUtil confirm(Integer acId){
        TActivityGeneralization tActivityGeneralization = activityGeneralizationService.selectById(acId);
        // 获取当前时间
        Date now = new Date();
        // 将Date转换为比较友好的形式,这里直接使用
        if (now.after(tActivityGeneralization.getStartTime()) && now.before(tActivityGeneralization.getEndTime())) {
           return ResultUtil.success();
        } else {
            return  ResultUtil.error("该活动已失效");
        }
    }
    @ResponseBody
    @PostMapping("/get/coupon")
    @ApiOperation(value = "获取优惠卷", tags = {"线下推广页面"}, notes = "")
    @ApiImplicitParams({
@@ -127,18 +146,45 @@
            @ApiImplicitParam(value = "验证码", name = "code", required = true, dataType = "String")
    })
    public ResultUtil coupon(String phone,String code,Integer acId){
        //判断验证码是否正确
        // 校验验证码是否正确
            String redisCode = redisUtil.getValue("code:"+phone);
        if (redisCode==null&&!code.equals("111111")){
            return ResultUtil.error("验证码错误");
        }
        if (!code.equals(redisCode)&&!code.equals("111111")) {
            return ResultUtil.error("验证码错误");
        }
        //判断该手机号是否注册
        UserInfo byAccount = userInfoService.selectList(new EntityWrapper<UserInfo>().ne("flag",3)).get(0);
        List<UserInfo> userInfos = userInfoService.selectList(new EntityWrapper<UserInfo>().eq("phone", phone).ne("flag", 3));
        //已注册直接添加优惠卷
        TActivityGeneralization tActivityGeneralization = activityGeneralizationService.selectById(acId);
        if (tActivityGeneralization.getState()==4){
            return ResultUtil.error("当前活动已暂停");
        }
        // 获取当前时间
        Date now = new Date();
        // 将Date转换为比较友好的形式,这里直接使用
//        if (now.after(tActivityGeneralization.getStartTime()) && now.before(tActivityGeneralization.getEndTime())) {
//            System.out.println("当前时间在活动的开始时间和结束时间之间");
//        } else {
//            return  ResultUtil.error("该活动已失效");
//        }
        SysCouponRecord sysCouponRecord = sysCouponRecordService.selectById(tActivityGeneralization.getCouponId());
        if (byAccount != null){
        int i1 = userCouponRecordService.selectCount(new EntityWrapper<UserCouponRecord>().eq("activityType", 5).eq("couponActivityId", acId).groupBy("userId"));
        if (tActivityGeneralization.getParticipateCount()<=i1){
            return ResultUtil.error("当前参与人数已满");
        }
        if (!userInfos.isEmpty()){
            //判断该账号是否领取
            List<UserCouponRecord> userCouponRecords = userCouponRecordService.selectList(new EntityWrapper<UserCouponRecord>().eq("activityType", 5).eq("couponActivityId", acId));
            List<UserCouponRecord> userCouponRecords = userCouponRecordService.selectList(new EntityWrapper<UserCouponRecord>().eq("userId", userInfos.get(0).getId()).eq("activityType", 5).eq("couponActivityId", acId));
            if (!userCouponRecords.isEmpty()){
                return ResultUtil.error("当前用户已领取");
                return ResultUtil.error("您已领取过该优惠活动,不可重复领取");
            }
            Date date = new Date();
            UserCouponRecord userCouponRecord = new UserCouponRecord();
@@ -148,20 +194,20 @@
            userCouponRecord.setState(1);
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            calendar.set(Calendar.DAY_OF_MONTH, calendar.get(Calendar.DAY_OF_MONTH) + sysCouponRecord.getEffective());
            calendar.set(Calendar.DAY_OF_MONTH, calendar.get(Calendar.DAY_OF_MONTH) + tActivityGeneralization.getEffective());
            userCouponRecord.setExpirationTime(calendar.getTime());
            userCouponRecord.setCouponType(Integer.valueOf(String.valueOf(sysCouponRecord.getCouponType())));
            userCouponRecord.setCouponUseType(sysCouponRecord.getCouponUseType());
            userCouponRecord.setInsertTime(date);
            userCouponRecord.setFullMoney(Double.valueOf(String.valueOf(sysCouponRecord.getFullMoney())));
            userCouponRecord.setFullMoney(Double.valueOf(String.valueOf(sysCouponRecord.getFullMoney()==null?0:sysCouponRecord.getFullMoney())));
            userCouponRecord.setMoney(Double.valueOf(String.valueOf(sysCouponRecord.getMoney())));
            userCouponRecord.setCompanyId(byAccount.getCompanyId());
            userCouponRecord.setUserId(byAccount.getId());
            userCouponRecord.setCompanyId(sysCouponRecord.getCompanyId());
            userCouponRecord.setUserId(userInfos.get(0).getId());
            Integer userGrantCount = tActivityGeneralization.getUserGrantCount();
//            userCouponRecordService.insert(userCouponRecord);
            if (userGrantCount != null && userGrantCount > 0) {
                for (int i = 0; i < userGrantCount; i++) {// ...
                for (int i = 0; i < userGrantCount; i++) {
                    userCouponRecordService.insert(userCouponRecord);
                }
            }
@@ -169,7 +215,13 @@
            //判断当前用户是否领取
            String value = redisUtil.getValue("counpon:" + phone);
            if (value!=null){
                return ResultUtil.error("当前用户已领取");
                String[] split = value.split(",");
                for (String s : split) {
                    if (s.equals(String.valueOf(acId))){
                        return ResultUtil.error("您已领取过该优惠活动,不可重复领取");
                    }
                }
                redisUtil.setStrValue("counpon:"+phone, value+","+String.valueOf(acId));
            }
            //未注册将优惠卷信息存入缓存,待用户注册时调用来添加优惠卷
            redisUtil.setStrValue("counpon:"+phone, String.valueOf(acId));
@@ -196,6 +248,7 @@
            aliSms.setCode(code);
            String json = JSONObject.toJSONString(aliSms);
            try {
                redisUtil.setStrValue("code:"+phone, code,15 * 60 * 1000);
                aLiSendSms.sendSms(phone, "SMS_467580138", json);
            } catch (Exception e) {
@@ -242,5 +295,38 @@
    @ResponseBody
    @PostMapping("/get/driverQr")
    @ApiOperation(value = "获取司机二维码新", tags = {"线下推广页面"}, notes = "")
    @ApiImplicitParams({
    })
    public ResultUtil driverQr(){
        try {
            String urlLink = weChatUtil.getUrlLink("pages/areaDetails/areaDetails", null);
            return ResultUtil.success(urlLink);
        }catch (Exception e){
            e.printStackTrace();
        }
        return ResultUtil.error("请稍后再试");
    }
    @ResponseBody
    @PostMapping("/get/rid")
    @ApiOperation(value = "获取司机二维码新", tags = {"线下推广页面"}, notes = "")
    @ApiImplicitParams({
    })
    public ResultUtil rid(){
        try {
            String urlLink = weChatUtil.rid("/pages/home/scanPage/scanPage", null);
            return ResultUtil.success(urlLink);
        }catch (Exception e){
            e.printStackTrace();
        }
        return ResultUtil.error("请稍后再试");
    }
}