'use strict'; const Service = require('egg').Service; const md5 = require('md5-node'); class AppUserService extends Service { async login(name, password) { let { ctx , config, app} = this; let pwdmd5 = md5(password); //验证用户是否存在 let data = await ctx.model.Admin.find({name, password: pwdmd5}); if( data.length < 1 ) { throw '用户名或密码错误!'; } let info = data[0]; const beijingTimeOffset = 28800000; let ret = await ctx.model.Admin.update({_id: info._id}, {$set:{lastLogin: Date.now()+beijingTimeOffset}}); let token = await ctx.jwtSign({name:info.name, id:info._id, role:info.role}, config.loginAdmin.secret, { expiresIn: 60 * 60 }); return {token, role: info.name}; } async getFamily( userid ){ let {app} = this; let user = await app.mysql.select("app_user_family", { where:{user_id: userid}, columns:["id","name","avatar","relation","ins_num","coverage_amt_total","birthday","career_type","income_num","loan_type"]}); return user; } async addFamily( userid , data) { let { app } = this; data.user_id = userid; data.coverage_amt_total = 0; data.ins_num = 0; console.log("adding family", data); let ret = await app.mysql.insert("app_user_family", data); return ret; } async deleteFamily(id){ let ret = await this.app.mysql.delete("app_user_family", {id}); return ret; } async updateFamily( userid, data ) { let { app } = this; let ret = await app.mysql.update("app_user_family", data, {id: data.id}); return ret; } async add ( data ) { } //个人中心返回用户基本信息 async info(uid) { let mysql = this.app.mysql; let ret = await mysql.get("app_user", {id: uid}, {columns:["id","name", "tel", "sex", "avatar","wechat","address","birthday"]}); return ret; } async updateInfo(uid, data) { let mysql = this.app.mysql; let ret = await mysql.update("app_user", data, {where: {id: uid}}); return ret; } async send(uid, data) { let mysql = this.app.mysql; let phones = data.phones; let tels = phones.split(","); let n = tels.length; let inserted = 0; let i=0; for( ;i