智慧食堂
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

hdl_enterprise.go 22 KiB

1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
2 个月前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821
  1. package hdl
  2. import (
  3. enum2 "applet/app/admin/enum"
  4. "applet/app/admin/lib/validate"
  5. "applet/app/admin/md"
  6. "applet/app/admin/svc"
  7. "applet/app/db"
  8. "applet/app/db/model"
  9. "applet/app/e"
  10. "applet/app/enum"
  11. "applet/app/utils"
  12. "github.com/gin-gonic/gin"
  13. "time"
  14. )
  15. func EnterpriseList(c *gin.Context) {
  16. var req md.EnterpriseListReq
  17. err := c.ShouldBindJSON(&req)
  18. if err != nil {
  19. err = validate.HandleValidateErr(err)
  20. err1 := err.(e.E)
  21. e.OutErr(c, err1.Code, err1.Error())
  22. return
  23. }
  24. if req.Limit == 0 {
  25. req.Limit = 10
  26. }
  27. if req.Page == 0 {
  28. req.Page = 10
  29. }
  30. admin := svc.GetUser(c)
  31. enterprises, total, err := svc.EnterpriseList(*admin, req)
  32. if err != nil {
  33. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  34. return
  35. }
  36. e.OutSuc(c, map[string]interface{}{
  37. "list": enterprises,
  38. "total": total,
  39. "state": []map[string]interface{}{
  40. {
  41. "name": enum.EnterpriseState(enum.EnterpriseStateForNormal).String(),
  42. "value": enum.EnterpriseStateForNormal,
  43. },
  44. {
  45. "name": enum.EnterpriseState(enum.EnterpriseStateForFreeze).String(),
  46. "value": enum.EnterpriseStateForFreeze,
  47. },
  48. },
  49. "kind_by_mode": md.EnterpriseKindByMode,
  50. "pvd": []map[string]interface{}{
  51. {
  52. "name": enum.EnterprisePvd(enum.EnterprisePvdForOnlinePayment).String(),
  53. "value": enum.EnterprisePvdForOnlinePayment,
  54. },
  55. {
  56. "name": enum.EnterprisePvd(enum.EnterprisePvdForFaceScanPayment).String(),
  57. "value": enum.EnterprisePvdForFaceScanPayment,
  58. },
  59. },
  60. }, nil)
  61. return
  62. }
  63. func Detail(c *gin.Context) {
  64. enterpriseId := c.DefaultQuery("id", "")
  65. enterpriseDb := db.EnterpriseDb{}
  66. enterpriseDb.Set()
  67. enterprise, err := enterpriseDb.GetEnterprise(utils.StrToInt(enterpriseId))
  68. if err != nil {
  69. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  70. return
  71. }
  72. if enterprise.Pvd == enum.EnterprisePvdForFaceScanPayment && enterprise.Mode == enum.EnterpriseModeForSchool {
  73. detail, err := svc.EnterpriseDetailV2(utils.StrToInt(enterpriseId))
  74. if err != nil {
  75. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  76. return
  77. }
  78. e.OutSuc(c, detail, nil)
  79. return
  80. }
  81. detail, err := svc.EnterpriseDetail(utils.StrToInt(enterpriseId))
  82. if err != nil {
  83. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  84. return
  85. }
  86. e.OutSuc(c, detail, nil)
  87. return
  88. }
  89. func SchoolBelowGrade(c *gin.Context) {
  90. enterpriseId := c.DefaultQuery("enterprise_id", "")
  91. gradeDb := db.GradeDb{}
  92. gradeDb.Set(utils.StrToInt(enterpriseId))
  93. gradeList, err := gradeDb.FindGrade()
  94. if err != nil {
  95. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  96. return
  97. }
  98. e.OutSuc(c, map[string]interface{}{
  99. "list": gradeList,
  100. }, nil)
  101. return
  102. }
  103. func PeriodBelowGrade(c *gin.Context) {
  104. periodId := c.DefaultQuery("period_id", "")
  105. periodDb := db.PeriodDb{}
  106. periodDb.Set(0)
  107. period, err1 := periodDb.GetPeriod(utils.StrToInt(periodId))
  108. if err1 != nil {
  109. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  110. return
  111. }
  112. if period == nil {
  113. e.OutErr(c, e.ERR_NO_DATA, "未查询到相关学段信息")
  114. return
  115. }
  116. gradeDb := db.GradeDb{}
  117. gradeDb.Set(period.EnterpriseId)
  118. gradeList, err := gradeDb.FindGradeByPeriodId(period.Id)
  119. if err != nil {
  120. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  121. return
  122. }
  123. e.OutSuc(c, map[string]interface{}{
  124. "list": gradeList,
  125. }, nil)
  126. return
  127. }
  128. func SchoolBelowPeriod(c *gin.Context) {
  129. enterpriseId := c.DefaultQuery("enterprise_id", "")
  130. periodDb := db.PeriodDb{}
  131. periodDb.Set(utils.StrToInt(enterpriseId))
  132. periodList, err := periodDb.FindPeriod()
  133. if err != nil {
  134. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  135. return
  136. }
  137. e.OutSuc(c, map[string]interface{}{
  138. "list": periodList,
  139. }, nil)
  140. return
  141. }
  142. func SchoolGradeBelowClass(c *gin.Context) {
  143. gradeId := c.DefaultQuery("grade_id", "")
  144. enterpriseId := c.DefaultQuery("enterprise_id", "")
  145. classDb := db.ClassDb{}
  146. if gradeId != "" {
  147. classDb.Set(utils.StrToInt(gradeId))
  148. classList, err := classDb.FindClass()
  149. if err != nil {
  150. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  151. return
  152. }
  153. e.OutSuc(c, map[string]interface{}{
  154. "list": classList,
  155. }, nil)
  156. } else {
  157. classDb.Set(0)
  158. classList, err := classDb.FindClassByEnterprise(enterpriseId)
  159. if err != nil {
  160. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  161. return
  162. }
  163. e.OutSuc(c, map[string]interface{}{
  164. "list": classList,
  165. }, nil)
  166. }
  167. return
  168. }
  169. func EnterpriseAdd(c *gin.Context) {
  170. var req md.EnterpriseAddReq
  171. err := c.ShouldBindJSON(&req)
  172. if err != nil {
  173. err = validate.HandleValidateErr(err)
  174. err1 := err.(e.E)
  175. e.OutErr(c, err1.Code, err1.Error())
  176. return
  177. }
  178. enterpriseDb := db.EnterpriseDb{}
  179. enterpriseDb.Set()
  180. now := time.Now()
  181. //var pvd = 2
  182. //if req.Kind == enum.EnterpriseKindByCentralKitchenForSchool || req.Kind == enum.EnterpriseKindByCentralKitchenForFactory {
  183. // pvd = 1
  184. //}
  185. enterprise := model.Enterprise{
  186. Name: req.Name,
  187. Pvd: req.Pvd,
  188. Mode: req.Mode,
  189. Kind: req.Kind,
  190. CompanyId: req.CompanyId,
  191. State: enum2.CompanyStateForNormal,
  192. Memo: req.Memo,
  193. CreateAt: now.Format("2006-01-02 15:04:05"),
  194. UpdateAt: now.Format("2006-01-02 15:04:05"),
  195. }
  196. enterpriseId, err := enterpriseDb.EnterpriseInsert(&enterprise)
  197. if err != nil {
  198. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  199. return
  200. }
  201. if req.Pvd == enum.EnterprisePvdForOnlinePayment && req.Mode == enum.EnterpriseModeForSchool {
  202. //新增 `central_kitchen_for_school_set` && `central_kitchen_for_school_with_spec`
  203. centralKitchenForSchoolSetDb := db.CentralKitchenForSchoolSetDb{}
  204. centralKitchenForSchoolSetDb.Set(enterpriseId)
  205. centralKitchenForSchoolSetDb.CentralKitchenForSchoolSetInsert(&model.CentralKitchenForSchoolSet{
  206. EnterpriseId: enterpriseId,
  207. IsOpenTeacherReportMeal: 1,
  208. IsOpenReportMealForDay: 1,
  209. IsOpenReportMealForMonth: 1,
  210. IsOpenReportMealForSemester: 1,
  211. IsOpenTeacherReportMealForDay: 1,
  212. IsOpenTeacherReportMealForMonth: 1,
  213. IsOpenTeacherReportMealForSemester: 1,
  214. CreateAt: now.Format("2006-01-02 15:04:05"),
  215. UpdateAt: now.Format("2006-01-02 15:04:05"),
  216. })
  217. centralKitchenForSchoolWithSpec := db.CentralKitchenForSchoolWithSpec{}
  218. centralKitchenForSchoolWithSpec.Set(enterpriseId)
  219. centralKitchenForSchoolWithSpec.CentralKitchenForSchoolWithSpecInsert(&model.CentralKitchenForSchoolWithSpec{
  220. EnterpriseId: enterpriseId,
  221. IsOpenBreakfast: 1,
  222. IsOpenLunch: 1,
  223. IsOpenDinner: 1,
  224. IsOpenBreakfastForTeacher: 1,
  225. IsOpenLunchForTeacher: 1,
  226. IsOpenDinnerForTeacher: 1,
  227. BreakfastUnitPrice: "0.00",
  228. LunchUnitPrice: "0.00",
  229. DinnerUnitPrice: "0.00",
  230. BreakfastUnitPriceForTeacher: "0.00",
  231. LunchUnitPriceForTeacher: "0.00",
  232. DinnerUnitPriceForTeacher: "0.00",
  233. CreateAt: now.Format("2006-01-02 15:04:05"),
  234. UpdateAt: now.Format("2006-01-02 15:04:05"),
  235. })
  236. }
  237. if req.Kind == enum.EnterpriseKindByNursingHome {
  238. //新增 `nursing_home_set` && `nursing_home_with_spec`
  239. nursingHomeSetDb := db.NursingHomeSetDb{}
  240. nursingHomeSetDb.Set(enterpriseId)
  241. nursingHomeSetDb.NursingHomeSetInsert(&model.NursingHomeSet{
  242. EnterpriseId: enterpriseId,
  243. IsOpenReportMealForDay: 1,
  244. IsOpenReportMealForMonth: 1,
  245. IsOpenReportMealForYear: 1,
  246. CreateAt: now.Format("2006-01-02 15:04:05"),
  247. UpdateAt: now.Format("2006-01-02 15:04:05"),
  248. })
  249. nursingHomeWithSpec := db.NursingHomeWithSpec{}
  250. nursingHomeWithSpec.Set(enterpriseId)
  251. nursingHomeWithSpec.NursingHomeWithSpecInsert(&model.NursingHomeWithSpec{
  252. EnterpriseId: enterpriseId,
  253. IsOpenBreakfast: 1,
  254. IsOpenLunch: 1,
  255. IsOpenDinner: 1,
  256. BreakfastUnitPrice: "0.00",
  257. LunchUnitPrice: "0.00",
  258. DinnerUnitPrice: "0.00",
  259. CreateAt: now.Format("2006-01-02 15:04:05"),
  260. UpdateAt: now.Format("2006-01-02 15:04:05"),
  261. })
  262. }
  263. e.OutSuc(c, "success", nil)
  264. return
  265. }
  266. func EnterpriseDelete(c *gin.Context) {
  267. var req md.EnterpriseDeleteReq
  268. err := c.ShouldBindJSON(&req)
  269. if err != nil {
  270. err = validate.HandleValidateErr(err)
  271. err1 := err.(e.E)
  272. e.OutErr(c, err1.Code, err1.Error())
  273. return
  274. }
  275. err = svc.EnterpriseDelete(req.EnterpriseIds)
  276. if err != nil {
  277. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  278. return
  279. }
  280. e.OutSuc(c, "success", nil)
  281. return
  282. }
  283. func CentralKitchenForSchoolUpdate(c *gin.Context) {
  284. var req md.CentralKitchenForSchoolUpdateReq
  285. err := c.ShouldBindJSON(&req)
  286. if err != nil {
  287. err = validate.HandleValidateErr(err)
  288. err1 := err.(e.E)
  289. e.OutErr(c, err1.Code, err1.Error())
  290. return
  291. }
  292. //1、更新 enterprise
  293. enterpriseDb := db.EnterpriseDb{}
  294. enterpriseDb.Set()
  295. enterprise, err := enterpriseDb.GetEnterprise(req.Id)
  296. if err != nil {
  297. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  298. return
  299. }
  300. if enterprise == nil {
  301. e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录")
  302. return
  303. }
  304. now := time.Now()
  305. enterprise.Name = req.Name
  306. enterprise.Memo = req.Memo
  307. enterprise.CompanyId = req.CompanyId
  308. enterprise.UpdateAt = now.Format("2006-01-02 15:04:05")
  309. _, err = enterpriseDb.EnterpriseUpdate(enterprise, "name", "memo", "company_id", "update_at")
  310. if err != nil {
  311. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  312. return
  313. }
  314. //2、更新 period && grade && class 数据
  315. periodDb := db.PeriodDb{}
  316. periodDb.Set(req.Id)
  317. gradeDb := db.GradeDb{}
  318. gradeDb.Set(req.Id)
  319. classDb := db.ClassDb{}
  320. classDb.Set(0)
  321. //新增 grade 数据 && class 数据
  322. var classes []*model.Class
  323. for _, v := range req.PeriodList {
  324. if v.Id == 0 {
  325. //TODO::新增
  326. insertId, err1 := periodDb.PeriodInsert(&model.Period{
  327. EnterpriseId: req.Id,
  328. Name: v.Name,
  329. BreakfastUnitPrice: "0.00",
  330. LunchUnitPrice: "0.00",
  331. DinnerUnitPrice: "0.00",
  332. CreateAt: now.Format("2006-01-02 15:04:05"),
  333. UpdateAt: now.Format("2006-01-02 15:04:05"),
  334. })
  335. if err1 != nil {
  336. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  337. return
  338. }
  339. for _, v1 := range v.GradeList {
  340. insertId1, err2 := gradeDb.GradeInsert(&model.Grade{
  341. Name: v1.Name,
  342. Memo: "",
  343. PeriodId: insertId,
  344. EnterpriseId: req.Id,
  345. CreateAt: now.Format("2006-01-02 15:04:05"),
  346. UpdateAt: now.Format("2006-01-02 15:04:05"),
  347. })
  348. if err2 != nil {
  349. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  350. return
  351. }
  352. for _, v2 := range v1.ClassList {
  353. classes = append(classes, &model.Class{
  354. Name: v2.Name,
  355. Memo: "",
  356. GradeId: insertId1,
  357. EnterpriseId: req.Id,
  358. CreateAt: now.Format("2006-01-02 15:04:05"),
  359. UpdateAt: now.Format("2006-01-02 15:04:05"),
  360. })
  361. }
  362. }
  363. } else {
  364. //TODO::编辑
  365. period, err1 := periodDb.GetPeriod(v.Id)
  366. if err1 != nil {
  367. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  368. return
  369. }
  370. if period == nil {
  371. e.OutErr(c, e.ERR_NO_DATA, "未查询到相关学段信息")
  372. return
  373. }
  374. period.Name = v.Name
  375. _, err2 := periodDb.PeriodUpdate(period, "name")
  376. if err2 != nil {
  377. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  378. return
  379. }
  380. for _, v1 := range v.GradeList {
  381. var gradeId int
  382. if v1.Id == 0 {
  383. gradeId, err2 = gradeDb.GradeInsert(&model.Grade{
  384. Name: v1.Name,
  385. Memo: "",
  386. PeriodId: period.Id,
  387. EnterpriseId: req.Id,
  388. CreateAt: now.Format("2006-01-02 15:04:05"),
  389. UpdateAt: now.Format("2006-01-02 15:04:05"),
  390. })
  391. if err2 != nil {
  392. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  393. return
  394. }
  395. } else {
  396. grade, err3 := gradeDb.GetGrade(v1.Id)
  397. if err3 != nil {
  398. e.OutErr(c, e.ERR_DB_ORM, err3.Error())
  399. return
  400. }
  401. if grade == nil {
  402. e.OutErr(c, e.ERR_NO_DATA, "未查询到相关年级信息")
  403. return
  404. }
  405. grade.Name = v1.Name
  406. _, err4 := gradeDb.GradeUpdate(grade, "name")
  407. if err4 != nil {
  408. e.OutErr(c, e.ERR_DB_ORM, err4.Error())
  409. return
  410. }
  411. gradeId = grade.Id
  412. }
  413. for _, v2 := range v1.ClassList {
  414. if v2.Id == 0 {
  415. //新增
  416. classes = append(classes, &model.Class{
  417. Name: v2.Name,
  418. Memo: "",
  419. GradeId: gradeId,
  420. EnterpriseId: req.Id,
  421. CreateAt: now.Format("2006-01-02 15:04:05"),
  422. UpdateAt: now.Format("2006-01-02 15:04:05"),
  423. })
  424. } else {
  425. //编辑
  426. class, err4 := classDb.GetClass(v2.Id)
  427. if err4 != nil {
  428. e.OutErr(c, e.ERR_DB_ORM, err4.Error())
  429. return
  430. }
  431. if class == nil {
  432. e.OutErr(c, e.ERR_NO_DATA, "未查询到相关班级信息")
  433. return
  434. }
  435. class.Name = v2.Name
  436. _, err6 := classDb.ClassUpdate(class, "name")
  437. if err6 != nil {
  438. e.OutErr(c, e.ERR_DB_ORM, err6.Error())
  439. return
  440. }
  441. }
  442. }
  443. }
  444. }
  445. }
  446. if len(classes) > 0 {
  447. _, err2 := classDb.BatchAddClass(classes)
  448. if err2 != nil {
  449. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  450. return
  451. }
  452. }
  453. e.OutSuc(c, "success", nil)
  454. return
  455. }
  456. func SelfSupportForSchoolUpdate(c *gin.Context) {
  457. var req md.SelfSupportForSchoolUpdateReq
  458. err := c.ShouldBindJSON(&req)
  459. if err != nil {
  460. err = validate.HandleValidateErr(err)
  461. err1 := err.(e.E)
  462. e.OutErr(c, err1.Code, err1.Error())
  463. return
  464. }
  465. //1、更新 enterprise
  466. enterpriseDb := db.EnterpriseDb{}
  467. enterpriseDb.Set()
  468. enterprise, err := enterpriseDb.GetEnterprise(req.Id)
  469. if err != nil {
  470. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  471. return
  472. }
  473. if enterprise == nil {
  474. e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录")
  475. return
  476. }
  477. now := time.Now()
  478. enterprise.Name = req.Name
  479. enterprise.Memo = req.Memo
  480. enterprise.CompanyId = req.CompanyId
  481. enterprise.UpdateAt = now.Format("2006-01-02 15:04:05")
  482. _, err = enterpriseDb.EnterpriseUpdate(enterprise, "name", "memo", "company_id", "update_at")
  483. if err != nil {
  484. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  485. return
  486. }
  487. //2、更新 grade && class 数据
  488. //2、删除 grade && class 数据
  489. gradeDb := db.GradeDb{}
  490. gradeDb.Set(req.Id)
  491. //_, err = gradeDb.ClassDeleteBySessionForEnterprise(db.Db.NewSession(), req.Id)
  492. //if err != nil {
  493. // e.OutErr(c, e.ERR_DB_ORM, err.Error())
  494. // return
  495. //}
  496. classDb := db.ClassDb{}
  497. classDb.Set(0)
  498. //_, err = classDb.ClassDeleteBySessionForEnterprise(db.Db.NewSession(), req.Id)
  499. //if err != nil {
  500. // e.OutErr(c, e.ERR_DB_ORM, err.Error())
  501. // return
  502. //}
  503. //新增 grade 数据 && class 数据
  504. for _, v := range req.GradeList {
  505. var classes []*model.Class
  506. if v.Id == 0 {
  507. //TODO::新增
  508. insertId, err1 := gradeDb.GradeInsert(&model.Grade{
  509. EnterpriseId: req.Id,
  510. Name: v.Name,
  511. Memo: "",
  512. CreateAt: now.Format("2006-01-02 15:04:05"),
  513. UpdateAt: now.Format("2006-01-02 15:04:05"),
  514. })
  515. if err1 != nil {
  516. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  517. return
  518. }
  519. for _, v1 := range v.ClassList {
  520. classes = append(classes, &model.Class{
  521. Name: v1.Name,
  522. Memo: "",
  523. GradeId: insertId,
  524. EnterpriseId: req.Id,
  525. CreateAt: now.Format("2006-01-02 15:04:05"),
  526. UpdateAt: now.Format("2006-01-02 15:04:05"),
  527. })
  528. }
  529. } else {
  530. //TODO::编辑
  531. grade, err3 := gradeDb.GetGrade(v.Id)
  532. if err3 != nil {
  533. e.OutErr(c, e.ERR_DB_ORM, err3.Error())
  534. return
  535. }
  536. if grade == nil {
  537. e.OutErr(c, e.ERR_NO_DATA, "未查询到相关年级信息")
  538. return
  539. }
  540. grade.Name = v.Name
  541. _, err4 := gradeDb.GradeUpdate(grade, "name")
  542. if err4 != nil {
  543. e.OutErr(c, e.ERR_DB_ORM, err4.Error())
  544. return
  545. }
  546. for _, v1 := range v.ClassList {
  547. if v1.Id == 0 {
  548. //新增
  549. classes = append(classes, &model.Class{
  550. Name: v1.Name,
  551. Memo: "",
  552. GradeId: grade.Id,
  553. EnterpriseId: req.Id,
  554. CreateAt: now.Format("2006-01-02 15:04:05"),
  555. UpdateAt: now.Format("2006-01-02 15:04:05"),
  556. })
  557. } else {
  558. //编辑
  559. class, err5 := classDb.GetClass(v1.Id)
  560. if err5 != nil {
  561. e.OutErr(c, e.ERR_DB_ORM, err5.Error())
  562. return
  563. }
  564. if class == nil {
  565. e.OutErr(c, e.ERR_NO_DATA, "未查询到相关班级信息")
  566. return
  567. }
  568. class.Name = v1.Name
  569. _, err6 := classDb.ClassUpdate(class, "name")
  570. if err6 != nil {
  571. e.OutErr(c, e.ERR_DB_ORM, err6.Error())
  572. return
  573. }
  574. }
  575. }
  576. }
  577. if len(classes) > 0 {
  578. _, err2 := classDb.BatchAddClass(classes)
  579. if err2 != nil {
  580. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  581. return
  582. }
  583. }
  584. }
  585. e.OutSuc(c, "success", nil)
  586. return
  587. }
  588. func EnterpriseAddGrade(c *gin.Context) {
  589. var req md.EnterpriseUpdateStateReq
  590. err := c.ShouldBindJSON(&req)
  591. if err != nil {
  592. err = validate.HandleValidateErr(err)
  593. err1 := err.(e.E)
  594. e.OutErr(c, err1.Code, err1.Error())
  595. return
  596. }
  597. enterpriseDb := db.EnterpriseDb{}
  598. enterpriseDb.Set()
  599. enterprise, err := enterpriseDb.GetEnterprise(req.Id)
  600. if err != nil {
  601. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  602. return
  603. }
  604. if enterprise == nil {
  605. e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录")
  606. return
  607. }
  608. now := time.Now()
  609. enterprise.State = req.State
  610. enterprise.UpdateAt = now.Format("2006-01-02 15:04:05")
  611. _, err = enterpriseDb.EnterpriseUpdate(enterprise, "state", "update_at")
  612. if err != nil {
  613. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  614. return
  615. }
  616. e.OutSuc(c, "success", nil)
  617. return
  618. }
  619. func EnterpriseUpdateState(c *gin.Context) {
  620. var req md.EnterpriseUpdateStateReq
  621. err := c.ShouldBindJSON(&req)
  622. if err != nil {
  623. err = validate.HandleValidateErr(err)
  624. err1 := err.(e.E)
  625. e.OutErr(c, err1.Code, err1.Error())
  626. return
  627. }
  628. enterpriseDb := db.EnterpriseDb{}
  629. enterpriseDb.Set()
  630. enterprise, err := enterpriseDb.GetEnterprise(req.Id)
  631. if err != nil {
  632. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  633. return
  634. }
  635. if enterprise == nil {
  636. e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录")
  637. return
  638. }
  639. now := time.Now()
  640. enterprise.State = req.State
  641. enterprise.UpdateAt = now.Format("2006-01-02 15:04:05")
  642. _, err = enterpriseDb.EnterpriseUpdate(enterprise, "state", "update_at")
  643. if err != nil {
  644. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  645. return
  646. }
  647. e.OutSuc(c, "success", nil)
  648. return
  649. }
  650. func ListCentralKitchenForSchoolPackageForSystem(c *gin.Context) {
  651. var req md.ListCentralKitchenForSchoolPackageForSystemReq
  652. err := c.ShouldBindJSON(&req)
  653. if err != nil {
  654. err = validate.HandleValidateErr(err)
  655. err1 := err.(e.E)
  656. e.OutErr(c, err1.Code, err1.Error())
  657. return
  658. }
  659. centralKitchenForSchoolPackageForSystemDb := db.CentralKitchenForSchoolPackageForSystemDb{}
  660. centralKitchenForSchoolPackageForSystemDb.Set()
  661. list, total, err := centralKitchenForSchoolPackageForSystemDb.CentralKitchenForSchoolPackageForSystemList(req)
  662. if err != nil {
  663. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  664. return
  665. }
  666. e.OutSuc(c, map[string]interface{}{
  667. "list": list,
  668. "total": total,
  669. }, nil)
  670. return
  671. }
  672. func SetCentralKitchenForSchoolWithSpecForSystem(c *gin.Context) {
  673. var req md.SetCentralKitchenForSchoolWithSpecForSystemReq
  674. err := c.ShouldBindJSON(&req)
  675. if err != nil {
  676. err = validate.HandleValidateErr(err)
  677. err1 := err.(e.E)
  678. e.OutErr(c, err1.Code, err1.Error())
  679. return
  680. }
  681. centralKitchenForSchoolWithSpecForSystemDb := db.CentralKitchenForSchoolWithSpecForSystem{}
  682. centralKitchenForSchoolWithSpecForSystemDb.Set()
  683. system, err := centralKitchenForSchoolWithSpecForSystemDb.GetCentralKitchenForSchoolWithSpecForSystem()
  684. if err != nil {
  685. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  686. return
  687. }
  688. system.BreakfastUnitPrice = req.BreakfastUnitPrice
  689. system.LunchUnitPrice = req.LunchUnitPrice
  690. system.DinnerUnitPrice = req.DinnerUnitPrice
  691. system.BreakfastUnitPriceForTeacher = req.BreakfastUnitPriceForTeacher
  692. system.LunchUnitPriceForTeacher = req.LunchUnitPriceForTeacher
  693. system.DinnerUnitPriceForTeacher = req.DinnerUnitPriceForTeacher
  694. system.UpdateAt = time.Now().Format("2006-01-02 15:04:05")
  695. updateAffected, err := centralKitchenForSchoolWithSpecForSystemDb.CentralKitchenForSchoolWithSpecForSystemUpdate(system.Id, system)
  696. if err != nil {
  697. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  698. return
  699. }
  700. if updateAffected <= 0 {
  701. e.OutErr(c, e.ERR, "更新数据失败")
  702. return
  703. }
  704. e.OutSuc(c, "success", nil)
  705. return
  706. }
  707. func GetCentralKitchenForSchoolWithSpecForSystem(c *gin.Context) {
  708. centralKitchenForSchoolWithSpecForSystemDb := db.CentralKitchenForSchoolWithSpecForSystem{}
  709. centralKitchenForSchoolWithSpecForSystemDb.Set()
  710. system, err := centralKitchenForSchoolWithSpecForSystemDb.GetCentralKitchenForSchoolWithSpecForSystem()
  711. if err != nil {
  712. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  713. return
  714. }
  715. e.OutSuc(c, map[string]interface{}{
  716. "data": system,
  717. }, nil)
  718. return
  719. }
  720. func SaveCentralKitchenForSchoolPackageForSystem(c *gin.Context) {
  721. var req md.SaveCentralKitchenForSchoolPackageForSystemReq
  722. err := c.ShouldBindJSON(&req)
  723. if err != nil {
  724. err = validate.HandleValidateErr(err)
  725. err1 := err.(e.E)
  726. e.OutErr(c, err1.Code, err1.Error())
  727. return
  728. }
  729. //判断是新增 / 编辑
  730. if req.Id > 0 {
  731. err = svc.UpdateCentralKitchenForSchoolPackageForSystem(req)
  732. if err != nil {
  733. e.OutErr(c, e.ERR, err.Error())
  734. return
  735. }
  736. } else {
  737. err = svc.AddCentralKitchenForSchoolPackageForSystem(req)
  738. if err != nil {
  739. e.OutErr(c, e.ERR, err.Error())
  740. return
  741. }
  742. }
  743. e.OutSuc(c, "success", nil)
  744. return
  745. }
  746. func SyncCentralKitchenForSchoolPackageForSystem(c *gin.Context) {
  747. var req md.SyncCentralKitchenForSchoolPackageForSystemReq
  748. err := c.ShouldBindJSON(&req)
  749. if err != nil {
  750. err = validate.HandleValidateErr(err)
  751. err1 := err.(e.E)
  752. e.OutErr(c, err1.Code, err1.Error())
  753. return
  754. }
  755. err = svc.SyncCentralKitchenForSchoolPackageForSystem(req)
  756. if err != nil {
  757. e.OutErr(c, e.ERR, err.Error())
  758. return
  759. }
  760. e.OutSuc(c, "success", nil)
  761. return
  762. }
  763. func DeleteCentralKitchenForSchoolPackageForSystem(c *gin.Context) {
  764. id := c.Param("id")
  765. err := svc.DeleteCentralKitchenForSchoolPackageForSystem(utils.StrToInt(id))
  766. if err != nil {
  767. e.OutErr(c, e.ERR, err.Error())
  768. return
  769. }
  770. e.OutSuc(c, "success", nil)
  771. return
  772. }