var system = require("../../system")
const http = require("http")
const querystring = require('querystring');
var settings = require("../../../config/settings");
const CtlBase = require("../ctl.base");
const logCtl = system.getObject("web.oplogCtl");
class FooterinfoCtl extends CtlBase {
  constructor() {
    super(CtlBase.getServiceName(FooterinfoCtl));
  }
  async fetchCompanyInfo(pobj, obj, req) {
    var companyinfo = await this.service.findAll({ company_id: req.companyid });
    if (companyinfo && companyinfo.length > 0) {
      return system.getResult2(companyinfo[0]);
    }
    return { status: -100, msg: "暂无信息，请进行填写", bizmsg: "empty" };
  }
  async createOrUpdate(pobj, obj, req) {
    var companyinfo = await this.service.findAll({ company_id: req.companyid });
    console.log(companyinfo);
    if (companyinfo.length == 0) {
      var params = {
        companyName: obj.companyname,
        serviceTel: obj.servicetel,
        cooperationTel: obj.cooperationtel,
        address: obj.address,
        picUrl: obj.picUrl,
        loginUrl: obj.loginUrl,
        aboutUs: obj.aboutus,
        wxQrCodeUrl: obj.wxQrCodeUrl,
        company_id: req.companyid,
        icpNum: obj.icpNum,
        icpCard:obj.icpCard,
        establishmentYear:obj.establishmentYear,
      };
      var result = await this.service.create(params);
    } else {
      console.log("---------update---------------");
      var params = {
        id: companyinfo[0].id,
        companyName: obj.companyname,
        serviceTel: obj.servicetel,
        cooperationTel: obj.cooperationtel,
        address: obj.address,
        picUrl: obj.picUrl,
        loginUrl: obj.loginUrl,
        aboutUs: obj.aboutus,
        company_id: req.companyid,
        wxQrCodeUrl: obj.wxQrCodeUrl,
        icpNum: obj.icpNum,
        icpCard:obj.icpCard,
        establishmentYear:obj.establishmentYear
      };
      var result = await this.service.update(params);

    }
    return system.getResult2(result);
  }
}
module.exports = FooterinfoCtl;
