Compare commits
No commits in common. "11226f53eaa531332ee8548e0a4ccf34deb8871b" and "56c69c3ff873ae14ed06ecd07df881c6b9f93b8b" have entirely different histories.
11226f53ea
...
56c69c3ff8
@ -1,25 +0,0 @@
|
|||||||
package me.xiaoyan.point.api.controller.admin;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
||||||
import me.xiaoyan.point.api.pojo.vo.GoodsQueryParam;
|
|
||||||
import me.xiaoyan.point.api.pojo.vo.PageDataResult;
|
|
||||||
import me.xiaoyan.point.api.pojo.vo.PageParam;
|
|
||||||
import me.xiaoyan.point.api.service.GoodsService;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("admin/goods")
|
|
||||||
public class GoodsAdminController {
|
|
||||||
@Resource
|
|
||||||
private GoodsService goodsService;
|
|
||||||
|
|
||||||
@PostMapping("/list")
|
|
||||||
public PageDataResult list(@RequestBody GoodsQueryParam param) {
|
|
||||||
return PageDataResult.convert(goodsService.queryByPage(param));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,60 +0,0 @@
|
|||||||
package me.xiaoyan.point.api.controller.admin;
|
|
||||||
|
|
||||||
import cn.dev33.satoken.stp.StpUtil;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import me.xiaoyan.point.api.error.BizException;
|
|
||||||
import me.xiaoyan.point.api.pojo.vo.UserAdminInfo;
|
|
||||||
import org.springframework.validation.annotation.Validated;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("admin/user")
|
|
||||||
@Slf4j
|
|
||||||
public class UserAdminController {
|
|
||||||
private HashMap<String, UserAdminInfo> userStoreMap = new HashMap<>();
|
|
||||||
|
|
||||||
@PostConstruct
|
|
||||||
public void initUserStore() {
|
|
||||||
log.info("初始化用户数据");
|
|
||||||
userStoreMap.put("admin", UserAdminInfo.create(1, "admin", "admin"));
|
|
||||||
userStoreMap.put("test", UserAdminInfo.create(2, "test", "123123"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("login")
|
|
||||||
public UserAdminInfo login(@Validated @RequestBody UserAdminInfo user) {
|
|
||||||
// 判断是否存在账号
|
|
||||||
if (!userStoreMap.containsKey(user.getAccount())) {
|
|
||||||
throw BizException.create("账号不存在");
|
|
||||||
}
|
|
||||||
// 获取到用户数据
|
|
||||||
UserAdminInfo admin = userStoreMap.get(user.getAccount());
|
|
||||||
// 判断密码
|
|
||||||
if (!admin.getPassword().equals(user.getPassword())) {
|
|
||||||
throw BizException.create("密码不正确");
|
|
||||||
}
|
|
||||||
user.setId(admin.getId());
|
|
||||||
user.setPassword("");
|
|
||||||
StpUtil.login(user.getId(), "admin");
|
|
||||||
user.setToken(StpUtil.getTokenInfo().getTokenValue());
|
|
||||||
StpUtil.getSession().set("user", user);
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
|
|
||||||
@RequestMapping("info")
|
|
||||||
public UserAdminInfo info() {
|
|
||||||
return (UserAdminInfo) StpUtil.getSession().get("user");
|
|
||||||
}
|
|
||||||
|
|
||||||
@RequestMapping("logout")
|
|
||||||
public String logout() {
|
|
||||||
StpUtil.logout();
|
|
||||||
return "ok";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
package me.xiaoyan.point.api.pojo.vo;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class GoodsQueryParam extends PageParam {
|
|
||||||
private String title;
|
|
||||||
private int category;
|
|
||||||
}
|
|
@ -1,26 +0,0 @@
|
|||||||
package me.xiaoyan.point.api.pojo.vo;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@AllArgsConstructor
|
|
||||||
@NoArgsConstructor
|
|
||||||
@Builder
|
|
||||||
public class PageDataResult<T> implements Serializable {
|
|
||||||
private List<T> items;
|
|
||||||
private long total;
|
|
||||||
|
|
||||||
public static PageDataResult convert(Page result) {
|
|
||||||
return PageDataResult.builder()
|
|
||||||
.items(result.getRecords())
|
|
||||||
.total(result.getTotal())
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,25 +0,0 @@
|
|||||||
package me.xiaoyan.point.api.pojo.vo;
|
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
import javax.validation.constraints.NotEmpty;
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@AllArgsConstructor
|
|
||||||
@NoArgsConstructor
|
|
||||||
@Builder
|
|
||||||
public class UserAdminInfo implements Serializable {
|
|
||||||
private int id;
|
|
||||||
@NotEmpty(message = "账号不允许为空")
|
|
||||||
private String account;
|
|
||||||
@NotEmpty(message = "密码不允许为空")
|
|
||||||
private String password;
|
|
||||||
private String token;
|
|
||||||
public static UserAdminInfo create(int id,String acc,String pwd){
|
|
||||||
return new UserAdminInfo(id,acc,pwd,null);
|
|
||||||
}
|
|
||||||
}
|
|
@ -3,7 +3,6 @@ package me.xiaoyan.point.api.service;
|
|||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import me.xiaoyan.point.api.pojo.Goods;
|
import me.xiaoyan.point.api.pojo.Goods;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import me.xiaoyan.point.api.pojo.vo.GoodsQueryParam;
|
|
||||||
import me.xiaoyan.point.api.pojo.vo.PageParam;
|
import me.xiaoyan.point.api.pojo.vo.PageParam;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -14,7 +13,6 @@ import java.util.List;
|
|||||||
public interface GoodsService extends IService<Goods> {
|
public interface GoodsService extends IService<Goods> {
|
||||||
|
|
||||||
Page<Goods> queryByPage(int category, Page page);
|
Page<Goods> queryByPage(int category, Page page);
|
||||||
Page<Goods> queryByPage(GoodsQueryParam page);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 减库存
|
* 减库存
|
||||||
|
@ -1,14 +1,11 @@
|
|||||||
package me.xiaoyan.point.api.service.impl;
|
package me.xiaoyan.point.api.service.impl;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import me.xiaoyan.point.api.pojo.Goods;
|
import me.xiaoyan.point.api.pojo.Goods;
|
||||||
import me.xiaoyan.point.api.pojo.vo.GoodsQueryParam;
|
|
||||||
import me.xiaoyan.point.api.service.GoodsService;
|
import me.xiaoyan.point.api.service.GoodsService;
|
||||||
import me.xiaoyan.point.api.mapper.GoodsMapper;
|
import me.xiaoyan.point.api.mapper.GoodsMapper;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -24,19 +21,9 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods>
|
|||||||
return this.getBaseMapper().queryByCategory(category, page);
|
return this.getBaseMapper().queryByCategory(category, page);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Page<Goods> queryByPage(GoodsQueryParam param) {
|
|
||||||
QueryWrapper q = new QueryWrapper();
|
|
||||||
// 查询标题
|
|
||||||
if (StringUtils.hasText(param.getTitle())) {
|
|
||||||
q.eq("title", param.getTitle().trim());
|
|
||||||
}
|
|
||||||
return getBaseMapper().selectPage(param.getPage(), q);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean deductStock(int id, int count) {
|
public boolean deductStock(int id, int count) {
|
||||||
return getBaseMapper().deductCount(id, count) == 1;
|
return getBaseMapper().deductCount(id,count) == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -9,8 +9,11 @@ import me.xiaoyan.point.api.pojo.OrderInfo;
|
|||||||
import me.xiaoyan.point.api.pojo.UserInfo;
|
import me.xiaoyan.point.api.pojo.UserInfo;
|
||||||
import me.xiaoyan.point.api.pojo.dto.OrderStatus;
|
import me.xiaoyan.point.api.pojo.dto.OrderStatus;
|
||||||
import me.xiaoyan.point.api.pojo.vo.CreateOrderData;
|
import me.xiaoyan.point.api.pojo.vo.CreateOrderData;
|
||||||
import me.xiaoyan.point.api.service.*;
|
import me.xiaoyan.point.api.service.GoodsService;
|
||||||
|
import me.xiaoyan.point.api.service.OrderInfoService;
|
||||||
|
import me.xiaoyan.point.api.service.UserInfoService;
|
||||||
import me.xiaoyan.point.api.util.OrderIdGenerator;
|
import me.xiaoyan.point.api.util.OrderIdGenerator;
|
||||||
|
import org.springframework.core.annotation.Order;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
@ -30,8 +33,6 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
|||||||
private UserInfoService userInfoService;
|
private UserInfoService userInfoService;
|
||||||
@Resource
|
@Resource
|
||||||
private GoodsService goodsService;
|
private GoodsService goodsService;
|
||||||
@Resource
|
|
||||||
private PointRecordService pointRecordService;
|
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
@ -48,17 +49,12 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
|||||||
if (goods.getOnlineTime().getTime() > now || goods.getOfflineTime().getTime() < now) {
|
if (goods.getOnlineTime().getTime() > now || goods.getOfflineTime().getTime() < now) {
|
||||||
throw BizException.create("商品未上架或已下架");
|
throw BizException.create("商品未上架或已下架");
|
||||||
}
|
}
|
||||||
|
// TODO 需要判断积分
|
||||||
if (goods.getStock() < data.getBuyCount()) throw BizException.create("商品存库不足");
|
if (goods.getStock() < data.getBuyCount()) throw BizException.create("商品存库不足");
|
||||||
// 需要判断积分
|
|
||||||
if (goods.getPrice() > 0 && user.getPointInfo().getTotalPoint() < goods.getPrice()) {
|
|
||||||
throw BizException.create("积分不足,兑换失败");
|
|
||||||
}
|
|
||||||
// 判断购买数量的限制
|
// 判断购买数量的限制
|
||||||
if (goods.getLimitCount() > 0 && buyHistoryCount(uid, data.getGoodsId()) + data.getBuyCount() > goods.getLimitCount()) {
|
if(goods.getLimitCount() > 0 && buyHistoryCount(uid,data.getGoodsId()) + data.getBuyCount() > goods.getLimitCount()){
|
||||||
throw BizException.create("最多兑换" + goods.getLimitCount() + "件");
|
throw BizException.create("最多兑换" + goods.getLimitCount() + "件");
|
||||||
}
|
}
|
||||||
// 扣减积分
|
|
||||||
pointRecordService.record(uid, 0 - goods.getPrice(), "兑换商品 " + goods.getTitle());
|
|
||||||
// 3.减库存
|
// 3.减库存
|
||||||
if (!goodsService.deductStock(data.getGoodsId(), data.getBuyCount())) {
|
if (!goodsService.deductStock(data.getGoodsId(), data.getBuyCount())) {
|
||||||
throw BizException.create("商品库存不足");
|
throw BizException.create("商品库存不足");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user