123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437 |
- package admin_api_controllers
-
- import (
- "XT_Admin_Api/enums"
- "XT_Admin_Api/models"
- "XT_Admin_Api/models/admin_models"
- "XT_Admin_Api/service"
- "XT_Admin_Api/utils"
- "encoding/json"
- "fmt"
- "reflect"
- "time"
- )
-
- type SystemApiController struct {
- AdminBaseAPIAuthController
- }
-
- func (this *SystemApiController) GetUserList() {
- list, _ := service.GetAllAdmin()
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
-
- }
-
- func (this *SystemApiController) CreateAdminUser() {
- name := this.GetString("name")
- mobile := this.GetString("mobile")
- password := this.GetString("password")
- admin := &admin_models.AdminAccount{
- Account: mobile,
- Pwd: password,
- Name: name,
- Status: 1,
- IsSuperAdmin: 2,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- }
- admins, _ := service.FindUserInfoByAccount(mobile)
- if admins.ID > 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNameException)
- return
-
- }
-
- err := service.CreateAdmin(admin)
- if err == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "admin": admin,
- })
- }
- }
-
- func (this *SystemApiController) ModifyAdminUser() {
- id, _ := this.GetInt64("id")
- name := this.GetString("name")
- mobile := this.GetString("mobile")
- password := this.GetString("password")
- status, _ := this.GetInt64("status")
-
- admins, _ := service.FindAdminById(id)
-
- admin := &admin_models.AdminAccount{
- ID: admins.ID,
- Account: mobile,
- Pwd: password,
- Name: name,
- Status: status,
- IsSuperAdmin: 2,
- Ctime: admins.Ctime,
- Mtime: time.Now().Unix(),
- }
-
- if admins.Account != mobile {
- info, _ := service.FindUserInfoByAccount(mobile)
- if info.ID > 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNameException)
- return
-
- }
-
- }
-
- err := service.UpdateAdmin(admin)
- if err == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "admin": admin,
- })
- }
- }
-
- func (this *SystemApiController) DeleteAdminUser() {
- id, _ := this.GetInt64("id")
- err := service.DeleteAdmin(id)
- if err == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- }
- }
-
- func (this *SystemApiController) GetUserInitData() {
- org, err := service.FindAllOrg()
- if err == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "org": org,
- })
- }
- }
-
- func (this *SystemApiController) GetFollowOrg() {
- id, _ := this.GetInt64("admin_user_id")
- FollowOrgs, err := service.FindFollowOrg(id)
- unFollow, _ := service.FindUnFollowOrgByIds(id)
-
- fmt.Println(FollowOrgs)
- fmt.Println(unFollow)
-
- if err == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "follows": FollowOrgs,
- "unFollow": unFollow,
- })
- }
- }
-
- func (this *SystemApiController) GetAdminUserById() {
- id, _ := this.GetInt64("id")
- account, err := service.FindAdminById(id)
- if err == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "account": account,
- })
- }
- }
-
- func (this *SystemApiController) PostFollowInfo() {
- time := time.Now().Unix()
-
- var orgFollow []*models.OrgFollow
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if dataBody["Follow"] != nil && reflect.TypeOf(dataBody["Follow"]).String() == "[]interface {}" {
- thisFollow, _ := dataBody["Follow"].([]interface{})
- if len(thisFollow) > 0 {
- for _, item := range thisFollow {
- items := item.(map[string]interface{})
- if items["org_id"] == nil || reflect.TypeOf(items["org_id"]).String() != "float64" {
- utils.ErrorLog("org_id")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- org_id := int64(items["org_id"].(float64))
-
- if items["admin_user_id"] == nil || reflect.TypeOf(items["admin_user_id"]).String() != "float64" {
- utils.ErrorLog("admin_user_id")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- admin_user_id := int64(items["admin_user_id"].(float64))
- follow := &models.OrgFollow{
- Mtime: time,
- Status: 1,
- Ctime: time,
- OrgId: org_id,
- AdminUserId: admin_user_id,
- }
- orgFollow = append(orgFollow, follow)
- }
- }
- }
-
- //防止数据冗余,先查出之前被删的数据是否存在,存在则直接改变删除状态,不插入新数据
- for index, follow := range orgFollow {
- info, err := service.FindFollowRecordByID(follow)
-
- if err == nil { //存在,则修改删除状态
- orgFollow = append(orgFollow[:index], orgFollow[index+1:]...)
- if info.Status == 0 {
- follow := &models.OrgFollow{
- ID: info.ID,
- Mtime: info.Mtime,
- Status: 1,
- Ctime: info.Ctime,
- OrgId: info.OrgId,
- AdminUserId: info.AdminUserId,
- }
- service.UpdateFollow(follow)
- }
-
- }
- }
-
- if len(orgFollow) > 0 {
- errs := service.CreateFollowInfo(orgFollow)
- if errs == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "提交成功",
- })
-
- }
- } else {
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "提交成功",
- })
- }
-
- }
-
- func (this *SystemApiController) CancelFollowInfo() {
- time := time.Now().Unix()
-
- var orgFollow []*models.OrgFollow
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if dataBody["Follow"] != nil && reflect.TypeOf(dataBody["Follow"]).String() == "[]interface {}" {
- thisFollow, _ := dataBody["Follow"].([]interface{})
- if len(thisFollow) > 0 {
- for _, item := range thisFollow {
- items := item.(map[string]interface{})
- if items["org_id"] == nil || reflect.TypeOf(items["org_id"]).String() != "float64" {
- utils.ErrorLog("org_id")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- org_id := int64(items["org_id"].(float64))
-
- if items["follow_id"] == nil || reflect.TypeOf(items["follow_id"]).String() != "float64" {
- utils.ErrorLog("follow_id")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- follow_id := int64(items["follow_id"].(float64))
-
- if items["admin_user_id"] == nil || reflect.TypeOf(items["admin_user_id"]).String() != "float64" {
- utils.ErrorLog("admin_user_id")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- admin_user_id := int64(items["admin_user_id"].(float64))
- follow := &models.OrgFollow{
- ID: follow_id,
- Mtime: time,
- Status: 0,
- Ctime: time,
- OrgId: org_id,
- AdminUserId: admin_user_id,
- }
- orgFollow = append(orgFollow, follow)
- }
- }
- }
- for _, follow := range orgFollow {
- service.UpdateFollow(follow)
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "follow": orgFollow,
- })
-
- }
-
- func (this *SystemApiController) PostUnFollow() {
- org_id, _ := this.GetInt64("org_id")
- admin_user_id, _ := this.GetInt64("admin_user_id")
-
- info, _ := service.FindFollowInfoById(org_id, admin_user_id)
- follow := &models.OrgFollow{
- ID: info.ID,
- Mtime: time.Now().Unix(),
- Status: 0,
- Ctime: info.Ctime,
- OrgId: org_id,
- AdminUserId: info.AdminUserId,
- }
- err := service.UpdateFollow(follow)
- if err == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- }
-
- }
-
- func (this *SystemApiController) ModifyFollowInfo() {
- time := time.Now().Unix()
- var orgFollow []*models.OrgFollow
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if dataBody["Follow"] != nil && reflect.TypeOf(dataBody["Follow"]).String() == "[]interface {}" {
- thisFollow, _ := dataBody["Follow"].([]interface{})
- if len(thisFollow) > 0 {
- for _, item := range thisFollow {
- items := item.(map[string]interface{})
- if items["admin_user_id"] == nil || reflect.TypeOf(items["admin_user_id"]).String() != "float64" {
- utils.ErrorLog("admin_user_id")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- admin_user_id := int64(items["admin_user_id"].(float64))
-
- if items["org_id"] == nil || reflect.TypeOf(items["org_id"]).String() != "float64" {
- utils.ErrorLog("org_id")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- org_id := int64(items["org_id"].(float64))
-
- if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
- utils.ErrorLog("id")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- id := int64(items["id"].(float64))
-
- if id == 0 {
- follow := &models.OrgFollow{
- Mtime: time,
- Status: 1,
- Ctime: time,
- OrgId: org_id,
- AdminUserId: admin_user_id,
- }
- orgFollow = append(orgFollow, follow)
- }
- }
- }
- }
- //防止数据冗余,先查出之前被删的数据是否存在,存在则直接改变删除状态,不插入新数据
- for index, follow := range orgFollow {
- info, err := service.FindFollowRecordByID(follow)
-
- if err == nil { //存在,则修改删除状态
- orgFollow = append(orgFollow[:index], orgFollow[index+1:]...)
- if info.Status == 0 {
- follow := &models.OrgFollow{
- ID: info.ID,
- Mtime: info.Mtime,
- Status: 1,
- Ctime: info.Ctime,
- OrgId: info.OrgId,
- AdminUserId: info.AdminUserId,
- }
- service.UpdateFollow(follow)
- }
-
- }
- }
-
- if len(orgFollow) > 0 {
- errs := service.CreateFollowInfo(orgFollow)
- if errs == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "提交成功",
- })
-
- }
- } else {
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "提交成功",
- })
- }
-
- }
-
- func (this *SystemApiController) GetWaitFollowOrg() {
- admin_id, _ := this.GetInt64("admin_id", 0)
- keyword := this.GetString("keyword")
- page, _ := this.GetInt64("page", 0)
- limit, _ := this.GetInt64("limit", 0)
- if page <= 0 {
- page = 1
- }
- if limit <= 0 {
- limit = 7
- }
-
- list, err, total := service.GetAllWaitFollowOrgList(keyword, page, limit, admin_id)
- if err != nil {
-
- } else {
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "total": total,
- })
- }
-
- }
-
- func (this *SystemApiController) GetAllFollowOrg() {
- admin_id, _ := this.GetInt64("admin_id", 0)
- keyword := this.GetString("keyword")
- page, _ := this.GetInt64("page", 0)
- limit, _ := this.GetInt64("limit", 0)
- if page <= 0 {
- page = 1
- }
- if limit <= 0 {
- limit = 7
- }
-
- list, err, total := service.FindAllFollowOrg(keyword, page, limit, admin_id)
- fmt.Println(list)
- fmt.Println(err)
- fmt.Println(total)
-
- if err != nil {
-
- } else {
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "total": total,
- })
- }
-
- }
|