Commit 203a3a25 by 任晓松

价格修改

parent 9d113880
...@@ -286,25 +286,47 @@ class ProductService extends ServiceBase { ...@@ -286,25 +286,47 @@ class ProductService extends ServiceBase {
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
async updateProductPrice(actionBody,appInfo){ async updateProductPrice(actionBody,appInfo){
// let productPrice = await this.findOne({pay_code:actionBody.payCode}); let arr = actionBody.data;
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 successRet = [];
let whereParams = { let failRet = [];
payCode:actionBody.payCode, for(let i =0;i<arr.length;i++){
uapp_id:appInfo.uapp_id const item = arr[i];
} let msg = '';
let productPrice = await this.customQuery(sql,whereParams); if(!item.price || !item.payCode){
if(!productPrice || productPrice.length == 0){ msg = JSON.stringify(item) + " 参数错误!"
return system.getResultFail(-1,'暂无产品') failRet.push(msg)
} continue;
let price = productPrice[0].supply_price; }
if(actionBody.price < price){ 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";
return system.getResultFail(-1,'修改的价格不能低于供货价!') let whereParams = {
} payCode:item.payCode,
let updateFields = { uapp_id:appInfo.uapp_id
price : actionBody.price }
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({successRet,failRet})
return system.getResultSuccess()
} }
} }
module.exports = ProductService; 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