function customSQL(sql, type) {
  let promise = new Promise((res, rej) => {
    wx.request({
      url: "https://server.fmode.cn/api/novaql/select",
      data: {
        sql: sql,
      },
      method: "POST",
      success(success) {
        res(success.data.data);
      },
      fail(err) {
        rej(err);
      },
    });
  });
  return promise;
}

function getPhone(code) {
  return new Promise((res) => {
    wx.request({
      url: 'https://server.fmode.cn/api/wxapp/decrypt_phone',
      data: {
        code: code,
        companyId: getApp().globalData.company
      },
      header: {
        'content-type': 'application/json'
      },
      method: 'GET',
      success: (result) => {
        if (result.data.code == 0 && result.data.data && result.data.data.phoneNumber) {
          console.log(result.data.data.phoneNumber)
          res(result.data.data.phoneNumber)
        } else {
          wx.showToast({
            title: '手机号获取失败',
            icon: 'error',
            image: '',
            duration: 1500,
            mask: false,
          });
          res()
        }
      },
      fail: () => {
        wx.showToast({
          title: '手机号获取失败',
          icon: 'error',
          image: '',
          duration: 1500,
          mask: false,
        });
        res()
      },
      complete: () => {
      }
    });
  })
}

module.exports = {
  customSQL,
  getPhone
};