123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- 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")
- }
-
- 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: userType,
- 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,
- })
- }
|