Commit 8355b4c7 by 王昆

Merge branch 'engine-product' of gitlab.gongsibao.com:jiangyong/zhichan into engine-product

parents 20ddbb1d 425b3d82
...@@ -18,13 +18,13 @@ class ProductAPI extends APIBase { ...@@ -18,13 +18,13 @@ class ProductAPI extends APIBase {
pobj.action_body.types, pobj.action_body.keywords) pobj.action_body.types, pobj.action_body.keywords)
return system.getResultSuccess(result) return system.getResultSuccess(result)
case 'createOrUpdate': 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, '单产品不能有子产品') 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, '未选择子产品') 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) let checkRes = await this.productSve.checkSitem(pobj.action_body.items)
if (!checkRes) { if (!checkRes) {
return system.getResult(null, '不能选择组合产品为子产品') return system.getResult(null, '不能选择组合产品为子产品')
......
...@@ -4,7 +4,7 @@ class productDao extends Dao { ...@@ -4,7 +4,7 @@ class productDao extends Dao {
super(Dao.getModelName(productDao)); 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 = { let params = {
where: { product_type: { [this.db.Op.in]: type }, source_id: 10001 }, where: { product_type: { [this.db.Op.in]: type }, source_id: 10001 },
limit: limit, limit: limit,
...@@ -16,14 +16,7 @@ class productDao extends Dao { ...@@ -16,14 +16,7 @@ class productDao extends Dao {
return await this.model.findAndCountAll(params) return await this.model.findAndCountAll(params)
} }
async getAllDic (type = [0, 1]) { async getByIds (ids, type = [1, 2]) {
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]) {
return await this.model.findAll({ return await this.model.findAll({
where: { id: { [this.db.Op.in]: ids }, source_id: 10001, product_type: { [this.db.Op.in]: type } } 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 { ...@@ -10,8 +10,27 @@ class ProductService extends ServiceBase {
return await this.dao.getPage(page, limit, type, keywords) return await this.dao.getPage(page, limit, type, keywords)
} }
async getAllDic (type) { async getAllDic (type = [1, 2]) {
return await this.dao.getAllDic(type) 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) { async getByIds (ids) {
...@@ -33,8 +52,8 @@ class ProductService extends ServiceBase { ...@@ -33,8 +52,8 @@ class ProductService extends ServiceBase {
return result return result
} }
async checkSitem(ids) { async checkSitem (ids) {
let res = await this.dao.getByIds(ids, [0]) let res = await this.dao.getByIds(ids, [1])
let arr = [] let arr = []
for (let i of res) { for (let i of res) {
arr.push(i.id) arr.push(i.id)
...@@ -56,7 +75,7 @@ class ProductService extends ServiceBase { ...@@ -56,7 +75,7 @@ class ProductService extends ServiceBase {
async create (params) { async create (params) {
let items let items
if (params.product_type == 1) { if (params.product_type == 2) {
items = JSON.parse(JSON.stringify(params.items)) items = JSON.parse(JSON.stringify(params.items))
delete params.items delete params.items
} }
...@@ -74,7 +93,7 @@ class ProductService extends ServiceBase { ...@@ -74,7 +93,7 @@ class ProductService extends ServiceBase {
async update (params) { async update (params) {
let items let items
if (params.product_type == 1) { if (params.product_type == 2) {
items = JSON.parse(JSON.stringify(params.items)) items = JSON.parse(JSON.stringify(params.items))
delete params.items delete params.items
} }
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
| -------- | -------- | ------ | -------------------- | | -------- | -------- | ------ | -------------------- |
| page | number | 可选 | 页数 默认 1 | | page | number | 可选 | 页数 默认 1 |
| limit | number | 可选 | 每页条数 默认 10 | | limit | number | 可选 | 每页条数 默认 10 |
| types | list | 可选 | 所选类别 默认 [0, 1] | | types | list | 可选 | 所选类别 默认 [1, 2] |
| keywords | string | 可选 | 关键字 | | keywords | string | 可选 | 关键字 |
#### 参数示例 #### 参数示例
...@@ -81,7 +81,7 @@ ...@@ -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