|
@@ -0,0 +1,162 @@
|
|
|
+/*
|
|
|
+ * Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
|
|
|
+ *
|
|
|
+ * https://www.mall4j.com/
|
|
|
+ *
|
|
|
+ * 未经允许,不可做商业用途!
|
|
|
+ *
|
|
|
+ * 版权所有,侵权必究!
|
|
|
+ */
|
|
|
+
|
|
|
+package com.qs.mp.web.controller.api.channel;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.qs.mp.channel.domain.ChannelAddr;
|
|
|
+import com.qs.mp.channel.domain.param.AddrParam;
|
|
|
+import com.qs.mp.channel.service.IChannelAddrService;
|
|
|
+import com.qs.mp.common.core.domain.AjaxResult;
|
|
|
+import com.qs.mp.utils.SecurityUtils;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiImplicitParam;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import javax.validation.Valid;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import ma.glasnost.orika.MapperFacade;
|
|
|
+import org.aspectj.weaver.loadtime.Aj;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
+import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.Mapping;
|
|
|
+import org.springframework.web.bind.annotation.PathVariable;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.PutMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+
|
|
|
+@RestController
|
|
|
+@RequestMapping("/api/v1/mp/channel")
|
|
|
+@Api(tags = "地址接口")
|
|
|
+@AllArgsConstructor
|
|
|
+public class ChannelAddrController {
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IChannelAddrService channelAddrService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MapperFacade mapperFacade;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 选择订单配送地址
|
|
|
+ */
|
|
|
+ @PostMapping("/address/list")
|
|
|
+ @ApiOperation(value = "渠道地址列表", notes = "获取渠道的所有地址信息")
|
|
|
+ public AjaxResult list() {
|
|
|
+ Long channelId = SecurityUtils.getLoginUser().getChannelId();
|
|
|
+ List<ChannelAddr> channelAddrs = channelAddrService.list(new LambdaQueryWrapper<ChannelAddr>().eq(ChannelAddr::getChannelId, channelId).orderByDesc(ChannelAddr::getCommonAddr).orderByDesc(ChannelAddr::getUpdateTime));
|
|
|
+ return AjaxResult.success(channelAddrs);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/address/create")
|
|
|
+ @ApiOperation(value = "新增用户地址", notes = "新增用户地址")
|
|
|
+ public AjaxResult create(@Valid @RequestBody AddrParam addrParam) {
|
|
|
+ Long channelId = SecurityUtils.getLoginUser().getChannelId();
|
|
|
+
|
|
|
+ if (addrParam.getAddrId() != null && addrParam.getAddrId() != 0) {
|
|
|
+ return AjaxResult.error("该地址已存在");
|
|
|
+ }
|
|
|
+ int addrCount = channelAddrService.count(new LambdaQueryWrapper<ChannelAddr>().eq(ChannelAddr::getChannelId, channelId));
|
|
|
+ ChannelAddr channelAddr = mapperFacade.map(addrParam, ChannelAddr.class);
|
|
|
+
|
|
|
+ if (addrCount == 0) {
|
|
|
+ channelAddr.setCommonAddr(1);
|
|
|
+ } else {
|
|
|
+ channelAddr.setCommonAddr(0);
|
|
|
+ }
|
|
|
+ channelAddr.setChannelId(channelId);
|
|
|
+ channelAddr.setStatus(1);
|
|
|
+ channelAddr.setCreateTime(new Date());
|
|
|
+ channelAddr.setUpdateTime(new Date());
|
|
|
+ channelAddrService.save(channelAddr);
|
|
|
+
|
|
|
+ return AjaxResult.success("添加地址成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改订单配送地址
|
|
|
+ */
|
|
|
+ @PostMapping("/address/update")
|
|
|
+ @ApiOperation(value = "修改订单用户地址", notes = "修改用户地址")
|
|
|
+ public AjaxResult update(@Valid @RequestBody AddrParam addrParam) {
|
|
|
+ Long channelId = SecurityUtils.getLoginUser().getUserId();
|
|
|
+
|
|
|
+ ChannelAddr dbChannelAddr = channelAddrService.getChannelAddrByUserId(addrParam.getAddrId(), channelId);
|
|
|
+ if (dbChannelAddr == null) {
|
|
|
+ return AjaxResult.error("该地址已被删除");
|
|
|
+ }
|
|
|
+
|
|
|
+ ChannelAddr channelAddr = mapperFacade.map(addrParam, ChannelAddr.class);
|
|
|
+ channelAddr.setChannelId(channelId);
|
|
|
+ channelAddrService.updateById(channelAddr);
|
|
|
+ return AjaxResult.success("修改地址成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除订单配送地址
|
|
|
+ */
|
|
|
+ @PostMapping("/deleteAddr/{addrId}")
|
|
|
+ @ApiOperation(value = "删除订单用户地址", notes = "根据地址id,删除用户地址")
|
|
|
+ @ApiImplicitParam(name = "addrId", value = "地址ID", required = true, dataType = "Long")
|
|
|
+ public AjaxResult deleteDvy(@PathVariable("addrId") Long addrId) {
|
|
|
+ /*String userId = SecurityUtils.getUser().getUserId();
|
|
|
+ UserAddr userAddr = channelAddrService.getUserAddrByUserId(addrId, userId);
|
|
|
+ if (userAddr == null) {
|
|
|
+ return ResponseEntity.badRequest().body("该地址已被删除");
|
|
|
+ }
|
|
|
+ if (userAddr.getCommonAddr() == 1) {
|
|
|
+ return ResponseEntity.badRequest().body("默认地址无法删除");
|
|
|
+ }
|
|
|
+ channelAddrService.removeById(addrId);
|
|
|
+ channelAddrService.removeUserAddrByUserId(addrId, userId);
|
|
|
+ return ResponseEntity.ok("删除地址成功");*/
|
|
|
+ return AjaxResult.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置默认地址
|
|
|
+ */
|
|
|
+ @PutMapping("/defaultAddr/{addrId}")
|
|
|
+ @ApiOperation(value = "设置默认地址", notes = "根据地址id,设置默认地址")
|
|
|
+ public AjaxResult defaultAddr(@PathVariable("addrId") Long addrId) {
|
|
|
+ /*String userId = SecurityUtils.getUser().getUserId();
|
|
|
+
|
|
|
+ channelAddrService.updateDefaultUserAddr(addrId, userId);
|
|
|
+
|
|
|
+ channelAddrService.removeUserAddrByUserId(0L, userId);
|
|
|
+ channelAddrService.removeUserAddrByUserId(addrId, userId);
|
|
|
+ return ResponseEntity.ok("修改地址成功");*/
|
|
|
+ return AjaxResult.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取地址信息订单配送地址
|
|
|
+ */
|
|
|
+ @GetMapping("/addrInfo/{addrId}")
|
|
|
+ @ApiOperation(value = "获取地址信息", notes = "根据地址id,获取地址信息")
|
|
|
+ @ApiImplicitParam(name = "addrId", value = "地址ID", required = true, dataType = "Long")
|
|
|
+ public AjaxResult addrInfo(@PathVariable("addrId") Long addrId) {
|
|
|
+ /*String userId = SecurityUtils.getUser().getUserId();
|
|
|
+ UserAddr userAddr = channelAddrService.getUserAddrByUserId(addrId, userId);
|
|
|
+ if (userAddr == null) {
|
|
|
+ throw new YamiShopBindException("该地址已被删除");
|
|
|
+ }
|
|
|
+ return ResponseEntity.ok(mapperFacade.map(userAddr, UserAddrDto.class));*/
|
|
|
+ return AjaxResult.success();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|