3.4 商品购买模块
3.5 超市账单模块
四、部分源码展示
4.1 实体类定义
商品实体类:
@Table(name = "a_product") @TableName("a_product") @ApiModel(value = "商品") public class Product extends ZwzBaseEntity { private static final long serialVersionUID = 1L; @ApiModelProperty(value = "商品名称") private String title; @ApiModelProperty(value = "商品类型") private String type; @ApiModelProperty(value = "销售价") private BigDecimal price; @ApiModelProperty(value = "图片") private String image; @ApiModelProperty(value = "供应商") private String supplier; @Transient @TableField(exist=false) @ApiModelProperty(value = "购买数量") private BigDecimal number; }
商品类型实体类:
@Table(name = "a_product_type") @TableName("a_product_type") @ApiModel(value = "商品类型") public class ProductType extends ZwzBaseEntity { private static final long serialVersionUID = 1L; @ApiModelProperty(value = "类型名称") private String title; @ApiModelProperty(value = "类型状态") private String status; @ApiModelProperty(value = "排序值") private BigDecimal sortOrder; @ApiModelProperty(value = "备注") private String remark; }
4.2 控制器接口
查询我发布的商品:
@RequestMapping(value = "/getSellPage", method = RequestMethod.GET) @ApiOperation(value = "查询商品") public Result<IPage<Product>> getSellPage(@ModelAttribute Product product,@ModelAttribute PageVo page){ QueryWrapper<Product> qw = new QueryWrapper<>(); User currUser = securityUtil.getCurrUser(); QueryWrapper<SupermarketBill> billQw = new QueryWrapper<>(); billQw.eq("user_id",currUser.getId()); billQw.eq("status","未付款"); List<SupermarketBill> billList = iSupermarketBillService.list(billQw); if(!ZwzNullUtils.isNull(product.getTitle())) { qw.like("title",product.getTitle()); } if(!ZwzNullUtils.isNull(product.getType())) { qw.eq("type",product.getType()); } IPage<Product> data = iProductService.page(PageUtil.initMpPage(page),qw); for (Product vo : data.getRecords()) { vo.setNumber(BigDecimal.ZERO); } for (Product vo : data.getRecords()) { for (SupermarketBill bill : billList) { if(Objects.equals(vo.getId(),bill.getProductId())) { vo.setNumber(vo.getNumber().add(bill.getNumber())); } } } return new ResultUtil<IPage<Product>>().setData(data); }
商品下单:
@RequestMapping(value = "/addOne", method = RequestMethod.GET) @ApiOperation(value = "下单") public Result<Object> addOne(@RequestParam String id){ Product p = iProductService.getById(id); if(p == null) { return ResultUtil.error("商品不存在"); } User currUser = securityUtil.getCurrUser(); /** * 判断是否下单 */ QueryWrapper<SupermarketBill> billQw = new QueryWrapper<>(); billQw.eq("product_id",id); billQw.eq("user_id",currUser.getId()); billQw.eq("status","未付款"); billQw.last("limit 1"); SupermarketBill bill = iSupermarketBillService.getOne(billQw); if(bill != null) { bill.setNumber(bill.getNumber().add(BigDecimal.ONE)); bill.setSum(bill.getPrice().multiply(bill.getNumber())); iSupermarketBillService.saveOrUpdate(bill); return ResultUtil.success(); } /** * 下单 */ SupermarketBill b = new SupermarketBill(); b.setProductId(p.getId()); b.setProductName(p.getTitle()); b.setProductImage(p.getImage()); b.setUserId(currUser.getId()); b.setUserName(currUser.getNickname()); b.setPrice(p.getPrice()); b.setNumber(BigDecimal.ONE); b.setSum(p.getPrice()); b.setStatus("未付款"); iSupermarketBillService.saveOrUpdate(b); return ResultUtil.success(); }
五、配套文档展示
六、免责说明
- 本项目仅供个人学习使用,商用授权请联系博主,否则后果自负。
- 博主拥有本软件构建后的应用系统全部内容所有权及独立的知识产权,拥有最终解释权。
- 如有问题,欢迎在仓库 Issue 留言,看到后会第一时间回复,相关意见会酌情考虑,但没有一定被采纳的承诺或保证。
下载本系统代码或使用本系统的用户,必须同意以下内容,否则请勿下载!
- 出于自愿而使用/开发本软件,了解使用本软件的风险,且同意自己承担使用本软件的风险。
- 利用本软件构建的网站的任何信息内容以及导致的任何版权纠纷和法律争议及后果和博主无关,博主对此不承担任何责任。
- 在任何情况下,对于因使用或无法使用本软件而导致的任何难以合理预估的损失(包括但不仅限于商业利润损失、业务中断与业务信息丢失),博主概不承担任何责任。
- 必须了解使用本软件的风险,博主不承诺提供一对一的技术支持、使用担保,也不承担任何因本软件而产生的难以预料的问题的相关责任。