// 保存图片广告 func (this *adService) SaveImageAd(adUserId int, v *ad.Image) (int, error) { pa := this.getUserAd(adUserId) var adv ad.IAd = pa.GetById(v.AdId) if adv.Type() == ad.TypeImage { g := adv.(ad.IImageAd) g.SetData(v) return adv.Save() } return -1, nil }
// 保存广告,更新时不允许修改类型 func (this *adService) SaveAd(adUserId int, v *ad.Ad) (int, error) { pa := this.getUserAd(adUserId) var adv ad.IAd if v.Id > 0 { adv = pa.GetById(v.Id) err := adv.SetValue(v) if err != nil { return -1, err } } else { adv = pa.CreateAd(v) } return adv.Save() }
// 保存广告图片 func (this *adService) SaveImage(adUserId int, advertisementId int, v *ad.Image) (int, error) { pa := this.getUserAd(adUserId) var adv ad.IAd = pa.GetById(advertisementId) if adv != nil { switch adv.Type() { case ad.TypeGallery: gad := adv.(ad.IGalleryAd) return gad.SaveImage(v) case ad.TypeImage: gad := adv.(ad.IImageAd) gad.SetData(v) return adv.Save() } } return -1, ad.ErrNoSuchAd }