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. 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: data.OrganizationType, //机构类型 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, 0
  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, 0
  64. }
  65. //
  66. if ent_name != entinfo.Name { //企业名称不同、统一社会信用代码相同
  67. return entity.ErrorCode, APPROVEDMSG, entity.ErrorCode, 0
  68. }
  69. }
  70. entinfo.Id = int(id)
  71. // entinfo.Phone = phone //更换注册人手机号为管理员手机号
  72. if entinfo.Update() {
  73. return entity.SuccessCode, OKMSG, 1, int64(entinfo.Id)
  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 ok, entid := entinfo.Add(); ok {
  89. return entity.SuccessCode, OKMSG, 1, entid
  90. }
  91. }
  92. if audit_status == 1 {
  93. return entity.ErrorCode, EXAMINEINGMSG, entity.ErrorCode, 0
  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, 0
  99. }
  100. }
  101. entinfo.Id = int(id)
  102. // entinfo.Phone = phone //更换注册人手机号为管理员手机号
  103. if entinfo.Update() {
  104. return entity.SuccessCode, OKMSG, 1, int64(entinfo.Id)
  105. }
  106. }
  107. }
  108. if ok, id := entinfo.Add(); ok {
  109. return entity.SuccessCode, OKMSG, 1, id
  110. }
  111. return entity.ErrorCode, "", entity.ErrorCode, 0
  112. }
  113. //机构审核
  114. func (this *EntService) Examinet(data *userCenter.ExamineReq) (int64, string, int64) {
  115. if data.EntId == 0 || data.ExamineId == "" {
  116. return -1, "参数异常", 0
  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. ResourceLib: entity.ResourceLib,
  126. }
  127. if info.EntExamine() {
  128. return 1, "", 0
  129. }
  130. //修改状态
  131. return -1, "修改失败", -1
  132. }
  133. //企业列表
  134. func (this *EntService) EntList(data *userCenter.EntListReq) (int64, string, *userCenter.EntData) {
  135. info := &entity.List{
  136. Name: data.Name,
  137. AuthStatus: data.AuthStatus,
  138. PageNum: data.PageNum,
  139. PageSize: data.PageSize,
  140. CreditCode: data.CreditCode,
  141. CreateStartTime: data.CreateStartTime,
  142. CreateEndTime: data.CreateEndTime,
  143. ValidStartTime: data.ValidStartTime,
  144. ValidEndTime: data.ValidEndTime,
  145. FrozenStatus: data.FrozenStatus,
  146. RegPhone: data.RegPhone,
  147. AuthPhone: data.AuthPhone,
  148. Mysql: entity.Mysql,
  149. }
  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.ObjToString(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 0, "", &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 0, "", &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, int64) {
  210. info := &entity.CheckEnt{
  211. EntId: data.EntId,
  212. Mysql: entity.Mysql,
  213. }
  214. authStatus, frozenStatus, msg := info.Check()
  215. return authStatus, frozenStatus, msg, common.Int64All(common.If(msg == "", entity.SuccessCode, entity.ErrorCode))
  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. CreateTime: rdata.CreateTime,
  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. }