import { default as BaseController } from "../../baseController";
|
import { Post } from "egg-shell-decorators";
|
import { AppAddress } from "../../../entity/crm/app/appAddress";
|
export default class AppAddressController extends BaseController {
|
//#region 获得货主地址列表
|
/**
|
* 获得货主地址列表
|
*/
|
@Post()
|
public async getList() {
|
let { ctx } = this;
|
let userInfo = await ctx.helper.userInfo();
|
let body = ctx.request.body;
|
try {
|
let dataList = await this.dbRead.find(AppAddress, {
|
userProduct_Id: userInfo.userProduct_Id,
|
user_Id: body.user_Id
|
});
|
if (!dataList) {
|
this.info.result = false;
|
this.info.msg = "数据不存在";
|
ctx.body = this.info;
|
return;
|
}
|
this.info.result = true;
|
this.info.data = dataList;
|
ctx.body = this.info;
|
this.info.msg = "获取成功";
|
} catch (error) {
|
this.info.result = false;
|
this.info.msg = "数据获取失败" + error.message;
|
this.info.data = error.message;
|
}
|
ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region 货主地址修改
|
/**
|
*地址修改
|
*/
|
@Post()
|
public async updateAddress() {
|
let { ctx } = this;
|
let userInfo = await ctx.helper.userInfo();
|
let body = ctx.request.body;
|
|
try {
|
let dataList = await this.dbRead.find(AppAddress, {
|
userProduct_Id: userInfo.userProduct_Id,
|
address_Id: body.address_Id
|
});
|
|
this.info.result = true;
|
this.info.data = dataList;
|
await this.dbWrite.update(
|
AppAddress,
|
{
|
address_Id: body.address_Id
|
},
|
{
|
// 修改地址
|
consignee: body.consignee, // 收货人名称
|
mobile: body.mobile, // 手机号
|
isDefault: body.isDefault, //
|
detailAddress: body.detailAddress,
|
provinceName: body.provinceName,
|
cityName: body.cityName,
|
regionName: body.regionName
|
}
|
);
|
this.info.result = true;
|
this.info.msg = "修改成功";
|
ctx.body = this.info;
|
} catch (error) {
|
this.info.result = false;
|
this.info.msg = "修改失败" + error.message;
|
this.info.data = error.message;
|
}
|
ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region 新建货主地址
|
/**
|
*新建地址
|
*/
|
@Post()
|
public async saveAddress() {
|
let { ctx } = this;
|
// let userInfo = await ctx.helper.userInfo();
|
try {
|
// 保存数据
|
let dataInfo = this.body;
|
dataInfo.isDefault = dataInfo.isDefault ? 1 : 0;
|
dataInfo.user_Id = 1; // 暂时使用超级管理员
|
dataInfo.userTrueName = "超级管理员";
|
|
// 设置账套数据
|
await this.setAccountInfo(dataInfo);
|
await this.dbWrite.save(AppAddress, dataInfo);
|
if (dataInfo.isDefault === 1) {
|
let sql = `Update App_Address set isDefault=0 where address_Id!='${dataInfo.address_Id}'`;
|
await this.dbWrite.query(sql);
|
}
|
|
this.info.result = true;
|
this.info.msg = "保存成功";
|
ctx.body = this.info;
|
} catch (error) {
|
this.info.result = false;
|
this.info.msg = "新建失败" + error.message;
|
}
|
ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region 货主地址删除
|
/**
|
*删除地址
|
*/
|
@Post()
|
public async deleteAddress() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
try {
|
await this.dbWrite.delete(AppAddress, {
|
address_Id: body.address_Id
|
});
|
this.info.result = true;
|
this.info.msg = "已删除";
|
ctx.body = this.info;
|
} catch (error) {
|
this.info.result = false;
|
this.info.msg = "删除失败:" + error.message;
|
}
|
ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region 获得单条地址
|
/**
|
*获得单条地址
|
*/
|
@Post()
|
public async getAddress() {
|
let { ctx } = this;
|
try {
|
let dataInfo = await this.dbRead.findOne(AppAddress, {
|
address_Id: this.body.address_Id
|
});
|
this.info.result = true;
|
this.info.data = dataInfo;
|
|
ctx.body = this.info;
|
} catch (error) {
|
this.info.result = false;
|
this.info.msg = "获取失败:" + error.message;
|
}
|
ctx.body = this.info;
|
}
|
//#endregion
|
}
|