智慧食堂
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

hdl_user_identity.go 14 KiB

1 ano atrás
1 ano atrás
1 ano atrás
1 ano atrás
1 ano atrás
1 ano atrás
1 ano atrás
1 ano atrás
1 ano atrás
1 ano atrás
1 ano atrás
1 ano atrás
1 ano atrás
1 ano atrás
1 ano atrás
1 ano atrás
1 ano atrás
1 ano atrás
1 ano atrás
1 ano atrás
1 ano atrás
1 ano atrás
1 ano atrás
1 ano atrás
1 ano atrás
1 ano atrás
1 ano atrás
1 ano atrás
1 ano atrás
1 ano atrás
1 ano atrás
1 ano atrás
1 ano atrás
1 ano atrás
1 ano atrás
1 ano atrás
1 ano atrás
1 ano atrás
1 ano atrás
1 ano atrás
1 ano atrás
1 ano atrás
1 ano atrás
1 ano atrás
1 ano atrás
1 ano atrás
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  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.UserIdentityExist(req.EnterpriseId, req.IdNo)
  32. if err != nil {
  33. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  34. return
  35. }
  36. now := time.Time{}
  37. if isHasUserIdentity == nil {
  38. //2、新增身份信息
  39. userIdentity := &model.UserIdentity{
  40. Uid: user.Id,
  41. Name: req.Name,
  42. IdNo: req.IdNo,
  43. Kind: enum.UserIdentityKindForCommon,
  44. Identity: identity,
  45. EnterpriseId: req.EnterpriseId,
  46. State: enum.UserIdentityStateForNormal,
  47. Memo: "",
  48. CreateAt: now.Format("2006-01-02 15:04:05"),
  49. UpdateAt: now.Format("2006-01-02 15:04:05"),
  50. }
  51. insertAffected, err := userIdentityDb.UserIdentityInsert(userIdentity)
  52. if err != nil {
  53. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  54. return
  55. }
  56. if insertAffected <= 0 {
  57. e.OutErr(c, e.ERR_DB_ORM, "新增身份数据失败")
  58. return
  59. }
  60. //3、新增 class_with_user 记录
  61. if !req.IsTeacher {
  62. classWithUserDb := db.ClassWithUserDb{}
  63. classWithUserDb.Set()
  64. _, err = classWithUserDb.ClassWithUserInsert(&model.ClassWithUser{
  65. UserIdentityId: insertAffected,
  66. ClassId: req.ClassId,
  67. CreateAt: now.Format("2006-01-02 15:04:05"),
  68. UpdateAt: now.Format("2006-01-02 15:04:05"),
  69. })
  70. if err != nil {
  71. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  72. return
  73. }
  74. }
  75. } else {
  76. if isHasUserIdentity.Uid != user.Id {
  77. e.OutErr(c, e.ERR, "当前身份信息已被绑定使用")
  78. return
  79. }
  80. //4、修改身份信息
  81. isHasUserIdentity.Uid = user.Id
  82. isHasUserIdentity.Name = req.Name
  83. isHasUserIdentity.State = enum.UserIdentityStateForNormal
  84. _, err = userIdentityDb.UserIdentityUpdate(isHasUserIdentity.Id, isHasUserIdentity, "uid", "name", "state")
  85. if err != nil {
  86. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  87. return
  88. }
  89. //5、修改 class_with_user 记录
  90. if !req.IsTeacher {
  91. classWithUserDb := db.ClassWithUserDb{}
  92. classWithUserDb.Set()
  93. classWithUser, err1 := classWithUserDb.GetClassWithUserByUserIdentityId(isHasUserIdentity.Id)
  94. if err1 != nil {
  95. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  96. return
  97. }
  98. if classWithUser == nil {
  99. _, err2 := classWithUserDb.ClassWithUserInsert(&model.ClassWithUser{
  100. UserIdentityId: isHasUserIdentity.Id,
  101. ClassId: req.ClassId,
  102. CreateAt: now.Format("2006-01-02 15:04:05"),
  103. UpdateAt: now.Format("2006-01-02 15:04:05"),
  104. })
  105. if err2 != nil {
  106. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  107. return
  108. }
  109. } else {
  110. classWithUser.ClassId = req.ClassId
  111. _, err2 := classWithUserDb.ClassWithUserUpdateByUserIdentity(isHasUserIdentity.Id, classWithUser, "class_id")
  112. if err2 != nil {
  113. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  114. return
  115. }
  116. }
  117. }
  118. }
  119. e.OutSuc(c, "success", nil)
  120. return
  121. }
  122. func SaveSelfSupportForSchoolUserIdentity(c *gin.Context) {
  123. var req md.SaveSelfSupportForSchoolUserIdentityReq
  124. err := c.ShouldBindJSON(&req)
  125. if err != nil {
  126. err = validate.HandleValidateErr(err)
  127. err1 := err.(e.E)
  128. e.OutErr(c, err1.Code, err1.Error())
  129. return
  130. }
  131. user := svc.GetUser(c)
  132. now := time.Time{}
  133. var identity = enum.UserIdentityForSelfSupportForStudent
  134. var kind = enum.UserIdentityKindForCommon
  135. if req.Kind == enum.UserIdentityKindForWorker {
  136. kind = enum.UserIdentityKindForWorker
  137. identity = enum.UserIdentityForSelfSupportForWorker
  138. } else {
  139. if req.IsTeacher {
  140. identity = enum.UserIdentityForCentralKitchenForTeacher
  141. }
  142. }
  143. //1、判断当前身份是否已绑定
  144. userIdentityDb := db.UserIdentityDb{}
  145. userIdentityDb.Set(user.Id)
  146. isHasUserIdentity, err := userIdentityDb.UserIdentityExist(req.EnterpriseId, req.IdNo)
  147. if err != nil {
  148. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  149. return
  150. }
  151. if isHasUserIdentity == nil {
  152. if identity != enum.UserIdentityForSelfSupportForStudent {
  153. e.OutErr(c, e.ERR_NO_DATA, "当前身份信息不存在")
  154. return
  155. }
  156. //2、新增身份信息
  157. userIdentity := &model.UserIdentity{
  158. Uid: user.Id,
  159. Name: req.Name,
  160. IdNo: req.IdNo,
  161. Kind: kind,
  162. Identity: identity,
  163. EnterpriseId: req.EnterpriseId,
  164. State: enum.UserIdentityStateForNormal,
  165. Memo: "",
  166. CreateAt: now.Format("2006-01-02 15:04:05"),
  167. UpdateAt: now.Format("2006-01-02 15:04:05"),
  168. }
  169. insertAffected, err := userIdentityDb.UserIdentityInsert(userIdentity)
  170. if err != nil {
  171. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  172. return
  173. }
  174. if insertAffected <= 0 {
  175. e.OutErr(c, e.ERR_DB_ORM, "新增身份数据失败")
  176. return
  177. }
  178. //3、新增 class_with_user 记录
  179. if !req.IsTeacher {
  180. classWithUserDb := db.ClassWithUserDb{}
  181. classWithUserDb.Set()
  182. _, err1 := classWithUserDb.ClassWithUserInsert(&model.ClassWithUser{
  183. UserIdentityId: insertAffected,
  184. ClassId: req.ClassId,
  185. CreateAt: now.Format("2006-01-02 15:04:05"),
  186. UpdateAt: now.Format("2006-01-02 15:04:05"),
  187. })
  188. if err1 != nil {
  189. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  190. return
  191. }
  192. }
  193. //4、新增 self_support_for_user_face_info 记录
  194. selfSupportForSchoolInfoDb := db.SelfSupportForSchoolInfoDb{}
  195. selfSupportForSchoolInfoDb.Set(req.EnterpriseId)
  196. selfSupportForSchoolInfo, err := selfSupportForSchoolInfoDb.GetSelfSupportForSchoolInfo()
  197. if err != nil {
  198. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  199. return
  200. }
  201. if selfSupportForSchoolInfo == nil {
  202. e.OutErr(c, e.ERR_NO_DATA, "当前学校暂未完成《一脸通行入驻》")
  203. return
  204. }
  205. selfSupportForUserFaceInfoDb := db.SelfSupportForUserFaceInfoDb{}
  206. selfSupportForUserFaceInfoDb.Set(insertAffected)
  207. _, err2 := selfSupportForUserFaceInfoDb.SelfSupportForUserFaceInfoInsert(&model.SelfSupportForUserFaceInfo{
  208. UserIdentityId: insertAffected,
  209. CollectFaceType: 1,
  210. SchoolCode: selfSupportForSchoolInfo.SchoolCode,
  211. SchoolStdCode: selfSupportForSchoolInfo.SchoolStdCode,
  212. ParentUserId: "",
  213. ParentLogonId: "",
  214. UserId: "",
  215. SchoolFacePassStatus: "CLOSE",
  216. SchoolFacePaymentStatus: "CLOSE",
  217. ConcentrateSchoolFacePassStatus: 1,
  218. CreateAt: now.Format("2006-01-02 15:04:05"),
  219. UpdateAt: now.Format("2006-01-02 15:04:05"),
  220. })
  221. if err2 != nil {
  222. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  223. return
  224. }
  225. } else {
  226. if isHasUserIdentity != nil && isHasUserIdentity.Uid != 0 && isHasUserIdentity.Uid != user.Id {
  227. e.OutErr(c, e.ERR, "当前身份信息已被绑定使用")
  228. return
  229. }
  230. //4、修改身份信息
  231. isHasUserIdentity.Uid = user.Id
  232. isHasUserIdentity.Name = req.Name
  233. isHasUserIdentity.State = enum.UserIdentityStateForNormal
  234. _, err = userIdentityDb.UserIdentityUpdate(isHasUserIdentity.Id, isHasUserIdentity, "uid", "name", "state")
  235. if err != nil {
  236. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  237. return
  238. }
  239. if identity == enum.UserIdentityForSelfSupportForStudent {
  240. //5、修改 class_with_user 记录
  241. classWithUserDb := db.ClassWithUserDb{}
  242. classWithUserDb.Set()
  243. classWithUser, err1 := classWithUserDb.GetClassWithUserByUserIdentityId(isHasUserIdentity.Id)
  244. if err1 != nil {
  245. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  246. return
  247. }
  248. if classWithUser == nil {
  249. _, err2 := classWithUserDb.ClassWithUserInsert(&model.ClassWithUser{
  250. UserIdentityId: isHasUserIdentity.Id,
  251. ClassId: req.ClassId,
  252. CreateAt: now.Format("2006-01-02 15:04:05"),
  253. UpdateAt: now.Format("2006-01-02 15:04:05"),
  254. })
  255. if err2 != nil {
  256. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  257. return
  258. }
  259. } else {
  260. classWithUser.ClassId = req.ClassId
  261. _, err2 := classWithUserDb.ClassWithUserUpdateByUserIdentity(isHasUserIdentity.Id, classWithUser, "class_id")
  262. if err2 != nil {
  263. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  264. return
  265. }
  266. }
  267. }
  268. }
  269. e.OutSuc(c, "success", nil)
  270. return
  271. }
  272. func UpdateCentralKitchenForSchoolUserIdentity(c *gin.Context) {
  273. var req md.UpdateCentralKitchenForSchoolUserIdentityReq
  274. err := c.ShouldBindJSON(&req)
  275. if err != nil {
  276. err = validate.HandleValidateErr(err)
  277. err1 := err.(e.E)
  278. e.OutErr(c, err1.Code, err1.Error())
  279. return
  280. }
  281. user := svc.GetUser(c)
  282. now := time.Time{}
  283. //1、查询当前身份是否存在
  284. userIdentityDb := db.UserIdentityDb{}
  285. userIdentityDb.Set(user.Id)
  286. userIdentity, err := userIdentityDb.GetUserIdentity(req.UserIdentityId)
  287. if err != nil {
  288. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  289. return
  290. }
  291. if userIdentity == nil {
  292. e.OutErr(c, e.ERR_NO_DATA, "当前身份信息不存在")
  293. return
  294. }
  295. //2、修改身份信息
  296. userIdentity.Name = req.Name
  297. userIdentity.IdNo = req.IdNo
  298. _, err = userIdentityDb.UserIdentityUpdate(userIdentity.Id, userIdentity, "id_no", "name")
  299. if err != nil {
  300. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  301. return
  302. }
  303. //3、修改 class_with_user 记录
  304. if userIdentity.Identity == enum.UserIdentityForCentralKitchenForStudent {
  305. classWithUserDb := db.ClassWithUserDb{}
  306. classWithUserDb.Set()
  307. classWithUser, err1 := classWithUserDb.GetClassWithUserByUserIdentityId(userIdentity.Id)
  308. if err1 != nil {
  309. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  310. return
  311. }
  312. if classWithUser == nil {
  313. _, err2 := classWithUserDb.ClassWithUserInsert(&model.ClassWithUser{
  314. UserIdentityId: userIdentity.Id,
  315. ClassId: req.ClassId,
  316. CreateAt: now.Format("2006-01-02 15:04:05"),
  317. UpdateAt: now.Format("2006-01-02 15:04:05"),
  318. })
  319. if err2 != nil {
  320. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  321. return
  322. }
  323. } else {
  324. classWithUser.ClassId = req.ClassId
  325. _, err2 := classWithUserDb.ClassWithUserUpdateByUserIdentity(userIdentity.Id, classWithUser, "class_id")
  326. if err2 != nil {
  327. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  328. return
  329. }
  330. }
  331. }
  332. e.OutSuc(c, "success", nil)
  333. return
  334. }
  335. func UpdateSelfSupportForSchoolUserIdentity(c *gin.Context) {
  336. var req md.UpdateSelfSupportForSchoolUserIdentityReq
  337. err := c.ShouldBindJSON(&req)
  338. if err != nil {
  339. err = validate.HandleValidateErr(err)
  340. err1 := err.(e.E)
  341. e.OutErr(c, err1.Code, err1.Error())
  342. return
  343. }
  344. user := svc.GetUser(c)
  345. now := time.Time{}
  346. //1、查询当前身份是否存在
  347. userIdentityDb := db.UserIdentityDb{}
  348. userIdentityDb.Set(user.Id)
  349. userIdentity, err := userIdentityDb.GetUserIdentity(req.UserIdentityId)
  350. if err != nil {
  351. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  352. return
  353. }
  354. if userIdentity == nil {
  355. e.OutErr(c, e.ERR_NO_DATA, "当前身份信息不存在")
  356. return
  357. }
  358. //2、修改身份信息
  359. userIdentity.Name = req.Name
  360. userIdentity.IdNo = req.IdNo
  361. _, err = userIdentityDb.UserIdentityUpdate(userIdentity.Id, userIdentity, "id_no", "name")
  362. if err != nil {
  363. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  364. return
  365. }
  366. //3、修改 class_with_user 记录
  367. if userIdentity.Identity == enum.UserIdentityForSelfSupportForStudent {
  368. classWithUserDb := db.ClassWithUserDb{}
  369. classWithUserDb.Set()
  370. classWithUser, err1 := classWithUserDb.GetClassWithUserByUserIdentityId(userIdentity.Id)
  371. if err1 != nil {
  372. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  373. return
  374. }
  375. if classWithUser == nil {
  376. _, err2 := classWithUserDb.ClassWithUserInsert(&model.ClassWithUser{
  377. UserIdentityId: userIdentity.Id,
  378. ClassId: req.ClassId,
  379. CreateAt: now.Format("2006-01-02 15:04:05"),
  380. UpdateAt: now.Format("2006-01-02 15:04:05"),
  381. })
  382. if err2 != nil {
  383. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  384. return
  385. }
  386. } else {
  387. classWithUser.ClassId = req.ClassId
  388. _, err2 := classWithUserDb.ClassWithUserUpdateByUserIdentity(userIdentity.Id, classWithUser, "class_id")
  389. if err2 != nil {
  390. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  391. return
  392. }
  393. }
  394. }
  395. e.OutSuc(c, "success", nil)
  396. return
  397. }
  398. func DeleteUserIdentity(c *gin.Context) {
  399. userIdentityId := utils.StrToInt(c.Param("id"))
  400. user := svc.GetUser(c)
  401. //1、查询当前身份是否存在
  402. userIdentityDb := db.UserIdentityDb{}
  403. userIdentityDb.Set(user.Id)
  404. userIdentity, err := userIdentityDb.GetUserIdentity(userIdentityId)
  405. if err != nil {
  406. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  407. return
  408. }
  409. if userIdentity == nil {
  410. e.OutErr(c, e.ERR_NO_DATA, "当前身份信息不存在")
  411. return
  412. }
  413. switch userIdentity.Identity {
  414. case enum.UserIdentityForCentralKitchenForStudent:
  415. err1 := svc.DeleteUserIdentityForCentralKitchenForStudent(userIdentity.Id)
  416. if err1 != nil {
  417. e.OutErr(c, e.ERR, err1.Error())
  418. return
  419. }
  420. break
  421. case enum.UserIdentityForCentralKitchenForTeacher:
  422. err1 := svc.DeleteUserIdentityForCentralKitchenForTeacher(userIdentity.Id)
  423. if err1 != nil {
  424. e.OutErr(c, e.ERR, err1.Error())
  425. return
  426. }
  427. break
  428. case enum.UserIdentityForCentralKitchenForWorker:
  429. break
  430. case enum.UserIdentityForSelfSupportForStudent:
  431. err1 := svc.DeleteUserIdentityForSelfSupportForStudent(userIdentity.Id)
  432. if err1 != nil {
  433. e.OutErr(c, e.ERR, err1.Error())
  434. return
  435. }
  436. break
  437. case enum.UserIdentityForSelfSupportForTeacher:
  438. err1 := svc.DeleteUserIdentityForSelfSupportForTeacher(userIdentity.Id)
  439. if err1 != nil {
  440. e.OutErr(c, e.ERR, err1.Error())
  441. return
  442. }
  443. break
  444. case enum.UserIdentityForSelfSupportForWorker:
  445. err1 := svc.DeleteUserIdentityForSelfSupportForWorker(userIdentity.Id)
  446. if err1 != nil {
  447. e.OutErr(c, e.ERR, err1.Error())
  448. return
  449. }
  450. break
  451. }
  452. e.OutSuc(c, "success", nil)
  453. return
  454. }