From 9d2babb8bb99d55d76eab0558fd9f510652b270c Mon Sep 17 00:00:00 2001
From: luodangjia <luodangjia>
Date: 星期二, 11 六月 2024 15:16:17 +0800
Subject: [PATCH] 6.11

---
 UserNTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/api/UserCallbackController.java |  190 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 188 insertions(+), 2 deletions(-)

diff --git a/UserNTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/api/UserCallbackController.java b/UserNTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/api/UserCallbackController.java
index f6fbadd..e8200c2 100644
--- a/UserNTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/api/UserCallbackController.java
+++ b/UserNTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/api/UserCallbackController.java
@@ -1,10 +1,18 @@
 package com.stylefeng.guns.modular.api;
 
 
-import com.stylefeng.guns.modular.system.service.IUserInfoService;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.mapper.EntityWrapper;
+import com.stylefeng.guns.modular.system.model.*;
+import com.stylefeng.guns.modular.system.service.*;
 //import com.stylefeng.guns.modular.system.util.ICBCPayUtil;
-import com.stylefeng.guns.modular.system.util.PayMoneyUtil;
+import com.stylefeng.guns.modular.system.service.impl.UserServiceImpl;
+import com.stylefeng.guns.modular.system.util.*;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.util.StringUtils;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.ResponseBody;
@@ -13,6 +21,10 @@
 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;
 import java.util.Map;
 
 
@@ -32,7 +44,22 @@
     @Autowired
     private PayMoneyUtil payMoneyUtil;
 
+    @Autowired
+    private RedisUtil redisUtil;
 
+    @Autowired
+    private ALiSendSms aLiSendSms;
+    
+    @Autowired
+    private IUserService userService;
+    @Autowired
+    private ITActivityGeneralizationService activityGeneralizationService;
+
+    @Autowired
+    private IUserCouponRecordService userCouponRecordService;
+
+    @Autowired
+    private ISysCouponRecordService sysCouponRecordService;
 
 
 
@@ -93,6 +120,165 @@
         }
     }
 
+    @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({
+            @ApiImplicitParam(value = "电话", name = "phone", required = true, dataType = "String"),
+            @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>().eq("phone",phone).ne("flag",3)).get(0);
+        //已注册直接添加优惠卷
+        TActivityGeneralization tActivityGeneralization = activityGeneralizationService.selectById(acId);
+        // 获取当前时间
+        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){
+            //判断该账号是否领取
+            List<UserCouponRecord> userCouponRecords = userCouponRecordService.selectList(new EntityWrapper<UserCouponRecord>().eq("userId", byAccount.getId()).eq("activityType", 5).eq("couponActivityId", acId));
+            if (!userCouponRecords.isEmpty()){
+                return ResultUtil.error("当前用户已领取");
+            }
+            Date date = new Date();
+            UserCouponRecord userCouponRecord = new UserCouponRecord();
+            userCouponRecord.setActivityType(5);
+            userCouponRecord.setCouponActivityId(acId);
+            userCouponRecord.setCouponId(tActivityGeneralization.getCouponId());
+            userCouponRecord.setState(1);
+            Calendar calendar = Calendar.getInstance();
+            calendar.setTime(date);
+            calendar.set(Calendar.DAY_OF_MONTH, calendar.get(Calendar.DAY_OF_MONTH) + sysCouponRecord.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()==null?0:sysCouponRecord.getFullMoney())));
+            userCouponRecord.setMoney(Double.valueOf(String.valueOf(sysCouponRecord.getMoney())));
+            userCouponRecord.setCompanyId(byAccount.getCompanyId());
+            userCouponRecord.setUserId(byAccount.getId());
+
+            Integer userGrantCount = tActivityGeneralization.getUserGrantCount();
+//            userCouponRecordService.insert(userCouponRecord);
+            if (userGrantCount != null && userGrantCount > 0) {
+                for (int i = 0; i < userGrantCount; i++) {// ...
+                    userCouponRecordService.insert(userCouponRecord);
+                }
+            }
+        }else {
+            //判断当前用户是否领取
+            String value = redisUtil.getValue("counpon:" + phone);
+            if (value!=null){
+                return ResultUtil.error("当前用户已领取");
+            }
+            //未注册将优惠卷信息存入缓存,待用户注册时调用来添加优惠卷
+            redisUtil.setStrValue("counpon:"+phone, String.valueOf(acId));
+        }
+
+
+
+        return ResultUtil.success(tActivityGeneralization.getUserGrantCount());
+
+
+    }
+
+    @ResponseBody
+    @PostMapping("/get/code")
+    @ApiOperation(value = "获取验证码", tags = {"线下推广页面"}, notes = "")
+    @ApiImplicitParams({
+            @ApiImplicitParam(value = "电话", name = "phone", required = true, dataType = "String")
+    })
+    public ResultUtil coupon(String phone) {
+        if (StringUtils.hasLength(phone)) {
+            String code = String.valueOf((int) (Math.random() * 1000000));
+            redisUtil.setStrValue(phone, code, 15 * 60 * 1000);
+            AliSms aliSms = new AliSms();
+            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) {
+                e.printStackTrace();
+            }
+
+//            msgUtils.sendMsg(dto.getPhone(), code);
+            return ResultUtil.success("发送短信验证码成功!");
+        }
+        return ResultUtil.error("请输入手机号");
+    }
+
+
+    @ResponseBody
+    @PostMapping("/get/coupon/info")
+    @ApiOperation(value = "使用说明", tags = {"线下推广页面"}, notes = "")
+    @ApiImplicitParams({
+
+    })
+    public ResultUtil coupon(Integer acId){
+        TActivityGeneralization tActivityGeneralization = activityGeneralizationService.selectById(acId);
+
+        return ResultUtil.success(tActivityGeneralization.getUseExplain());
+    }
+
+    @Autowired
+    private WeChatUtil weChatUtil;
+
+    @ResponseBody
+    @PostMapping("/get/coupon/toWe")
+    @ApiOperation(value = "获取微信链接", tags = {"线下推广页面"}, notes = "")
+    @ApiImplicitParams({
+
+    })
+    public ResultUtil toWe(){
+        try {
+            String urlLink = weChatUtil.getUrlLink(null, null);
+            return ResultUtil.success(urlLink);
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+        return ResultUtil.error("请稍后再试");
+    }
+
+
 
 
 }

--
Gitblit v1.7.1