1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- 'use strict';
- const Service = require('egg').Service;
- class IconsService extends Service {
- async list(query) {
- let code = query.code;
- let where = code ? `where (id like '%${code}%' or name like '%${code}%' ) `: "";
- let type = query.type;
- if( type != undefined ) {
- where = where?where + `and (\`type\` like '%${type}$'`: `where \`type\` like '%${type}%'`;
- }
- let ctx = this.ctx;
- let ret = await ctx.pageSelect(query, 'icons', `id, name, type, icon, ${ctx.SqlFmtTime("add_time")}`, where);
- return ret;
- }
- async add( data ) {
- let mysql = this.app.mysql;
- data.add_time = mysql.literals.now;
- let ret = await mysql.insert("icons", data);
- return {id: ret.insertId};
- }
- async edit( data ) {
- let id = data.id;
- if( !id ) throw "id不为空";
- let mysql = this.app.mysql;
- let ret = await mysql.update("icons", data, {where:{id: data.id}});
- return ret;
- }
- async delete(data)
- {
- let mysql = this.app.mysql;
- let ret = await mysql.query("delete from icons where id=?",[data.id]);
- return ret;
- }
- //app相关接口
- async listInApp(query) {
- let type = query.type;
- let where = type ? `where \`type\`='${type}' `: "";
- let ctx = this.ctx;
- if( query.pageNo == '0') query.pageNo =1;
- let ret = await ctx.pageSelect(query, 'icons', `id, name, type, icon`, where);
- let server = this.app.config.server;
- ret.records.forEach(element => {
- element.icon = server.publicHost + element.icon;
- });
- return ret;
- }
- }
- module.exports = IconsService;
|