Ejemplo n.º 1
0
// 创建商户
func (this *MerchantImpl) createMerchant() (int, error) {
	if id := this.GetAggregateRootId(); id > 0 {
		return id, nil
	}

	id, err := this._rep.SaveMerchant(this._value)
	if err != nil {
		return id, err
	}

	//todo:事务

	// 初始化商户信息
	this._value.Id = id

	// 检测自营并保存
	if this.checkSelfSales() {
		this._rep.SaveMerchant(this._value)
	}

	//todo:  初始化商店

	// SiteConf
	//this._siteConf = &shop.ShopSiteConf{
	//	IndexTitle: "线上商店-" + v.Name,
	//	SubTitle:   "线上商店-" + v.Name,
	//	Logo:       v.Logo,
	//	State:      1,
	//	StateHtml:  "",
	//}
	//err = this._rep.SaveSiteConf(id, this._siteConf)
	//this._siteConf.MerchantId = id

	// SaleConf
	//this._saleConf = &merchant.SaleConf{
	//	AutoSetupOrder:  1,
	//	IntegralBackNum: 0,
	//}
	//err = this._rep.SaveSaleConf(id, this._saleConf)
	//this._saleConf.MerchantId = id

	// 创建API
	api := &merchant.ApiInfo{
		ApiId:     domain.NewApiId(id),
		ApiSecret: domain.NewSecret(id),
		WhiteList: "*",
		Enabled:   1,
	}
	err = this.ApiManager().SaveApiInfo(api)
	return id, err
}
Ejemplo n.º 2
0
// 获取API信息
func (this *apiManagerImpl) getApiInfo() *merchant.ApiInfo {
	if this._apiInfo == nil {
		this._apiInfo = this._rep.GetApiInfo(this.GetAggregateRootId())
		//没有API则生成
		if this._apiInfo == nil {
			mchId := this.GetAggregateRootId()
			this._apiInfo = &merchant.ApiInfo{
				MerchantId: mchId,
				ApiId:      domain.NewApiId(mchId),
				ApiSecret:  domain.NewSecret(mchId),
				WhiteList:  "*",
				Enabled:    0,
			}
			this.SaveApiInfo(this._apiInfo)
		}
	}
	return this._apiInfo
}