Commit 89e1bfdf by 兰国旗

Merge branch 'gsb-marketplat-mag' of gitlab.gongsibao.com:jiangyong/zhichan into gsb-marketplat-mag

parents 836e5946 993dd16a
...@@ -4,30 +4,30 @@ class ProducttypeDao extends Dao { ...@@ -4,30 +4,30 @@ class ProducttypeDao extends Dao {
constructor() { constructor() {
super(Dao.getModelName(ProducttypeDao)); super(Dao.getModelName(ProducttypeDao));
} }
async findAndCountAll(req) { // async findAndCountAll(req) {
var params = { // var params = {
// company_id: req.actionBody.company_id // // company_id: req.actionBody.company_id
company_id: 10 // company_id: 10
}; // };
var returnRes = { // var returnRes = {
results: {rows:[],count:[]} // results: {rows:[],count:[]}
}; // };
var dataCount = "select count(1) as dataCount from mc_product_type where deleted_at is null and p_id = 0 and company_id = :company_id "; // var dataCount = "select count(1) as dataCount from mc_product_type where deleted_at is null and p_id = 0 and company_id = :company_id ";
var sql = "select * from mc_product_type where deleted_at is null and p_id = 0 and company_id = :company_id "; // var sql = "select * from mc_product_type where deleted_at is null and p_id = 0 and company_id = :company_id ";
var childData = "select *,count(1) as childCount from mc_product_type where p_id !=0 and company_id = :company_id group by p_id"; // var childData = "select *,count(1) as childCount from mc_product_type where p_id !=0 and company_id = :company_id group by p_id";
var list = await this.customQuery(sql, params); // var list = await this.customQuery(sql, params);
returnRes.results.rows = list; // returnRes.results.rows = list;
var tmpResultCount = await this.customQuery(dataCount, params); // var tmpResultCount = await this.customQuery(dataCount, params);
returnRes.results.count = tmpResultCount && tmpResultCount.length > 0 ? tmpResultCount[0].dataCount : 0; // returnRes.results.count = tmpResultCount && tmpResultCount.length > 0 ? tmpResultCount[0].dataCount : 0;
var childrenData = await this.customQuery(childData, params); // var childrenData = await this.customQuery(childData, params);
for(var i=0;i<childrenData.length;i++){ // for(var i=0;i<childrenData.length;i++){
returnRes.results.rows[i].childCount = childrenData && childrenData[i].childCount > 0 ? childrenData[i].childCount : 0; // returnRes.results.rows[i].childCount = childrenData && childrenData[i].childCount > 0 ? childrenData[i].childCount : 0;
} // }
console.log(returnRes) // console.log(returnRes)
return returnRes; // return returnRes;
} // }
} }
module.exports = ProducttypeDao; module.exports = ProducttypeDao;
...@@ -21,7 +21,10 @@ module.exports = (db, DataTypes) => { ...@@ -21,7 +21,10 @@ module.exports = (db, DataTypes) => {
strategy_date: { strategy_date: {
type: DataTypes.INTEGER type: DataTypes.INTEGER
}, },
strategy_time: { strategy_time_start: {
type: DataTypes.STRING
},
strategy_time_end: {
type: DataTypes.STRING type: DataTypes.STRING
}, },
button_type: { button_type: {
......
...@@ -24,6 +24,9 @@ module.exports = (db, DataTypes) => { ...@@ -24,6 +24,9 @@ module.exports = (db, DataTypes) => {
recommend_product: { recommend_product: {
type: DataTypes.JSON type: DataTypes.JSON
}, },
link_url: {
type: DataTypes.STRING
},
}, },
{ {
paranoid: true,//假的删除 paranoid: true,//假的删除
......
...@@ -57,12 +57,12 @@ class ProductService extends ServiceBase { ...@@ -57,12 +57,12 @@ class ProductService extends ServiceBase {
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
async getProductsByType(pobj){ async getProductsByType(pobj){
const type = await this.producttypeDao.findOne({name:pobj.typeName},[]); const type = await this.producttypeDao.findOne({code:pobj.typeName},[]);
if(!type){ if(!type){
return system.getResultFail(-1,'获取产品类型数据失败'); return system.getResultFail(-1,'获取产品类型数据失败');
} }
let products = await this.dao.model.findAll({ let products = await this.dao.model.findAll({
attributes:["name"], attributes:["code","name"],
where:{product_type_id:type.id},raw:true where:{product_type_id:type.id},raw:true
}); });
return system.getResult(products) return system.getResult(products)
......
...@@ -7,6 +7,14 @@ class ProducttypeService extends ServiceBase { ...@@ -7,6 +7,14 @@ class ProducttypeService extends ServiceBase {
} }
async findAndCountAll (obj) { async findAndCountAll (obj) {
let res = await this.dao.findAndCountAll(obj); let res = await this.dao.findAndCountAll(obj);
if(obj && obj.search && obj.search.p_id === 0 && res && res.results && res.results.rows && res.results.rows.length>0){
for(var i=0;i<res.results.rows.length;i++){
if(res.results.rows[i].id){
var count = await this.dao.findCount({ where: {p_id:res.results.rows[i].id} });
res.results.rows[i].dataValues.childCount = count;
}
}
}
return system.getResultSuccess(res); return system.getResultSuccess(res);
} }
async create(pobj) { async create(pobj) {
......
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