|
|
@@ -0,0 +1,165 @@
|
|
|
+package com.ssj.weixin.api.activity;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.google.gson.JsonObject;
|
|
|
+import com.google.gson.JsonParser;
|
|
|
+import com.ssj.bean.weixin.user.domain.User;
|
|
|
+import com.ssj.framework.core.common.controller.BaseController;
|
|
|
+import com.ssj.framework.core.security.annotation.IgnoreSecurity;
|
|
|
+import com.ssj.framework.core.security.manager.TokenManager;
|
|
|
+import com.ssj.framework.core.util.ResponseConstant;
|
|
|
+import com.ssj.framework.core.util.ResponseEntity;
|
|
|
+import com.ssj.service.conch.parents.service.ParentService;
|
|
|
+import com.ssj.service.weixin.user.service.UserService;
|
|
|
+import com.ssj.weixin.api.activity.service.ISignUpService;
|
|
|
+import com.ssj.weixin.api.activity.vo.ActivityLogin;
|
|
|
+import com.ssj.weixin.api.activity.vo.SignUpBase;
|
|
|
+import com.ssj.weixin.api.activity.vo.SignUpVO;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.jpa.repository.Modifying;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import java.util.ConcurrentModificationException;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author sh
|
|
|
+ * @className BrandActivityController
|
|
|
+ * @description 品牌活动api
|
|
|
+ * @date 2021/4/7
|
|
|
+ */
|
|
|
+@Api(value = "品牌落地活动相关接口", tags = "品牌落地活动相关接口")
|
|
|
+@RestController
|
|
|
+@RequestMapping("/api/activity")
|
|
|
+public class BrandActivityController extends BaseController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TokenManager tokenManager;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ParentService parentService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UserService userService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISignUpService signUpService;
|
|
|
+
|
|
|
+ @IgnoreSecurity
|
|
|
+ @RequestMapping(value="/activityLogin",method = RequestMethod.POST)
|
|
|
+ public ResponseEntity activityLogin(ActivityLogin req){
|
|
|
+ ResponseEntity responseEntity = new ResponseEntity();
|
|
|
+ Map<String,Object> data = new HashMap<>();
|
|
|
+ if(StringUtils.isBlank(req.getPhoneNum())){
|
|
|
+ return responseEntity.failure(ResponseConstant.CODE_000,"请输入电话号码");
|
|
|
+ }
|
|
|
+ if(StringUtils.isBlank(req.getMsgCode())){
|
|
|
+ return responseEntity.failure(ResponseConstant.CODE_000,"请输入验证码");
|
|
|
+ }
|
|
|
+ responseEntity = parentService.confirmSmsV2(req.getPhoneNum().trim(),req.getMsgCode());
|
|
|
+ if(responseEntity.getCode().equals(ResponseConstant.CODE_999)){
|
|
|
+ //查询此手机用户是否存在,如果不存在则新增一个手机用户,默认密码123456
|
|
|
+ User user = parentService.checkPhoneUser(req.getPhoneNum());
|
|
|
+ //创建token
|
|
|
+ data.put("accessToken",tokenManager.createToken("",user.getId(),"activity"));
|
|
|
+ responseEntity.success(data,"登录成功!");
|
|
|
+ }
|
|
|
+ return responseEntity;
|
|
|
+ }
|
|
|
+
|
|
|
+ @IgnoreSecurity
|
|
|
+ @RequestMapping(value="/sendCode",method = RequestMethod.POST)
|
|
|
+ public ResponseEntity sendCode(ActivityLogin req){
|
|
|
+ ResponseEntity responseEntity = new ResponseEntity();
|
|
|
+ if(StringUtils.isBlank(req.getPhoneNum())){
|
|
|
+ return responseEntity.failure(ResponseConstant.CODE_000,"请输入电话号码");
|
|
|
+ }
|
|
|
+ Map<String,Object> data = new HashMap<>();
|
|
|
+
|
|
|
+ //查看是否是已经报名成功
|
|
|
+ String phoneKey = "activitySuccess202101_"+req.getPhoneNum().trim();
|
|
|
+ if(tokenManager.exists(phoneKey)){
|
|
|
+ data.put("type",2);
|
|
|
+ data.put("qrCodeUrl",tokenManager.getString("activityQrCode_".concat(tokenManager.getString(phoneKey))));
|
|
|
+ return responseEntity.success(data,"成功");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ String codeKey = "repeatCode_".concat(req.getPhoneNum());
|
|
|
+ if(tokenManager.exists(codeKey)){
|
|
|
+ return responseEntity.failure("请于上次发送成功后60秒后再重新尝试!");
|
|
|
+ }
|
|
|
+ responseEntity = parentService.sendSmsV2(req.getPhoneNum().trim());
|
|
|
+ data.put("type",1);
|
|
|
+ responseEntity.success(data,"验证码发送成功");
|
|
|
+ }catch (Exception e){
|
|
|
+ responseEntity.failure(ResponseConstant.CODE_000,"发送短信验证码失败,请稍后重试");
|
|
|
+ }
|
|
|
+
|
|
|
+ return responseEntity;
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(value="/submitSignUp",method = RequestMethod.POST)
|
|
|
+ @Modifying
|
|
|
+ public ResponseEntity submitSignUp(@RequestParam(name = "accessToken") String accessToken,SignUpBase req){
|
|
|
+ ResponseEntity responseEntity = new ResponseEntity();
|
|
|
+ String param = request.getParameter("req");
|
|
|
+ req = JSON.parseObject(param,SignUpBase.class);
|
|
|
+ //查看是否是已经报名成功
|
|
|
+ Map<String,Object> data = new HashMap<>();
|
|
|
+ User user = userService.getById(tokenManager.getUserId(accessToken));
|
|
|
+ String phoneKey = "activitySuccess202101_"+user.getMobile();
|
|
|
+ if(tokenManager.exists(phoneKey)){
|
|
|
+ data.put("qrCodeUrl",tokenManager.getString("activityQrCode_".concat(tokenManager.getString(phoneKey))));
|
|
|
+ return responseEntity.success(data,"成功");
|
|
|
+ }
|
|
|
+ //检查剩余名额
|
|
|
+ int configNum = tokenManager.get("activity_num_limit",int.class);
|
|
|
+ int nowNum = tokenManager.get("activity_num_now",int.class);
|
|
|
+ if(nowNum>=configNum){
|
|
|
+ return responseEntity.failure("您好,名额已满!");
|
|
|
+ }
|
|
|
+ //添加数据库
|
|
|
+ signUpService.addData(req,user);
|
|
|
+ data.put("qrCodeUrl",tokenManager.getString("activityQrCode_"+req.getType()));
|
|
|
+ responseEntity.success(data,"报名成功");
|
|
|
+ return responseEntity;
|
|
|
+ }
|
|
|
+
|
|
|
+ @IgnoreSecurity
|
|
|
+ @RequestMapping(value="/signUpList",method = RequestMethod.POST)
|
|
|
+ public ResponseEntity signUpList(){
|
|
|
+ ResponseEntity responseEntity = new ResponseEntity();
|
|
|
+ Map<String,Object> data = new HashMap<>();
|
|
|
+ List<Map<String,Object>> list = signUpService.signUpList();
|
|
|
+ data.put("list",list);
|
|
|
+ responseEntity.success(data,"获取成功!");
|
|
|
+ return responseEntity;
|
|
|
+ }
|
|
|
+
|
|
|
+ @IgnoreSecurity
|
|
|
+ @RequestMapping(value="/initQrCode",method = RequestMethod.POST)
|
|
|
+ public ResponseEntity initQrCode(){
|
|
|
+ ResponseEntity responseEntity = new ResponseEntity();
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ map.put("1","/activity/kol.png");
|
|
|
+ map.put("2","/activity/电梯框架广告.png");
|
|
|
+ map.put("3","/activity/公交车站台广告.png");
|
|
|
+ map.put("4","/activity/公众号文章.png");
|
|
|
+ map.put("5","/activity/广州线下地推.png");
|
|
|
+ map.put("6","/activity/门禁广告.png");
|
|
|
+ map.put("7","/activity/朋友圈广告.png");
|
|
|
+ map.put("8","/activity/社群广告.png");
|
|
|
+ map.put("9","/activity/书店.png");
|
|
|
+ map.put("10","/activity/无锡线下地推.png");
|
|
|
+ for (Map.Entry<String, String> entry : map.entrySet()) {
|
|
|
+ tokenManager.setString("activityQrCode_".concat(entry.getKey()), entry.getValue());
|
|
|
+ }
|
|
|
+ responseEntity.success("初始化成功!");
|
|
|
+ return responseEntity;
|
|
|
+ }
|
|
|
+}
|