alipay.service.js 942 Bytes
const alipayRepository = require('./alipay.repository');
const { logger } = global.yoho;

async function create({ uid, alipayAccount, alipayName }) {
  try {
    const result = await alipayRepository.insert({
      uid, alipayAccount, alipayName
    });

    if (!result) {
      return {
        error: {
          code: 500,
          message: '服务器出错,请稍候再来提交'
        }
      };
    }

    return {
      code: 200,
      message: '提交成功'
    };
  } catch (e) {
    if (e.code === 'ER_DUP_ENTRY') {
      // 重复的情况
      return {
        error: {
          code: 404,
          message: '您已提交过支付宝信息,请不要重复提交!'
        }
      };
    } else {
      logger.error('mysql error =>', e);

      return {
        error: {
          code: 500,
          message: '服务器出错,请稍候再来提交'
        }
      };
    }
  }
}

module.exports = {
  create
};