|
@@ -4,19 +4,24 @@ import (
|
|
|
"encoding/json"
|
|
|
"eta/eta_mini_api/models"
|
|
|
"eta/eta_mini_api/models/request"
|
|
|
+ "eta/eta_mini_api/models/response"
|
|
|
+ "eta/eta_mini_api/utils"
|
|
|
+ "time"
|
|
|
+
|
|
|
+ "github.com/rdlucklib/rdluck_tools/paging"
|
|
|
)
|
|
|
|
|
|
type MyChartController struct {
|
|
|
BaseAuthController
|
|
|
}
|
|
|
|
|
|
-// @Title List
|
|
|
-// @Description create users
|
|
|
+// @Title 收藏图表
|
|
|
+// @Description 收藏图表
|
|
|
// @Param PageSize query int true "每页数据条数"
|
|
|
// @Param CurrentIndex query int true "当前页页码,从1开始"
|
|
|
// @Success 200 {object} models.BaseResponse
|
|
|
// @Failure 403 {object} models.BaseResponse
|
|
|
-// @router /collect [get]
|
|
|
+// @router /collect [post]
|
|
|
func (this *MyChartController) Collect() {
|
|
|
br := new(models.BaseResponse).Init()
|
|
|
defer func() {
|
|
@@ -27,7 +32,63 @@ func (this *MyChartController) Collect() {
|
|
|
var req request.MyChartCollectReq
|
|
|
if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
|
|
|
br.Msg = "参数解析失败"
|
|
|
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
|
|
|
+ br.ErrMsg = "参数解析失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ user := this.User
|
|
|
+ if user.Status != 2 {
|
|
|
+ br.Msg = "用户没有权限收藏"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ count, err := models.GetMyChartCount(user.UserId, req.UniqueCode)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "收藏失败"
|
|
|
+ br.ErrMsg = "查询收藏数量失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if count > 0 {
|
|
|
+ br.Msg = "该图表已收藏,请重新刷新页面"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ myChart := &models.MyChart{
|
|
|
+ UserId: user.UserId,
|
|
|
+ UserRealName: user.RealName,
|
|
|
+ UniqueCode: req.UniqueCode,
|
|
|
+ ChartImage: req.ChartImage,
|
|
|
+ ChartName: req.ChartName,
|
|
|
+ CreateTime: time.Now(),
|
|
|
+ ModifyTime: time.Now(),
|
|
|
+ }
|
|
|
+ err = myChart.Insert()
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "收藏失败"
|
|
|
+ br.ErrMsg = "收藏失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ br.Msg = "收藏成功"
|
|
|
+ br.Success = true
|
|
|
+ br.Ret = 200
|
|
|
+}
|
|
|
+
|
|
|
+// @Title 取消收藏
|
|
|
+// @Description 取消收藏
|
|
|
+// @Param PageSize query int true "每页数据条数"
|
|
|
+// @Param CurrentIndex query int true "当前页页码,从1开始"
|
|
|
+// @Success 200 {object} models.BaseResponse
|
|
|
+// @Failure 403 {object} models.BaseResponse
|
|
|
+// @router /collectCancel [post]
|
|
|
+func (this *MyChartController) CollectCancel() {
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
+ defer func() {
|
|
|
+ this.Data["json"] = br
|
|
|
+ this.ServeJSON()
|
|
|
+ }()
|
|
|
+
|
|
|
+ var req request.MyChartCollectCancelReq
|
|
|
+ if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
|
|
|
+ br.Msg = "参数解析失败"
|
|
|
+ br.ErrMsg = "参数解析失败,Err:" + err.Error()
|
|
|
return
|
|
|
}
|
|
|
user := this.User
|
|
@@ -35,5 +96,130 @@ func (this *MyChartController) Collect() {
|
|
|
br.Msg = "用户没有权限收藏"
|
|
|
return
|
|
|
}
|
|
|
+ count, err := models.GetMyChartCount(user.UserId, req.UniqueCode)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "取消收藏失败"
|
|
|
+ br.ErrMsg = "获取收藏信息失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if count == 0 {
|
|
|
+ br.Msg = "该图表已取消收藏,请重新刷新页面"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ err = models.DeleteMyChart(user.UserId, req.UniqueCode)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "取消收藏失败"
|
|
|
+ br.ErrMsg = "取消收藏失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ br.Msg = "取消收藏成功"
|
|
|
+ br.Success = true
|
|
|
+ br.Ret = 200
|
|
|
+}
|
|
|
|
|
|
+// @Title List
|
|
|
+// @Description create users
|
|
|
+// @Param PageSize query int true "每页数据条数"
|
|
|
+// @Param CurrentIndex query int true "当前页页码,从1开始"
|
|
|
+// @Success 200 {object} models.BaseResponse
|
|
|
+// @Failure 403 {object} models.BaseResponse
|
|
|
+// @router /list [get]
|
|
|
+func (this *MyChartController) List() {
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
+ defer func() {
|
|
|
+ this.Data["json"] = br
|
|
|
+ this.ServeJSON()
|
|
|
+ }()
|
|
|
+
|
|
|
+ pageSize, _ := this.GetInt("PageSize")
|
|
|
+ currentIndex, _ := this.GetInt("CurrentIndex")
|
|
|
+
|
|
|
+ if pageSize <= 0 {
|
|
|
+ pageSize = 30
|
|
|
+ }
|
|
|
+ if currentIndex <= 0 {
|
|
|
+ currentIndex = 1
|
|
|
+ }
|
|
|
+
|
|
|
+ user := this.User
|
|
|
+ if user.Status != 2 {
|
|
|
+ br.Msg = "用户没有收藏权限"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ total, err := models.GetMyChartListCountById(user.UserId)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "查询收藏数量失败"
|
|
|
+ br.ErrMsg = "查询收藏数量失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ resp := new(response.MyChartListResp)
|
|
|
+ if total == 0 {
|
|
|
+ br.Data = resp
|
|
|
+ br.Msg = "暂无数据"
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ return
|
|
|
+ }
|
|
|
+ startSize := utils.StartIndex(currentIndex, pageSize)
|
|
|
+ items, err := models.GetMyChartListById(user.UserId, startSize, pageSize)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "查询收藏失败"
|
|
|
+ br.ErrMsg = "查询收藏失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ page := paging.GetPaging(currentIndex, pageSize, total)
|
|
|
+ resp.List = items
|
|
|
+ resp.Paging = page
|
|
|
+
|
|
|
+ br.Data = resp
|
|
|
+ br.Msg = "查询成功"
|
|
|
+ br.Success = true
|
|
|
+ br.Ret = 200
|
|
|
+}
|
|
|
+
|
|
|
+// @Title IsCollect
|
|
|
+// @Description create users
|
|
|
+// @Param PageSize query int true "每页数据条数"
|
|
|
+// @Param CurrentIndex query int true "当前页页码,从1开始"
|
|
|
+// @Success 200 {object} models.BaseResponse
|
|
|
+// @Failure 403 {object} models.BaseResponse
|
|
|
+// @router /isCollect [post]
|
|
|
+func (this *MyChartController) IsCollect() {
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
+ defer func() {
|
|
|
+ this.Data["json"] = br
|
|
|
+ this.ServeJSON()
|
|
|
+ }()
|
|
|
+
|
|
|
+ var req request.MyChartIsCollectReq
|
|
|
+ if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
|
|
|
+ br.Msg = "参数解析失败"
|
|
|
+ br.ErrMsg = "参数解析失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ user := this.User
|
|
|
+ if user.Status != 2 {
|
|
|
+ br.Msg = "用户没有权限收藏"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ count, err := models.GetMyChartCount(user.UserId, req.UniqueCode)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "查询收藏数量失败"
|
|
|
+ br.ErrMsg = "查询收藏数量失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ resp := new(response.MyChartIsCollectResp)
|
|
|
+ if count > 0 {
|
|
|
+ resp.IsCollect = true
|
|
|
+ } else {
|
|
|
+ resp.IsCollect = false
|
|
|
+ }
|
|
|
+ br.Data = resp
|
|
|
+ br.Msg = "查询成功"
|
|
|
+ br.Success = true
|
|
|
+ br.Ret = 200
|
|
|
}
|