/** * 查找某个管理员数据 * @param {string} userName - 管理员账号 * @param {string} password - 管理员密码 * @return {object|null} - 查找结果 */ async getAdminByLogin(userName, password) { return await this.app.mysql.get('admin', { userName, password: md5(password) }); }
async updateModel(data) { // 修改数据,将会根据主键 ID 查找,并更新 const { ctx, app } = this; data.createtime = ctx.helper.currentDateTime(); const result = await app.mysql.update('tb_banner', data); return { error_code: result.affectedRows > 0 ? 0 : 1, msg: result.affectedRows > 0 ? '修改成功' : '修改失败', }; }
async getArticleDetail(id = {}) { // 通过name进行模糊查询 const TABLE_NAME = 'article'; const sql = `select * from ${TABLE_NAME} where atc_id = ${id}`; const articleList = await this.app.mysql.query(sql); const string = JSON.stringify(articleList); const list = JSON.parse(string); return { list }; }
// 后台文章分类信息 async getTypeInfo() { const resType = await this.app.mysql.select('article_type'); this.ctx.body = { data: resType }; }
//新增地址 async add(data) { const result = await this.app.mysql.insert('tb_address', data); return { insertId: result.insertId, // 添加返回的ID error_code: result.affectedRows > 0 ? 0 : 1, msg: result.affectedRows > 0 ? '添加成功' : '添加失败', }; }
async deleteDocument(data) { const result = await this.app.mysql.delete('document', { doc_id: data }); const flag = result.affectedRows; let id = null; if (flag === 1) { id = data; } return { id }; }
async addDownloadCount(atcId) { const TABLE_NAME = 'article'; const sql = `update ${TABLE_NAME} set atc_download=atc_download+1 where atc_id = ${atcId}`; const articleList = await this.app.mysql.query(sql); }
/* * mysql * @params: string db * @return: object */ mysqlClient(db) { if (!db) { db = 'user'; } return this.app.mysql.get(db); }
async addReadCount(atcId) { const TABLE_NAME = 'article'; const sql = `update ${TABLE_NAME} set atc_read=atc_read+1 where atc_id = ${atcId}`; const articleList = await this.app.mysql.query(sql); }
// 用户根据邮箱登录 async LoginByEmail(email, password) { const result = await this.app.mysql.get('tb_users', { email, password }); return { error_code: result ? 0 : 1, data: result, }; }
// 根据id查询数据 async findByID(id) { const result = await this.app.mysql.get('tb_goods', { id }); return { data: result }; }
/** * 查找某个商家数据 * @param {string} userName - 商家账号 * @param {string} password - 商家密码 * @return {object|null} - 查找结果 */ async getMerchantByLogin(userName, password) { return await this.app.mysql.get('merchant', { userName, password: md5(password) }); }
// 前端 async getDocList(json = {}) { // 通过name进行模糊查询 const sql = 'select * from document order by doc_weight desc'; const documentList = await this.app.mysql.query(sql); const string = JSON.stringify(documentList); const list = JSON.parse(string); return { list }; }
// 前端 async getTlList(json = {}) { // 通过name进行模糊查询 const sql = 'select * from tool order by tl_weight desc'; const toolList = await this.app.mysql.query(sql); const string = JSON.stringify(toolList); const list = JSON.parse(string); return { list }; }
async deleteTool(data) { const result = await this.app.mysql.delete('tool', { tl_id: data }); const flag = result.affectedRows; let id = null; if (flag === 1) { id = data; } return { id }; }