智慧食堂
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.

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