Commit 425b3d82 by wkliang

产品类型修正 字典添加子项

parent 5c12ee5b
......@@ -18,13 +18,13 @@ class ProductAPI extends APIBase {
pobj.action_body.types, pobj.action_body.keywords)
return system.getResultSuccess(result)
case 'createOrUpdate':
if (pobj.action_body.product_type == 0 && pobj.action_body.items) {
if (pobj.action_body.product_type == 1 && pobj.action_body.items) {
return system.getResult(null, '单产品不能有子产品')
}
if (pobj.action_body.product_type == 1 && (!pobj.action_body.items || pobj.action_body.items.length == 0)) {
if (pobj.action_body.product_type == 2 && (!pobj.action_body.items || pobj.action_body.items.length == 0)) {
return system.getResult(null, '未选择子产品')
}
if (pobj.action_body.product_type == 1) {
if (pobj.action_body.product_type == 2) {
let checkRes = await this.productSve.checkSitem(pobj.action_body.items)
if (!checkRes) {
return system.getResult(null, '不能选择组合产品为子产品')
......
......@@ -4,7 +4,7 @@ class productDao extends Dao {
super(Dao.getModelName(productDao));
}
async getPage (page = 1, limit = 10, type = [0, 1], keywords) {
async getPage (page = 1, limit = 10, type = [1, 2], keywords) {
let params = {
where: { product_type: { [this.db.Op.in]: type }, source_id: 10001 },
limit: limit,
......@@ -16,14 +16,7 @@ class productDao extends Dao {
return await this.model.findAndCountAll(params)
}
async getAllDic (type = [0, 1]) {
return await this.model.findAll({
where: { product_type: { [this.db.Op.in]: type }, source_id: 10001 },
attributes: ['id', 'product_type', 'product_name']
})
}
async getByIds (ids, type = [0, 1]) {
async getByIds (ids, type = [1, 2]) {
return await this.model.findAll({
where: { id: { [this.db.Op.in]: ids }, source_id: 10001, product_type: { [this.db.Op.in]: type } }
})
......
......@@ -10,8 +10,27 @@ class ProductService extends ServiceBase {
return await this.dao.getPage(page, limit, type, keywords)
}
async getAllDic (type) {
return await this.dao.getAllDic(type)
async getAllDic (type = [1, 2]) {
let query = {
where: { product_type: { [this.db.Op.in]: type }, source_id: 10001 },
attributes: ['id', 'product_type', 'product_name', 'price'],
include: [{
model: this.itemDao.model,
attributes: [['product_id', 'id']],
require: false,
raw: true
}],
}
this.dao.model.hasMany(this.itemDao.model, { foreignKey: 'parent_id' })
let result = await this.dao.model.findAll(query)
for (let i in result) {
let res = []
res = result[i].dataValues.productitems.map((data) => {
return data.id
})
result[i].setDataValue("ids", res)
}
return result
}
async getByIds (ids) {
......@@ -33,8 +52,8 @@ class ProductService extends ServiceBase {
return result
}
async checkSitem(ids) {
let res = await this.dao.getByIds(ids, [0])
async checkSitem (ids) {
let res = await this.dao.getByIds(ids, [1])
let arr = []
for (let i of res) {
arr.push(i.id)
......@@ -56,7 +75,7 @@ class ProductService extends ServiceBase {
async create (params) {
let items
if (params.product_type == 1) {
if (params.product_type == 2) {
items = JSON.parse(JSON.stringify(params.items))
delete params.items
}
......@@ -74,7 +93,7 @@ class ProductService extends ServiceBase {
async update (params) {
let items
if (params.product_type == 1) {
if (params.product_type == 2) {
items = JSON.parse(JSON.stringify(params.items))
delete params.items
}
......
......@@ -24,7 +24,7 @@
| -------- | -------- | ------ | -------------------- |
| page | number | 可选 | 页数 默认 1 |
| limit | number | 可选 | 每页条数 默认 10 |
| types | list | 可选 | 所选类别 默认 [0, 1] |
| types | list | 可选 | 所选类别 默认 [1, 2] |
| keywords | string | 可选 | 关键字 |
#### 参数示例
......@@ -81,7 +81,7 @@
| 参数名 | 参数类型 | 必选项 | 备注 |
| ------ | -------- | ------ | -------------------- |
| types | list | 可选 | 所选类别 默认 [0, 1] |
| types | list | 可选 | 所选类别 默认 [1, 2] |
#### 参数示例
......
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