Commit ffde0856 by wkliang

增加 属性校验

parent ca61803a
...@@ -51,6 +51,10 @@ class ActionAPI extends APIBase { ...@@ -51,6 +51,10 @@ class ActionAPI extends APIBase {
if (!checkRes) { if (!checkRes) {
return system.getResult(null, '不能选择组合产品为子产品') return system.getResult(null, '不能选择组合产品为子产品')
} }
checkRes = await this.productSve.maxItem(action_body.items)
if (!checkRes) {
return system.getResult(null, '每个属性产品最多只能有一个')
}
} }
result = await this.productSve.createOrUpdate(action_body) result = await this.productSve.createOrUpdate(action_body)
break break
......
...@@ -24,7 +24,7 @@ class ProductService extends ServiceBase { ...@@ -24,7 +24,7 @@ class ProductService extends ServiceBase {
this.dao.model.hasMany(this.itemDao.model, { foreignKey: 'parent_id' }) this.dao.model.hasMany(this.itemDao.model, { foreignKey: 'parent_id' })
let result = await this.dao.model.findAll(query) let result = await this.dao.model.findAll(query)
for (let i in result) { for (let i in result) {
let res = [] let res = []
res = result[i].dataValues.productitems.map((data) => { res = result[i].dataValues.productitems.map((data) => {
return data.id return data.id
}) })
...@@ -66,8 +66,23 @@ class ProductService extends ServiceBase { ...@@ -66,8 +66,23 @@ class ProductService extends ServiceBase {
} }
} }
async maxItem (ids) {
let res = await this.dao.getByIds(ids)
let arr = []
arr = res.map(data => {
return data.product_property
})
arr = arr.sort()
for (let i = 0; i < arr.length - 1; ++i) {
if (arr[i] === arr[i + 1]) {
return false
}
}
return true
}
async createOrUpdate (params) { async createOrUpdate (params) {
if(params.price) { if (params.price) {
params.price = Math.round(parseFloat(params.price) * 100) params.price = Math.round(parseFloat(params.price) * 100)
} }
if (params.id) { if (params.id) {
...@@ -114,16 +129,16 @@ class ProductService extends ServiceBase { ...@@ -114,16 +129,16 @@ class ProductService extends ServiceBase {
return result return result
} }
async apiList() { async apiList () {
return [ return [
{key: "nameTwo_1", name: "姓名二要素-e签宝"}, { key: "nameTwo_1", name: "姓名二要素-e签宝" },
{key: "sign_1", name: "手动签-e签宝"}, { key: "sign_1", name: "手动签-e签宝" },
{key: "autoSign_1", name: "静默签-e签宝"}, { key: "autoSign_1", name: "静默签-e签宝" },
{key: "bankThree_2", name: "银行卡三要素-兰铂旺"}, { key: "bankThree_2", name: "银行卡三要素-兰铂旺" },
{key: "bankFour_2", name: "银行卡四要素-兰铂旺"} { key: "bankFour_2", name: "银行卡四要素-兰铂旺" }
] ]
} }
async apiMap() { async apiMap () {
let list = await this.apiList(); let list = await this.apiList();
let map = {}; let map = {};
for (let item of list) { for (let item of list) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment