scrm-go

staff_controller.go 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. package staff
  2. import (
  3. "github.com/astaxie/beego"
  4. "SCRM/controllers"
  5. "encoding/json"
  6. "fmt"
  7. "SCRM/utils"
  8. "SCRM/enums"
  9. "SCRM/models"
  10. "SCRM/service/staff_service"
  11. "time"
  12. )
  13. func staffRouters() {
  14. beego.Router("/api/staff/addStaffInfo",&StaffManage{},"Post:AddStaffInfo")
  15. beego.Router("/api/staff/getAllStaffInfo",&StaffManage{},"Get:GetAllStaffInfo")
  16. }
  17. type StaffManage struct {
  18. controllers.BaseAuthAPIController
  19. }
  20. func (this *StaffManage) AddStaffInfo() {
  21. adminUserInfo := this.GetAdminUserInfo()
  22. userOrgID := int64(adminUserInfo.CurrentOrgId)
  23. fmt.Println("机构ID",userOrgID)
  24. dataBody := make(map[string]interface{}, 0)
  25. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  26. fmt.Println("视频发布是什么呢",err)
  27. if err != nil {
  28. utils.ErrorLog(err.Error())
  29. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "参数错误")
  30. return
  31. }
  32. fmt.Println("hhhhh")
  33. staffname := dataBody["name"].(string)
  34. if len(staffname) == 0 {
  35. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "姓名不能为空")
  36. return
  37. }
  38. phone := dataBody["phone"].(string)
  39. if len(phone) == 0 {
  40. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "手机不能为空")
  41. return
  42. }
  43. gender := int64(dataBody["gender"].(float64))
  44. if gender <= 0{
  45. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "性别不能为空")
  46. return
  47. }
  48. birthday, _ := dataBody["birthday"].(string)
  49. if len(birthday) == 0 {
  50. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "生日格式不正确")
  51. return
  52. }
  53. timeLayout := "2006-01-02 15:04:05"
  54. theTime, err := utils.ParseTimeStringToTime(timeLayout, birthday+" 00:00:00")
  55. if err != nil {
  56. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "生日格式不正确")
  57. return
  58. }
  59. var staffbirthday = theTime.Unix()
  60. fmt.Println("生日",staffbirthday)
  61. userType := int64(dataBody["user_type"].(float64))
  62. if userType <= 0 {
  63. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "职称类型不正确")
  64. return
  65. }
  66. userTitle :=int64(dataBody["user_title"].(float64))
  67. if userTitle <= 0 {
  68. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "职称名称不正确")
  69. return
  70. }
  71. dochead := dataBody["dochead"].(string)
  72. if len(dochead) == 0 {
  73. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "头像不正确")
  74. return
  75. }
  76. content := dataBody["content"].(string)
  77. if len(content) == 0 {
  78. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "头像不正确")
  79. return
  80. }
  81. fmt.Println("姓名",staffname,"性别" ,gender,"生日",staffbirthday,"职称类型",userType,"职称名称",userTitle,"头像",dochead,"内容",content)
  82. StaffInfo := models.SgjUserStaffInfo{
  83. Name: staffname,
  84. Phone: phone,
  85. Birthday: staffbirthday,
  86. Gender:gender,
  87. Content:content,
  88. UserType: userType,
  89. UserTitle: userType,
  90. Dochead: dochead,
  91. Status: 1,
  92. UserOrgId:userOrgID,
  93. Ctime:time.Now().Unix(),
  94. }
  95. err = staff_service.AddStaffInfo(StaffInfo)
  96. if err !=nil{
  97. this.ServeFailJsonSend(enums.ErrorCodeDataException, "插入文章失败")
  98. return
  99. }
  100. this.ServeSuccessJSON(map[string]interface{}{
  101. "staffInfo":StaffInfo,
  102. })
  103. return
  104. }
  105. func (this *StaffManage) GetAllStaffInfo() {
  106. keyword := this.GetString("keyword")
  107. page, _ := this.GetInt64("page", 1)
  108. fmt.Println("页面",page)
  109. limit, _ := this.GetInt64("limit", 10)
  110. if page <= 0 {
  111. page = 1
  112. }
  113. if limit <= 0 {
  114. limit = 10
  115. }
  116. fmt.Println("限制",limit)
  117. fmt.Println("关键字",keyword,"limit",limit,"page",page)
  118. adminUserInfo := this.GetAdminUserInfo()
  119. userOrgID := int64(adminUserInfo.CurrentOrgId)
  120. userStaffInfo, total, err := staff_service.GetAllStaffInfo(userOrgID, page, limit, keyword)
  121. fmt.Println("内容",userStaffInfo,"total",total,"err",err)
  122. if err !=nil{
  123. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取文章分类列表失败")
  124. return
  125. }
  126. this.ServeSuccessJSON(map[string]interface{}{
  127. "userStaffInfo":userStaffInfo,
  128. "total":total,
  129. })
  130. }