Commit e2fdfef5 by zhaoxiqing

gsb

parent 66a97040
......@@ -2,55 +2,54 @@ const system = require("../../../system");
const Dao = require("../../dao.base");
class AccountDao extends Dao {
constructor() {
super(Dao.getModelName(AccountDao));
}
async incrementBalance(id, balance, t) {
let sql = [];
sql.push("UPDATE");
sql.push(this.model.tableName);
sql.push("SET");
sql.push("balance = balance + :balance");
sql.push("WHERE id = :id AND balance + :balance >= 0");
let res = await this.customUpdate(sql.join(" "), {id: id, balance: balance}, t);
console.log(res);
if (res.length < 2) {
return 0;
constructor() {
super(Dao.getModelName(AccountDao));
}
return res[1] || 0;
}
async listByIds(ids, attrs) {
if (!ids || ids.length == 0) {
return [];
async incrementBalance(id, balance, t) {
let sql = [];
sql.push("UPDATE");
sql.push(this.model.tableName);
sql.push("SET");
sql.push("balance = balance + :balance");
sql.push("WHERE id = :id AND balance + :balance >= 0");
let res = await this.customUpdate(sql.join(" "), {id: id, balance: balance}, t);
console.log(res);
if (res.length < 2) {
return 0;
}
return res[1] || 0;
}
var sql = [];
sql.push("SELECT");
sql.push(attrs || "*");
sql.push("FROM");
sql.push(this.model.tableName);
sql.push("WHERE id IN (:ids)");
return await this.customQuery(sql.join(" "), {
ids: ids
}) || [];
}
async mapByIds(ids, attrs) {
var result = {};
if (!ids || ids.length == 0) {
return result;
}
var list = await this.findListByIds(ids, attrs);
if (!list || list.length == 0) {
return result;
async listByIds(ids, attrs) {
if (!ids || ids.length == 0) {
return [];
}
var sql = [];
sql.push("SELECT");
sql.push(attrs || "*");
sql.push("FROM");
sql.push(this.model.tableName);
sql.push("WHERE id IN (:ids)");
return await this.customQuery(sql.join(" "), {
ids: ids
}) || [];
}
for (var item of list) {
result[item.id] = item;
}
return result;
}
async mapByIds(ids, attrs) {
var result = {};
if (!ids || ids.length == 0) {
return result;
}
var list = await this.listByIds(ids, attrs);
if (!list || list.length == 0) {
return result;
}
for (var item of list) {
result[item.id] = item;
}
return result;
}
}
......
......@@ -11,13 +11,11 @@ class MerchantDao extends Dao {
return list || [];
}
async findMapByIds(ids, attrs) {
var result = [];
var result = {};
if (!ids || ids.length == 0) {
return result;
}
attrs = attrs || "*";
var sql = "SELECT " + attrs + " FROM e_merchant where id IN (:ids) ";
var list = await this.customQuery(sql, {ids: ids});
......@@ -31,24 +29,6 @@ class MerchantDao extends Dao {
return result;
}
async findMapInIds(ids, attrs) {
var result = [];
if (!ids || ids.length == 0) {
return result;
}
attrs = attrs || "*";
var sql = "SELECT " + attrs + " FROM e_merchant where id IN (:ids) ";
var list = await this.customQuery(sql, {ids: ids});
if (!list || list.length == 0) {
return result;
}
return list;
}
}
module.exports = MerchantDao;
......@@ -126,7 +126,7 @@ class MerchantService extends ServiceBase {
if (params.merchantIds.length == 0) {
return system.getResultFail(-1, "请提供商户ID");
}
var merchantMap = await this.dao.findMapInIds(params.merchantIds);
var merchantMap = await this.dao.findMapByIds(params.merchantIds);
return system.getResultSuccess(merchantMap);
} catch (e) {
......
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