const system=require("../system");
const settings=require("../../config/settings.js");
const reclient=system.getObject("util.redisClient");
//获取平台配置兑换率
//初次登录的赠送数量
//创建一笔交易
//同时增加账户数量,增加系统平台账户
var dbf=system.getObject("db.connection");
var db=dbf.getCon();
db.sync({force:true}).then(async ()=>{
  console.log("sync complete...");
  //创建平台配置
  const PConfig=db.models.pconfig;
  var pconfigObjs=await PConfig.bulkCreate([
    {configType:"price",configValue:"100"},
    {configType:"initGift",configValue:"10000"},
    {configType:"platformProfitRatio",configValue:"0"},
    {configType:"apiInitGift",configValue:"500"},
    {configType:"apiCallPrice",configValue:"10"},
    {configType:"referrerProfitRatio",configValue:"10"},
    {configType:"platformUseProfit",configValue:"100"},
    {configType:"wtsName",configValue:"张飞龙"},
    {configType:"wtsMobile",configValue:"010-84927588"},
    {configType:"wtsZipcode",configValue:"100000"},
    {configType:"withdrawalData",configValue:"-1"},//提现申请限制日期范围20-31，-1不限制
    {configType:"withdrawalLimit",configValue:"-1"},//提现限制额度，-1不限制，0则不发放提现申请，大于0则为限制的额度
    {configType:"withdrawalIssueLimit",configValue:"-1"},//提现申请发放限制，-1不限制，0则不发放提现申请，大于0则为限制的额度
    {configType:"logOpWrite",configValue:"-1"},//操作日志步骤是否写入，0否，1是
    {configType:"invoiceTaxRate",configValue:"7"},//发票税率 0~100
    {configType:"bussinessAllotChannelConfig",configValue:"wssyh5"},//商机分配渠道配置，格式：wssyh5,yzc等
  ]);
  //创建平台账户
  const PAccount=db.models.paccount;
  const pa=await PAccount.create({});

  //创建APP
  const App=db.models.app;
  var hp=settings.homePage();
  App.create({appid:"wx76a324c5d201d1a4",name:"工具箱",homePage:hp,authPage:hp,secret:"f99d413b767f09b5dff0b3610366cc46",logoUrl:""}).then(app=>{
    //初始化产品
    const Product=db.models.product;
    Product.bulkCreate([
        {name:"公司商机汇总","code":"xzall",price:10,app_id:app.id,productCata:"ip",funcCata:"clueDig",style:"tool-summary",deleted_at:"2018-11-08 18:44:55"},//已经删除
        {name:"续展查询","code":"xzquery",price:10,app_id:app.id,productCata:"ip",funcCata:"clueDig",style:"tool-query"},
        {name:"续展过期查询","code":"xzgqquery",price:10,app_id:app.id,productCata:"ip",funcCata:"clueDig",style:"tool-query"},
        {name:"异议查询","code":"yyquery",price:10,app_id:app.id,productCata:"ip",funcCata:"clueDig",style:"tool-query"},
        {name:"不予受理查询","code":"byslquery",price:10,app_id:app.id,productCata:"ip",funcCata:"clueDig",style:"tool-query"},
        {name:"营业执照识别","code":"yyzz",price:10,app_id:app.id,productCata:"common",funcCata:"common",style:"tool-scanning"},
        {name:"图片转文字",price:100,"code":"imgtoword",app_id:app.id,productCata:"common",funcCata:"common",style:"tool-bg_icon_Transformation"},
        {name:"身份证识别",price:100,"code":"sfz",app_id:app.id,productCata:"common",funcCata:"common",style:"tool-scanning1"},
        {name:"商标查询",price:100,"code":"trademarkquery",app_id:app.id,productCata:"ip",funcCata:"query",style:"tool-search"},
        {name:"PDF转WORD",price:50,"code":"pdf2word",app_id:app.id,productCata:"common",funcCata:"common",style:"tool-bg_icon_Transformation"},
        {name:"商标图像检索",price:100,"code":"imagequery",app_id:app.id,productCata:"ip",funcCata:"query",style:"tool-search",deleted_at:"2018-11-09 14:59:26"},//已经删除
        // {name:"资料完善",price:0,"code":"finishpersoninfo",app_id:app.id,productCata:"ip",funcCata:"prof",style:"tool-eglass-data"},
        {name:"商标建档",price:0,"code":"calculateprice",app_id:app.id,productCata:"ip",funcCata:"prof",style:"tool-paper-report"},
        {name:"下单提报",price:10000,"code":"order",app_id:app.id,productCata:"ip",funcCata:"prof",style:"tool-order"},
        {name:"进度查询",price:0,"code":"trademark",app_id:app.id,productCata:"ip",funcCata:"prof",style:"tool-trademark-1"},
        {name:"发票申请",price:0,"code":"invoice",app_id:app.id,productCata:"ip",funcCata:"prof",style:"tool-invoice"},
        {name:"钱包提现",price:0,"code":"profitcenter",app_id:app.id,productCata:"ip",funcCata:"prof",style:"tool-cash"},
        {name:"商标建议函",price:0,"code":"advicelettercase",app_id:app.id,productCata:"ip",funcCata:"prof",style:"tool-paper-report"},
        {name:"版权建档",price:0,"code":"copyrightarch",app_id:app.id,productCata:"ic",funcCata:"cp",style:"tool-paper-report"},
        {name:"软件著作权提报",price:0,"code":"softwarecrsubmit",app_id:app.id,productCata:"ic",funcCata:"cp",style:"tool-paper-report"},
        {name:"作品著作权提报",price:0,"code":"workcrsubmit",app_id:app.id,productCata:"ic",funcCata:"cp",style:"tool-paper-report"},
        {name:"版权订单",price:0,"code":"copyrightorder",app_id:app.id,productCata:"ic",funcCata:"cp",style:"tool-paper-report"},
        {name:"图像检索",price:100,"code":"imagequeryengine",app_id:app.id,productCata:"ip",funcCata:"query",style:"tool-search"},
        {name:"LBS","code":"lbs",price:10,app_id:app.id,productCata:"ip",funcCata:"clueDig",style:"tool-summary"},
        {name:"专利建档",price:0,"code":"patentarch",app_id:app.id,productCata:"pa",funcCata:"pat",style:"tool-paper-report"},
        {name:"专利订单",price:0,"code":"patentorder",app_id:app.id,productCata:"pa",funcCata:"pat",style:"tool-paper-report"},
        {name:"专利检索",price:100,"code":"patentquery",app_id:app.id,productCata:"pa",funcCata:"query",style:"tool-search"},//发布时要加上
        {name:"CYLBS","code":"cylbs",price:10,app_id:app.id,productCata:"ip",funcCata:"clueDig",style:"tool-summary"},
      // {name:"学历证识别",price:100,app_id:app.id},
      // {name:"WORD转PDF",price:50,app_id:app.id},
      // {name:"PDF转WORD",price:50,app_id:app.id},
      // {name:"商标建议函生成",price:100,app_id:app.id},
    ]);
    //创建role
    const Role=db.models.role;
    Role.bulkCreate([
      {  name:"个体合伙人",code:"person",app_id:app.id},
      {  name:"企业合伙人",code:"ent",app_id:app.id},
      {  name:"财务",code:"fi",app_id:app.id},
      {  name:"商务运营",code:"bizop",app_id:app.id},
      {  name:"访客",code:"guest",app_id:app.id},
    ]);
  });
  App.create({appid:"ccb00829347e4048833af213e502c8c5",name:"创业家"});
  App.create({appid:"a95ad36efc064343aff200d18be6637d",name:"蜂擎云服"});
  App.create({appid:"fff5dafd1f6044c4ba2065e9dbad125d",name:"慧聪网"});
  App.create({appid:"9d9bcbb6a82f44dbbdb185afe28032bc",name:"研发中心"});
  App.create({appid:"95f167212a8146daac99feddffa6a995",name:"天津商标提报"});
  App.create({appid:"wx4c91e81bbb6039cd",name:"我想我要","secret":"12048e66dba64f2581e02b306680b232",homePage:"https://boss.gongsibao.com/mobile",authPage:hp});
  App.create({appid:"wx57678a30a6b5babc",name:"微信小程序","secret":"ac845d30d8973cc5e8e5b061b50f3263"});
  App.create({appid:"wxda6eab8429128ccd",name:"微信小程序","secret":"9a03f3ca37e97c92de9275265e4a3595"});
  App.create({appid:"wx9a01a96463f3f356",name:"微信小程序微商城","secret":"104ba29efa9aad971a7c5751b42cd67c"});
  App.create({appid:"wxdc08c441c9fdb7a7",name:"智信云","secret":"379e582e28645585a7def9c1c88de550",homePage:"http://192.168.4.1:3000/h5",authPage:hp});
  App.create({appid:"wx6cf486f309407dd7",name:"魔方实验室","secret":"2149b29f84bb38bca24e1388192bf204",homePage:"https://magic.gongsibao.com/m#/magicsearch",authPage:hp});
  const servicesitem=db.models.servicesitem;
  servicesitem.create({code:"sbzc",name:"商标注册"});
  //创建role
  // if(settings.env=="prod"){
  //   reclient.flushall(()=>{
  //     console.log("clear caches ok.....");
  //   });
  // }
  reclient.flushall(()=>{
    console.log("clear caches ok.....");
  });
});
