| | |
| | | package com.matrix.system.app.action; |
| | | |
| | | import com.matrix.core.constance.MatrixConstance; |
| | | import com.matrix.core.exception.GlobleException; |
| | | import com.matrix.core.pojo.AjaxResult; |
| | | import com.matrix.core.pojo.PaginationVO; |
| | | import com.matrix.core.tools.WebUtil; |
| | | import com.matrix.system.app.dto.CreateOderItemDto; |
| | | import com.matrix.system.app.dto.CreateOrderDto; |
| | | import com.matrix.system.app.dto.OrderListDto; |
| | | import com.matrix.system.app.dto.ShoppingGoodsListDto; |
| | | import com.matrix.system.app.vo.OrderDetailVo; |
| | | import com.matrix.system.app.vo.ShoppingGoodsDetailVo; |
| | | import com.matrix.system.app.vo.ShoppingGoodsListVo; |
| | | import com.matrix.system.common.bean.SysUsers; |
| | | import com.matrix.system.common.tools.DataAuthUtil; |
| | | import com.matrix.system.hive.bean.ShoppingGoodsCategory; |
| | | import com.matrix.system.hive.bean.SysOrder; |
| | | import com.matrix.system.hive.plugin.util.CollectionUtils; |
| | | import com.matrix.system.hive.pojo.ShoppingCarItem; |
| | | import com.matrix.system.hive.pojo.ShoppingCarItemsVo; |
| | | import com.matrix.system.hive.service.ShoppingGoodsCategoryService; |
| | | import com.matrix.system.hive.service.ShoppingGoodsService; |
| | | import com.matrix.system.hive.service.SysOrderService; |
| | | import io.swagger.annotations.Api; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import io.swagger.annotations.ApiResponse; |
| | | import io.swagger.annotations.ApiResponses; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @author wzy |
| | | * @date 2020-12-21 |
| | | **/ |
| | | @Api(value = "ApiOrderAction", tags = "订单接口类") |
| | | @RestController |
| | | @RequestMapping(value = "/api/order") |
| | | public class ApiOrderAction { |
| | | |
| | | @Autowired |
| | | private ShoppingGoodsCategoryService shoppingGoodsCategoryService; |
| | | |
| | | @Autowired |
| | | private ShoppingGoodsService shoppingGoodsService; |
| | | |
| | | @Autowired |
| | | private SysOrderService sysOrderService; |
| | | |
| | | @ApiOperation(value = "获取商品类型列表", notes = "获取商品类型列表") |
| | | @ApiResponses({ |
| | | @ApiResponse(code = 200, message = "ok", response = ShoppingGoodsCategory.class) |
| | | }) |
| | | @GetMapping(value = "/findShoppingGoodsType") |
| | | public AjaxResult findShoppingGoodsType() { |
| | | return null; |
| | | SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); |
| | | |
| | | ShoppingGoodsCategory category = new ShoppingGoodsCategory(); |
| | | category.setShopId(user.getShopId()); |
| | | return AjaxResult.buildSuccessInstance(shoppingGoodsCategoryService.findByModel(category)); |
| | | } |
| | | |
| | | public AjaxResult findShoppingGoods() { |
| | | return null; |
| | | @ApiOperation(value = "获取商品列表", notes = "获取商品列表") |
| | | @ApiResponses({ |
| | | @ApiResponse(code = 200, message = "ok", response = ShoppingGoodsListVo.class) |
| | | }) |
| | | @PostMapping(value = "/findShoppingGoods") |
| | | public AjaxResult findShoppingGoods(@RequestBody @Validated ShoppingGoodsListDto shoppingGoodsListDto) { |
| | | |
| | | return AjaxResult.buildSuccessInstance(shoppingGoodsService.findShoppingGoodsListForApi(shoppingGoodsListDto), shoppingGoodsService.findShoppingGoodsListTotalForApi(shoppingGoodsListDto)); |
| | | } |
| | | |
| | | |
| | | @ApiOperation(value = "获取商品详情", notes = "获取商品详情") |
| | | @ApiResponses({ |
| | | @ApiResponse(code = 200, message = "ok", response = ShoppingGoodsDetailVo.class) |
| | | }) |
| | | @GetMapping(value = "/findGoodsDetailById/{goodsId}") |
| | | public AjaxResult findGoodsDetailById(@PathVariable("goodsId") Long goodsId) { |
| | | ShoppingGoodsDetailVo goodsDetail = shoppingGoodsService.findApiShoppingGoodsDetailById(goodsId); |
| | | AjaxResult ajaxResult = AjaxResult.buildSuccessInstance("获取成功"); |
| | | ajaxResult.putInMap("goods", goodsDetail); |
| | | return ajaxResult; |
| | | } |
| | | |
| | | |
| | | @ApiOperation(value = "创建订单", notes = "创建订单") |
| | | @PostMapping(value = "/createOrder") |
| | | public AjaxResult createOrder() { |
| | | return null; |
| | | public AjaxResult createOrder(@RequestBody @Validated CreateOrderDto createOrderDto) { |
| | | SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); |
| | | |
| | | ShoppingCarItemsVo car = new ShoppingCarItemsVo(); |
| | | car.setVipId(createOrderDto.getVipId()); |
| | | |
| | | if (CollectionUtils.isNotEmpty(createOrderDto.getItems())) { |
| | | List<ShoppingCarItem> list = new ArrayList<>(); |
| | | for (CreateOderItemDto item : createOrderDto.getItems()) { |
| | | ShoppingCarItem carItem = new ShoppingCarItem(); |
| | | carItem.setCount(item.getCount()); |
| | | carItem.setGoodsId(item.getGoodsId()); |
| | | carItem.setIsFree(item.getIsFree()); |
| | | carItem.setType(item.getGoodsType()); |
| | | |
| | | carItem.setShoppingGoods(shoppingGoodsService.findById(item.getGoodsId())); |
| | | list.add(carItem); |
| | | } |
| | | car.setCarItems(list); |
| | | } |
| | | int i = sysOrderService.createOrder(WebUtil.getSession(), car); |
| | | if (i > 0) { |
| | | return AjaxResult.buildSuccessInstance("下单成功"); |
| | | } |
| | | |
| | | return AjaxResult.buildFailInstance("下单失败"); |
| | | } |
| | | |
| | | } |
| | | @ApiOperation(value = "获取订单列表", notes = "获取订单列表") |
| | | @ApiResponses({ |
| | | @ApiResponse(code = 200, message = "ok", response = OrderDetailVo.class) |
| | | }) |
| | | @PostMapping(value = "/findOrderList") |
| | | public AjaxResult findOrderList(@RequestBody @Validated OrderListDto orderListDto) { |
| | | SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); |
| | | int offset = (orderListDto.getPageNum() - 1) * orderListDto.getPageSize(); |
| | | int limit = orderListDto.getPageSize(); |
| | | PaginationVO pageVo = new PaginationVO(); |
| | | pageVo.setOffset(offset); |
| | | pageVo.setLimit(limit); |
| | | |
| | | if (!DataAuthUtil.hasAllShopAuth()) { |
| | | orderListDto.setShopId(user.getShopId()); |
| | | } |
| | | return AjaxResult.buildSuccessInstance(sysOrderService.findApiOrderListInPage(orderListDto, pageVo), sysOrderService.findApiOrderListTotal(orderListDto)); |
| | | } |
| | | |
| | | @ApiOperation(value = "获取订单详情", notes = "获取订单详情") |
| | | @ApiResponses({ |
| | | @ApiResponse(code = 200, message = "ok", response = OrderDetailVo.class) |
| | | }) |
| | | @GetMapping(value = "/findOrderDetail/{orderId}") |
| | | public AjaxResult findOrderDetail(@PathVariable("orderId") Long orderId) { |
| | | OrderDetailVo orderDetail = sysOrderService.findApiOrderDetailByOrderId(orderId); |
| | | AjaxResult ajaxResult = AjaxResult.buildSuccessInstance("获取成功"); |
| | | ajaxResult.putInMap("orderDetail", orderDetail); |
| | | return ajaxResult; |
| | | } |
| | | |
| | | @ApiOperation(value = "取消订单", notes = "取消订单") |
| | | @GetMapping(value = "/cancelOrder/{orderId}") |
| | | public AjaxResult cancelOrder(@PathVariable("orderId") Long orderId) { |
| | | SysOrder order = sysOrderService.findById(orderId); |
| | | if (order == null) { |
| | | throw new GlobleException("订单不存在"); |
| | | } |
| | | |
| | | |
| | | int i = sysOrderService.cancelOrder(orderId); |
| | | if (i > 0) { |
| | | return AjaxResult.buildSuccessInstance("取消成功"); |
| | | } |
| | | return AjaxResult.buildFailInstance("取消失败"); |
| | | } |
| | | |
| | | } |