智慧食堂
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

826 satır
22 KiB

  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. enterpriseDb := db.EnterpriseDb{}
  77. enterpriseDb.Set()
  78. enterprise, err := enterpriseDb.GetEnterprise(utils.StrToInt(enterpriseId))
  79. if err != nil {
  80. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  81. return
  82. }
  83. if enterprise.Kind == enum.EnterprisePvdBySelfSupportForSchool {
  84. detail, err := svc.EnterpriseDetailV2(utils.StrToInt(enterpriseId))
  85. if err != nil {
  86. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  87. return
  88. }
  89. e.OutSuc(c, detail, nil)
  90. return
  91. }
  92. detail, err := svc.EnterpriseDetail(utils.StrToInt(enterpriseId))
  93. if err != nil {
  94. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  95. return
  96. }
  97. e.OutSuc(c, detail, nil)
  98. return
  99. }
  100. func SchoolBelowGrade(c *gin.Context) {
  101. enterpriseId := c.DefaultQuery("enterprise_id", "")
  102. gradeDb := db.GradeDb{}
  103. gradeDb.Set(utils.StrToInt(enterpriseId))
  104. gradeList, err := gradeDb.FindGrade()
  105. if err != nil {
  106. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  107. return
  108. }
  109. e.OutSuc(c, map[string]interface{}{
  110. "list": gradeList,
  111. }, nil)
  112. return
  113. }
  114. func PeriodBelowGrade(c *gin.Context) {
  115. periodId := c.DefaultQuery("period_id", "")
  116. gradeDb := db.GradeDb{}
  117. gradeDb.Set(0)
  118. gradeList, err := gradeDb.FindGradeByPeriodId(utils.StrToInt(periodId))
  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.EnterprisePvdByCentralKitchenForSchool || req.Kind == enum.EnterprisePvdByCentralKitchenForFactory {
  183. pvd = 1
  184. }
  185. enterprise := model.Enterprise{
  186. Name: req.Name,
  187. Pvd: int32(pvd),
  188. Kind: req.Kind,
  189. CompanyId: req.CompanyId,
  190. State: enum2.CompanyStateForNormal,
  191. Memo: req.Memo,
  192. CreateAt: now.Format("2006-01-02 15:04:05"),
  193. UpdateAt: now.Format("2006-01-02 15:04:05"),
  194. }
  195. enterpriseId, err := enterpriseDb.EnterpriseInsert(&enterprise)
  196. if err != nil {
  197. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  198. return
  199. }
  200. if req.Kind == enum.EnterprisePvdByCentralKitchenForSchool {
  201. //新增 `central_kitchen_for_school_set` && `central_kitchen_for_school_with_spec`
  202. centralKitchenForSchoolSetDb := db.CentralKitchenForSchoolSetDb{}
  203. centralKitchenForSchoolSetDb.Set(enterpriseId)
  204. centralKitchenForSchoolSetDb.CentralKitchenForSchoolSetInsert(&model.CentralKitchenForSchoolSet{
  205. EnterpriseId: enterpriseId,
  206. IsOpenTeacherReportMeal: 1,
  207. IsOpenReportMealForDay: 1,
  208. IsOpenReportMealForMonth: 1,
  209. IsOpenReportMealForSemester: 1,
  210. IsOpenTeacherReportMealForDay: 1,
  211. IsOpenTeacherReportMealForMonth: 1,
  212. IsOpenTeacherReportMealForSemester: 1,
  213. CreateAt: now.Format("2006-01-02 15:04:05"),
  214. UpdateAt: now.Format("2006-01-02 15:04:05"),
  215. })
  216. centralKitchenForSchoolWithSpec := db.CentralKitchenForSchoolWithSpec{}
  217. centralKitchenForSchoolWithSpec.Set(enterpriseId)
  218. centralKitchenForSchoolWithSpec.CentralKitchenForSchoolWithSpecInsert(&model.CentralKitchenForSchoolWithSpec{
  219. EnterpriseId: enterpriseId,
  220. IsOpenBreakfast: 1,
  221. IsOpenLunch: 1,
  222. IsOpenDinner: 1,
  223. BreakfastUnitPrice: "0.00",
  224. LunchUnitPrice: "0.00",
  225. DinnerUnitPrice: "0.00",
  226. BreakfastUnitPriceForTeacher: "0.00",
  227. LunchUnitPriceForTeacher: "0.00",
  228. DinnerUnitPriceForTeacher: "0.00",
  229. CreateAt: now.Format("2006-01-02 15:04:05"),
  230. UpdateAt: now.Format("2006-01-02 15:04:05"),
  231. })
  232. }
  233. if req.Kind == enum.EnterprisePvdByNursingHome {
  234. //新增 `nursing_home_set` && `nursing_home_with_spec`
  235. nursingHomeSetDb := db.NursingHomeSetDb{}
  236. nursingHomeSetDb.Set(enterpriseId)
  237. nursingHomeSetDb.NursingHomeSetInsert(&model.NursingHomeSet{
  238. EnterpriseId: enterpriseId,
  239. IsOpenReportMealForDay: 1,
  240. IsOpenReportMealForMonth: 1,
  241. IsOpenReportMealForYear: 1,
  242. CreateAt: now.Format("2006-01-02 15:04:05"),
  243. UpdateAt: now.Format("2006-01-02 15:04:05"),
  244. })
  245. nursingHomeWithSpec := db.NursingHomeWithSpec{}
  246. nursingHomeWithSpec.Set(enterpriseId)
  247. nursingHomeWithSpec.NursingHomeWithSpecInsert(&model.NursingHomeWithSpec{
  248. EnterpriseId: enterpriseId,
  249. IsOpenBreakfast: 1,
  250. IsOpenLunch: 1,
  251. IsOpenDinner: 1,
  252. BreakfastUnitPrice: "0.00",
  253. LunchUnitPrice: "0.00",
  254. DinnerUnitPrice: "0.00",
  255. CreateAt: now.Format("2006-01-02 15:04:05"),
  256. UpdateAt: now.Format("2006-01-02 15:04:05"),
  257. })
  258. }
  259. e.OutSuc(c, "success", nil)
  260. return
  261. }
  262. func EnterpriseDelete(c *gin.Context) {
  263. var req md.EnterpriseDeleteReq
  264. err := c.ShouldBindJSON(&req)
  265. if err != nil {
  266. err = validate.HandleValidateErr(err)
  267. err1 := err.(e.E)
  268. e.OutErr(c, err1.Code, err1.Error())
  269. return
  270. }
  271. err = svc.EnterpriseDelete(req.EnterpriseIds)
  272. if err != nil {
  273. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  274. return
  275. }
  276. e.OutSuc(c, "success", nil)
  277. return
  278. }
  279. func CentralKitchenForSchoolUpdate(c *gin.Context) {
  280. var req md.CentralKitchenForSchoolUpdateReq
  281. err := c.ShouldBindJSON(&req)
  282. if err != nil {
  283. err = validate.HandleValidateErr(err)
  284. err1 := err.(e.E)
  285. e.OutErr(c, err1.Code, err1.Error())
  286. return
  287. }
  288. //1、更新 enterprise
  289. enterpriseDb := db.EnterpriseDb{}
  290. enterpriseDb.Set()
  291. enterprise, err := enterpriseDb.GetEnterprise(req.Id)
  292. if err != nil {
  293. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  294. return
  295. }
  296. if enterprise == nil {
  297. e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录")
  298. return
  299. }
  300. var pvd = 2
  301. if req.Kind == enum.EnterprisePvdByCentralKitchenForSchool || req.Kind == enum.EnterprisePvdByCentralKitchenForFactory || req.Kind == enum.EnterprisePvdByNursingHome {
  302. pvd = 1
  303. }
  304. now := time.Now()
  305. enterprise.Name = req.Name
  306. enterprise.Memo = req.Memo
  307. enterprise.Pvd = int32(pvd)
  308. enterprise.Kind = req.Kind
  309. enterprise.CompanyId = req.CompanyId
  310. enterprise.UpdateAt = now.Format("2006-01-02 15:04:05")
  311. _, err = enterpriseDb.EnterpriseUpdate(enterprise, "name", "memo", "pvd", "kind", "company_id", "update_at")
  312. if err != nil {
  313. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  314. return
  315. }
  316. //2、更新 period && grade && class 数据
  317. periodDb := db.PeriodDb{}
  318. periodDb.Set(req.Id)
  319. gradeDb := db.GradeDb{}
  320. gradeDb.Set(req.Id)
  321. classDb := db.ClassDb{}
  322. classDb.Set(0)
  323. //新增 grade 数据 && class 数据
  324. var classes []*model.Class
  325. for _, v := range req.PeriodList {
  326. if v.Id == 0 {
  327. //TODO::新增
  328. insertId, err1 := periodDb.PeriodInsert(&model.Period{
  329. EnterpriseId: req.Id,
  330. Name: v.Name,
  331. BreakfastUnitPrice: "0.00",
  332. LunchUnitPrice: "0.00",
  333. DinnerUnitPrice: "0.00",
  334. CreateAt: now.Format("2006-01-02 15:04:05"),
  335. UpdateAt: now.Format("2006-01-02 15:04:05"),
  336. })
  337. if err1 != nil {
  338. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  339. return
  340. }
  341. for _, v1 := range v.GradeList {
  342. insertId1, err2 := gradeDb.GradeInsert(&model.Grade{
  343. Name: v1.Name,
  344. Memo: "",
  345. PeriodId: insertId,
  346. EnterpriseId: req.Id,
  347. CreateAt: now.Format("2006-01-02 15:04:05"),
  348. UpdateAt: now.Format("2006-01-02 15:04:05"),
  349. })
  350. if err2 != nil {
  351. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  352. return
  353. }
  354. for _, v2 := range v1.ClassList {
  355. classes = append(classes, &model.Class{
  356. Name: v2.Name,
  357. Memo: "",
  358. GradeId: insertId1,
  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. }
  364. }
  365. } else {
  366. //TODO::编辑
  367. period, err1 := periodDb.GetPeriod(v.Id)
  368. if err1 != nil {
  369. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  370. return
  371. }
  372. if period == nil {
  373. e.OutErr(c, e.ERR_NO_DATA, "未查询到相关学段信息")
  374. return
  375. }
  376. period.Name = v.Name
  377. _, err2 := periodDb.PeriodUpdate(period, "name")
  378. if err2 != nil {
  379. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  380. return
  381. }
  382. for _, v1 := range v.GradeList {
  383. var gradeId int
  384. if v1.Id == 0 {
  385. gradeId, err2 = gradeDb.GradeInsert(&model.Grade{
  386. Name: v1.Name,
  387. Memo: "",
  388. PeriodId: period.Id,
  389. EnterpriseId: req.Id,
  390. CreateAt: now.Format("2006-01-02 15:04:05"),
  391. UpdateAt: now.Format("2006-01-02 15:04:05"),
  392. })
  393. if err2 != nil {
  394. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  395. return
  396. }
  397. } else {
  398. grade, err3 := gradeDb.GetGrade(v1.Id)
  399. if err3 != nil {
  400. e.OutErr(c, e.ERR_DB_ORM, err3.Error())
  401. return
  402. }
  403. if grade == nil {
  404. e.OutErr(c, e.ERR_NO_DATA, "未查询到相关年级信息")
  405. return
  406. }
  407. grade.Name = v1.Name
  408. _, err4 := gradeDb.GradeUpdate(grade, "name")
  409. if err4 != nil {
  410. e.OutErr(c, e.ERR_DB_ORM, err4.Error())
  411. return
  412. }
  413. gradeId = grade.Id
  414. }
  415. for _, v2 := range v1.ClassList {
  416. if v2.Id == 0 {
  417. //新增
  418. classes = append(classes, &model.Class{
  419. Name: v2.Name,
  420. Memo: "",
  421. GradeId: gradeId,
  422. EnterpriseId: req.Id,
  423. CreateAt: now.Format("2006-01-02 15:04:05"),
  424. UpdateAt: now.Format("2006-01-02 15:04:05"),
  425. })
  426. } else {
  427. //编辑
  428. class, err4 := classDb.GetClass(v2.Id)
  429. if err4 != nil {
  430. e.OutErr(c, e.ERR_DB_ORM, err4.Error())
  431. return
  432. }
  433. if class == nil {
  434. e.OutErr(c, e.ERR_NO_DATA, "未查询到相关班级信息")
  435. return
  436. }
  437. class.Name = v2.Name
  438. _, err6 := classDb.ClassUpdate(class, "name")
  439. if err6 != nil {
  440. e.OutErr(c, e.ERR_DB_ORM, err6.Error())
  441. return
  442. }
  443. }
  444. }
  445. }
  446. }
  447. }
  448. if len(classes) > 0 {
  449. _, err2 := classDb.BatchAddClass(classes)
  450. if err2 != nil {
  451. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  452. return
  453. }
  454. }
  455. e.OutSuc(c, "success", nil)
  456. return
  457. }
  458. func SelfSupportForSchoolUpdate(c *gin.Context) {
  459. var req md.SelfSupportForSchoolUpdateReq
  460. err := c.ShouldBindJSON(&req)
  461. if err != nil {
  462. err = validate.HandleValidateErr(err)
  463. err1 := err.(e.E)
  464. e.OutErr(c, err1.Code, err1.Error())
  465. return
  466. }
  467. //1、更新 enterprise
  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. var pvd = 2
  480. if req.Kind == enum.EnterprisePvdByCentralKitchenForSchool || req.Kind == enum.EnterprisePvdByCentralKitchenForFactory || req.Kind == enum.EnterprisePvdByNursingHome {
  481. pvd = 1
  482. }
  483. now := time.Now()
  484. enterprise.Name = req.Name
  485. enterprise.Memo = req.Memo
  486. enterprise.Pvd = int32(pvd)
  487. enterprise.Kind = req.Kind
  488. enterprise.CompanyId = req.CompanyId
  489. enterprise.UpdateAt = now.Format("2006-01-02 15:04:05")
  490. _, err = enterpriseDb.EnterpriseUpdate(enterprise, "name", "memo", "pvd", "kind", "company_id", "update_at")
  491. if err != nil {
  492. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  493. return
  494. }
  495. //2、更新 grade && class 数据
  496. //2、删除 grade && class 数据
  497. gradeDb := db.GradeDb{}
  498. gradeDb.Set(req.Id)
  499. //_, err = gradeDb.ClassDeleteBySessionForEnterprise(db.Db.NewSession(), req.Id)
  500. //if err != nil {
  501. // e.OutErr(c, e.ERR_DB_ORM, err.Error())
  502. // return
  503. //}
  504. classDb := db.ClassDb{}
  505. classDb.Set(0)
  506. //_, err = classDb.ClassDeleteBySessionForEnterprise(db.Db.NewSession(), req.Id)
  507. //if err != nil {
  508. // e.OutErr(c, e.ERR_DB_ORM, err.Error())
  509. // return
  510. //}
  511. //新增 grade 数据 && class 数据
  512. for _, v := range req.GradeList {
  513. var classes []*model.Class
  514. if v.Id == 0 {
  515. //TODO::新增
  516. insertId, err1 := gradeDb.GradeInsert(&model.Grade{
  517. EnterpriseId: req.Id,
  518. Name: v.Name,
  519. Memo: "",
  520. CreateAt: now.Format("2006-01-02 15:04:05"),
  521. UpdateAt: now.Format("2006-01-02 15:04:05"),
  522. })
  523. if err1 != nil {
  524. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  525. return
  526. }
  527. for _, v1 := range v.ClassList {
  528. classes = append(classes, &model.Class{
  529. Name: v1.Name,
  530. Memo: "",
  531. GradeId: insertId,
  532. EnterpriseId: req.Id,
  533. CreateAt: now.Format("2006-01-02 15:04:05"),
  534. UpdateAt: now.Format("2006-01-02 15:04:05"),
  535. })
  536. }
  537. } else {
  538. //TODO::编辑
  539. grade, err3 := gradeDb.GetGrade(v.Id)
  540. if err3 != nil {
  541. e.OutErr(c, e.ERR_DB_ORM, err3.Error())
  542. return
  543. }
  544. if grade == nil {
  545. e.OutErr(c, e.ERR_NO_DATA, "未查询到相关年级信息")
  546. return
  547. }
  548. grade.Name = v.Name
  549. _, err4 := gradeDb.GradeUpdate(grade, "name")
  550. if err4 != nil {
  551. e.OutErr(c, e.ERR_DB_ORM, err4.Error())
  552. return
  553. }
  554. for _, v1 := range v.ClassList {
  555. if v1.Id == 0 {
  556. //新增
  557. classes = append(classes, &model.Class{
  558. Name: v1.Name,
  559. Memo: "",
  560. GradeId: grade.Id,
  561. EnterpriseId: req.Id,
  562. CreateAt: now.Format("2006-01-02 15:04:05"),
  563. UpdateAt: now.Format("2006-01-02 15:04:05"),
  564. })
  565. } else {
  566. //编辑
  567. class, err5 := classDb.GetClass(v1.Id)
  568. if err5 != nil {
  569. e.OutErr(c, e.ERR_DB_ORM, err5.Error())
  570. return
  571. }
  572. if class == nil {
  573. e.OutErr(c, e.ERR_NO_DATA, "未查询到相关班级信息")
  574. return
  575. }
  576. class.Name = v1.Name
  577. _, err6 := classDb.ClassUpdate(class, "name")
  578. if err6 != nil {
  579. e.OutErr(c, e.ERR_DB_ORM, err6.Error())
  580. return
  581. }
  582. }
  583. }
  584. }
  585. if len(classes) > 0 {
  586. _, err2 := classDb.BatchAddClass(classes)
  587. if err2 != nil {
  588. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  589. return
  590. }
  591. }
  592. }
  593. e.OutSuc(c, "success", nil)
  594. return
  595. }
  596. func EnterpriseAddGrade(c *gin.Context) {
  597. var req md.EnterpriseUpdateStateReq
  598. err := c.ShouldBindJSON(&req)
  599. if err != nil {
  600. err = validate.HandleValidateErr(err)
  601. err1 := err.(e.E)
  602. e.OutErr(c, err1.Code, err1.Error())
  603. return
  604. }
  605. enterpriseDb := db.EnterpriseDb{}
  606. enterpriseDb.Set()
  607. enterprise, err := enterpriseDb.GetEnterprise(req.Id)
  608. if err != nil {
  609. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  610. return
  611. }
  612. if enterprise == nil {
  613. e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录")
  614. return
  615. }
  616. now := time.Now()
  617. enterprise.State = req.State
  618. enterprise.UpdateAt = now.Format("2006-01-02 15:04:05")
  619. _, err = enterpriseDb.EnterpriseUpdate(enterprise, "state", "update_at")
  620. if err != nil {
  621. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  622. return
  623. }
  624. e.OutSuc(c, "success", nil)
  625. return
  626. }
  627. func EnterpriseUpdateState(c *gin.Context) {
  628. var req md.EnterpriseUpdateStateReq
  629. err := c.ShouldBindJSON(&req)
  630. if err != nil {
  631. err = validate.HandleValidateErr(err)
  632. err1 := err.(e.E)
  633. e.OutErr(c, err1.Code, err1.Error())
  634. return
  635. }
  636. enterpriseDb := db.EnterpriseDb{}
  637. enterpriseDb.Set()
  638. enterprise, err := enterpriseDb.GetEnterprise(req.Id)
  639. if err != nil {
  640. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  641. return
  642. }
  643. if enterprise == nil {
  644. e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录")
  645. return
  646. }
  647. now := time.Now()
  648. enterprise.State = req.State
  649. enterprise.UpdateAt = now.Format("2006-01-02 15:04:05")
  650. _, err = enterpriseDb.EnterpriseUpdate(enterprise, "state", "update_at")
  651. if err != nil {
  652. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  653. return
  654. }
  655. e.OutSuc(c, "success", nil)
  656. return
  657. }
  658. func ListCentralKitchenForSchoolPackageForSystem(c *gin.Context) {
  659. var req md.ListCentralKitchenForSchoolPackageForSystemReq
  660. err := c.ShouldBindJSON(&req)
  661. if err != nil {
  662. err = validate.HandleValidateErr(err)
  663. err1 := err.(e.E)
  664. e.OutErr(c, err1.Code, err1.Error())
  665. return
  666. }
  667. centralKitchenForSchoolPackageForSystemDb := db.CentralKitchenForSchoolPackageForSystemDb{}
  668. centralKitchenForSchoolPackageForSystemDb.Set()
  669. list, total, err := centralKitchenForSchoolPackageForSystemDb.CentralKitchenForSchoolPackageForSystemList(req)
  670. if err != nil {
  671. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  672. return
  673. }
  674. e.OutSuc(c, map[string]interface{}{
  675. "list": list,
  676. "total": total,
  677. }, nil)
  678. return
  679. }
  680. func SetCentralKitchenForSchoolWithSpecForSystem(c *gin.Context) {
  681. var req md.SetCentralKitchenForSchoolWithSpecForSystemReq
  682. err := c.ShouldBindJSON(&req)
  683. if err != nil {
  684. err = validate.HandleValidateErr(err)
  685. err1 := err.(e.E)
  686. e.OutErr(c, err1.Code, err1.Error())
  687. return
  688. }
  689. centralKitchenForSchoolWithSpecForSystemDb := db.CentralKitchenForSchoolWithSpecForSystem{}
  690. centralKitchenForSchoolWithSpecForSystemDb.Set()
  691. system, err := centralKitchenForSchoolWithSpecForSystemDb.GetCentralKitchenForSchoolWithSpecForSystem()
  692. if err != nil {
  693. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  694. return
  695. }
  696. system.BreakfastUnitPrice = req.BreakfastUnitPrice
  697. system.LunchUnitPrice = req.LunchUnitPrice
  698. system.DinnerUnitPrice = req.DinnerUnitPrice
  699. system.BreakfastUnitPriceForTeacher = req.BreakfastUnitPriceForTeacher
  700. system.LunchUnitPriceForTeacher = req.LunchUnitPriceForTeacher
  701. system.DinnerUnitPriceForTeacher = req.DinnerUnitPriceForTeacher
  702. system.UpdateAt = time.Now().Format("2006-01-02 15:04:05")
  703. updateAffected, err := centralKitchenForSchoolWithSpecForSystemDb.CentralKitchenForSchoolWithSpecForSystemUpdate(system.Id, system)
  704. if err != nil {
  705. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  706. return
  707. }
  708. if updateAffected <= 0 {
  709. e.OutErr(c, e.ERR, "更新数据失败")
  710. return
  711. }
  712. e.OutSuc(c, "success", nil)
  713. return
  714. }
  715. func GetCentralKitchenForSchoolWithSpecForSystem(c *gin.Context) {
  716. centralKitchenForSchoolWithSpecForSystemDb := db.CentralKitchenForSchoolWithSpecForSystem{}
  717. centralKitchenForSchoolWithSpecForSystemDb.Set()
  718. system, err := centralKitchenForSchoolWithSpecForSystemDb.GetCentralKitchenForSchoolWithSpecForSystem()
  719. if err != nil {
  720. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  721. return
  722. }
  723. e.OutSuc(c, map[string]interface{}{
  724. "data": system,
  725. }, nil)
  726. return
  727. }
  728. func SaveCentralKitchenForSchoolPackageForSystem(c *gin.Context) {
  729. var req md.SaveCentralKitchenForSchoolPackageForSystemReq
  730. err := c.ShouldBindJSON(&req)
  731. if err != nil {
  732. err = validate.HandleValidateErr(err)
  733. err1 := err.(e.E)
  734. e.OutErr(c, err1.Code, err1.Error())
  735. return
  736. }
  737. //判断是新增 / 编辑
  738. if req.Id > 0 {
  739. err = svc.UpdateCentralKitchenForSchoolPackageForSystem(req)
  740. if err != nil {
  741. e.OutErr(c, e.ERR, err.Error())
  742. return
  743. }
  744. } else {
  745. err = svc.AddCentralKitchenForSchoolPackageForSystem(req)
  746. if err != nil {
  747. e.OutErr(c, e.ERR, err.Error())
  748. return
  749. }
  750. }
  751. e.OutSuc(c, "success", nil)
  752. return
  753. }
  754. func SyncCentralKitchenForSchoolPackageForSystem(c *gin.Context) {
  755. var req md.SyncCentralKitchenForSchoolPackageForSystemReq
  756. err := c.ShouldBindJSON(&req)
  757. if err != nil {
  758. err = validate.HandleValidateErr(err)
  759. err1 := err.(e.E)
  760. e.OutErr(c, err1.Code, err1.Error())
  761. return
  762. }
  763. err = svc.SyncCentralKitchenForSchoolPackageForSystem(req)
  764. if err != nil {
  765. e.OutErr(c, e.ERR, err.Error())
  766. return
  767. }
  768. e.OutSuc(c, "success", nil)
  769. return
  770. }
  771. func DeleteCentralKitchenForSchoolPackageForSystem(c *gin.Context) {
  772. id := c.Param("id")
  773. err := svc.DeleteCentralKitchenForSchoolPackageForSystem(utils.StrToInt(id))
  774. if err != nil {
  775. e.OutErr(c, e.ERR, err.Error())
  776. return
  777. }
  778. e.OutSuc(c, "success", nil)
  779. return
  780. }