Commit 6b0b50c3 by 王昆

gsb

parent 15dc7119
...@@ -186,6 +186,31 @@ class Dao{ ...@@ -186,6 +186,31 @@ class Dao{
} }
return this.db.query(sql,tmpParas); return this.db.query(sql,tmpParas);
} }
async customUpdate(sql, paras, t) {
var tmpParas = null;
if (t && t != 'undefined') {
if (paras == null || paras == 'undefined') {
tmpParas = {
type: this.db.QueryTypes.UPDATE
};
tmpParas.transaction = t;
} else {
tmpParas = {
replacements: paras,
type: this.db.QueryTypes.UPDATE
};
tmpParas.transaction = t;
}
} else {
tmpParas = paras == null || paras == 'undefined' ? {
type: this.db.QueryTypes.UPDATE
} : {
replacements: paras,
type: this.db.QueryTypes.UPDATE
};
}
return this.db.query(sql, tmpParas);
}
async findCount(whereObj=null){ async findCount(whereObj=null){
return this.model.count(whereObj, {logging : false}).then(c=>{ return this.model.count(whereObj, {logging : false}).then(c=>{
return c; return c;
......
...@@ -5,6 +5,12 @@ class LDUserDao extends Dao { ...@@ -5,6 +5,12 @@ class LDUserDao extends Dao {
constructor() { constructor() {
super(Dao.getModelName(LDUserDao)); super(Dao.getModelName(LDUserDao));
} }
async updateBalance(id, amt) {
let sql = `UPDATE ${this.model.tableName} SET p_user_balance = p_user_balance + :amt WHERE id = :id AND p_user_balance + :amt >= 0`;
let rs = await this.customUpdate(sql, {id: id, amt: amt});
return rs;
}
} }
module.exports = LDUserDao; module.exports = LDUserDao;
...@@ -5,6 +5,20 @@ class LDUserBankDao extends Dao { ...@@ -5,6 +5,20 @@ class LDUserBankDao extends Dao {
constructor() { constructor() {
super(Dao.getModelName(LDUserBankDao)); super(Dao.getModelName(LDUserBankDao));
} }
async listByCondition(params) {
let sql = [];
sql.push("SELECT");
sql.push(params.attrs || "*");
sql.push("FROM");
sql.push(this.model.tableName);
sql.push("WHERE 1 = 1");
if (params.user_id) {
sql.push("AND user_id = :user_id");
}
return await this.customQuery(sql.join(" "), params);
}
} }
module.exports = LDUserBankDao; module.exports = LDUserBankDao;
...@@ -10,12 +10,20 @@ class LDUserService extends ServiceBase { ...@@ -10,12 +10,20 @@ class LDUserService extends ServiceBase {
async loginH5(params) { async loginH5(params) {
let p_id = params.p_id; let p_id = params.p_id;
let p_user_id = params.p_user_id; let p_user_id = params.p_user_id;
let p_user_balance = system.y2f(params.p_user_balance);
let user = await this.dao.findOne({p_id: p_id, p_user_id: p_user_id}); let user = await this.dao.findOne({p_id: p_id, p_user_id: p_user_id});
if (!user) { if (!user) {
user = await this.dao.create(params); user = await this.dao.create(params);
} else {
user.p_user_balance = p_user_balance;
user.save();
} }
return user; return user;
} }
async updateBalance(id, balance) {
return await this.dao.updateBalance(id, balance);
}
} }
module.exports = LDUserService; module.exports = LDUserService;
\ No newline at end of file
...@@ -6,6 +6,12 @@ class LDUserBankService extends ServiceBase { ...@@ -6,6 +6,12 @@ class LDUserBankService extends ServiceBase {
constructor() { constructor() {
super(ServiceBase.getDaoName(LDUserBankService)); super(ServiceBase.getDaoName(LDUserBankService));
} }
async listByCondition(params) {
let rs = await this.dao.listByCondition(params);
return rs;
}
} }
module.exports = LDUserBankService; module.exports = LDUserBankService;
\ No newline at end of file
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