- 调通 用户商品地址

This commit is contained in:
sin 2019-04-06 18:26:57 +08:00
parent 27d3a6bba1
commit 207342187b
11 changed files with 352 additions and 105 deletions

16
mobile-web/.editorconfig Normal file
View File

@ -0,0 +1,16 @@
# http://editorconfig.org
root = true
[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.md]
trim_trailing_whitespace = false
[Makefile]
indent_style = tab

View File

@ -18,31 +18,40 @@ export function DelFavorite(id){
export function GetAddressList(){ export function GetAddressList(){
return request({ return request({
url: '/User/GetAddressList', url: '/user-api/user/address/list',
method: 'get', method: 'get',
}) })
} }
export function GetAddressById(id){ export function GetAddressById(id){
return request({ return request({
url: '/User/GetAddressById', url: '/user-api/user/address/address',
method: 'get', method: 'get',
params: { id } params: { id }
}) })
} }
export function SaveAddress(data){ export function UpdateAddress(data){
return request({ return request({
url: '/User/SaveAddress', url: '/user-api/user/address/update',
method: 'post', method: 'PUT',
params: { data } params: data
}) })
} }
export function SaveAddress(data){
return request({
url: '/user-api/user/address/add',
method: 'POST',
params: data
})
}
export function DelAddress(data){ export function DelAddress(data){
return request({ return request({
url: '/User/DelAddress', url: '/user-api/user/address/remove',
method: 'post', method: 'DELETE',
params: { data } params: data
}) })
} }

View File

@ -4,8 +4,74 @@ import datas from '../data/data';
import { getAccessToken } from '../utils/cache.js'; import { getAccessToken } from '../utils/cache.js';
import { Dialog } from 'vant'; import { Dialog } from 'vant';
const serviceRouter = function(requestUrl) {
function getConfig() {
const configDev = {
'/order-api': {
prefix: '/order-api',
target: 'http://127.0.0.1:18084/order-api',
},
'/user-api': {
prefix: '/user-api',
target: 'http://127.0.0.1:18082/user-api',
},
};
const configProd = {
'/order-api': {
prefix: '/order-api',
target: 'http://127.0.0.1:18084/order-api',
},
'/user-api': {
prefix: '/user-api',
target: 'http://127.0.0.1:18082/user-api',
},
};
if (process.env.NODE_ENV == 'development') {
return configDev;
} else {
return configProd
}
}
// function doCreateServer(config) {
// // 获取请求配置文件
// const createServer = {};
// for (const configKey in config) {
// const serverPrefix = configKey;
// const {target} = config[configKey];
// // 创建服务
// createServer[serverPrefix] = axios.create({
// baseURL: target, // api 的 base_url
// timeout: 5000, // request timeout
// headers: {
// 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
// }
// });
// }
// }
const config = getConfig();
// const createServer = doCreateServer(config);
const indexOf = requestUrl.indexOf("/", 1);
const _urlPrefix = requestUrl.substring(0, indexOf);
if (!config[_urlPrefix]) {
throw new Error(`服务路由,未找到可用服务! ${requestUrl}`);
}
// if (!createServer[_urlPrefix]) {
// throw new Error("服务路由,未找到可用服务!");
// }
// const { target } = config[_urlPrefix];
// const requestServer = createServer[_urlPrefix];
// const targetRequestUrl = _requestUrl.replace(_urlPrefix, target)
// return createServer;
return config[_urlPrefix];
};
const service = axios.create({ const service = axios.create({
baseURL: baseUrl, // api 的 base_url // baseURL: baseUrl, // api 的 base_url
timeout: 5000, // request timeout timeout: 5000, // request timeout
headers: { headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
@ -34,6 +100,7 @@ const servicef = function (parameter) {
// }; // };
// } // }
// debugger; // debugger;
return service(parameter); return service(parameter);
} }
@ -46,11 +113,12 @@ service.interceptors.request.use(
// config.headers['X-Token'] = getToken() // config.headers['X-Token'] = getToken()
// } // }
// debugger; // 切换地址
let url = config.url; const { target, prefix } = serviceRouter(config.url)
let url = config.url = config.url.replace(`${prefix}`, target);
// TODO 芋艿,这些 url 不用增加认证 token 。可能这么写,有点脏,后面看看咋优化下。 // TODO 芋艿,这些 url 不用增加认证 token 。可能这么写,有点脏,后面看看咋优化下。
if (url === 'user-api/users/passport/mobile/send_register_code' if (url.indexOf('user-api/users/passport/mobile/send_register_code') != -1
|| url === 'user-api/users/passport/mobile/register') { || url.indexOf('user-api/users/passport/mobile/register') != -1) {
return config; return config;
} }

View File

@ -14,9 +14,10 @@
<script> <script>
import areaList from '../../../data/area'; import areaList from '../../../data/area';
import { GetAddressById,SaveAddress,DelAddress } from "../../../api/user.js"; import {GetAddressById, SaveAddress, UpdateAddress, DelAddress} from "../../../api/user.js";
import {AddressEdit} from 'vant'; import {AddressEdit} from 'vant';
export default { export default {
components: { components: {
[AddressEdit.name]: AddressEdit, [AddressEdit.name]: AddressEdit,
@ -25,31 +26,59 @@ export default {
return { return {
areaList, areaList,
showDelete: false, showDelete: false,
info:{}, info: {
},
} }
}, },
methods: { methods: {
onSave(data) { onSave(data) {
SaveAddress(data).then(response=>{ const params = {
...data,
address: data.addressDetail,
areaNo: data.areaCode,
city: data.city,
county: data.county,
country: data.country,
mobile: data.tel,
name: data.name,
hasDefault: data.isDefault,
};
if (data.id !== 0) {
UpdateAddress(params).then(response => {
this.$toast('更新成功');
this.$router.go(-1);
})
} else {
SaveAddress(params).then(response => {
this.$toast('保存成功'); this.$toast('保存成功');
this.$router.go(-1); this.$router.go(-1);
}) })
}
}, },
onDelete(data) { onDelete(data) {
DelAddress(data).then(response=>{ const params = {
id: data.id,
};
DelAddress(params).then(response => {
this.$toast('删除成功'); this.$toast('删除成功');
this.$router.go(-1); this.$router.go(-1);
}) })
}, },
}, },
created: function () { created: function () {
var id=this.$route.query.id; const id = this.$route.query.id;
if (id > 0) { if (id > 0) {
this.showDelete = true; this.showDelete = true;
GetAddressById(id).then(response => { GetAddressById(id).then(response => {
console.log(response); this.info = {
this.info=response; ...response,
addressDetail: response.address,
tel: response.mobile,
areaCode: response.areaNo,
isDefault: 0,
};
}) })
} }
} }

View File

@ -17,6 +17,7 @@
import {GetAddressList} from "../../../api/user.js"; import {GetAddressList} from "../../../api/user.js";
import {AddressList} from 'vant'; import {AddressList} from 'vant';
export default { export default {
components: { components: {
[AddressList.name]: AddressList, [AddressList.name]: AddressList,
@ -49,7 +50,14 @@ export default {
this.chosenAddressId = this.$route.query.id; this.chosenAddressId = this.$route.query.id;
this.isSelect = this.$route.query.id > 0; this.isSelect = this.$route.query.id > 0;
GetAddressList().then(response => { GetAddressList().then(response => {
this.list=response; this.list = response.map(item => {
// convert data
return {
...item,
tel: item.mobile,
}
});
}) })
} }

View File

@ -30,19 +30,19 @@ public class UserAddressController {
@PostMapping("add") @PostMapping("add")
@ApiOperation(value = "用户地址-添加") @ApiOperation(value = "用户地址-添加")
public CommonResult addAddress(@RequestBody @Validated UserAddressAddPO userAddressAddPO) { public CommonResult addAddress(@Validated UserAddressAddPO userAddressAddPO) {
Integer userId = UserSecurityContextHolder.getContext().getUserId(); Integer userId = UserSecurityContextHolder.getContext().getUserId();
UserAddressAddDTO userAddressAddDTO = UserAddressConvert.INSTANCE.convert(userAddressAddPO); UserAddressAddDTO userAddressAddDTO = UserAddressConvert.INSTANCE.convert(userAddressAddPO);
userAddressAddDTO.setUserId(userId); userAddressAddDTO.setUserId(1);
return userAddressService.addAddress(userAddressAddDTO); return userAddressService.addAddress(userAddressAddDTO);
} }
@PutMapping("update") @PutMapping("update")
@ApiOperation(value = "用户地址-更新") @ApiOperation(value = "用户地址-更新")
public CommonResult updateAddress(@RequestBody @Validated UserAddressUpdatePO userAddressUpdatePO) { public CommonResult updateAddress(@Validated UserAddressUpdatePO userAddressUpdatePO) {
Integer userId = UserSecurityContextHolder.getContext().getUserId(); Integer userId = UserSecurityContextHolder.getContext().getUserId();
UserAddressUpdateDTO userAddressUpdateDTO = UserAddressConvert.INSTANCE.convert(userAddressUpdatePO); UserAddressUpdateDTO userAddressUpdateDTO = UserAddressConvert.INSTANCE.convert(userAddressUpdatePO);
userAddressUpdateDTO.setUserId(userId); userAddressUpdateDTO.setUserId(1);
return userAddressService.updateAddress(userAddressUpdateDTO); return userAddressService.updateAddress(userAddressUpdateDTO);
} }
@ -50,7 +50,7 @@ public class UserAddressController {
@ApiOperation(value = "用户地址-删除") @ApiOperation(value = "用户地址-删除")
public CommonResult removeAddress(@RequestParam("id") Integer id) { public CommonResult removeAddress(@RequestParam("id") Integer id) {
Integer userId = UserSecurityContextHolder.getContext().getUserId(); Integer userId = UserSecurityContextHolder.getContext().getUserId();
return userAddressService.removeAddress(userId, id); return userAddressService.removeAddress(1, id);
} }
@GetMapping("list") @GetMapping("list")
@ -59,4 +59,11 @@ public class UserAddressController {
Integer userId = UserSecurityContextHolder.getContext().getUserId(); Integer userId = UserSecurityContextHolder.getContext().getUserId();
return userAddressService.addressList(1); return userAddressService.addressList(1);
} }
@GetMapping("address")
@ApiOperation(value = "获取地址")
public CommonResult getAddress(@RequestParam("id") Integer id) {
Integer userId = UserSecurityContextHolder.getContext().getUserId();
return userAddressService.getAddress(1, id);
}
} }

View File

@ -22,4 +22,6 @@ public interface UserAddressService {
CommonResult removeAddress(Integer userId, Integer addressId); CommonResult removeAddress(Integer userId, Integer addressId);
CommonResult<List<UserAddressBO>> addressList(Integer userId); CommonResult<List<UserAddressBO>> addressList(Integer userId);
CommonResult<UserAddressBO> getAddress(Integer userId, Integer id);
} }

View File

@ -5,4 +5,96 @@ package cn.iocoder.mall.user.api.bo;
* @time 2019-04-06 13:28 * @time 2019-04-06 13:28
*/ */
public class UserAddressBO { public class UserAddressBO {
/**
* 编号
*/
private Integer id;
/**
* 用户编号
*/
private Integer userId;
/**
* 收件区域编号
*/
private String areaNo;
/**
* 收件人名称
*/
private String name;
/**
* 收件手机号
*/
private String mobile;
/**
* 收件详细地址
*/
private String address;
@Override
public String toString() {
return "UserAddressBO{" +
"id=" + id +
", userId=" + userId +
", areaNo='" + areaNo + '\'' +
", name='" + name + '\'' +
", mobile='" + mobile + '\'' +
", address='" + address + '\'' +
'}';
}
public Integer getId() {
return id;
}
public UserAddressBO setId(Integer id) {
this.id = id;
return this;
}
public Integer getUserId() {
return userId;
}
public UserAddressBO setUserId(Integer userId) {
this.userId = userId;
return this;
}
public String getAreaNo() {
return areaNo;
}
public UserAddressBO setAreaNo(String areaNo) {
this.areaNo = areaNo;
return this;
}
public String getName() {
return name;
}
public UserAddressBO setName(String name) {
this.name = name;
return this;
}
public String getMobile() {
return mobile;
}
public UserAddressBO setMobile(String mobile) {
this.mobile = mobile;
return this;
}
public String getAddress() {
return address;
}
public UserAddressBO setAddress(String address) {
this.address = address;
return this;
}
} }

View File

@ -27,6 +27,9 @@ public interface UserAddressConvert {
@Mappings({}) @Mappings({})
UserAddressDO convert(UserAddressUpdateDTO userAddressUpdateDTO); UserAddressDO convert(UserAddressUpdateDTO userAddressUpdateDTO);
@Mappings({})
UserAddressBO convert(UserAddressDO userAddressDO);
@Mappings({}) @Mappings({})
List<UserAddressBO> convertUserAddressBOList(List<UserAddressDO> userAddressDOList); List<UserAddressBO> convertUserAddressBOList(List<UserAddressDO> userAddressDOList);
} }

View File

@ -44,7 +44,7 @@ public class UserAddressServiceImpl implements UserAddressService {
.selectByUserIdAndId(userAddressAddDTO.getUserId(), userAddressAddDTO.getId()); .selectByUserIdAndId(userAddressAddDTO.getUserId(), userAddressAddDTO.getId());
if (DeletedStatusEnum.DELETED_YES.getValue().equals(userAddress.getDeleted())) { if (DeletedStatusEnum.DELETED_YES.getValue().equals(userAddress.getDeleted())) {
return CommonResult.success(UserErrorCodeEnum.USER_ADDRESS_IS_DELETED.getCode()); return ServiceExceptionUtil.error(UserErrorCodeEnum.USER_ADDRESS_IS_DELETED.getCode());
} }
if (userAddress == null) { if (userAddress == null) {
@ -89,4 +89,16 @@ public class UserAddressServiceImpl implements UserAddressService {
return CommonResult.success(userAddressBOList); return CommonResult.success(userAddressBOList);
} }
@Override
public CommonResult<UserAddressBO> getAddress(Integer userId, Integer id) {
UserAddressDO userAddress = userAddressMapper.selectByUserIdAndId(userId, id);
if (DeletedStatusEnum.DELETED_YES.getValue().equals(userAddress.getDeleted())) {
return ServiceExceptionUtil.error(UserErrorCodeEnum.USER_ADDRESS_IS_DELETED.getCode());
}
UserAddressBO userAddressBO = UserAddressConvert.INSTANCE.convert(userAddress);
return CommonResult.success(userAddressBO);
}
} }

View File

@ -9,7 +9,8 @@
<insert id="insert" parameterType="UserAddressDO" useGeneratedKeys="true" keyProperty="id"> <insert id="insert" parameterType="UserAddressDO" useGeneratedKeys="true" keyProperty="id">
INSERT INTO user_address ( INSERT INTO user_address (
user_id, area_no, `name`, mobile, address user_id, area_no, `name`, mobile, address,
create_time, update_time, deleted
) VALUES ( ) VALUES (
#{userId}, #{areaNo}, #{name}, #{mobile}, #{address}, #{userId}, #{areaNo}, #{name}, #{mobile}, #{address},
#{createTime}, #{updateTime}, #{deleted} #{createTime}, #{updateTime}, #{deleted}