entService.go 12 KB

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