Commit 21109c83 by 蒋勇

d

parent a7cd5183
...@@ -11,5 +11,15 @@ class PricecatCtl extends CtlBase { ...@@ -11,5 +11,15 @@ class PricecatCtl extends CtlBase {
super("product", CtlBase.getServiceName(PricecatCtl)); super("product", CtlBase.getServiceName(PricecatCtl));
this.pricestrategyService=system.getObject("service.product.pricestrategySve") this.pricestrategyService=system.getObject("service.product.pricestrategySve")
} }
async buildPriceStrategy(p,q,req){
let pricetypes=p.pricetypes
let rtn=await this.pricestrategyService.buildPriceStrategy(pricetypes)
if(rtn){
if(rtn.status==-1){
return system.getResult(null,rtn.msg)
}
}
return system.getResult({})
}
} }
module.exports = PricecatCtl; module.exports = PricecatCtl;
var system = require("../../../system") var system = require("../../../system")
var settings = require("../../../../config/settings");
const CtlBase = require("../../ctl.base"); const CtlBase = require("../../ctl.base");
class PricestrategyCtl extends CtlBase { class PricestrategyCtl extends CtlBase {
constructor() { constructor() {
super("product", CtlBase.getServiceName(PricestrategyCtl)); super("product", CtlBase.getServiceName(PricestrategyCtl));
} }
async refQuery(pobj, qobj, req) {
let rtn=await this.service.refQuery(pobj);
return rtn
}
} }
module.exports = PricestrategyCtl; module.exports = PricestrategyCtl;
var system = require("../../../system")
const CtlBase = require("../../ctl.base");
class ProductCtl extends CtlBase {
constructor() {
super("product", CtlBase.getServiceName(ProductCtl));
// this.pricestrategyService=system.getObject("service.product.pricestrategySve")
}
async create(p,q,req){
let pn=await this.service.create(p)
return system.getResult(pn)
}
}
module.exports = ProductCtl;
var system = require("../../../system")
const CtlBase = require("../../ctl.base");
class ProductpriceCtl extends CtlBase {
constructor() {
super("product", CtlBase.getServiceName(ProductpriceCtl));
// this.pricestrategyService=system.getObject("service.product.pricestrategySve")
}
}
module.exports = ProductpriceCtl;
const system=require("../../../system");
const Dao=require("../../dao.base");
class ProductpriceDao extends Dao{
constructor(){
super(Dao.getModelName(ProductpriceDao));
}
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.pricestrategy,attributes:["id","optionunion"]},
{model:this.db.models.product,attributes:["id","name"]}]};
}
}
module.exports=ProductpriceDao;
// var u=new UserDao();
// var roledao=system.getObject("db.roleDao");
// (async ()=>{
// var users=await u.model.findAll({where:{app_id:1}});
// var role=await roledao.model.findOne({where:{code:"guest"}});
// console.log(role);
// for(var i=0;i<users.length;i++){
// await users[i].setRoles([role]);
// console.log(i);
// }
//
// })();
...@@ -24,6 +24,10 @@ module.exports = (db, DataTypes) => { ...@@ -24,6 +24,10 @@ module.exports = (db, DataTypes) => {
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: false, allowNull: false,
},//和user的from },//和user的from
stragetyids: {//不需要持久化
type: DataTypes.STRING,
allowNull: false,
},//和user的from
}, { }, {
paranoid: true,//假的删除 paranoid: true,//假的删除
underscored: true, underscored: true,
......
...@@ -7,22 +7,27 @@ module.exports = (db, DataTypes) => { ...@@ -7,22 +7,27 @@ module.exports = (db, DataTypes) => {
lowpriceref:{ lowpriceref:{
type: DataTypes.DECIMAL(10, 2) , type: DataTypes.DECIMAL(10, 2) ,
allowNull: false, allowNull: false,
defaultValue: 0.00
}, },
hignpriceref:{ hignpriceref:{
type: DataTypes.DECIMAL(10, 2) , type: DataTypes.DECIMAL(10, 2) ,
allowNull: false, allowNull: false,
defaultValue: 0.00
}, },
deliverfile:{ deliverfile:{
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: false, allowNull: false,
defaultValue:''
}, },
extrafile: { extrafile: {
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: false, allowNull: false,
defaultValue:''
},//和user的from相同,在注册user时,去创建 },//和user的from相同,在注册user时,去创建
desc: { desc: {
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: false, allowNull: false,
defaultValue:''
},//和user的from },//和user的from
isEnabled:{ isEnabled:{
type:DataTypes.BOOLEAN, type:DataTypes.BOOLEAN,
......
...@@ -7,8 +7,63 @@ class PricestrategyService extends ServiceBase { ...@@ -7,8 +7,63 @@ class PricestrategyService extends ServiceBase {
constructor() { constructor() {
super("product", ServiceBase.getDaoName(PricestrategyService)); super("product", ServiceBase.getDaoName(PricestrategyService));
} }
async buildPriceStrategy(){ async buildPriceStrategy(pricetypes) {
let dks = []
let codeattr=[]
let pricetypenames=[]
pricetypes.forEach(item => {
dks.push(item.options.split(","))
codeattr.push(item.code)
pricetypenames.push(item.name)
})
let codeunion=codeattr.join("~")
//先按照codeunion检查是否已经生成
let se=await this.dao.findOne({codeunion:codeunion})
if(se!=null){
return {status:-1,msg:'定价策略已经存在,无需再次生成'}
}
let nameunion=pricetypenames.join("~")
let dkresults=this.makedks(dks)
let strategys=[]
for(let dk of dkresults){
let tmp={
"codeunion":codeunion,
"nameunion":nameunion,
"optionunion":dk.split("|").join(",")
}
strategys.push(tmp)
}
var self=this;
return this.db.transaction(async function (t) {
let r=await self.dao.bulkCreate(strategys,t)
return {status:0};
});
}
makedks(rows) {
var mid = []
for (let i = 0; i < rows.length; i++) {
if (mid.length == 0) {
console.log("in..........")
let one = rows[i]
let two = rows[++i]
console.log(two, "..........")
one.forEach(item => {
two.forEach(c => {
mid.push(item + "|" + c)
})
})
} else {
let next = rows[i]
let tmparray = []
mid.forEach(m => {
next.forEach(n => {
tmparray.push(m + "|" + n)
})
})
mid = tmparray
}
}
return mid;
} }
} }
module.exports = PricestrategyService; module.exports = PricestrategyService;
......
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 create(p) {
if (!p.name || p.name == "") {
p.name = p.regionpath + "~" + p.productcatpath
}
let stragetyids = p.stragetyids
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 = []
stragetyids.forEach(stragetyid => {
let pps = {
product_id: pnew.id,
pricestrategy_id: stragetyid,
}
productprices.push(pps)
})
await self.priceDao.bulkCreate(productprices, t)
return pnew;
});
}
}
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
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