// 保存线上商店 func (this *shopService) SaveOnlineShop(s *shop.Shop, v *shop.OnlineShop) error { mch, err := this._mchRep.GetMerchant(s.MerchantId) if err == nil { mgr := mch.ShopManager() var sp shop.IShop if s.Id > 0 { // 保存商店 sp = mgr.GetShop(s.Id) err = sp.SetValue(s) if err != nil { return err } } else { //检测店名是否重复 if err = this.checkShopName(mgr, s.Id, s.Name); err != nil { return err } // 创建商店 sp = mgr.CreateShop(s) } ofs := sp.(shop.IOnlineShop) err = ofs.SetShopValue(v) if err == nil { _, err = sp.Save() } } return err }
func (this *shopService) SaveShop(mchId int, v *shop.Shop) (int, error) { mch, err := this._mchRep.GetMerchant(mchId) if err != nil { log.Println("[ Merchant][ Service]-", err.Error()) return 0, err } var shop shop.IShop if v.Id > 0 { shop = mch.ShopManager().GetShop(v.Id) if shop == nil { return 0, errors.New("门店不存在") } } else { shop = mch.ShopManager().CreateShop(v) } err = shop.SetValue(v) if err != nil { return v.Id, err } return shop.Save() }