Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Z
zhichan
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
蒋勇
zhichan
Commits
af2e3cef
Commit
af2e3cef
authored
Jun 29, 2020
by
wkliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
参数校验 接口调整
parent
5c4b9559
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
68 additions
and
34 deletions
+68
-34
engine-product/app/base/api/impl/op/product.js
+20
-8
engine-product/app/base/db/impl/product/productDao.js
+7
-8
engine-product/app/base/db/impl/product/productitemDao.js
+6
-1
engine-product/app/base/service/impl/product/productSve.js
+35
-17
No files found.
engine-product/app/base/api/impl/op/product.js
View file @
af2e3cef
...
...
@@ -14,21 +14,33 @@ class ProductAPI extends APIBase {
let
result
switch
(
pobj
.
actionType
)
{
case
'getPage'
:
result
=
await
this
.
productSve
.
getPage
(
pobj
.
actionBody
.
page
,
pobj
.
actionBody
.
offse
t
,
pobj
.
actionBody
.
type
,
pobj
.
actionBody
.
keywords
)
return
system
.
getResult
(
result
)
result
=
await
this
.
productSve
.
getPage
(
pobj
.
actionBody
.
page
,
pobj
.
actionBody
.
limi
t
,
pobj
.
actionBody
.
type
s
,
pobj
.
actionBody
.
keywords
)
return
system
.
getResult
Success
(
result
)
case
'createOrUpdate'
:
if
(
pobj
.
actionBody
.
product_type
==
0
&&
pobj
.
actionBody
.
items
)
{
return
system
.
getResult
(
null
,
'单产品不能有子产品'
)
}
if
(
pobj
.
actionBody
.
product_type
==
1
&&
(
!
pobj
.
actionBody
.
items
||
pobj
.
actionBody
.
items
.
length
==
0
))
{
return
system
.
getResult
(
null
,
'未选择子产品'
)
}
if
(
pobj
.
actionBody
.
product_type
==
1
)
{
let
checkRes
=
await
this
.
productSve
.
checkSitem
(
pobj
.
actionBody
.
items
)
if
(
!
checkRes
)
{
return
system
.
getResult
(
null
,
'不能选择组合产品为子产品'
)
}
}
result
=
await
this
.
productSve
.
createOrUpdate
(
pobj
.
actionBody
)
return
system
.
getResult
(
result
)
return
system
.
getResult
Success
(
result
)
case
'getAllDic'
:
result
=
await
this
.
productSve
.
getAllDic
(
pobj
.
actionBody
.
type
)
return
system
.
getResult
(
result
)
result
=
await
this
.
productSve
.
getAllDic
(
pobj
.
actionBody
.
type
s
)
return
system
.
getResult
Success
(
result
)
case
'getByIds'
:
result
=
await
this
.
productSve
.
getByIds
(
pobj
.
actionBody
.
ids
)
return
system
.
getResult
(
result
)
return
system
.
getResult
Success
(
result
)
case
'getItems'
:
result
=
await
this
.
productSve
.
getItems
(
pobj
.
actionBody
.
id
)
return
system
.
getResult
(
result
)
return
system
.
getResult
Success
(
result
)
default
:
break
}
...
...
engine-product/app/base/db/impl/product/productDao.js
View file @
af2e3cef
...
...
@@ -4,11 +4,11 @@ class productDao extends Dao {
super
(
Dao
.
getModelName
(
productDao
));
}
async
getPage
(
page
=
1
,
offse
t
=
10
,
type
=
[
0
,
1
],
keywords
)
{
async
getPage
(
page
=
1
,
limi
t
=
10
,
type
=
[
0
,
1
],
keywords
)
{
let
params
=
{
where
:
{
product_type
:
{
[
this
.
db
.
Op
.
in
]:
type
}
},
limit
:
offse
t
,
offset
:
(
page
-
1
)
*
offse
t
where
:
{
product_type
:
{
[
this
.
db
.
Op
.
in
]:
type
}
,
source_id
:
10001
},
limit
:
limi
t
,
offset
:
(
page
-
1
)
*
limi
t
}
if
(
keywords
)
{
params
.
where
.
product_name
=
{
[
this
.
db
.
Op
.
like
]:
`%
${
keywords
}
%`
}
...
...
@@ -18,14 +18,14 @@ class productDao extends Dao {
async
getAllDic
(
type
=
[
0
,
1
])
{
return
await
this
.
model
.
findAll
({
where
:
{
product_type
:
{
[
this
.
db
.
Op
.
in
]:
type
}
},
where
:
{
product_type
:
{
[
this
.
db
.
Op
.
in
]:
type
}
,
source_id
:
10001
},
attributes
:
[
'id'
,
'product_type'
,
'product_name'
]
})
}
async
getByIds
(
ids
)
{
async
getByIds
(
ids
,
type
=
[
0
,
1
]
)
{
return
await
this
.
model
.
findAll
({
where
:
{
id
:
{
[
this
.
db
.
Op
.
in
]:
ids
}
}
where
:
{
id
:
{
[
this
.
db
.
Op
.
in
]:
ids
}
,
source_id
:
10001
,
product_type
:
{
[
this
.
db
.
Op
.
in
]:
type
}
}
})
}
...
...
@@ -34,7 +34,6 @@ class productDao extends Dao {
}
async
update
(
params
)
{
console
.
log
(
params
)
return
await
this
.
model
.
update
(
params
,
{
where
:
{
id
:
params
.
id
}
})
}
}
...
...
engine-product/app/base/db/impl/product/productitemDao.js
View file @
af2e3cef
...
...
@@ -4,6 +4,10 @@ class productItemDao extends Dao {
super
(
Dao
.
getModelName
(
productItemDao
));
}
async
getAll
(
params
)
{
return
await
this
.
model
.
findAll
(
params
)
}
async
getById
(
id
)
{
return
await
this
.
model
.
findOne
(
id
)
}
...
...
@@ -29,7 +33,7 @@ class productItemDao extends Dao {
}
async
delete
(
params
)
{
return
await
this
.
model
.
destroy
({
where
:
params
})
return
await
this
.
model
.
destroy
({
where
:
params
})
}
}
module
.
exports
=
productItemDao
;
\ No newline at end of file
engine-product/app/base/service/impl/product/productSve.js
View file @
af2e3cef
...
...
@@ -6,8 +6,8 @@ class ProductService extends ServiceBase {
this
.
itemDao
=
system
.
getObject
(
"db.product.productitemDao"
);
}
async
getPage
(
page
,
offse
t
,
type
,
keywords
)
{
return
await
this
.
dao
.
getPage
(
page
,
offse
t
,
type
,
keywords
)
async
getPage
(
page
,
limi
t
,
type
,
keywords
)
{
return
await
this
.
dao
.
getPage
(
page
,
limi
t
,
type
,
keywords
)
}
async
getAllDic
(
type
)
{
...
...
@@ -21,15 +21,29 @@ class ProductService extends ServiceBase {
async
getItems
(
id
)
{
const
querys
=
{
where
:
{
parent_id
:
id
},
attributes
:
[
'id'
],
distinct
:
true
,
include
:
[{
model
:
this
.
dao
.
model
,
require
:
false
,
}],
attributes
:
[
'product_id'
],
raw
:
true
};
this
.
itemDao
.
model
.
hasMany
(
this
.
dao
.
model
,
{
foreignKey
:
'id'
,
sourceKey
:
"parent_id"
});
return
await
this
.
itemDao
.
model
.
findAll
(
querys
)
let
ids
=
await
this
.
itemDao
.
getAll
(
querys
)
let
arr
=
[]
for
(
let
i
of
ids
)
{
arr
.
push
(
i
.
product_id
)
}
let
result
=
await
this
.
dao
.
getByIds
(
arr
)
return
result
}
async
checkSitem
(
ids
)
{
let
res
=
await
this
.
dao
.
getByIds
(
ids
,
[
0
])
let
arr
=
[]
for
(
let
i
of
res
)
{
arr
.
push
(
i
.
id
)
}
if
(
JSON
.
stringify
(
ids
)
==
JSON
.
stringify
(
arr
))
{
return
true
}
else
{
return
false
}
}
async
createOrUpdate
(
params
)
{
...
...
@@ -49,10 +63,12 @@ class ProductService extends ServiceBase {
params
.
source_id
=
params
.
source_id
||
10001
let
result
=
await
this
.
dao
.
create
(
params
)
let
itemArr
=
[]
for
(
let
i
of
items
)
{
itemArr
.
push
({
parent_id
:
result
.
id
,
product_id
:
i
})
if
(
items
)
{
for
(
let
i
of
items
)
{
itemArr
.
push
({
parent_id
:
result
.
id
,
product_id
:
i
})
}
let
itemResult
=
await
this
.
itemDao
.
createMany
(
itemArr
)
}
let
itemResult
=
await
this
.
itemDao
.
createMany
(
itemArr
)
return
result
}
...
...
@@ -65,11 +81,13 @@ class ProductService extends ServiceBase {
params
.
source_id
=
params
.
source_id
||
10001
let
result
=
await
this
.
dao
.
update
(
params
)
let
itemArr
=
[]
for
(
let
i
of
items
)
{
itemArr
.
push
({
parent_id
:
params
.
id
,
product_id
:
i
})
if
(
items
)
{
for
(
let
i
of
items
)
{
itemArr
.
push
({
parent_id
:
result
.
id
,
product_id
:
i
})
}
await
this
.
itemDao
.
delete
({
parent_id
:
params
.
id
})
let
itemResult
=
await
this
.
itemDao
.
createMany
(
itemArr
)
}
await
this
.
itemDao
.
delete
({
parent_id
:
params
.
id
})
let
itemResult
=
await
this
.
itemDao
.
createMany
(
itemArr
)
return
result
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment