智慧食堂
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

678 lines
19 KiB

  1. package hdl
  2. import (
  3. "applet/app/customer/lib/validate"
  4. "applet/app/customer/md"
  5. "applet/app/customer/svc"
  6. "applet/app/db"
  7. "applet/app/db/model"
  8. "applet/app/e"
  9. "applet/app/enum"
  10. "applet/app/utils"
  11. "github.com/gin-gonic/gin"
  12. "time"
  13. )
  14. func SaveCentralKitchenForSchoolUserIdentity(c *gin.Context) {
  15. var req md.SaveCentralKitchenForSchoolUserIdentityReq
  16. err := c.ShouldBindJSON(&req)
  17. if err != nil {
  18. err = validate.HandleValidateErr(err)
  19. err1 := err.(e.E)
  20. e.OutErr(c, err1.Code, err1.Error())
  21. return
  22. }
  23. user := svc.GetUser(c)
  24. var identity = enum.UserIdentityForCentralKitchenForStudent
  25. if req.IsTeacher {
  26. identity = enum.UserIdentityForCentralKitchenForTeacher
  27. }
  28. //1、判断当前身份是否已绑定
  29. userIdentityDb := db.UserIdentityDb{}
  30. userIdentityDb.Set(user.Id)
  31. isHasUserIdentity, err := userIdentityDb.UserIdentityExistV1(req.EnterpriseId, req.Name)
  32. if err != nil {
  33. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  34. return
  35. }
  36. now := time.Now()
  37. if isHasUserIdentity == nil {
  38. //2、新增身份信息
  39. userIdentity := &model.UserIdentity{
  40. Uid: user.Id,
  41. Name: req.Name,
  42. IdNo: req.IdNo,
  43. CertType: enum.UserIdentityCertTypeForIdCard,
  44. Kind: enum.UserIdentityKindForCommon,
  45. Identity: identity,
  46. EnterpriseId: req.EnterpriseId,
  47. State: enum.UserIdentityStateForNormal,
  48. Memo: "",
  49. CreateAt: now.Format("2006-01-02 15:04:05"),
  50. UpdateAt: now.Format("2006-01-02 15:04:05"),
  51. }
  52. insertAffected, err := userIdentityDb.UserIdentityInsert(userIdentity)
  53. if err != nil {
  54. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  55. return
  56. }
  57. if insertAffected <= 0 {
  58. e.OutErr(c, e.ERR_DB_ORM, "新增身份数据失败")
  59. return
  60. }
  61. //3、新增 class_with_user 记录
  62. if !req.IsTeacher {
  63. classWithUserDb := db.ClassWithUserDb{}
  64. classWithUserDb.Set()
  65. _, err = classWithUserDb.ClassWithUserInsert(&model.ClassWithUser{
  66. UserIdentityId: insertAffected,
  67. ClassId: req.ClassId,
  68. CreateAt: now.Format("2006-01-02 15:04:05"),
  69. UpdateAt: now.Format("2006-01-02 15:04:05"),
  70. })
  71. if err != nil {
  72. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  73. return
  74. }
  75. }
  76. } else {
  77. //4、修改身份信息
  78. isHasUserIdentity.Uid = user.Id
  79. isHasUserIdentity.Name = req.Name
  80. isHasUserIdentity.State = enum.UserIdentityStateForNormal
  81. _, err = userIdentityDb.UserIdentityUpdate(isHasUserIdentity.Id, isHasUserIdentity, "uid", "name", "state")
  82. if err != nil {
  83. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  84. return
  85. }
  86. //5、修改 class_with_user 记录
  87. if !req.IsTeacher {
  88. classWithUserDb := db.ClassWithUserDb{}
  89. classWithUserDb.Set()
  90. classWithUser, err1 := classWithUserDb.GetClassWithUserByUserIdentityId(isHasUserIdentity.Id)
  91. if err1 != nil {
  92. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  93. return
  94. }
  95. if classWithUser == nil {
  96. _, err2 := classWithUserDb.ClassWithUserInsert(&model.ClassWithUser{
  97. UserIdentityId: isHasUserIdentity.Id,
  98. ClassId: req.ClassId,
  99. CreateAt: now.Format("2006-01-02 15:04:05"),
  100. UpdateAt: now.Format("2006-01-02 15:04:05"),
  101. })
  102. if err2 != nil {
  103. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  104. return
  105. }
  106. } else {
  107. classWithUser.ClassId = req.ClassId
  108. _, err2 := classWithUserDb.ClassWithUserUpdateByUserIdentity(isHasUserIdentity.Id, classWithUser, "class_id")
  109. if err2 != nil {
  110. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  111. return
  112. }
  113. }
  114. }
  115. }
  116. e.OutSuc(c, "success", nil)
  117. return
  118. }
  119. func SaveSelfSupportForSchoolUserIdentity(c *gin.Context) {
  120. var req md.SaveSelfSupportForSchoolUserIdentityReq
  121. err := c.ShouldBindJSON(&req)
  122. if err != nil {
  123. err = validate.HandleValidateErr(err)
  124. err1 := err.(e.E)
  125. e.OutErr(c, err1.Code, err1.Error())
  126. return
  127. }
  128. user := svc.GetUser(c)
  129. now := time.Now()
  130. var identity = enum.UserIdentityForSelfSupportForStudent
  131. var kind = enum.UserIdentityKindForCommon
  132. if req.CertType == 0 {
  133. req.CertType = enum.UserIdentityCertTypeForIdCard
  134. }
  135. if req.Kind == enum.UserIdentityKindForWorker {
  136. kind = enum.UserIdentityKindForWorker
  137. identity = enum.UserIdentityForSelfSupportForWorker
  138. req.CertType = enum.UserIdentityCertTypeForIdCard
  139. } else {
  140. if req.IsTeacher {
  141. identity = enum.UserIdentityForCentralKitchenForTeacher
  142. }
  143. }
  144. //1、判断当前身份是否已绑定
  145. userIdentityDb := db.UserIdentityDb{}
  146. userIdentityDb.Set(user.Id)
  147. isHasUserIdentity, err := userIdentityDb.UserIdentityExist(req.EnterpriseId, req.IdNo, req.CertType)
  148. if err != nil {
  149. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  150. return
  151. }
  152. if isHasUserIdentity == nil {
  153. if identity != enum.UserIdentityForSelfSupportForStudent {
  154. e.OutErr(c, e.ERR_NO_DATA, "当前身份信息不存在")
  155. return
  156. }
  157. //2、新增身份信息
  158. userIdentity := &model.UserIdentity{
  159. Uid: user.Id,
  160. Name: req.Name,
  161. IdNo: req.IdNo,
  162. CertType: req.CertType,
  163. Kind: kind,
  164. Identity: identity,
  165. EnterpriseId: req.EnterpriseId,
  166. State: enum.UserIdentityStateForNormal,
  167. Memo: "",
  168. CreateAt: now.Format("2006-01-02 15:04:05"),
  169. UpdateAt: now.Format("2006-01-02 15:04:05"),
  170. }
  171. insertAffected, err := userIdentityDb.UserIdentityInsert(userIdentity)
  172. if err != nil {
  173. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  174. return
  175. }
  176. if insertAffected <= 0 {
  177. e.OutErr(c, e.ERR_DB_ORM, "新增身份数据失败")
  178. return
  179. }
  180. //3、新增 class_with_user 记录
  181. if !req.IsTeacher {
  182. classWithUserDb := db.ClassWithUserDb{}
  183. classWithUserDb.Set()
  184. _, err1 := classWithUserDb.ClassWithUserInsert(&model.ClassWithUser{
  185. UserIdentityId: insertAffected,
  186. ClassId: req.ClassId,
  187. CreateAt: now.Format("2006-01-02 15:04:05"),
  188. UpdateAt: now.Format("2006-01-02 15:04:05"),
  189. })
  190. if err1 != nil {
  191. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  192. return
  193. }
  194. }
  195. //4、新增 self_support_for_user_face_info 记录
  196. selfSupportForSchoolInfoDb := db.SelfSupportForSchoolInfoDb{}
  197. selfSupportForSchoolInfoDb.Set(req.EnterpriseId)
  198. selfSupportForSchoolInfo, err := selfSupportForSchoolInfoDb.GetSelfSupportForSchoolInfo()
  199. if err != nil {
  200. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  201. return
  202. }
  203. if selfSupportForSchoolInfo == nil {
  204. e.OutErr(c, e.ERR_NO_DATA, "当前学校暂未完成《一脸通行入驻》")
  205. return
  206. }
  207. selfSupportForUserFaceInfoDb := db.SelfSupportForUserFaceInfoDb{}
  208. selfSupportForUserFaceInfoDb.Set(insertAffected)
  209. _, err2 := selfSupportForUserFaceInfoDb.SelfSupportForUserFaceInfoInsert(&model.SelfSupportForUserFaceInfo{
  210. EnterpriseId: req.EnterpriseId,
  211. UserIdentityId: insertAffected,
  212. CollectFaceType: 1,
  213. SchoolCode: selfSupportForSchoolInfo.SchoolCode,
  214. SchoolStdCode: selfSupportForSchoolInfo.SchoolStdCode,
  215. ParentUserId: "",
  216. ParentLogonId: "",
  217. UserId: "",
  218. SchoolFacePassStatus: "CLOSE",
  219. SchoolFacePaymentStatus: "CLOSE",
  220. ConcentrateSchoolFacePassStatus: 1,
  221. CreateAt: now.Format("2006-01-02 15:04:05"),
  222. UpdateAt: now.Format("2006-01-02 15:04:05"),
  223. })
  224. if err2 != nil {
  225. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  226. return
  227. }
  228. } else {
  229. if isHasUserIdentity.Uid != 0 && isHasUserIdentity.Uid != user.Id {
  230. e.OutErr(c, e.ERR, "当前身份信息已被绑定使用")
  231. return
  232. }
  233. //4、修改身份信息
  234. isHasUserIdentity.Uid = user.Id
  235. isHasUserIdentity.Name = req.Name
  236. isHasUserIdentity.State = enum.UserIdentityStateForNormal
  237. _, err = userIdentityDb.UserIdentityUpdate(isHasUserIdentity.Id, isHasUserIdentity, "uid", "name", "state")
  238. if err != nil {
  239. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  240. return
  241. }
  242. if identity == enum.UserIdentityForSelfSupportForStudent {
  243. //5、修改 class_with_user 记录
  244. classWithUserDb := db.ClassWithUserDb{}
  245. classWithUserDb.Set()
  246. classWithUser, err1 := classWithUserDb.GetClassWithUserByUserIdentityId(isHasUserIdentity.Id)
  247. if err1 != nil {
  248. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  249. return
  250. }
  251. if classWithUser == nil {
  252. _, err2 := classWithUserDb.ClassWithUserInsert(&model.ClassWithUser{
  253. UserIdentityId: isHasUserIdentity.Id,
  254. ClassId: req.ClassId,
  255. CreateAt: now.Format("2006-01-02 15:04:05"),
  256. UpdateAt: now.Format("2006-01-02 15:04:05"),
  257. })
  258. if err2 != nil {
  259. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  260. return
  261. }
  262. } else {
  263. classWithUser.ClassId = req.ClassId
  264. _, err2 := classWithUserDb.ClassWithUserUpdateByUserIdentity(isHasUserIdentity.Id, classWithUser, "class_id")
  265. if err2 != nil {
  266. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  267. return
  268. }
  269. }
  270. }
  271. }
  272. e.OutSuc(c, "success", nil)
  273. return
  274. }
  275. func SaveFactoryUserIdentity(c *gin.Context) {
  276. var req md.SaveFactoryUserIdentityReq
  277. err := c.ShouldBindJSON(&req)
  278. if err != nil {
  279. err = validate.HandleValidateErr(err)
  280. err1 := err.(e.E)
  281. e.OutErr(c, err1.Code, err1.Error())
  282. return
  283. }
  284. user := svc.GetUser(c)
  285. if req.CertType == 0 {
  286. req.CertType = enum.UserIdentityCertTypeForIdCard
  287. }
  288. //1、判断当前身份是否已绑定
  289. userIdentityDb := db.UserIdentityDb{}
  290. userIdentityDb.Set(user.Id)
  291. isHasUserIdentity, err := userIdentityDb.UserIdentityExist(req.EnterpriseId, req.IdNo, req.CertType)
  292. if err != nil {
  293. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  294. return
  295. }
  296. if isHasUserIdentity == nil {
  297. e.OutErr(c, e.ERR_NO_DATA, "当前身份信息不存在")
  298. return
  299. } else {
  300. if isHasUserIdentity.Uid != 0 && isHasUserIdentity.Uid != user.Id {
  301. e.OutErr(c, e.ERR, "当前身份信息已被绑定使用")
  302. return
  303. }
  304. //2、修改身份信息
  305. isHasUserIdentity.Uid = user.Id
  306. isHasUserIdentity.Name = req.Name
  307. isHasUserIdentity.State = enum.UserIdentityStateForNormal
  308. _, err = userIdentityDb.UserIdentityUpdate(isHasUserIdentity.Id, isHasUserIdentity, "uid", "name", "state")
  309. if err != nil {
  310. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  311. return
  312. }
  313. }
  314. e.OutSuc(c, "success", nil)
  315. return
  316. }
  317. func SaveNursingHomeUserIdentity(c *gin.Context) {
  318. var req md.SaveNursingHomeUserIdentityReq
  319. err := c.ShouldBindJSON(&req)
  320. if err != nil {
  321. err = validate.HandleValidateErr(err)
  322. err1 := err.(e.E)
  323. e.OutErr(c, err1.Code, err1.Error())
  324. return
  325. }
  326. user := svc.GetUser(c)
  327. var identity = enum.UserIdentityForNursingHome
  328. //1、判断当前身份是否已绑定
  329. userIdentityDb := db.UserIdentityDb{}
  330. userIdentityDb.Set(user.Id)
  331. isHasUserIdentity, err := userIdentityDb.UserIdentityExist(req.EnterpriseId, req.IdNo, enum.UserIdentityCertTypeForIdCard)
  332. if err != nil {
  333. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  334. return
  335. }
  336. now := time.Now()
  337. if isHasUserIdentity == nil {
  338. //2、新增身份信息
  339. userIdentity := &model.UserIdentity{
  340. Uid: user.Id,
  341. Name: req.Name,
  342. IdNo: req.IdNo,
  343. Kind: enum.UserIdentityKindForCommon,
  344. Identity: identity,
  345. EnterpriseId: req.EnterpriseId,
  346. State: enum.UserIdentityStateForNormal,
  347. Memo: "",
  348. CreateAt: now.Format("2006-01-02 15:04:05"),
  349. UpdateAt: now.Format("2006-01-02 15:04:05"),
  350. }
  351. insertAffected, err := userIdentityDb.UserIdentityInsert(userIdentity)
  352. if err != nil {
  353. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  354. return
  355. }
  356. if insertAffected <= 0 {
  357. e.OutErr(c, e.ERR_DB_ORM, "新增身份数据失败")
  358. return
  359. }
  360. } else {
  361. //4、修改身份信息
  362. isHasUserIdentity.Uid = user.Id
  363. isHasUserIdentity.Name = req.Name
  364. isHasUserIdentity.State = enum.UserIdentityStateForNormal
  365. _, err = userIdentityDb.UserIdentityUpdate(isHasUserIdentity.Id, isHasUserIdentity, "uid", "name", "state")
  366. if err != nil {
  367. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  368. return
  369. }
  370. }
  371. e.OutSuc(c, "success", nil)
  372. return
  373. }
  374. func UpdateCentralKitchenForSchoolUserIdentity(c *gin.Context) {
  375. var req md.UpdateCentralKitchenForSchoolUserIdentityReq
  376. err := c.ShouldBindJSON(&req)
  377. if err != nil {
  378. err = validate.HandleValidateErr(err)
  379. err1 := err.(e.E)
  380. e.OutErr(c, err1.Code, err1.Error())
  381. return
  382. }
  383. user := svc.GetUser(c)
  384. now := time.Now()
  385. //1、查询当前身份是否存在
  386. userIdentityDb := db.UserIdentityDb{}
  387. userIdentityDb.Set(user.Id)
  388. userIdentity, err := userIdentityDb.GetUserIdentity(req.UserIdentityId)
  389. if err != nil {
  390. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  391. return
  392. }
  393. if userIdentity == nil {
  394. e.OutErr(c, e.ERR_NO_DATA, "当前身份信息不存在")
  395. return
  396. }
  397. //2、修改身份信息
  398. userIdentity.Name = req.Name
  399. userIdentity.IdNo = req.IdNo
  400. _, err = userIdentityDb.UserIdentityUpdate(userIdentity.Id, userIdentity, "id_no", "name")
  401. if err != nil {
  402. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  403. return
  404. }
  405. //3、修改 class_with_user 记录
  406. if userIdentity.Identity == enum.UserIdentityForCentralKitchenForStudent {
  407. classWithUserDb := db.ClassWithUserDb{}
  408. classWithUserDb.Set()
  409. classWithUser, err1 := classWithUserDb.GetClassWithUserByUserIdentityId(userIdentity.Id)
  410. if err1 != nil {
  411. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  412. return
  413. }
  414. if classWithUser == nil {
  415. _, err2 := classWithUserDb.ClassWithUserInsert(&model.ClassWithUser{
  416. UserIdentityId: userIdentity.Id,
  417. ClassId: req.ClassId,
  418. CreateAt: now.Format("2006-01-02 15:04:05"),
  419. UpdateAt: now.Format("2006-01-02 15:04:05"),
  420. })
  421. if err2 != nil {
  422. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  423. return
  424. }
  425. } else {
  426. classWithUser.ClassId = req.ClassId
  427. _, err2 := classWithUserDb.ClassWithUserUpdateByUserIdentity(userIdentity.Id, classWithUser, "class_id")
  428. if err2 != nil {
  429. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  430. return
  431. }
  432. }
  433. }
  434. e.OutSuc(c, "success", nil)
  435. return
  436. }
  437. func UpdateSelfSupportForSchoolUserIdentity(c *gin.Context) {
  438. var req md.UpdateSelfSupportForSchoolUserIdentityReq
  439. err := c.ShouldBindJSON(&req)
  440. if err != nil {
  441. err = validate.HandleValidateErr(err)
  442. err1 := err.(e.E)
  443. e.OutErr(c, err1.Code, err1.Error())
  444. return
  445. }
  446. user := svc.GetUser(c)
  447. now := time.Now()
  448. //1、查询当前身份是否存在
  449. userIdentityDb := db.UserIdentityDb{}
  450. userIdentityDb.Set(user.Id)
  451. userIdentity, err := userIdentityDb.GetUserIdentity(req.UserIdentityId)
  452. if err != nil {
  453. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  454. return
  455. }
  456. if userIdentity == nil {
  457. e.OutErr(c, e.ERR_NO_DATA, "当前身份信息不存在")
  458. return
  459. }
  460. //2、修改身份信息
  461. userIdentity.Name = req.Name
  462. userIdentity.IdNo = req.IdNo
  463. _, err = userIdentityDb.UserIdentityUpdate(userIdentity.Id, userIdentity, "id_no", "name")
  464. if err != nil {
  465. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  466. return
  467. }
  468. //3、修改 class_with_user 记录
  469. if userIdentity.Identity == enum.UserIdentityForSelfSupportForStudent {
  470. classWithUserDb := db.ClassWithUserDb{}
  471. classWithUserDb.Set()
  472. classWithUser, err1 := classWithUserDb.GetClassWithUserByUserIdentityId(userIdentity.Id)
  473. if err1 != nil {
  474. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  475. return
  476. }
  477. if classWithUser == nil {
  478. _, err2 := classWithUserDb.ClassWithUserInsert(&model.ClassWithUser{
  479. UserIdentityId: userIdentity.Id,
  480. ClassId: req.ClassId,
  481. CreateAt: now.Format("2006-01-02 15:04:05"),
  482. UpdateAt: now.Format("2006-01-02 15:04:05"),
  483. })
  484. if err2 != nil {
  485. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  486. return
  487. }
  488. } else {
  489. classWithUser.ClassId = req.ClassId
  490. _, err2 := classWithUserDb.ClassWithUserUpdateByUserIdentity(userIdentity.Id, classWithUser, "class_id")
  491. if err2 != nil {
  492. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  493. return
  494. }
  495. }
  496. }
  497. e.OutSuc(c, "success", nil)
  498. return
  499. }
  500. func UpdateFactoryUserIdentity(c *gin.Context) {
  501. var req md.UpdateFactoryUserIdentityReq
  502. err := c.ShouldBindJSON(&req)
  503. if err != nil {
  504. err = validate.HandleValidateErr(err)
  505. err1 := err.(e.E)
  506. e.OutErr(c, err1.Code, err1.Error())
  507. return
  508. }
  509. user := svc.GetUser(c)
  510. //1、查询当前身份是否存在
  511. userIdentityDb := db.UserIdentityDb{}
  512. userIdentityDb.Set(user.Id)
  513. userIdentity, err := userIdentityDb.GetUserIdentity(req.UserIdentityId)
  514. if err != nil {
  515. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  516. return
  517. }
  518. if userIdentity == nil {
  519. e.OutErr(c, e.ERR_NO_DATA, "当前身份信息不存在")
  520. return
  521. }
  522. //2、修改身份信息
  523. userIdentity.Name = req.Name
  524. userIdentity.IdNo = req.IdNo
  525. _, err = userIdentityDb.UserIdentityUpdate(userIdentity.Id, userIdentity, "id_no", "name")
  526. if err != nil {
  527. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  528. return
  529. }
  530. e.OutSuc(c, "success", nil)
  531. return
  532. }
  533. func UpdateNursingHomeUserIdentity(c *gin.Context) {
  534. var req md.UpdateNursingHomeUserIdentityReq
  535. err := c.ShouldBindJSON(&req)
  536. if err != nil {
  537. err = validate.HandleValidateErr(err)
  538. err1 := err.(e.E)
  539. e.OutErr(c, err1.Code, err1.Error())
  540. return
  541. }
  542. user := svc.GetUser(c)
  543. //1、查询当前身份是否存在
  544. userIdentityDb := db.UserIdentityDb{}
  545. userIdentityDb.Set(user.Id)
  546. userIdentity, err := userIdentityDb.GetUserIdentity(req.UserIdentityId)
  547. if err != nil {
  548. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  549. return
  550. }
  551. if userIdentity == nil {
  552. e.OutErr(c, e.ERR_NO_DATA, "当前身份信息不存在")
  553. return
  554. }
  555. //2、修改身份信息
  556. userIdentity.Name = req.Name
  557. userIdentity.IdNo = req.IdNo
  558. _, err = userIdentityDb.UserIdentityUpdate(userIdentity.Id, userIdentity, "id_no", "name")
  559. if err != nil {
  560. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  561. return
  562. }
  563. e.OutSuc(c, "success", nil)
  564. return
  565. }
  566. func DeleteUserIdentity(c *gin.Context) {
  567. userIdentityId := utils.StrToInt(c.Param("id"))
  568. user := svc.GetUser(c)
  569. //1、查询当前身份是否存在
  570. userIdentityDb := db.UserIdentityDb{}
  571. userIdentityDb.Set(user.Id)
  572. userIdentity, err := userIdentityDb.GetUserIdentity(userIdentityId)
  573. if err != nil {
  574. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  575. return
  576. }
  577. if userIdentity == nil {
  578. e.OutErr(c, e.ERR_NO_DATA, "当前身份信息不存在")
  579. return
  580. }
  581. switch userIdentity.Identity {
  582. case enum.UserIdentityForCentralKitchenForStudent:
  583. err1 := svc.DeleteUserIdentityForCentralKitchenForStudent(userIdentity.Id)
  584. if err1 != nil {
  585. e.OutErr(c, e.ERR, err1.Error())
  586. return
  587. }
  588. break
  589. case enum.UserIdentityForCentralKitchenForTeacher:
  590. err1 := svc.DeleteUserIdentityForCentralKitchenForTeacher(userIdentity.Id)
  591. if err1 != nil {
  592. e.OutErr(c, e.ERR, err1.Error())
  593. return
  594. }
  595. break
  596. case enum.UserIdentityForCentralKitchenForWorker:
  597. break
  598. case enum.UserIdentityForSelfSupportForStudent:
  599. err1 := svc.DeleteUserIdentityForSelfSupportForStudent(userIdentity.Id)
  600. if err1 != nil {
  601. e.OutErr(c, e.ERR, err1.Error())
  602. return
  603. }
  604. break
  605. case enum.UserIdentityForSelfSupportForTeacher:
  606. err1 := svc.DeleteUserIdentityForSelfSupportForTeacher(userIdentity.Id)
  607. if err1 != nil {
  608. e.OutErr(c, e.ERR, err1.Error())
  609. return
  610. }
  611. break
  612. case enum.UserIdentityForSelfSupportForWorker:
  613. err1 := svc.DeleteUserIdentityForSelfSupportForWorker(userIdentity.Id)
  614. if err1 != nil {
  615. e.OutErr(c, e.ERR, err1.Error())
  616. return
  617. }
  618. break
  619. case enum.UserIdentityForFactory:
  620. err1 := svc.DeleteUserIdentityForFactory(userIdentity.Id)
  621. if err1 != nil {
  622. e.OutErr(c, e.ERR, err1.Error())
  623. return
  624. }
  625. break
  626. case enum.UserIdentityForNursingHome:
  627. err1 := svc.DeleteUserIdentityForNursingHome(userIdentity.Id)
  628. if err1 != nil {
  629. e.OutErr(c, e.ERR, err1.Error())
  630. return
  631. }
  632. break
  633. }
  634. e.OutSuc(c, "success", nil)
  635. return
  636. }