package logic import ( "encoding/json" "errors" "ik3cloud/app/common" "ik3cloud/app/config" "ik3cloud/app/lib/ik3cloud" "log" "time" ik3cloud2 "git.kumo.work/shama/service/ik3cloud" "git.kumo.work/shama/service/ik3cloud/constant" "git.kumo.work/shama/service/lib/bean" ) var StaffLogic = &staffLogic{} type staffLogic struct { } type staffItem struct { Id int64 `json:"FID"` // id Number *string `json:"FStaffNumber"` // 工号 Name *string `json:"FName"` // 姓名 Position *string `json:"FBaseProperty"` // 职位 Mobile *string `json:"FMobile"` // 手机号 Tel *string `json:"FTel"` // 账号 Status *string `json:"FForbidStatus"` // 状态 } // List @TITLE 员工列表 func (s *staffLogic) List(page bean.Page, search ik3cloud2.StaffSearch) (list []ik3cloud2.StaffItem, total int64, err error) { where := []map[string]interface{}{ { "FieldName": "FCreateOrgId.FNumber", "Compare": "67", "Value": config.Config.Ik3cloud.OrganizationNumber, "Left": "", "Right": "", "Logic": 0, }, } { // 搜索 // 状态 if search.Status > 0 { status := "B" if search.Status == 1 { status = "A" } where = append(where, map[string]interface{}{ "FieldName": "FForbidStatus", "Compare": "105", "Value": status, "Left": "", "Right": "", "Logic": 0, }) } // 姓名 if search.Name != "" { where = append(where, map[string]interface{}{ "FieldName": "FName", "Compare": "17", "Value": search.Name, "Left": "", "Right": "", "Logic": 0, }) } // 手机号 if search.Phone != "" { where = append(where, map[string]interface{}{ "FieldName": "FBaseProperty", "Compare": "17", "Value": search.Phone, "Left": "", "Right": "", "Logic": 0, }) } } raw, err := ik3cloud.Client.BillQuery(map[string]interface{}{ "FormId": constant.ActionStaff, "FieldKeys": "FName,FStaffNumber,FBaseProperty,FMobile,FTel,FForbidStatus", "FilterString": where, "StartRow": page.GetStart(), "Limit": page.GetLimit(), }) if err != nil { return } log.Println(string(raw)) var data []staffItem if err = json.Unmarshal(raw, &data); err != nil { return } for _, item := range data { status := "禁用" if common.PtrCmp(item.Status, common.Ptr("A")) { status = "启用" } list = append(list, ik3cloud2.StaffItem{ Id: item.Id, Number: item.Number, Name: item.Name, Position: item.Position, Mobile: item.Mobile, Tel: item.Tel, Status: &status, }) } return } // Add @TITLE 添加员工 func (s *staffLogic) Add(data ik3cloud2.ArgsStaffAdd) (entity ik3cloud2.Entity, err error) { return ik3cloud.Client.Save(constant.ActionStaff, nil, map[string]any{ "FCreateOrgId": map[string]any{ "FNumber": config.Config.Ik3cloud.OrganizationNumber, }, "FName": data.Name, "FStaffNumber": data.Number, "FUseOrgId": map[string]any{ "FNumber": config.Config.Ik3cloud.OrganizationNumber, }, "FMobile": data.Mobile, "FTel": data.Tel, "FEmail": data.Email, "FCreateSaler": false, "FCreateUser": false, "FCreateCashier": false, "FJoinDate": time.Now().Format("2006-01-02 15:04:05"), }) } // Edit @TITLE 员工编辑 func (s *staffLogic) Edit(staffId int64, data ik3cloud2.ArgsStaffAdd) error { if staffId == 0 { return errors.New("员工错误") } if _, err := ik3cloud.Client.Save(constant.ActionStaff, []string{"FStaffNumber", "FName", "FMobile", "FTel", "FEmail"}, map[string]any{ "FID": staffId, "FStaffNumber": data.Number, "FName": data.Name, "FMobile": data.Mobile, "FTel": data.Tel, "FEmail": data.Email, }); err != nil { return errors.New("编辑员工失败") } return nil } // Disable @TITLE 禁用账户 func (s *staffLogic) Disable(numbers []string, ids []int64) error { return ik3cloud.Client.Disable(constant.ActionStaff, numbers, ids) } // Enable @TITLE 启用账户 func (s *staffLogic) Enable(numbers []string, ids []int64) error { return ik3cloud.Client.Enable(constant.ActionStaff, numbers, ids) } // Delete @TITLE 删除 func (s *staffLogic) Delete(numbers []string, ids []int64) error { return ik3cloud.Client.Delete(constant.ActionStaff, numbers, ids) }