123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282 |
- package staff
-
- import (
- "github.com/astaxie/beego"
- "SCRM/controllers"
- "encoding/json"
- "fmt"
- "SCRM/utils"
- "SCRM/enums"
- "SCRM/models"
- "SCRM/service/staff_service"
- "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)
- 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,
- Mtime:time.Now().Unix(),
- }
- fmt.Println(StaffInfo)
- staff_service.UpdateStaffInfo(StaffInfo,userOrgID,id)
- 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
- }
|