From da009b7eacc94b09044bf340e9b94bd8c3ca1f0d Mon Sep 17 00:00:00 2001 From: DengBiao <2319963317@qq.com> Date: Fri, 1 Dec 2023 13:39:43 +0800 Subject: [PATCH] update --- .../hdl_central_kitchen_for_school.go | 14 + .../hdl_self_support_for_school.go | 239 ++++++++---------- app/admin/md/md_enterprise_manage.go | 70 ++--- .../svc_central_kitchen_for_school.go | 148 +++++++++++ .../svc_self_support_for_school.go | 154 +++++++++++ app/customer/md/md_curl_smart_pay.go | 26 +- app/customer/svc/svc_curl_smart_pay.go | 8 +- .../self_support_for_user_consume_limit.go | 20 +- 8 files changed, 484 insertions(+), 195 deletions(-) diff --git a/app/admin/hdl/enterprise_manage/hdl_central_kitchen_for_school.go b/app/admin/hdl/enterprise_manage/hdl_central_kitchen_for_school.go index a91e385..3550681 100644 --- a/app/admin/hdl/enterprise_manage/hdl_central_kitchen_for_school.go +++ b/app/admin/hdl/enterprise_manage/hdl_central_kitchen_for_school.go @@ -823,7 +823,21 @@ func CentralKitchenForSchoolOrdList(c *gin.Context) { e.OutErr(c, e.ERR, err.Error()) return } + + personNum, orderCountByDay, orderCountByMonth, orderCountByTerm, consumeAmount, err := svc2.CentralKitchenForSchoolOrdStatistics(req) + if err != nil { + e.OutErr(c, e.ERR, err.Error()) + return + } + e.OutSuc(c, map[string]interface{}{ + "statistics": map[string]interface{}{ + "person_num": personNum, + "order_count_by_day": orderCountByDay, + "order_count_by_month": orderCountByMonth, + "order_count_by_term": orderCountByTerm, + "consume_amount": consumeAmount, + }, "list": resp, "total": total, "enterprise_kind_list": md.EnterpriseKindForSchool, diff --git a/app/admin/hdl/enterprise_manage/hdl_self_support_for_school.go b/app/admin/hdl/enterprise_manage/hdl_self_support_for_school.go index a2b8760..729f6ce 100644 --- a/app/admin/hdl/enterprise_manage/hdl_self_support_for_school.go +++ b/app/admin/hdl/enterprise_manage/hdl_self_support_for_school.go @@ -13,6 +13,7 @@ import ( "applet/app/enum" "applet/app/utils" "encoding/csv" + "encoding/json" "fmt" "github.com/360EntSecGroup-Skylar/excelize" "github.com/gin-gonic/gin" @@ -1079,7 +1080,22 @@ func SelfSupportForSchoolOrdList(c *gin.Context) { e.OutErr(c, e.ERR, err.Error()) return } + + personNum, count, consumeAmount, alreadyPayAmount, waitPayAmount, refundPayAmount, err := svc2.SelfSupportForSchoolOrdStatistics(req) + if err != nil { + e.OutErr(c, e.ERR, err.Error()) + return + } + e.OutSuc(c, map[string]interface{}{ + "statistics": map[string]interface{}{ + "person_num": personNum, + "order_count": count, + "consume_amount": consumeAmount, + "already_pay_amount": alreadyPayAmount, + "wait_pay_amount": waitPayAmount, + "refund_pay_amount": refundPayAmount, + }, "list": resp, "total": total, "enterprise_kind_list": md.EnterpriseKindForSchool, @@ -1102,7 +1118,7 @@ func SelfSupportForSchoolOrdList(c *gin.Context) { } func SelfSupportForSchoolConsumeLimit(c *gin.Context) { - var req []*md.SelfSupportForSchoolConsumeLimitReq + var req md.SelfSupportForSchoolConsumeLimitReq err := c.ShouldBindJSON(&req) if err != nil { err = validate.HandleValidateErr(err) @@ -1110,6 +1126,17 @@ func SelfSupportForSchoolConsumeLimit(c *gin.Context) { e.OutErr(c, err1.Code, err1.Error()) return } + //TODO::业务校验 + var totalMaxConsumeTimes int + for _, v := range req.RosterPeriodConsumeLimitConfigList { + totalMaxConsumeTimes += v.MaxConsumeTimes + } + if totalMaxConsumeTimes > utils.StrToInt(req.DailyMaxConsumeTimes) { + fmt.Println(utils.StrToInt(req.DailyMaxConsumeTimes)) + e.OutErr(c, e.ERR_INVALID_ARGS, "单日最大消费次数,上限99(如需设置需要大于餐段次数之和,否则可能会导致餐段消费次数不足)") + return + } + enterpriseId := utils.StrToInt(c.DefaultQuery("enterprise_id", "")) enterpriseDb := db.EnterpriseDb{} enterpriseDb.Set() @@ -1135,80 +1162,82 @@ func SelfSupportForSchoolConsumeLimit(c *gin.Context) { selfSupportForUserFaceInfoDb := db.SelfSupportForUserFaceInfoDb{} userIdentityDb := db.UserIdentityDb{} - var data md2.CurlAlipayPlanetEcocampusApiRosterConsumeLimit - var mm []*model.SelfSupportForUserConsumeLimit - var userIdentityIds []int + var data md2.CurlAlipayPlanetEcocampusApiRosterSingleConsumeLimitSync now := time.Now() - for _, v := range req { - selfSupportForUserFaceInfoDb.Set(v.UserIdentityId) - userIdentityDb.Set(0) - faceInfo, err := selfSupportForUserFaceInfoDb.GetSelfSupportForUserFaceInfo() - if err != nil { - e.OutErr(c, e.ERR_DB_ORM, err.Error()) - return - } - if faceInfo == nil { - e.OutErr(c, e.ERR_NO_DATA, "用户【"+utils.IntToStr(v.UserIdentityId)+"】身份未查询到一脸通行相关数据") - return - } - identity, err := userIdentityDb.GetUserIdentity(v.UserIdentityId) - if err != nil { - e.OutErr(c, e.ERR_DB_ORM, err.Error()) - return - } - if identity == nil { - e.OutErr(c, e.ERR_NO_DATA, "用户【"+utils.IntToStr(v.UserIdentityId)+"】身份未查询到") - return - } - - data.SchoolCode = selfSupportForSchoolInfo.SchoolCode - data.SchoolName = selfSupportForSchoolInfo.SchoolName - data.ConsumeLimitSyncInfo = append(data.ConsumeLimitSyncInfo, md2.ConsumeLimitSyncInfo{ - FaceUid: faceInfo.UserId, - OutRosterCode: utils.IntToStr(v.UserIdentityId), - RosterName: identity.Name, - DailyConsumeLimit: v.DailyConsumeLimit, - DailyConsumeLimitSwitch: v.DailyConsumeLimitSwitch, - SingleConsumeLimit: v.SingleConsumeLimit, - SingleConsumeLimitSwitch: v.SingleConsumeLimitSwitch, - DailyConsumeNumber: v.DailyConsumeNumber, - DailyConsumeNumberSwitch: v.DailyConsumeNumberSwitch, - }) - mm = append(mm, &model.SelfSupportForUserConsumeLimit{ - EnterpriseId: enterpriseId, - UserIdentityId: v.UserIdentityId, - DailyConsumeLimit: v.DailyConsumeLimit, - DailyConsumeLimitSwitch: v.DailyConsumeLimitSwitch, - SingleConsumeLimit: v.SingleConsumeLimit, - SingleConsumeLimitSwitch: v.SingleConsumeLimitSwitch, - DailyConsumeNumber: v.DailyConsumeNumber, - DailyConsumeNumberSwitch: v.DailyConsumeNumberSwitch, - CreateAt: now.Format("2006-01-02 15:04:05"), - UpdateAt: now.Format("2006-01-02 15:04:05"), - }) - userIdentityIds = append(userIdentityIds, v.UserIdentityId) + selfSupportForUserFaceInfoDb.Set(req.UserIdentityId) + userIdentityDb.Set(0) + faceInfo, err := selfSupportForUserFaceInfoDb.GetSelfSupportForUserFaceInfo() + if err != nil { + e.OutErr(c, e.ERR_DB_ORM, err.Error()) + return + } + if faceInfo == nil { + e.OutErr(c, e.ERR_NO_DATA, "用户【"+utils.IntToStr(req.UserIdentityId)+"】身份未查询到一脸通行相关数据") + return + } + identity, err := userIdentityDb.GetUserIdentity(req.UserIdentityId) + if err != nil { + e.OutErr(c, e.ERR_DB_ORM, err.Error()) + return + } + if identity == nil { + e.OutErr(c, e.ERR_NO_DATA, "用户【"+utils.IntToStr(req.UserIdentityId)+"】身份未查询到") + return } - err, resp := svc.CurlAlipayPlanetEcocampusApiRosterConsumeLimit(data) + data.SchoolCode = selfSupportForSchoolInfo.SchoolCode + data.FaceUid = faceInfo.UserId + data.RosterName = identity.Name + data.DailyConsumeLimit = req.DailyConsumeLimit + data.SingleConsumeLimit = req.SingleConsumeLimit + data.DailyMaxConsumeTimes = req.DailyMaxConsumeTimes + data.RosterPeriodConsumeLimitConfigList = req.RosterPeriodConsumeLimitConfigList + err, resp := svc.CurlAlipayPlanetEcocampusApiRosterSingleConsumeLimitSync(data) fmt.Println(">>>>>>>>>>>>>>>>>!!!<<<<<<<<<<<<<<<<", data, err) - if err != nil { e.OutErr(c, e.ERR, err.Error()) return } //TODO::记录到表中 - _, err = db.Db.In("user_identity_id", userIdentityIds).Delete(model.SelfSupportForUserConsumeLimit{}) - if err != nil { - return - } selfSupportForUserConsumeLimitDb := db.SelfSupportForUserConsumeLimitDb{} - selfSupportForUserConsumeLimitDb.Set(0) - _, err = selfSupportForUserConsumeLimitDb.BatchAdd(mm) + selfSupportForUserConsumeLimitDb.Set(req.UserIdentityId) + m, err := selfSupportForUserConsumeLimitDb.GetSelfSupportForUserConsumeLimit() if err != nil { - e.OutErr(c, e.ERR, err.Error()) + e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } + if m == nil { + m = &model.SelfSupportForUserConsumeLimit{ + EnterpriseId: enterpriseId, + UserIdentityId: req.UserIdentityId, + DailyConsumeLimit: req.DailyConsumeLimit, + SingleConsumeLimit: req.SingleConsumeLimit, + DailyMaxConsumeTimes: req.DailyMaxConsumeTimes, + RosterPeriodConsumeLimitConfigList: utils.SerializeStr(req.RosterPeriodConsumeLimitConfigList), + CreateAt: now.Format("2006-01-02 15:04:05"), + UpdateAt: now.Format("2006-01-02 15:04:05"), + } + _, err1 := selfSupportForUserConsumeLimitDb.SelfSupportForUserConsumeLimitInsert(m) + if err1 != nil { + e.OutErr(c, e.ERR_DB_ORM, err1.Error()) + return + } + } else { + m.EnterpriseId = enterpriseId + m.UserIdentityId = req.UserIdentityId + m.DailyConsumeLimit = req.DailyConsumeLimit + m.SingleConsumeLimit = req.SingleConsumeLimit + m.DailyMaxConsumeTimes = req.DailyMaxConsumeTimes + m.RosterPeriodConsumeLimitConfigList = utils.SerializeStr(req.RosterPeriodConsumeLimitConfigList) + m.UpdateAt = now.Format("2006-01-02 15:04:05") + _, err1 := selfSupportForUserConsumeLimitDb.SelfSupportForUserConsumeLimitUpdate(m, + "enterprise_id", "user_identity_id", "daily_consume_limit", "single_consume_limit", "daily_consume_number", "roster_period_consume_limit_config_list") + if err1 != nil { + e.OutErr(c, e.ERR_DB_ORM, err1.Error()) + return + } + } e.OutSuc(c, resp, nil) return @@ -1273,21 +1302,6 @@ func SelfSupportForSchoolConsumeLimitList(c *gin.Context) { if req.DailyConsumeLimit != "" { sess.And("self_support_for_user_consume_limit.daily_consume_limit = ?", req.DailyConsumeLimit) } - if req.DailyConsumeLimitSwitch != "" { - sess.And("self_support_for_user_consume_limit.daily_consume_limit_switch = ?", req.DailyConsumeLimitSwitch) - } - if req.SingleConsumeLimit != "" { - sess.And("self_support_for_user_consume_limit.single_consume_limit = ?", req.SingleConsumeLimit) - } - if req.SingleConsumeLimitSwitch != "" { - sess.And("self_support_for_user_consume_limit.single_consume_limit_switch = ?", req.SingleConsumeLimitSwitch) - } - if req.DailyConsumeNumber != "" { - sess.And("self_support_for_user_consume_limit.daily_consume_number = ?", req.DailyConsumeNumber) - } - if req.DailyConsumeNumberSwitch != "" { - sess.And("self_support_for_user_consume_limit.daily_consume_number_switch = ?", req.DailyConsumeNumberSwitch) - } if req.Name != "" { sess.And("user_identity.name like ?", "%"+req.Name+"%") } @@ -1316,67 +1330,34 @@ func SelfSupportForSchoolConsumeLimitList(c *gin.Context) { var list []md.SelfSupportForSchoolConsumeLimitListResp for _, v := range m { - var dailyConsumeLimitSwitch, singleConsumeLimitSwitch, dailyConsumeNumberSwitch = "off", "off", "off" - if v.SelfSupportForUserConsumeLimit.DailyConsumeLimitSwitch != "" { - dailyConsumeLimitSwitch = v.SelfSupportForUserConsumeLimit.DailyConsumeLimitSwitch - } - if v.SelfSupportForUserConsumeLimit.SingleConsumeLimitSwitch != "" { - singleConsumeLimitSwitch = v.SelfSupportForUserConsumeLimit.SingleConsumeLimitSwitch - } - if v.SelfSupportForUserConsumeLimit.DailyConsumeNumberSwitch != "" { - dailyConsumeNumberSwitch = v.SelfSupportForUserConsumeLimit.DailyConsumeNumberSwitch + var rosterPeriodConsumeLimitConfigList []md.RosterPeriodConsumeLimitConfig + if v.SelfSupportForUserConsumeLimit.DailyMaxConsumeTimes != "" { + err = json.Unmarshal([]byte(v.SelfSupportForUserConsumeLimit.DailyMaxConsumeTimes), &rosterPeriodConsumeLimitConfigList) + if err != nil { + e.OutErr(c, e.ERR, err.Error()) + return + } } list = append(list, md.SelfSupportForSchoolConsumeLimitListResp{ - UserIdentityId: v.UserIdentity.Id, - Name: v.UserIdentity.Name, - GradeId: v.Grade.Id, - GradeName: v.Grade.Name, - ClassId: v.Class.Id, - ClassName: v.Class.Name, - Phone: v.User.Phone, - DailyConsumeLimit: v.SelfSupportForUserConsumeLimit.DailyConsumeLimit, - DailyConsumeLimitSwitch: dailyConsumeLimitSwitch, - SingleConsumeLimit: v.SelfSupportForUserConsumeLimit.SingleConsumeLimit, - SingleConsumeLimitSwitch: singleConsumeLimitSwitch, - DailyConsumeNumber: v.SelfSupportForUserConsumeLimit.DailyConsumeNumber, - DailyConsumeNumberSwitch: dailyConsumeNumberSwitch, + UserIdentityId: v.UserIdentity.Id, + Name: v.UserIdentity.Name, + GradeId: v.Grade.Id, + GradeName: v.Grade.Name, + ClassId: v.Class.Id, + ClassName: v.Class.Name, + Phone: v.User.Phone, + DailyConsumeLimit: v.SelfSupportForUserConsumeLimit.DailyConsumeLimit, + SingleConsumeLimit: v.SelfSupportForUserConsumeLimit.SingleConsumeLimit, + DailyMaxConsumeTimes: v.SelfSupportForUserConsumeLimit.DailyMaxConsumeTimes, + RosterPeriodConsumeLimitConfigList: rosterPeriodConsumeLimitConfigList, }) } + e.OutSuc(c, map[string]interface{}{ "list": list, "enterprise_kind_list": md.EnterpriseKindForSchool, - "daily_consume_limit_switch_list": []map[string]string{ - { - "name": "开启", - "value": "ON", - }, - { - "name": "关闭", - "value": "OFF", - }, - }, - "single_consume_limit_switch_list": []map[string]string{ - { - "name": "开启", - "value": "ON", - }, - { - "name": "关闭", - "value": "OFF", - }, - }, - "daily_consume_number_switch_list": []map[string]string{ - { - "name": "开启", - "value": "ON", - }, - { - "name": "关闭", - "value": "OFF", - }, - }, - "total": count, + "total": count, }, nil) return } diff --git a/app/admin/md/md_enterprise_manage.go b/app/admin/md/md_enterprise_manage.go index c841d3d..ec883cf 100644 --- a/app/admin/md/md_enterprise_manage.go +++ b/app/admin/md/md_enterprise_manage.go @@ -503,47 +503,47 @@ type SelfSupportForSchoolOrdListReq struct { } type SelfSupportForSchoolConsumeLimitReq struct { - UserIdentityId int `json:"user_identity_id" label:"用户身份id"` - DailyConsumeLimit string `json:"daily_consume_limit" label:"单日金额上限"` - DailyConsumeLimitSwitch string `json:"daily_consume_limit_switch" label:"单日金额上限 功能开关"` - SingleConsumeLimit string `json:"single_consume_limit" label:"单笔金额上限"` - SingleConsumeLimitSwitch string `json:"single_consume_limit_switch" label:"单笔金额上限 功能开关"` - DailyConsumeNumber string `json:"daily_consume_number" label:"单日笔数上限"` - DailyConsumeNumberSwitch string `json:"daily_consume_number_switch" label:"单日笔数上限 功能开关"` + UserIdentityId int `json:"user_identity_id" label:"用户身份id"` + DailyConsumeLimit string `json:"daily_consume_limit" label:"单日金额上限"` + SingleConsumeLimit string `json:"single_consume_limit" label:"单笔金额上限"` + DailyMaxConsumeTimes string `json:"daily_max_consume_times" label:"单日最大消费次数"` + RosterPeriodConsumeLimitConfigList []RosterPeriodConsumeLimitConfig `json:"roster_period_consume_limit_config_list" label:"餐段设置"` +} + +type RosterPeriodConsumeLimitConfig struct { + PeriodDesc string `json:"period_desc" label:"餐段时间描述"` + StartTime string `json:"start_time" label:"餐段开始时间,格式为:xx:xx"` + EndTime string `json:"end_time" label:"餐段结束时间,格式为:xx:xx"` + MaxConsumeTimes int `json:"max_consume_times" label:"餐段内最大消费次数,默认值1,最大9"` } type SelfSupportForSchoolConsumeLimitListReq struct { - EnterpriseId int `json:"enterprise_id" binding:"required" label:"企业id"` - EnterpriseKind int `json:"enterprise_kind" label:"企业类型"` - Limit int `json:"limit" binding:"required"` - Page int `json:"page" binding:"required"` - Name string `json:"name" label:"姓名"` - GradeId int `json:"grade_id" label:"年级id"` - ClassId int `json:"class_id" label:"班级id"` - Phone string `json:"phone" label:"用户电话"` - DailyConsumeLimit string `json:"daily_consume_limit" label:"单日金额上限"` - DailyConsumeLimitSwitch string `json:"daily_consume_limit_switch" label:"单日金额上限 功能开关"` - SingleConsumeLimit string `json:"single_consume_limit" label:"单笔金额上限"` - SingleConsumeLimitSwitch string `json:"single_consume_limit_switch" label:"单笔金额上限 功能开关"` - DailyConsumeNumber string `json:"daily_consume_number" label:"单日笔数上限"` - DailyConsumeNumberSwitch string `json:"daily_consume_number_switch" label:"单日笔数上限 功能开关"` - IsTeacher int `json:"is_teacher" label:"是否教师"` + EnterpriseId int `json:"enterprise_id" binding:"required" label:"企业id"` + EnterpriseKind int `json:"enterprise_kind" label:"企业类型"` + Limit int `json:"limit" binding:"required"` + Page int `json:"page" binding:"required"` + Name string `json:"name" label:"姓名"` + GradeId int `json:"grade_id" label:"年级id"` + ClassId int `json:"class_id" label:"班级id"` + Phone string `json:"phone" label:"用户电话"` + DailyConsumeLimit string `json:"daily_consume_limit" label:"单日金额上限"` + SingleConsumeLimit string `json:"single_consume_limit" label:"单笔金额上限"` + DailyMaxConsumeTimes string `json:"daily_max_consume_times" label:"单日最大消费次数"` + IsTeacher int `json:"is_teacher" label:"是否教师"` } type SelfSupportForSchoolConsumeLimitListResp struct { - UserIdentityId int `json:"user_identity_id" label:"用户身份id"` - Name string `json:"name" label:"姓名"` - GradeId int `json:"grade_id" label:"年级id"` - GradeName string `json:"grade_name" label:"年级名称"` - ClassId int `json:"class_id" label:"班级id"` - ClassName string `json:"class_name" label:"班级名称"` - Phone string `json:"phone" label:"用户电话"` - DailyConsumeLimit string `json:"daily_consume_limit" label:"单日金额上限"` - DailyConsumeLimitSwitch string `json:"daily_consume_limit_switch" label:"单日金额上限 功能开关"` - SingleConsumeLimit string `json:"single_consume_limit" label:"单笔金额上限"` - SingleConsumeLimitSwitch string `json:"single_consume_limit_switch" label:"单笔金额上限 功能开关"` - DailyConsumeNumber string `json:"daily_consume_number" label:"单日笔数上限"` - DailyConsumeNumberSwitch string `json:"daily_consume_number_switch" label:"单日笔数上限 功能开关"` + UserIdentityId int `json:"user_identity_id" label:"用户身份id"` + Name string `json:"name" label:"姓名"` + GradeId int `json:"grade_id" label:"年级id"` + GradeName string `json:"grade_name" label:"年级名称"` + ClassId int `json:"class_id" label:"班级id"` + ClassName string `json:"class_name" label:"班级名称"` + Phone string `json:"phone" label:"用户电话"` + DailyConsumeLimit string `json:"daily_consume_limit" label:"单日金额上限"` + SingleConsumeLimit string `json:"single_consume_limit" label:"单笔金额上限"` + DailyMaxConsumeTimes string `json:"daily_max_consume_times" label:"单日最大消费次数"` + RosterPeriodConsumeLimitConfigList []RosterPeriodConsumeLimitConfig `json:"roster_period_consume_limit_config_list" label:"餐段设置"` } type SelfSupportForSchoolArrearsOrdListReq struct { diff --git a/app/admin/svc/enterprise_manage/svc_central_kitchen_for_school.go b/app/admin/svc/enterprise_manage/svc_central_kitchen_for_school.go index 6961729..f8e248d 100644 --- a/app/admin/svc/enterprise_manage/svc_central_kitchen_for_school.go +++ b/app/admin/svc/enterprise_manage/svc_central_kitchen_for_school.go @@ -718,6 +718,154 @@ func CentralKitchenForSchoolOrdList(req md.CentralKitchenForSchoolOrdListReq) (r return } +func CentralKitchenForSchoolOrdStatistics(req md.CentralKitchenForSchoolOrdListReq) (personNum, orderCountByDay, orderCountByMonth, orderCountByTerm int64, consumeAmount float64, err error) { + var classWithUserIdentityIdsOne []int + var classWithUserIdentityIdsTwo []int + classWithUserDb := db.ClassWithUserDb{} + classWithUserDb.Set() + if req.ClassId != 0 { + classWithUsers, err2 := classWithUserDb.FindUserIdentity(req.ClassId) + if err2 != nil { + return 0, 0, 0, 0, 0, err2 + } + for _, v := range *classWithUsers { + classWithUserIdentityIdsOne = append(classWithUserIdentityIdsOne, v.UserIdentityId) + } + } + if req.GradeId != 0 { + classDb := db.ClassDb{} + classDb.Set(req.GradeId) + classes, err3 := classDb.FindClass() + if err3 != nil { + return 0, 0, 0, 0, 0, err3 + } + var classesId []int + for _, v := range *classes { + classesId = append(classesId, v.Id) + } + classWithUsers, err4 := classWithUserDb.FindUserIdentity(classesId) + if err4 != nil { + return 0, 0, 0, 0, 0, err4 + } + for _, v := range *classWithUsers { + classWithUserIdentityIdsTwo = append(classWithUserIdentityIdsTwo, v.UserIdentityId) + } + } + + sess := db.Db.Desc("central_kitchen_for_school_package_ord.id") + if req.EnterpriseId != 0 { + sess.And("central_kitchen_for_school_package_ord.enterprise_id =?", req.EnterpriseId) + } + if req.IsTeacher != 0 { + if req.IsTeacher == 1 { + sess.And("user_identity.identity =?", enum2.UserIdentityForCentralKitchenForTeacher) + } + if req.IsTeacher == 2 { + sess.And("user_identity.identity !=?", enum2.UserIdentityForCentralKitchenForTeacher) + } + } + if req.StartDate != "" { + sess.And("central_kitchen_for_school_package_ord.create_at >= ?", req.StartDate) + } + if req.EndDate != "" { + sess.And("central_kitchen_for_school_package_ord.create_at <= ?", req.EndDate) + } + if req.Kind != 0 { + sess.And("central_kitchen_for_school_package_ord.kind = ?", req.Kind) + } + if req.Sate != -1 { + sess.And("central_kitchen_for_school_package_ord.state = ?", req.Sate) + } + if req.OrdSate != -1 { + sess.And("central_kitchen_for_school_package_ord.ord_state = ?", req.OrdSate) + } + if req.OutTradeNo != "" { + sess.And("central_kitchen_for_school_package_ord.out_trade_no like ?", "%"+req.OutTradeNo+"%") + } + + if req.Name != "" { + sess.And("user_identity.name like ?", "%"+req.Name+"%") + } + if req.Phone != "" { + sess.And("user.phone like ?", "%"+req.Phone+"%") + } + + if req.EnterPriseKind != 0 { + sess.And("enterprise.kind = ?", req.EnterPriseKind) + } + + if len(classWithUserIdentityIdsOne) > 0 { + sess.In("user_identity.id", classWithUserIdentityIdsOne) + } + if len(classWithUserIdentityIdsTwo) > 0 { + sess.In("user_identity.id", classWithUserIdentityIdsTwo) + } + var sess1, sess2, sess3, sess4, sess5 = sess, sess, sess, sess, sess + + var m []*db.CentralKitchenForSchoolPackageOrdWithUserIdentity + personNum, err = sess1. + Join("LEFT", "user_identity", "central_kitchen_for_school_package_ord.user_identity_id = user_identity.id"). + Join("LEFT", "enterprise", "enterprise.id = user_identity.enterprise_id"). + Join("LEFT", "user", "user.id = user_identity.uid"). + Join("LEFT", "class_with_user", "class_with_user.user_identity_id = user_identity.id"). + Join("LEFT", "class", "class_with_user.class_id = class.id"). + Join("LEFT", "grade", "class.grade_id = grade.id"). + GroupBy("central_kitchen_for_school_package_ord.user_identity_id"). + FindAndCount(&m) + if err != nil { + return 0, 0, 0, 0, 0, err + } + + orderCountByTerm, err = sess2.And("central_kitchen_for_school_package_ord.kind = ?", 1). + Join("LEFT", "user_identity", "central_kitchen_for_school_package_ord.user_identity_id = user_identity.id"). + Join("LEFT", "enterprise", "enterprise.id = user_identity.enterprise_id"). + Join("LEFT", "user", "user.id = user_identity.uid"). + Join("LEFT", "class_with_user", "class_with_user.user_identity_id = user_identity.id"). + Join("LEFT", "class", "class_with_user.class_id = class.id"). + Join("LEFT", "grade", "class.grade_id = grade.id"). + FindAndCount(&m) + if err != nil { + return 0, 0, 0, 0, 0, err + } + orderCountByMonth, err = sess3.And("central_kitchen_for_school_package_ord.kind = ?", 2). + Join("LEFT", "user_identity", "central_kitchen_for_school_package_ord.user_identity_id = user_identity.id"). + Join("LEFT", "enterprise", "enterprise.id = user_identity.enterprise_id"). + Join("LEFT", "user", "user.id = user_identity.uid"). + Join("LEFT", "class_with_user", "class_with_user.user_identity_id = user_identity.id"). + Join("LEFT", "class", "class_with_user.class_id = class.id"). + Join("LEFT", "grade", "class.grade_id = grade.id"). + FindAndCount(&m) + if err != nil { + return 0, 0, 0, 0, 0, err + } + orderCountByDay, err = sess4.And("central_kitchen_for_school_package_ord.kind = ?", 3). + Join("LEFT", "user_identity", "central_kitchen_for_school_package_ord.user_identity_id = user_identity.id"). + Join("LEFT", "enterprise", "enterprise.id = user_identity.enterprise_id"). + Join("LEFT", "user", "user.id = user_identity.uid"). + Join("LEFT", "class_with_user", "class_with_user.user_identity_id = user_identity.id"). + Join("LEFT", "class", "class_with_user.class_id = class.id"). + Join("LEFT", "grade", "class.grade_id = grade.id"). + FindAndCount(&m) + if err != nil { + return 0, 0, 0, 0, 0, err + } + + var mm db.CentralKitchenForSchoolPackageOrdWithUserIdentity + consumeAmount, err = sess5. + Join("LEFT", "user_identity", "central_kitchen_for_school_package_ord.user_identity_id = user_identity.id"). + Join("LEFT", "enterprise", "enterprise.id = user_identity.enterprise_id"). + Join("LEFT", "user", "user.id = user_identity.uid"). + Join("LEFT", "class_with_user", "class_with_user.user_identity_id = user_identity.id"). + Join("LEFT", "class", "class_with_user.class_id = class.id"). + Join("LEFT", "grade", "class.grade_id = grade.id"). + Sum(mm, "central_kitchen_for_school_package_ord.total_price") + if err != nil { + return 0, 0, 0, 0, 0, err + } + + return +} + func CentralKitchenForSchoolReserveList(req md.CentralKitchenForSchoolReserveListReq) (resp []md.CentralKitchenForSchoolReserveListResp, count int64, err error) { var classWithUserIdentityIdsOne []int var classWithUserIdentityIdsTwo []int diff --git a/app/admin/svc/enterprise_manage/svc_self_support_for_school.go b/app/admin/svc/enterprise_manage/svc_self_support_for_school.go index 1cbc7c6..b276121 100644 --- a/app/admin/svc/enterprise_manage/svc_self_support_for_school.go +++ b/app/admin/svc/enterprise_manage/svc_self_support_for_school.go @@ -669,6 +669,160 @@ func SelfSupportForSchoolOrdList(req md.SelfSupportForSchoolOrdListReq) (resp [] return } +func SelfSupportForSchoolOrdStatistics(req md.SelfSupportForSchoolOrdListReq) (personNum, count int64, consumeAmount, alreadyPayAmount, waitPayAmount, refundPayAmount float64, err error) { + var classWithUserIdentityIdsOne []int + var classWithUserIdentityIdsTwo []int + classWithUserDb := db.ClassWithUserDb{} + classWithUserDb.Set() + if req.ClassId != 0 { + classWithUsers, err2 := classWithUserDb.FindUserIdentity(req.ClassId) + if err2 != nil { + return 0, 0, 0, 0, 0, 0, err2 + } + for _, v := range *classWithUsers { + classWithUserIdentityIdsOne = append(classWithUserIdentityIdsOne, v.UserIdentityId) + } + } + if req.GradeId != 0 { + classDb := db.ClassDb{} + classDb.Set(req.GradeId) + classes, err3 := classDb.FindClass() + if err3 != nil { + return 0, 0, 0, 0, 0, 0, err + } + var classesId []int + for _, v := range *classes { + classesId = append(classesId, v.Id) + } + classWithUsers, err4 := classWithUserDb.FindUserIdentity(classesId) + if err4 != nil { + return 0, 0, 0, 0, 0, 0, err + } + for _, v := range *classWithUsers { + classWithUserIdentityIdsTwo = append(classWithUserIdentityIdsTwo, v.UserIdentityId) + } + } + + sess := db.Db.Desc("self_support_for_school_ord.id") + if req.EnterpriseId != 0 { + sess.And("self_support_for_school_ord.enterprise_id =?", req.EnterpriseId) + } + if req.StartDate != "" { + sess.And("self_support_for_school_ord.face_time >= ?", req.StartDate) + } + if req.EndDate != "" { + sess.And("self_support_for_school_ord.face_time <= ?", req.EndDate) + } + if req.OrderStatus != 0 { + sess.And("self_support_for_school_ord.order_status = ?", req.OrderStatus) + } + if req.OutTradeNo != "" { + sess.And("self_support_for_school_ord.out_order_no like ?", "%"+req.OutTradeNo+"%") + } + if req.EnterpriseKind != 0 { + sess.And("enterprise.kind = ?", req.EnterpriseKind) + } + if req.IsTeacher != 0 { + if req.IsTeacher == 1 { + sess.And("user_identity.identity =?", enum2.UserIdentityForCentralKitchenForTeacher) + } + if req.IsTeacher == 2 { + sess.And("user_identity.identity !=?", enum2.UserIdentityForCentralKitchenForTeacher) + } + } + + if req.Name != "" { + sess.And("user_identity.name like ?", "%"+req.Name+"%") + } + if req.Phone != "" { + sess.And("user.phone like ?", "%"+req.Phone+"%") + } + if len(classWithUserIdentityIdsOne) > 0 { + sess.In("user_identity.id", classWithUserIdentityIdsOne) + } + if len(classWithUserIdentityIdsTwo) > 0 { + sess.In("user_identity.id", classWithUserIdentityIdsTwo) + } + var sess1, sess2, sess3, sess4, sess5, sess6 = sess, sess, sess, sess, sess, sess + + var m []*db.SelfSupportForSchoolOrdWithUserIdentity + personNum, err = sess1. + Join("LEFT", "user_identity", "self_support_for_school_ord.user_identity_id = user_identity.id"). + Join("LEFT", "enterprise", "enterprise.id = user_identity.enterprise_id"). + Join("LEFT", "user", "user.id = user_identity.uid"). + Join("LEFT", "class_with_user", "class_with_user.user_identity_id = user_identity.id"). + Join("LEFT", "class", "class_with_user.class_id = class.id"). + Join("LEFT", "grade", "class.grade_id = grade.id"). + GroupBy("self_support_for_school_ord.user_identity_id"). + FindAndCount(&m) + if err != nil { + return 0, 0, 0, 0, 0, 0, err + } + + count, err = sess2. + Join("LEFT", "user_identity", "self_support_for_school_ord.user_identity_id = user_identity.id"). + Join("LEFT", "enterprise", "enterprise.id = user_identity.enterprise_id"). + Join("LEFT", "user", "user.id = user_identity.uid"). + Join("LEFT", "class_with_user", "class_with_user.user_identity_id = user_identity.id"). + Join("LEFT", "class", "class_with_user.class_id = class.id"). + Join("LEFT", "grade", "class.grade_id = grade.id"). + FindAndCount(&m) + if err != nil { + return 0, 0, 0, 0, 0, 0, err + } + + var mm db.SelfSupportForSchoolOrdWithUserIdentity + consumeAmount, err = sess3. + Join("LEFT", "user_identity", "self_support_for_school_ord.user_identity_id = user_identity.id"). + Join("LEFT", "enterprise", "enterprise.id = user_identity.enterprise_id"). + Join("LEFT", "user", "user.id = user_identity.uid"). + Join("LEFT", "class_with_user", "class_with_user.user_identity_id = user_identity.id"). + Join("LEFT", "class", "class_with_user.class_id = class.id"). + Join("LEFT", "grade", "class.grade_id = grade.id"). + Sum(mm, "self_support_for_school_ord.trade_amount") + if err != nil { + return 0, 0, 0, 0, 0, 0, err + } + + waitPayAmount, err = sess4.And("self_support_for_school_ord.order_status = ?", enum2.SelfSupportForSchoolOrdOrderStatusForWait). + Join("LEFT", "user_identity", "self_support_for_school_ord.user_identity_id = user_identity.id"). + Join("LEFT", "enterprise", "enterprise.id = user_identity.enterprise_id"). + Join("LEFT", "user", "user.id = user_identity.uid"). + Join("LEFT", "class_with_user", "class_with_user.user_identity_id = user_identity.id"). + Join("LEFT", "class", "class_with_user.class_id = class.id"). + Join("LEFT", "grade", "class.grade_id = grade.id"). + Sum(mm, "self_support_for_school_ord.trade_amount") + if err != nil { + return 0, 0, 0, 0, 0, 0, err + } + + alreadyPayAmount, err = sess5.And("self_support_for_school_ord.order_status = ?", enum2.SelfSupportForSchoolOrdOrderStatusForSuccess). + Join("LEFT", "user_identity", "self_support_for_school_ord.user_identity_id = user_identity.id"). + Join("LEFT", "enterprise", "enterprise.id = user_identity.enterprise_id"). + Join("LEFT", "user", "user.id = user_identity.uid"). + Join("LEFT", "class_with_user", "class_with_user.user_identity_id = user_identity.id"). + Join("LEFT", "class", "class_with_user.class_id = class.id"). + Join("LEFT", "grade", "class.grade_id = grade.id"). + Sum(mm, "self_support_for_school_ord.trade_amount") + if err != nil { + return 0, 0, 0, 0, 0, 0, err + } + + refundPayAmount, err = sess6.And("self_support_for_school_ord.order_status = ?", enum2.SelfSupportForSchoolOrdOrderStatusForSuccess). + Join("LEFT", "user_identity", "self_support_for_school_ord.user_identity_id = user_identity.id"). + Join("LEFT", "enterprise", "enterprise.id = user_identity.enterprise_id"). + Join("LEFT", "user", "user.id = user_identity.uid"). + Join("LEFT", "class_with_user", "class_with_user.user_identity_id = user_identity.id"). + Join("LEFT", "class", "class_with_user.class_id = class.id"). + Join("LEFT", "grade", "class.grade_id = grade.id"). + Sum(mm, "self_support_for_school_ord.trade_amount") + if err != nil { + return 0, 0, 0, 0, 0, 0, err + } + + return +} + func SelfSupportForSchoolOrdListExport(req md.SelfSupportForSchoolOrdListReq) (resp []md.SelfSupportForSchoolOrdListResp, err error) { var classWithUserIdentityIdsOne []int var classWithUserIdentityIdsTwo []int diff --git a/app/customer/md/md_curl_smart_pay.go b/app/customer/md/md_curl_smart_pay.go index e71c52f..4e8fda2 100644 --- a/app/customer/md/md_curl_smart_pay.go +++ b/app/customer/md/md_curl_smart_pay.go @@ -1,5 +1,7 @@ package md +import "applet/app/admin/md" + type CurlAesDecrypt struct { AesKey string `json:"aes_key" label:"支付宝开放平台-小程序-接口内容加密-aesKey"` Content string `json:"content" binding:"required" label:"解密内容"` @@ -151,20 +153,12 @@ type CurlAlipayPlanetEcocampusApiDebtCancel struct { MerchantCode string `json:"merchant_code" label:"商户编号"` } -type CurlAlipayPlanetEcocampusApiRosterConsumeLimit struct { - ConsumeLimitSyncInfo []ConsumeLimitSyncInfo `json:"consume_limit_sync_info" label:"外部订单号"` - SchoolCode string `json:"school_code" label:"学校内标"` - SchoolName string `json:"school_name" label:"学校名称"` -} - -type ConsumeLimitSyncInfo struct { - FaceUid string `json:"face_uid" label:"学生刷脸编号"` - OutRosterCode string `json:"out_roster_code" label:"外部花名册编号"` - RosterName string `json:"roster_name" label:"花名册名称"` - DailyConsumeLimit string `json:"daily_consume_limit" label:"单日金额上限"` - DailyConsumeLimitSwitch string `json:"daily_consume_limit_switch" label:"单日金额上限 功能开关"` - SingleConsumeLimit string `json:"single_consume_limit" label:"单笔金额上限"` - SingleConsumeLimitSwitch string `json:"single_consume_limit_switch" label:"单笔金额上限 功能开关"` - DailyConsumeNumber string `json:"daily_consume_number" label:"单日笔数上限"` - DailyConsumeNumberSwitch string `json:"daily_consume_number_switch" label:"单日笔数上限 功能开关"` +type CurlAlipayPlanetEcocampusApiRosterSingleConsumeLimitSync struct { + SchoolCode string `json:"school_code" label:"学校内标"` + FaceUid string `json:"face_uid" label:"学生刷脸编号"` + RosterName string `json:"roster_name" label:"花名册名称"` + DailyConsumeLimit string `json:"daily_consume_limit" label:"单日金额上限"` + SingleConsumeLimit string `json:"single_consume_limit" label:"单笔金额上限"` + DailyMaxConsumeTimes string `json:"daily_max_consume_times" label:"单日笔数上限"` + RosterPeriodConsumeLimitConfigList []md.RosterPeriodConsumeLimitConfig `json:"roster_period_consume_limit_config_list" label:"餐段设置"` } diff --git a/app/customer/svc/svc_curl_smart_pay.go b/app/customer/svc/svc_curl_smart_pay.go index 56aa0f0..8c27dfe 100644 --- a/app/customer/svc/svc_curl_smart_pay.go +++ b/app/customer/svc/svc_curl_smart_pay.go @@ -857,9 +857,9 @@ func CurlAlipayPlanetEcocampusApiDebtCancel(args md.CurlAlipayPlanetEcocampusApi return nil, result.Data } -func CurlAlipayPlanetEcocampusApiRosterConsumeLimit(args md.CurlAlipayPlanetEcocampusApiRosterConsumeLimit) (err error, resp interface{}) { - url := cfg.SmartCanteenPay + "/alipay/bPass/alipayPlanetEcocampusApiRosterConsumeLimit" - utils.FilePutContents("CurlAlipayPlanetEcocampusApiRosterConsumeLimit", utils.SerializeStr(map[string]interface{}{ +func CurlAlipayPlanetEcocampusApiRosterSingleConsumeLimitSync(args md.CurlAlipayPlanetEcocampusApiRosterSingleConsumeLimitSync) (err error, resp interface{}) { + url := cfg.SmartCanteenPay + "/alipay/bPass/alipayPlanetEcocampusApiRosterSingleConsumeLimitSync" + utils.FilePutContents("CurlAlipayPlanetEcocampusApiRosterSingleConsumeLimitSync", utils.SerializeStr(map[string]interface{}{ "args": args, })) bytes, err := utils.CurlPost(url, utils.Serialize(args), nil) @@ -871,7 +871,7 @@ func CurlAlipayPlanetEcocampusApiRosterConsumeLimit(args md.CurlAlipayPlanetEcoc Msg string `json:"msg"` Data interface{} `json:"data"` } - utils.FilePutContents("CurlAlipayPlanetEcocampusApiRosterConsumeLimit", utils.SerializeStr(result)) + utils.FilePutContents("CurlAlipayPlanetEcocampusApiRosterSingleConsumeLimitSync", utils.SerializeStr(result)) err = json.Unmarshal(bytes, &result) if err != nil { return diff --git a/app/db/model/self_support_for_user_consume_limit.go b/app/db/model/self_support_for_user_consume_limit.go index 7d2b545..34266d0 100644 --- a/app/db/model/self_support_for_user_consume_limit.go +++ b/app/db/model/self_support_for_user_consume_limit.go @@ -1,15 +1,13 @@ package model type SelfSupportForUserConsumeLimit struct { - Id int `json:"id" xorm:"not null pk autoincr INT(11)"` - EnterpriseId int `json:"enterprise_id" xorm:"not null default 0 comment('单位id') INT(11)"` - UserIdentityId int `json:"user_identity_id" xorm:"not null default 0 comment('用户身份id') INT(11)"` - DailyConsumeLimit string `json:"daily_consume_limit" xorm:"not null default '' comment('单日金额上限') CHAR(50)"` - DailyConsumeLimitSwitch string `json:"daily_consume_limit_switch" xorm:"not null default '' comment('单日金额上限 功能开关') CHAR(50)"` - SingleConsumeLimit string `json:"single_consume_limit" xorm:"not null default '' comment('单笔金额上限') CHAR(50)"` - SingleConsumeLimitSwitch string `json:"single_consume_limit_switch" xorm:"not null default '' comment('单日金额上限 功能开关') CHAR(50)"` - DailyConsumeNumber string `json:"daily_consume_number" xorm:"not null default '' comment('单日笔数上限') CHAR(50)"` - DailyConsumeNumberSwitch string `json:"daily_consume_number_switch" xorm:"not null default '' comment('单日笔数上限 功能开关') CHAR(50)"` - CreateAt string `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"` - UpdateAt string `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"` + Id int `json:"id" xorm:"not null pk autoincr INT(11)"` + EnterpriseId int `json:"enterprise_id" xorm:"not null default 0 comment('单位id') INT(11)"` + UserIdentityId int `json:"user_identity_id" xorm:"not null default 0 comment('用户身份id') INT(11)"` + DailyConsumeLimit string `json:"daily_consume_limit" xorm:"not null default '' comment('单日金额上限,上限999') CHAR(50)"` + SingleConsumeLimit string `json:"single_consume_limit" xorm:"not null default '' comment('单笔金额上限,上限99') CHAR(50)"` + DailyMaxConsumeTimes string `json:"daily_max_consume_times" xorm:"not null default '' comment('单日最大消费次数,上限99(如需设置需要大于餐段次数之和,否则可能会导致餐段消费次数不足)') CHAR(50)"` + RosterPeriodConsumeLimitConfigList string `json:"roster_period_consume_limit_config_list" xorm:"not null comment('餐段设置,如需设置支持2-4个餐段。餐段时间不能有重叠') TEXT"` + CreateAt string `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"` + UpdateAt string `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"` }