entService.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. package service
  2. import (
  3. "log"
  4. "strconv"
  5. "time"
  6. "app.yhyue.com/moapp/jybase/common"
  7. "bp.jydev.jianyu360.cn/BaseService/userCenter/entity"
  8. userCenter "bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/usercenter"
  9. )
  10. type EntService struct{}
  11. //创建企业用户
  12. /*
  13. 根据统一社会信用代码判断
  14. 查询是否已存在该企业
  15. 若无该企业
  16. 创建新企业
  17. 存在该企业
  18. 老企业更新
  19. */
  20. const (
  21. EXAMINEINGMSG = "该机构正在审核中,无法提交认证申请"
  22. APPROVEDMSG = "该机构已完成认证,无法提交认证申请"
  23. OKMSG = "提交成功"
  24. )
  25. func (this *EntService) CreateEnt(data *userCenter.EntAuthReq) (int64, string, int64) {
  26. if data.Name == "" || data.Phone == "" || data.CreditCode == "" {
  27. return entity.ErrorCode, "参数异常", entity.ErrorCode
  28. }
  29. organType, _ := strconv.Atoi(data.OrganizationType)
  30. authType, _ := strconv.Atoi(data.ComPanyType)
  31. entinfo := &entity.EntInfo{
  32. Name: data.Name, //企业名称
  33. Phone: data.Phone, //注册人手机号
  34. Code: data.CreditCode, //统一社会信用代码
  35. Createtime: time.Now().Format("2006-01-02 15:04:05"),
  36. Organization_type: organType, //机构类型 1投标企业 2招标采购单位 3厂商 4招标代理机构 5经销商 6服务提供商 7其他
  37. Auth_type: authType, // 认证类型 1-事业单位 0-企业
  38. License: data.Business, //营业执照
  39. Official_letter: data.OfficialLetter, //认证公函
  40. Linkman_phone: data.AuthPhone, //联系人手机号
  41. Linkman_name: data.AuthName, //联系人姓名
  42. AreaNumber: data.AreaNumber, //
  43. Frozen_status: 1,
  44. Auth_status: 0,
  45. Audit_status: 1,
  46. Mysql: entity.Mysql,
  47. }
  48. //存在统一社会信用代码
  49. r := entity.Mysql.SelectBySql(`select id,audit_status,auth_status,name,phone from entniche_info where code =?`, data.CreditCode)
  50. if r != nil && len(*r) > 0 {
  51. for _, v := range *r {
  52. id, _ := v["id"].(int64)
  53. audit_status, _ := v["audit_status"].(int64)
  54. auth_status, _ := v["auth_status"].(int64)
  55. ent_name, _ := v["name"].(string)
  56. phone, _ := v["phone"].(string)
  57. if audit_status == 1 {
  58. return entity.ErrorCode, EXAMINEINGMSG, entity.ErrorCode
  59. }
  60. if auth_status == 1 { //已认证
  61. list := entity.Mysql.SelectBySql(`select * from entniche_user where ent_id =? and phone =?`, id, entinfo.Phone)
  62. if len(*list) <= 0 {
  63. return entity.ErrorCode, APPROVEDMSG, entity.ErrorCode
  64. }
  65. //
  66. if ent_name != entinfo.Name { //企业名称不同、统一社会信用代码相同
  67. return entity.ErrorCode, APPROVEDMSG, entity.ErrorCode
  68. }
  69. }
  70. entinfo.Id = int(id)
  71. entinfo.Phone = phone //更换注册人手机号为管理员手机号
  72. if entinfo.Update() {
  73. return entity.SuccessCode, OKMSG, entity.SuccessCode
  74. }
  75. }
  76. }
  77. //不存在统一社会信用代码
  78. r = entity.Mysql.SelectBySql(`select id,audit_status,auth_status,name,phone from entniche_info where id =?`, data.EntId)
  79. if r != nil && len(*r) > 0 {
  80. for _, v := range *r {
  81. id, _ := v["id"].(int64)
  82. audit_status, _ := v["audit_status"].(int64)
  83. auth_status, _ := v["auth_status"].(int64)
  84. ent_name, _ := v["name"].(string)
  85. phone, _ := v["phone"].(string)
  86. //该企业下员工 可以重新认证
  87. if ent_name != entinfo.Name { //企业名称不同 创建全新企业
  88. if entinfo.Add() {
  89. return entity.SuccessCode, OKMSG, entity.SuccessCode
  90. }
  91. }
  92. if audit_status == 1 {
  93. return entity.ErrorCode, EXAMINEINGMSG, entity.ErrorCode
  94. }
  95. if auth_status == 1 { //已认证
  96. list := entity.Mysql.SelectBySql(`select * from entniche_user where ent_id =? and phone =?`, id, entinfo.Phone)
  97. if len(*list) <= 0 {
  98. return entity.ErrorCode, APPROVEDMSG, entity.ErrorCode
  99. }
  100. }
  101. entinfo.Id = int(id)
  102. entinfo.Phone = phone //更换注册人手机号为管理员手机号
  103. if entinfo.Update() {
  104. return entity.SuccessCode, OKMSG, entity.SuccessCode
  105. }
  106. }
  107. }
  108. if entinfo.Add() {
  109. return entity.SuccessCode, OKMSG, entity.SuccessCode
  110. }
  111. return entity.ErrorCode, "", entity.ErrorCode
  112. }
  113. //机构审核
  114. func (this *EntService) Examinet(data *userCenter.ExamineReq) (int64, string) {
  115. if data.EntId == 0 || data.ExamineId == "" {
  116. return entity.ErrorCode, "参数异常"
  117. }
  118. info := &entity.Examine{
  119. ExamineId: data.ExamineId,
  120. EntId: data.EntId,
  121. Reason: data.Reason,
  122. AuthType: data.AuthType,
  123. AuditUser: data.AuditUser,
  124. Mysql: entity.Mysql,
  125. }
  126. if info.EntExamine() {
  127. return entity.SuccessCode, ""
  128. }
  129. //修改状态
  130. return entity.ErrorCode, "修改失败"
  131. }
  132. //企业列表
  133. func (this *EntService) EntList(data *userCenter.EntListReq) (int64, string, *userCenter.EntData) {
  134. info := &entity.List{
  135. Name: data.Name,
  136. AuthStatus: data.AuthStatus,
  137. PageNum: data.PageNum,
  138. PageSize: data.PageSize,
  139. CreditCode: data.CreditCode,
  140. CreateStartTime: data.CreateStartTime,
  141. CreateEndTime: data.CreateEndTime,
  142. ValidStartTime: data.ValidStartTime,
  143. ValidEndTime: data.ValidEndTime,
  144. FrozenStatus: data.FrozenStatus,
  145. RegPhone: data.RegPhone,
  146. AuthPhone: data.AuthPhone,
  147. Mysql: entity.Mysql,
  148. }
  149. log.Println("--------", data)
  150. r, count := info.List()
  151. pageSize := common.If(data.PageSize != "", data.PageSize, "10").(string)
  152. i_pageSize, _ := strconv.Atoi(pageSize)
  153. list := []*userCenter.EntList{}
  154. for _, v := range *r {
  155. log.Println(v)
  156. list = append(list, &userCenter.EntList{
  157. Id: common.Int64All(v["id"]), //机构id
  158. ComPanyType: common.Int64All(v["comPanyType"]), // 机构性质 1企业 2党政机关事业单位及其他
  159. Name: common.ObjToString(v["name"]), //机构名称
  160. OrganizationType: common.Int64All(v["organizationType"]), //机构类型 1企业 2党政机关事业单位及其他
  161. Createtime: common.ObjToString(v["createTime"]), //创建时间
  162. ValidTime: common.ObjToString(v["validTime"]), //有效截至日期
  163. AuthStatus: common.Int64All(v["authStatus"]), //认证状态
  164. FrozenStatus: common.Int64All(v["frozenStatus"]),
  165. })
  166. }
  167. return entity.SuccessCode, "", &userCenter.EntData{
  168. Count: count,
  169. PageSize: int64(i_pageSize),
  170. List: list,
  171. }
  172. }
  173. //审核列表
  174. func (this *EntService) ExamineList(data *userCenter.ExamineListReq) (int64, string, *userCenter.ExamineListData) {
  175. info := &entity.ExamineList{
  176. Name: data.Name,
  177. AuthPhone: data.AuthPhone,
  178. RegPhone: data.RegPhone,
  179. AuthType: data.AuthType, //审核状态 1:待审核 2:审核通过 3:审核不通过
  180. AuthStartTime: data.AuthStartTime, //申请开始时间
  181. AuthEndTime: data.AuthEndTime, //申请结束时间
  182. PageNum: data.PageNum, //页码
  183. PageSize: data.PageSize, //每页展示条数
  184. Mysql: entity.Mysql,
  185. }
  186. r, count := info.List()
  187. pageSize := common.If(data.PageSize != "", data.PageSize, "10").(string)
  188. i_pageSize, _ := strconv.Atoi(pageSize)
  189. list := []*userCenter.ExamineList{}
  190. for _, v := range *r {
  191. list = append(list, &userCenter.ExamineList{
  192. Id: common.Int64All(v["id"]),
  193. EntId: common.Int64All(v["entId"]),
  194. ComPanyType: common.Int64All(v["companyType"]), // 机构性质 1企业 2党政机关事业单位及其他
  195. Name: common.ObjToString(v["name"]), //机构名称
  196. CreditCode: common.ObjToString(v["creditCode"]), //统一社会信用代码
  197. AuthPhone: common.ObjToString(v["authPhone"]), //联系人手机号
  198. ApplyTime: common.ObjToString(v["authTime"]), //申请时间戳
  199. AuthType: common.Int64All(v["authStatus"]), //审核状态
  200. RegPhone: common.ObjToString(v["regPhone"]),
  201. })
  202. }
  203. return entity.SuccessCode, "", &userCenter.ExamineListData{
  204. Count: count,
  205. PageSize: int64(i_pageSize),
  206. List: list,
  207. }
  208. }
  209. func (this *EntService) CheckEnt(data *userCenter.CheckEntReq) (int64, int64, string) {
  210. info := &entity.CheckEnt{
  211. EntId: data.EntId,
  212. Mysql: entity.Mysql,
  213. }
  214. authStatus, frozenStatus, msg := info.Check()
  215. return authStatus, frozenStatus, msg
  216. }
  217. //企业信息
  218. func (this *EntService) Info(data *userCenter.CheckEntReq) (int64, string, *userCenter.EntInfoData) {
  219. info := &entity.CheckEnt{
  220. EntId: data.EntId,
  221. Mysql: entity.Mysql,
  222. }
  223. rdata := info.Info()
  224. entInfoData := &userCenter.EntInfoData{
  225. Name: rdata.Name,
  226. OrganizationType: rdata.OrganizationType,
  227. CreditCode: rdata.CreditCode,
  228. CompanyType: rdata.CompanyType,
  229. AreaNumber: rdata.AreaNumber,
  230. Business: rdata.Business,
  231. OfficialLetter: rdata.OfficialLetter,
  232. AuthStartTime: rdata.AuthStartTime,
  233. AuthEndTime: rdata.AuthEndTime,
  234. ForzenStatus: rdata.ForzenStatus,
  235. AuthState: rdata.AuthState,
  236. ContactPerson: rdata.ContactPerson,
  237. ContactPhone: rdata.ContactPhone,
  238. AuthType: rdata.AuthType,
  239. }
  240. return entity.SuccessCode, "", entInfoData
  241. }
  242. func (this *EntService) UpdateEnt(data *userCenter.EntUpdateReq) (int64, string, int64) {
  243. info := &entity.UpdateEnt{
  244. EntId: data.EntId,
  245. UpdateType: data.UpdateType,
  246. Mysql: entity.Mysql,
  247. }
  248. status, msg := info.UpdateEnt()
  249. return entity.SuccessCode, msg, status
  250. }
  251. func (this *EntService) ExamineInfo(data *userCenter.CheckExamineReq) (int64, string, *userCenter.EntInfoData) {
  252. info := &entity.ExamineInfo{
  253. ExamineId: data.ExamineId,
  254. Mysql: entity.Mysql,
  255. }
  256. rdata := info.Info()
  257. entInfoData := &userCenter.EntInfoData{
  258. Name: rdata.Name,
  259. OrganizationType: rdata.OrganizationType,
  260. CreditCode: rdata.CreditCode,
  261. CompanyType: rdata.CompanyType,
  262. AreaNumber: rdata.AreaNumber,
  263. Business: rdata.Business,
  264. OfficialLetter: rdata.OfficialLetter,
  265. AuthState: rdata.AuthState,
  266. ContactPerson: rdata.ContactPerson,
  267. ContactPhone: rdata.ContactPhone,
  268. RegPhone: rdata.RegPhone,
  269. AuthTime: rdata.AuthTime,
  270. AuthReason: rdata.AuthReason,
  271. AuditUser: rdata.AuditUser,
  272. AuditTime: rdata.AuditTime,
  273. }
  274. return entity.SuccessCode, "", entInfoData
  275. }