import request from './request';

export const code2Session = params => {
  return request({
    url: 'code2Session',
    data: params,
    method: 'get'
  }).then(res => res.data);
};

export const zyycLogin = params => {
  return request({
    url: `login`,
    data: params,
    method: 'post',
    header: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  }).then(res => res.data);
};

export const zyycLogout = params => {
  return request({
    url: `token/logout`,
    data: params,
    method: 'get'
  }).then(res => res.data);
};

export const checkLogin = () => {
  if (mpvue.getStorageSync('token')) {
    return request({
      url: `token/checkLogin`,
      method: 'get'
    }).then(res => res.data);
  } else {
    return new Promise(resolve => {
      resolve({
        status: '9001',
        message: '系统未登录'
      });
    });
  }
};

export const getUserPhone = () => {
  return request({
    url: `token/encryptPhone`,
    method: 'get'
  }).then(res => res.data);
};

export const getUserInfo = params => {
  return request({
    url: `token/userInfo`,
    data: {
      signature: params.signature,
      rawData: params.rawData,
      encryptedData: params.encryptedData,
      iv: params.iv
    },
    method: 'post',
    header: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  }).then(res => res.data);
};

export const getShareUser = params => {
  return request({
    url: `getWxUser`,
    method: 'post',
    data: params
  }).then(res => res.data);
};

export const grantCoupon = params => {
  return request({
    url: `token/customerCoupon/grantCoupon`,
    method: 'post',
    data: params
  }).then(res => res.data);
};
