ent.go 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876
  1. package entity
  2. import (
  3. "context"
  4. "database/sql"
  5. "fmt"
  6. "log"
  7. "strconv"
  8. "strings"
  9. "time"
  10. "app.yhyue.com/moapp/jybase/common"
  11. "app.yhyue.com/moapp/jybase/mongodb"
  12. "app.yhyue.com/moapp/jybase/mysql"
  13. resourcepb "bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/pb"
  14. "bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/resource"
  15. usercenterclient "bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/usercenter"
  16. "github.com/zeromicro/go-zero/core/logx"
  17. )
  18. var VarEntInfo = &EntInfo{}
  19. var UserCenterRpc usercenterclient.UserCenter
  20. type Competitor struct {
  21. Name string
  22. }
  23. type Service struct {
  24. Name string
  25. }
  26. type EntInfo struct {
  27. Id int //企业id
  28. Name string //企业名
  29. Phone string //手机号
  30. Model int //1-统一订阅,2-个人订阅
  31. Status int //0:未生效,1:已生效,-1:已到期
  32. Quota int //限额人数
  33. Startdate int //开始时间
  34. Enddate int //结束时间
  35. Createtime string //创建时间
  36. Mail string //邮箱
  37. Marketarea string
  38. Industryclass string //行业分类
  39. Admin string //管理员姓名-只有商机洞察中有,可能没什么用
  40. Code string //统一社会信用代码
  41. License string //营业执照
  42. Legal_name string //法人姓名
  43. Legal_idcard string //身份证号
  44. Legal_idcard_front string //身份证前面
  45. Legal_idcard_after string //身份证后面
  46. Auth_status int //-1-未通过 0-未认证 1-已认证
  47. Auth_reason string //审核不通过的原因说明
  48. Auth_time string //提交时间
  49. Audit_time string //审核时间
  50. User_id int
  51. Competitors []*Competitor //竞争对手
  52. Services []*Service //产品服务
  53. Auth_type int //认证类型 1-事业单位 0=企业
  54. Legal_mancard string //法人证
  55. IsNew int //1新商机管理0老商机管理
  56. Frozen_status int //是否冻结 1正常 0冻结
  57. Auth_startTime string //认证通过开始时间
  58. Auth_endTime string //认证通过结束时间
  59. Audit_status int //审核状态 1:待审核 2:审核通过 3:审核不通过
  60. Linkman_phone string //联系人手机号
  61. Linkman_name string //联系人姓名
  62. Organization_type string //机构类型 1投标企业 2招标采购单位 3厂商 4招标代理机构 5经销商 6服务提供商 7其他
  63. Official_letter string //认证公函
  64. AreaNumber string //行政区号
  65. Mysql *mysql.Mysql
  66. }
  67. const (
  68. Dataexport_order = "dataexport_order"
  69. Entniche_department = "entniche_department"
  70. Entniche_department_user = "entniche_department_user"
  71. Entniche_department_parent = "entniche_department_parent"
  72. Entniche_info = "entniche_info"
  73. Entniche_log = "entniche_log"
  74. Entniche_role = "entniche_role"
  75. Entniche_user = "entniche_user"
  76. Entniche_user_role = "entniche_user_role"
  77. Entniche_competitor = "entniche_competitor"
  78. Entniche_service = "entniche_service"
  79. Entniche_user_rule = "entniche_user_rule"
  80. Entniche_distribute = "entniche_distribute" //分发规则表(mongo)
  81. Entniche_rule = "entniche_rule" //订阅表(mongo)
  82. Entniche_delete = "entniche_delete"
  83. Ent_bank = "ent_bank"
  84. Auth_record = "auth_record" //认证记录表
  85. //角色
  86. Role_admin_system = 1 //系统管理员
  87. Role_admin_department = 2 //部门管理员
  88. //
  89. Entniche_customer = "entniche_customer"
  90. Entniche_user_customer = "entniche_user_customer"
  91. Entniche_customer_contact = "entniche_customer_contact"
  92. Entniche_customer_return = "entniche_customer_return"
  93. Entniche_project = "entniche_project"
  94. Entniche_project_track = "entniche_project_track"
  95. Entniche_entmodel = "entniche_entmodel"
  96. Entniche_follow = "entniche_follow"
  97. Admin_name = "我"
  98. Entnice_life_cycle = "entnice_life_cycle"
  99. Bdcollection_entniche = "bdcollection_entniche"
  100. Bdlabel_entniche = "bdlabel_entniche"
  101. Date_Full_Layout = "2006-01-02 15:04:05"
  102. Date_Short_Layout = "2006-01-02"
  103. //信息发布产品code
  104. GOODSCODE_XXFB = "xxfb_gyxx"
  105. )
  106. //创建企业
  107. func (this *EntInfo) Add() (bool, int64) {
  108. m := map[string]interface{}{
  109. "status": 0,
  110. "auth_status": this.Auth_status,
  111. "audit_status": this.Audit_status,
  112. }
  113. //不能为空
  114. if this.Name != "" {
  115. m["name"] = this.Name
  116. }
  117. if this.Phone != "" {
  118. m["phone"] = this.Phone
  119. }
  120. if this.Createtime != "" {
  121. m["createtime"] = this.Createtime
  122. }
  123. if this.Admin != "" {
  124. m["admin"] = this.Admin
  125. }
  126. if this.Code != "" {
  127. m["code"] = this.Code
  128. }
  129. if this.License != "" {
  130. m["license"] = this.License
  131. }
  132. if this.Linkman_name != "" {
  133. m["linkman_name"] = this.Linkman_name
  134. }
  135. if this.Linkman_phone != "" {
  136. m["linkman_phone"] = this.Linkman_phone
  137. }
  138. if this.Organization_type != "" {
  139. m["organization_type"] = this.Organization_type
  140. }
  141. if this.Official_letter != "" {
  142. m["official_letter"] = this.Official_letter
  143. }
  144. if this.AreaNumber != "" {
  145. m["area_number"] = this.AreaNumber
  146. }
  147. if this.Auth_type >= 0 {
  148. m["auth_type"] = this.Auth_type
  149. }
  150. return this.Mysql.ExecTx("创建企业", func(tx *sql.Tx) bool {
  151. this.Id = int(this.Mysql.InsertByTx(tx, Entniche_info, m))
  152. //
  153. var ok_2 int64
  154. if len(this.Competitors) > 0 {
  155. array := []interface{}{}
  156. for _, v := range this.Competitors {
  157. array = append(array, this.Id, v.Name)
  158. }
  159. _, ok_2 = this.Mysql.InsertBatchByTx(tx, Entniche_competitor, []string{"ent_id", "name"}, array)
  160. }
  161. //
  162. var ok_3 int64
  163. if len(this.Services) > 0 {
  164. array := []interface{}{}
  165. for _, v := range this.Services {
  166. array = append(array, this.Id, v.Name)
  167. }
  168. _, ok_3 = this.Mysql.InsertBatchByTx(tx, Entniche_service, []string{"ent_id", "name"}, array)
  169. }
  170. deptId := this.Mysql.InsertByTx(tx, Entniche_department, map[string]interface{}{
  171. "pid": 0,
  172. "name": this.Name,
  173. "ent_id": this.Id,
  174. "subdis": 1,
  175. "nodiff": 0,
  176. "createtime": this.Createtime,
  177. "timestamp": this.Createtime,
  178. })
  179. this.User_id = int(this.Mysql.InsertByTx(tx, Entniche_user, map[string]interface{}{
  180. "name": Admin_name,
  181. "phone": this.Phone,
  182. "ent_id": this.Id,
  183. "createtime": this.Createtime,
  184. "timestamp": this.Createtime,
  185. }))
  186. deptUser := this.Mysql.InsertByTx(tx, Entniche_department_user, map[string]interface{}{
  187. "dept_id": deptId,
  188. "user_id": this.User_id,
  189. })
  190. userRole := this.Mysql.InsertByTx(tx, Entniche_user_role, map[string]interface{}{
  191. "user_id": this.User_id,
  192. "role_id": Role_admin_system,
  193. })
  194. AuthRecordId := this.Mysql.InsertByTx(tx, Auth_record, map[string]interface{}{
  195. "creditCode": this.Code,
  196. "name": this.Name,
  197. "comPanyType": this.Auth_type,
  198. "areaNumber": this.AreaNumber,
  199. "business": this.License,
  200. "officialLetter": this.Official_letter,
  201. "authName": this.Linkman_name,
  202. "authPhone": this.Linkman_phone,
  203. "authReason": "",
  204. "authTime": time.Now().Format(Date_Full_Layout), //提交时间
  205. "regPhone": this.Phone,
  206. "entId": this.Id,
  207. "organizationType": this.Organization_type,
  208. "authStatus": 1,
  209. })
  210. return this.Id > 0 && ok_2 > -1 && ok_3 > -1 && deptId > 0 && this.User_id > 0 && deptUser > -1 && userRole > -1 && AuthRecordId > 0
  211. }), int64(this.Id)
  212. }
  213. //修改企业信息
  214. func (this *EntInfo) Update() bool {
  215. m := map[string]interface{}{
  216. "auth_status": this.Auth_status,
  217. "audit_status": this.Audit_status,
  218. }
  219. if this.Linkman_name != "" {
  220. m["linkman_name"] = this.Linkman_name
  221. }
  222. if this.Linkman_phone != "" {
  223. m["linkman_phone"] = this.Linkman_phone
  224. }
  225. if this.License != "" {
  226. m["license"] = this.License
  227. }
  228. if this.Organization_type != "" {
  229. m["organization_type"] = this.Organization_type
  230. }
  231. if this.Official_letter != "" {
  232. m["official_letter"] = this.Official_letter
  233. }
  234. if this.AreaNumber != "" {
  235. m["area_number"] = this.AreaNumber
  236. }
  237. if this.Auth_type >= 0 {
  238. m["auth_type"] = this.Auth_type
  239. }
  240. if this.Code != "" {
  241. m["code"] = this.Code
  242. }
  243. if this.Name != "" {
  244. m["name"] = this.Name
  245. }
  246. return this.Mysql.ExecTx("更新企业", func(tx *sql.Tx) bool {
  247. ok_1 := this.Mysql.UpdateByTx(tx, Entniche_info, map[string]interface{}{
  248. "id": this.Id,
  249. }, m)
  250. AuthRecordId := this.Mysql.InsertByTx(tx, Auth_record, map[string]interface{}{
  251. "entId": this.Id,
  252. "creditCode": this.Code,
  253. "name": this.Name,
  254. "comPanyType": this.Auth_type,
  255. "areaNumber": this.AreaNumber,
  256. "business": this.License,
  257. "officialLetter": this.Official_letter,
  258. "authName": this.Linkman_name,
  259. "authPhone": this.Linkman_phone,
  260. "authTime": time.Now().Format(Date_Full_Layout), //提交时间
  261. "regPhone": this.Phone,
  262. "authStatus": 1,
  263. "organizationType": this.Organization_type,
  264. })
  265. return ok_1 && AuthRecordId > 0
  266. })
  267. }
  268. type Examine struct {
  269. EntId int64
  270. ExamineId string
  271. AuthType string
  272. Reason string
  273. AuditUser string
  274. Mysql *mysql.Mysql
  275. ResourceLib resource.Resource
  276. }
  277. //审核
  278. func (this *Examine) EntExamine() bool {
  279. now := time.Now()
  280. m := map[string]interface{}{
  281. "audit_status": this.AuthType, //审核状态 1:待审核 2:审核通过 3:审核不通过
  282. "auth_reason": this.Reason,
  283. "auth_status": -1,
  284. }
  285. //已通过更新时间状态
  286. if this.AuthType == "2" {
  287. endDate := now.Format(Date_Short_Layout) + " 23:59:59"
  288. loc, _ := time.LoadLocation("Local")
  289. end, _ := time.ParseInLocation(Date_Full_Layout, endDate, loc)
  290. m["auth_status"] = 1
  291. m["auth_startTime"] = now.Format(Date_Full_Layout)
  292. m["auth_endTime"] = end.AddDate(1, 0, 0).Format(Date_Full_Layout)
  293. //开通权限
  294. req := &resourcepb.PowerReq{
  295. Appid: "10000",
  296. GoodsCode: GOODSCODE_XXFB,
  297. EntId: this.EntId,
  298. Type: 1,
  299. GoodsSpecId: 4,
  300. BuyNum: 1,
  301. }
  302. resp, err := this.ResourceLib.PowerHandle(context.Background(), req)
  303. //0:失败 1:成功 -1:不在有效期内 -2:数量不足 -3:没有授权
  304. if resp.Status == 0 || err != nil {
  305. logx.Infof("信息发布开通失败", this.EntId, resp.Status, "err:", err)
  306. return false
  307. }
  308. }
  309. return this.Mysql.ExecTx("更新企业", func(tx *sql.Tx) bool {
  310. ok_1 := this.Mysql.UpdateByTx(tx, Entniche_info, map[string]interface{}{
  311. "id": this.EntId,
  312. }, m)
  313. ok_2 := this.Mysql.UpdateByTx(tx, Auth_record, map[string]interface{}{
  314. "id": this.ExamineId,
  315. }, map[string]interface{}{
  316. "auditTime": now.Format(Date_Full_Layout),
  317. "auditUser": this.AuditUser,
  318. "authReason": this.Reason,
  319. "authStatus": this.AuthType,
  320. })
  321. return ok_1 && ok_2
  322. })
  323. }
  324. type List struct {
  325. Name string //企业名称
  326. AuthStatus string //认证状态 0未认证 1已认证
  327. PageNum string //页码,不传默认第一页 第一页为0
  328. PageSize string //每页显示条数,不传默认为10
  329. CreditCode string //统一社会信用代码
  330. CreateStartTime string //创建开始时间戳
  331. CreateEndTime string //创建结束时间戳
  332. ValidStartTime string //有效截至开始时间戳
  333. ValidEndTime string //有效截止时间戳
  334. FrozenStatus string //冻结状态 1正常 0冻结
  335. RegPhone string //注册人手机号 即管理员手机号
  336. AuthPhone string //联系人手机号
  337. Mysql *mysql.Mysql
  338. }
  339. //企业列表
  340. func (this *List) List() (*[]map[string]interface{}, int64) {
  341. selectSql, countSql := this.GetSql()
  342. r := this.Mysql.SelectBySql(selectSql)
  343. if r != nil {
  344. for k, v := range *r {
  345. authStatus := common.Int64All(v["authStatus"])
  346. if authStatus == -2 {
  347. (*r)[k]["authStatus"] = 0
  348. }
  349. }
  350. }
  351. count := this.Mysql.CountBySql(countSql)
  352. return r, count
  353. }
  354. //企业列表sql拼接
  355. func (this *List) GetSql() (selectSql, selectCountSql string) {
  356. 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)
  357. selectCountSql = fmt.Sprintf(`select count(1) from %s`, Entniche_info)
  358. sql := ""
  359. if this.Name != "" {
  360. sql += " name like " + "'%" + this.Name + "%' and"
  361. }
  362. if this.AuthStatus != "" { //z1 已认证
  363. if this.AuthStatus == "0" { //前端传0 则是已到期 库中为-2
  364. this.AuthStatus = "-2"
  365. }
  366. sql += " auth_status =" + this.AuthStatus + " and"
  367. } else {
  368. sql += " (auth_status =1 or auth_status=-2 ) and"
  369. }
  370. if this.CreditCode != "" {
  371. sql += " code like " + "'%" + this.CreditCode + "%' and"
  372. }
  373. s_starttime := TimeFormat(this.CreateStartTime, Date_Full_Layout)
  374. s_endtime := TimeFormat(this.CreateEndTime, Date_Full_Layout)
  375. if this.CreateStartTime != "" && this.CreateEndTime != "" {
  376. sql += ` auth_startTime >= '` + s_starttime + `' and auth_startTime < '` + s_endtime + `' and`
  377. } else if this.CreateStartTime != "" && this.CreateEndTime == "" {
  378. sql += ` auth_startTime >= '` + s_starttime + `' and`
  379. } else if this.CreateStartTime == "" && this.CreateEndTime != "" {
  380. sql += ` auth_startTime < '` + s_endtime + `' and`
  381. }
  382. e_starttime := TimeFormat(this.ValidStartTime, Date_Full_Layout)
  383. e_endtime := TimeFormat(this.ValidEndTime, Date_Full_Layout)
  384. if this.ValidStartTime != "" && this.ValidEndTime != "" {
  385. sql += ` auth_endTime >= '` + e_starttime + `' and auth_endTime < '` + e_endtime + `' and`
  386. } else if this.ValidStartTime != "" && this.ValidEndTime == "" {
  387. sql += ` auth_endTime >= '` + e_starttime + `' and`
  388. } else if this.ValidStartTime == "" && this.ValidEndTime != "" {
  389. sql += ` auth_endTime < '` + e_endtime + `' and`
  390. }
  391. if this.FrozenStatus != "" {
  392. if this.FrozenStatus == "0" {
  393. sql += " (frozen_status =" + this.FrozenStatus + " or frozen_status is null) and"
  394. } else {
  395. sql += " frozen_status =" + this.FrozenStatus + " and"
  396. }
  397. }
  398. if this.RegPhone != "" {
  399. sql += " phone like " + "'%" + this.RegPhone + "%' and"
  400. }
  401. if this.AuthPhone != "" {
  402. sql += " linkman_phone like " + "'%" + this.AuthPhone + "%' and"
  403. }
  404. if sql != "" {
  405. selectSql += " where " + sql[:len(sql)-3]
  406. selectCountSql += " where " + sql[:len(sql)-3]
  407. }
  408. limit := 10
  409. if this.PageSize != "" {
  410. limit, _ = strconv.Atoi(this.PageSize)
  411. }
  412. pageNum, _ := strconv.Atoi(this.PageNum)
  413. offset := pageNum * limit
  414. selectSql += fmt.Sprintf("order by auth_endTime desc limit %v,%v", offset, limit)
  415. logx.Info("sql:", selectSql)
  416. logx.Info("sqlcout:", selectCountSql)
  417. return
  418. }
  419. type ExamineList struct {
  420. Name string //机构名称
  421. AuthPhone string //联系人手机号
  422. RegPhone string //注册人手机号
  423. AuthType string //审核状态 1:待审核 2:审核通过 3:审核不通过
  424. AuthStartTime string //申请开始时间
  425. AuthEndTime string //申请结束时间
  426. PageNum string //页码
  427. PageSize string //每页展示条数
  428. Mysql *mysql.Mysql
  429. }
  430. //审核列表
  431. func (this *ExamineList) List() (*[]map[string]interface{}, int64) {
  432. selectSql, countSql := this.GetSql()
  433. r := this.Mysql.SelectBySql(selectSql)
  434. count := this.Mysql.CountBySql(countSql)
  435. return r, count
  436. }
  437. func (this *ExamineList) GetSql() (selectSql, countSql string) {
  438. selectSql = fmt.Sprintf(`select id,entId,comPanyType,name,creditCode,authPhone,authTime,authStatus,regPhone from %s`, Auth_record)
  439. countSql = fmt.Sprintf(`select count(1) from %s`, Auth_record)
  440. sql := ""
  441. if this.Name != "" {
  442. sql += " name like '%" + this.Name + "%' and"
  443. }
  444. if this.AuthType != "" {
  445. sql += " authStatus = " + this.AuthType + " and"
  446. }
  447. if this.RegPhone != "" {
  448. sql += " regPhone like '%" + this.RegPhone + "%' and"
  449. }
  450. if this.AuthPhone != "" {
  451. sql += " authPhone like '%" + this.AuthPhone + "%' and"
  452. }
  453. a_starttime := TimeFormat(this.AuthStartTime, Date_Full_Layout)
  454. a_endtime := TimeFormat(this.AuthEndTime, Date_Full_Layout)
  455. if this.AuthStartTime != "" && this.AuthEndTime != "" {
  456. sql += ` authTime >= '` + a_starttime + `' and authTime < '` + a_endtime + `' and`
  457. } else if this.AuthStartTime != "" && this.AuthEndTime == "" {
  458. sql += ` authTime >= '` + a_starttime + `' and`
  459. } else if this.AuthStartTime == "" && this.AuthEndTime != "" {
  460. sql += ` authTime < '` + a_endtime + `' and`
  461. }
  462. if sql != "" {
  463. selectSql += " where " + sql[:len(sql)-3]
  464. countSql += " where " + sql[:len(sql)-3]
  465. }
  466. limit := 10
  467. if this.PageSize != "" {
  468. limit, _ = strconv.Atoi(this.PageSize)
  469. }
  470. pageNum, _ := strconv.Atoi(this.PageNum)
  471. offset := pageNum * limit
  472. selectSql += fmt.Sprintf(" order by authTime limit %v,%v", offset, limit)
  473. logx.Info("sql:", selectSql)
  474. logx.Info("sqlcout:", countSql)
  475. return
  476. }
  477. //查看企业认证状态、是否冻结
  478. type CheckEnt struct {
  479. EntId int64
  480. Mysql *mysql.Mysql
  481. Url string
  482. }
  483. /*
  484. int64 authStatus ;//企业是否认证 -1 未通过,0 未认证,1 已认证. -2 已到期 3待审核
  485. int64 frozenStatus ; //冻结 0正常 1冻结
  486. */
  487. func (this *CheckEnt) Check() (authStatus, frozenStatus int64, msg string) {
  488. if this.EntId == 0 {
  489. msg = "企业id为空"
  490. return
  491. }
  492. if r := this.Mysql.SelectBySql(`select auth_status,frozen_status,audit_status from entniche_info where id =?`, this.EntId); r != nil && len(*r) > 0 {
  493. authStatus = common.Int64All(common.If((*r)[0]["auth_status"] == nil, 0, (*r)[0]["auth_status"]))
  494. if (*r)[0]["audit_status"] != nil && common.Int64All((*r)[0]["audit_status"]) == 1 {
  495. authStatus = 3
  496. }
  497. frozenStatus = common.Int64All(common.If((*r)[0]["frozen_status"] == nil, 0, (*r)[0]["frozen_status"]))
  498. } else {
  499. msg = "未查询到企业"
  500. }
  501. return
  502. }
  503. type EntInfoData struct {
  504. Name string //名称
  505. AreaNumber string //区域代码
  506. ContactPerson string //联系人
  507. ContactPhone string //联系电话
  508. AuthState int64 //0未认证 1已认证
  509. Industry string //行业
  510. CompanyType int64 //1-事业单位 0-企业
  511. CreditCode string //统一社会信用代码
  512. Business string //营业执照
  513. OfficialLetter string //认证公函
  514. OrganizationType string //机构类型 1投标企业 2招标采购单位 3厂商 4招标代理机构 5经销商 6服务提供商 7其他
  515. AuthType int64 //1待审核 2审核通过 3审核不通过
  516. ForzenStatus int64 //1冻结 0未冻结
  517. AuditUser string //审核人
  518. AuditTime string //审核时间
  519. CreateTime string //创建时间
  520. AuthStartTime string //认证开始时间
  521. AuthEndTime string //认证截止时间
  522. AuthReason string //审核原因
  523. AuthTime string //申请时间
  524. RegPhone string //注册人手机号
  525. }
  526. func (this *CheckEnt) Info() *EntInfoData {
  527. r := this.Mysql.SelectBySql(`select * from entniche_info where id =?`, this.EntId)
  528. info := EntInfoData{}
  529. if r != nil && len(*r) > 0 {
  530. data := (*r)[0]
  531. license := common.ObjToString(data["license"]) //老企业认证只传了后缀,需要拼接
  532. if license != "" && !strings.Contains(license, "http") {
  533. license = this.Url + license
  534. }
  535. submitTime := common.ObjToString(data["craetetime"])
  536. auth_data := this.Mysql.SelectBySql(`select authTime from auth_record where entId = ? and authStatus=1 order by id desc limit 1`, this.EntId)
  537. if auth_data != nil && len(*auth_data) > 0 {
  538. submitTime = common.ObjToString((*auth_data)[0]["authTime"])
  539. }
  540. info.OrganizationType = common.ObjToString(data["organization_type"])
  541. info.CreditCode = common.ObjToString(data["code"])
  542. info.Name = common.ObjToString(data["name"])
  543. info.CompanyType = common.Int64All(data["auth_type"])
  544. info.AreaNumber = common.ObjToString(data["area_number"])
  545. info.Business = license
  546. info.OfficialLetter = common.ObjToString(data["official_letter"])
  547. info.AuthStartTime = common.ObjToString(data["auth_startTime"]) //创建时间 即为认证通过时间
  548. info.AuthEndTime = common.ObjToString(data["auth_endTime"]) //有效截止日期
  549. info.ForzenStatus = common.Int64All(data["frozen_status"])
  550. info.AuthState = common.Int64All(data["auth_status"])
  551. info.ContactPerson = common.ObjToString(data["linkman_name"])
  552. info.ContactPhone = common.ObjToString(data["linkman_phone"])
  553. info.AuthType = common.Int64All(data["audit_status"])
  554. info.AreaNumber = GetArea(info.AreaNumber, this.Mysql)
  555. info.CreateTime = submitTime
  556. info.AuthReason = common.ObjToString(data["auth_reason"])
  557. }
  558. return &info
  559. }
  560. type UpdateEnt struct {
  561. EntId int64
  562. UpdateType int64
  563. Mysql *mysql.Mysql
  564. ResourceLib resource.Resource
  565. }
  566. //冻结解冻用户 1-冻结 2-解冻
  567. func (this *UpdateEnt) UpdateEnt() (int64, string) {
  568. needUpdate := false
  569. req := &resourcepb.PowerReq{
  570. Appid: "10000",
  571. GoodsCode: GOODSCODE_XXFB,
  572. EntId: this.EntId,
  573. Type: 1, //1:开通权益 -1:取消权益
  574. GoodsSpecId: 4,
  575. }
  576. //解冻
  577. rdata := this.Mysql.FindOne(Entniche_info, map[string]interface{}{
  578. "id": this.EntId,
  579. }, `auth_status,auth_startTime,auth_endTime`, "")
  580. if rdata != nil && len(*rdata) > 0 {
  581. if auth_status := common.Int64All((*rdata)["auth_status"]); auth_status == 1 {
  582. needUpdate = true
  583. }
  584. }
  585. if this.UpdateType == 2 {
  586. this.UpdateType = 0
  587. } else if this.UpdateType == 1 {
  588. needUpdate = true
  589. //冻结
  590. req.Type = -1
  591. }
  592. if needUpdate {
  593. //调用中台服务 开通权限
  594. resp, err := this.ResourceLib.PowerHandle(context.Background(), req)
  595. //0:失败 1:成功 -1:不在有效期内 -2:数量不足 -3:没有授权
  596. if resp.Status == 0 || err != nil {
  597. logx.Infof("信息发布开通", this.EntId, req, "err:", err)
  598. return -1, "失败"
  599. }
  600. }
  601. if this.Mysql.UpdateOrDeleteBySql(`update entniche_info set frozen_status=? where id =?`, this.UpdateType, this.EntId) > -1 {
  602. //修改成功
  603. return 1, ""
  604. }
  605. return -1, "失败"
  606. }
  607. type ExamineInfo struct {
  608. ExamineId int64
  609. Mysql *mysql.Mysql
  610. }
  611. func (this *ExamineInfo) Info() *EntInfoData {
  612. r := this.Mysql.SelectBySql(`select organizationType,creditCode,name,comPanyType,areaNumber,business,officialLetter,authName,
  613. authPhone,regPhone,authTime,authStatus,authReason,auditUser,auditTime from auth_record where id =?`, this.ExamineId)
  614. info := EntInfoData{}
  615. if r != nil && len(*r) > 0 {
  616. data := (*r)[0]
  617. log.Println(data)
  618. info.OrganizationType = common.ObjToString(data["organizationType"])
  619. info.CreditCode = common.ObjToString(data["creditCode"])
  620. info.Name = common.ObjToString(data["name"])
  621. info.CompanyType = common.Int64All(data["comPanyType"])
  622. info.AreaNumber = common.ObjToString(data["areaNumber"])
  623. info.Business = common.ObjToString(data["business"])
  624. info.OfficialLetter = common.ObjToString(data["officialLetter"])
  625. info.ContactPerson = common.ObjToString(data["authName"])
  626. info.ContactPhone = common.ObjToString(data["authPhone"])
  627. info.RegPhone = common.ObjToString(data["regPhone"])
  628. info.AuthTime = common.ObjToString(data["authTime"])
  629. info.AuthState = common.Int64All(data["authStatus"])
  630. info.AuthReason = common.ObjToString(data["authReason"])
  631. info.AuditUser = common.ObjToString(data["auditUser"])
  632. info.AuditTime = common.ObjToString(data["auditTime"])
  633. info.AreaNumber = GetArea(info.AreaNumber, this.Mysql)
  634. log.Println(common.ObjToString(data["auditTime"]))
  635. log.Println(common.ObjToString(data["areaNumber"]))
  636. log.Println(common.ObjToString(data["authTime"]))
  637. }
  638. return &info
  639. }
  640. func GetArea(areaNumber string, mysql *mysql.Mysql) string {
  641. if areaNumber == "" {
  642. return ""
  643. }
  644. 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)
  645. if r != nil && len(*r) > 0 {
  646. rdata := (*r)[0]
  647. province := common.ObjToString(rdata["province"])
  648. city := common.ObjToString(rdata["city"])
  649. return fmt.Sprintf("%s_%s", province, city)
  650. }
  651. return ""
  652. }
  653. //时间戳转换
  654. func TimeFormat(timestamp, format string) string {
  655. i_timestamp, _ := strconv.Atoi(timestamp)
  656. return time.Unix(int64(i_timestamp), 0).Format(format)
  657. }
  658. type GetStatusByCodeStruct struct {
  659. Code string
  660. Phone string
  661. Mysql *mysql.Mysql
  662. }
  663. //
  664. func (this *GetStatusByCodeStruct) GetStatusByCode() (int, bool, string) {
  665. isin := false
  666. authStatus := 0
  667. if this.Code == "" {
  668. return authStatus, isin, "参数错误"
  669. }
  670. 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 {
  671. for _, v := range *r {
  672. //记录所有的统一社会信用代码相同的企业
  673. entids := ""
  674. id := common.Int64All(v["id"])
  675. audit_status := common.Int64All(v["audit_status"])
  676. authStatus = common.IntAll(v["auth_status"])
  677. if audit_status == 1 { //根据统一社会信用代码查看该企业正在审核中
  678. authStatus = 3
  679. return authStatus, isin, ""
  680. }
  681. entids += strconv.Itoa(int(id)) + ","
  682. if entids != "" {
  683. entids = entids[:len(entids)-1]
  684. }
  685. isin = this.Mysql.CountBySql(`select count(1) from entniche_user where ent_id in(?) and phone =?`, entids, this.Phone) > 0
  686. }
  687. }
  688. return authStatus, isin, ""
  689. }
  690. //根据id获取企业信息
  691. func (e *EntInfo) GetById(id int) *EntInfo {
  692. r := e.Mysql.FindOne(Entniche_info, map[string]interface{}{"id": id}, "*", "")
  693. entInfo, _ := common.JsonUnmarshal(r, &EntInfo{}).(*EntInfo)
  694. if entInfo == nil {
  695. return &EntInfo{}
  696. }
  697. return entInfo
  698. }
  699. type EntDeptParent struct {
  700. Id int
  701. Pid int
  702. }
  703. type EntDept struct {
  704. Id int
  705. Pid int
  706. Name string
  707. Nodiff int
  708. Subdis int
  709. }
  710. type EntDistribute struct {
  711. Id string
  712. DeptId int
  713. Area map[string]interface{}
  714. Buyerclass []interface{}
  715. Items []string
  716. }
  717. type EntRuleUser struct {
  718. UserId int
  719. RuleId string
  720. }
  721. //查找父级部门(跨级)
  722. func GetEntDeptParent(mysq *mysql.Mysql, entParentDept map[int][]*EntDeptParent, deptid int) map[int][]*EntDeptParent {
  723. //先获取用户组织架构权益
  724. //查找父级部门(跨级)
  725. list := mysq.SelectBySql(`select id,pid from entniche_department_parent where id =?`, deptid)
  726. for _, v := range *list {
  727. id := common.IntAll(v["id"])
  728. pid := common.IntAll(v["pid"])
  729. entParentDept[id] = append(entParentDept[id], &EntDeptParent{
  730. Id: id,
  731. Pid: pid,
  732. })
  733. }
  734. return entParentDept
  735. }
  736. //查看部门相关设置
  737. func GetEntDepts(mysq *mysql.Mysql, entDepts map[int]*EntDept, entid int64) map[int]*EntDept {
  738. //查看部门相关设置
  739. lis := mysq.SelectBySql(`select * from entniche_department where ent_id=?`, entid)
  740. for _, v := range *lis {
  741. //获取部门相关
  742. deptid := common.IntAll(v["id"])
  743. pid := common.IntAll(v["pid"])
  744. name := common.ObjToString(v["name"])
  745. subdis := common.IntAll(v["subdis"])
  746. nodiff := common.IntAll(v["nodiff"])
  747. entDepts[deptid] = &EntDept{
  748. Id: deptid,
  749. Pid: pid,
  750. Name: name,
  751. Nodiff: nodiff,
  752. Subdis: subdis,
  753. }
  754. }
  755. return entDepts
  756. }
  757. //获取某个用户的所有分发规则
  758. func GetUserRules(mysq *mysql.Mysql, entUserId int64) map[int][]*EntRuleUser {
  759. entUserRules := map[int][]*EntRuleUser{} //用户下所有的分发规则
  760. // 分发规则遍历 查询用户是否有被分发的规则
  761. data := mysq.SelectBySql(`SELECT * FROM entniche_user_rule WHERE user_id=?`, entUserId)
  762. if data != nil {
  763. for _, v := range *data {
  764. ruleId := common.ObjToString(v["rule_id"])
  765. userId := common.IntAll(v["user_id"])
  766. entRuleUser := &EntRuleUser{
  767. UserId: userId,
  768. RuleId: ruleId,
  769. }
  770. entUserRules[userId] = append(entUserRules[userId], entRuleUser)
  771. }
  772. }
  773. return entUserRules
  774. }
  775. //获取企业下的所有分发规则详情
  776. func GetEntDistribute(mgo mongodb.MongodbSim, entId int64) map[string]*EntDistribute {
  777. entDis := map[string]*EntDistribute{} //分发规则的相关设置
  778. //获取具体分发规则
  779. disData, ok := mgo.Find("entniche_distribute", map[string]interface{}{
  780. "i_status": map[string]interface{}{"$ne": 1},
  781. "i_entid": entId,
  782. }, nil, nil, false, -1, -1)
  783. if ok && disData != nil && len(*disData) > 0 {
  784. for _, v := range *disData {
  785. deptId := common.IntAll(v["i_deptid"])
  786. a_items, _ := v["a_items"].([]interface{})
  787. o_area, _ := v["o_area"].(map[string]interface{})
  788. a_buyerclass, _ := v["a_buyerclass"].([]interface{})
  789. ruleId := mongodb.BsonIdToSId(v["_id"])
  790. entDis[ruleId] = &EntDistribute{
  791. Id: ruleId,
  792. DeptId: deptId,
  793. Area: o_area,
  794. Buyerclass: a_buyerclass,
  795. Items: common.ObjArrToStringArr(a_items),
  796. }
  797. }
  798. }
  799. return entDis
  800. }
  801. //根据手机号获取用户商机管理企业
  802. func GetEntByPhone(mys *mysql.Mysql, phone string) (entId, entUserId int64) {
  803. data := mys.SelectBySql(`SELECT a.id entid,b.id as user_id from entniche_info a
  804. INNER JOIN entniche_user b on (b.phone=? and a.id=b.ent_id and a.status=1 and b.power=1)
  805. ORDER BY if(a.createtime<b.createtime,b.createtime,a.createtime) desc limit 1`, phone)
  806. if data != nil && len(*data) > 0 {
  807. entId := common.Int64All((*data)[0]["entid"])
  808. entUserId := common.Int64All((*data)[0]["user_id"])
  809. return entId, entUserId
  810. }
  811. return 0, 0
  812. }
  813. //获取用户资源信息
  814. func GetResources(appId, baseUserId string, entId, entUserId int64) []string {
  815. baseUserIdInt, _ := strconv.ParseInt(baseUserId, 10, 0)
  816. req := &resourcepb.HaspowersReq{
  817. EntId: entId,
  818. UserId: baseUserIdInt,
  819. EntUserId: entUserId,
  820. Appid: appId,
  821. }
  822. powerList, err := ResourceLib.Haspowers(context.Background(), req)
  823. if err == nil && len(powerList.Powers) > 0 {
  824. return powerList.Powers
  825. }
  826. return []string{}
  827. }