package entity import ( "context" "database/sql" "fmt" "log" "strconv" "strings" "time" "app.yhyue.com/moapp/jybase/common" "app.yhyue.com/moapp/jybase/mongodb" "app.yhyue.com/moapp/jybase/mysql" resourcepb "bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/pb" "bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/resource" usercenterclient "bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/usercenter" "github.com/zeromicro/go-zero/core/logx" ) var VarEntInfo = &EntInfo{} var UserCenterRpc usercenterclient.UserCenter type Competitor struct { Name string } type Service struct { Name string } type EntInfo struct { Id int //企业id Name string //企业名 Phone string //手机号 Model int //1-统一订阅,2-个人订阅 Status int //0:未生效,1:已生效,-1:已到期 Quota int //限额人数 Startdate int //开始时间 Enddate int //结束时间 Createtime string //创建时间 Mail string //邮箱 Marketarea string Industryclass string //行业分类 Admin string //管理员姓名-只有商机洞察中有,可能没什么用 Code string //统一社会信用代码 License string //营业执照 Legal_name string //法人姓名 Legal_idcard string //身份证号 Legal_idcard_front string //身份证前面 Legal_idcard_after string //身份证后面 Auth_status int //-1-未通过 0-未认证 1-已认证 Auth_reason string //审核不通过的原因说明 Auth_time string //提交时间 Audit_time string //审核时间 User_id int Competitors []*Competitor //竞争对手 Services []*Service //产品服务 Auth_type int //认证类型 1-事业单位 0=企业 Legal_mancard string //法人证 IsNew int //1新商机管理0老商机管理 Frozen_status int //是否冻结 1正常 0冻结 Auth_startTime string //认证通过开始时间 Auth_endTime string //认证通过结束时间 Audit_status int //审核状态 1:待审核 2:审核通过 3:审核不通过 Linkman_phone string //联系人手机号 Linkman_name string //联系人姓名 Organization_type string //机构类型 1投标企业 2招标采购单位 3厂商 4招标代理机构 5经销商 6服务提供商 7其他 Official_letter string //认证公函 AreaNumber string //行政区号 Mysql *mysql.Mysql } const ( Dataexport_order = "dataexport_order" Entniche_department = "entniche_department" Entniche_department_user = "entniche_department_user" Entniche_department_parent = "entniche_department_parent" Entniche_info = "entniche_info" Entniche_log = "entniche_log" Entniche_role = "entniche_role" Entniche_user = "entniche_user" Entniche_user_role = "entniche_user_role" Entniche_competitor = "entniche_competitor" Entniche_service = "entniche_service" Entniche_user_rule = "entniche_user_rule" Entniche_distribute = "entniche_distribute" //分发规则表(mongo) Entniche_rule = "entniche_rule" //订阅表(mongo) Entniche_delete = "entniche_delete" Ent_bank = "ent_bank" Auth_record = "auth_record" //认证记录表 //角色 Role_admin_system = 1 //系统管理员 Role_admin_department = 2 //部门管理员 // Entniche_customer = "entniche_customer" Entniche_user_customer = "entniche_user_customer" Entniche_customer_contact = "entniche_customer_contact" Entniche_customer_return = "entniche_customer_return" Entniche_project = "entniche_project" Entniche_project_track = "entniche_project_track" Entniche_entmodel = "entniche_entmodel" Entniche_follow = "entniche_follow" Admin_name = "我" Entnice_life_cycle = "entnice_life_cycle" Bdcollection_entniche = "bdcollection_entniche" Bdlabel_entniche = "bdlabel_entniche" Date_Full_Layout = "2006-01-02 15:04:05" Date_Short_Layout = "2006-01-02" //信息发布产品code GOODSCODE_XXFB = "xxfb_gyxx" ) //创建企业 func (this *EntInfo) Add() (bool, int64) { m := map[string]interface{}{ "status": 0, "auth_status": this.Auth_status, "audit_status": this.Audit_status, } //不能为空 if this.Name != "" { m["name"] = this.Name } if this.Phone != "" { m["phone"] = this.Phone } if this.Createtime != "" { m["createtime"] = this.Createtime } if this.Admin != "" { m["admin"] = this.Admin } if this.Code != "" { m["code"] = this.Code } if this.License != "" { m["license"] = this.License } if this.Linkman_name != "" { m["linkman_name"] = this.Linkman_name } if this.Linkman_phone != "" { m["linkman_phone"] = this.Linkman_phone } if this.Organization_type != "" { m["organization_type"] = this.Organization_type } if this.Official_letter != "" { m["official_letter"] = this.Official_letter } if this.AreaNumber != "" { m["area_number"] = this.AreaNumber } if this.Auth_type >= 0 { m["auth_type"] = this.Auth_type } return this.Mysql.ExecTx("创建企业", func(tx *sql.Tx) bool { this.Id = int(this.Mysql.InsertByTx(tx, Entniche_info, m)) // var ok_2 int64 if len(this.Competitors) > 0 { array := []interface{}{} for _, v := range this.Competitors { array = append(array, this.Id, v.Name) } _, ok_2 = this.Mysql.InsertBatchByTx(tx, Entniche_competitor, []string{"ent_id", "name"}, array) } // var ok_3 int64 if len(this.Services) > 0 { array := []interface{}{} for _, v := range this.Services { array = append(array, this.Id, v.Name) } _, ok_3 = this.Mysql.InsertBatchByTx(tx, Entniche_service, []string{"ent_id", "name"}, array) } deptId := this.Mysql.InsertByTx(tx, Entniche_department, map[string]interface{}{ "pid": 0, "name": this.Name, "ent_id": this.Id, "subdis": 1, "nodiff": 0, "createtime": this.Createtime, "timestamp": this.Createtime, }) this.User_id = int(this.Mysql.InsertByTx(tx, Entniche_user, map[string]interface{}{ "name": Admin_name, "phone": this.Phone, "ent_id": this.Id, "createtime": this.Createtime, "timestamp": this.Createtime, })) deptUser := this.Mysql.InsertByTx(tx, Entniche_department_user, map[string]interface{}{ "dept_id": deptId, "user_id": this.User_id, }) userRole := this.Mysql.InsertByTx(tx, Entniche_user_role, map[string]interface{}{ "user_id": this.User_id, "role_id": Role_admin_system, }) AuthRecordId := this.Mysql.InsertByTx(tx, Auth_record, map[string]interface{}{ "creditCode": this.Code, "name": this.Name, "comPanyType": this.Auth_type, "areaNumber": this.AreaNumber, "business": this.License, "officialLetter": this.Official_letter, "authName": this.Linkman_name, "authPhone": this.Linkman_phone, "authReason": "", "authTime": time.Now().Format(Date_Full_Layout), //提交时间 "regPhone": this.Phone, "entId": this.Id, "organizationType": this.Organization_type, "authStatus": 1, }) if this.Id > 0 && ok_2 > -1 && ok_3 > -1 && deptId > 0 && this.User_id > 0 && deptUser > -1 && userRole > -1 && AuthRecordId > 0 { rpc := JyUser{} respData := Resp{ Fool: false, } rpc.AddUserInfo(&CompletionUserInfo{ IsEnt: true, EntName: this.Name, Phone: this.Phone, EntId: this.Id, Mail: this.Mail, }, &respData) return respData.Fool } else { return false } }), int64(this.Id) } //修改企业信息 func (this *EntInfo) Update() bool { m := map[string]interface{}{ "auth_status": this.Auth_status, "audit_status": this.Audit_status, } if this.Linkman_name != "" { m["linkman_name"] = this.Linkman_name } if this.Linkman_phone != "" { m["linkman_phone"] = this.Linkman_phone } if this.License != "" { m["license"] = this.License } if this.Organization_type != "" { m["organization_type"] = this.Organization_type } if this.Official_letter != "" { m["official_letter"] = this.Official_letter } if this.AreaNumber != "" { m["area_number"] = this.AreaNumber } if this.Auth_type >= 0 { m["auth_type"] = this.Auth_type } if this.Code != "" { m["code"] = this.Code } if this.Name != "" { m["name"] = this.Name } return this.Mysql.ExecTx("更新企业", func(tx *sql.Tx) bool { ok_1 := this.Mysql.UpdateByTx(tx, Entniche_info, map[string]interface{}{ "id": this.Id, }, m) if this.Name != "" { this.Mysql.UpdateByTx(tx, Entniche_department, map[string]interface{}{ "ent_id": this.Id, "pid": 0, }, map[string]interface{}{"name": this.Name}) } AuthRecordId := this.Mysql.InsertByTx(tx, Auth_record, map[string]interface{}{ "entId": this.Id, "creditCode": this.Code, "name": this.Name, "comPanyType": this.Auth_type, "areaNumber": this.AreaNumber, "business": this.License, "officialLetter": this.Official_letter, "authName": this.Linkman_name, "authPhone": this.Linkman_phone, "authTime": time.Now().Format(Date_Full_Layout), //提交时间 "regPhone": this.Phone, "authStatus": 1, "organizationType": this.Organization_type, }) return ok_1 && AuthRecordId > 0 }) } type Examine struct { EntId int64 AccountId int64 ExamineId string AuthType string Reason string AuditUser string Mysql *mysql.Mysql ResourceLib resource.Resource } //审核 func (this *Examine) EntExamine() bool { now := time.Now() m := map[string]interface{}{ "audit_status": this.AuthType, //审核状态 1:待审核 2:审核通过 3:审核不通过 "auth_reason": this.Reason, "auth_status": -1, } //已通过更新时间状态 if this.AuthType == "2" { endDate := now.Format(Date_Short_Layout) + " 23:59:59" loc, _ := time.LoadLocation("Local") end, _ := time.ParseInLocation(Date_Full_Layout, endDate, loc) m["auth_status"] = 1 m["auth_startTime"] = now.Format(Date_Full_Layout) m["auth_endTime"] = end.AddDate(1, 0, 0).Format(Date_Full_Layout) //开通权限 req := &resourcepb.PowerReq{ Appid: "10000", GoodsCode: GOODSCODE_XXFB, EntId: this.EntId, AccountId: this.AccountId, Type: 1, GoodsSpecId: 4, BuyNum: 1, } resp, err := this.ResourceLib.PowerHandle(context.Background(), req) //0:失败 1:成功 -1:不在有效期内 -2:数量不足 -3:没有授权 if resp.Status == 0 || err != nil { logx.Infof("信息发布开通失败", this.EntId, resp.Status, "err:", err) return false } } return this.Mysql.ExecTx("更新企业", func(tx *sql.Tx) bool { ok_1 := this.Mysql.UpdateByTx(tx, Entniche_info, map[string]interface{}{ "id": this.EntId, }, m) ok_2 := this.Mysql.UpdateByTx(tx, Auth_record, map[string]interface{}{ "id": this.ExamineId, }, map[string]interface{}{ "auditTime": now.Format(Date_Full_Layout), "auditUser": this.AuditUser, "authReason": this.Reason, "authStatus": this.AuthType, }) return ok_1 && ok_2 }) } type List struct { Name string //企业名称 AuthStatus string //认证状态 0未认证 1已认证 PageNum string //页码,不传默认第一页 第一页为0 PageSize string //每页显示条数,不传默认为10 CreditCode string //统一社会信用代码 CreateStartTime string //创建开始时间戳 CreateEndTime string //创建结束时间戳 ValidStartTime string //有效截至开始时间戳 ValidEndTime string //有效截止时间戳 FrozenStatus string //冻结状态 1正常 0冻结 RegPhone string //注册人手机号 即管理员手机号 AuthPhone string //联系人手机号 Mysql *mysql.Mysql } //企业列表 func (this *List) List() (*[]map[string]interface{}, int64) { selectSql, countSql := this.GetSql() r := this.Mysql.SelectBySql(selectSql) if r != nil { for k, v := range *r { authStatus := common.Int64All(v["authStatus"]) if authStatus == -2 { (*r)[k]["authStatus"] = 0 } } } count := this.Mysql.CountBySql(countSql) return r, count } //企业列表sql拼接 func (this *List) GetSql() (selectSql, selectCountSql string) { selectSql = fmt.Sprintf(`select id,auth_type as comPanyType ,name,organization_type as organizationType ,auth_startTime as createTime,auth_endTime as validTime,auth_status as authStatus ,frozen_status as frozenStatus from %s`, Entniche_info) selectCountSql = fmt.Sprintf(`select count(1) from %s`, Entniche_info) sql := "" if this.Name != "" { sql += " name like " + "'%" + this.Name + "%' and" } if this.AuthStatus != "" { //z1 已认证 if this.AuthStatus == "0" { //前端传0 则是已到期 库中为-2 this.AuthStatus = "-2" } sql += " auth_status =" + this.AuthStatus + " and" } else { sql += " (auth_status =1 or auth_status=-2 ) and" } if this.CreditCode != "" { sql += " code like " + "'%" + this.CreditCode + "%' and" } s_starttime := TimeFormat(this.CreateStartTime, Date_Full_Layout) s_endtime := TimeFormat(this.CreateEndTime, Date_Full_Layout) if this.CreateStartTime != "" && this.CreateEndTime != "" { sql += ` auth_startTime >= '` + s_starttime + `' and auth_startTime < '` + s_endtime + `' and` } else if this.CreateStartTime != "" && this.CreateEndTime == "" { sql += ` auth_startTime >= '` + s_starttime + `' and` } else if this.CreateStartTime == "" && this.CreateEndTime != "" { sql += ` auth_startTime < '` + s_endtime + `' and` } e_starttime := TimeFormat(this.ValidStartTime, Date_Full_Layout) e_endtime := TimeFormat(this.ValidEndTime, Date_Full_Layout) if this.ValidStartTime != "" && this.ValidEndTime != "" { sql += ` auth_endTime >= '` + e_starttime + `' and auth_endTime < '` + e_endtime + `' and` } else if this.ValidStartTime != "" && this.ValidEndTime == "" { sql += ` auth_endTime >= '` + e_starttime + `' and` } else if this.ValidStartTime == "" && this.ValidEndTime != "" { sql += ` auth_endTime < '` + e_endtime + `' and` } if this.FrozenStatus != "" { if this.FrozenStatus == "0" { sql += " (frozen_status =" + this.FrozenStatus + " or frozen_status is null) and" } else { sql += " frozen_status =" + this.FrozenStatus + " and" } } if this.RegPhone != "" { sql += " phone like " + "'%" + this.RegPhone + "%' and" } if this.AuthPhone != "" { sql += " linkman_phone like " + "'%" + this.AuthPhone + "%' and" } if sql != "" { selectSql += " where " + sql[:len(sql)-3] selectCountSql += " where " + sql[:len(sql)-3] } limit := 10 if this.PageSize != "" { limit, _ = strconv.Atoi(this.PageSize) } pageNum, _ := strconv.Atoi(this.PageNum) offset := pageNum * limit selectSql += fmt.Sprintf("order by auth_endTime desc limit %v,%v", offset, limit) logx.Info("sql:", selectSql) logx.Info("sqlcout:", selectCountSql) return } type ExamineList struct { Name string //机构名称 AuthPhone string //联系人手机号 RegPhone string //注册人手机号 AuthType string //审核状态 1:待审核 2:审核通过 3:审核不通过 AuthStartTime string //申请开始时间 AuthEndTime string //申请结束时间 PageNum string //页码 PageSize string //每页展示条数 Mysql *mysql.Mysql } //审核列表 func (this *ExamineList) List() (*[]map[string]interface{}, int64) { selectSql, countSql := this.GetSql() r := this.Mysql.SelectBySql(selectSql) count := this.Mysql.CountBySql(countSql) return r, count } func (this *ExamineList) GetSql() (selectSql, countSql string) { selectSql = fmt.Sprintf(`select id,entId,comPanyType,name,creditCode,authPhone,authTime,authStatus,regPhone from %s`, Auth_record) countSql = fmt.Sprintf(`select count(1) from %s`, Auth_record) sql := "" if this.Name != "" { sql += " name like '%" + this.Name + "%' and" } if this.AuthType != "" { sql += " authStatus = " + this.AuthType + " and" } if this.RegPhone != "" { sql += " regPhone like '%" + this.RegPhone + "%' and" } if this.AuthPhone != "" { sql += " authPhone like '%" + this.AuthPhone + "%' and" } a_starttime := TimeFormat(this.AuthStartTime, Date_Full_Layout) a_endtime := TimeFormat(this.AuthEndTime, Date_Full_Layout) if this.AuthStartTime != "" && this.AuthEndTime != "" { sql += ` authTime >= '` + a_starttime + `' and authTime < '` + a_endtime + `' and` } else if this.AuthStartTime != "" && this.AuthEndTime == "" { sql += ` authTime >= '` + a_starttime + `' and` } else if this.AuthStartTime == "" && this.AuthEndTime != "" { sql += ` authTime < '` + a_endtime + `' and` } if sql != "" { selectSql += " where " + sql[:len(sql)-3] countSql += " where " + sql[:len(sql)-3] } limit := 10 if this.PageSize != "" { limit, _ = strconv.Atoi(this.PageSize) } pageNum, _ := strconv.Atoi(this.PageNum) offset := pageNum * limit selectSql += fmt.Sprintf(" order by authTime limit %v,%v", offset, limit) logx.Info("sql:", selectSql) logx.Info("sqlcout:", countSql) return } //查看企业认证状态、是否冻结 type CheckEnt struct { EntId int64 Mysql *mysql.Mysql Url string } /* int64 authStatus ;//企业是否认证 -1 未通过,0 未认证,1 已认证. -2 已到期 3待审核 int64 frozenStatus ; //冻结 0正常 1冻结 */ func (this *CheckEnt) Check() (authStatus, frozenStatus int64, msg string) { if this.EntId == 0 { msg = "企业id为空" return } if r := this.Mysql.SelectBySql(`select auth_status,frozen_status,audit_status from entniche_info where id =?`, this.EntId); r != nil && len(*r) > 0 { authStatus = common.Int64All(common.If((*r)[0]["auth_status"] == nil, 0, (*r)[0]["auth_status"])) if (*r)[0]["audit_status"] != nil && common.Int64All((*r)[0]["audit_status"]) == 1 { authStatus = 3 } frozenStatus = common.Int64All(common.If((*r)[0]["frozen_status"] == nil, 0, (*r)[0]["frozen_status"])) } else { msg = "未查询到企业" } return } type EntInfoData struct { Name string //名称 AreaNumber string //区域代码 ContactPerson string //联系人 ContactPhone string //联系电话 AuthState int64 //0未认证 1已认证 Industry string //行业 CompanyType int64 //1-事业单位 0-企业 CreditCode string //统一社会信用代码 Business string //营业执照 OfficialLetter string //认证公函 OrganizationType string //机构类型 1投标企业 2招标采购单位 3厂商 4招标代理机构 5经销商 6服务提供商 7其他 AuthType int64 //1待审核 2审核通过 3审核不通过 ForzenStatus int64 //1冻结 0未冻结 AuditUser string //审核人 AuditTime string //审核时间 CreateTime string //创建时间 AuthStartTime string //认证开始时间 AuthEndTime string //认证截止时间 AuthReason string //审核原因 AuthTime string //申请时间 RegPhone string //注册人手机号 } func (this *CheckEnt) Info() *EntInfoData { r := this.Mysql.SelectBySql(`select * from entniche_info where id =?`, this.EntId) info := EntInfoData{} if r != nil && len(*r) > 0 { data := (*r)[0] license := common.ObjToString(data["license"]) //老企业认证只传了后缀,需要拼接 if license != "" && !strings.Contains(license, "http") { license = this.Url + license } submitTime := common.ObjToString(data["craetetime"]) auth_data := this.Mysql.SelectBySql(`select authTime from auth_record where entId = ? and authStatus=1 order by id desc limit 1`, this.EntId) if auth_data != nil && len(*auth_data) > 0 { submitTime = common.ObjToString((*auth_data)[0]["authTime"]) } info.OrganizationType = common.ObjToString(data["organization_type"]) info.CreditCode = common.ObjToString(data["code"]) info.Name = common.ObjToString(data["name"]) info.CompanyType = common.Int64All(data["auth_type"]) info.AreaNumber = common.ObjToString(data["area_number"]) info.Business = license info.OfficialLetter = common.ObjToString(data["official_letter"]) info.AuthStartTime = common.ObjToString(data["auth_startTime"]) //创建时间 即为认证通过时间 info.AuthEndTime = common.ObjToString(data["auth_endTime"]) //有效截止日期 info.ForzenStatus = common.Int64All(data["frozen_status"]) info.AuthState = common.Int64All(data["auth_status"]) info.ContactPerson = common.ObjToString(data["linkman_name"]) info.ContactPhone = common.ObjToString(data["linkman_phone"]) info.AuthType = common.Int64All(data["audit_status"]) info.AreaNumber = GetArea(info.AreaNumber, this.Mysql) info.CreateTime = submitTime info.AuthReason = common.ObjToString(data["auth_reason"]) } return &info } type UpdateEnt struct { EntId int64 AccountId int64 UpdateType int64 Mysql *mysql.Mysql ResourceLib resource.Resource } //冻结解冻用户 1-冻结 2-解冻 func (this *UpdateEnt) UpdateEnt() (int64, string) { needUpdate := false req := &resourcepb.PowerReq{ Appid: "10000", GoodsCode: GOODSCODE_XXFB, EntId: this.EntId, AccountId: this.AccountId, Type: 1, //1:开通权益 -1:取消权益 GoodsSpecId: 4, } //解冻 rdata := this.Mysql.FindOne(Entniche_info, map[string]interface{}{ "id": this.EntId, }, `auth_status,auth_startTime,auth_endTime`, "") if rdata != nil && len(*rdata) > 0 { if auth_status := common.Int64All((*rdata)["auth_status"]); auth_status == 1 { needUpdate = true } } if this.UpdateType == 2 { this.UpdateType = 0 } else if this.UpdateType == 1 { needUpdate = true //冻结 req.Type = -1 } if needUpdate { //调用中台服务 开通权限 resp, err := this.ResourceLib.PowerHandle(context.Background(), req) //0:失败 1:成功 -1:不在有效期内 -2:数量不足 -3:没有授权 if resp.Status == 0 || err != nil { logx.Infof("信息发布开通", this.EntId, req, "err:", err) return -1, "失败" } } if this.Mysql.UpdateOrDeleteBySql(`update entniche_info set frozen_status=? where id =?`, this.UpdateType, this.EntId) > -1 { //修改成功 return 1, "" } return -1, "失败" } type ExamineInfo struct { ExamineId int64 Mysql *mysql.Mysql } func (this *ExamineInfo) Info() *EntInfoData { r := this.Mysql.SelectBySql(`select organizationType,creditCode,name,comPanyType,areaNumber,business,officialLetter,authName, authPhone,regPhone,authTime,authStatus,authReason,auditUser,auditTime from auth_record where id =?`, this.ExamineId) info := EntInfoData{} if r != nil && len(*r) > 0 { data := (*r)[0] log.Println(data) info.OrganizationType = common.ObjToString(data["organizationType"]) info.CreditCode = common.ObjToString(data["creditCode"]) info.Name = common.ObjToString(data["name"]) info.CompanyType = common.Int64All(data["comPanyType"]) info.AreaNumber = common.ObjToString(data["areaNumber"]) info.Business = common.ObjToString(data["business"]) info.OfficialLetter = common.ObjToString(data["officialLetter"]) info.ContactPerson = common.ObjToString(data["authName"]) info.ContactPhone = common.ObjToString(data["authPhone"]) info.RegPhone = common.ObjToString(data["regPhone"]) info.AuthTime = common.ObjToString(data["authTime"]) info.AuthState = common.Int64All(data["authStatus"]) info.AuthReason = common.ObjToString(data["authReason"]) info.AuditUser = common.ObjToString(data["auditUser"]) info.AuditTime = common.ObjToString(data["auditTime"]) info.AreaNumber = GetArea(info.AreaNumber, this.Mysql) log.Println(common.ObjToString(data["auditTime"])) log.Println(common.ObjToString(data["areaNumber"])) log.Println(common.ObjToString(data["authTime"])) } return &info } func GetArea(areaNumber string, mysql *mysql.Mysql) string { if areaNumber == "" { return "" } r := mysql.SelectBySql(`select a.name city,b.name province from province a left join province b on a.pid = b.cid where a.cid=?`, areaNumber) if r != nil && len(*r) > 0 { rdata := (*r)[0] province := common.ObjToString(rdata["province"]) city := common.ObjToString(rdata["city"]) return fmt.Sprintf("%s_%s", province, city) } return "" } //时间戳转换 func TimeFormat(timestamp, format string) string { i_timestamp, _ := strconv.Atoi(timestamp) return time.Unix(int64(i_timestamp), 0).Format(format) } type GetStatusByCodeStruct struct { Code string Phone string Mysql *mysql.Mysql } // func (this *GetStatusByCodeStruct) GetStatusByCode() (int, bool, string) { isin := false authStatus := 0 if this.Code == "" { return authStatus, isin, "参数错误" } if r := this.Mysql.SelectBySql(`select id,auth_status,frozen_status,audit_status from entniche_info where code =?`, this.Code); r != nil && len(*r) > 0 { for _, v := range *r { //记录所有的统一社会信用代码相同的企业 entids := "" id := common.Int64All(v["id"]) audit_status := common.Int64All(v["audit_status"]) authStatus = common.IntAll(v["auth_status"]) if audit_status == 1 { //根据统一社会信用代码查看该企业正在审核中 authStatus = 3 return authStatus, isin, "" } entids += strconv.Itoa(int(id)) + "," if entids != "" { entids = entids[:len(entids)-1] } isin = this.Mysql.CountBySql(`select count(1) from entniche_user where ent_id in(?) and phone =?`, entids, this.Phone) > 0 } } return authStatus, isin, "" } //根据id获取企业信息 func (e *EntInfo) GetById(id int) *EntInfo { r := e.Mysql.FindOne(Entniche_info, map[string]interface{}{"id": id}, "*", "") entInfo, _ := common.JsonUnmarshal(r, &EntInfo{}).(*EntInfo) if entInfo == nil { return &EntInfo{} } return entInfo } type EntDeptParent struct { Id int Pid int } type EntDept struct { Id int Pid int Name string Nodiff int Subdis int } type EntDistribute struct { Id string DeptId int Area map[string]interface{} Buyerclass []interface{} Items []string } type EntRuleUser struct { UserId int RuleId string } //查找父级部门(跨级) func GetEntDeptParent(mysq *mysql.Mysql, entParentDept map[int][]*EntDeptParent, deptid int) map[int][]*EntDeptParent { //先获取用户组织架构权益 //查找父级部门(跨级) list := mysq.SelectBySql(`select id,pid from entniche_department_parent where id =?`, deptid) for _, v := range *list { id := common.IntAll(v["id"]) pid := common.IntAll(v["pid"]) entParentDept[id] = append(entParentDept[id], &EntDeptParent{ Id: id, Pid: pid, }) } return entParentDept } //查看部门相关设置 func GetEntDepts(mysq *mysql.Mysql, entDepts map[int]*EntDept, entid int64) map[int]*EntDept { //查看部门相关设置 lis := mysq.SelectBySql(`select * from entniche_department where ent_id=?`, entid) for _, v := range *lis { //获取部门相关 deptid := common.IntAll(v["id"]) pid := common.IntAll(v["pid"]) name := common.ObjToString(v["name"]) subdis := common.IntAll(v["subdis"]) nodiff := common.IntAll(v["nodiff"]) entDepts[deptid] = &EntDept{ Id: deptid, Pid: pid, Name: name, Nodiff: nodiff, Subdis: subdis, } } return entDepts } //获取某个用户的所有分发规则 func GetUserRules(mysq *mysql.Mysql, entUserId int64) map[int][]*EntRuleUser { entUserRules := map[int][]*EntRuleUser{} //用户下所有的分发规则 // 分发规则遍历 查询用户是否有被分发的规则 data := mysq.SelectBySql(`SELECT * FROM entniche_user_rule WHERE user_id=?`, entUserId) if data != nil { for _, v := range *data { ruleId := common.ObjToString(v["rule_id"]) userId := common.IntAll(v["user_id"]) entRuleUser := &EntRuleUser{ UserId: userId, RuleId: ruleId, } entUserRules[userId] = append(entUserRules[userId], entRuleUser) } } return entUserRules } //获取企业下的所有分发规则详情 func GetEntDistribute(mgo mongodb.MongodbSim, entId int64) map[string]*EntDistribute { entDis := map[string]*EntDistribute{} //分发规则的相关设置 //获取具体分发规则 disData, ok := mgo.Find("entniche_distribute", map[string]interface{}{ "i_status": map[string]interface{}{"$ne": 1}, "i_entid": entId, }, nil, nil, false, -1, -1) if ok && disData != nil && len(*disData) > 0 { for _, v := range *disData { deptId := common.IntAll(v["i_deptid"]) a_items, _ := v["a_items"].([]interface{}) o_area, _ := v["o_area"].(map[string]interface{}) a_buyerclass, _ := v["a_buyerclass"].([]interface{}) ruleId := mongodb.BsonIdToSId(v["_id"]) entDis[ruleId] = &EntDistribute{ Id: ruleId, DeptId: deptId, Area: o_area, Buyerclass: a_buyerclass, Items: common.ObjArrToStringArr(a_items), } } } return entDis } //根据手机号获取用户商机管理企业 func GetEntByPhone(mys *mysql.Mysql, phone string) (entId, entUserId int64) { data := mys.SelectBySql(`SELECT a.id entid,b.id as user_id from entniche_info a INNER JOIN entniche_user b on (b.phone=? and a.id=b.ent_id and a.status=1 and b.power=1) ORDER BY if(a.createtime 0 { entId := common.Int64All((*data)[0]["entid"]) entUserId := common.Int64All((*data)[0]["user_id"]) return entId, entUserId } return 0, 0 }