|
|
@@ -1110,6 +1110,177 @@ func CentralKitchenForSchoolReserveList(req md.CentralKitchenForSchoolReserveLis |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
func CentralKitchenForSchoolReserveListBack(req md.CentralKitchenForSchoolReserveListReq) (resp []md.CentralKitchenForSchoolReserveListResp, count int64, 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 nil, 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 nil, 0, err3 |
|
|
|
} |
|
|
|
var classesId []int |
|
|
|
for _, v := range *classes { |
|
|
|
classesId = append(classesId, v.Id) |
|
|
|
} |
|
|
|
classWithUsers, err4 := classWithUserDb.FindUserIdentity(classesId) |
|
|
|
if err4 != nil { |
|
|
|
return nil, 0, err4 |
|
|
|
} |
|
|
|
for _, v := range *classWithUsers { |
|
|
|
classWithUserIdentityIdsTwo = append(classWithUserIdentityIdsTwo, v.UserIdentityId) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var centralKitchenForSchoolUserWithDayIds []string |
|
|
|
if req.StartDate != "" && req.EndDate != "" { |
|
|
|
var m []model.CentralKitchenForSchoolUserWithDay |
|
|
|
if err1 := db.Db.Where("state != ?", enum2.CentralKitchenForSchoolUserWithDayStateForCancel). |
|
|
|
And("date >= ? And date <= ?", req.StartDate, req.EndDate).Asc("date").Find(&m); err != nil { |
|
|
|
return nil, 0, err1 |
|
|
|
} |
|
|
|
for _, v := range m { |
|
|
|
centralKitchenForSchoolUserWithDayIds = append(centralKitchenForSchoolUserWithDayIds, v.OrdNo) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var months []time.Month |
|
|
|
if req.StartDate != "" { |
|
|
|
sDate, _ := time.ParseInLocation("2006-01-02", req.StartDate, time.Local) |
|
|
|
eDate, _ := time.ParseInLocation("2006-01-02", req.EndDate, time.Local) |
|
|
|
_, sMonth, _ := sDate.Date() |
|
|
|
_, eMonth, _ := eDate.Date() |
|
|
|
diffMonth := sMonth - eMonth |
|
|
|
if diffMonth == 0 { |
|
|
|
//TODO::查询一个月 |
|
|
|
months = append(months, sMonth) |
|
|
|
} else { |
|
|
|
for i := sMonth; i <= eMonth; i++ { |
|
|
|
months = append(months, i) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
sess := db.Db. |
|
|
|
Desc("central_kitchen_for_school_package_ord_for_reserve.id") |
|
|
|
if req.EnterpriseId != 0 { |
|
|
|
sess.And("central_kitchen_for_school_package_ord_for_reserve.enterprise_id =?", req.EnterpriseId) |
|
|
|
} |
|
|
|
if req.Kind != 0 { |
|
|
|
sess.And("central_kitchen_for_school_package_ord_for_reserve.kind = ?", req.Kind) |
|
|
|
} |
|
|
|
if req.OutTradeNo != "" { |
|
|
|
sess.And("central_kitchen_for_school_package_ord_for_reserve.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 len(classWithUserIdentityIdsOne) > 0 { |
|
|
|
sess.In("user_identity.id", classWithUserIdentityIdsOne) |
|
|
|
} |
|
|
|
if len(classWithUserIdentityIdsTwo) > 0 { |
|
|
|
sess.In("user_identity.id", classWithUserIdentityIdsTwo) |
|
|
|
} |
|
|
|
if len(centralKitchenForSchoolUserWithDayIds) > 0 { |
|
|
|
sess.In("central_kitchen_for_school_package_ord.out_trade_no", centralKitchenForSchoolUserWithDayIds) |
|
|
|
} |
|
|
|
if len(months) > 0 { |
|
|
|
sess.In("central_kitchen_for_school_package_ord_for_reserve.reserve_month", months) |
|
|
|
} |
|
|
|
if req.EnterPriseKind != 0 { |
|
|
|
sess.And("enterprise.kind = ?", req.EnterPriseKind) |
|
|
|
} |
|
|
|
|
|
|
|
var m []*db.CentralKitchenForSchoolPackageOrdForReserveWithUserIdentity |
|
|
|
count, err = sess. |
|
|
|
Join("LEFT", "central_kitchen_for_school_package_ord", "central_kitchen_for_school_package_ord_for_reserve.out_trade_no = central_kitchen_for_school_package_ord.out_trade_no"). |
|
|
|
Join("LEFT", "user_identity", "central_kitchen_for_school_package_ord_for_reserve.user_identity_id = user_identity.id"). |
|
|
|
Join("LEFT", "enterprise", "enterprise.id = central_kitchen_for_school_package_ord_for_reserve.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"). |
|
|
|
Limit(req.Limit, (req.Page-1)*req.Limit).FindAndCount(&m) |
|
|
|
if err != nil { |
|
|
|
return nil, 0, err |
|
|
|
} |
|
|
|
|
|
|
|
for _, v := range m { |
|
|
|
//获取当前预定记录下有多少退款记录 |
|
|
|
var state = 1 |
|
|
|
var stateZh = "已支付" |
|
|
|
|
|
|
|
var sql = fmt.Sprintf("SELECT COUNT(*) as total, state, kind FROM `central_kitchen_for_school_user_with_day` WHERE (ord_no = %s) AND date >= '%s' and date <= '%s' group by state,kind", v.CentralKitchenForSchoolPackageOrdForReserve.OutTradeNo, v.CentralKitchenForSchoolPackageOrdForReserve.MealTimeStart, v.CentralKitchenForSchoolPackageOrdForReserve.MealTimeEnd) |
|
|
|
mapArrs, err1 := db.QueryNativeString(db.Db, sql) |
|
|
|
if err1 != nil { |
|
|
|
return nil, 0, err1 |
|
|
|
} |
|
|
|
|
|
|
|
var ordMap = map[int]map[int]int{} |
|
|
|
var total int |
|
|
|
for _, mapArr := range mapArrs { |
|
|
|
if ordMap[utils.StrToInt(mapArr["kind"])] == nil { |
|
|
|
ordMap[utils.StrToInt(mapArr["kind"])] = map[int]int{} |
|
|
|
} |
|
|
|
ordMap[utils.StrToInt(mapArr["kind"])][utils.StrToInt(mapArr["state"])] = utils.StrToInt(mapArr["total"]) |
|
|
|
total += utils.StrToInt(mapArr["total"]) |
|
|
|
} |
|
|
|
|
|
|
|
if ordMap[v.CentralKitchenForSchoolPackageOrdForReserve.Kind][enum2.CentralKitchenForSchoolUserWithDayStateForCanceling] > 0 { |
|
|
|
state = 2 |
|
|
|
stateZh = "退款中" |
|
|
|
} else { |
|
|
|
if ordMap[v.CentralKitchenForSchoolPackageOrdForReserve.Kind][enum2.CentralKitchenForSchoolUserWithDayStateForCancel] > 0 { |
|
|
|
state = 3 |
|
|
|
stateZh = "部分退款" |
|
|
|
if ordMap[v.CentralKitchenForSchoolPackageOrdForReserve.Kind][enum2.CentralKitchenForSchoolUserWithDayStateForCancel] == total { |
|
|
|
state = 4 |
|
|
|
stateZh = "已退款" |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
resp = append(resp, md.CentralKitchenForSchoolReserveListResp{ |
|
|
|
Id: v.CentralKitchenForSchoolPackageOrdForReserve.Id, |
|
|
|
EnterpriseId: v.UserIdentity.EnterpriseId, |
|
|
|
EnterpriseName: v.Enterprise.Name, |
|
|
|
Uid: v.UserIdentity.Uid, |
|
|
|
UserIdentityId: v.UserIdentity.Id, |
|
|
|
UserIdentityName: v.CentralKitchenForSchoolPackageOrdForReserve.UserIdentityName, |
|
|
|
Kind: v.CentralKitchenForSchoolPackageOrdForReserve.Kind, |
|
|
|
ReserveMonth: v.CentralKitchenForSchoolPackageOrdForReserve.ReserveMonth, |
|
|
|
TotalPrice: v.CentralKitchenForSchoolPackageOrdForReserve.TotalPrice, |
|
|
|
CreateAt: v.CentralKitchenForSchoolPackageOrdForReserve.CreateAt, |
|
|
|
OutTradeNo: v.CentralKitchenForSchoolPackageOrd.OutTradeNo, |
|
|
|
TradeNo: v.CentralKitchenForSchoolPackageOrd.TradeNo, |
|
|
|
Phone: v.User.Phone, |
|
|
|
Grade: v.Grade.Name, |
|
|
|
GradeId: v.Grade.Id, |
|
|
|
Class: v.Class.Name, |
|
|
|
ClassId: v.Class.Id, |
|
|
|
State: state, |
|
|
|
StateZh: stateZh, |
|
|
|
}) |
|
|
|
} |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
func CentralKitchenForSchoolOrdRefund(req md.CentralKitchenForSchoolOrdRefundReq) (err error) { |
|
|
|
//1、查询出所有 `central_kitchen_for_school_user_with_day` 记录 |
|
|
|
var m []model.CentralKitchenForSchoolUserWithDay |
|
|
|