scrm-go

staff_controller.go 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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. 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. if len(staffname) == 0 {
  149. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "姓名不能为空")
  150. return
  151. }
  152. phone := dataBody["phone"].(string)
  153. if len(phone) == 0 {
  154. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "手机不能为空")
  155. return
  156. }
  157. gender := int64(dataBody["gender"].(float64))
  158. if gender <= 0{
  159. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "性别不能为空")
  160. return
  161. }
  162. birthday, _ := dataBody["birthday"].(string)
  163. if len(birthday) == 0 {
  164. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "生日格式不正确")
  165. return
  166. }
  167. timeLayout := "2006-01-02 15:04:05"
  168. theTime, err := utils.ParseTimeStringToTime(timeLayout, birthday+" 00:00:00")
  169. if err != nil {
  170. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "生日格式不正确")
  171. return
  172. }
  173. var staffbirthday = theTime.Unix()
  174. fmt.Println("生日",staffbirthday)
  175. userType := int64(dataBody["user_type"].(float64))
  176. if userType <= 0 {
  177. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "职称类型不正确")
  178. return
  179. }
  180. userTitle :=int64(dataBody["user_title"].(float64))
  181. if userTitle <= 0 {
  182. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "职称名称不正确")
  183. return
  184. }
  185. dochead := dataBody["dochead"].(string)
  186. if len(dochead) == 0 {
  187. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "头像不正确")
  188. return
  189. }
  190. content := dataBody["content"].(string)
  191. if len(content) == 0 {
  192. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "头像不正确")
  193. return
  194. }
  195. fmt.Println("姓名",staffname,"性别" ,gender,"生日",staffbirthday,"职称类型",userType,"职称名称",userTitle,"头像",dochead,"内容",content)
  196. StaffInfo := models.SgjUserStaffInfo{
  197. Name: staffname,
  198. Phone: phone,
  199. Birthday: staffbirthday,
  200. Gender:gender,
  201. Content:content,
  202. UserType: userType,
  203. UserTitle: userTitle,
  204. Dochead: dochead,
  205. Status: 1,
  206. UserOrgId:userOrgID,
  207. Mtime:time.Now().Unix(),
  208. }
  209. fmt.Println(StaffInfo)
  210. staff_service.UpdateStaffInfo(StaffInfo,userOrgID,id)
  211. this.ServeSuccessJSON(map[string]interface{}{
  212. "userStaffInfo":StaffInfo,
  213. })
  214. }
  215. func (this *StaffManage) DeleteStaffs() {
  216. adminUserInfo := this.GetAdminUserInfo()
  217. OrgID := adminUserInfo.CurrentOrgId
  218. dataBody := make(map[string]interface{}, 0)
  219. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  220. if err != nil {
  221. utils.ErrorLog(err.Error())
  222. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "参数错误")
  223. return
  224. }
  225. idsInters := dataBody["ids"].([]interface{})
  226. if len(idsInters) == 0 {
  227. if err != nil {
  228. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除会员失败:(没有选择会员)")
  229. return
  230. }
  231. }
  232. ids := make([]int64, 0)
  233. for _, idsInter := range idsInters {
  234. id := int64(idsInter.(float64))
  235. ids = append(ids, id)
  236. }
  237. err = staff_service.DeleteStaffs(OrgID, ids)
  238. fmt.Println("错误",err)
  239. if err != nil {
  240. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除失败:("+err.Error()+")")
  241. return
  242. }
  243. returnData := make(map[string]interface{}, 0)
  244. returnData["msg"] = "ok"
  245. this.ServeSuccessJSON(returnData)
  246. return
  247. }