Commit b407de27 by linboxuan

tmStatusUpdate增加批量状态修改的接口

parent 23049e43
......@@ -439,17 +439,17 @@ class TrademarktransactionService extends ServiceBase {
* {
"actionType": "tmStatusUpdate",
"actionBody": {
tm:[
"tm":[
{
id:1,
code:1,
platform_quoted_price:1200
"id":1,
"code":1,
"platform_quoted_price":1200
},{
id:2,
code;2,
platform_quoted_price:1200
"id":2,
"code":2,
"platform_quoted_price":1200
}
],
]
status:"uppershelf/lowershelf"
}
}
......@@ -505,31 +505,38 @@ class TrademarktransactionService extends ServiceBase {
// 如果下架 全部下架
case "lowershelf" :
for(var i = 0;i <actionBody.tm.length;i++) {
actionBody.tm[i].publish_status = "lowershelf"
await this.dao.model.update({publish_status:"lowershelf"},{ where: { id: actionBody.tm[i].id } })
}
var tmUpdateResult = await this.dao.model.bulkCreate(actionBody.tm,{updateOnDuplicate:true})
// 这个方法会把其他字段改为null 不使用了
// var tmUpdateResult = await this.dao.model.bulkCreate(actionBody.tm,{updateOnDuplicate:true})
break;
case "uppershelf":
var tmUpdateResult = []
// 如果上架 去查询code相同并上架的标源,价格低于,则上。否失败
for(var i = 0;i <actionBody.tm.length;i++) {
// 查处code相同 id不相同 状态为上架的标
var tmInfo = await this.dao.model.findOne({
where: { code:actionBody.tm[i].code, publish_status:"uppershelf" },
where: { code:actionBody.tm[i].code, publish_status:"uppershelf",[this.db.Op.not]: [{id:[actionBody.tm[i].id]}] },
attributes: [
"id",
"platform_quoted_price"
],
raw: true
});
// 如果没有 随意更改
if(!tmInfo) {
await this.dao.model.update({publish_status:"uppershelf"},{ where: { id: actionBody.tm[i].id } })
continue
}
// 如果有并 价格低于之前上架的
if(actionBody.tm[i].platform_quoted_price < tmInfo.platform_quoted_price) {
//修改之前的为下架
tmInfo.publish_status = "lowershelf";
await this.dao.model.update(tmInfo)
await this.dao.model.update({publish_status:"lowershelf"},{ where: { id: tmInfo.id } })
//修改需要上架的
actionBody.tm[i].publish_status = "uppershelf";
await this.dao.model.update(actionBody.tm[i])
await this.dao.model.update({publish_status:"uppershelf"},{ where: { id: actionBody.tm[i].id } })
}
// 否则失败 暂时不做处理
// 可以优化的地方:比如已经是想修改的状态 怎么做跳过?其他验证是否完善?
}
break;
default:
......
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