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
171ce4b7
Commit
171ce4b7
authored
Jun 08, 2020
by
蒋勇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
d
parent
21109c83
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
130 additions
and
36 deletions
+130
-36
center-manage/app/base/controller/impl/product/productpriceCtl.js
+5
-0
center-manage/app/base/db/dao.base.js
+12
-3
center-manage/app/base/db/impl/product/productDao.js
+16
-0
center-manage/app/base/db/models/product/product.js
+0
-4
center-manage/app/base/db/models/product/productprice.js
+10
-4
center-manage/app/base/service/impl/product/productSve.js
+71
-24
center-manage/app/base/service/impl/product/productpriceSve.js
+15
-0
center-manage/app/base/system.js
+1
-1
No files found.
center-manage/app/base/controller/impl/product/productpriceCtl.js
View file @
171ce4b7
...
...
@@ -5,5 +5,10 @@ class ProductpriceCtl extends CtlBase {
super
(
"product"
,
CtlBase
.
getServiceName
(
ProductpriceCtl
));
// this.pricestrategyService=system.getObject("service.product.pricestrategySve")
}
async
updownProduct
(
p
,
q
,
req
){
let
updownid
=
p
.
curid
let
rtn
=
await
this
.
service
.
updownProduct
(
updownid
)
return
system
.
getResult
(
rtn
)
}
}
module
.
exports
=
ProductpriceCtl
;
center-manage/app/base/db/dao.base.js
View file @
171ce4b7
...
...
@@ -48,9 +48,15 @@ class Dao {
return
this
.
model
.
findAll
({
where
:
w
,
attributes
:
qobj
.
fields
});
}
}
async
bulkDelete
(
ids
)
{
var
en
=
await
this
.
model
.
destroy
({
where
:
{
id
:
{
[
this
.
db
.
Op
.
in
]:
ids
}
}
});
return
en
;
async
bulkDelete
(
ids
,
t
)
{
if
(
t
){
var
en
=
await
this
.
model
.
destroy
({
where
:
{
id
:
{
[
this
.
db
.
Op
.
in
]:
ids
}
},
transaction
:
t
});
return
en
;
}
else
{
var
en
=
await
this
.
model
.
destroy
({
where
:
{
id
:
{
[
this
.
db
.
Op
.
in
]:
ids
}
}});
return
en
}
}
async
bulkDeleteByWhere
(
whereParam
,
t
)
{
var
en
=
null
;
...
...
@@ -270,6 +276,9 @@ class Dao {
async
findOne
(
obj
)
{
return
this
.
model
.
findOne
({
"where"
:
obj
});
}
async
findOneWithTm
(
obj
,
t
)
{
return
this
.
model
.
findOne
({
"where"
:
obj
,
transaction
:
t
});
}
async
findById
(
oid
)
{
return
this
.
model
.
findById
(
oid
);
}
...
...
center-manage/app/base/db/impl/product/productDao.js
0 → 100644
View file @
171ce4b7
const
system
=
require
(
"../../../system"
);
const
Dao
=
require
(
"../../dao.base"
);
class
ProductDao
extends
Dao
{
constructor
()
{
super
(
Dao
.
getModelName
(
ProductDao
));
}
extraModelFilter
()
{
//return {"key":"include","value":[{model:this.db.models.app,},{model:this.db.models.role,as:"Roles",attributes:["id","name"],joinTableAttributes:['created_at']}]};
return
{
"key"
:
"include"
,
"value"
:
[
{
model
:
this
.
db
.
models
.
productprice
,
as
:
"skus"
,
attributes
:
[
"id"
,
"pricestrategy_id"
]
}]
}
}
}
module
.
exports
=
ProductDao
;
\ No newline at end of file
center-manage/app/base/db/models/product/product.js
View file @
171ce4b7
...
...
@@ -24,10 +24,6 @@ module.exports = (db, DataTypes) => {
type
:
DataTypes
.
STRING
,
allowNull
:
false
,
},
//和user的from
stragetyids
:
{
//不需要持久化
type
:
DataTypes
.
STRING
,
allowNull
:
false
,
},
//和user的from
},
{
paranoid
:
true
,
//假的删除
underscored
:
true
,
...
...
center-manage/app/base/db/models/product/productprice.js
View file @
171ce4b7
...
...
@@ -4,15 +4,21 @@ const appconfig=system.getSysConfig();
module
.
exports
=
(
db
,
DataTypes
)
=>
{
//定价类型
return
db
.
define
(
"productprice"
,
{
pname
:{
//产品名称
type
:
DataTypes
.
STRING
,
allowNull
:
true
,
},
strategyitems
:{
//定价策略
type
:
DataTypes
.
STRING
,
allowNull
:
true
,
},
lowpriceref
:{
type
:
DataTypes
.
DECIMAL
(
10
,
2
)
,
allowNull
:
false
,
defaultValue
:
0.00
allowNull
:
true
,
},
hignpriceref
:{
type
:
DataTypes
.
DECIMAL
(
10
,
2
)
,
allowNull
:
false
,
defaultValue
:
0.00
allowNull
:
true
,
},
deliverfile
:{
type
:
DataTypes
.
STRING
,
...
...
center-manage/app/base/service/impl/product/productSve.js
View file @
171ce4b7
const
system
=
require
(
"../../../system"
);
const
ServiceBase
=
require
(
"../../sve.base"
);
const
settings
=
require
(
"../../../../config/settings"
);
const
appconfig
=
system
.
getSysConfig
();
const
fs
=
require
(
"fs"
)
class
ProductService
extends
ServiceBase
{
constructor
()
{
super
(
"product"
,
ServiceBase
.
getDaoName
(
ProductService
));
this
.
priceDao
=
system
.
getObject
(
"db.product.productpriceDao"
)
}
async
findPriceStrategys
(
stragetyids
,
t
){
//按照策略id查询出定价策略集合
let
pts
=
await
this
.
db
.
models
.
pricestrategy
.
findAll
({
where
:
{
id
:
{
[
this
.
db
.
Op
.
in
]:
stragetyids
}
},
attributes
:[
'id'
,
'optionunion'
],
transaction
:
t
})
let
tmpdic
=
{}
pts
.
forEach
(
p
=>
{
tmpdic
[
p
.
id
+
''
]
=
p
.
optionunion
})
return
tmpdic
}
async
create
(
p
)
{
if
(
!
p
.
name
||
p
.
name
==
""
)
{
p
.
name
=
p
.
regionpath
+
"~"
+
p
.
productcatpath
}
let
stragetyids
=
p
.
stragetyids
//策略ids
let
stragetyids
=
p
.
sts
var
self
=
this
;
return
this
.
db
.
transaction
(
async
function
(
t
)
{
p
.
stragetyids
=
p
.
stragetyids
.
join
(
","
)
let
pnew
=
await
self
.
dao
.
create
(
p
,
t
)
let
productprices
=
[]
//按照策略id查询出定价策略集合
let
tmpdic
=
await
self
.
findPriceStrategys
(
stragetyids
,
t
)
stragetyids
.
forEach
(
stragetyid
=>
{
let
pps
=
{
product_id
:
pnew
.
id
,
pricestrategy_id
:
stragetyid
,
pname
:
p
.
name
,
strategyitems
:
tmpdic
[
stragetyid
+
''
]
}
productprices
.
push
(
pps
)
})
...
...
@@ -29,22 +39,59 @@ class ProductService extends ServiceBase {
return
pnew
;
});
}
async
update
(
p
)
{
if
(
!
p
.
name
||
p
.
name
==
""
)
{
p
.
name
=
p
.
regionpath
+
"~"
+
p
.
productcatpath
}
//策略ids
let
stragetyids
=
p
.
sts
var
self
=
this
;
return
this
.
db
.
transaction
(
async
function
(
t
)
{
let
pupdate
=
await
self
.
dao
.
update
(
p
,
t
)
//先按照产品id检查出当前产品的价格策略,检查出不在传入中的,需要删除
//在传入中的不做处理
let
currentProduct
=
await
self
.
dao
.
model
.
findOne
({
where
:
{
id
:
p
.
id
},
include
:
[
{
model
:
self
.
db
.
models
.
productprice
,
as
:
"skus"
,
attributes
:
[
'id'
,
'pricestrategy_id'
],
raw
:
true
},
],
transaction
:
t
})
let
notInInput
=
[]
//需要删除
let
skusarray
=
[]
currentProduct
.
skus
.
forEach
(
sku
=>
{
skusarray
.
push
(
sku
.
pricestrategy_id
)
if
(
stragetyids
.
indexOf
(
sku
.
pricestrategy_id
)
<
0
){
notInInput
.
push
(
sku
.
id
)
}
})
//删除
if
(
notInInput
.
length
>
0
){
await
self
.
priceDao
.
bulkDelete
(
notInInput
,
t
)
}
//传入不在查出中的,需要新增
let
notintables
=
[]
stragetyids
.
forEach
(
st
=>
{
if
(
skusarray
.
indexOf
(
st
)
<
0
){
notintables
.
push
(
st
)
}
})
//新增
let
productprices
=
[]
let
tmpdic
=
await
self
.
findPriceStrategys
(
stragetyids
,
t
)
notintables
.
forEach
(
stragetyid
=>
{
let
pps
=
{
product_id
:
p
.
id
,
pricestrategy_id
:
stragetyid
,
pname
:
p
.
name
,
strategyitems
:
tmpdic
[
stragetyid
+
''
]
}
productprices
.
push
(
pps
)
})
if
(
productprices
.
length
>
0
){
await
self
.
priceDao
.
bulkCreate
(
productprices
,
t
)
}
return
{};
});
}
}
module
.
exports
=
ProductService
;
// (async ()=>{
// let u=new AppService();
// // let x=await u.cregister("jiangong")
// // console.log(x)
// // let x=await u.cunregister("jiangong")
// // console.log(x)
// // let t=await u.cmakejwt()
// // console.log(t)
// //let ux=await u.cjsonregister(AppService.newRouteUrl("test-service2"),{name:"test-service2",hosts:["ttest1.com"]})
// //let ux=await u.cjsonregister(AppService.newServiceUrl(),{name:"test-service3",url:"http://zhichan.gongsibao.com"})
// //let ux=await u.cdel(AppService.routeUrl("test-service2"))
// //let ux=await u.cdel(AppService.serviceUrl("test-service2"))
// // let ux=await u.create({name:"test4-service",backend:"zhichan-service",domainName:"domain.com"})
// // console.log(ux);
// // let delrtn=await u.delete({id:2,name:"test4-service"})
// // console.log(delrtn);
// })()
\ No newline at end of file
module
.
exports
=
ProductService
;
\ No newline at end of file
center-manage/app/base/service/impl/product/productpriceSve.js
0 → 100644
View file @
171ce4b7
const
system
=
require
(
"../../../system"
);
const
ServiceBase
=
require
(
"../../sve.base"
);
class
ProductpriceService
extends
ServiceBase
{
constructor
()
{
super
(
"product"
,
ServiceBase
.
getDaoName
(
ProductpriceService
));
}
async
updownProduct
(
uid
){
let
p
=
await
this
.
dao
.
findById
(
uid
)
p
.
isEnabled
=!
p
.
isEnabled
await
p
.
save
()
return
{}
}
}
module
.
exports
=
ProductpriceService
;
\ No newline at end of file
center-manage/app/base/system.js
View file @
171ce4b7
...
...
@@ -217,7 +217,7 @@ class System {
try
{
ClassObj
=
require
(
objabspath
);
}
catch
(
e
)
{
//
console.log(e)
//console.log(e)
let
fname
=
objsettings
[
packageName
+
"base"
];
ClassObj
=
require
(
fname
);
}
...
...
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