Files
bd-contest/app/service/Bind.js

41 lines
1.4 KiB
JavaScript
Raw Normal View History

'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;