staff_controller.go 7.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. package staff
  2. import (
  3. "SCRM/controllers"
  4. "SCRM/enums"
  5. "SCRM/models"
  6. "SCRM/service/staff_service"
  7. "SCRM/utils"
  8. "encoding/json"
  9. "fmt"
  10. "github.com/astaxie/beego"
  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. beego.Router("/api/staff/EditStaffInfo", &StaffManage{}, "Post:EditStaffInfo")
  17. beego.Router("/api/staff/DeleteStaffs", &StaffManage{}, "Delete:DeleteStaffs")
  18. }
  19. type StaffManage struct {
  20. controllers.BaseAuthAPIController
  21. }
  22. func (this *StaffManage) AddStaffInfo() {
  23. adminUserInfo := this.GetAdminUserInfo()
  24. userOrgID := int64(adminUserInfo.CurrentOrgId)
  25. fmt.Println("机构ID", userOrgID)
  26. dataBody := make(map[string]interface{}, 0)
  27. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  28. fmt.Println("视频发布是什么呢", err)
  29. if err != nil {
  30. utils.ErrorLog(err.Error())
  31. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "参数错误")
  32. return
  33. }
  34. fmt.Println("hhhhh")
  35. staffname := dataBody["name"].(string)
  36. if len(staffname) == 0 {
  37. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "姓名不能为空")
  38. return
  39. }
  40. phone := dataBody["phone"].(string)
  41. if len(phone) == 0 {
  42. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "手机不能为空")
  43. return
  44. }
  45. gender := int64(dataBody["gender"].(float64))
  46. if gender <= 0 {
  47. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "性别不能为空")
  48. return
  49. }
  50. birthday, _ := dataBody["birthday"].(string)
  51. if len(birthday) == 0 {
  52. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "生日格式不正确")
  53. return
  54. }
  55. timeLayout := "2006-01-02 15:04:05"
  56. theTime, err := utils.ParseTimeStringToTime(timeLayout, birthday+" 00:00:00")
  57. if err != nil {
  58. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "生日格式不正确")
  59. return
  60. }
  61. var staffbirthday = theTime.Unix()
  62. fmt.Println("生日", staffbirthday)
  63. userType := int64(dataBody["user_type"].(float64))
  64. if userType <= 0 {
  65. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "职称类型不正确")
  66. return
  67. }
  68. userTitle := int64(dataBody["user_title"].(float64))
  69. if userTitle <= 0 {
  70. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "职称名称不正确")
  71. return
  72. }
  73. dochead := dataBody["dochead"].(string)
  74. if len(dochead) == 0 {
  75. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "头像不正确")
  76. return
  77. }
  78. content := dataBody["content"].(string)
  79. if len(content) == 0 {
  80. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "头像不正确")
  81. return
  82. }
  83. fmt.Println("姓名", staffname, "性别", gender, "生日", staffbirthday, "职称类型", userType, "职称名称", userTitle, "头像", dochead, "内容", content)
  84. StaffInfo := models.SgjUserStaffInfo{
  85. Name: staffname,
  86. Phone: phone,
  87. Birthday: staffbirthday,
  88. Gender: gender,
  89. Content: content,
  90. UserType: userType,
  91. UserTitle: userTitle,
  92. Dochead: dochead,
  93. Status: 1,
  94. UserOrgId: userOrgID,
  95. Ctime: time.Now().Unix(),
  96. }
  97. err = staff_service.AddStaffInfo(StaffInfo)
  98. if err != nil {
  99. this.ServeFailJsonSend(enums.ErrorCodeDataException, "插入文章失败")
  100. return
  101. }
  102. this.ServeSuccessJSON(map[string]interface{}{
  103. "staffInfo": StaffInfo,
  104. })
  105. return
  106. }
  107. func (this *StaffManage) GetAllStaffInfo() {
  108. keyword := this.GetString("keyword")
  109. page, _ := this.GetInt64("page", 1)
  110. fmt.Println("页面", page)
  111. limit, _ := this.GetInt64("limit", 10)
  112. if page <= 0 {
  113. page = 1
  114. }
  115. if limit <= 0 {
  116. limit = 10
  117. }
  118. fmt.Println("限制", limit)
  119. fmt.Println("关键字", keyword, "limit", limit, "page", page)
  120. adminUserInfo := this.GetAdminUserInfo()
  121. userOrgID := int64(adminUserInfo.CurrentOrgId)
  122. userStaffInfo, total, err := staff_service.GetAllStaffInfo(userOrgID, page, limit, keyword)
  123. fmt.Println("内容", userStaffInfo, "total", total, "err", err)
  124. if err != nil {
  125. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取文章分类列表失败")
  126. return
  127. }
  128. this.ServeSuccessJSON(map[string]interface{}{
  129. "userStaffInfo": userStaffInfo,
  130. "total": total,
  131. })
  132. }
  133. func (this *StaffManage) EditStaffInfo() {
  134. id, _ := this.GetInt64("id")
  135. fmt.Println("ID是多少?", id)
  136. adminUserInfo := this.GetAdminUserInfo()
  137. userOrgID := int64(adminUserInfo.CurrentOrgId)
  138. fmt.Println("机构ID", userOrgID)
  139. dataBody := make(map[string]interface{}, 0)
  140. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  141. fmt.Println("视频发布是什么呢", err)
  142. if err != nil {
  143. utils.ErrorLog(err.Error())
  144. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "参数错误")
  145. return
  146. }
  147. staffname := dataBody["name"].(string)
  148. fmt.Println("staffname", staffname)
  149. if len(staffname) == 0 {
  150. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "姓名不能为空")
  151. return
  152. }
  153. phone := dataBody["phone"].(string)
  154. fmt.Println("phone", phone)
  155. if len(phone) == 0 {
  156. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "手机不能为空")
  157. return
  158. }
  159. gender := int64(dataBody["gender"].(float64))
  160. fmt.Println("gender", gender)
  161. if gender <= 0 {
  162. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "性别不能为空")
  163. return
  164. }
  165. birthday, _ := dataBody["birthday"].(string)
  166. fmt.Println("birthday", birthday)
  167. if len(birthday) == 0 {
  168. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "生日格式不正确")
  169. return
  170. }
  171. timeLayout := "2006-01-02 15:04:05"
  172. theTime, err := utils.ParseTimeStringToTime(timeLayout, birthday+" 00:00:00")
  173. if err != nil {
  174. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "生日格式不正确")
  175. return
  176. }
  177. var staffbirthday = theTime.Unix()
  178. fmt.Println("生日", staffbirthday)
  179. userType := int64(dataBody["user_type"].(float64))
  180. fmt.Println("userType", userType)
  181. if userType <= 0 {
  182. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "职称类型不正确")
  183. return
  184. }
  185. userTitle := int64(dataBody["user_title"].(float64))
  186. fmt.Println("userTitle", userTitle)
  187. if userTitle <= 0 {
  188. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "职称名称不正确")
  189. return
  190. }
  191. dochead := dataBody["dochead"].(string)
  192. fmt.Println("dochead", dochead)
  193. if len(dochead) == 0 {
  194. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "头像不正确")
  195. return
  196. }
  197. content := dataBody["content"].(string)
  198. fmt.Println("content", content)
  199. if len(content) == 0 {
  200. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "头像不正确")
  201. return
  202. }
  203. fmt.Println("姓名", staffname, "性别", gender, "生日", staffbirthday, "职称类型", userType, "职称名称", userTitle, "头像", dochead, "内容", content)
  204. StaffInfo := models.SgjUserStaffInfo{
  205. Name: staffname,
  206. Phone: phone,
  207. Birthday: staffbirthday,
  208. Gender: gender,
  209. Content: content,
  210. UserType: userType,
  211. UserTitle: userTitle,
  212. Dochead: dochead,
  213. Status: 1,
  214. UserOrgId: userOrgID,
  215. Mtime: time.Now().Unix(),
  216. }
  217. fmt.Println(StaffInfo)
  218. err = staff_service.UpdateStaffInfo(StaffInfo, userOrgID, id)
  219. fmt.Println("err", err)
  220. this.ServeSuccessJSON(map[string]interface{}{
  221. "userStaffInfo": StaffInfo,
  222. })
  223. }
  224. func (this *StaffManage) DeleteStaffs() {
  225. adminUserInfo := this.GetAdminUserInfo()
  226. OrgID := adminUserInfo.CurrentOrgId
  227. dataBody := make(map[string]interface{}, 0)
  228. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  229. if err != nil {
  230. utils.ErrorLog(err.Error())
  231. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "参数错误")
  232. return
  233. }
  234. idsInters := dataBody["ids"].([]interface{})
  235. if len(idsInters) == 0 {
  236. if err != nil {
  237. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除会员失败:(没有选择会员)")
  238. return
  239. }
  240. }
  241. ids := make([]int64, 0)
  242. for _, idsInter := range idsInters {
  243. id := int64(idsInter.(float64))
  244. ids = append(ids, id)
  245. }
  246. err = staff_service.DeleteStaffs(OrgID, ids)
  247. fmt.Println("错误", err)
  248. if err != nil {
  249. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除失败:("+err.Error()+")")
  250. return
  251. }
  252. returnData := make(map[string]interface{}, 0)
  253. returnData["msg"] = "ok"
  254. this.ServeSuccessJSON(returnData)
  255. return
  256. }