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
710e11e5
Commit
710e11e5
authored
Jul 03, 2020
by
王昆
Browse files
Options
Browse Files
Download
Plain Diff
gsb
parents
6f6f7fa9
d35cf2dc
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
120 additions
and
18 deletions
+120
-18
engine-product/app/base/api/impl/op/action.js
+13
-3
engine-product/app/base/db/impl/product/productDao.js
+2
-2
engine-product/app/base/db/models/product/product.js
+2
-0
engine-product/app/base/service/impl/product/productSve.js
+75
-13
engine-product/app/config/routes/api.js
+28
-0
No files found.
engine-product/app/base/api/impl/op/action.js
View file @
710e11e5
...
...
@@ -37,21 +37,31 @@ class ActionAPI extends APIBase {
action_body
.
types
,
action_body
.
keywords
)
break
case
'createOrUpdate'
:
if
(
action_body
.
product_type
==
0
&&
action_body
.
items
)
{
if
(
action_body
.
product_type
==
1
&&
action_body
.
items
)
{
return
system
.
getResult
(
null
,
'单产品不能有子产品'
)
}
if
(
action_body
.
product_type
==
1
&&
(
!
action_body
.
items
||
action_body
.
items
.
length
==
0
))
{
if
(
action_body
.
product_type
==
2
&&
(
!
action_body
.
items
||
action_body
.
items
.
length
==
0
))
{
return
system
.
getResult
(
null
,
'未选择子产品'
)
}
if
(
action_body
.
product_type
==
1
)
{
if
(
action_body
.
product_type
==
2
)
{
action_body
.
items
=
action_body
.
items
.
map
(
data
=>
{
return
parseInt
(
data
)
})
let
checkRes
=
await
this
.
productSve
.
checkSitem
(
action_body
.
items
)
if
(
!
checkRes
)
{
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
)
break
case
'getAllDic'
:
if
(
!
action_body
.
types
)
{
delete
action_body
.
types
}
result
=
await
this
.
productSve
.
getAllDic
(
action_body
.
types
)
break
;
case
'getByIds'
:
...
...
engine-product/app/base/db/impl/product/productDao.js
View file @
710e11e5
...
...
@@ -16,9 +16,9 @@ class productDao extends Dao {
return
await
this
.
model
.
findAndCountAll
(
params
)
}
async
getByIds
(
ids
,
type
=
[
1
,
2
]
)
{
async
getByIds
(
ids
)
{
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
}
})
}
...
...
engine-product/app/base/db/models/product/product.js
View file @
710e11e5
...
...
@@ -5,6 +5,8 @@ module.exports = (db, DataTypes) => {
product_type
:
DataTypes
.
TINYINT
,
// 产品类型 1: 单产品, 2: 组合产品
product_desc
:
DataTypes
.
STRING
,
// 产品描述
price
:
DataTypes
.
BIGINT
,
// 价格
product_property
:
DataTypes
.
INTEGER
,
// 产品属性 1认证 2签约
api
:
DataTypes
.
STRING
,
// 产品关联api
cost
:
DataTypes
.
BIGINT
,
// 成本
},
{
paranoid
:
true
,
...
...
engine-product/app/base/service/impl/product/productSve.js
View file @
710e11e5
const
ServiceBase
=
require
(
"../../sve.base"
);
const
system
=
require
(
'../../../system'
)
const
system
=
require
(
'../../../system'
)
;
class
ProductService
extends
ServiceBase
{
constructor
()
{
super
(
"product"
,
ServiceBase
.
getDaoName
(
ProductService
));
...
...
@@ -7,13 +7,19 @@ class ProductService extends ServiceBase {
}
async
getPage
(
page
,
limit
,
type
,
keywords
)
{
return
await
this
.
dao
.
getPage
(
page
,
limit
,
type
,
keywords
)
let
result
=
await
this
.
dao
.
getPage
(
page
,
limit
,
type
,
keywords
)
for
(
let
i
=
0
;
i
<
result
.
rows
.
length
;
++
i
)
{
if
(
result
.
rows
[
i
].
price
)
{
result
.
rows
[
i
].
setDataValue
(
"price"
,
result
.
rows
[
i
].
price
/
100
)
}
}
return
result
}
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'
],
attributes
:
[
'id'
,
'product_type'
,
'product_name'
,
'price'
,
'product_property'
],
include
:
[{
model
:
this
.
itemDao
.
model
,
attributes
:
[[
'product_id'
,
'id'
]],
...
...
@@ -24,17 +30,40 @@ class ProductService extends ServiceBase {
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
=
[]
let
res
=
[]
res
=
result
[
i
].
dataValues
.
productitems
.
map
((
data
)
=>
{
return
data
.
id
})
result
[
i
].
setDataValue
(
"ids"
,
res
)
result
[
i
].
setDataValue
(
'price'
,
result
[
i
].
price
?
result
[
i
].
price
/
100
:
result
[
i
].
price
)
delete
result
[
i
].
dataValues
.
productitems
let
resItem
=
await
this
.
dao
.
model
.
findAll
({
where
:
{
id
:
{
[
this
.
db
.
Op
.
in
]:
res
}
},
attributes
:
[
'id'
,
'product_name'
,
'price'
,
'product_property'
],
raw
:
true
})
for
(
let
j
=
0
;
j
<=
resItem
.
length
;
++
j
)
{
console
.
log
(
resItem
[
j
])
if
(
resItem
[
j
]
&&
resItem
[
j
].
price
&&
resItem
[
j
].
price
>
0
)
{
resItem
[
j
].
price
=
resItem
[
j
].
price
/
100
}
}
result
[
i
].
setDataValue
(
'items'
,
resItem
)
}
return
result
}
async
getByIds
(
ids
)
{
return
await
this
.
dao
.
getByIds
(
ids
)
let
result
=
await
this
.
dao
.
getByIds
(
ids
)
for
(
let
i
=
0
;
i
<
result
.
rows
.
length
;
++
i
)
{
if
(
result
.
rows
[
i
].
price
)
{
result
.
rows
[
i
].
setDataValue
(
"price"
,
result
.
rows
[
i
].
price
/
100
)
}
}
return
result
}
async
getItems
(
id
)
{
...
...
@@ -49,11 +78,26 @@ class ProductService extends ServiceBase {
arr
.
push
(
i
.
product_id
)
}
let
result
=
await
this
.
dao
.
getByIds
(
arr
)
return
result
for
(
let
i
in
result
)
{
if
(
result
[
i
].
price
)
{
result
[
i
].
setDataValue
(
"price"
,
result
[
i
].
price
/
100
)
}
}
let
res
=
result
.
map
((
data
)
=>
{
return
data
.
id
})
let
ans
=
{}
ans
.
items
=
result
ans
.
ids
=
res
let
pro
=
await
this
.
dao
.
model
.
findOne
({
where
:
{
id
:
id
}
})
pro
.
setDataValue
(
"price"
,
pro
.
price
/
100
)
ans
.
pro
=
pro
return
ans
}
async
checkSitem
(
ids
)
{
let
res
=
await
this
.
dao
.
getByIds
(
ids
,
[
1
])
ids
=
ids
.
sort
()
let
arr
=
[]
for
(
let
i
of
res
)
{
arr
.
push
(
i
.
id
)
...
...
@@ -65,7 +109,25 @@ 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
)
{
if
(
params
.
price
)
{
params
.
price
=
Math
.
round
(
parseFloat
(
params
.
price
)
*
100
)
}
if
(
params
.
id
)
{
return
await
this
.
update
(
params
)
}
else
{
...
...
@@ -110,16 +172,16 @@ class ProductService extends ServiceBase {
return
result
}
async
apiList
()
{
async
apiList
()
{
return
[
{
key
:
"nameTwo_1"
,
name
:
"姓名二要素-e签宝"
},
{
key
:
"handsign_1"
,
name
:
"手动签-e签宝"
},
{
key
:
"autoSign_1"
,
name
:
"静默签-e签宝"
},
{
key
:
"bankThree_2"
,
name
:
"银行卡三要素-兰铂旺"
},
{
key
:
"bankFour_2"
,
name
:
"银行卡四要素-兰铂旺"
}
{
key
:
"nameTwo_1"
,
name
:
"姓名二要素-e签宝"
},
{
key
:
"handsign_1"
,
name
:
"手动签-e签宝"
},
{
key
:
"autoSign_1"
,
name
:
"静默签-e签宝"
},
{
key
:
"bankThree_2"
,
name
:
"银行卡三要素-兰铂旺"
},
{
key
:
"bankFour_2"
,
name
:
"银行卡四要素-兰铂旺"
}
]
}
async
apiMap
()
{
async
apiMap
()
{
let
list
=
await
this
.
apiList
();
let
map
=
{};
for
(
let
item
of
list
)
{
...
...
engine-product/app/config/routes/api.js
View file @
710e11e5
...
...
@@ -51,6 +51,34 @@ module.exports = function (app) {
params
.
push
(
req
.
body
);
params
.
push
(
req
.
query
);
params
.
push
(
req
);
let
keys
=
Object
.
keys
(
params
[
2
].
action_body
)
for
(
let
i
of
keys
)
{
// 小数处理
let
regdigu
=
/^
[
1-9
]\d
*
\.\d
*|0
\.\d
*
[
1-9
]\d
*$/
let
regdig
=
/^-
[
1-9
]\d
*
\.\d
*|-0
\.\d
*
[
1-9
]\d
*$/
// 整数处理
let
regint
=
/^-
?[
0-9
]\d
*$/
// 空key处理
if
(
params
[
2
].
action_body
[
i
]
==
null
||
params
[
2
].
action_body
[
i
]
==
""
||
params
[
2
].
action_body
[
i
]
==
[])
{
delete
params
[
2
].
action_body
[
i
]
}
else
if
(
Array
.
isArray
(
params
[
2
].
action_body
[
i
]))
{
// list
for
(
let
j
=
0
;
j
<
params
[
2
].
action_body
[
i
];
++
j
)
{
if
(
regdig
.
test
(
`
${
params
[
2
].
action_body
[
i
][
j
]}
`
)
||
regdigu
.
test
(
`
${
params
[
2
].
action_body
[
i
][
j
]}
`
))
{
params
[
2
].
action_body
[
i
][
j
]
=
Number
(
params
[
2
].
action_body
[
i
][
j
])
}
else
if
(
regint
.
test
(
`
${
params
[
2
].
action_body
[
i
][
j
]}
`
))
{
params
[
2
].
action_body
[
i
][
j
]
=
Number
(
params
[
2
].
action_body
[
i
][
j
])
}
}
}
else
if
(
regdig
.
test
(
`
${
params
[
2
].
action_body
[
i
]}
`
)
||
regdigu
.
test
(
`
${
params
[
2
].
action_body
[
i
]}
`
))
{
// 小数
params
[
2
].
action_body
[
i
]
=
Number
(
params
[
2
].
action_body
[
i
])
}
else
if
(
regint
.
test
(
`
${
params
[
2
].
action_body
[
i
]}
`
))
{
// 整数
params
[
2
].
action_body
[
i
]
=
Number
(
params
[
2
].
action_body
[
i
])
}
}
var
p
=
null
;
var
invokeObj
=
system
.
getObject
(
"api."
+
classPath
);
if
(
invokeObj
[
"doexec"
])
{
...
...
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