package staff import ( "SCRM/controllers" "SCRM/enums" "SCRM/models" "SCRM/service/staff_service" "SCRM/utils" "encoding/json" "fmt" "github.com/astaxie/beego" "time" ) func staffRouters() { beego.Router("/api/staff/addStaffInfo", &StaffManage{}, "Post:AddStaffInfo") beego.Router("/api/staff/getAllStaffInfo", &StaffManage{}, "Get:GetAllStaffInfo") beego.Router("/api/staff/EditStaffInfo", &StaffManage{}, "Post:EditStaffInfo") beego.Router("/api/staff/DeleteStaffs", &StaffManage{}, "Delete:DeleteStaffs") } type StaffManage struct { controllers.BaseAuthAPIController } func (this *StaffManage) AddStaffInfo() { adminUserInfo := this.GetAdminUserInfo() userOrgID := int64(adminUserInfo.CurrentOrgId) fmt.Println("机构ID", userOrgID) dataBody := make(map[string]interface{}, 0) err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody) fmt.Println("视频发布是什么呢", err) if err != nil { utils.ErrorLog(err.Error()) this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "参数错误") return } fmt.Println("hhhhh") staffname := dataBody["name"].(string) if len(staffname) == 0 { this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "姓名不能为空") return } phone := dataBody["phone"].(string) if len(phone) == 0 { this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "手机不能为空") return } gender := int64(dataBody["gender"].(float64)) if gender <= 0 { this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "性别不能为空") return } birthday, _ := dataBody["birthday"].(string) if len(birthday) == 0 { this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "生日格式不正确") return } timeLayout := "2006-01-02 15:04:05" theTime, err := utils.ParseTimeStringToTime(timeLayout, birthday+" 00:00:00") if err != nil { this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "生日格式不正确") return } var staffbirthday = theTime.Unix() fmt.Println("生日", staffbirthday) userType := int64(dataBody["user_type"].(float64)) if userType <= 0 { this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "职称类型不正确") return } userTitle := int64(dataBody["user_title"].(float64)) if userTitle <= 0 { this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "职称名称不正确") return } dochead := dataBody["dochead"].(string) if len(dochead) == 0 { this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "头像不正确") return } content := dataBody["content"].(string) if len(content) == 0 { this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "头像不正确") return } fmt.Println("姓名", staffname, "性别", gender, "生日", staffbirthday, "职称类型", userType, "职称名称", userTitle, "头像", dochead, "内容", content) StaffInfo := models.SgjUserStaffInfo{ Name: staffname, Phone: phone, Birthday: staffbirthday, Gender: gender, Content: content, UserType: userType, UserTitle: userTitle, Dochead: dochead, Status: 1, UserOrgId: userOrgID, Ctime: time.Now().Unix(), } err = staff_service.AddStaffInfo(StaffInfo) if err != nil { this.ServeFailJsonSend(enums.ErrorCodeDataException, "插入文章失败") return } this.ServeSuccessJSON(map[string]interface{}{ "staffInfo": StaffInfo, }) return } func (this *StaffManage) GetAllStaffInfo() { keyword := this.GetString("keyword") page, _ := this.GetInt64("page", 1) fmt.Println("页面", page) limit, _ := this.GetInt64("limit", 10) if page <= 0 { page = 1 } if limit <= 0 { limit = 10 } fmt.Println("限制", limit) fmt.Println("关键字", keyword, "limit", limit, "page", page) adminUserInfo := this.GetAdminUserInfo() userOrgID := int64(adminUserInfo.CurrentOrgId) userStaffInfo, total, err := staff_service.GetAllStaffInfo(userOrgID, page, limit, keyword) fmt.Println("内容", userStaffInfo, "total", total, "err", err) if err != nil { this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取文章分类列表失败") return } this.ServeSuccessJSON(map[string]interface{}{ "userStaffInfo": userStaffInfo, "total": total, }) } func (this *StaffManage) EditStaffInfo() { id, _ := this.GetInt64("id") fmt.Println("ID是多少?", id) adminUserInfo := this.GetAdminUserInfo() userOrgID := int64(adminUserInfo.CurrentOrgId) fmt.Println("机构ID", userOrgID) dataBody := make(map[string]interface{}, 0) err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody) fmt.Println("视频发布是什么呢", err) if err != nil { utils.ErrorLog(err.Error()) this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "参数错误") return } staffname := dataBody["name"].(string) fmt.Println("staffname", staffname) if len(staffname) == 0 { this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "姓名不能为空") return } phone := dataBody["phone"].(string) fmt.Println("phone", phone) if len(phone) == 0 { this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "手机不能为空") return } gender := int64(dataBody["gender"].(float64)) fmt.Println("gender", gender) if gender <= 0 { this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "性别不能为空") return } birthday, _ := dataBody["birthday"].(string) fmt.Println("birthday", birthday) if len(birthday) == 0 { this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "生日格式不正确") return } timeLayout := "2006-01-02 15:04:05" theTime, err := utils.ParseTimeStringToTime(timeLayout, birthday+" 00:00:00") if err != nil { this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "生日格式不正确") return } var staffbirthday = theTime.Unix() fmt.Println("生日", staffbirthday) userType := int64(dataBody["user_type"].(float64)) fmt.Println("userType", userType) if userType <= 0 { this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "职称类型不正确") return } userTitle := int64(dataBody["user_title"].(float64)) fmt.Println("userTitle", userTitle) if userTitle <= 0 { this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "职称名称不正确") return } dochead := dataBody["dochead"].(string) fmt.Println("dochead", dochead) if len(dochead) == 0 { this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "头像不正确") return } content := dataBody["content"].(string) fmt.Println("content", content) if len(content) == 0 { this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "头像不正确") return } fmt.Println("姓名", staffname, "性别", gender, "生日", staffbirthday, "职称类型", userType, "职称名称", userTitle, "头像", dochead, "内容", content) StaffInfo := models.SgjUserStaffInfo{ Name: staffname, Phone: phone, Birthday: staffbirthday, Gender: gender, Content: content, UserType: userType, UserTitle: userTitle, Dochead: dochead, Status: 1, UserOrgId: userOrgID, Mtime: time.Now().Unix(), } fmt.Println(StaffInfo) err = staff_service.UpdateStaffInfo(StaffInfo, userOrgID, id) fmt.Println("err", err) this.ServeSuccessJSON(map[string]interface{}{ "userStaffInfo": StaffInfo, }) } func (this *StaffManage) DeleteStaffs() { adminUserInfo := this.GetAdminUserInfo() OrgID := adminUserInfo.CurrentOrgId dataBody := make(map[string]interface{}, 0) err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody) if err != nil { utils.ErrorLog(err.Error()) this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "参数错误") return } idsInters := dataBody["ids"].([]interface{}) if len(idsInters) == 0 { if err != nil { this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除会员失败:(没有选择会员)") return } } ids := make([]int64, 0) for _, idsInter := range idsInters { id := int64(idsInter.(float64)) ids = append(ids, id) } err = staff_service.DeleteStaffs(OrgID, ids) fmt.Println("错误", err) if err != nil { this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除失败:("+err.Error()+")") return } returnData := make(map[string]interface{}, 0) returnData["msg"] = "ok" this.ServeSuccessJSON(returnData) return }