entService.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. package service
  2. import (
  3. "fmt"
  4. "strconv"
  5. "time"
  6. "app.yhyue.com/moapp/jybase/common"
  7. "userCenter/entity"
  8. userCenter "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 info.EntExamine() {
  148. return 1, "", 0
  149. }
  150. //修改状态
  151. return -1, "修改失败", -1
  152. }
  153. //企业列表
  154. func (this *EntService) EntList(data *userCenter.EntListReq) (int64, string, *userCenter.EntData) {
  155. info := &entity.List{
  156. Name: data.Name,
  157. AuthStatus: data.AuthStatus,
  158. PageNum: data.PageNum,
  159. PageSize: data.PageSize,
  160. CreditCode: data.CreditCode,
  161. CreateStartTime: data.CreateStartTime,
  162. CreateEndTime: data.CreateEndTime,
  163. ValidStartTime: data.ValidStartTime,
  164. ValidEndTime: data.ValidEndTime,
  165. FrozenStatus: data.FrozenStatus,
  166. RegPhone: data.RegPhone,
  167. AuthPhone: data.AuthPhone,
  168. Mysql: entity.Mysql,
  169. }
  170. r, count := info.List()
  171. pageSize := common.If(data.PageSize != "", data.PageSize, "10").(string)
  172. i_pageSize, _ := strconv.Atoi(pageSize)
  173. list := []*userCenter.EntList{}
  174. for _, v := range *r {
  175. list = append(list, &userCenter.EntList{
  176. Id: common.Int64All(v["id"]), //机构id
  177. ComPanyType: common.Int64All(v["comPanyType"]), // 机构性质 1企业 2党政机关事业单位及其他
  178. Name: common.ObjToString(v["name"]), //机构名称
  179. OrganizationType: common.ObjToString(v["organizationType"]), //机构类型 1企业 2党政机关事业单位及其他
  180. Createtime: common.ObjToString(v["createTime"]), //创建时间
  181. ValidTime: common.ObjToString(v["validTime"]), //有效截至日期
  182. AuthStatus: common.Int64All(v["authStatus"]), //认证状态
  183. FrozenStatus: common.Int64All(v["frozenStatus"]),
  184. })
  185. }
  186. return 0, "", &userCenter.EntData{
  187. Count: count,
  188. PageSize: int64(i_pageSize),
  189. List: list,
  190. }
  191. }
  192. //审核列表
  193. func (this *EntService) ExamineList(data *userCenter.ExamineListReq) (int64, string, *userCenter.ExamineListData) {
  194. info := &entity.ExamineList{
  195. Name: data.Name,
  196. AuthPhone: data.AuthPhone,
  197. RegPhone: data.RegPhone,
  198. AuthType: data.AuthType, //审核状态 1:待审核 2:审核通过 3:审核不通过
  199. AuthStartTime: data.AuthStartTime, //申请开始时间
  200. AuthEndTime: data.AuthEndTime, //申请结束时间
  201. PageNum: data.PageNum, //页码
  202. PageSize: data.PageSize, //每页展示条数
  203. Mysql: entity.Mysql,
  204. }
  205. r, count := info.List()
  206. pageSize := common.If(data.PageSize != "", data.PageSize, "10").(string)
  207. i_pageSize, _ := strconv.Atoi(pageSize)
  208. list := []*userCenter.ExamineList{}
  209. for _, v := range *r {
  210. list = append(list, &userCenter.ExamineList{
  211. Id: common.Int64All(v["id"]),
  212. EntId: common.Int64All(v["entId"]),
  213. ComPanyType: common.Int64All(v["comPanyType"]), // 机构性质 1企业 2党政机关事业单位及其他
  214. Name: common.ObjToString(v["name"]), //机构名称
  215. CreditCode: common.ObjToString(v["creditCode"]), //统一社会信用代码
  216. AuthPhone: common.ObjToString(v["authPhone"]), //联系人手机号
  217. ApplyTime: common.ObjToString(v["authTime"]), //申请时间戳
  218. AuthType: common.Int64All(v["authStatus"]), //审核状态
  219. RegPhone: common.ObjToString(v["regPhone"]),
  220. })
  221. }
  222. return 0, "", &userCenter.ExamineListData{
  223. Count: count,
  224. PageSize: int64(i_pageSize),
  225. List: list,
  226. }
  227. }
  228. func (this *EntService) CheckEnt(data *userCenter.CheckEntReq) (int64, int64, string, int64) {
  229. info := &entity.CheckEnt{
  230. EntId: data.EntId,
  231. Mysql: entity.Mysql,
  232. }
  233. authStatus, frozenStatus, msg := info.Check()
  234. return authStatus, frozenStatus, msg, common.Int64All(common.If(msg == "", entity.SuccessCode, entity.ErrorCode))
  235. }
  236. //企业信息
  237. func (this *EntService) Info(data *userCenter.CheckEntReq) (int64, string, *userCenter.EntInfoData) {
  238. info := &entity.CheckEnt{
  239. EntId: data.EntId,
  240. Mysql: entity.Mysql,
  241. Url: this.Url,
  242. }
  243. rdata := info.Info()
  244. entInfoData := &userCenter.EntInfoData{
  245. Name: rdata.Name,
  246. OrganizationType: rdata.OrganizationType,
  247. CreditCode: rdata.CreditCode,
  248. CompanyType: rdata.CompanyType,
  249. AreaNumber: rdata.AreaNumber,
  250. Business: rdata.Business,
  251. OfficialLetter: rdata.OfficialLetter,
  252. AuthStartTime: rdata.AuthStartTime,
  253. AuthEndTime: rdata.AuthEndTime,
  254. ForzenStatus: rdata.ForzenStatus,
  255. AuthState: rdata.AuthState,
  256. ContactPerson: rdata.ContactPerson,
  257. ContactPhone: rdata.ContactPhone,
  258. AuthType: rdata.AuthType,
  259. CreateTime: rdata.CreateTime,
  260. AuthReason: rdata.AuthReason,
  261. }
  262. return 0, "", entInfoData
  263. }
  264. func (this *EntService) UpdateEnt(data *userCenter.EntUpdateReq) (int64, string, int64) {
  265. info := &entity.UpdateEnt{
  266. EntId: data.EntId,
  267. UpdateType: data.UpdateType,
  268. Mysql: entity.Mysql,
  269. ResourceLib: entity.ResourceLib,
  270. }
  271. status, msg := info.UpdateEnt()
  272. return 0, msg, status
  273. }
  274. func (this *EntService) ExamineInfo(data *userCenter.CheckExamineReq) (int64, string, *userCenter.EntInfoData) {
  275. info := &entity.ExamineInfo{
  276. ExamineId: data.ExamineId,
  277. Mysql: entity.Mysql,
  278. }
  279. rdata := info.Info()
  280. entInfoData := &userCenter.EntInfoData{
  281. Name: rdata.Name,
  282. OrganizationType: rdata.OrganizationType,
  283. CreditCode: rdata.CreditCode,
  284. CompanyType: rdata.CompanyType,
  285. AreaNumber: rdata.AreaNumber,
  286. Business: rdata.Business,
  287. OfficialLetter: rdata.OfficialLetter,
  288. AuthState: rdata.AuthState,
  289. ContactPerson: rdata.ContactPerson,
  290. ContactPhone: rdata.ContactPhone,
  291. RegPhone: rdata.RegPhone,
  292. AuthTime: rdata.AuthTime,
  293. AuthReason: rdata.AuthReason,
  294. AuditUser: rdata.AuditUser,
  295. AuditTime: rdata.AuditTime,
  296. }
  297. return 0, "", entInfoData
  298. }
  299. func (this *EntService) GetStatusByCode(data *userCenter.GetStatusByCodeReq) (int, bool, string) {
  300. info := &entity.GetStatusByCodeStruct{
  301. Mysql: entity.Mysql,
  302. Code: data.Code,
  303. Phone: data.Phone,
  304. }
  305. return info.GetStatusByCode()
  306. }
  307. //根据entid 获取员工 信息
  308. func (this *EntService) GetEntUserInfo(data *userCenter.EntUserReq) (*entity.User, string) {
  309. info := &entity.EntUserInfo{
  310. Mysql: entity.Mysql,
  311. EntUserId: data.EntUserId,
  312. EntId: data.EntId,
  313. }
  314. return info.GetEntUserInfo()
  315. }
  316. //获取部门及子部门的员工列表
  317. func (this *EntService) GetEntUserList(data *userCenter.EntUserListReq) ([]*userCenter.EntUserListData, string) {
  318. info := &entity.EntUserList{
  319. Mysql: entity.Mysql,
  320. EntId: data.EntId,
  321. DeptId: data.DeptId,
  322. Name: data.Name,
  323. }
  324. return info.GetEntUserList()
  325. }
  326. //判断是否是企业管理员
  327. func (this *EntService) CheckEntUserAdmin(data *userCenter.EntUserReq) (int64, string) {
  328. info := &entity.EntUserInfo{
  329. Mysql: entity.Mysql,
  330. EntUserId: data.EntUserId,
  331. EntId: data.EntId,
  332. }
  333. return info.CheckEntAdmin()
  334. }