北斗导航定位通信综合实践赛服务系统
This commit is contained in:
41
app/service/Bind.js
Normal file
41
app/service/Bind.js
Normal file
@@ -0,0 +1,41 @@
|
||||
'use strict';
|
||||
|
||||
const Service = require('../core/base_service');
|
||||
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
const fileName = "Bind";
|
||||
|
||||
class BindService extends Service {
|
||||
// 竞赛账号绑定北斗卡
|
||||
async bindCard(uid, card_id, card_imsi) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const card = await ctx.model3.BDCard.update({ status: 3 }, { where: { card_id, card_imsi, status: 0 } });
|
||||
if (card[0] == 0) return false;
|
||||
const result = await ctx.model4.TuserBind.create({ user_uid: uid, card_id });
|
||||
return result ? true : false;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "bindCard";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 竞赛账号解绑北斗卡
|
||||
async unBindCard(uid, card_id, card_imsi) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const card = await ctx.model3.BDCard.update({ status: 0 }, { where: { card_id, card_imsi, status: 3 } });
|
||||
if (card[0] == 0) return false;
|
||||
const result = await ctx.model4.TuserBind.destroy({ where: { user_uid: uid } });
|
||||
return result.length == 0 ? false : true;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "unBindCard";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BindService;
|
||||
Reference in New Issue
Block a user