parent
06d22250af
commit
63a54df37d
|
|
@ -5,6 +5,8 @@ import com.alibaba.fastjson.JSON;
|
|||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.sqx.common.annotation.Debounce;
|
||||
import com.sqx.common.utils.Result;
|
||||
import com.sqx.modules.app.annotation.Login;
|
||||
import com.sqx.modules.app.dto.BindWxDTO;
|
||||
import com.sqx.modules.app.dto.LoginDTO;
|
||||
import com.sqx.modules.app.dto.RegisterDTO;
|
||||
import com.sqx.modules.app.dto.UserInviteDTO;
|
||||
|
|
@ -168,6 +170,14 @@ public class AppLoginController {
|
|||
return userService.register(registerDTO);
|
||||
}
|
||||
|
||||
@Login
|
||||
@PostMapping("/bindWx")
|
||||
@ResponseBody
|
||||
@Debounce(interval = 2500, value = "#code")
|
||||
public Result bindWx(@RequestBody BindWxDTO bindWxDTO, @RequestAttribute("userId") Long userId) {
|
||||
return userService.bindWx(bindWxDTO, userId);
|
||||
}
|
||||
|
||||
@PostMapping("/bindWxOpenPhone")
|
||||
@ApiOperation("微信公众号绑定手机号")
|
||||
public Result bindWxOpenPhone(Long userId,String phone,String msg){
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
package com.sqx.modules.app.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
*/
|
||||
@Data
|
||||
public class BindWxDTO {
|
||||
@NotEmpty(message = "code不能为空")
|
||||
private String code;
|
||||
}
|
||||
|
|
@ -238,4 +238,6 @@ public interface UserService extends IService<UserEntity> {
|
|||
Result removeUserBlack(Long userId, Integer status);
|
||||
|
||||
Map<String, Object> queryPayAndExtractInfo();
|
||||
|
||||
Result bindWx(BindWxDTO bindWxDTO, Long userId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,6 +80,7 @@ import org.springframework.context.annotation.Lazy;
|
|||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import weixin.popular.api.SnsAPI;
|
||||
import weixin.popular.bean.sns.SnsToken;
|
||||
import weixin.popular.util.JsonUtil;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
|
@ -1824,4 +1825,31 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements
|
|||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result bindWx(BindWxDTO bindWxDTO, Long userId) {
|
||||
//微信appid
|
||||
CommonInfo one = commonInfoService.findOne(937);
|
||||
//微信秘钥
|
||||
CommonInfo two = commonInfoService.findOne(936);
|
||||
SnsToken snsToken = SnsAPI.oauth2AccessToken(one.getValue(), two.getValue(), bindWxDTO.getCode());
|
||||
if (!snsToken.isSuccess()) {
|
||||
return Result.error("获取失败");
|
||||
}
|
||||
String openid = snsToken.getOpenid();
|
||||
int count = count(new LambdaQueryWrapper<UserEntity>().eq(UserEntity::getWxOpenId, openid));
|
||||
if (count > 0) {
|
||||
return Result.error("该微信已被其他用户绑定");
|
||||
}
|
||||
|
||||
UserEntity userEntity = queryByUserId(userId);
|
||||
if (StringUtils.isNotBlank(userEntity.getWxOpenId())) {
|
||||
return Result.error("当前用户已绑定微信");
|
||||
}
|
||||
|
||||
userEntity.setWxOpenId(openid);
|
||||
userEntity.setUpdateTime(DateUtil.now());
|
||||
update(userEntity, new LambdaQueryWrapper<UserEntity>().eq(UserEntity::getUserId, userId));
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,16 @@
|
|||
package com.sqx.modules.orders.controller.app;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.sqx.common.annotation.Debounce;
|
||||
import com.sqx.common.exception.SqxException;
|
||||
import com.sqx.common.utils.Result;
|
||||
import com.sqx.modules.app.annotation.Login;
|
||||
import com.sqx.modules.app.entity.UserEntity;
|
||||
import com.sqx.modules.app.service.UserService;
|
||||
import com.sqx.modules.common.entity.CommonInfo;
|
||||
import com.sqx.modules.common.service.CommonInfoService;
|
||||
import com.sqx.modules.orders.service.OrdersService;
|
||||
import com.sqx.modules.sys.controller.AbstractController;
|
||||
import io.swagger.annotations.Api;
|
||||
|
|
@ -26,6 +34,22 @@ public class AppOrdersController extends AbstractController {
|
|||
|
||||
@Autowired
|
||||
private OrdersService ordersService;
|
||||
@Autowired
|
||||
private CommonInfoService commonInfoService;
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
private void checkWxBind(Long userId) {
|
||||
CommonInfo commonInfo = commonInfoService.findOne(938);
|
||||
if (commonInfo == null || !"1".equals(commonInfo.getValue())) {
|
||||
return;
|
||||
}
|
||||
UserEntity userEntity = userService.queryByUserId(userId);
|
||||
if (StrUtil.isBlank(userEntity.getWxOpenId())) {
|
||||
throw new SqxException("请先绑定微信");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 生成商品订单
|
||||
|
|
@ -39,6 +63,7 @@ public class AppOrdersController extends AbstractController {
|
|||
@ApiOperation("生成商品订单")
|
||||
@Debounce(interval = 20000, value = "#userId")
|
||||
public Result insertCourseOrders(Long courseId,Long courseDetailsId, @RequestAttribute("userId") Long userId) {
|
||||
checkWxBind(userId);
|
||||
return ordersService.insertCourseOrders(courseId, courseDetailsId,userId);
|
||||
}
|
||||
|
||||
|
|
@ -53,6 +78,7 @@ public class AppOrdersController extends AbstractController {
|
|||
@GetMapping("/insertCourseOrders/limit10")
|
||||
@ApiOperation("生成商品订单")
|
||||
public Result insertCourseOrdersLimit10(Long courseId, @RequestAttribute("userId") Long userId) {
|
||||
checkWxBind(userId);
|
||||
return ordersService.insertCourseOrdersLimit10(courseId, userId);
|
||||
}
|
||||
|
||||
|
|
@ -60,6 +86,7 @@ public class AppOrdersController extends AbstractController {
|
|||
@GetMapping("/insertVipOrders")
|
||||
@ApiOperation("生成会员订单")
|
||||
public Result insertVipOrders(@ApiParam("会员详情信息") Long vipDetailsId, @RequestAttribute("userId") Long userId) {
|
||||
checkWxBind(userId);
|
||||
return ordersService.insertVipOrders(vipDetailsId, userId);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue