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

hdl_enterprise.go 18 KiB

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年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  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": []map[string]interface{}{
  50. {
  51. "name": enum.EnterprisePvd(enum.EnterprisePvdByCentralKitchenForSchool).String(),
  52. "value": enum.EnterprisePvdByCentralKitchenForSchool,
  53. },
  54. {
  55. "name": enum.EnterprisePvd(enum.EnterprisePvdByCentralKitchenForFactory).String(),
  56. "value": enum.EnterprisePvdByCentralKitchenForFactory,
  57. },
  58. {
  59. "name": enum.EnterprisePvd(enum.EnterprisePvdBySelfSupportForSchool).String(),
  60. "value": enum.EnterprisePvdBySelfSupportForSchool,
  61. },
  62. {
  63. "name": enum.EnterprisePvd(enum.EnterprisePvdBySelfSupportForFactory).String(),
  64. "value": enum.EnterprisePvdBySelfSupportForFactory,
  65. },
  66. {
  67. "name": enum.EnterprisePvd(enum.EnterprisePvdByNursingHome).String(),
  68. "value": enum.EnterprisePvdByNursingHome,
  69. },
  70. },
  71. }, nil)
  72. return
  73. }
  74. func Detail(c *gin.Context) {
  75. enterpriseId := c.DefaultQuery("id", "")
  76. detail, err := svc.EnterpriseDetail(utils.StrToInt(enterpriseId))
  77. if err != nil {
  78. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  79. return
  80. }
  81. e.OutSuc(c, detail, nil)
  82. return
  83. }
  84. func SchoolBelowGrade(c *gin.Context) {
  85. enterpriseId := c.DefaultQuery("enterprise_id", "")
  86. gradeDb := db.GradeDb{}
  87. gradeDb.Set(utils.StrToInt(enterpriseId))
  88. gradeList, err := gradeDb.FindGrade()
  89. if err != nil {
  90. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  91. return
  92. }
  93. e.OutSuc(c, map[string]interface{}{
  94. "list": gradeList,
  95. }, nil)
  96. return
  97. }
  98. func SchoolBelowPeriod(c *gin.Context) {
  99. enterpriseId := c.DefaultQuery("enterprise_id", "")
  100. periodDb := db.PeriodDb{}
  101. periodDb.Set(utils.StrToInt(enterpriseId))
  102. periodList, err := periodDb.FindPeriod()
  103. if err != nil {
  104. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  105. return
  106. }
  107. e.OutSuc(c, map[string]interface{}{
  108. "list": periodList,
  109. }, nil)
  110. return
  111. }
  112. func SchoolGradeBelowClass(c *gin.Context) {
  113. gradeId := c.DefaultQuery("grade_id", "")
  114. enterpriseId := c.DefaultQuery("enterprise_id", "")
  115. classDb := db.ClassDb{}
  116. if gradeId != "" {
  117. classDb.Set(utils.StrToInt(gradeId))
  118. classList, err := classDb.FindClass()
  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": classList,
  125. }, nil)
  126. } else {
  127. classDb.Set(0)
  128. classList, err := classDb.FindClassByEnterprise(enterpriseId)
  129. if err != nil {
  130. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  131. return
  132. }
  133. e.OutSuc(c, map[string]interface{}{
  134. "list": classList,
  135. }, nil)
  136. }
  137. return
  138. }
  139. func EnterpriseAdd(c *gin.Context) {
  140. var req md.EnterpriseAddReq
  141. err := c.ShouldBindJSON(&req)
  142. if err != nil {
  143. err = validate.HandleValidateErr(err)
  144. err1 := err.(e.E)
  145. e.OutErr(c, err1.Code, err1.Error())
  146. return
  147. }
  148. enterpriseDb := db.EnterpriseDb{}
  149. enterpriseDb.Set()
  150. now := time.Now()
  151. var pvd = 2
  152. if req.Kind == enum.EnterprisePvdByCentralKitchenForSchool || req.Kind == enum.EnterprisePvdByCentralKitchenForFactory {
  153. pvd = 1
  154. }
  155. enterprise := model.Enterprise{
  156. Name: req.Name,
  157. Pvd: int32(pvd),
  158. Kind: req.Kind,
  159. CompanyId: req.CompanyId,
  160. State: enum2.CompanyStateForNormal,
  161. Memo: req.Memo,
  162. CreateAt: now.Format("2006-01-02 15:04:05"),
  163. UpdateAt: now.Format("2006-01-02 15:04:05"),
  164. }
  165. enterpriseId, err := enterpriseDb.EnterpriseInsert(&enterprise)
  166. if err != nil {
  167. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  168. return
  169. }
  170. if req.Kind == enum.EnterprisePvdByCentralKitchenForSchool {
  171. //新增 `central_kitchen_for_school_set` && `central_kitchen_for_school_with_spec`
  172. centralKitchenForSchoolSetDb := db.CentralKitchenForSchoolSetDb{}
  173. centralKitchenForSchoolSetDb.Set(enterpriseId)
  174. centralKitchenForSchoolSetDb.CentralKitchenForSchoolSetInsert(&model.CentralKitchenForSchoolSet{
  175. EnterpriseId: enterpriseId,
  176. IsOpenTeacherReportMeal: 1,
  177. IsOpenReportMealForDay: 1,
  178. IsOpenReportMealForMonth: 1,
  179. IsOpenReportMealForSemester: 1,
  180. IsOpenTeacherReportMealForDay: 1,
  181. IsOpenTeacherReportMealForMonth: 1,
  182. IsOpenTeacherReportMealForSemester: 1,
  183. CreateAt: now.Format("2006-01-02 15:04:05"),
  184. UpdateAt: now.Format("2006-01-02 15:04:05"),
  185. })
  186. centralKitchenForSchoolWithSpec := db.CentralKitchenForSchoolWithSpec{}
  187. centralKitchenForSchoolWithSpec.Set(enterpriseId)
  188. centralKitchenForSchoolWithSpec.CentralKitchenForSchoolWithSpecInsert(&model.CentralKitchenForSchoolWithSpec{
  189. EnterpriseId: enterpriseId,
  190. IsOpenBreakfast: 1,
  191. IsOpenLunch: 1,
  192. IsOpenDinner: 1,
  193. BreakfastUnitPrice: "0.00",
  194. LunchUnitPrice: "0.00",
  195. DinnerUnitPrice: "0.00",
  196. BreakfastUnitPriceForTeacher: "0.00",
  197. LunchUnitPriceForTeacher: "0.00",
  198. DinnerUnitPriceForTeacher: "0.00",
  199. CreateAt: now.Format("2006-01-02 15:04:05"),
  200. UpdateAt: now.Format("2006-01-02 15:04:05"),
  201. })
  202. }
  203. if req.Kind == enum.EnterprisePvdByNursingHome {
  204. //新增 `nursing_home_set` && `nursing_home_with_spec`
  205. nursingHomeSetDb := db.NursingHomeSetDb{}
  206. nursingHomeSetDb.Set(enterpriseId)
  207. nursingHomeSetDb.NursingHomeSetInsert(&model.NursingHomeSet{
  208. EnterpriseId: enterpriseId,
  209. IsOpenReportMealForDay: 1,
  210. IsOpenReportMealForMonth: 1,
  211. IsOpenReportMealForYear: 1,
  212. CreateAt: now.Format("2006-01-02 15:04:05"),
  213. UpdateAt: now.Format("2006-01-02 15:04:05"),
  214. })
  215. nursingHomeWithSpec := db.NursingHomeWithSpec{}
  216. nursingHomeWithSpec.Set(enterpriseId)
  217. nursingHomeWithSpec.NursingHomeWithSpecInsert(&model.NursingHomeWithSpec{
  218. EnterpriseId: enterpriseId,
  219. IsOpenBreakfast: 1,
  220. IsOpenLunch: 1,
  221. IsOpenDinner: 1,
  222. BreakfastUnitPrice: "0.00",
  223. LunchUnitPrice: "0.00",
  224. DinnerUnitPrice: "0.00",
  225. CreateAt: now.Format("2006-01-02 15:04:05"),
  226. UpdateAt: now.Format("2006-01-02 15:04:05"),
  227. })
  228. }
  229. e.OutSuc(c, "success", nil)
  230. return
  231. }
  232. func EnterpriseDelete(c *gin.Context) {
  233. var req md.EnterpriseDeleteReq
  234. err := c.ShouldBindJSON(&req)
  235. if err != nil {
  236. err = validate.HandleValidateErr(err)
  237. err1 := err.(e.E)
  238. e.OutErr(c, err1.Code, err1.Error())
  239. return
  240. }
  241. err = svc.EnterpriseDelete(req.EnterpriseIds)
  242. if err != nil {
  243. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  244. return
  245. }
  246. e.OutSuc(c, "success", nil)
  247. return
  248. }
  249. func EnterpriseUpdate(c *gin.Context) {
  250. var req md.EnterpriseUpdateReq
  251. err := c.ShouldBindJSON(&req)
  252. if err != nil {
  253. err = validate.HandleValidateErr(err)
  254. err1 := err.(e.E)
  255. e.OutErr(c, err1.Code, err1.Error())
  256. return
  257. }
  258. //1、更新 enterprise
  259. enterpriseDb := db.EnterpriseDb{}
  260. enterpriseDb.Set()
  261. enterprise, err := enterpriseDb.GetEnterprise(req.Id)
  262. if err != nil {
  263. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  264. return
  265. }
  266. if enterprise == nil {
  267. e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录")
  268. return
  269. }
  270. var pvd = 2
  271. if req.Kind == enum.EnterprisePvdByCentralKitchenForSchool || req.Kind == enum.EnterprisePvdByCentralKitchenForFactory || req.Kind == enum.EnterprisePvdByNursingHome {
  272. pvd = 1
  273. }
  274. now := time.Now()
  275. enterprise.Name = req.Name
  276. enterprise.Memo = req.Memo
  277. enterprise.Pvd = int32(pvd)
  278. enterprise.Kind = req.Kind
  279. enterprise.CompanyId = req.CompanyId
  280. enterprise.UpdateAt = now.Format("2006-01-02 15:04:05")
  281. _, err = enterpriseDb.EnterpriseUpdate(enterprise, "name", "memo", "pvd", "kind", "company_id", "update_at")
  282. if err != nil {
  283. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  284. return
  285. }
  286. //2、更新 period && grade && class 数据
  287. periodDb := db.PeriodDb{}
  288. periodDb.Set(req.Id)
  289. gradeDb := db.GradeDb{}
  290. gradeDb.Set(req.Id)
  291. classDb := db.ClassDb{}
  292. classDb.Set(0)
  293. //新增 grade 数据 && class 数据
  294. var classes []*model.Class
  295. for _, v := range req.PeriodList {
  296. if v.Id == 0 {
  297. //TODO::新增
  298. insertId, err1 := periodDb.PeriodInsert(&model.Period{
  299. EnterpriseId: req.Id,
  300. Name: v.Name,
  301. BreakfastUnitPrice: "0.00",
  302. LunchUnitPrice: "0.00",
  303. DinnerUnitPrice: "0.00",
  304. CreateAt: now.Format("2006-01-02 15:04:05"),
  305. UpdateAt: now.Format("2006-01-02 15:04:05"),
  306. })
  307. if err1 != nil {
  308. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  309. return
  310. }
  311. for _, v1 := range v.GradeList {
  312. insertId1, err2 := gradeDb.GradeInsert(&model.Grade{
  313. Name: v1.Name,
  314. Memo: "",
  315. PeriodId: insertId,
  316. EnterpriseId: req.Id,
  317. CreateAt: now.Format("2006-01-02 15:04:05"),
  318. UpdateAt: now.Format("2006-01-02 15:04:05"),
  319. })
  320. if err2 != nil {
  321. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  322. return
  323. }
  324. for _, v2 := range v1.ClassList {
  325. classes = append(classes, &model.Class{
  326. Name: v2.Name,
  327. Memo: "",
  328. GradeId: insertId1,
  329. EnterpriseId: req.Id,
  330. CreateAt: now.Format("2006-01-02 15:04:05"),
  331. UpdateAt: now.Format("2006-01-02 15:04:05"),
  332. })
  333. }
  334. }
  335. } else {
  336. //TODO::编辑
  337. period, err1 := periodDb.GetPeriod(v.Id)
  338. if err1 != nil {
  339. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  340. return
  341. }
  342. if period == nil {
  343. e.OutErr(c, e.ERR_NO_DATA, "未查询到相关学段信息")
  344. return
  345. }
  346. period.Name = v.Name
  347. _, err2 := periodDb.PeriodUpdate(period, "name")
  348. if err2 != nil {
  349. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  350. return
  351. }
  352. for _, v1 := range v.GradeList {
  353. var gradeId int
  354. if v1.Id == 0 {
  355. gradeId, err2 = gradeDb.GradeInsert(&model.Grade{
  356. Name: v1.Name,
  357. Memo: "",
  358. PeriodId: period.Id,
  359. EnterpriseId: req.Id,
  360. CreateAt: now.Format("2006-01-02 15:04:05"),
  361. UpdateAt: now.Format("2006-01-02 15:04:05"),
  362. })
  363. if err2 != nil {
  364. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  365. return
  366. }
  367. } else {
  368. grade, err3 := gradeDb.GetGrade(v1.Id)
  369. if err3 != nil {
  370. e.OutErr(c, e.ERR_DB_ORM, err3.Error())
  371. return
  372. }
  373. if grade == nil {
  374. e.OutErr(c, e.ERR_NO_DATA, "未查询到相关年级信息")
  375. return
  376. }
  377. grade.Name = v1.Name
  378. _, err4 := gradeDb.GradeUpdate(grade, "name")
  379. if err4 != nil {
  380. e.OutErr(c, e.ERR_DB_ORM, err4.Error())
  381. return
  382. }
  383. gradeId = grade.Id
  384. }
  385. for _, v2 := range v1.ClassList {
  386. if v2.Id == 0 {
  387. //新增
  388. classes = append(classes, &model.Class{
  389. Name: v2.Name,
  390. Memo: "",
  391. GradeId: gradeId,
  392. EnterpriseId: req.Id,
  393. CreateAt: now.Format("2006-01-02 15:04:05"),
  394. UpdateAt: now.Format("2006-01-02 15:04:05"),
  395. })
  396. } else {
  397. //编辑
  398. class, err4 := classDb.GetClass(v2.Id)
  399. if err4 != nil {
  400. e.OutErr(c, e.ERR_DB_ORM, err4.Error())
  401. return
  402. }
  403. if class == nil {
  404. e.OutErr(c, e.ERR_NO_DATA, "未查询到相关班级信息")
  405. return
  406. }
  407. class.Name = v2.Name
  408. _, err6 := classDb.ClassUpdate(class, "name")
  409. if err6 != nil {
  410. e.OutErr(c, e.ERR_DB_ORM, err6.Error())
  411. return
  412. }
  413. }
  414. }
  415. }
  416. }
  417. }
  418. if len(classes) > 0 {
  419. _, err2 := classDb.BatchAddClass(classes)
  420. if err2 != nil {
  421. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  422. return
  423. }
  424. }
  425. e.OutSuc(c, "success", nil)
  426. return
  427. }
  428. func EnterpriseAddGrade(c *gin.Context) {
  429. var req md.EnterpriseUpdateStateReq
  430. err := c.ShouldBindJSON(&req)
  431. if err != nil {
  432. err = validate.HandleValidateErr(err)
  433. err1 := err.(e.E)
  434. e.OutErr(c, err1.Code, err1.Error())
  435. return
  436. }
  437. enterpriseDb := db.EnterpriseDb{}
  438. enterpriseDb.Set()
  439. enterprise, err := enterpriseDb.GetEnterprise(req.Id)
  440. if err != nil {
  441. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  442. return
  443. }
  444. if enterprise == nil {
  445. e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录")
  446. return
  447. }
  448. now := time.Now()
  449. enterprise.State = req.State
  450. enterprise.UpdateAt = now.Format("2006-01-02 15:04:05")
  451. _, err = enterpriseDb.EnterpriseUpdate(enterprise, "state", "update_at")
  452. if err != nil {
  453. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  454. return
  455. }
  456. e.OutSuc(c, "success", nil)
  457. return
  458. }
  459. func EnterpriseUpdateState(c *gin.Context) {
  460. var req md.EnterpriseUpdateStateReq
  461. err := c.ShouldBindJSON(&req)
  462. if err != nil {
  463. err = validate.HandleValidateErr(err)
  464. err1 := err.(e.E)
  465. e.OutErr(c, err1.Code, err1.Error())
  466. return
  467. }
  468. enterpriseDb := db.EnterpriseDb{}
  469. enterpriseDb.Set()
  470. enterprise, err := enterpriseDb.GetEnterprise(req.Id)
  471. if err != nil {
  472. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  473. return
  474. }
  475. if enterprise == nil {
  476. e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录")
  477. return
  478. }
  479. now := time.Now()
  480. enterprise.State = req.State
  481. enterprise.UpdateAt = now.Format("2006-01-02 15:04:05")
  482. _, err = enterpriseDb.EnterpriseUpdate(enterprise, "state", "update_at")
  483. if err != nil {
  484. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  485. return
  486. }
  487. e.OutSuc(c, "success", nil)
  488. return
  489. }
  490. func ListCentralKitchenForSchoolPackageForSystem(c *gin.Context) {
  491. var req md.ListCentralKitchenForSchoolPackageForSystemReq
  492. err := c.ShouldBindJSON(&req)
  493. if err != nil {
  494. err = validate.HandleValidateErr(err)
  495. err1 := err.(e.E)
  496. e.OutErr(c, err1.Code, err1.Error())
  497. return
  498. }
  499. centralKitchenForSchoolPackageForSystemDb := db.CentralKitchenForSchoolPackageForSystemDb{}
  500. centralKitchenForSchoolPackageForSystemDb.Set()
  501. list, total, err := centralKitchenForSchoolPackageForSystemDb.CentralKitchenForSchoolPackageForSystemList(req)
  502. if err != nil {
  503. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  504. return
  505. }
  506. e.OutSuc(c, map[string]interface{}{
  507. "list": list,
  508. "total": total,
  509. }, nil)
  510. return
  511. }
  512. func SetCentralKitchenForSchoolWithSpecForSystem(c *gin.Context) {
  513. var req md.SetCentralKitchenForSchoolWithSpecForSystemReq
  514. err := c.ShouldBindJSON(&req)
  515. if err != nil {
  516. err = validate.HandleValidateErr(err)
  517. err1 := err.(e.E)
  518. e.OutErr(c, err1.Code, err1.Error())
  519. return
  520. }
  521. centralKitchenForSchoolWithSpecForSystemDb := db.CentralKitchenForSchoolWithSpecForSystem{}
  522. centralKitchenForSchoolWithSpecForSystemDb.Set()
  523. system, err := centralKitchenForSchoolWithSpecForSystemDb.GetCentralKitchenForSchoolWithSpecForSystem()
  524. if err != nil {
  525. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  526. return
  527. }
  528. system.BreakfastUnitPrice = req.BreakfastUnitPrice
  529. system.LunchUnitPrice = req.LunchUnitPrice
  530. system.DinnerUnitPrice = req.DinnerUnitPrice
  531. system.BreakfastUnitPriceForTeacher = req.BreakfastUnitPriceForTeacher
  532. system.LunchUnitPriceForTeacher = req.LunchUnitPriceForTeacher
  533. system.DinnerUnitPriceForTeacher = req.DinnerUnitPriceForTeacher
  534. system.UpdateAt = time.Now().Format("2006-01-02 15:04:05")
  535. updateAffected, err := centralKitchenForSchoolWithSpecForSystemDb.CentralKitchenForSchoolWithSpecForSystemUpdate(system.Id, system)
  536. if err != nil {
  537. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  538. return
  539. }
  540. if updateAffected <= 0 {
  541. e.OutErr(c, e.ERR, "更新数据失败")
  542. return
  543. }
  544. e.OutSuc(c, "success", nil)
  545. return
  546. }
  547. func GetCentralKitchenForSchoolWithSpecForSystem(c *gin.Context) {
  548. centralKitchenForSchoolWithSpecForSystemDb := db.CentralKitchenForSchoolWithSpecForSystem{}
  549. centralKitchenForSchoolWithSpecForSystemDb.Set()
  550. system, err := centralKitchenForSchoolWithSpecForSystemDb.GetCentralKitchenForSchoolWithSpecForSystem()
  551. if err != nil {
  552. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  553. return
  554. }
  555. e.OutSuc(c, map[string]interface{}{
  556. "data": system,
  557. }, nil)
  558. return
  559. }
  560. func SaveCentralKitchenForSchoolPackageForSystem(c *gin.Context) {
  561. var req md.SaveCentralKitchenForSchoolPackageForSystemReq
  562. err := c.ShouldBindJSON(&req)
  563. if err != nil {
  564. err = validate.HandleValidateErr(err)
  565. err1 := err.(e.E)
  566. e.OutErr(c, err1.Code, err1.Error())
  567. return
  568. }
  569. //判断是新增 / 编辑
  570. if req.Id > 0 {
  571. err = svc.UpdateCentralKitchenForSchoolPackageForSystem(req)
  572. if err != nil {
  573. e.OutErr(c, e.ERR, err.Error())
  574. return
  575. }
  576. } else {
  577. err = svc.AddCentralKitchenForSchoolPackageForSystem(req)
  578. if err != nil {
  579. e.OutErr(c, e.ERR, err.Error())
  580. return
  581. }
  582. }
  583. e.OutSuc(c, "success", nil)
  584. return
  585. }
  586. func SyncCentralKitchenForSchoolPackageForSystem(c *gin.Context) {
  587. var req md.SyncCentralKitchenForSchoolPackageForSystemReq
  588. err := c.ShouldBindJSON(&req)
  589. if err != nil {
  590. err = validate.HandleValidateErr(err)
  591. err1 := err.(e.E)
  592. e.OutErr(c, err1.Code, err1.Error())
  593. return
  594. }
  595. err = svc.SyncCentralKitchenForSchoolPackageForSystem(req)
  596. if err != nil {
  597. e.OutErr(c, e.ERR, err.Error())
  598. return
  599. }
  600. e.OutSuc(c, "success", nil)
  601. return
  602. }
  603. func DeleteCentralKitchenForSchoolPackageForSystem(c *gin.Context) {
  604. id := c.Param("id")
  605. err := svc.DeleteCentralKitchenForSchoolPackageForSystem(utils.StrToInt(id))
  606. if err != nil {
  607. e.OutErr(c, e.ERR, err.Error())
  608. return
  609. }
  610. e.OutSuc(c, "success", nil)
  611. return
  612. }