scrm-go

article_controller.go 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876
  1. package article
  2. import (
  3. "github.com/astaxie/beego"
  4. "fmt"
  5. "SCRM/controllers"
  6. "SCRM/service/article_service"
  7. "SCRM/enums"
  8. "SCRM/models"
  9. "time"
  10. "SCRM/utils"
  11. "encoding/json"
  12. "strconv"
  13. )
  14. func ArticleRouters() {
  15. beego.Router("/api/acticle/createacticle",&ArticleManage{},"Post:CreateArticle")
  16. beego.Router("/api/acticle/getArticleType",&ArticleManage{},"Get:GetArticleType")
  17. beego.Router("/api/acticle/getAllArticles",&ArticleManage{},"Get:GetAllArticles")
  18. beego.Router("/api/article/addCategory",&ArticleManage{},"Post:AddCategory")
  19. beego.Router("/api/acticle/getCategorys",&ArticleManage{},"Get:GetCategorys")
  20. beego.Router("/api/acticle/edit",&ArticleManage{},"Post:EditCategorys")
  21. beego.Router("/api/acticle/delete",&ArticleManage{},"Delete:DeleteCategorys")
  22. beego.Router("/api/acticle/addvido",&ArticleManage{},"Post:Addvido")
  23. beego.Router("/api/acticle/savedraft",&ArticleManage{},"Post:SaveDraft")
  24. beego.Router("/api/acticle/prviewArticle",&ArticleManage{},"Post:PrviewArticle")
  25. beego.Router("/api/acticle/getarticlePreview",&ArticleManage{},"Get:GetArtilcePreview")
  26. beego.Router("/api/acticle/save",&ArticleManage{},"Post:AddDraft")
  27. beego.Router("/api/acticle/getEditArticle",&ArticleManage{},"Get:GetArticleInfo")
  28. beego.Router("/api/article/Delete",&ArticleManage{},"Delete:DeleteArticle")
  29. beego.Router("/api/acticle/getMenus",&ArticleManage{},"Get:GetMenus")
  30. beego.Router("/api/acticle/updateArticlesInfo",&ArticleManage{},"Post:UpdataArticleInfo")
  31. beego.Router("/api/acticle/previewEditArticle",&ArticleManage{},"Post:PreviewEditArticle")
  32. beego.Router("/api/acticle/getPreviewInfo",&ArticleManage{},"Post:GetPreviewInfo")
  33. beego.Router("/api/acticle/getAllComment",&ArticleManage{},"Get:GetAllComment")
  34. beego.Router("/api/acticle/getArticleCommentDetail",&ArticleManage{},"Get:GetArticleCommentDetail")
  35. }
  36. type ArticleManage struct {
  37. controllers.BaseAuthAPIController
  38. }
  39. func (this *ArticleManage) CreateArticle(){
  40. adminUserInfo := this.GetAdminUserInfo()
  41. userOrgID := int64(adminUserInfo.CurrentOrgId)
  42. dataBody := make(map[string]interface{}, 0)
  43. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  44. fmt.Println("视频发布是什么呢",err)
  45. if err != nil {
  46. utils.ErrorLog(err.Error())
  47. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "参数错误")
  48. return
  49. }
  50. actname := dataBody["act_name"].(string)
  51. if len(actname) == 0 {
  52. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "文章标题不能为空")
  53. return
  54. }
  55. actcontent := dataBody["act_content"].(string)
  56. if len(actcontent) == 0 {
  57. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "文章内容不能为空")
  58. return
  59. }
  60. orglogo := dataBody["org_logo"].(string)
  61. if len(orglogo) == 0 {
  62. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "封面图片不能为空")
  63. return
  64. }
  65. acttype := int64(dataBody["act_type"].(float64))
  66. if acttype <= 0 {
  67. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "分类号不能为空")
  68. return
  69. }
  70. timenow := time.Now().Unix()
  71. fmt.Println("姓名:",actname,"文章内容",actcontent,"图片",orglogo,"文章类型",acttype,userOrgID)
  72. articles := models.Articles{
  73. Title: actname,
  74. Content: actcontent,
  75. Imgs: orglogo,
  76. ClassId: acttype,
  77. UserOrgId:userOrgID,
  78. Ctime:timenow,
  79. Status:1,
  80. Type:1,
  81. ArticleStatus:1,
  82. }
  83. err = article_service.AddAritcle(articles)
  84. if err !=nil{
  85. this.ServeFailJsonSend(enums.ErrorCodeDataException, "插入文章失败")
  86. return
  87. }
  88. this.ServeSuccessJSON(map[string]interface{}{
  89. "articles":articles,
  90. })
  91. }
  92. func (this *ArticleManage) GetArticleType(){
  93. adminUserInfo := this.GetAdminUserInfo()
  94. userOrgID := adminUserInfo.CurrentOrgId
  95. category, err := article_service.FindArticleCategoryType(userOrgID)
  96. fmt.Println("文章分类列表",category,err)
  97. if err !=nil{
  98. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取文章分类列表失败")
  99. return
  100. }
  101. this.ServeSuccessJSON(map[string]interface{}{
  102. "category":category,
  103. })
  104. return
  105. }
  106. func (this *ArticleManage) GetAllArticles() {
  107. page, _ := this.GetInt64("page", 1)
  108. fmt.Println("页面",page)
  109. limit, _ := this.GetInt64("limit", 10)
  110. fmt.Println("限制",limit)
  111. searchKey := this.GetString("keyword", "")
  112. classId,_ := this.GetInt64("id",0)
  113. status, _ := this.GetInt64("status")
  114. fmt.Println("页面",page,"限制",limit,"关键字",searchKey,"分类号",classId,"状态值:",status)
  115. if page <= 0 {
  116. page = 1
  117. }
  118. if limit <= 0 {
  119. limit = 10
  120. }
  121. adminUserInfo := this.GetAdminUserInfo()
  122. userOrgID := adminUserInfo.CurrentOrgId
  123. if(status == 1){
  124. articles, total, err := article_service.GetPublished(userOrgID, page, limit, searchKey)
  125. category, err := article_service.FindCategoryList(userOrgID)
  126. if err !=nil{
  127. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取文章分类列表失败")
  128. return
  129. }
  130. this.ServeSuccessJSON(map[string]interface{}{
  131. "articles":articles,
  132. "total":total,
  133. "category":category,
  134. })
  135. }
  136. if(status == 2){
  137. articles, total, err := article_service.GetDraftbox(userOrgID, page, limit, searchKey)
  138. category, err := article_service.FindCategoryList(userOrgID)
  139. if err !=nil{
  140. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取文章分类列表失败")
  141. return
  142. }
  143. this.ServeSuccessJSON(map[string]interface{}{
  144. "articles":articles,
  145. "total":total,
  146. "category":category,
  147. })
  148. }
  149. if(status == 3){
  150. articles, total, err := article_service.GetNoPass(userOrgID, page, limit, searchKey)
  151. category, err := article_service.FindCategoryList(userOrgID)
  152. if err !=nil{
  153. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取文章分类列表失败")
  154. return
  155. }
  156. this.ServeSuccessJSON(map[string]interface{}{
  157. "articles":articles,
  158. "total":total,
  159. "category":category,
  160. })
  161. }
  162. articles, total, err := article_service.FindAllArticle(userOrgID, page,limit, searchKey,classId)
  163. fmt.Println("文章内容是是么",articles)
  164. fmt.Println("total",total)
  165. fmt.Println("err",err)
  166. if err !=nil{
  167. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取文章列表失败")
  168. return
  169. }
  170. category, err := article_service.FindCategoryList(userOrgID)
  171. fmt.Println("category是傻",category,err)
  172. if err !=nil{
  173. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取文章分类列表失败")
  174. return
  175. }
  176. this.ServeSuccessJSON(map[string]interface{}{
  177. "articles":articles,
  178. "total":total,
  179. "category":category,
  180. })
  181. return
  182. }
  183. func (this *ArticleManage) AddCategory(){
  184. dataBody := make(map[string]interface{}, 0)
  185. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  186. fmt.Println("err是什么呢",err)
  187. if err != nil {
  188. utils.ErrorLog(err.Error())
  189. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "参数错误")
  190. return
  191. }
  192. name:= dataBody["name"].(string)
  193. fmt.Println("name是谁?",name)
  194. if len(name) == 0 {
  195. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "姓名不能为空")
  196. return
  197. }
  198. content := dataBody["summary"].(string)
  199. fmt.Println("content是谁?",content)
  200. if len(content) == 0 {
  201. this.ServeFailJsonSend(enums.ErrorCodeParamWrong,"内容不能为空")
  202. return
  203. }
  204. sort := dataBody["order"].(string)
  205. sors, _ := strconv.ParseInt(sort, 10, 64)
  206. if sors <=0 {
  207. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "排序不能为空")
  208. return
  209. }
  210. fmt.Println("soert是谁?",sort)
  211. fmt.Println("姓名:",name,"内容",content,"排序",sort)
  212. timenow := time.Now().Unix()
  213. adminUserInfo := this.GetAdminUserInfo()
  214. userOrgID := adminUserInfo.CurrentOrgId
  215. category := models.ArticleCategory{
  216. Name: name,
  217. Summary: content,
  218. Order: sors,
  219. UserOrgId:userOrgID,
  220. Status: 1,
  221. Ctime: timenow,
  222. }
  223. fmt.Println(category)
  224. err = article_service.AddCategory(category)
  225. fmt.Println(err)
  226. if err !=nil{
  227. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加分类失败")
  228. return
  229. }
  230. this.ServeSuccessJSON(map[string]interface{}{
  231. "category":category,
  232. })
  233. }
  234. func (this *ArticleManage) GetCategorys() {
  235. adminUserInfo := this.GetAdminUserInfo()
  236. userOrgID := adminUserInfo.CurrentOrgId
  237. page, _ := this.GetInt64("page", 1)
  238. limit, _ := this.GetInt64("limit", 10)
  239. if page <= 0 {
  240. page = 1
  241. }
  242. if limit <= 0 {
  243. limit = 10
  244. }
  245. fmt.Println("机构ID",userOrgID)
  246. categorys, total, err := article_service.GetCategorys(page, limit, userOrgID)
  247. fmt.Println("hhe",categorys,total,err)
  248. if err !=nil{
  249. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取文章分类列表失败")
  250. return
  251. }
  252. this.ServeSuccessJSON(map[string]interface{}{
  253. "category":categorys,
  254. "total":total,
  255. })
  256. return
  257. }
  258. func (this *ArticleManage) EditCategorys() {
  259. id, _ := this.GetInt64("id", 0)
  260. fmt.Println("ID是多少",id)
  261. if id <= 0 {
  262. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "参数错误:id")
  263. return
  264. }
  265. adminUserInfo := this.GetAdminUserInfo()
  266. userOrgID := adminUserInfo.CurrentOrgId
  267. categorys, err := article_service.GetCategorysByID(userOrgID, id)
  268. fmt.Println("categorys是?",categorys,err)
  269. if err != nil {
  270. this.ServeFailJsonSend(enums.ErrorCodeDBUpdate, "编辑会员失败:("+err.Error()+")")
  271. return
  272. }
  273. if categorys == nil {
  274. this.ServeFailJsonSend(enums.ErrorCodeDBUpdate, "编辑会员失败:(会员记录不存在)")
  275. return
  276. }
  277. timenow := time.Now().Unix()
  278. dataBody := make(map[string]interface{}, 0)
  279. err = json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  280. if err != nil {
  281. utils.ErrorLog(err.Error())
  282. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "参数错误")
  283. return
  284. }
  285. name:= dataBody["name"].(string)
  286. fmt.Println("name是谁?",name)
  287. content := dataBody["summary"].(string)
  288. fmt.Println("content是谁?",content)
  289. if len(content) == 0 {
  290. this.ServeFailJsonSend(enums.ErrorCodeParamWrong,"内容不能为空")
  291. return
  292. }
  293. sors :=int64(dataBody["order"].(float64))
  294. //sors, _ := strconv.ParseInt(sort, 10, 64)
  295. fmt.Println("sort0",sors)
  296. if sors <= 0 {
  297. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "排序不能为空")
  298. return
  299. }
  300. fmt.Println("soert是谁?",sors)
  301. fmt.Println("姓名:",name,"内容",content,"排序",sors)
  302. category := models.ArticleCategory{
  303. Name: name,
  304. Summary: content,
  305. Order: sors,
  306. UserOrgId:userOrgID,
  307. Status: 1,
  308. Mtime: timenow,
  309. }
  310. fmt.Println("category是?",category)
  311. article_service.EditCategory(&category,userOrgID,id)
  312. this.ServeSuccessJSON(map[string]interface{}{
  313. "category":category,
  314. })
  315. }
  316. func (this *ArticleManage) DeleteCategorys() {
  317. adminUserInfo := this.GetAdminUserInfo()
  318. dataBody := make(map[string]interface{}, 0)
  319. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  320. if err != nil {
  321. utils.ErrorLog(err.Error())
  322. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "参数错误")
  323. return
  324. }
  325. idsInters := dataBody["ids"].([]interface{})
  326. if len(idsInters) == 0 {
  327. if err != nil {
  328. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除会员失败:(没有选择会员)")
  329. return
  330. }
  331. }
  332. ids := make([]int64, 0)
  333. for _, idsInter := range idsInters {
  334. id := int64(idsInter.(float64))
  335. ids = append(ids, id)
  336. }
  337. err = article_service.DeleteCategorys(adminUserInfo.CurrentOrgId, ids)
  338. if err != nil {
  339. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除分类失败:("+err.Error()+")")
  340. return
  341. }
  342. returnData := make(map[string]interface{}, 0)
  343. returnData["msg"] = "ok"
  344. this.ServeSuccessJSON(returnData)
  345. return
  346. }
  347. func (this *ArticleManage) Addvido(){
  348. adminUserInfo := this.GetAdminUserInfo()
  349. userOrgID := adminUserInfo.CurrentOrgId
  350. dataBody := make(map[string]interface{}, 0)
  351. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  352. fmt.Println("视频发布是什么呢",err)
  353. if err != nil {
  354. utils.ErrorLog(err.Error())
  355. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "参数错误")
  356. return
  357. }
  358. vidupload := dataBody["vio_upload"].(string)
  359. if len(vidupload) == 0 {
  360. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "视频不能为空")
  361. return
  362. }
  363. fmt.Println("视频",vidupload)
  364. vidname := dataBody["vid_name"].(string)
  365. if len(vidname)==0{
  366. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "视频标题不能为空")
  367. return
  368. }
  369. fmt.Println("视频名称",vidname)
  370. vidpic := dataBody["vid_pic"].(string)
  371. if(vidpic == ""){
  372. vidpic = vidupload + "?vframe/jpg/offset/1/w/300/h/200"
  373. }
  374. if len(vidpic)==0{
  375. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "视频封面不能为空")
  376. return
  377. }
  378. fmt.Println("视频图片",vidpic)
  379. vidtype := int64(dataBody["vid_type"].(float64))
  380. if vidtype <= 0 {
  381. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "所属分类不能为空")
  382. return
  383. }
  384. fmt.Println("视频类型",vidtype)
  385. fmt.Println("视频",vidupload,"视频标题",vidname,"视频封面",vidpic,"视频类型",vidtype)
  386. timenow := time.Now().Unix()
  387. articles := models.Articles{
  388. UserOrgId:userOrgID,
  389. Ctime:timenow,
  390. Type:2,
  391. VideoUrl:vidupload,
  392. Title:vidname,
  393. Imgs:vidpic,
  394. ClassId:vidtype,
  395. ArticleStatus:1,
  396. }
  397. err = article_service.AddVido(articles)
  398. if err !=nil{
  399. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加分类失败")
  400. return
  401. }
  402. this.ServeSuccessJSON(map[string]interface{}{
  403. "vido":articles,
  404. })
  405. }
  406. func (this *ArticleManage) SaveDraft() {
  407. adminUserInfo := this.GetAdminUserInfo()
  408. userOrgID := adminUserInfo.CurrentOrgId
  409. dataBody := make(map[string]interface{}, 0)
  410. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  411. fmt.Println("视频发布是什么呢",err)
  412. if err != nil {
  413. utils.ErrorLog(err.Error())
  414. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "参数错误")
  415. return
  416. }
  417. vidupload := dataBody["vio_upload"].(string)
  418. if len(vidupload) == 0 {
  419. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "视频不能为空")
  420. return
  421. }
  422. fmt.Println("视频",vidupload)
  423. vidname := dataBody["vid_name"].(string)
  424. if len(vidname)==0{
  425. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "视频标题不能为空")
  426. return
  427. }
  428. fmt.Println("视频名称",vidname)
  429. vidpic := dataBody["vid_pic"].(string)
  430. if(vidpic == ""){
  431. vidpic = vidupload + "?vframe/jpg/offset/1/w/300/h/200"
  432. }
  433. if len(vidpic)==0{
  434. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "视频封面不能为空")
  435. return
  436. }
  437. fmt.Println("视频图片",vidpic)
  438. vidtype := int64(dataBody["vid_type"].(float64))
  439. if vidtype <= 0 {
  440. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "所属分类不能为空")
  441. return
  442. }
  443. fmt.Println("视频类型",vidtype)
  444. fmt.Println("视频",vidupload,"视频标题",vidname,"视频封面",vidpic,"视频类型",vidtype)
  445. timenow := time.Now().Unix()
  446. articles := models.Articles{
  447. UserOrgId:userOrgID,
  448. Ctime:timenow,
  449. Type:2,
  450. VideoUrl:vidupload,
  451. Title:vidname,
  452. Imgs:vidpic,
  453. ClassId:vidtype,
  454. ArticleStatus:2,
  455. }
  456. err = article_service.AddVido(articles)
  457. if err !=nil{
  458. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加分类失败")
  459. return
  460. }
  461. this.ServeSuccessJSON(map[string]interface{}{
  462. "savedraft":articles,
  463. })
  464. }
  465. func (this *ArticleManage) PrviewArticle() {
  466. adminUserInfo := this.GetAdminUserInfo()
  467. userOrgID := adminUserInfo.CurrentOrgId
  468. dataBody := make(map[string]interface{}, 0)
  469. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  470. fmt.Println("视频发布是什么呢",err)
  471. if err != nil {
  472. utils.ErrorLog(err.Error())
  473. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "参数错误")
  474. return
  475. }
  476. actname := dataBody["act_name"].(string)
  477. if len(actname) == 0 {
  478. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "文章标题不能为空")
  479. return
  480. }
  481. actcontent := dataBody["act_content"].(string)
  482. if len(actcontent) == 0 {
  483. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "文章内容不能为空")
  484. return
  485. }
  486. orglogo := dataBody["org_logo"].(string)
  487. if len(orglogo) == 0 {
  488. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "封面图片不能为空")
  489. return
  490. }
  491. acttype := int64(dataBody["act_type"].(float64))
  492. if acttype <= 0 {
  493. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "分类号不能为空")
  494. return
  495. }
  496. timenow := time.Now().Unix()
  497. fmt.Println("姓名:",actname,"文章内容",actcontent,"图片",orglogo,"文章类型",acttype,userOrgID)
  498. articles := models.Articles{
  499. Title: actname,
  500. Content: actcontent,
  501. Imgs: orglogo,
  502. ClassId: acttype,
  503. UserOrgId:userOrgID,
  504. Ctime:timenow,
  505. Status:1,
  506. Type:1,
  507. ArticleStatus:3,
  508. }
  509. err = article_service.AddPrviewArticle(articles)
  510. if err !=nil{
  511. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加预览失败")
  512. return
  513. }
  514. this.ServeSuccessJSON(map[string]interface{}{
  515. "art":articles,
  516. })
  517. fmt.Println("art是谁",articles)
  518. }
  519. func (this *ArticleManage) GetArtilcePreview() {
  520. adminUserInfo := this.GetAdminUserInfo()
  521. userOrgID := adminUserInfo.CurrentOrgId
  522. articles, err := article_service.GetArtilcePreview(userOrgID)
  523. if err !=nil{
  524. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取预览失败")
  525. return
  526. }
  527. fmt.Println("文章内容",articles)
  528. this.ServeSuccessJSON(map[string]interface{}{
  529. "articles":articles,
  530. })
  531. }
  532. func (this *ArticleManage) AddDraft() {
  533. adminUserInfo := this.GetAdminUserInfo()
  534. userOrgID := adminUserInfo.CurrentOrgId
  535. dataBody := make(map[string]interface{}, 0)
  536. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  537. fmt.Println("视频发布是什么呢", err)
  538. if err != nil {
  539. utils.ErrorLog(err.Error())
  540. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "参数错误")
  541. return
  542. }
  543. actname := dataBody["act_name"].(string)
  544. if len(actname) == 0 {
  545. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "文章标题不能为空")
  546. return
  547. }
  548. actcontent := dataBody["act_content"].(string)
  549. if len(actcontent) == 0 {
  550. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "文章内容不能为空")
  551. return
  552. }
  553. orglogo := dataBody["org_logo"].(string)
  554. if len(orglogo) == 0 {
  555. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "封面图片不能为空")
  556. return
  557. }
  558. acttype := int64(dataBody["act_type"].(float64))
  559. if acttype <= 0 {
  560. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "分类号不能为空")
  561. return
  562. }
  563. timenow := time.Now().Unix()
  564. fmt.Println("姓名:", actname, "文章内容", actcontent, "图片", orglogo, "文章类型", acttype, userOrgID)
  565. articles := models.Articles{
  566. Title: actname,
  567. Content: actcontent,
  568. Imgs: orglogo,
  569. ClassId: acttype,
  570. UserOrgId: userOrgID,
  571. Ctime: timenow,
  572. Status: 1,
  573. Type: 1,
  574. ArticleStatus: 2,
  575. }
  576. err = article_service.AddDraft(articles)
  577. if err !=nil{
  578. this.ServeFailJsonSend(enums.ErrorCodeDataException, "保存草稿失败")
  579. return
  580. }
  581. fmt.Println("文章内容",articles)
  582. this.ServeSuccessJSON(map[string]interface{}{
  583. "articles":articles,
  584. })
  585. }
  586. func (this *ArticleManage) GetArticleInfo() {
  587. id, _ := this.GetInt64("id")
  588. fmt.Println("id是啥",id)
  589. adminUserInfo := this.GetAdminUserInfo()
  590. userOrgID := adminUserInfo.CurrentOrgId
  591. articles, err := article_service.GetArticleInfo(userOrgID, id)
  592. if err !=nil{
  593. this.ServeFailJsonSend(enums.ErrorCodeDataException, "查询文章信息失败")
  594. return
  595. }
  596. fmt.Println("内容是啥什么",articles)
  597. this.ServeSuccessJSON(map[string]interface{}{
  598. "articles":articles,
  599. })
  600. }
  601. func (this *ArticleManage) DeleteArticle() {
  602. adminUserInfo := this.GetAdminUserInfo()
  603. userOrgID := adminUserInfo.CurrentOrgId
  604. dataBody := make(map[string]interface{}, 0)
  605. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  606. if err != nil {
  607. utils.ErrorLog(err.Error())
  608. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "参数错误")
  609. return
  610. }
  611. idsInters := dataBody["ids"].([]interface{})
  612. if len(idsInters) == 0 {
  613. if err != nil {
  614. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除会员失败:(没有选择会员)")
  615. return
  616. }
  617. }
  618. ids := make([]int64, 0)
  619. for _, idsInter := range idsInters {
  620. id := int64(idsInter.(float64))
  621. ids = append(ids, id)
  622. }
  623. err = article_service.DeleteArticle(ids, userOrgID)
  624. if err !=nil{
  625. this.ServeFailJsonSend(enums.ErrorCodeDataException, "删除失败")
  626. return
  627. }
  628. returnData := make(map[string]interface{}, 0)
  629. returnData["msg"] = "ok"
  630. this.ServeSuccessJSON(returnData)
  631. return
  632. }
  633. func (this *ArticleManage) GetMenus(){
  634. adminUserInfo := this.GetAdminUserInfo()
  635. userOrgID := adminUserInfo.CurrentOrgId
  636. categorys, err := article_service.GetMenus(userOrgID)
  637. if err !=nil{
  638. this.ServeFailJsonSend(enums.ErrorCodeDataException, "查询失败")
  639. return
  640. }
  641. this.ServeSuccessJSON(map[string]interface{}{
  642. "categorys":categorys,
  643. })
  644. }
  645. func (this * ArticleManage) UpdataArticleInfo(){
  646. adminUserInfo := this.GetAdminUserInfo()
  647. userOrgID := adminUserInfo.CurrentOrgId
  648. id, _ := this.GetInt64("id")
  649. fmt.Println("id是多少",id)
  650. dataBody := make(map[string]interface{}, 0)
  651. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  652. fmt.Println("视频发布是什么呢",err)
  653. if err != nil {
  654. utils.ErrorLog(err.Error())
  655. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "参数错误")
  656. return
  657. }
  658. title := dataBody["title"].(string)
  659. if len(title) == 0 {
  660. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "文章标题不能为空")
  661. return
  662. }
  663. fmt.Println("title",title)
  664. content := dataBody["content"].(string)
  665. if len(content) == 0 {
  666. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "内容不能为空")
  667. return
  668. }
  669. fmt.Println("content",content)
  670. images := dataBody["imgs"].(string)
  671. fmt.Println("images",images)
  672. classid :=int64( dataBody["class_id"].(float64))
  673. if classid <=0 {
  674. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "分类号不能为空")
  675. return
  676. }
  677. //classid, _ := strconv.ParseInt(class_id, 10, 64)
  678. fmt.Println("分类号",classid)
  679. fmt.Println("标题",title,"内容",content,"图片",images,"分类号",classid,"机构ID",userOrgID)
  680. articles := models.Articles{
  681. Title: title,
  682. Content: content,
  683. Imgs: images,
  684. ClassId: classid,
  685. Status: 1,
  686. Mtime: time.Now().Unix(),
  687. }
  688. fmt.Println("为什么",articles)
  689. article_service.UpdataArticleInfo(&articles,userOrgID, id)
  690. this.ServeSuccessJSON(map[string]interface{}{
  691. "articls":articles,
  692. })
  693. }
  694. func (this * ArticleManage) PreviewEditArticle() {
  695. adminUserInfo := this.GetAdminUserInfo()
  696. userOrgID := adminUserInfo.CurrentOrgId
  697. id, _ := this.GetInt64("id")
  698. fmt.Println("id是多少",id)
  699. dataBody := make(map[string]interface{}, 0)
  700. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  701. fmt.Println("视频发布是什么呢",err)
  702. if err != nil {
  703. utils.ErrorLog(err.Error())
  704. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "参数错误")
  705. return
  706. }
  707. title := dataBody["title"].(string)
  708. if len(title) == 0 {
  709. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "文章标题不能为空")
  710. return
  711. }
  712. fmt.Println("title",title)
  713. content := dataBody["content"].(string)
  714. if len(content) == 0 {
  715. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "内容不能为空")
  716. return
  717. }
  718. fmt.Println("content",content)
  719. images := dataBody["imgs"].(string)
  720. fmt.Println("images",images)
  721. classid :=int64( dataBody["class_id"].(float64))
  722. if classid <=0 {
  723. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "分类号不能为空")
  724. return
  725. }
  726. //classid, _ := strconv.ParseInt(class_id, 10, 64)
  727. fmt.Println("分类号",classid)
  728. fmt.Println("标题",title,"内容",content,"图片",images,"分类号",classid,"机构ID",userOrgID)
  729. articles := models.Articles{
  730. Title: title,
  731. Content: content,
  732. Imgs: images,
  733. ClassId: classid,
  734. Status: 1,
  735. Mtime: time.Now().Unix(),
  736. ArticleStatus:3,
  737. }
  738. article_service.PreviewEditArticle(articles,userOrgID,id)
  739. this.ServeSuccessJSON(map[string]interface{}{
  740. "articls":articles,
  741. })
  742. }
  743. func (this * ArticleManage) GetPreviewInfo() {
  744. adminUserInfo := this.GetAdminUserInfo()
  745. userOrgID := adminUserInfo.CurrentOrgId
  746. articles, err := article_service.GetPreviewInfo(userOrgID)
  747. if err !=nil{
  748. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取预览失败")
  749. return
  750. }
  751. fmt.Println("文章内容",articles)
  752. this.ServeSuccessJSON(map[string]interface{}{
  753. "articles":articles,
  754. })
  755. }
  756. func (this * ArticleManage) GetAllComment() {
  757. page, _ := this.GetInt64("page", 1)
  758. fmt.Println("页面",page)
  759. limit, _ := this.GetInt64("limit", 10)
  760. fmt.Println("限制",limit)
  761. if page <= 0 {
  762. page = 1
  763. }
  764. if limit <= 0 {
  765. limit = 10
  766. }
  767. adminUserInfo := this.GetAdminUserInfo()
  768. userOrgID := adminUserInfo.CurrentOrgId
  769. articles, total, err := article_service.GetAllComment(page, limit, userOrgID)
  770. fmt.Println("文章内容",articles)
  771. if err !=nil{
  772. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取预览失败")
  773. return
  774. }
  775. this.ServeSuccessJSON(map[string]interface{}{
  776. "total":total,
  777. "articles":articles,
  778. })
  779. }
  780. func (this * ArticleManage) GetArticleCommentDetail(){
  781. id, _ := this.GetInt64("id")
  782. fmt.Println("id是多少",id)
  783. adminUserInfo := this.GetAdminUserInfo()
  784. userOrgID := adminUserInfo.CurrentOrgId
  785. articles, err := article_service.GetArticleCommentDetail(id, userOrgID)
  786. if err !=nil{
  787. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取预览失败")
  788. return
  789. }
  790. this.ServeSuccessJSON(map[string]interface{}{
  791. "articles":articles,
  792. })
  793. }