home.service
/**
* 文件上传,接收图片并插入到数据库中
*/
async upload(params) {
console.log('333', params);
const result = await app.mysql.insert('image', params);
if (result.affectedRows === 1) {
const temp_img = await app.mysql.get('image', {
id: result.insertId
});
if (temp_img !== null) {
this.config.back_data.code = 200;
this.config.back_data.data = {
id: temp_img.id,
url: temp_img.url,
};
this.config.back_data.msg = '上传成功';
} else {
this.config.back_data.code = 400;
this.config.back_data.data = {};
this.config.back_data.msg = '失败';
}
} else {
this.config.back_data.code = 10000;
this.config.back_data.data = [];
this.config.back_data.msg = '上传失败';
}
return this.config.back_data;
}