ent.go 25 KB

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