|
@@ -0,0 +1,257 @@
|
|
|
+package com.txz.mall.controller.appcontroller;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
+import com.github.pagehelper.PageInfo;
|
|
|
+import com.txz.mall.business.OrderServiceBusiness;
|
|
|
+import com.txz.mall.core.Result;
|
|
|
+import com.txz.mall.core.ResultCode;
|
|
|
+import com.txz.mall.core.ServiceException;
|
|
|
+import com.txz.mall.model.StoreCombination;
|
|
|
+import com.txz.mall.service.StoreCombinationService;
|
|
|
+import com.txz.mall.service.StoreOrderService;
|
|
|
+import dto.GoPinkDTO;
|
|
|
+import dto.StoreProductDTO;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import tk.mybatis.mapper.entity.Condition;
|
|
|
+import tk.mybatis.mapper.entity.Example;
|
|
|
+import vo.StoreCombinationRankVO;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by CodeGenerator on 2025/07/14.
|
|
|
+ */
|
|
|
+@Api(tags = "app拼团商品管理")
|
|
|
+@RestController
|
|
|
+@RequestMapping("/app/combination")
|
|
|
+public class AppCombinationController {
|
|
|
+
|
|
|
+ private static Logger log = LoggerFactory.getLogger(AppCombinationController.class);
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private StoreCombinationService storeCombinationService;
|
|
|
+ @Resource
|
|
|
+ private StoreOrderService storeOrderService;
|
|
|
+ @Resource
|
|
|
+ private OrderServiceBusiness orderServiceBusiness;
|
|
|
+
|
|
|
+ @PostMapping("/add")
|
|
|
+ @ApiOperation(value = "拼团商品表新增")
|
|
|
+ public Result add(@RequestBody StoreCombination storeCombination) {
|
|
|
+ if (storeCombination == null) {
|
|
|
+ return Result.fail(ResultCode.OBJECT_IS_NULL);
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ storeCombination.setCreateTime(new Date());
|
|
|
+// storeCombination.setCreateUserId(userId);
|
|
|
+ storeCombinationService.save(storeCombination);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("新增对象操作异常e:{}", e);
|
|
|
+ return Result.fail(ResultCode.INTERNAL_SERVER_ERROR);
|
|
|
+ }
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/delete")
|
|
|
+ @ApiOperation(value = "拼团商品表删除")
|
|
|
+ public Result delete(@RequestParam Long id) {
|
|
|
+ if (id == null) {
|
|
|
+ return Result.fail(ResultCode.ID_IS_NULL);
|
|
|
+ }
|
|
|
+ StoreCombination combination = storeCombinationService.findById(id);
|
|
|
+ if (combination == null) {
|
|
|
+ return Result.fail(ResultCode.OBJECT_IS_NULL);
|
|
|
+ }
|
|
|
+ Date date = new Date();
|
|
|
+ if (combination.getIsShow().equals(1) && combination.getStartTime().before(date) && combination.getStopTime().after(date)) {
|
|
|
+ throw new ServiceException("活动开启中,商品不支持删除");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ StoreCombination storeCombination = new StoreCombination();
|
|
|
+ storeCombination.setId(id);
|
|
|
+ storeCombination.setIsDelete(1);
|
|
|
+ storeCombinationService.update(storeCombination);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("删除对象操作异常e:{}", e);
|
|
|
+ return Result.fail(ResultCode.INTERNAL_SERVER_ERROR);
|
|
|
+ }
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/update")
|
|
|
+ @ApiOperation(value = "拼团商品表更新")
|
|
|
+ public Result update(@RequestBody StoreCombination storeCombination) {
|
|
|
+ if (storeCombination == null) {
|
|
|
+ return Result.fail(ResultCode.OBJECT_IS_NULL);
|
|
|
+ }
|
|
|
+ if (storeCombination.getId() == null) {
|
|
|
+ return Result.fail(ResultCode.ID_IS_NULL);
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ storeCombination.setUpdateTime(new Date());
|
|
|
+// storeCombination.setUpdateUserId(userId);
|
|
|
+ storeCombinationService.update(storeCombination);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("更新对象操作异常e:{}", e);
|
|
|
+ return Result.fail(ResultCode.INTERNAL_SERVER_ERROR);
|
|
|
+ }
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/detail")
|
|
|
+ @ApiOperation(value = "拼团商品表获取详情")
|
|
|
+ public Result<StoreCombination> detail(@RequestParam Long id) {
|
|
|
+ if (id == null) {
|
|
|
+ return Result.fail(ResultCode.ID_IS_NULL);
|
|
|
+ }
|
|
|
+
|
|
|
+ StoreCombination storeCombination = null;
|
|
|
+ try {
|
|
|
+ storeCombination = storeCombinationService.findById(id);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("查询对象操作异常e:{}", e);
|
|
|
+ return Result.fail(ResultCode.INTERNAL_SERVER_ERROR);
|
|
|
+ }
|
|
|
+ return Result.success(storeCombination);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/app/list")
|
|
|
+ @ApiOperation(value = "拼团商品表获取列表")
|
|
|
+ public Result<List<StoreCombination>> list(@RequestBody StoreProductDTO dto, @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer size) {
|
|
|
+ PageHelper.startPage(page, size);
|
|
|
+
|
|
|
+ Condition condition = new Condition(StoreCombination.class);
|
|
|
+ Example.Criteria criteria = condition.createCriteria();
|
|
|
+ criteria.andEqualTo("isDelete", 0);
|
|
|
+ criteria.andEqualTo("isShow", 1);
|
|
|
+
|
|
|
+ if (dto.getSortWay() == null) {
|
|
|
+ dto.setSortWay(0);
|
|
|
+ }
|
|
|
+ switch (dto.getSortWay()) {
|
|
|
+ case 1:
|
|
|
+ condition.setOrderByClause("price ASC");
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ condition.setOrderByClause("price DESC");
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ condition.setOrderByClause("sales DESC");
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ condition.setOrderByClause("sales ASC");
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ condition.setOrderByClause("create_time DESC");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (dto.getIsNew() != null) {
|
|
|
+ criteria.andEqualTo("isNew", 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (dto.getMinPrice() != null && dto.getMaxPrice() != null) {
|
|
|
+ criteria.andBetween("price", dto.getMinPrice(), dto.getMaxPrice());
|
|
|
+ }
|
|
|
+ PageInfo pageInfo = null;
|
|
|
+ try {
|
|
|
+ List<StoreCombination> list = storeCombinationService.findByCondition(condition);
|
|
|
+ pageInfo = new PageInfo(list);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("查询对象操作异常e:{}", e);
|
|
|
+ return Result.fail(ResultCode.INTERNAL_SERVER_ERROR);
|
|
|
+ }
|
|
|
+ return Result.success(pageInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/addActivityProduct")
|
|
|
+ @ApiOperation(value = "添加活动商品")
|
|
|
+ public Result addActivityProduct(@RequestBody List<StoreCombination> list, @RequestParam("activityId") Long activityId) {
|
|
|
+ if (CollectionUtils.isEmpty(list)) {
|
|
|
+ throw new ServiceException("添加商品不能为空");
|
|
|
+ }
|
|
|
+ if (activityId == null) {
|
|
|
+ return Result.fail(ResultCode.ID_IS_NULL);
|
|
|
+ }
|
|
|
+ storeCombinationService.addActivityProduct(list, activityId);
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/getActivityProductIds")
|
|
|
+ @ApiOperation(value = "获取活动商品ids")
|
|
|
+ public Result<List<Long>> getActivityProductIds(@RequestParam("activityId") Long activityId) {
|
|
|
+ Condition condition = new Condition(StoreCombination.class);
|
|
|
+ Example.Criteria criteria = condition.createCriteria();
|
|
|
+ criteria.andEqualTo("isDelete", 0);
|
|
|
+ criteria.andEqualTo("activityId", activityId);
|
|
|
+ List<StoreCombination> combinationList = storeCombinationService.findByCondition(condition);
|
|
|
+ List<Long> arrayList = combinationList.stream().map(StoreCombination::getProductId).collect(Collectors.toList());
|
|
|
+ return Result.success(arrayList);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 去开团
|
|
|
+ */
|
|
|
+// @ApiOperation(value = "支付成功-去开团")
|
|
|
+// @PostMapping(value = "/open")
|
|
|
+ public Result goOpen(@RequestParam("orderId") String orderId) {
|
|
|
+ storeOrderService.goOpen(orderId);
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 去拼团
|
|
|
+ */
|
|
|
+// @ApiOperation(value = "去拼团")
|
|
|
+// @PostMapping(value = "/pink")
|
|
|
+ public Result goPink(@Validated @RequestBody GoPinkDTO dto) {
|
|
|
+ if (dto.getPinkId() == null && dto.getCid() == null) {
|
|
|
+ return Result.fail(ResultCode.ID_IS_NULL);
|
|
|
+ }
|
|
|
+ storeOrderService.goPink(dto);
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更多拼团
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "更多拼团")
|
|
|
+ @GetMapping(value = "/more")
|
|
|
+ public Result<PageInfo<StoreCombination>> getMore(@RequestParam Integer comId, @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer size) {
|
|
|
+ PageHelper.startPage(page, size);
|
|
|
+ PageInfo pageInfo = null;
|
|
|
+ try {
|
|
|
+ List<StoreCombination> list = storeCombinationService.getMore(comId);
|
|
|
+ pageInfo = new PageInfo(list);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("查询对象操作异常e:{}", e);
|
|
|
+ return Result.fail(ResultCode.INTERNAL_SERVER_ERROR);
|
|
|
+ }
|
|
|
+ return Result.success(pageInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "排行榜")
|
|
|
+ @GetMapping(value = "/rank")
|
|
|
+ public Result<List<StoreCombinationRankVO>> getRank(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer size) {
|
|
|
+ PageHelper.startPage(page, size);
|
|
|
+ PageInfo pageInfo = null;
|
|
|
+ try {
|
|
|
+ List<StoreCombinationRankVO> list = orderServiceBusiness.getRank();
|
|
|
+ pageInfo = new PageInfo(list);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("查询对象操作异常e:{}", e);
|
|
|
+ return Result.fail(ResultCode.INTERNAL_SERVER_ERROR);
|
|
|
+ }
|
|
|
+ return Result.success(pageInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|