ent.go 29 KB

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