var path = require('path');
var AlipaySdk = require('alipay-sdk').default;
var WXPay = require('wx-pay');
const tenpay = require('tenpay');
var ENVINPUT = {
  DB_HOST: process.env.DB_HOST,
  DB_PORT: process.env.DB_PORT,
  DB_USER: process.env.DB_USER,
  DB_PWD: process.env.DB_PWD,
  REDIS_HOST: process.env.REDIS_HOST,
  REDIS_PORT: process.env.REDIS_PORT,
  REDIS_PWD: process.env.REDIS_PWD,
  DB_NAME: process.env.CENTER_CHANNEL_DB_NAME,
  REDIS_DB: process.env.CENTER_CHANNEL_REDIS_DB,
  APP_ENV: process.env.APP_ENV ? process.env.APP_ENV : "dev"
};
var settings = {
  env: ENVINPUT.APP_ENV,
  appKey: "201911061250",
  secret: "f99d413b767f09b5dff0b3610366cc46",
  salt: "%iatpD1gcxz7iF#B",
  cacheprefix: "ucommune-back",
  usertimeout: 3600,//单位秒
  basepath: path.normalize(path.join(__dirname, '../..')),
  port: process.env.NODE_PORT || 4015,  
  entProfileUrl: function () {
    if (this.env == "dev") {
      return "https://entprofile.gongsibao.com/";
    } else {
      return "https://entprofile.gongsibao.com/";
    }
  },
  aliossjavaUrl: function () {
    if (this.env == "dev") {
      return "http://192.168.2.109:8080/uploadfile";
    } else {
      return "http://aliossjava-service/uploadfile";
    }
  },
  qifuPayAfterH5JumpUrl: function () {
    if (this.env == "dev") {
      return "http://tm.qifu.gongsibao.com:4012/#/home/indent_list";
    } else {
      return "http://tm.qifu.gongsibao.com/#/home/indent_list";
    }
  },
  qifuPayAfterPcJumpUrl: function () {
    if (this.env == "dev") {
      return "http://tm.qifu.gongsibao.com:4012/#/home/indent_list";
    } else {
      return "http://tm.qifu.gongsibao.com/#/home/indent_list";
    }
  },  
  qifuH5PayNotifyUrl: function () {
    if (this.env == "dev") {
      return "http://gsb.qifu.gongsibao.com:4012/tlpay/notify";
    } else {
      return "http://gsb.qifu.gongsibao.com/tlpay/notify";
    }
  },  
  paasUrl: function () {
    if (this.env == "dev") {
      return "http://p.apps.com:4001/";
    } else {
      return "https://open.gongsibao.com/";
    }
  },
  centerAppUrl: function () {
    if (this.env == "dev") {
      return "http://centerapp.apps.com:4010/";
    } else {
      return "http://center-app-service.chaolai/";
    }
  },
  centerChannelUrl: function () {
      if (this.env == "dev") {
          return "http://60.205.209.94:4012/"
      } else {
        //   return "channel的正式环境" 6.30修改目前只用作生成alipay/wx的通知回调地址
          return "http://youke.qifu.gongsibao.com/"
      }
  },
  gatewayUrl: function () {
    if (this.env == "dev") {
      return "http://192.168.0.106:4005/";
    } else {
      return "https://channelgateway-api.gongsibao.com/";
    }
  },
  centerOrderUrl: function () {
    if (this.env == "dev") {
      return "http://centerorder.apps.com:4011/";
    } else {
      return "http://center-order-service.chaolai/";
    }
  },
  igirlWeburl: function(){
    if (this.env == "dev") {
      return "http://127.0.0.1:3000/";
    } else {
      return "http://igirl-service/";
    }
  },
  centerCacheUrl:function(){
    if(this.env=='dev'){
      return "http://123.57.217.203:30005/";
    }else{
      return "http://specialprofile-service/"
    }
  },
  reqTransferurl: function () {
    if (this.env == "dev") {
      return "http://192.168.18.61:3003/";
    } else {
      return "http://jiaxiya-service/";
    }
  },
  reqEsAddr: function () {
    if (this.env == "dev") {
      var localsettings = require("./localsettings");
      return "http://43.247.184.94:7200/";//localsettings.reqEsDevUrl;
    } else {
      return "http://43.247.184.94:7200/";
    }
  },
  reqZcApi: function () {
    if (this.env == "dev") {
      return "http://zcapi.apps.com:4002/";//localsettings.reqEsDevUrl;
    } else {
      return "http://zcapi-service/";//k8s服务名称
    }
  },
  pushFqbossDataUrl: function () {
    if (this.env == "dev") {
      return "http://192.168.18.141:3000/";//localsettings.reqEsDevUrl;
    } else {
      return "https://fqgirl.gongsibao.com/";
    }
  },
  ucommuneUrl: function () {
    if (this.env == "dev") {
      return "https://m-dev.ucommune.com/"// 优客测试环境
    } else {
    //   return "https://m.ucommune.com/"// 优客正式环境
      return "https://m.ucommune.com/"// 6.29lin修改为测试环境。原因优客 目前还没有正式环境
    }
  },
  apiconfig: {
    opLogUrl: function () {
      return settings.reqEsAddr() + "center_channel_log/_doc?pretty";
    },
    opLogEsIsAdd: function () {
      return 1;
    },
  },

  homePage: function () {
    if (this.env == "dev") {
      var localsettings = require("./localsettings");
      return localsettings.reqHomePageDevUrl;
    } else {
      return "http://boss.gongsibao.com/";
    }
  },
  redis: function () {
    if (this.env == "dev") {
      var localsettings = require("./localsettings");
      return localsettings.redis;
    } else {
      return {
        host: ENVINPUT.REDIS_HOST,
        port: ENVINPUT.REDIS_PORT,
        password: ENVINPUT.REDIS_PWD,
        db: ENVINPUT.REDIS_DB,
      };
    }
  },
  database: function () {
    if (this.env == "dev") {
      var localsettings = require("./localsettings");
      return localsettings.database;
    } else {
      return {
        dbname: ENVINPUT.DB_NAME,
        user: ENVINPUT.DB_USER,
        password: ENVINPUT.DB_PWD,
        config: {
          host: ENVINPUT.DB_HOST,
          dialect: 'mysql',
          operatorsAliases: false,
          pool: {
            max: 5,
            min: 0,
            acquire: 90000000,
            idle: 1000000
          },
          debug: false,
          dialectOptions: {
            requestTimeout: 999999,
            // instanceName:'DEV'
          }  //设置MSSQL超时时间
        },
      };
    }
  },
  alipay: function() {// 没有在使用 确定不需要后会去掉
    return new AlipaySdk({

        // appId: payConfig.ali.appId,
        
        // privateKey: payConfig.ali.privateKey,
        
        // alipayPublicKey: payConfig.ali.publicKey,
        
    });
  },
  wxpay: function() {// 没有在使用 确定不需要后会去掉
      return WXPay({
        appid: 'wx6f3ebe44defe336a',
        mch_id: '1232813602',
        partner_key: 'sinotone2014sinotone2014sinotone', //微信商户平台API密钥
        //pfx: fs.readFileSync('./wxpay_cert.p12'), //微信商户平台证书
        //pfx: "sinotone2014sinotone2014sinotone"
      })
    // const config = {
    //     appid: 'wx6f3ebe44defe336a',
    //     mchid: '1232813602',
    //     partnerKey: 'sinotone2014sinotone2014sinotone',
    //   };
    //   return new tenpay(config);
  },
  paySecret: function() {
    if (this.env == "dev") {
    // return "ab53dfb909e4c32a";
      return "34cdecaac35b1d8d"// 7.1之前测试环境的secret无法使用，测试/正式全部使用同一个secret
    } else {
      return "34cdecaac35b1d8d";// 6.29lin新增 小黑给的secret
    }
  },
  ucommuneOperatorPhone: function() {
    if (this.env == "dev") {
      return "13911391996"// 7.7修改测试环境优客 辅助/担保订单推送业务员手机号
    } else {
      return "15754717260";// 7.7修改正式环境优客 辅助/担保订单推送业务员手机号 刘文悦
    }
  }
};
module.exports = settings;
