entService.go 10 KB

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