entService.go 12 KB

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