瀏覽代碼

Merge branch 'cygx_12.1' of http://8.136.199.33:3000/hongze/hongze_cygx

xingzai 1 年之前
父節點
當前提交
fa5c98897d

+ 201 - 0
controllers/questionnaire.go

@@ -0,0 +1,201 @@
+package controllers
+
+import (
+	"encoding/json"
+	"hongze/hongze_cygx/models"
+	"hongze/hongze_cygx/utils"
+	"strconv"
+	"time"
+)
+
+// 问卷调查
+type QuestionnaireController struct {
+	BaseAuthController
+}
+
+// @Title 详情
+// @Description 详情接口
+// @Param   IsBestNew   query   bool  false       "是否获取最新的一条问卷消息"
+// @Param   QuestionnaireId   query   int  true       "问卷ID"
+// @Success Ret=200 {object} cygx.GetCygxTacticsTimeLineResp
+// @router /detail [get]
+func (this *QuestionnaireController) Detail() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	user := this.User
+	if user == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,用户信息为空"
+		br.Ret = 408
+		return
+	}
+	resp := new(models.GetCygxQuestionnaireDetailResp)
+	questionnaireId, _ := this.GetInt("QuestionnaireId")
+	isBestNew, _ := this.GetBool("IsBestNew", false)
+	var err error
+	detail := new(models.CygxQuestionnaireResp)
+	//如果是最新的就获取最新的一套问卷信息
+	if isBestNew {
+		detail, err = models.GetCygxQuestionnaireDetailBestNew()
+		if err != nil {
+			br.Msg = "详情不存在"
+			br.ErrMsg = "获取失败,GetCygxQuestionnaireDetailBestNew Err:" + err.Error()
+			return
+		}
+		questionnaireId = detail.QuestionnaireId
+	} else {
+		detail, err = models.GetCygxQuestionnaireDetail(questionnaireId)
+		if err != nil {
+			br.Msg = "详情不存在"
+			br.ErrMsg = "获取失败,GetCygxQuestionnaireDetail Err:" + err.Error()
+			return
+		}
+	}
+
+	ListTheme, err := models.GetCygxQuestionnaireThemeListByQuestionnaireId(questionnaireId)
+	if err != nil {
+		br.Msg = "详情不存在"
+		br.ErrMsg = "获取失败,GetCygxQuestionnaireThemeListByQuestionnaireId Err:" + err.Error()
+		return
+	}
+	detail.ListTheme = ListTheme
+	resp.Detail = detail
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}
+
+// @Title 问卷投票
+// @Description 问卷投票接口
+// @Param   QuestionnaireId   query   int  true       "问卷ID"
+// @Success Ret=200 {object} cygx.GetCygxTacticsTimeLineResp
+// @router /vote_add [post]
+func (this *QuestionnaireController) VoteAdd() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	user := this.User
+	if user == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,用户信息为空"
+		br.Ret = 408
+		return
+	}
+	uid := user.UserId
+	var req models.CygxQuestionnaireVoteReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	if uid == 0 {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,用户信息为空"
+		br.Ret = 408
+	}
+
+	questionnaireId := req.QuestionnaireId
+	questionnaireThemeIds := req.QuestionnaireThemeIds
+	content := req.Content
+	if len(questionnaireThemeIds) == 0 && content == "" {
+		br.Msg = "提交信息不能为空"
+		return
+	}
+
+	detail, err := models.GetCygxQuestionnaireDetail(questionnaireId)
+	if err != nil {
+		br.Msg = "提交失败"
+		br.ErrMsg = "获取失败,GetCygxQuestionnaireDetail Err:" + err.Error()
+		return
+	}
+
+	endTime := utils.StrTimeToTime(detail.EndTime + " 23:59:59") //时间字符串格式转时间格式
+	if endTime.Before(time.Now()) {
+		br.Msg = "此次投票已截止"
+		return
+	}
+
+	lenCheck := len(questionnaireThemeIds)
+	if lenCheck > detail.MaxChooseTotal {
+		br.Msg = "最多可选择" + strconv.Itoa(detail.MaxChooseTotal) + "项"
+		return
+	}
+
+	sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		return
+	}
+
+	var voteItems []*models.CygxQuestionnaireVote
+	//主题ID提交问卷需要写入的信息
+	if lenCheck > 0 {
+		var condition string
+		var pars []interface{}
+		condition += " AND  user_id = ?  AND questionnaire_id = ? "
+		pars = append(pars, user.UserId, questionnaireId)
+
+		totalhistory, err := models.GetCygxQuestionnaireVoteCount(condition, pars)
+		if err != nil {
+			br.Msg = "提交失败"
+			br.ErrMsg = "获取失败,GetCygxQuestionnaireDetail Err:" + err.Error()
+			return
+		}
+		if totalhistory > 0 {
+			br.Msg = "您已投过票"
+			return
+		}
+		for _, v := range questionnaireThemeIds {
+			item := new(models.CygxQuestionnaireVote)
+			item.QuestionnaireId = questionnaireId
+			item.QuestionnaireThemeId = v
+			item.UserId = user.UserId
+			item.CreateTime = time.Now()
+			item.ModifyTime = time.Now()
+			item.Mobile = user.Mobile
+			item.Email = user.Email
+			item.CompanyId = user.CompanyId
+			item.CompanyName = user.CompanyName
+			item.RealName = user.RealName
+			if sellerItem != nil {
+				item.SellerName = sellerItem.RealName
+			}
+			item.RegisterPlatform = utils.REGISTER_PLATFORM
+			voteItems = append(voteItems, item)
+		}
+	}
+
+	//其它主题类型提交需要写入的信息
+	itemOther := new(models.CygxQuestionnaireVoteOtherTheme)
+	if content != "" {
+		itemOther.QuestionnaireId = questionnaireId
+		itemOther.UserId = user.UserId
+		itemOther.CreateTime = time.Now()
+		itemOther.ModifyTime = time.Now()
+		itemOther.Mobile = user.Mobile
+		itemOther.Email = user.Email
+		itemOther.CompanyId = user.CompanyId
+		itemOther.CompanyName = user.CompanyName
+		itemOther.RealName = user.RealName
+		itemOther.Content = content
+		if sellerItem != nil {
+			itemOther.SellerName = sellerItem.RealName
+		}
+		itemOther.RegisterPlatform = utils.REGISTER_PLATFORM
+	}
+	err = models.AddCygxQuestionnaireVote(voteItems, itemOther)
+	if err != nil {
+		br.Msg = "提交失败"
+		br.ErrMsg = "获取失败,AddCygxQuestionnaireVote Err:" + err.Error()
+		return
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "提交成功"
+}

+ 4 - 0
controllers/report.go

@@ -1406,7 +1406,11 @@ func (this *ReportController) IsShow() {
 	//resp.YanXuan_Explain = true
 	resp.IsShowFreeButton = IsShowFreeButton
 	resp.IsBelongRai = services.GetBelongingRai(user.Mobile)
+	resp.IsShowQuestionnaire = services.GetQuestionnaireButtonIsShow() // 获取研选问卷调查按钮是否展示
 	resp.IsShowResearchPoints = true
+	if utils.RunMode == "release" { //是否展示关于我们的视频,测试环境审核做隐藏
+		resp.IsShowAboutVideo = true
+	}
 	//mobile := user.Mobile
 	//if mobile == "" {
 	//	br.Ret = 200

+ 2 - 0
models/db.go

@@ -177,6 +177,8 @@ func init() {
 		new(CygxYanxuanSpecial),
 		new(CygxYanxuanSpecialFollow),
 		new(CygxYanxuanSpecialCompany),
+		new(CygxQuestionnaireVote),
+		new(CygxQuestionnaireVoteOtherTheme),
 	)
 	// 记录ORM查询日志
 	orm.Debug = true

+ 70 - 0
models/questionnaire.go

@@ -0,0 +1,70 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"github.com/rdlucklib/rdluck_tools/paging"
+	"hongze/hongze_cygx/utils"
+	"time"
+)
+
+type AddCygxQuestionnaireThemeReq struct {
+	QuestionnaireThemeId int    `description:"ID"`
+	ActivityTheme        string `description:"活动主题"`
+	DisabledRadio        bool   `description:"是否选择,配合前端添加的字段"`
+}
+
+type CygxQuestionnaireResp struct {
+	QuestionnaireId  int    `description:"ID"`
+	ActivityTypeId   int    `description:"活动类型id"`
+	ActivityTypeName string `description:"活动类型名称"`
+	Content          string `description:"内容"`
+	EndTime          string `description:"截止日期"`
+	PublishTime      string `description:"发布时间"`
+	MaxChooseTotal   int    `description:"最多可选几项"`
+	State            string `description:"状态"`
+	ListTheme        []*AddCygxQuestionnaireThemeReq
+}
+
+type GetCygxQuestionnaireResp struct {
+	Paging *paging.PagingItem `description:"分页数据"`
+	List   []*CygxQuestionnaireResp
+}
+
+type GetCygxQuestionnaireDetailResp struct {
+	Detail *CygxQuestionnaireResp
+}
+
+// 通过ID获取详情
+func GetCygxQuestionnaireDetail(questionnaireId int) (item *CygxQuestionnaireResp, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_questionnaire  WHERE questionnaire_id=? `
+	err = o.Raw(sql, questionnaireId).QueryRow(&item)
+	return
+}
+
+// 获取数量
+func GetCygxQuestionnaireCount(condition string, pars []interface{}) (count int, err error) {
+	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_questionnaire as art WHERE 1= 1  `
+	if condition != "" {
+		sqlCount += condition
+	}
+	o := orm.NewOrm()
+	err = o.Raw(sqlCount, pars).QueryRow(&count)
+	return
+}
+
+// 通过ID获取详情
+func GetCygxQuestionnaireDetailBestNew() (item *CygxQuestionnaireResp, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_questionnaire WHERE end_time >= ? ORDER BY publish_time DESC LIMIT 1     `
+	err = o.Raw(sql, time.Now().Format(utils.FormatDate)).QueryRow(&item)
+	return
+}
+
+// 列表
+func GetCygxQuestionnaireThemeListByQuestionnaireId(questionnaireId int) (items []*AddCygxQuestionnaireThemeReq, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_questionnaire_theme as art WHERE questionnaire_id = ? `
+	_, err = o.Raw(sql, questionnaireId).QueryRows(&items)
+	return
+}

+ 91 - 0
models/questionnaire_vote.go

@@ -0,0 +1,91 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxQuestionnaireVote struct {
+	QuestionnaireVoteId  int `orm:"column(questionnaire_vote_id);pk"`
+	QuestionnaireId      int `description:"问卷ID"`
+	QuestionnaireThemeId int `description:"问卷主题ID"`
+	UserId               int `description:"用户ID"`
+	CreateTime           time.Time
+	Mobile               string    `description:"手机号"`
+	Email                string    `description:"邮箱"`
+	CompanyId            int       `description:"公司id"`
+	CompanyName          string    `description:"公司名称"`
+	ModifyTime           time.Time `description:"修改时间"`
+	RealName             string    `description:"用户实际名称"`
+	SellerName           string    `description:"所属销售"`
+	RegisterPlatform     int       `description:"来源 1小程序,2:网页"`
+}
+
+type CygxQuestionnaireVoteOtherTheme struct {
+	QuestionnaireVoteOtherThemeId int `orm:"column(questionnaire_vote_other_theme_id);pk"`
+	QuestionnaireId               int `description:"问卷ID"`
+	UserId                        int `description:"用户ID"`
+	CreateTime                    time.Time
+	Mobile                        string    `description:"手机号"`
+	Email                         string    `description:"邮箱"`
+	CompanyId                     int       `description:"公司id"`
+	CompanyName                   string    `description:"公司名称"`
+	ModifyTime                    time.Time `description:"修改时间"`
+	RealName                      string    `description:"用户实际名称"`
+	SellerName                    string    `description:"所属销售"`
+	Content                       string    `description:"内容"`
+	RegisterPlatform              int       `description:"来源 1小程序,2:网页"`
+}
+
+// 获取数量
+func GetCygxQuestionnaireVoteCount(condition string, pars []interface{}) (count int, err error) {
+	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_questionnaire_vote as art WHERE 1= 1  `
+	if condition != "" {
+		sqlCount += condition
+	}
+	o := orm.NewOrm()
+	err = o.Raw(sqlCount, pars).QueryRow(&count)
+	return
+}
+
+type CygxQuestionnaireVoteReq struct {
+	QuestionnaireId       int    `description:"问卷ID"`
+	QuestionnaireThemeIds []int  `description:"问卷主题ID"`
+	Content               string `description:"内容"`
+}
+
+// 添加
+func AddCygxQuestionnaireVote(voteItems []*CygxQuestionnaireVote, otherItem *CygxQuestionnaireVoteOtherTheme) (err error) {
+	o := orm.NewOrm()
+	to, err := o.Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		if err != nil {
+			_ = to.Rollback()
+		} else {
+			_ = to.Commit()
+		}
+	}()
+
+	//其它主题类型提交需要写入的信息
+	if otherItem.Content != "" {
+		_, err = to.Insert(otherItem)
+		if err != nil {
+			return
+		}
+
+		//更新其他主题投票数量
+		sql := ` UPDATE cygx_questionnaire SET other_theme_total =  other_theme_total +1 WHERE questionnaire_id = ?  `
+		_, err = o.Raw(sql, otherItem.QuestionnaireId).Exec()
+	}
+	//主题ID提交问卷需要写入的信息
+	for _, v := range voteItems {
+		_, err = to.Insert(v)
+		if err != nil {
+			return
+		}
+	}
+	return
+}

+ 2 - 0
models/report.go

@@ -382,6 +382,8 @@ type IsShow struct {
 	SearchTxtList          SearchTxt `description:"搜索栏回显内容说明"`
 	IsBelongRai            bool      `description:"是否属于权益内部人员"`
 	IsShowResearchPoints   bool      `description:"是否展示研选扣点搜索"`
+	IsShowQuestionnaire    bool      `description:"是否展示研选问卷调查"`
+	IsShowAboutVideo       bool      `description:"是否展示关于我们的视频"`
 }
 
 type SearchTxt struct {

+ 18 - 0
routers/commentsRouter.go

@@ -907,6 +907,24 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:QuestionnaireController"] = append(beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:QuestionnaireController"],
+        beego.ControllerComments{
+            Method: "Detail",
+            Router: `/detail`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:QuestionnaireController"] = append(beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:QuestionnaireController"],
+        beego.ControllerComments{
+            Method: "VoteAdd",
+            Router: `/vote_add`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:ReportBillboardController"] = append(beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:ReportBillboardController"],
         beego.ControllerComments{
             Method: "FllowList",

+ 5 - 0
routers/router.go

@@ -175,6 +175,11 @@ func init() {
 				&controllers.CollectionController{},
 			),
 		),
+		web.NSNamespace("/questionnaire",
+			web.NSInclude(
+				&controllers.QuestionnaireController{},
+			),
+		),
 	)
 	web.AddNamespace(ns)
 }

+ 37 - 0
services/questionnaire.go

@@ -0,0 +1,37 @@
+package services
+
+import (
+	"errors"
+	"fmt"
+	"hongze/hongze_cygx/models"
+	"hongze/hongze_cygx/utils"
+	"time"
+)
+
+//func init() {
+//	fmt.Println(GetQuestionnaireButtonIsShow())
+//}
+
+// 获取研选问卷调查按钮是否展示
+func GetQuestionnaireButtonIsShow() (isShow bool) {
+	var err error
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			go utils.SendAlarmMsg("约访专家的请求失败"+err.Error(), 2)
+		}
+	}()
+	var condition string
+	var pars []interface{}
+	condition += ` AND end_time >= ? `
+	pars = append(pars, time.Now().Format(utils.FormatDate))
+	total, e := models.GetCygxQuestionnaireCount(condition, pars)
+	if e != nil {
+		err = errors.New("GetCygxQuestionnaireCount, Err: " + e.Error())
+		return
+	}
+	if total > 0 {
+		isShow = true
+	}
+	return
+}