ent.go 24 KB

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