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
5c4b9559
Commit
5c4b9559
authored
Jun 29, 2020
by
wkliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
接口基础功能完成
parent
3310631d
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
94 additions
and
18 deletions
+94
-18
engine-product/app/base/api/impl/op/product.js
+10
-7
engine-product/app/base/db/impl/product/productDao.js
+20
-6
engine-product/app/base/db/impl/product/productitemDao.js
+9
-0
engine-product/app/base/db/models/product/productitem.js
+1
-1
engine-product/app/base/service/impl/product/productSve.js
+54
-4
No files found.
engine-product/app/base/api/impl/op/product.js
View file @
5c4b9559
...
...
@@ -14,18 +14,21 @@ class ProductAPI extends APIBase {
let
result
switch
(
pobj
.
actionType
)
{
case
'getPage'
:
result
=
await
this
.
productSve
.
getPage
(
pobj
.
actionBody
.
page
,
pobj
.
actionBody
.
offset
,
pobj
.
actionBody
.
type
)
return
result
result
=
await
this
.
productSve
.
getPage
(
pobj
.
actionBody
.
page
,
pobj
.
actionBody
.
offset
,
pobj
.
actionBody
.
type
,
pobj
.
actionBody
.
keywords
)
return
system
.
getResult
(
result
)
case
'createOrUpdate'
:
break
case
'getAll'
:
result
=
await
this
.
productSve
.
createOrUpdate
(
pobj
.
actionBody
)
return
system
.
getResult
(
result
)
case
'getAllDic'
:
result
=
await
this
.
productSve
.
getAllDic
(
pobj
.
actionBody
.
type
)
return
result
return
system
.
getResult
(
result
)
case
'getByIds'
:
result
=
await
this
.
productSve
.
getByIds
(
pobj
.
actionBody
.
ids
)
break
return
system
.
getResult
(
result
)
case
'getItems'
:
break
result
=
await
this
.
productSve
.
getItems
(
pobj
.
actionBody
.
id
)
return
system
.
getResult
(
result
)
default
:
break
}
...
...
engine-product/app/base/db/impl/product/productDao.js
View file @
5c4b9559
...
...
@@ -4,25 +4,38 @@ class productDao extends Dao {
super
(
Dao
.
getModelName
(
productDao
));
}
async
getPage
(
page
=
1
,
offset
=
10
,
type
=
[
0
,
1
])
{
return
await
this
.
model
.
findAndCountAll
(
{
async
getPage
(
page
=
1
,
offset
=
10
,
type
=
[
0
,
1
]
,
keywords
)
{
let
params
=
{
where
:
{
product_type
:
{
[
this
.
db
.
Op
.
in
]:
type
}
},
limit
:
offset
,
offset
:
(
page
-
1
)
*
offset
})
}
if
(
keywords
)
{
params
.
where
.
product_name
=
{
[
this
.
db
.
Op
.
like
]:
`%
${
keywords
}
%`
}
}
return
await
this
.
model
.
findAndCountAll
(
params
)
}
async
getAllDic
(
type
=
[
0
,
1
])
{
// TODO: 筛选字段
return
await
this
.
model
.
findAll
({
where
:
{
product_type
:
{
[
this
.
db
.
Op
.
in
]:
type
}
}
where
:
{
product_type
:
{
[
this
.
db
.
Op
.
in
]:
type
}
},
attributes
:
[
'id'
,
'product_type'
,
'product_name'
]
})
}
async
getByIds
(
ids
)
{
return
await
this
.
model
.
get
All
({
return
await
this
.
model
.
find
All
({
where
:
{
id
:
{
[
this
.
db
.
Op
.
in
]:
ids
}
}
})
}
async
create
(
params
)
{
return
await
this
.
model
.
create
(
params
)
}
async
update
(
params
)
{
console
.
log
(
params
)
return
await
this
.
model
.
update
(
params
,
{
where
:
{
id
:
params
.
id
}
})
}
}
module
.
exports
=
productDao
;
\ No newline at end of file
engine-product/app/base/db/impl/product/productitemDao.js
View file @
5c4b9559
...
...
@@ -23,5 +23,13 @@ class productItemDao extends Dao {
}
})
}
async
createMany
(
params
)
{
return
await
this
.
model
.
bulkCreate
(
params
)
}
async
delete
(
params
)
{
return
await
this
.
model
.
destroy
({
where
:
params
})
}
}
module
.
exports
=
productItemDao
;
\ No newline at end of file
engine-product/app/base/db/models/product/productitem.js
View file @
5c4b9559
module
.
exports
=
(
db
,
DataTypes
)
=>
{
return
db
.
define
(
"product
I
tem"
,
{
return
db
.
define
(
"product
i
tem"
,
{
parent_id
:
DataTypes
.
BIGINT
,
// 父产品 id
product_id
:
DataTypes
.
BIGINT
,
// 单产品 id
},
{
...
...
engine-product/app/base/service/impl/product/productSve.js
View file @
5c4b9559
const
ServiceBase
=
require
(
"../../sve.base"
);
const
system
=
require
(
'../../../system'
)
class
ProductService
extends
ServiceBase
{
constructor
()
{
super
(
"product"
,
ServiceBase
.
getDaoName
(
ProductService
));
this
.
itemDao
=
system
.
getObject
(
"db.product.productitemDao"
);
}
async
getPage
(
page
,
offset
,
type
)
{
return
await
this
.
dao
.
getPage
(
page
,
offset
,
type
)
async
getPage
(
page
,
offset
,
type
,
keywords
)
{
return
await
this
.
dao
.
getPage
(
page
,
offset
,
type
,
keywords
)
}
async
getAllDic
(
type
)
{
...
...
@@ -17,11 +19,58 @@ class ProductService extends ServiceBase {
}
async
getItems
(
id
)
{
// TODO: relation
const
querys
=
{
where
:
{
parent_id
:
id
},
attributes
:
[
'id'
],
distinct
:
true
,
include
:
[{
model
:
this
.
dao
.
model
,
require
:
false
,
}],
};
this
.
itemDao
.
model
.
hasMany
(
this
.
dao
.
model
,
{
foreignKey
:
'id'
,
sourceKey
:
"parent_id"
});
return
await
this
.
itemDao
.
model
.
findAll
(
querys
)
}
async
createOrUpdate
(
params
)
{
// TODO:
if
(
params
.
id
)
{
return
await
this
.
update
(
params
)
}
else
{
return
await
this
.
create
(
params
)
}
}
async
create
(
params
)
{
let
items
if
(
params
.
product_type
==
1
)
{
items
=
JSON
.
parse
(
JSON
.
stringify
(
params
.
items
))
delete
params
.
items
}
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
})
}
let
itemResult
=
await
this
.
itemDao
.
createMany
(
itemArr
)
return
result
}
async
update
(
params
)
{
let
items
if
(
params
.
product_type
==
1
)
{
items
=
JSON
.
parse
(
JSON
.
stringify
(
params
.
items
))
delete
params
.
items
}
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
})
}
await
this
.
itemDao
.
delete
({
parent_id
:
params
.
id
})
let
itemResult
=
await
this
.
itemDao
.
createMany
(
itemArr
)
return
result
}
}
module
.
exports
=
ProductService
;
\ No newline at end of file
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