product.go 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. package controllers
  2. import (
  3. "eta/eta_mini_crm_ht/models"
  4. "eta/eta_mini_crm_ht/models/response"
  5. "eta/eta_mini_crm_ht/services"
  6. "eta/eta_mini_crm_ht/utils"
  7. "github.com/rdlucklib/rdluck_tools/paging"
  8. "strconv"
  9. "strings"
  10. )
  11. type ProductController struct {
  12. BaseAuthController
  13. }
  14. // UnSetProductList
  15. // @Title 未设置的产品列表
  16. // @Description 未设置的产品列表
  17. // @Param PageSize query int true "每页数据条数"
  18. // @Param CurrentIndex query int true "当前页页码,从1开始"
  19. // @Param ClassifyIds query string true "二级分类id,可多选用英文,隔开"
  20. // @Param KeyWord query string true "报告标题/创建人"
  21. // @Param SortType query string true "排序方式"
  22. // @Success 200 {object} models.ReportAuthorResp
  23. // @router /unSetProductList [get]
  24. func (this *ProductController) UnSetProductList() {
  25. br := new(models.BaseResponse).Init()
  26. defer func() {
  27. this.Data["json"] = br
  28. this.ServeJSON()
  29. }()
  30. pageSize, _ := this.GetInt("PageSize")
  31. currentIndex, _ := this.GetInt("CurrentIndex")
  32. sortType := this.GetString("SortType")
  33. ProductType := this.GetString("ProductType")
  34. permissionIds := this.GetString("PermissionIds")
  35. KeyWord := this.GetString("KeyWord")
  36. var condition string
  37. var pars []interface{}
  38. if pageSize <= 0 {
  39. pageSize = utils.PageSize20
  40. }
  41. if currentIndex <= 0 {
  42. currentIndex = 1
  43. }
  44. if ProductType == "" {
  45. br.Msg = "产品类型不能为空"
  46. br.ErrMsg = "获取未设置产品列表失败,Err:产品类型为空"
  47. return
  48. }
  49. if KeyWord != "" {
  50. switch ProductType {
  51. case "report":
  52. condition += " AND title like '%?%'"
  53. case "media":
  54. condition += " AND media_name like '%?%'"
  55. }
  56. pars = append(pars, KeyWord)
  57. }
  58. sortCondition := " ORDER BY published_time "
  59. if sortType == "" {
  60. sortType = "DESC"
  61. }
  62. sortCondition = sortCondition + sortType
  63. var permissionIdsList []int
  64. if permissionIds != "" {
  65. permissionStr := strings.Split(permissionIds, ",")
  66. for _, permissionItem := range permissionStr {
  67. permissionId, _ := strconv.Atoi(permissionItem)
  68. permissionIdsList = append(permissionIdsList, permissionId)
  69. }
  70. }
  71. total, ids, err := services.GetUnsetProductCountByCondition(ProductType, permissionIdsList, condition, pars)
  72. if err != nil {
  73. br.Msg = "获取未设置产品列表失败"
  74. br.ErrMsg = "获取未设置产品列表失败,Err:" + err.Error()
  75. return
  76. }
  77. var list []*services.ProductView
  78. if len(ids) > 0 {
  79. startSize := utils.StartIndex(currentIndex, pageSize)
  80. list, err = services.GetUnsetProductByCondition(ProductType, ids, sortCondition, startSize, pageSize)
  81. if err != nil {
  82. br.Msg = "获取未设置产品列表失败"
  83. br.ErrMsg = "获取未设置产品列表失败,Err:" + err.Error()
  84. return
  85. }
  86. }
  87. page := paging.GetPaging(currentIndex, pageSize, total)
  88. resp := new(response.ProductListResp)
  89. resp.List = list
  90. resp.Paging = page
  91. br.Ret = 200
  92. br.Success = true
  93. br.Data = resp
  94. br.Msg = "获取成功"
  95. }
  96. //
  97. //// UploadFile @Title 上传图片
  98. //// @Description 上传视频
  99. //// @Param File query file true "文件"
  100. //// @Success 200 {object} models.ReportAuthorResp
  101. //// @router /uploadFile [post]
  102. //func (this *VideoController) UploadFile() {
  103. // br := new(models.BaseResponse).Init()
  104. // defer func() {
  105. // this.Data["json"] = br
  106. // this.ServeJSON()
  107. // }()
  108. // f, h, err := this.GetFile("File")
  109. // if err != nil {
  110. // br.Msg = "获取资源信息失败"
  111. // br.ErrMsg = "获取资源信息失败,Err:" + err.Error()
  112. // return
  113. // }
  114. // defer f.Close()
  115. // size, err := strconv.Atoi(utils.UPLOAD_IMG_SIZE)
  116. // if err != nil {
  117. // size = 100
  118. // }
  119. // if h.Size > 1024*1024*int64(size) {
  120. // br.Msg = fmt.Sprintf("图片大小不能超过%dK", size)
  121. // br.ErrMsg = "图片上传失败,Err:" + err.Error()
  122. // return
  123. // }
  124. // ext := path.Ext(h.Filename)
  125. // //if ext != ".mp3" {
  126. // // br.Msg = "音频格式不正确"
  127. // // br.ErrMsg = "音频上传失败,Err:" + err.Error()
  128. // // return
  129. // //}
  130. // dateDir := time.Now().Format("20060102")
  131. // uploadDir := utils.STATIC_DIR + "ht/audio" + dateDir
  132. // err = os.MkdirAll(uploadDir, utils.DIR_MOD)
  133. // if err != nil {
  134. // br.Msg = "存储目录创建失败"
  135. // br.ErrMsg = "存储目录创建失败,Err:" + err.Error()
  136. // return
  137. // }
  138. // randStr := utils.GetRandStringNoSpecialChar(28)
  139. // fileName := randStr + ext
  140. // fpath := uploadDir + "/" + fileName
  141. // err = this.SaveToFile("File", fpath)
  142. // if err != nil {
  143. // br.Msg = "图片上传失败"
  144. // br.ErrMsg = "图片上传失败,Err:" + err.Error()
  145. // return
  146. // }
  147. // audioUploadDir := utils.RESOURCE_DIR + "img/"
  148. // savePdfToOssPath := audioUploadDir + time.Now().Format("200601/20060102/")
  149. // audioName := utils.GetRandStringNoSpecialChar(28)
  150. // savePdfToOssPath += audioName + ext
  151. //
  152. // defer func() {
  153. // err = os.Remove(fpath)
  154. // fmt.Sprintf("删除文件失败:%v", err)
  155. // }()
  156. // ossClient := services.NewOssClient()
  157. // if ossClient == nil {
  158. // br.Msg = "图片上传失败"
  159. // br.ErrMsg = "初始化OSS服务失败"
  160. // return
  161. // }
  162. // mp3Url, err := ossClient.UploadFile("", fpath, savePdfToOssPath)
  163. // if err != nil {
  164. // br.Msg = "图片上传失败"
  165. // br.ErrMsg = "图片上传失败,Err:" + err.Error()
  166. // return
  167. // }
  168. // base := path.Base(h.Filename)
  169. // resp := new(response.MediaUploadResp)
  170. // resp.Url = mp3Url
  171. // resp.FileName = base
  172. // br.Data = resp
  173. // br.Msg = "上传成功"
  174. // br.Ret = 200
  175. // br.Success = true
  176. //}