Эх сурвалжийг харах

Merge branch 'banner_down' into debug

zwxi 10 сар өмнө
parent
commit
ab02c23737

+ 42 - 17
controller/public.go

@@ -15,6 +15,7 @@ import (
 	"hongze/hongze_yb/models/tables/company"
 	"hongze/hongze_yb/models/tables/wx_user"
 	"hongze/hongze_yb/models/tables/yb_config"
+	"hongze/hongze_yb/models/tables/yb_research_banner"
 	"hongze/hongze_yb/models/tables/yb_research_signup_statistics"
 	"hongze/hongze_yb/models/tables/yb_resource"
 	"hongze/hongze_yb/models/tables/yb_suncode_pars"
@@ -567,7 +568,7 @@ func BannerGetQRCode(c *gin.Context) {
 	companyName := companyInfo.CompanyName
 
 	companyNameCode := url.QueryEscape(companyName) // 进行URL编码
-	remarkCode := url.QueryEscape(remark) // 进行URL编码
+	remarkCode := url.QueryEscape(remark)           // 进行URL编码
 	url := "pages-report/signUpPage/signUpPage?RealName=%s&CompanyName=%s&Mobile=%s&BannerId=%d&Title=%s"
 	url = fmt.Sprintf(url, wxUserInfo.RealName, companyNameCode, wxUserInfo.Mobile, bannerId, remarkCode)
 
@@ -597,6 +598,7 @@ func BannerGetQRCode(c *gin.Context) {
 		response.FailData("文件上传失败", "文件上传失败,Err:"+err.Error(), c)
 		return
 	}
+
 	response.OkData("获取成功", resourceUrl, c)
 }
 
@@ -674,24 +676,47 @@ func BannerDowload(c *gin.Context) {
 		response.Fail("参数有误:"+err.Error(), c)
 		return
 	}
-
-	randStr := utils.GetRandStringNoSpecialChar(28)
-	jpegPath := `./static/` + randStr + ".jpeg"
-	err := services.ReportToJpeg(req.BannerUrl, jpegPath)
-
-	dateDir := time.Now().Format("20060102")
-	uploadDir := global.CONFIG.Serve.StaticDir + "hongze/" + dateDir
-	err = os.MkdirAll(uploadDir, 0766)
-	if err != nil {
-		response.FailData("存储目录创建失败", "存储目录创建失败,Err:"+err.Error(), c)
+	obj := yb_research_banner.YbResearchBanner{}
+	item, err := obj.Fetch(req.UserId, req.BannerId)
+	if err != nil && err != utils.ErrNoRow {
+		response.Fail(err.Error(), c)
 		return
 	}
+	resourceUrl := ""
 
-	//上传到阿里云
-	resourceUrl, err := services.UploadAliyun(randStr + ".jpeg", jpegPath)
-	if err != nil {
-		response.FailData("文件上传失败", "文件上传失败,Err:"+err.Error(), c)
-		return
+	if item == nil {
+		randStr := utils.GetRandStringNoSpecialChar(28)
+		jpegPath := `./static/` + randStr + ".jpeg"
+		err := services.ReportToJpeg(req.BannerUrl, jpegPath)
+
+		dateDir := time.Now().Format("20060102")
+		uploadDir := global.CONFIG.Serve.StaticDir + "hongze/" + dateDir
+		err = os.MkdirAll(uploadDir, 0766)
+		if err != nil {
+			response.FailData("存储目录创建失败", "存储目录创建失败,Err:"+err.Error(), c)
+			return
+		}
+
+		defer func() {
+			os.Remove(jpegPath)
+		}()
+
+		//上传到阿里云
+		resourceUrl, err := services.UploadAliyun(randStr+".jpeg", jpegPath)
+		if err != nil {
+			response.FailData("文件上传失败", "文件上传失败,Err:"+err.Error(), c)
+			return
+		}
+		obj.BannerID = req.BannerId
+		obj.UserID = req.UserId
+		obj.ImgURL = resourceUrl
+		err = obj.Create()
+		if err != nil {
+			response.FailData("创建banner长图记录失败", "创建banner长图记录失败,Err:"+err.Error(), c)
+			return
+		}
+	} else {
+		resourceUrl = item.ImgURL
 	}
 	response.OkData("获取成功", resourceUrl, c)
-}
+}

+ 13 - 0
models/tables/yb_research_banner/entity.go

@@ -0,0 +1,13 @@
+package yb_research_banner
+
+type YbResearchBanner struct {
+	YbResearchBannerID uint64    `gorm:"primaryKey;autoIncrement;comment:调研bannerid" json:"yb_research_banner_id"`
+	BannerID           int       `gorm:"comment:调研bannerid" json:"banner_id"`
+	UserID             int       `gorm:"comment:用户id" json:"user_id"`
+	ImgURL             string    `gorm:"comment:图片地址" json:"img_url"`
+}
+
+// TableName get sql table name.获取数据库表名
+func (m *YbResearchBanner) TableName() string {
+	return "yb_research_banner"
+}

+ 13 - 0
models/tables/yb_research_banner/model.go

@@ -0,0 +1,13 @@
+package yb_research_banner
+
+import "hongze/hongze_yb/global"
+
+func (item *YbResearchBanner) Create() (err error) {
+	err = global.DEFAULT_MYSQL.Create(item).Error
+	return
+}
+
+func (m *YbResearchBanner) Fetch(userId, bannerId int) (item *YbResearchBanner, err error) {
+	err = global.DEFAULT_MYSQL.Model(m).Where("user_id = ? and banner_id= ?", userId, bannerId).First(&item).Error
+	return
+}