| package com.mzl.flower.web.customer; | 
|   | 
| import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; | 
| import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
| import com.mzl.flower.base.BaseController; | 
| import com.mzl.flower.base.R; | 
| import com.mzl.flower.base.ReturnDataDTO; | 
| import com.mzl.flower.dto.PriceDTO; | 
| import com.mzl.flower.dto.request.flower.*; | 
| import com.mzl.flower.dto.request.payment.CartCommitDTO; | 
| import com.mzl.flower.dto.request.payment.CartDeleteDTO; | 
| import com.mzl.flower.dto.request.payment.CartSaveDTO; | 
| import com.mzl.flower.dto.request.payment.OrderCommitDTO; | 
| import com.mzl.flower.dto.request.transport.TransportGetDTO; | 
| import com.mzl.flower.dto.response.flower.*; | 
| import com.mzl.flower.dto.response.payment.PreOrderDTO; | 
| import com.mzl.flower.dto.response.transport.TransportOrderDTO; | 
| import com.mzl.flower.service.flower.FlowerCategoryService; | 
| import com.mzl.flower.service.flower.FlowerParamService; | 
| import com.mzl.flower.service.flower.FlowerService; | 
| import com.mzl.flower.service.payment.OrderService; | 
| import com.mzl.flower.service.transport.TransportService; | 
| import com.wechat.pay.java.service.payments.jsapi.model.PrepayResponse; | 
| import com.wechat.pay.java.service.payments.jsapi.model.PrepayWithRequestPaymentResponse; | 
| import io.swagger.annotations.Api; | 
| import io.swagger.annotations.ApiImplicitParam; | 
| import io.swagger.annotations.ApiImplicitParams; | 
| import io.swagger.annotations.ApiOperation; | 
| import lombok.extern.slf4j.Slf4j; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.http.ResponseEntity; | 
| import org.springframework.validation.annotation.Validated; | 
| import org.springframework.web.bind.annotation.*; | 
|   | 
| import javax.validation.ValidationException; | 
| import javax.validation.constraints.NotBlank; | 
| import java.util.HashMap; | 
| import java.util.List; | 
| import java.util.Map; | 
|   | 
| @RestController | 
| @RequestMapping("/api/customer/flower") | 
| @Api(value = "交易大厅-花店", tags = "交易大厅-花店") | 
| @Validated | 
| @Slf4j | 
| public class FlowerCustomerController extends BaseController { | 
|   | 
|     @Autowired | 
|     private FlowerService flowerService; | 
|   | 
|     @Autowired | 
|     private FlowerParamService paramService; | 
|   | 
|     @Autowired | 
|     private FlowerCategoryService categoryService; | 
|   | 
|     @Autowired | 
|     private OrderService orderService; | 
|   | 
|     @Autowired | 
|     private TransportService transportService; | 
|   | 
|     @GetMapping("/category/tree") | 
|     @ApiOperation(value = "获取商品分类树") | 
|     public ResponseEntity<ReturnDataDTO<List<FlowerCategoryTreeDTO>>> selectCategoryTree(FlowerCategoryQueryDTO dto){ | 
|         return returnData(R.SUCCESS.getCode(), categoryService.selectCustomerCategoryTree(dto)); | 
|     } | 
|   | 
|     @GetMapping("/category/tree/view") | 
|     @ApiOperation(value = "查询商品分类详情") | 
|     @ApiImplicitParams({ | 
|             @ApiImplicitParam(name = "id", value = "商品分类id", required = true, dataType = "String", paramType = "query") | 
|     }) | 
|     public ResponseEntity<ReturnDataDTO<FlowerCategoryDTO>> getCategoryShow(@NotBlank(message = "id不能为空") String id){ | 
|         return returnData(R.SUCCESS.getCode(), categoryService.getCategoryShow(id)); | 
|     } | 
|   | 
|     @GetMapping("/params") | 
|     @ApiOperation(value = "获取分类参数列表") | 
|     @ApiImplicitParams({ | 
|             @ApiImplicitParam(name = "categoryId", value = "商品分类id", required = true, dataType = "Long", paramType = "query") | 
|     }) | 
|     public ResponseEntity<ReturnDataDTO<List<ParamItemDTO>>> getParamItemListByCategoryId(Long categoryId){ | 
|         return returnData(R.SUCCESS.getCode(), paramService.getParamItemListByCategoryId(categoryId)); | 
|     } | 
|   | 
|     @PostMapping("/list") | 
|     @ApiOperation(value = "商品列表") | 
|     public ResponseEntity<ReturnDataDTO<Page<FlowerShowListDTO>>> selectShowFlowerList(@RequestBody FlowerShowQueryDTO dto){ | 
|         Page page = new Page(dto.getCurrent(), dto.getSize()); | 
|         return returnData(R.SUCCESS.getCode(), flowerService.selectShowFlowerList(page, dto)); | 
|     } | 
|   | 
|     @GetMapping("/list/view") | 
|     @ApiOperation(value = "商品详情") | 
|     @ApiImplicitParams({ | 
|             @ApiImplicitParam(name = "id", value = "商品id", required = true, dataType = "Long", paramType = "query"), | 
|             @ApiImplicitParam(name = "partnerId", value = "合伙人id", required = true, dataType = "Long", paramType = "query"), | 
|     }) | 
|     public ResponseEntity<ReturnDataDTO<FlowerShowDTO>> getShowFlowerDetail(Long id, Long partnerId) { | 
|         return returnData(R.SUCCESS.getCode(), flowerService.getShowFlowerDetail(id, partnerId)); | 
|     } | 
|   | 
|     @GetMapping("/up/stock") | 
|     @ApiOperation(value = "在售商品数量") | 
|     public ResponseEntity<ReturnDataDTO<Integer>> getUpFlowerStock() { | 
|         return returnData(R.SUCCESS.getCode(), flowerService.getUpFlowerStock()); | 
|     } | 
|   | 
|     @PostMapping("/cart/change-num") | 
|     @ApiOperation(value = "添加/编辑购物车商品(如果已存在,进行增量的更新)") | 
|     public ResponseEntity<ReturnDataDTO<?>> changeFlower2Cart(@RequestBody CartSaveDTO dto){ | 
|         orderService.changeFlower2Cart(dto); | 
|         return returnData(R.SUCCESS.getCode(), null); | 
|     } | 
|   | 
|     @PostMapping("/cart/save") | 
|     @ApiOperation(value = "添加/编辑购物车商品") | 
|     public ResponseEntity<ReturnDataDTO<?>> saveFlower2Cart(@RequestBody CartSaveDTO dto){ | 
|         orderService.saveFlower2Cart(dto); | 
|         return returnData(R.SUCCESS.getCode(), null); | 
|     } | 
|   | 
|     @GetMapping("/cart/delete") | 
|     @ApiOperation(value = "删除购物车商品") | 
|     @ApiImplicitParams({ | 
|             @ApiImplicitParam(name = "id", value = "商品id", required = true, dataType = "Long", paramType = "query") | 
|     }) | 
|     public ResponseEntity<ReturnDataDTO<?>> deleteFlower4Cart(Long id){ | 
|         orderService.deleteFlower4Cart(id); | 
|         return returnData(R.SUCCESS.getCode(), null); | 
|     } | 
|   | 
|     @PostMapping("/cart/delete/batch") | 
|     @ApiOperation(value = "批量删除购物车商品") | 
|     public ResponseEntity<ReturnDataDTO<?>> deleteBatchFlower4Cart(@RequestBody CartDeleteDTO dto){ | 
|         if(dto == null || CollectionUtils.isEmpty(dto.getIds())){ | 
|             throw new ValidationException("ids不能为空"); | 
|         } | 
|         orderService.deleteBatchFlower4Cart(dto.getIds()); | 
|         return returnData(R.SUCCESS.getCode(), null); | 
|     } | 
|   | 
|   | 
|   | 
|     @GetMapping("/cart/list") | 
|     @ApiOperation(value = "查询购物车商品") | 
|     public ResponseEntity<ReturnDataDTO<List<FlowerCartListWrapDTO>>> getFlowerCartList(){ | 
|         return returnData(R.SUCCESS.getCode(), orderService.getFlowerCartList()); | 
|     } | 
|   | 
|     @GetMapping("/cart/flower/count") | 
|     @ApiOperation(value = "获取购物车商品数量") | 
|     public ResponseEntity<ReturnDataDTO<Integer>> getCartFlowerCount(String flowerId){ | 
|         return returnData(R.SUCCESS.getCode(), orderService.getCartFlowerCount(flowerId)); | 
|     } | 
|   | 
|     @PostMapping("/order/confirm/info") | 
|     @ApiOperation(value = "订单确认信息(购物车选择商品和数量后提交调用)") | 
|     public ResponseEntity<ReturnDataDTO<PreOrderDTO>> getPreOrderInfo(@RequestBody CartCommitDTO dto){ | 
|         return returnData(R.SUCCESS.getCode(), orderService.getPreOrderInfo(dto.getFlowers())); | 
|     } | 
|   | 
|     @PostMapping("/order/confirm/transports") | 
|     @ApiOperation(value = "订单确认信息页面-获取物流") | 
|     public ResponseEntity<ReturnDataDTO<List<TransportOrderDTO>>> getPreOrderTransportList(@RequestBody TransportGetDTO dto){ | 
|         return returnData(R.SUCCESS.getCode(), transportService.getPreOrderTransportList(dto.getAddressId(), dto.getWeight())); | 
|     } | 
|   | 
|     @PostMapping("/order/commit") | 
|     @ApiOperation(value = "提交订单") | 
|     public ResponseEntity<ReturnDataDTO<?>> commitOrder(@RequestBody OrderCommitDTO dto){ | 
|         Map<Long, PriceDTO > priceMap = new HashMap<>(); | 
|         PreOrderDTO p = orderService.processPreOrderInfo(dto.getFlowers(), priceMap); | 
|         Map map; | 
|         try { | 
|             map = orderService.commitOrder(dto, p, priceMap); | 
|         } catch (ValidationException e) { | 
|             orderService.revertFlowerStock(dto.getFlowers()); | 
|             throw e; | 
|         } catch (Exception e) { | 
|             orderService.revertFlowerStock(dto.getFlowers()); | 
|             throw e; | 
|         } | 
|   | 
|         return returnData(R.SUCCESS.getCode(), map); | 
|     } | 
|   | 
| } |