@@ -333,3 +333,24 @@ func CentralKitchenForSchoolMyReserve(c *gin.Context) { | |||
}, nil) | |||
return | |||
} | |||
func CentralKitchenForSchoolMyReserveList(c *gin.Context) { | |||
date := c.DefaultQuery("date", "") | |||
userIdentityId := c.DefaultQuery("user_identity_id", "") | |||
if date == "" { | |||
e.OutErr(c, e.ERR_INVALID_ARGS, "日期不能为空") | |||
return | |||
} | |||
startDate := date + "-01-01" | |||
startDateTime, _ := time.ParseInLocation("2006-01-02", startDate, time.Local) | |||
endDate := startDateTime.AddDate(1, 0, -1).Format("2006-01-02") | |||
err, resp := svc.CentralKitchenForSchoolMyReserveList(utils.StrToInt(userIdentityId), date, startDate, endDate) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, map[string]interface{}{ | |||
"info": resp, | |||
}, nil) | |||
return | |||
} |
@@ -64,6 +64,18 @@ type CentralKitchenForSchoolMyReserveRespList struct { | |||
} `json:"dinner_ord_no_list" label:"晚餐-订单列表"` | |||
} | |||
type CentralKitchenForSchoolMyReserveListResp struct { | |||
Date string `json:"date" label:"日期"` | |||
TotalAmount float64 `json:"total_amount" label:"总计金额"` | |||
List []CentralKitchenForSchoolMyReserveListRespList `json:"list" label:"列表"` | |||
} | |||
type CentralKitchenForSchoolMyReserveListRespList struct { | |||
Month int `json:"month" label:"月份"` | |||
TotalAmount float64 `json:"total_amount" label:"总金额"` | |||
RefundTotalAmount float64 `json:"refund_total_amount" label:"退款总金额"` | |||
} | |||
type SelfSupportForSchoolOrderListReq struct { | |||
UserIdentityId int `json:"user_identity_id" label:"用户身份id"` | |||
Limit int `json:"limit"` | |||
@@ -203,7 +203,7 @@ func CentralKitchenForSchoolMyReserve(userIdentityId int, date, startDate, endDa | |||
centralKitchenForSchoolUserWithDayDb := db.CentralKitchenForSchoolUserWithDayDb{} | |||
centralKitchenForSchoolUserWithDayDb.Set(userIdentityId) | |||
var states = []int{enum.CentralKitchenForSchoolUserWithDayStateForWait, enum.CentralKitchenForSchoolUserWithDayStateForAlready} | |||
list, err := centralKitchenForSchoolUserWithDayDb.FindCentralKitchenForSchoolUserWithDayByDate(startDate, endDate, states) | |||
list, err := centralKitchenForSchoolUserWithDayDb.FindCentralKitchenForSchoolUserWithDayByDateAndStates(startDate, endDate, states) | |||
if err != nil { | |||
return | |||
} | |||
@@ -263,3 +263,40 @@ func CentralKitchenForSchoolMyReserve(userIdentityId int, date, startDate, endDa | |||
resp.BreakfastTotal = totalBreakfast | |||
return | |||
} | |||
func CentralKitchenForSchoolMyReserveList(userIdentityId int, date, startDate, endDate string) (err error, resp md.CentralKitchenForSchoolMyReserveListResp) { | |||
resp.Date = date | |||
//1、查询出对应时间段,所有 "待就餐"、 "已就餐" 记录 | |||
centralKitchenForSchoolUserWithDayDb := db.CentralKitchenForSchoolUserWithDayDb{} | |||
centralKitchenForSchoolUserWithDayDb.Set(userIdentityId) | |||
list, err := centralKitchenForSchoolUserWithDayDb.FindCentralKitchenForSchoolUserWithDayByDate(startDate, endDate) | |||
if err != nil { | |||
return | |||
} | |||
//2、构造数据 | |||
var totalAmount float64 | |||
var dateMap = map[int]*md.CentralKitchenForSchoolMyReserveListRespList{} | |||
var dateMapKey []int | |||
for _, v := range *list { | |||
tmpDate, _ := time.ParseInLocation("2006-01-02", v.Date, time.Local) | |||
tmpDateMonth := int(tmpDate.Month()) | |||
if dateMap[tmpDateMonth] == nil { | |||
dateMapKey = append(dateMapKey, tmpDateMonth) | |||
dateMap[tmpDateMonth] = &md.CentralKitchenForSchoolMyReserveListRespList{} | |||
} | |||
dateMap[tmpDateMonth].Month = tmpDateMonth | |||
dateMap[tmpDateMonth].TotalAmount += utils.StrToFloat64(v.Amount) | |||
totalAmount += utils.StrToFloat64(v.Amount) | |||
if v.State == enum.CentralKitchenForSchoolUserWithDayStateForCancel { | |||
dateMap[tmpDateMonth].RefundTotalAmount += utils.StrToFloat64(v.Amount) | |||
} | |||
} | |||
for _, value := range dateMapKey { | |||
resp.List = append(resp.List, *dateMap[value]) | |||
} | |||
resp.TotalAmount = totalAmount | |||
return | |||
} |
@@ -30,7 +30,7 @@ func (centralKitchenForSchoolUserWithDayDb *CentralKitchenForSchoolUserWithDayDb | |||
return m, nil | |||
} | |||
func (centralKitchenForSchoolUserWithDayDb *CentralKitchenForSchoolUserWithDayDb) FindCentralKitchenForSchoolUserWithDayByDate(sDate, eDate string, states []int) (*[]model.CentralKitchenForSchoolUserWithDay, error) { | |||
func (centralKitchenForSchoolUserWithDayDb *CentralKitchenForSchoolUserWithDayDb) FindCentralKitchenForSchoolUserWithDayByDateAndStates(sDate, eDate string, states []int) (*[]model.CentralKitchenForSchoolUserWithDay, error) { | |||
var m []model.CentralKitchenForSchoolUserWithDay | |||
if err := centralKitchenForSchoolUserWithDayDb.Db.Where("identity_id =?", centralKitchenForSchoolUserWithDayDb.IdentityId).In("state", states). | |||
And("date >= ? And date <= ?", sDate, eDate).Asc("date").Find(&m); err != nil { | |||
@@ -39,6 +39,15 @@ func (centralKitchenForSchoolUserWithDayDb *CentralKitchenForSchoolUserWithDayDb | |||
return &m, nil | |||
} | |||
func (centralKitchenForSchoolUserWithDayDb *CentralKitchenForSchoolUserWithDayDb) FindCentralKitchenForSchoolUserWithDayByDate(sDate, eDate string) (*[]model.CentralKitchenForSchoolUserWithDay, error) { | |||
var m []model.CentralKitchenForSchoolUserWithDay | |||
if err := centralKitchenForSchoolUserWithDayDb.Db.Where("identity_id =?", centralKitchenForSchoolUserWithDayDb.IdentityId). | |||
And("date >= ? And date <= ?", sDate, eDate).Asc("date").Find(&m); err != nil { | |||
return nil, logx.Error(err) | |||
} | |||
return &m, nil | |||
} | |||
func (centralKitchenForSchoolUserWithDayDb *CentralKitchenForSchoolUserWithDayDb) FindCentralKitchenForSchoolUserWithDayByOrdNo(ordNo string) ([]map[string]interface{}, error) { | |||
var m []*CentralKitchenForSchoolUserWithDayWithCentralKitchenForSchoolUserRefundDay | |||
if err := centralKitchenForSchoolUserWithDayDb.Db.Where("central_kitchen_for_school_user_with_day.ord_no =?", ordNo). | |||
@@ -49,6 +49,7 @@ func CustomerInit(r *gin.RouterGroup) { | |||
r.POST("enterprise/centralKitchenForSchool/saveUserIdentity", hdl.SaveCentralKitchenForSchoolUserIdentity) //"央厨-学校"新增身份信息 | |||
r.GET("enterprise/centralKitchenForSchool/package", hdl.CentralKitchenForSchoolPackage) //"央厨-学校"获取套餐 | |||
r.GET("enterprise/centralKitchenForSchool/myReserve", hdl.CentralKitchenForSchoolMyReserve) //"央厨-学校"我的预定 | |||
r.GET("enterprise/centralKitchenForSchool/myReserveList", hdl.CentralKitchenForSchoolMyReserveList) //"央厨-学校"我的预定列表 | |||
r.POST("enterprise/selfSupportForSchool/saveUserIdentity", hdl.SaveSelfSupportForSchoolUserIdentity) //"自营-学校"新增身份信息 | |||