unbind-qq.js 1021 字节
Newer Older
DCloud_JSON's avatar
DCloud_JSON 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
const {
  preUnBind,
  postUnBind
} = require('../../lib/utils/relate')
const {
  LOG_TYPE, dbCmd
} = require('../../common/constants')
const {
  getQQPlatform
} = require('../../lib/utils/qq')

/**
 * 解绑QQ
 * @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#unbind-qq
 * @returns
 */
module.exports = async function () {
  const { uid } = this.authInfo
19
  const { appId } = this.getUniversalClientInfo()
DCloud_JSON's avatar
DCloud_JSON 已提交
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
  const qqPlatform = getQQPlatform.call(this)

  await preUnBind.call(this, {
    uid,
    unBindAccount: {
      qq_openid: dbCmd.or([
        {
          [qqPlatform]: dbCmd.exists(true)
        },
        {
          [`${qqPlatform}_${appId}`]: dbCmd.exists(true)
        }
      ]),
      qq_unionid: dbCmd.exists(true)
    },
    logType: LOG_TYPE.UNBIND_QQ
  })

  return await postUnBind.call(this, {
    uid,
    unBindAccount: {
      qq_openid: dbCmd.remove(),
      qq_unionid: dbCmd.remove()
    },
    logType: LOG_TYPE.UNBIND_QQ
  })
}