package service import ( "fmt" "strconv" "time" "app.yhyue.com/moapp/jybase/common" "userCenter/entity" userCenter "userCenter/rpc/usercenter" ) type EntService struct { Url string } //创建企业用户 /* 根据统一社会信用代码判断 查询是否已存在该企业 若无该企业 创建新企业 存在该企业 老企业更新 */ const ( EXAMINEINGMSG = "该机构正在审核中,无法提交认证申请" APPROVEDMSG = "该机构已完成认证,无法提交认证申请" OKMSG = "提交成功" ) //return error_code error_msg status entid func (this *EntService) CreateEnt(data *userCenter.EntAuthReq) (int64, string, int64, int64) { if data.Name == "" || data.Phone == "" || data.CreditCode == "" { return entity.ErrorCode, "参数异常", entity.ErrorCode, 0 } authType, _ := strconv.Atoi(data.ComPanyType) entinfo := &entity.EntInfo{ Name: data.Name, //企业名称 Phone: data.Phone, //注册人手机号 Code: data.CreditCode, //统一社会信用代码 Createtime: time.Now().Format("2006-01-02 15:04:05"), Organization_type: data.OrganizationType, //机构类型 1投标企业 2招标采购单位 3厂商 4招标代理机构 5经销商 6服务提供商 7其他 Auth_type: authType, // 认证类型 1-事业单位 0-企业 License: data.Business, //营业执照 Official_letter: data.OfficialLetter, //认证公函 Linkman_phone: data.AuthPhone, //联系人手机号 Linkman_name: data.AuthName, //联系人姓名 AreaNumber: data.AreaNumber, // Frozen_status: 1, Auth_status: 0, Audit_status: 1, Mysql: entity.Mysql, } //存在统一社会信用代码 r := entity.Mysql.SelectBySql(`select id,audit_status,auth_status,name,phone from entniche_info where code =?`, data.CreditCode) if r != nil && len(*r) > 0 { //记录所有的统一社会信用代码相同的企业 sameCode := map[int64]interface{}{} for _, v := range *r { id, _ := v["id"].(int64) audit_status, _ := v["audit_status"].(int64) auth_status, _ := v["auth_status"].(int64) ent_name, _ := v["name"].(string) // phone, _ := v["phone"].(string) if audit_status == 1 { //根据统一社会信用代码查看该企业正在审核中 return entity.ErrorCode, EXAMINEINGMSG, entity.ErrorCode, 0 } if auth_status == 1 { sameCode[id] = map[string]interface{}{ "name": ent_name, "authStatus": auth_status, "auditStatus": audit_status, } } } if len(sameCode) > 0 { entids := "" i := 0 for k, _ := range sameCode { //判断企业是否已认证 entids += fmt.Sprint(k) if i != len(sameCode)-1 { entids += "," } i++ } //查看该用户是否在已认证的企业机构下,如果在机构下则可以重新发起认证(编辑)如果不在则提示已被认证 list := entity.Mysql.SelectBySql(` SELECT a.ent_id,b.name FROM entniche_user a inner join entniche_info b on a.ent_id = b.id WHERE a.ent_id IN(?) AND a.phone = ?`, entids, entinfo.Phone) if len(*list) <= 0 { return entity.ErrorCode, APPROVEDMSG, entity.ErrorCode, 0 } //log.Println(fmt.Printf("查询到该统一社会信用代码存在%v个认证企业中,默认获取第一个企业进行认证,该企业企业id为%v", len(*list), (*list)[0]["ent_id"])) entinfo.Id = common.IntAll((*list)[0]["ent_id"]) if entinfo.Update() { return entity.SuccessCode, OKMSG, 1, int64(entinfo.Id) } } } //不存在统一社会信用代码 r = entity.Mysql.SelectBySql(`select id,audit_status,auth_status,name,phone from entniche_info where id =?`, data.EntId) if r != nil && len(*r) > 0 { for _, v := range *r { id, _ := v["id"].(int64) audit_status, _ := v["audit_status"].(int64) auth_status, _ := v["auth_status"].(int64) ent_name, _ := v["name"].(string) // phone, _ := v["phone"].(string) //该企业下员工 可以重新认证 if ent_name != entinfo.Name { //企业名称不同 创建全新企业 if ok, entid := entinfo.Add(); ok { return entity.SuccessCode, OKMSG, 1, entid } } if audit_status == 1 { //审核中 return entity.ErrorCode, EXAMINEINGMSG, entity.ErrorCode, 0 } if auth_status == 1 { //已认证 list := entity.Mysql.SelectBySql(`select * from entniche_user where ent_id =? and phone =?`, id, entinfo.Phone) if len(*list) <= 0 { return entity.ErrorCode, APPROVEDMSG, entity.ErrorCode, 0 } } entinfo.Id = int(id) // entinfo.Phone = phone //更换注册人手机号为管理员手机号 if entinfo.Update() { return entity.SuccessCode, OKMSG, 1, int64(entinfo.Id) } } } if ok, id := entinfo.Add(); ok { return entity.SuccessCode, OKMSG, 1, id } return entity.ErrorCode, "", entity.ErrorCode, 0 } //机构审核 func (this *EntService) Examinet(data *userCenter.ExamineReq) (int64, string, int64) { if data.EntId == 0 || data.ExamineId == "" { return -1, "参数异常", 0 } info := &entity.Examine{ ExamineId: data.ExamineId, EntId: data.EntId, Reason: data.Reason, AuthType: data.AuthType, AuditUser: data.AuditUser, Mysql: entity.Mysql, ResourceLib: entity.ResourceLib, } if info.EntExamine() { return 1, "", 0 } //修改状态 return -1, "修改失败", -1 } //企业列表 func (this *EntService) EntList(data *userCenter.EntListReq) (int64, string, *userCenter.EntData) { info := &entity.List{ Name: data.Name, AuthStatus: data.AuthStatus, PageNum: data.PageNum, PageSize: data.PageSize, CreditCode: data.CreditCode, CreateStartTime: data.CreateStartTime, CreateEndTime: data.CreateEndTime, ValidStartTime: data.ValidStartTime, ValidEndTime: data.ValidEndTime, FrozenStatus: data.FrozenStatus, RegPhone: data.RegPhone, AuthPhone: data.AuthPhone, Mysql: entity.Mysql, } r, count := info.List() pageSize := common.If(data.PageSize != "", data.PageSize, "10").(string) i_pageSize, _ := strconv.Atoi(pageSize) list := []*userCenter.EntList{} for _, v := range *r { list = append(list, &userCenter.EntList{ Id: common.Int64All(v["id"]), //机构id ComPanyType: common.Int64All(v["comPanyType"]), // 机构性质 1企业 2党政机关事业单位及其他 Name: common.ObjToString(v["name"]), //机构名称 OrganizationType: common.ObjToString(v["organizationType"]), //机构类型 1企业 2党政机关事业单位及其他 Createtime: common.ObjToString(v["createTime"]), //创建时间 ValidTime: common.ObjToString(v["validTime"]), //有效截至日期 AuthStatus: common.Int64All(v["authStatus"]), //认证状态 FrozenStatus: common.Int64All(v["frozenStatus"]), }) } return 0, "", &userCenter.EntData{ Count: count, PageSize: int64(i_pageSize), List: list, } } //审核列表 func (this *EntService) ExamineList(data *userCenter.ExamineListReq) (int64, string, *userCenter.ExamineListData) { info := &entity.ExamineList{ Name: data.Name, AuthPhone: data.AuthPhone, RegPhone: data.RegPhone, AuthType: data.AuthType, //审核状态 1:待审核 2:审核通过 3:审核不通过 AuthStartTime: data.AuthStartTime, //申请开始时间 AuthEndTime: data.AuthEndTime, //申请结束时间 PageNum: data.PageNum, //页码 PageSize: data.PageSize, //每页展示条数 Mysql: entity.Mysql, } r, count := info.List() pageSize := common.If(data.PageSize != "", data.PageSize, "10").(string) i_pageSize, _ := strconv.Atoi(pageSize) list := []*userCenter.ExamineList{} for _, v := range *r { list = append(list, &userCenter.ExamineList{ Id: common.Int64All(v["id"]), EntId: common.Int64All(v["entId"]), ComPanyType: common.Int64All(v["comPanyType"]), // 机构性质 1企业 2党政机关事业单位及其他 Name: common.ObjToString(v["name"]), //机构名称 CreditCode: common.ObjToString(v["creditCode"]), //统一社会信用代码 AuthPhone: common.ObjToString(v["authPhone"]), //联系人手机号 ApplyTime: common.ObjToString(v["authTime"]), //申请时间戳 AuthType: common.Int64All(v["authStatus"]), //审核状态 RegPhone: common.ObjToString(v["regPhone"]), }) } return 0, "", &userCenter.ExamineListData{ Count: count, PageSize: int64(i_pageSize), List: list, } } func (this *EntService) CheckEnt(data *userCenter.CheckEntReq) (int64, int64, string, int64) { info := &entity.CheckEnt{ EntId: data.EntId, Mysql: entity.Mysql, } authStatus, frozenStatus, msg := info.Check() return authStatus, frozenStatus, msg, common.Int64All(common.If(msg == "", entity.SuccessCode, entity.ErrorCode)) } //企业信息 func (this *EntService) Info(data *userCenter.CheckEntReq) (int64, string, *userCenter.EntInfoData) { info := &entity.CheckEnt{ EntId: data.EntId, Mysql: entity.Mysql, Url: this.Url, } rdata := info.Info() entInfoData := &userCenter.EntInfoData{ Name: rdata.Name, OrganizationType: rdata.OrganizationType, CreditCode: rdata.CreditCode, CompanyType: rdata.CompanyType, AreaNumber: rdata.AreaNumber, Business: rdata.Business, OfficialLetter: rdata.OfficialLetter, AuthStartTime: rdata.AuthStartTime, AuthEndTime: rdata.AuthEndTime, ForzenStatus: rdata.ForzenStatus, AuthState: rdata.AuthState, ContactPerson: rdata.ContactPerson, ContactPhone: rdata.ContactPhone, AuthType: rdata.AuthType, CreateTime: rdata.CreateTime, AuthReason: rdata.AuthReason, } return 0, "", entInfoData } func (this *EntService) UpdateEnt(data *userCenter.EntUpdateReq) (int64, string, int64) { info := &entity.UpdateEnt{ EntId: data.EntId, UpdateType: data.UpdateType, Mysql: entity.Mysql, ResourceLib: entity.ResourceLib, } status, msg := info.UpdateEnt() return 0, msg, status } func (this *EntService) ExamineInfo(data *userCenter.CheckExamineReq) (int64, string, *userCenter.EntInfoData) { info := &entity.ExamineInfo{ ExamineId: data.ExamineId, Mysql: entity.Mysql, } rdata := info.Info() entInfoData := &userCenter.EntInfoData{ Name: rdata.Name, OrganizationType: rdata.OrganizationType, CreditCode: rdata.CreditCode, CompanyType: rdata.CompanyType, AreaNumber: rdata.AreaNumber, Business: rdata.Business, OfficialLetter: rdata.OfficialLetter, AuthState: rdata.AuthState, ContactPerson: rdata.ContactPerson, ContactPhone: rdata.ContactPhone, RegPhone: rdata.RegPhone, AuthTime: rdata.AuthTime, AuthReason: rdata.AuthReason, AuditUser: rdata.AuditUser, AuditTime: rdata.AuditTime, } return 0, "", entInfoData } func (this *EntService) GetStatusByCode(data *userCenter.GetStatusByCodeReq) (int, bool, string) { info := &entity.GetStatusByCodeStruct{ Mysql: entity.Mysql, Code: data.Code, Phone: data.Phone, } return info.GetStatusByCode() }
package service import ( "database/sql" "time" "userCenter/entity" . "userCenter/rpc/usercenter" ) func UserAdd(this *UserAddReq) *UserAddResp { userId := entity.BaseMysql.Insert(entity.UserTable, map[string]interface{}{ "appid": this.Appid, "phone": this.Phone, "nickname": this.Nickname, "headimg": this.Headimg, "company": this.Company, "position": this.Position, "password": this.Password, "s_openid": this.SOpenid, "a_openid": this.AOpenid, "unionid": this.Unionid, "create_time": time.Now().Format("2006-01-02 15:04:05"), }) status, msg := 0, "" if userId > 0 { status = 1 } else { msg = "新增用户失败" } return &UserAddResp{ ErrorCode: entity.SuccessCode, ErrorMsg: msg, Data: &UserAdds{Status: int64(status), Id: userId}, } } func UserUpdate(this *UserIdReq) *ExamineResp { ok := UserUpdates(this) status, msg := 0, "" if ok { status = 1 } else { msg = "更新用户失败" } return &ExamineResp{ ErrorCode: entity.SuccessCode, ErrorMsg: msg, Data: &ExamineData{Status: int64(status)}, } } func UserDel(this *UserIdReq) *ExamineResp { ok := UserDels(this) status, msg := 0, "" if ok { status = 1 } else { msg = "删除用户失败" } return &ExamineResp{ ErrorCode: entity.SuccessCode, ErrorMsg: msg, Data: &ExamineData{Status: int64(status)}, } } func UserUpdates(this *UserIdReq) bool { ok := false flag := entity.BaseMysql.ExecTx("", func(tx *sql.Tx) bool { set := map[string]interface{}{} if this.Phone != "" { set["phone"] = this.Phone } else { set["phone"] = "" } if this.Nickname != "" { set["nickname"] = this.Nickname } else { set["nickname"] = "" } if this.Headimg != "" { set["headimg"] = this.Headimg } else { set["headimg"] = "" } if this.Company != "" { set["company"] = this.Company } else { set["company"] = "" } if this.Position != "" { set["position"] = this.Position } else { set["position"] = "" } if this.Password != "" { set["password"] = this.Password } else { set["password"] = "" } if this.AOpenid != "" { set["a_openid"] = this.AOpenid } else { set["a_openid"] = "" } if this.SOpenid != "" { set["s_openid"] = this.SOpenid } else { set["s_openid"] = "" } if this.Unionid != "" { set["unionid"] = this.Unionid } else { set["unionid"] = "" } ok1 := entity.BaseMysql.UpdateByTx(tx, entity.UserTable, map[string]interface{}{"id": this.Id}, set) snapshot := entity.BaseMysql.InsertByTx(tx, entity.UserSnapshotTable, map[string]interface{}{ "appid": this.Appid, "user_id": this.Id, "phone": this.Phone, "nickname": this.Nickname, "headimg": this.Headimg, "company": this.Company, "position": this.Position, "password": this.Password, "s_openid": this.SOpenid, "a_openid": this.AOpenid, "unionid": this.Unionid, "create_time": time.Now().Format("2006-01-02 15:04:05"), }) return ok1 && snapshot > 0 }) if flag { ok = true } return ok } func UserDels(this *UserIdReq) bool { ok := false userData := entity.BaseMysql.FindOne(entity.UserTable, map[string]interface{}{"id": this.Id}, "", "") if userData != nil && len(*userData) > 0 { flag := entity.BaseMysql.ExecTx("", func(tx *sql.Tx) bool { thisdata := *userData ok1 := entity.BaseMysql.DeleteByTx(tx, entity.UserTable, map[string]interface{}{"id": this.Id}) snapshot := entity.BaseMysql.InsertByTx(tx, entity.UserSnapshotTable, map[string]interface{}{ "appid": thisdata["appid"], "user_id": this.Id, "phone": thisdata["phone"], "nickname": thisdata["nickname"], "headimg": thisdata["headimg"], "company": thisdata["company"], "position": thisdata["position"], "password": thisdata["password"], "s_openid": thisdata["s_openid"], "a_openid": thisdata["a_openid"], "unionid": thisdata["unionid"], "create_time": time.Now().Format("2006-01-02 15:04:05"), }) return ok1 && snapshot > 0 }) if flag { ok = true } } return ok }
package service import ( MC "app.yhyue.com/moapp/jybase/common" "app.yhyue.com/moapp/jybase/redis" "encoding/json" "errors" "fmt" "github.com/zeromicro/go-zero/core/logx" "math/rand" "strings" "time" "userCenter/entity" "userCenter/rpc/pb" . "userCenter/rpc/usercenter" ) //工作桌面--菜单当前选择模式--全部:all/可用:usable //工作桌面--常用功能更新 //工作桌面--常用功能列表 func RenewWorkDesktopMenuModeOrCommonly(in *WorkDesktopComprehensiveReq) (r *WorkDesktopComprehensiveResp) { r = &WorkDesktopComprehensiveResp{} switch in.ActionMode { case "commonlyRenew": //常用功能更新 //in.MenuIds 为空;删除 if in.MenuIds == "" { count := entity.BaseMysql.CountBySql(`SELECT COUNT(id) FROM `+entity.WorkCommonly+` WHERE userid = ? AND appid = ? AND platform = ? AND field = ?`, in.UserId, in.AppId, in.Platform, in.ActionMode) if count > 0 { if count := entity.BaseMysql.UpdateOrDeleteBySql(`DELETE FROM `+entity.WorkCommonly+` WHERE userid = ? AND appid = ? AND platform = ? AND field = ?`, in.UserId, in.AppId, in.Platform, in.ActionMode); count <= 0 { r.ErrorCode = -1 r.ErrorMsg = "常用功能-清空常用功能异常" } } } else { //in.MenuIds 不为空:更新 if b, m := entity.CommonlyUpdate(in); !b { r.ErrorCode = -1 r.ErrorMsg = m } } case "commonlyList": //查询常用功能列表 in.ActionMode = "commonlyRenew" existingData := entity.BaseMysql.SelectBySql(`SELECT value FROM `+entity.WorkCommonly+` WHERE userid = ? AND appid = ? AND field = ? AND platform = ? ORDER BY id DESC `, in.UserId, in.AppId, in.ActionMode, in.Platform) if existingData != nil && len(*existingData) > 0 { eData := (*existingData)[0] if MC.ObjToString(eData["value"]) != "" { var ( params []string pIds []interface{} ) for _, pv := range strings.Split(MC.ObjToString(eData["value"]), ",") { params = append(params, "?") pIds = append(pIds, pv) } menuData := entity.BaseMysql.SelectBySql(fmt.Sprintf(`SELECT * from %s WHERE id IN (%s) AND status = 0`, entity.WorkMenu, strings.Join(params, ",")), pIds...) if menuData != nil && len(*menuData) > 0 { var menuList = []*pb.ThreeLevelMenu{} var m = &entity.WorkDesktopMenu{ MenuTree: nil, UserId: in.UserId, AppId: in.AppId, TimeOut: int(in.RedisOutTime), BigMemberOff: in.BigMemberOff, } for _, mv := range *menuData { //0:默认展示;1:需验证权限,有权限展示;2:需验证权限,无权限也可展示(可用服务无权限不展示) usable := m.VerifyPermissions(MC.ObjToString(mv["powerids"])) menu := &pb.ThreeLevelMenu{ Name: MC.ObjToString(mv["name"]), Icon: MC.ObjToString(mv["icon"]), AppType: MC.ObjToString(mv["apptype"]), Usable: MC.If(MC.ObjToString(mv["powerids"]) != "", usable && MC.IntAll(mv["checkcode"]) == 1, true).(bool), OpenType: MC.ObjToString(mv["opentype"]), } switch in.Platform { case "WX": menu.Url = MC.ObjToString(mv["wxurl"]) case "APP": menu.Url = MC.ObjToString(mv["appurl"]) default: menu.Url = MC.ObjToString(mv["pcurl"]) } if additionalInfo := MC.ObjToString(mv["additionalinfo"]); additionalInfo != "" { additional := pb.TipInfo{} if json.Unmarshal([]byte(additionalInfo), &additional) == nil { menu.TipInfo = &additional } } menuList = append(menuList, menu) } r.Data = menuList } } } case "menuMode": //菜单模式更新 if in.MenuMode == "" || (in.MenuMode != "usable" && in.MenuMode != "all") { r.ErrorCode = -1 r.ErrorMsg = "菜单模式-参数异常" } else { menuModes := entity.BaseMysql.SelectBySql(`SELECT id,value FROM `+entity.WorkCommonly+` WHERE appid=? AND userid=? AND field = ? AND platform = ? LIMIT 1`, in.AppId, in.UserId, in.ActionMode, in.Platform) if menuModes != nil && len(*menuModes) > 0 { menuMode := (*menuModes)[0] if MC.ObjToString(menuMode["value"]) != in.MenuMode { if entity.BaseMysql.UpdateOrDeleteBySql(`UPDATE `+entity.WorkCommonly+` SET value = ? WHERE id = ?`, in.MenuMode, MC.IntAll(menuMode["id"])) < 0 { r.ErrorCode = -1 r.ErrorMsg = "菜单模式-更新异常" } } } else { if entity.BaseMysql.Insert(entity.WorkCommonly, map[string]interface{}{ "appid": in.AppId, "userid": in.UserId, "field": in.ActionMode, "platform": in.Platform, "value": in.MenuMode, }) < 0 { r.ErrorCode = -1 r.ErrorMsg = "菜单模式-插入异常" } } } } return } // func GetWorkDesktopMenuMode(in *WorkDesktopMenuInfoReq) (str string, err error) { if in.UserId == "" { return "", fmt.Errorf("参数异常") } str = "all" menuModes := entity.BaseMysql.SelectBySql(`SELECT value FROM `+entity.WorkCommonly+` WHERE appid=? AND userid=? AND field = 'menuMode' AND platform = ? LIMIT 1`, in.AppId, in.UserId, in.Platform) if menuModes != nil && len(*menuModes) > 0 { menuMode := (*menuModes)[0] if MC.ObjToString(menuMode["value"]) != "" { str = MC.ObjToString(menuMode["value"]) } } return } //获取工作桌面菜单树 func GetWordDesktopMenuTree(in *WorkDesktopMenuInfoReq) ([]*pb.MenuList, error) { t1 := time.Now() //redis缓存 var menuList []*pb.MenuList RedisMenuKey := fmt.Sprintf(entity.RedisMenuKey, in.AppId, in.Platform, in.UserId) menuBytes, err := redis.GetBytes(entity.RedisCode, RedisMenuKey) if err == nil && len(*menuBytes) > 0 { if json.Unmarshal(*menuBytes, &menuList) == nil { return menuList, nil } } //tidb数据 menuData := entity.BaseMysql.SelectBySql(`SELECT * FROM `+entity.WorkMenu+` WHERE status=0 AND appid=? ORDER BY id ASC`, in.AppId) if menuData == nil || len(*menuData) == 0 { return nil, errors.New("查询数据异常") } wdm := &entity.WorkDesktopMenu{ MenuTree: []*entity.JYMenu{}, UserId: in.UserId, AppId: in.AppId, TimeOut: int(in.RedisOutTime), BigMemberOff: in.BigMemberOff, } for _, v := range *menuData { menu := &entity.JYMenu{ Id: MC.IntAll(v["id"]), Name: MC.ObjToString(v["name"]), OrderId: MC.IntAll(v["orderid"]), ParentId: MC.IntAll(v["parentid"]), PowerIds: MC.ObjToString(v["powerids"]), CheckCode: MC.IntAll(v["checkcode"]), Icon: MC.ObjToString(v["icon"]), AppType: MC.ObjToString(v["apptype"]), OpenType: MC.ObjToString(v["opentype"]), } switch in.Platform { case "WX": menu.Url = MC.ObjToString(v["wxurl"]) case "APP": menu.Url = MC.ObjToString(v["appurl"]) default: menu.Url = MC.ObjToString(v["pcurl"]) } if additionalInfo := MC.ObjToString(v["additionalinfo"]); additionalInfo != "" { additional := entity.Additional{} if json.Unmarshal([]byte(additionalInfo), &additional) == nil { menu.AdditionalInfo = additional } } if menu.Id > 0 { wdm.MenuTree = append(wdm.MenuTree, menu) } } logx.Info("数据长度:", len(wdm.MenuTree), "-- 查询菜单数据耗时:", time.Since(t1)) //jyMenu := wdm.WorkMenuTree(0) wdm.MenuTree = wdm.WorkMenuTree(0) logx.Info("菜单树生成耗时:", time.Since(t1)) menuList, err = wdm.WorkMenuFormat() logx.Info("菜单格式化耗时:", time.Since(t1)) if err == nil && len(menuList) > 0 { if menuBytes, err := json.Marshal(menuList); err == nil { redisOutTime := int(in.RedisOutTime) + rand.Intn(60*60) if redis.PutBytes(entity.RedisCode, RedisMenuKey, &menuBytes, redisOutTime) != nil { logx.Info("工作桌面菜单 redis缓存异常") } } else { logx.Info("菜单数据序列化异常") } } logx.Info("整体耗时:", time.Since(t1)) return menuList, err }