entService.go 12 KB

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