Commit 203a3a25 by 任晓松

价格修改

parent 9d113880
......@@ -286,25 +286,47 @@ class ProductService extends ServiceBase {
* @returns {Promise<void>}
*/
async updateProductPrice(actionBody,appInfo){
// let productPrice = await this.findOne({pay_code:actionBody.payCode});
let sql = "SELECT a.uapp_id,a.item_name,b.id,b.product_id,b.pay_code,b.price,b.supply_price FROM `p_product` a LEFT JOIN `p_product_price` b ON a.id = b.product_id where b.pay_code = :payCode and a.uapp_id = :uapp_id";
let whereParams = {
payCode:actionBody.payCode,
uapp_id:appInfo.uapp_id
}
let productPrice = await this.customQuery(sql,whereParams);
if(!productPrice || productPrice.length == 0){
return system.getResultFail(-1,'暂无产品')
}
let price = productPrice[0].supply_price;
if(actionBody.price < price){
return system.getResultFail(-1,'修改的价格不能低于供货价!')
}
let updateFields = {
price : actionBody.price
let arr = actionBody.data;
let successRet = [];
let failRet = [];
for(let i =0;i<arr.length;i++){
const item = arr[i];
let msg = '';
if(!item.price || !item.payCode){
msg = JSON.stringify(item) + " 参数错误!"
failRet.push(msg)
continue;
}
let sql = "SELECT a.uapp_id,a.item_name,b.id,b.product_id,b.pay_code,b.price,b.supply_price FROM `p_product` a LEFT JOIN `p_product_price` b ON a.id = b.product_id where b.pay_code = :payCode and a.uapp_id = :uapp_id";
let whereParams = {
payCode:item.payCode,
uapp_id:appInfo.uapp_id
}
let productPrice = await this.customQuery(sql,whereParams);
if(!productPrice || productPrice.length == 0){
msg = item.payCode + '暂无产品,请核对payCode';
failRet.push(msg);
continue;
}
let price = productPrice[0].supply_price;
if(item.price < price){
msg = item.payCode + '修改的价格不能低于供货价!';
failRet.push(msg);
continue;
}
let updateFields = {
price : item.price
}
let ret = await this.productpriceDao.updateByWhere(updateFields, { where: { id: productPrice[0].id } });
if(ret){
msg = item.payCode + "修改成功";
successRet.push(msg)
}else{
msg = item.payCode + "修改失败";
failRet.push(msg)
}
}
this.updateByWhere(updateFields, { where: { id: productPrice[0].id } });
return system.getResultSuccess()
return system.getResultSuccess({successRet,failRet})
}
}
module.exports = ProductService;
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