123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364 |
- package service
- import (
- "fmt"
- "strconv"
- "time"
- "app.yhyue.com/moapp/jybase/common"
- "bp.jydev.jianyu360.cn/BaseService/userCenter/entity"
- . "bp.jydev.jianyu360.cn/BaseService/userCenter/identity"
- userCenter "bp.jydev.jianyu360.cn/BaseService/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,
- Referer: data.Referer,
- }
- //存在统一社会信用代码
- 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 identity := IdentityByEntId(entity.BaseMysql, data.EntId); identity != nil {
- info.EntAccountId = identity.EntAccountId
- }
- 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,
- }
- if identity := IdentityByEntId(entity.BaseMysql, data.EntId); identity != nil {
- info.EntAccountId = identity.EntAccountId
- }
- 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()
- }
- // 根据entid 获取员工 信息
- func (this *EntService) GetEntUserInfo(data *userCenter.EntUserReq) (*entity.User, string) {
- info := &entity.EntUserInfo{
- Mysql: entity.Mysql,
- EntUserId: data.EntUserId,
- EntId: data.EntId,
- }
- return info.GetEntUserInfo()
- }
- // 获取部门及子部门的员工列表
- func (this *EntService) GetEntUserList(data *userCenter.EntUserListReq) ([]*userCenter.EntUserListData, string) {
- info := &entity.EntUserList{
- Mysql: entity.Mysql,
- EntId: data.EntId,
- DeptId: data.DeptId,
- Name: data.Name,
- }
- return info.GetEntUserList()
- }
- // 判断是否是企业管理员
- func (this *EntService) CheckEntUserAdmin(data *userCenter.EntUserReq) (int64, string) {
- info := &entity.EntUserInfo{
- Mysql: entity.Mysql,
- EntUserId: data.EntUserId,
- EntId: data.EntId,
- }
- return info.CheckEntAdmin()
- }
|