Compare commits
2 Commits
56c69c3ff8
...
11226f53ea
Author | SHA1 | Date | |
---|---|---|---|
11226f53ea | |||
2e2b5d4cdc |
@ -0,0 +1,25 @@
|
||||
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));
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
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";
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package me.xiaoyan.point.api.pojo.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class GoodsQueryParam extends PageParam {
|
||||
private String title;
|
||||
private int category;
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
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();
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
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,6 +3,7 @@ package me.xiaoyan.point.api.service;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import me.xiaoyan.point.api.pojo.Goods;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import me.xiaoyan.point.api.pojo.vo.GoodsQueryParam;
|
||||
import me.xiaoyan.point.api.pojo.vo.PageParam;
|
||||
|
||||
import java.util.List;
|
||||
@ -13,6 +14,7 @@ import java.util.List;
|
||||
public interface GoodsService extends IService<Goods> {
|
||||
|
||||
Page<Goods> queryByPage(int category, Page page);
|
||||
Page<Goods> queryByPage(GoodsQueryParam page);
|
||||
|
||||
/**
|
||||
* 减库存
|
||||
|
@ -1,11 +1,14 @@
|
||||
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.service.impl.ServiceImpl;
|
||||
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.mapper.GoodsMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -21,9 +24,19 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods>
|
||||
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
|
||||
public boolean deductStock(int id, int count) {
|
||||
return getBaseMapper().deductCount(id,count) == 1;
|
||||
return getBaseMapper().deductCount(id, count) == 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -9,11 +9,8 @@ import me.xiaoyan.point.api.pojo.OrderInfo;
|
||||
import me.xiaoyan.point.api.pojo.UserInfo;
|
||||
import me.xiaoyan.point.api.pojo.dto.OrderStatus;
|
||||
import me.xiaoyan.point.api.pojo.vo.CreateOrderData;
|
||||
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.service.*;
|
||||
import me.xiaoyan.point.api.util.OrderIdGenerator;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@ -33,6 +30,8 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
||||
private UserInfoService userInfoService;
|
||||
@Resource
|
||||
private GoodsService goodsService;
|
||||
@Resource
|
||||
private PointRecordService pointRecordService;
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
@ -49,12 +48,17 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
||||
if (goods.getOnlineTime().getTime() > now || goods.getOfflineTime().getTime() < now) {
|
||||
throw BizException.create("商品未上架或已下架");
|
||||
}
|
||||
// TODO 需要判断积分
|
||||
if (goods.getStock() < data.getBuyCount()) throw BizException.create("商品存库不足");
|
||||
// 判断购买数量的限制
|
||||
if(goods.getLimitCount() > 0 && buyHistoryCount(uid,data.getGoodsId()) + data.getBuyCount() > goods.getLimitCount()){
|
||||
throw BizException.create("最多兑换" + goods.getLimitCount() + "件");
|
||||
// 需要判断积分
|
||||
if (goods.getPrice() > 0 && user.getPointInfo().getTotalPoint() < goods.getPrice()) {
|
||||
throw BizException.create("积分不足,兑换失败");
|
||||
}
|
||||
// 判断购买数量的限制
|
||||
if (goods.getLimitCount() > 0 && buyHistoryCount(uid, data.getGoodsId()) + data.getBuyCount() > goods.getLimitCount()) {
|
||||
throw BizException.create("最多兑换" + goods.getLimitCount() + "件");
|
||||
}
|
||||
// 扣减积分
|
||||
pointRecordService.record(uid, 0 - goods.getPrice(), "兑换商品 " + goods.getTitle());
|
||||
// 3.减库存
|
||||
if (!goodsService.deductStock(data.getGoodsId(), data.getBuyCount())) {
|
||||
throw BizException.create("商品库存不足");
|
||||
|
Loading…
x
Reference in New Issue
Block a user