|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370 |
- package hdl
-
- import (
- "applet/app/admin/lib/validate"
- "applet/app/admin/md"
- svc "applet/app/admin/svc/enterprise_manage"
- svc2 "applet/app/admin/svc/order"
- "applet/app/db"
- "applet/app/db/model"
- "applet/app/e"
- "applet/app/enum"
- "applet/app/utils"
- "applet/app/utils/cache"
- "applet/app/utils/logx"
- "errors"
- "github.com/gin-gonic/gin"
- "time"
- )
-
- func CentralKitchenForSchoolOrderRefundList(c *gin.Context) {
- var req md.CentralKitchenForSchoolOrderRefundListReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- err = validate.HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
- list, total, err := svc2.CentralKitchenForSchoolOrderRefundList(req)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- e.OutSuc(c, map[string]interface{}{
- "list": list,
- "total": total,
- "audit_kind_list": []map[string]interface{}{
- {
- "name": "同意",
- "value": 1,
- },
- {
- "name": "拒绝",
- "value": 2,
- },
- },
- "order_by_name_list": []map[string]interface{}{
- {
- "name": "按姓名升序",
- "value": 1,
- },
- {
- "name": "按姓名降序",
- "value": 2,
- },
- },
- "kind_list": []map[string]interface{}{
- {
- "name": enum.CentralKitchenForSchoolUserWithDayKind.String(enum.CentralKitchenForSchoolUserWithDayKindForBreakfast),
- "value": enum.CentralKitchenForSchoolUserWithDayKindForBreakfast,
- },
- {
- "name": enum.CentralKitchenForSchoolUserWithDayKind.String(enum.CentralKitchenForSchoolUserWithDayKindForLunch),
- "value": enum.CentralKitchenForSchoolUserWithDayKindForLunch,
- },
- {
- "name": enum.CentralKitchenForSchoolUserWithDayKind.String(enum.CentralKitchenForSchoolUserWithDayKindForDinner),
- "value": enum.CentralKitchenForSchoolUserWithDayKindForDinner,
- },
- },
- "state_list": []map[string]interface{}{
- {
- "name": enum.CentralKitchenForSchoolUserRefundDayState.String(enum.CentralKitchenForSchoolUserRefundDayStateForAuditing),
- "value": enum.CentralKitchenForSchoolUserRefundDayStateForAuditing,
- },
- {
- "name": enum.CentralKitchenForSchoolUserRefundDayState.String(enum.CentralKitchenForSchoolUserRefundDayStateForAuditPass),
- "value": enum.CentralKitchenForSchoolUserRefundDayStateForAuditPass,
- },
- {
- "name": enum.CentralKitchenForSchoolUserRefundDayState.String(enum.CentralKitchenForSchoolUserRefundDayStateForAuditReject),
- "value": enum.CentralKitchenForSchoolUserRefundDayStateForAuditReject,
- },
- {
- "name": enum.CentralKitchenForSchoolUserRefundDayState.String(enum.CentralKitchenForSchoolUserRefundDayStateForAuditComplete),
- "value": enum.CentralKitchenForSchoolUserRefundDayStateForAuditComplete,
- },
- },
- "user_identity_kind_list": []map[string]interface{}{
- {
- "name": enum.UserIdentity.String(enum.UserIdentityForCentralKitchenForStudent),
- "value": enum.UserIdentityForCentralKitchenForStudent,
- },
- {
- "name": enum.UserIdentity.String(enum.UserIdentityForCentralKitchenForTeacher),
- "value": enum.UserIdentityForCentralKitchenForTeacher,
- },
- {
- "name": enum.UserIdentity.String(enum.UserIdentityForCentralKitchenForWorker),
- "value": enum.UserIdentityForCentralKitchenForWorker,
- },
- {
- "name": enum.UserIdentity.String(enum.UserIdentityForSelfSupportForStudent),
- "value": enum.UserIdentityForSelfSupportForStudent,
- },
- {
- "name": enum.UserIdentity.String(enum.UserIdentityForSelfSupportForTeacher),
- "value": enum.UserIdentityForSelfSupportForTeacher,
- },
- {
- "name": enum.UserIdentity.String(enum.UserIdentityForSelfSupportForWorker),
- "value": enum.UserIdentityForSelfSupportForWorker,
- },
- },
- }, nil)
- return
- }
-
- func CentralKitchenForSchoolOrderRefundAudit(c *gin.Context) {
- var req md.CentralKitchenForSchoolOrderRefundAuditReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- err = validate.HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
-
- //限制500条
- if len(req.Ids) > 500 {
- e.OutErr(c, e.ERR, errors.New("受理数据过长,请分批次处理"))
- return
- }
-
- //TODO:: 加锁 Redis 锁,防并发
- getString, _ := cache.GetString(md.AuditLockKeyForCentralKitchenLockKey)
- if getString != "" {
- e.OutErr(c, e.ERR, "请稍等,存在其他退款处理中!")
- return
- }
- cache.Set(md.AuditLockKeyForCentralKitchenLockKey, "running")
- utils.FilePutContents("DealCentralKitchenForSchoolOrderRefundAudit", "退款处理,开始时间:::"+time.Now().Format("2006-01-02 15:04:05"))
-
- //先将所有申请单改成 审核通过 状态
- session := db.Db.NewSession()
- defer session.Close()
- session.Begin()
-
- centralKitchenForSchoolUserRefundDayDb := db.CentralKitchenForSchoolUserRefundDayDb{}
- centralKitchenForSchoolUserRefundDayDb.Set(0)
- centralKitchenForSchoolUserWithDayDb := db.CentralKitchenForSchoolUserWithDayDb{}
- centralKitchenForSchoolUserWithDayDb.Set(0)
- var recordsId = map[int]bool{}
- for _, v := range req.Ids {
- returnDay, err1 := centralKitchenForSchoolUserRefundDayDb.GetCentralKitchenForSchoolUserRefundDay(utils.StrToInt(v))
- if returnDay == nil {
- cache.Del(md.AuditLockKeyForCentralKitchenLockKey)
- e.OutErr(c, e.ERR_DB_ORM, "记录id:【"+v+"】不存在")
- return
- }
- if err1 != nil {
- cache.Del(md.AuditLockKeyForCentralKitchenLockKey)
- e.OutErr(c, e.ERR_DB_ORM, err1.Error())
- return
- }
- if returnDay.State != enum.CentralKitchenForSchoolUserRefundDayStateForAuditing {
- cache.Del(md.AuditLockKeyForCentralKitchenLockKey)
- _ = session.Rollback()
- e.OutErr(c, e.ERR, "请勿重复审核申请单!")
- return
- }
- if recordsId[returnDay.RecordsId] {
- cache.Del(md.AuditLockKeyForCentralKitchenLockKey)
- _ = session.Rollback()
- e.OutErr(c, e.ERR, "当前含有重复退订餐记录【身份id:"+utils.IntToStr(returnDay.IdentityId)+"】;"+"记录id:【"+v+"】!")
- return
- }
- recordsId[returnDay.RecordsId] = true
-
- //1、更新状态
- if req.State == 1 {
- returnDay.State = enum.CentralKitchenForSchoolUserRefundDayStateForAuditPass
- } else {
- userWithDay, err3 := centralKitchenForSchoolUserWithDayDb.GetCentralKitchenForSchoolUserWithDay(returnDay.RecordsId)
- if err3 != nil {
- cache.Del(md.AuditLockKeyForCentralKitchenLockKey)
- _ = session.Rollback()
- e.OutErr(c, e.ERR_DB_ORM, err3.Error())
- return
- }
-
- returnDay.State = enum.CentralKitchenForSchoolUserRefundDayStateForAuditReject
- userWithDay.State = enum.CentralKitchenForSchoolUserWithDayStateForWait
-
- updateAck1, err4 := centralKitchenForSchoolUserWithDayDb.CentralKitchenForSchoolUserWithDayUpdateBySess(session, userWithDay.Id, userWithDay, "state")
- if err4 != nil {
- cache.Del(md.AuditLockKeyForCentralKitchenLockKey)
- _ = session.Rollback()
- e.OutErr(c, e.ERR_DB_ORM, err4.Error())
- return
- }
- if updateAck1 <= 0 {
- cache.Del(md.AuditLockKeyForCentralKitchenLockKey)
- _ = session.Rollback()
- e.OutErr(c, e.ERR_DB_ORM, errors.New("更新退款就餐记录状态失败2"))
- return
- }
-
- //2、处理订单状态
- err5 := svc.JudgePackageOrdOrdState(returnDay.OutTradeNo)
- if err5 != nil {
- cache.Del(md.AuditLockKeyForCentralKitchenLockKey)
- _ = session.Rollback()
- e.OutErr(c, e.ERR, err5.Error())
- return
- }
- }
-
- returnDay.Memo = req.Memo
- updateAck, err2 := centralKitchenForSchoolUserRefundDayDb.CentralKitchenForSchoolUserRefundDayUpdateBySess(session, returnDay.Id, returnDay, "state", "memo")
- if err2 != nil {
- cache.Del(md.AuditLockKeyForCentralKitchenLockKey)
- _ = session.Rollback()
- e.OutErr(c, e.ERR_DB_ORM, err2.Error())
- return
- }
- if updateAck <= 0 {
- cache.Del(md.AuditLockKeyForCentralKitchenLockKey)
- _ = session.Rollback()
- e.OutErr(c, e.ERR_DB_ORM, errors.New("更新退款订单记录状态失败1"))
- return
- }
- }
-
- err = session.Commit()
- if err != nil {
- cache.Del(md.AuditLockKeyForCentralKitchenLockKey)
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
-
- if req.State == 1 {
- //TODO::审核通过,进行退款处理
- go func() {
- err1 := svc2.CentralKitchenForSchoolOrderRefundAudit(c, req)
- if err1 != nil {
- logx.Error(err1)
- println("<<<<CentralKitchenForSchoolOrderRefundAudit>>>>>Error:::", err1.Error())
- var m model.CentralKitchenForSchoolUserRefundDay
- m.Memo = "退款处理失败:(" + err1.Error() + ")"
- m.State = enum.CentralKitchenForSchoolUserRefundDayStateForAuditing
- db.Db.In("id", req.Ids).Cols("memo", "state").Update(&m)
- }
- cache.Del(md.AuditLockKeyForCentralKitchenLockKey)
- utils.FilePutContents("DealCentralKitchenForSchoolOrderRefundAudit", "退款处理,结束时间:::"+time.Now().Format("2006-01-02 15:04:05"))
- }()
- } else {
- cache.Del(md.AuditLockKeyForCentralKitchenLockKey)
- }
-
- e.OutSuc(c, "success", nil)
- return
- }
-
- func NursingHomeOrderRefundList(c *gin.Context) {
- var req md.NursingHomeOrderRefundListReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- err = validate.HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
- list, total, err := svc2.NursingHomeOrderRefundList(req)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- e.OutSuc(c, map[string]interface{}{
- "list": list,
- "total": total,
- "audit_kind_list": []map[string]interface{}{
- {
- "name": "同意",
- "value": 1,
- },
- {
- "name": "拒绝",
- "value": 2,
- },
- },
- "kind_list": []map[string]interface{}{
- {
- "name": enum.CentralKitchenForSchoolUserWithDayKind.String(enum.CentralKitchenForSchoolUserWithDayKindForBreakfast),
- "value": enum.CentralKitchenForSchoolUserWithDayKindForBreakfast,
- },
- {
- "name": enum.CentralKitchenForSchoolUserWithDayKind.String(enum.CentralKitchenForSchoolUserWithDayKindForLunch),
- "value": enum.CentralKitchenForSchoolUserWithDayKindForLunch,
- },
- {
- "name": enum.CentralKitchenForSchoolUserWithDayKind.String(enum.CentralKitchenForSchoolUserWithDayKindForDinner),
- "value": enum.CentralKitchenForSchoolUserWithDayKindForDinner,
- },
- },
- "state_list": []map[string]interface{}{
- {
- "name": enum.CentralKitchenForSchoolUserRefundDayState.String(enum.CentralKitchenForSchoolUserRefundDayStateForAuditing),
- "value": enum.CentralKitchenForSchoolUserRefundDayStateForAuditing,
- },
- {
- "name": enum.CentralKitchenForSchoolUserRefundDayState.String(enum.CentralKitchenForSchoolUserRefundDayStateForAuditPass),
- "value": enum.CentralKitchenForSchoolUserRefundDayStateForAuditPass,
- },
- {
- "name": enum.CentralKitchenForSchoolUserRefundDayState.String(enum.CentralKitchenForSchoolUserRefundDayStateForAuditReject),
- "value": enum.CentralKitchenForSchoolUserRefundDayStateForAuditReject,
- },
- {
- "name": enum.CentralKitchenForSchoolUserRefundDayState.String(enum.CentralKitchenForSchoolUserRefundDayStateForAuditComplete),
- "value": enum.CentralKitchenForSchoolUserRefundDayStateForAuditComplete,
- },
- },
- "user_identity_kind_list": []map[string]interface{}{
- {
- "name": enum.UserIdentity.String(enum.UserIdentityForCentralKitchenForStudent),
- "value": enum.UserIdentityForCentralKitchenForStudent,
- },
- {
- "name": enum.UserIdentity.String(enum.UserIdentityForCentralKitchenForTeacher),
- "value": enum.UserIdentityForCentralKitchenForTeacher,
- },
- {
- "name": enum.UserIdentity.String(enum.UserIdentityForCentralKitchenForWorker),
- "value": enum.UserIdentityForCentralKitchenForWorker,
- },
- {
- "name": enum.UserIdentity.String(enum.UserIdentityForSelfSupportForStudent),
- "value": enum.UserIdentityForSelfSupportForStudent,
- },
- {
- "name": enum.UserIdentity.String(enum.UserIdentityForSelfSupportForTeacher),
- "value": enum.UserIdentityForSelfSupportForTeacher,
- },
- {
- "name": enum.UserIdentity.String(enum.UserIdentityForSelfSupportForWorker),
- "value": enum.UserIdentityForSelfSupportForWorker,
- },
- },
- }, nil)
- return
- }
-
- func NursingHomeOrderRefundAudit(c *gin.Context) {
- var req md.NursingHomeOrderRefundAuditReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- err = validate.HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
- err = svc2.NursingHomeOrderRefundAudit(req)
- if err != nil {
- e.OutErr(c, e.ERR, err.Error())
- return
- }
- e.OutSuc(c, "success", nil)
- return
- }
|