yshop3.0-RC2版本

This commit is contained in:
hupeng
2020-07-09 15:16:42 +08:00
parent 7347f37e19
commit 43f5ef2e41
353 changed files with 12676 additions and 1920 deletions

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>yshop</artifactId>
<groupId>co.yixiang</groupId>
<version>3.0-alpha</version>
<version>3.0-RC2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@ -21,14 +21,25 @@
<dependency>
<groupId>co.yixiang</groupId>
<artifactId>yshop-weixin</artifactId>
<version>3.0-alpha</version>
<version>3.0-RC2</version>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>co.yixiang</groupId>
<artifactId>yshop-message</artifactId>
<version>3.0-RC2</version>
<exclusions>
<exclusion>
<groupId>co.yixiang</groupId>
<artifactId>yshop-mall</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--jwt-->
@ -69,11 +80,6 @@
<artifactId>emoji-java</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-spring-boot-starter</artifactId>
<version>2.0.4</version>
</dependency>
</dependencies>
<build>

View File

@ -0,0 +1,30 @@
/**
* Copyright (C) 2018-2020
* All rights reserved, Designed By www.yixiang.co
* 注意:
* 本软件为www.yixiang.co开发研制未经购买不得使用
* 购买后可获得全部源代码禁止转卖、分享、上传到码云、github等开源平台
* 一经发现盗用、分享等行为,将追究法律责任,后果自负
*/
package co.yixiang.common.config;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* MybatisPlus配置
*
*/
@Configuration
public class MybatisPlusConfig {
/**
* mybatis-plus分页插件
*/
@Bean
public PaginationInterceptor paginationInterceptor() {
return new PaginationInterceptor();
}
}

View File

@ -13,8 +13,10 @@ import co.yixiang.api.ApiCode;
import co.yixiang.api.UnAuthenticatedException;
import co.yixiang.common.bean.LocalUser;
import co.yixiang.common.util.JwtToken;
import co.yixiang.constant.ShopConstants;
import co.yixiang.modules.user.domain.YxUser;
import co.yixiang.modules.user.service.YxUserService;
import co.yixiang.utils.RedisUtils;
import com.auth0.jwt.interfaces.Claim;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
@ -37,6 +39,9 @@ public class PermissionInterceptor extends HandlerInterceptorAdapter {
@Autowired
private YxUserService userService;
@Autowired
private RedisUtils redisUtils;
public PermissionInterceptor() {
super();
}
@ -61,10 +66,17 @@ public class PermissionInterceptor extends HandlerInterceptorAdapter {
throw new UnAuthenticatedException(ApiCode.UNAUTHORIZED);
}
String token = tokens[1];
//检测用户是否被踢出
if(redisUtils.get(ShopConstants.YSHOP_APP_LOGIN_USER + token) == null){
throw new UnAuthenticatedException(ApiCode.UNAUTHORIZED);
}
Optional<Map<String, Claim>> optionalMap = JwtToken.getClaims(token);
Map<String, Claim> map = optionalMap
.orElseThrow(() -> new UnAuthenticatedException(ApiCode.UNAUTHORIZED));
boolean valid = this.hasPermission(authCheck.get(), map);
if(valid){
this.setToThreadLocal(map);

View File

@ -1,86 +1,87 @@
//package co.yixiang.common.util;
//
//
//import co.yixiang.user.vo.CityVO;
//import org.springframework.util.CollectionUtils;
//
//import java.util.ArrayList;
//import java.util.List;
//
///**
// * @ClassName 树形工具类
// * @Author hupeng <610796224@qq.com>
// * @Date 2019/10/22
// **/
//public class CityTreeUtil {
// /**
// * 获得指定节点下所有归档
// *
// * @param list
// * @param parentId
// * @return
// */
// public static List<CityVO> list2TreeConverter(List<CityVO> list, int parentId) {
// List<CityVO> returnList = new ArrayList<>();
//
// for (CityVO res : list) {
// //判断对象是否为根节点
//
// if (res.getPid() == parentId) {
// //该节点为根节点,开始递归
//
// recursionFn(list, res); //通过递归为节点设置childList
//
// returnList.add(res);
// }
// }
//
// return returnList;
// }
//
// /**
// * 递归列表
// * 通过递归,给指定t节点设置childList
// *
// * @param list
// * @param t
// */
// public static void recursionFn(List<CityVO> list, CityVO t) {
// //只能获取当前t节点的子节点集,并不是所有子节点集
// List<CityVO> childsList = getChildList(list, t);
//
// //设置他的子集对象集
// t.setC(childsList);
//
// //迭代子集对象集
// for (CityVO nextChild : childsList) { //遍历完,则退出递归
//
// //判断子集对象是否还有子节点
// if (!CollectionUtils.isEmpty(childsList)) {
// //有下一个子节点,继续递归
// recursionFn(list, nextChild);
// }
// }
// }
//
// /**
// * 获得指定节点下的所有子节点
// *
// * @param list
// * @param t
// * @return
// */
// public static List<CityVO> getChildList(List<CityVO> list, CityVO t) {
// List<CityVO> childsList = new ArrayList<>();
// //遍历集合元素,如果元素的Parentid==指定元素的id,则说明是该元素的子节点
// for (CityVO t1 : list) {
// if (t1.getPid().equals(t.getV())) {
// childsList.add(t1);
// }
// }
//
// return childsList;
// }
//
//
//}
package co.yixiang.common.util;
import co.yixiang.modules.user.vo.CityVo;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
/**
* @ClassName 树形工具类
* @Author hupeng <610796224@qq.com>
* @Date 2019/10/22
**/
public class CityTreeUtil {
/**
* 获得指定节点下所有归档
*
* @param list
* @param parentId
* @return
*/
public static List<CityVo> list2TreeConverter(List<CityVo> list, int parentId) {
List<CityVo> returnList = new ArrayList<>();
for (CityVo res : list) {
//判断对象是否为根节点
if (res.getPid() == parentId) {
//该节点为根节点,开始递归
recursionFn(list, res); //通过递归为节点设置childList
returnList.add(res);
}
}
return returnList;
}
/**
* 递归列表
* 通过递归,给指定t节点设置childList
*
* @param list
* @param t
*/
public static void recursionFn(List<CityVo> list, CityVo t) {
//只能获取当前t节点的子节点集,并不是所有子节点集
List<CityVo> childsList = getChildList(list, t);
//设置他的子集对象集
t.setC(childsList);
//迭代子集对象集
for (CityVo nextChild : childsList) { //遍历完,则退出递归
//判断子集对象是否还有子节点
if (!CollectionUtils.isEmpty(childsList)) {
//有下一个子节点,继续递归
recursionFn(list, nextChild);
}
}
}
/**
* 获得指定节点下的所有子节点
*
* @param list
* @param t
* @return
*/
public static List<CityVo> getChildList(List<CityVo> list, CityVo t) {
List<CityVo> childsList = new ArrayList<>();
//遍历集合元素,如果元素的Parentid==指定元素的id,则说明是该元素的子节点
for (CityVo t1 : list) {
if (t1.getPid().equals(t.getV())) {
childsList.add(t1);
}
}
return childsList;
}
}

View File

@ -1,31 +0,0 @@
///**
// * Copyright (C) 2018-2020
// * All rights reserved, Designed By www.yixiang.co
// * 注意:
// * 本软件为www.yixiang.co开发研制未经购买不得使用
// * 购买后可获得全部源代码禁止转卖、分享、上传到码云、github等开源平台
// * 一经发现盗用、分享等行为,将追究法律责任,后果自负
// */
//package co.yixiang.config;
//
//import lombok.Data;
//import org.springframework.boot.context.properties.ConfigurationProperties;
//import org.springframework.context.annotation.Configuration;
//
//
///**
// * reids相关配置
// * @author hupeng
// * @since 2020-02-27
// */
//@Data
//@Configuration
//@ConfigurationProperties(prefix = "spring.redis")
//public class RedisConfigProperties {
//
// private String host = "host";
// private String port = "port";
// private String password = "password";
// private String database = "database";
//
//}

View File

@ -1,48 +0,0 @@
///**
// * Copyright (C) 2018-2020
// * All rights reserved, Designed By www.yixiang.co
// * 注意:
// * 本软件为www.yixiang.co开发研制未经购买不得使用
// * 购买后可获得全部源代码禁止转卖、分享、上传到码云、github等开源平台
// * 一经发现盗用、分享等行为,将追究法律责任,后果自负
// */
//package co.yixiang.config;
//
//import cn.hutool.core.util.StrUtil;
//import co.yixiang.listener.RedisKeyExpirationListener;
//import co.yixiang.modules.activity.service.YxStorePinkService;
//import co.yixiang.modules.order.service.YxStoreOrderService;
//import lombok.AllArgsConstructor;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.data.redis.connection.RedisConnectionFactory;
//import org.springframework.data.redis.core.RedisTemplate;
//import org.springframework.data.redis.listener.PatternTopic;
//import org.springframework.data.redis.listener.RedisMessageListenerContainer;
//
///**
// * redis监听配置
// * @author hupeng
// * @since 2020-02-27
// */
//
//@Configuration
//@AllArgsConstructor
//public class RedisListenerConfig {
//
// private final RedisTemplate<String, String> redisTemplate;
// private final RedisConfigProperties redisConfigProperties;
// private final YxStoreOrderService storeOrderService;
// private final YxStorePinkService storePinkService;
//
// @Bean
// RedisMessageListenerContainer container(RedisConnectionFactory factory) {
// String topic =StrUtil.format("__keyevent@{}__:expired", redisConfigProperties.getDatabase());
// RedisMessageListenerContainer container = new RedisMessageListenerContainer();
// container.setConnectionFactory(factory);
// container.addMessageListener(new RedisKeyExpirationListener(redisTemplate,redisConfigProperties
// ,storeOrderService,storePinkService), new PatternTopic(topic));
// return container;
// }
//}
//

View File

@ -1,102 +0,0 @@
///**
// * Copyright (C) 2018-2020
// * All rights reserved, Designed By www.yixiang.co
// * 注意:
// * 本软件为www.yixiang.co开发研制未经购买不得使用
// * 购买后可获得全部源代码禁止转卖、分享、上传到码云、github等开源平台
// * 一经发现盗用、分享等行为,将追究法律责任,后果自负
// */
//package co.yixiang.listener;
//
//import cn.hutool.core.util.StrUtil;
//import co.yixiang.config.RedisConfigProperties;
//import co.yixiang.constant.ShopConstants;
//import co.yixiang.modules.activity.entity.YxStorePink;
//import co.yixiang.modules.activity.service.YxStorePinkService;
//import co.yixiang.modules.order.entity.YxStoreOrder;
//import co.yixiang.modules.order.service.YxStoreOrderService;
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
//import com.baomidou.mybatisplus.core.toolkit.Wrappers;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.data.redis.connection.Message;
//import org.springframework.data.redis.connection.MessageListener;
//import org.springframework.data.redis.core.RedisTemplate;
//import org.springframework.data.redis.serializer.RedisSerializer;
//import org.springframework.stereotype.Component;
//
///**
// * redis过期监听
// * @author hupeng
// * @since 2020-02-27
// */
//@Component
//@Slf4j
//public class RedisKeyExpirationListener implements MessageListener {
//
// private RedisTemplate<String, String> redisTemplate;
// private RedisConfigProperties redisConfigProperties;
// private YxStoreOrderService storeOrderService;
// private YxStorePinkService storePinkService;
//
// public RedisKeyExpirationListener(RedisTemplate<String, String> redisTemplate,
// RedisConfigProperties redisConfigProperties,
// YxStoreOrderService storeOrderService,
// YxStorePinkService storePinkService){
// this.redisTemplate = redisTemplate;
// this.redisConfigProperties = redisConfigProperties;
// this.storeOrderService = storeOrderService;
// this.storePinkService = storePinkService;
// }
// @Override
// public void onMessage(Message message, byte[] bytes) {
// RedisSerializer<?> serializer = redisTemplate.getValueSerializer();
// String channel = String.valueOf(serializer.deserialize(message.getChannel()));
// String body = String.valueOf(serializer.deserialize(message.getBody()));
// //key过期监听
// if(StrUtil.format("__keyevent@{}__:expired", redisConfigProperties.getDatabase()).equals(channel)){
// //订单自动取消
// if(body.contains(ShopConstants.REDIS_ORDER_OUTTIME_UNPAY)) {
// body = body.replace(ShopConstants.REDIS_ORDER_OUTTIME_UNPAY, "");
// log.info("body:{}",body);
// String orderId = body;
// YxStoreOrder order = storeOrderService.getOne(new QueryWrapper<YxStoreOrder>()
// .eq("id", orderId).eq("is_del",0).eq("paid",0));
// //只有待支付的订单能取消
// if(order != null){
// storeOrderService.cancelOrderByTask(Integer.valueOf(orderId));
//
// log.info("订单id:{},未在规定时间支付取消成功",body);
// }
// }
// //订单自动收货
// if(body.contains(ShopConstants.REDIS_ORDER_OUTTIME_UNCONFIRM)) {
// body = body.replace(ShopConstants.REDIS_ORDER_OUTTIME_UNCONFIRM, "");
// log.info("body:{}",body);
// String orderId = body;
// YxStoreOrder order = storeOrderService.getOne(new QueryWrapper<YxStoreOrder>()
// .eq("id", orderId).eq("is_del",0).eq("paid",1).eq("status",1));
// //只有待收货的订单能收货
// if(order != null){
// storeOrderService.takeOrder(order.getOrderId(),0);
// log.info("订单id:{},自动收货成功",body);
// }
// }
//
// //拼团过期取消
// if(body.contains(ShopConstants.REDIS_PINK_CANCEL_KEY)) {
// body = body.replace(ShopConstants.REDIS_PINK_CANCEL_KEY, "");
// log.info("body:{}",body);
// String pinkId = body;
// YxStorePink storePink = storePinkService.getOne(Wrappers.<YxStorePink>lambdaQuery()
// .eq(YxStorePink::getId,pinkId)
// .eq(YxStorePink::getStatus,1).eq(YxStorePink::getIsRefund,0));
// //取消拼团
// if(storePink != null){
// storePinkService.removePink(storePink.getUid(),storePink.getCid(),storePink.getId());
// log.info("拼团订单id:{},未在规定时间完成取消成功",body);
// }
// }
// }
//
// }
//}

View File

@ -1,54 +0,0 @@
//package co.yixiang.listener;
//
//import co.yixiang.enums.RedisKeyEnum;
//import co.yixiang.modules.shop.entity.YxSystemConfig;
//import co.yixiang.modules.shop.service.YxSystemConfigService;
//import lombok.RequiredArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.data.redis.core.RedisTemplate;
//import org.springframework.stereotype.Component;
//
//import javax.annotation.PostConstruct;
//import java.util.List;
//import java.util.stream.Collectors;
//import java.util.stream.Stream;
//
//
///**
// * api服务启动初始化reids
// */
//@Slf4j
//@Component
//@RequiredArgsConstructor(onConstructor = @__(@Autowired))
//public class RedisKeyInitialization {
//
//
// private final YxSystemConfigService systemConfigService;
//
// private final RedisTemplate<Object, Object> redisTemplate;
//
// @PostConstruct
// public void redisKeyInitialization(){
// try {
// List<RedisKeyEnum> redisKeyEnums = Stream.of(RedisKeyEnum.values()).collect(Collectors.toList());
// List<YxSystemConfig> systemConfigs = systemConfigService.list();
// for (RedisKeyEnum redisKeyEnum : redisKeyEnums) {
// Object redisKey = redisTemplate.opsForValue().get(redisKeyEnum.getValue());
// if(redisKey == null){
// String dbKey = "";
// for (YxSystemConfig systemConfig : systemConfigs) {
// if(systemConfig.getMenuName().equals(redisKeyEnum.getValue())){
// dbKey = systemConfig.getValue();
// }
// }
// redisTemplate.opsForValue().set(redisKeyEnum.getValue(),dbKey);
// }
// }
// log.info("---------------redisKey初始化成功---------------");
// }catch (Exception e){
// log.error("redisKey初始化失败: {}",e);
// }
//
// }
//}

View File

@ -12,7 +12,9 @@ import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import co.yixiang.api.ApiCode;
import co.yixiang.api.ApiResult;
import co.yixiang.api.UnAuthenticatedException;
import co.yixiang.api.YshopException;
import co.yixiang.common.enums.SmsTypeEnum;
import co.yixiang.common.util.JwtToken;
@ -35,9 +37,12 @@ import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
@ -57,16 +62,21 @@ public class AuthController {
private final RedisUtils redisUtil;
private final AuthService authService;
@Value("${single.login:false}")
private Boolean singleLogin;
/**
* 小程序登陆接口
*/
@PostMapping("/wxapp/auth")
@ApiOperation(value = "小程序登陆", notes = "小程序登陆")
public ApiResult<Map<String, Object>> login(@Validated @RequestBody LoginParam loginParam) {
public ApiResult<Map<String, Object>> login(@Validated @RequestBody LoginParam loginParam,
HttpServletRequest request) {
long uid = authService.wxappLogin(loginParam);
String token = JwtToken.makeToken(uid);
YxUser yxUser = authService.wxappLogin(loginParam);
String token = JwtToken.makeToken(yxUser.getUid());
String expiresTimeStr = JwtToken.getExpireTime(token);
// 返回 token
@ -75,6 +85,12 @@ public class AuthController {
map.put("token", token);
map.put("expires_time", expiresTimeStr);
// 保存在线信息
authService.save(yxUser, token, request);
if(singleLogin){
authService.checkLoginOnUser(yxUser.getUsername(),token);
}
return ApiResult.ok(map).setMsg("登陆成功");
@ -86,18 +102,26 @@ public class AuthController {
@GetMapping("/wechat/auth")
@ApiOperation(value = "微信公众号授权", notes = "微信公众号授权")
public ApiResult<Map<String, Object>> authLogin(@RequestParam(value = "code") String code,
@RequestParam(value = "spread") String spread) {
@RequestParam(value = "spread") String spread,
HttpServletRequest request) {
long uid = authService.wechatLogin(code,spread);
String token = JwtToken.makeToken(uid);
YxUser yxUser = authService.wechatLogin(code,spread);
String token = JwtToken.makeToken(yxUser.getUid());
String expiresTimeStr = JwtToken.getExpireTime(token);
// 返回 token
Map<String, Object> map = new HashMap<String, Object>(2) {{
put("token", token);
put("expires_time", expiresTimeStr);
}};
// 保存在线信息
authService.save(yxUser, token, request);
if(singleLogin){
authService.checkLoginOnUser(yxUser.getUsername(),token);
}
return ApiResult.ok(map).setMsg("登陆成功");
@ -107,7 +131,7 @@ public class AuthController {
@ApiOperation("H5登录授权")
@PostMapping(value = "/login")
public ApiResult<Map<String, Object>> login(@Validated @RequestBody HLoginParam loginDTO) {
public ApiResult<Map<String, Object>> login(@Validated @RequestBody HLoginParam loginDTO,HttpServletRequest request) {
YxUser yxUser = userService.getOne(Wrappers.<YxUser>lambdaQuery()
.eq(YxUser::getUsername,loginDTO.getUsername())
.eq(YxUser::getPassword,SecureUtil.md5(loginDTO.getPassword())),false);
@ -116,6 +140,9 @@ public class AuthController {
String token = JwtToken.makeToken(yxUser.getUid());
String expiresTimeStr = JwtToken.getExpireTime(token);
// 保存在线信息
authService.save(yxUser, token, request);
// 返回 token
Map<String, Object> map = new HashMap<String, Object>(2) {{
put("token", token);
@ -124,6 +151,11 @@ public class AuthController {
userService.setSpread(loginDTO.getSpread(),yxUser.getUid());
if(singleLogin){
//踢掉之前已经登录的token
authService.checkLoginOnUser(yxUser.getUsername(),token);
}
return ApiResult.ok(map).setMsg("登陆成功");
}
@ -192,7 +224,11 @@ public class AuthController {
@ApiOperation(value = "退出登录", notes = "退出登录")
@PostMapping(value = "/auth/logout")
public ApiResult<String> logout() {
public ApiResult<String> logout(HttpServletRequest request) {
String bearerToken = request.getHeader("Authorization");
String[] tokens = bearerToken.split(" ");
String token = tokens[1];
authService.logout(token);
return ApiResult.ok("退出成功");
}

View File

@ -9,7 +9,6 @@
package co.yixiang.modules.coupon.rest;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import co.yixiang.api.ApiResult;
import co.yixiang.api.YshopException;
import co.yixiang.common.aop.NoRepeatSubmit;
@ -17,6 +16,8 @@ import co.yixiang.common.bean.LocalUser;
import co.yixiang.common.interceptor.AuthCheck;
import co.yixiang.modules.activity.service.YxStoreCouponIssueService;
import co.yixiang.modules.activity.service.YxStoreCouponUserService;
import co.yixiang.modules.activity.vo.StoreCouponUserVo;
import co.yixiang.modules.activity.vo.YxStoreCouponIssueQueryVo;
import co.yixiang.modules.activity.vo.YxStoreCouponUserQueryVo;
import co.yixiang.modules.coupon.param.YxStoreCouponQueryParam;
import io.swagger.annotations.Api;
@ -52,10 +53,12 @@ public class CouponController {
@AuthCheck
@GetMapping("/coupons")
@ApiOperation(value = "可领取优惠券列表",notes = "可领取优惠券列表")
public ApiResult<Object> getList(@RequestParam(value = "page",defaultValue = "1") int page,
@RequestParam(value = "limit",defaultValue = "10") int limit){
public ApiResult<List<YxStoreCouponIssueQueryVo>> getList(@RequestParam(value = "page",defaultValue = "1") int page,
@RequestParam(value = "limit",defaultValue = "10") int limit,
@RequestParam(value = "productId",required = false) Long productId,
@RequestParam(value = "type",required = false) Integer type){
Long uid = LocalUser.getUser().getUid();
return ApiResult.ok(couponIssueService.getCouponList(page, limit,uid));
return ApiResult.ok(couponIssueService.getCouponList(page, limit,uid,productId,type));
}
/**
@ -91,12 +94,11 @@ public class CouponController {
* 优惠券 订单获取
*/
@AuthCheck
@GetMapping("/coupons/order/{price}")
@GetMapping("/coupons/order/{cartIds}")
@ApiOperation(value = "优惠券订单获取",notes = "优惠券订单获取")
public ApiResult<List<YxStoreCouponUserQueryVo>> orderCoupon(@PathVariable String price){
if(StrUtil.isBlank(price) || !NumberUtil.isNumber(price)) throw new YshopException("参数非法");
public ApiResult<List<StoreCouponUserVo>> orderCoupon(@PathVariable String cartIds){
Long uid = LocalUser.getUser().getUid();
return ApiResult.ok(storeCouponUserService.beUsableCouponList(uid,Double.valueOf(price)));
return ApiResult.ok(storeCouponUserService.beUsableCouponList(uid,cartIds));
}

View File

@ -15,6 +15,6 @@ import java.io.Serializable;
public class OrderPriceParam implements Serializable {
@NotBlank(message = "订单编号错误")
private String orderId;
@NotNull(message = "修改价格必填")
private Double price;
@NotBlank(message = "修改价格必填")
private String price;
}

View File

@ -32,6 +32,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.math.BigDecimal;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@ -143,7 +144,7 @@ public class ShoperController {
@PostMapping("/admin/order/refund")
@ApiOperation(value = "订单退款",notes = "订单退款")
public ApiResult<Boolean> orderRefund(@Validated @RequestBody OrderRefundParam param){
storeOrderService.orderRefund(param.getOrderId(),param.getPrice(),param.getType());
storeOrderService.orderRefund(param.getOrderId(),new BigDecimal(param.getPrice()),param.getType());
return ApiResult.ok();
}

View File

@ -16,7 +16,7 @@ public class OrderRefundParam implements Serializable {
@NotBlank(message = "订单编号错误")
private String orderId;
@NotNull(message = "退款金额必填")
private Double price;
private String price;
@NotNull(message = "参数错误")
private Integer type;
}

View File

@ -103,7 +103,8 @@ public class StoreOrderController {
ComputeVo computeVo = storeOrderService.computedOrder(yxUser,key,
param.getCouponId(),
param.getUseIntegral(),
param.getShippingType());
param.getShippingType(),
param.getAddressId());
map.put("result",computeVo);
map.put("status",OrderLogEnum.NONE_ORDER.getValue());

View File

@ -17,6 +17,7 @@ import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import co.yixiang.api.YshopException;
import co.yixiang.common.util.IpUtil;
import co.yixiang.common.util.JwtToken;
import co.yixiang.constant.ShopConstants;
import co.yixiang.enums.AppFromEnum;
import co.yixiang.modules.auth.param.LoginParam;
@ -24,21 +25,33 @@ import co.yixiang.modules.auth.param.RegParam;
import co.yixiang.modules.user.domain.YxUser;
import co.yixiang.modules.user.service.YxUserService;
import co.yixiang.modules.user.service.dto.WechatUserDto;
import co.yixiang.modules.user.vo.OnlineUser;
import co.yixiang.mp.config.WxMpConfiguration;
import co.yixiang.utils.EncryptUtils;
import co.yixiang.utils.RedisUtils;
import co.yixiang.utils.ShopKeyUtils;
import co.yixiang.utils.StringUtils;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.vdurmont.emoji.EmojiParser;
import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
import me.chanjar.weixin.mp.bean.result.WxMpUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
/**
* @ClassName 登陆认证服务类
* @Author hupeng <610796224@qq.com>
@ -46,12 +59,24 @@ import org.springframework.transaction.annotation.Transactional;
**/
@Slf4j
@Service
@AllArgsConstructor
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class AuthService {
private final YxUserService userService;
private final RedisUtils redisUtil;
private final WxMaService wxMaService;
private final RedisUtils redisUtils;
private static Integer expiredTimeIn;
@Value("${yshop.security.token-expired-in}")
public void setExpiredTimeIn(Integer expiredTimeIn) {
AuthService.expiredTimeIn = expiredTimeIn;
}
/**
* 小程序登陆
@ -59,7 +84,7 @@ public class AuthService {
* @return long
*/
@Transactional
public long wxappLogin(LoginParam loginParam) {
public YxUser wxappLogin(LoginParam loginParam) {
String code = loginParam.getCode();
String encryptedData = loginParam.getEncryptedData();
String iv = loginParam.getIv();
@ -80,7 +105,7 @@ public class AuthService {
WxMaUserInfo wxMpUser = wxMaService.getUserService()
.getUserInfo(session.getSessionKey(), encryptedData, iv);
String openid = wxMpUser.getOpenId();
long uid = 0;
YxUser returnUser = null;
//如果开启了UnionId
if (StrUtil.isNotBlank(wxMpUser.getUnionId())) {
openid = wxMpUser.getUnionId();
@ -117,27 +142,26 @@ public class AuthService {
.headimgurl(wxMpUser.getAvatarUrl())
.build();
user.setWxProfile(JSON.toJSONString(wechatUserDTO));
user.setWxProfile(wechatUserDTO);
userService.save(user);
uid = user.getUid();
returnUser = user;
} else {
uid = yxUser.getUid();
WechatUserDto wechatUser = JSON.parseObject(yxUser.getWxProfile(), WechatUserDto.class);
returnUser = yxUser;
WechatUserDto wechatUser =yxUser.getWxProfile();
if ((StrUtil.isBlank(wechatUser.getOpenid()) && StrUtil.isNotBlank(wxMpUser.getOpenId()))
|| (StrUtil.isBlank(wechatUser.getUnionId()) && StrUtil.isNotBlank(wxMpUser.getUnionId()))) {
wechatUser.setRoutineOpenid(wxMpUser.getOpenId());
wechatUser.setUnionId(wxMpUser.getUnionId());
yxUser.setWxProfile(JSON.toJSONString(wechatUser));
yxUser.setWxProfile(wechatUser);
userService.updateById(yxUser);
}
}
userService.setSpread(spread, uid);
return uid;
userService.setSpread(spread, returnUser.getUid());
return returnUser;
} catch (WxErrorException e) {
e.printStackTrace();
log.error(e.getMessage());
@ -154,7 +178,7 @@ public class AuthService {
* @return uid
*/
@Transactional
public long wechatLogin(String code,String spread){
public YxUser wechatLogin(String code,String spread){
try {
WxMpService wxService = WxMpConfiguration.getWxMpService();
WxMpOAuth2AccessToken wxMpOAuth2AccessToken = wxService.oauth2getAccessToken(code);
@ -169,8 +193,8 @@ public class AuthService {
YxUser yxUser = userService.getOne(Wrappers.<YxUser>lambdaQuery()
.eq(YxUser::getUsername,openid),false);
long uid = 0;
//long uid = 0;
YxUser returnUser = null;
if(yxUser == null){
//过滤掉表情
String nickname = EmojiParser.removeAllEmojis(wxMpUser.getNickname());
@ -201,27 +225,27 @@ public class AuthService {
.subscribeTime(wxMpUser.getSubscribeTime())
.build();
user.setWxProfile(JSON.toJSONString(wechatUserDTO));
user.setWxProfile(wechatUserDTO);
userService.save(user);
uid = user.getUid();
returnUser = user;
}else{
uid = yxUser.getUid();
WechatUserDto wechatUser = JSON.parseObject(yxUser.getWxProfile(), WechatUserDto.class);
returnUser = yxUser;
WechatUserDto wechatUser = yxUser.getWxProfile();
if((StrUtil.isBlank(wechatUser.getOpenid()) && StrUtil.isNotBlank(wxMpUser.getOpenId()))
|| (StrUtil.isBlank(wechatUser.getUnionId()) && StrUtil.isNotBlank(wxMpUser.getUnionId()))){
wechatUser.setOpenid(wxMpUser.getOpenId());
wechatUser.setUnionId(wxMpUser.getUnionId());
yxUser.setWxProfile(JSON.toJSONString(wechatUser));
yxUser.setWxProfile(wechatUser);
userService.updateById(yxUser);
}
}
userService.setSpread(spread,uid);
userService.setSpread(spread,returnUser.getUid());
return uid;
return returnUser;
} catch (WxErrorException e) {
e.printStackTrace();
@ -256,4 +280,98 @@ public class AuthService {
}
/**
* 保存在线用户信息
* @param yxUser /
* @param token /
* @param request /
*/
public void save(YxUser yxUser, String token, HttpServletRequest request){
String job = "yshop开发工程师";
String ip = StringUtils.getIp(request);
String browser = StringUtils.getBrowser(request);
String address = StringUtils.getCityInfo(ip);
OnlineUser onlineUser = null;
try {
onlineUser = new OnlineUser(yxUser.getUsername(), yxUser.getNickname(), job, browser ,
ip, address, EncryptUtils.desEncrypt(token), new Date());
} catch (Exception e) {
e.printStackTrace();
}
redisUtils.set(ShopConstants.YSHOP_APP_LOGIN_USER + token, onlineUser, AuthService.expiredTimeIn);
}
/**
* 检测用户是否在之前已经登录,已经登录踢下线
* @param userName 用户名
*/
public void checkLoginOnUser(String userName, String igoreToken){
List<OnlineUser> onlineUsers = this.getAll(userName);
if(onlineUsers ==null || onlineUsers.isEmpty()){
return;
}
System.out.println("onlineUsers:"+onlineUsers);
for(OnlineUser onlineUser:onlineUsers){
if(onlineUser.getUserName().equals(userName)){
try {
String token = EncryptUtils.desDecrypt(onlineUser.getKey());
if(StringUtils.isNotBlank(igoreToken)&&!igoreToken.equals(token)){
this.kickOut(onlineUser.getKey());
}else if(StringUtils.isBlank(igoreToken)){
this.kickOut(onlineUser.getKey());
}
} catch (Exception e) {
log.error("checkUser is error",e);
}
}
}
}
/**
* 踢出用户
* @param key /
*/
public void kickOut(String key) throws Exception {
key = ShopConstants.YSHOP_APP_LOGIN_USER + EncryptUtils.desDecrypt(key);
redisUtils.del(key);
}
/**
* 退出登录
* @param token /
*/
public void logout(String token) {
String key = ShopConstants.YSHOP_APP_LOGIN_USER + token;
redisUtils.del(key);
}
/**
* 查询全部数据,不分页
* @param filter /
* @return /
*/
private List<OnlineUser> getAll(String filter){
List<String> keys = null;
keys = redisUtils.scan(ShopConstants.YSHOP_APP_LOGIN_USER + "*");
Collections.reverse(keys);
List<OnlineUser> onlineUsers = new ArrayList<>();
for (String key : keys) {
OnlineUser onlineUser = (OnlineUser) redisUtils.get(key);
if(StringUtils.isNotBlank(filter)){
if(onlineUser.toString().contains(filter)){
onlineUsers.add(onlineUser);
}
} else {
onlineUsers.add(onlineUser);
}
}
onlineUsers.sort((o1, o2) -> o2.getLoginTime().compareTo(o1.getLoginTime()));
return onlineUsers;
}
}

View File

@ -33,6 +33,7 @@ import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
@ -59,7 +60,7 @@ public class IndexController {
private final YxSystemStoreService systemStoreService;
//@Cacheable(cacheNames = ShopConstants.YSHOP_REDIS_INDEX_KEY)
@Cacheable(cacheNames = ShopConstants.YSHOP_REDIS_INDEX_KEY)
@GetMapping("/index")
@ApiOperation(value = "首页数据",notes = "首页数据")
public ApiResult<Map<String,Object>> index(){

View File

@ -15,21 +15,28 @@ import co.yixiang.api.ApiResult;
import co.yixiang.api.YshopException;
import co.yixiang.common.bean.LocalUser;
import co.yixiang.common.interceptor.AuthCheck;
import co.yixiang.common.util.CityTreeUtil;
import co.yixiang.common.web.param.IdParam;
import co.yixiang.constant.ShopConstants;
import co.yixiang.logging.aop.log.Log;
import co.yixiang.modules.template.domain.YxSystemCity;
import co.yixiang.modules.template.service.YxSystemCityService;
import co.yixiang.modules.user.domain.YxUserAddress;
import co.yixiang.modules.user.service.YxUserAddressService;
import co.yixiang.modules.user.param.AddressParam;
import co.yixiang.modules.user.param.YxUserAddressQueryParam;
import co.yixiang.modules.user.vo.CityVo;
import co.yixiang.modules.user.vo.YxUserAddressQueryVo;
import co.yixiang.utils.OrderUtil;
import co.yixiang.utils.SecurityUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.common.collect.Lists;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
@ -52,6 +59,31 @@ import java.util.Map;
public class UserAddressController {
private final YxUserAddressService userAddressService;
private final YxSystemCityService systemCityService;
@Cacheable(cacheNames = ShopConstants.YSHOP_REDIS_CITY_KEY)
@GetMapping("/city_list")
@ApiOperation(value = "城市列表",notes = "城市列表")
public ApiResult<List<CityVo>> getTest() {
List<YxSystemCity> yxSystemCities = systemCityService.list();
List<CityVo> cityVOS = Lists.newArrayList();
for (YxSystemCity systemCity : yxSystemCities){
CityVo cityVO = new CityVo();
cityVO.setV(systemCity.getCityId());
cityVO.setN(systemCity.getName());
cityVO.setPid(systemCity.getParentId());
cityVOS.add(cityVO);
}
return ApiResult.ok(CityTreeUtil.list2TreeConverter(cityVOS, 0));
}
/**
* 添加或修改地址

View File

@ -87,26 +87,7 @@ public class UserController {
return ApiResult.ok(map);
}
// /**
// * 个人中心
// */
// @GetMapping("/user")
// @ApiOperation(value = "个人中心",notes = "个人中心")
// public ApiResult<Object> user(){
// int uid = SecurityUtils.getUserId().intValue();
// YxUserQueryVo yxUserQueryVo = yxUserService.getNewYxUserById(uid);
//
//
// if(yxUserQueryVo.getLevel() > 0) {
// yxUserQueryVo.setVip(true);
// YxSystemUserLevelQueryVo systemUserLevelQueryVo = systemUserLevelService
// .getYxSystemUserLevelById(yxUserQueryVo.getLevel());
// yxUserQueryVo.setVipIcon(systemUserLevelQueryVo.getIcon());
// yxUserQueryVo.setVipId(yxUserQueryVo.getLevel());
// yxUserQueryVo.setVipName(systemUserLevelQueryVo.getName());
// }
// return ApiResult.ok(yxUserQueryVo);
// }
/**
* 订单统计数据

View File

@ -48,7 +48,7 @@ spring:
multi-statement-allow: true
redis:
host: localhost # Redis服务器地址
database: 0 # Redis数据库索引默认为0
database: 2 # Redis数据库索引默认为0
port: 6379 # Redis服务器连接端口
password: # Redis服务器连接密码默认为空
jedis:

View File

@ -5,9 +5,9 @@ spring:
druid:
# 主库数据源
master:
url: jdbc:mysql://localhost:3306/yxshop?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: root
password: root
url: jdbc:mysql://localhost:3306/yshop3?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: yshop3
password:
# 从库数据源
slave:
# 从数据源开关/默认关闭
@ -47,10 +47,10 @@ spring:
config:
multi-statement-allow: true
redis:
host: localhost # Redis服务器地址
database: 0 # Redis数据库索引默认为0
host: 127.0.0.1 # Redis服务器地址
database: 2 # Redis数据库索引默认为0
port: 6379 # Redis服务器连接端口
password: # Redis服务器连接密码默认为空
password: # Redis服务器连接密码默认为空
jedis:
pool:
max-active: 8 # 连接池最大连接数(使用负值表示没有限制)
@ -81,7 +81,7 @@ yshop:
#是否开启 swagger-ui生产环境默认不开启
swagger:
enabled: false
enabled: true
title: yshop商城移动端API
serverUrl: http://localhost:8009
version: 3.0

View File

@ -1,5 +1,5 @@
server:
port: 8009
port: 8008
servlet:
context-path: /api
tomcat: