|
|
@@ -808,210 +808,628 @@ func CentralKitchenForSchoolOrdRefund(req md.CentralKitchenForSchoolOrdRefundReq |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
func CentralKitchenForSchoolBatchAskForLeave(req md.CentralKitchenForSchoolBatchAskForLeaveReq) (err error) { |
|
|
|
classWithUserDb := db.ClassWithUserDb{} |
|
|
|
classWithUserDb.Set() |
|
|
|
|
|
|
|
//1、判断 "按年级" / "按班级" |
|
|
|
var classWithUser *[]model.ClassWithUser |
|
|
|
if req.ClassId != 0 { |
|
|
|
classWithUser, err = classWithUserDb.FindUserIdentity(req.ClassId) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
} else { |
|
|
|
classDb := db.ClassDb{} |
|
|
|
classDb.Set(req.GradeId) |
|
|
|
classes, err1 := classDb.FindClass() |
|
|
|
func CentralKitchenForSchoolBatchAskForLeaveBySchool(req md.CentralKitchenForSchoolBatchAskForLeaveReqBySchool) (err error) { |
|
|
|
enterpriseDb := db.EnterpriseDb{} |
|
|
|
enterpriseDb.Set() |
|
|
|
for _, v := range req.EnterpriseIds { |
|
|
|
//1、查询学校 |
|
|
|
enterprise, err1 := enterpriseDb.GetEnterprise(v) |
|
|
|
if err1 != nil { |
|
|
|
return err1 |
|
|
|
} |
|
|
|
var classIds []int |
|
|
|
for _, v := range *classes { |
|
|
|
classIds = append(classIds, v.Id) |
|
|
|
} |
|
|
|
classWithUser, err = classWithUserDb.FindUserIdentity(classIds) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
var identityIds []string |
|
|
|
for _, v := range *classWithUser { |
|
|
|
identityIds = append(identityIds, utils.IntToStr(v.UserIdentityId)) |
|
|
|
} |
|
|
|
|
|
|
|
if len(identityIds) <= 0 { |
|
|
|
return errors.New("【" + req.Date + "】,无需请假学生") |
|
|
|
} |
|
|
|
|
|
|
|
//2、查询出所有 `central_kitchen_for_school_user_with_day` 记录 |
|
|
|
var m []model.CentralKitchenForSchoolUserWithDay |
|
|
|
centralKitchenForSchoolUserWithDayDb := db.CentralKitchenForSchoolUserWithDayDb{} |
|
|
|
centralKitchenForSchoolUserWithDayDb.Set(0) |
|
|
|
if req.IsBreakfast == 1 { |
|
|
|
err = centralKitchenForSchoolUserWithDayDb.Db.In("identity_id", identityIds).And("date =?", req.Date). |
|
|
|
And("kind =?", enum2.CentralKitchenForSchoolUserWithDayKindForBreakfast).Find(&m) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
if enterprise == nil { |
|
|
|
return errors.New("未查询到id:【" + utils.IntToStr(v) + "】公司对应记录") |
|
|
|
} |
|
|
|
if len(m) > 0 { |
|
|
|
//2、更改 `central_kitchen_for_school_user_with_day` 的 state 为 退款中 |
|
|
|
sql := "update central_kitchen_for_school_user_with_day set state = %d where identity_id In (%s) and date = '%s' and kind = %d" |
|
|
|
idsStr := strings.Join(identityIds, ",") |
|
|
|
sql = fmt.Sprintf(sql, enum2.CentralKitchenForSchoolUserWithDayStateForCanceling, idsStr, req.Date, enum2.CentralKitchenForSchoolUserWithDayKindForBreakfast) |
|
|
|
fmt.Println(sql) |
|
|
|
_, err = db.ExecuteOriginalSql(db.Db, sql) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
for _, date := range req.Dates { |
|
|
|
//2、查询出所有 `central_kitchen_for_school_user_with_day` 记录 |
|
|
|
var mm []model.CentralKitchenForSchoolUserWithDay |
|
|
|
centralKitchenForSchoolUserWithDayDb := db.CentralKitchenForSchoolUserWithDayDb{} |
|
|
|
centralKitchenForSchoolUserWithDayDb.Set(0) |
|
|
|
if req.IsBreakfast == 1 { |
|
|
|
err = centralKitchenForSchoolUserWithDayDb.Db.Where("enterprise_id =?", v).And("date =?", date). |
|
|
|
And("kind =?", enum2.CentralKitchenForSchoolUserWithDayKindForBreakfast).Find(&mm) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
if len(mm) > 0 { |
|
|
|
var identityIds []string |
|
|
|
for _, m := range mm { |
|
|
|
identityIds = append(identityIds, utils.IntToStr(m.Id)) |
|
|
|
} |
|
|
|
if len(identityIds) <= 0 { |
|
|
|
//无请假学生 |
|
|
|
continue |
|
|
|
} |
|
|
|
//2、更改 `central_kitchen_for_school_user_with_day` 的 state 为 退款中 |
|
|
|
sql := "update central_kitchen_for_school_user_with_day set state = %d where identity_id In (%s) and date = '%s' and kind = %d" |
|
|
|
idsStr := strings.Join(identityIds, ",") |
|
|
|
sql = fmt.Sprintf(sql, enum2.CentralKitchenForSchoolUserWithDayStateForCanceling, idsStr, date, enum2.CentralKitchenForSchoolUserWithDayKindForBreakfast) |
|
|
|
fmt.Println(sql) |
|
|
|
_, err = db.ExecuteOriginalSql(db.Db, sql) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
//3、循环处理数据 |
|
|
|
var dealOutTradeNo = map[string]string{} |
|
|
|
var centralKitchenForSchoolUserRefundDays []*model.CentralKitchenForSchoolUserRefundDay |
|
|
|
now := time.Now() |
|
|
|
for _, m := range mm { |
|
|
|
dealOutTradeNo[m.OrdNo] = m.OrdNo |
|
|
|
outRequestNo := utils.OrderUUID(m.Uid) |
|
|
|
centralKitchenForSchoolUserRefundDays = append(centralKitchenForSchoolUserRefundDays, &model.CentralKitchenForSchoolUserRefundDay{ |
|
|
|
OutTradeNo: m.OrdNo, |
|
|
|
OutRequestNo: outRequestNo, |
|
|
|
Uid: m.Uid, |
|
|
|
IdentityId: m.IdentityId, |
|
|
|
RecordsId: m.Id, |
|
|
|
State: enum2.CentralKitchenForSchoolUserRefundDayStateForAuditing, |
|
|
|
Amount: m.Amount, |
|
|
|
Memo: "", |
|
|
|
CreateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
UpdateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
//4、处理 `central_kitchen_for_school_package_ord` 的 订单状态 (ord_state) |
|
|
|
for _, vv := range dealOutTradeNo { |
|
|
|
err2 := JudgePackageOrdOrdState(vv) |
|
|
|
if err2 != nil { |
|
|
|
return err2 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//5、新增 `central_kitchen_for_school_user_refund_day` 数据 |
|
|
|
centralKitchenForSchoolUserRefundDayDb := db.CentralKitchenForSchoolUserRefundDayDb{} |
|
|
|
centralKitchenForSchoolUserRefundDayDb.Set(0) |
|
|
|
_, err = centralKitchenForSchoolUserRefundDayDb.BatchAddCentralKitchenForSchoolUserRefundDays(centralKitchenForSchoolUserRefundDays) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//3、循环处理数据 |
|
|
|
var dealOutTradeNo = map[string]string{} |
|
|
|
var centralKitchenForSchoolUserRefundDays []*model.CentralKitchenForSchoolUserRefundDay |
|
|
|
now := time.Now() |
|
|
|
for _, v := range m { |
|
|
|
dealOutTradeNo[v.OrdNo] = v.OrdNo |
|
|
|
outRequestNo := utils.OrderUUID(v.Uid) |
|
|
|
centralKitchenForSchoolUserRefundDays = append(centralKitchenForSchoolUserRefundDays, &model.CentralKitchenForSchoolUserRefundDay{ |
|
|
|
OutTradeNo: v.OrdNo, |
|
|
|
OutRequestNo: outRequestNo, |
|
|
|
Uid: v.Uid, |
|
|
|
IdentityId: v.IdentityId, |
|
|
|
RecordsId: v.Id, |
|
|
|
State: enum2.CentralKitchenForSchoolUserRefundDayStateForAuditing, |
|
|
|
Amount: v.Amount, |
|
|
|
Memo: "", |
|
|
|
CreateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
UpdateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
}) |
|
|
|
} |
|
|
|
if req.IsLunch == 1 { |
|
|
|
err = centralKitchenForSchoolUserWithDayDb.Db.Where("enterprise_id =?", v).And("date =?", date). |
|
|
|
And("kind =?", enum2.CentralKitchenForSchoolUserWithDayKindForLunch).Find(&mm) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
//4、处理 `central_kitchen_for_school_package_ord` 的 订单状态(ord_state) |
|
|
|
for _, v := range dealOutTradeNo { |
|
|
|
err1 := JudgePackageOrdOrdState(v) |
|
|
|
if err1 != nil { |
|
|
|
return err1 |
|
|
|
if len(mm) > 0 { |
|
|
|
var identityIds []string |
|
|
|
for _, m := range mm { |
|
|
|
identityIds = append(identityIds, utils.IntToStr(m.Id)) |
|
|
|
} |
|
|
|
//2、更改 `central_kitchen_for_school_user_with_day` 的 state 为 退款中 |
|
|
|
sql := "update central_kitchen_for_school_user_with_day set state = %d where identity_id In (%s) and date = '%s' and kind = %d" |
|
|
|
idsStr := strings.Join(identityIds, ",") |
|
|
|
sql = fmt.Sprintf(sql, enum2.CentralKitchenForSchoolUserWithDayStateForCanceling, idsStr, date, enum2.CentralKitchenForSchoolUserWithDayKindForLunch) |
|
|
|
fmt.Println(sql) |
|
|
|
_, err = db.ExecuteOriginalSql(db.Db, sql) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
//3、循环处理数据 |
|
|
|
var dealOutTradeNo = map[string]string{} |
|
|
|
var centralKitchenForSchoolUserRefundDays []*model.CentralKitchenForSchoolUserRefundDay |
|
|
|
now := time.Now() |
|
|
|
for _, m := range mm { |
|
|
|
dealOutTradeNo[m.OrdNo] = m.OrdNo |
|
|
|
outRequestNo := utils.OrderUUID(m.Uid) |
|
|
|
centralKitchenForSchoolUserRefundDays = append(centralKitchenForSchoolUserRefundDays, &model.CentralKitchenForSchoolUserRefundDay{ |
|
|
|
OutTradeNo: m.OrdNo, |
|
|
|
OutRequestNo: outRequestNo, |
|
|
|
Uid: m.Uid, |
|
|
|
IdentityId: m.IdentityId, |
|
|
|
RecordsId: m.Id, |
|
|
|
State: enum2.CentralKitchenForSchoolUserRefundDayStateForAuditing, |
|
|
|
Amount: m.Amount, |
|
|
|
Memo: "", |
|
|
|
CreateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
UpdateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
//4、处理 `central_kitchen_for_school_package_ord` 的 订单状态 (ord_state) |
|
|
|
for _, vv := range dealOutTradeNo { |
|
|
|
err1 := JudgePackageOrdOrdState(vv) |
|
|
|
if err1 != nil { |
|
|
|
return err1 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//5、新增 `central_kitchen_for_school_user_refund_day` 数据 |
|
|
|
centralKitchenForSchoolUserRefundDayDb := db.CentralKitchenForSchoolUserRefundDayDb{} |
|
|
|
centralKitchenForSchoolUserRefundDayDb.Set(0) |
|
|
|
_, err = centralKitchenForSchoolUserRefundDayDb.BatchAddCentralKitchenForSchoolUserRefundDays(centralKitchenForSchoolUserRefundDays) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//5、新增 `central_kitchen_for_school_user_refund_day` 数据 |
|
|
|
centralKitchenForSchoolUserRefundDayDb := db.CentralKitchenForSchoolUserRefundDayDb{} |
|
|
|
centralKitchenForSchoolUserRefundDayDb.Set(0) |
|
|
|
_, err = centralKitchenForSchoolUserRefundDayDb.BatchAddCentralKitchenForSchoolUserRefundDays(centralKitchenForSchoolUserRefundDays) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
if req.IsDinner == 1 { |
|
|
|
err = centralKitchenForSchoolUserWithDayDb.Db.Where("enterprise_id =?", v).And("date =?", date). |
|
|
|
And("kind =?", enum2.CentralKitchenForSchoolUserWithDayKindForDinner).Find(&mm) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
if len(mm) > 0 { |
|
|
|
var identityIds []string |
|
|
|
for _, m := range mm { |
|
|
|
identityIds = append(identityIds, utils.IntToStr(m.Id)) |
|
|
|
} |
|
|
|
//2、更改 `central_kitchen_for_school_user_with_day` 的 state 为 退款中 |
|
|
|
sql := "update central_kitchen_for_school_user_with_day set state = %d where identity_id In (%s) and date = '%s' and kind = %d" |
|
|
|
idsStr := strings.Join(identityIds, ",") |
|
|
|
sql = fmt.Sprintf(sql, enum2.CentralKitchenForSchoolUserWithDayStateForCanceling, idsStr, date, enum2.CentralKitchenForSchoolUserWithDayKindForDinner) |
|
|
|
fmt.Println(sql) |
|
|
|
_, err = db.ExecuteOriginalSql(db.Db, sql) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
//3、循环处理数据 |
|
|
|
var dealOutTradeNo = map[string]string{} |
|
|
|
var centralKitchenForSchoolUserRefundDays []*model.CentralKitchenForSchoolUserRefundDay |
|
|
|
now := time.Now() |
|
|
|
for _, m := range mm { |
|
|
|
dealOutTradeNo[m.OrdNo] = m.OrdNo |
|
|
|
outRequestNo := utils.OrderUUID(m.Uid) |
|
|
|
centralKitchenForSchoolUserRefundDays = append(centralKitchenForSchoolUserRefundDays, &model.CentralKitchenForSchoolUserRefundDay{ |
|
|
|
OutTradeNo: m.OrdNo, |
|
|
|
OutRequestNo: outRequestNo, |
|
|
|
Uid: m.Uid, |
|
|
|
IdentityId: m.IdentityId, |
|
|
|
RecordsId: m.Id, |
|
|
|
State: enum2.CentralKitchenForSchoolUserRefundDayStateForAuditing, |
|
|
|
Amount: m.Amount, |
|
|
|
Memo: "", |
|
|
|
CreateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
UpdateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
//4、处理 `central_kitchen_for_school_package_ord` 的 订单状态 (ord_state) |
|
|
|
for _, vv := range dealOutTradeNo { |
|
|
|
err1 := JudgePackageOrdOrdState(vv) |
|
|
|
if err1 != nil { |
|
|
|
return err1 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//5、新增 `central_kitchen_for_school_user_refund_day` 数据 |
|
|
|
centralKitchenForSchoolUserRefundDayDb := db.CentralKitchenForSchoolUserRefundDayDb{} |
|
|
|
centralKitchenForSchoolUserRefundDayDb.Set(0) |
|
|
|
_, err = centralKitchenForSchoolUserRefundDayDb.BatchAddCentralKitchenForSchoolUserRefundDays(centralKitchenForSchoolUserRefundDays) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if req.IsLunch == 1 { |
|
|
|
err = centralKitchenForSchoolUserWithDayDb.Db.In("identity_id", identityIds).And("date =?", req.Date). |
|
|
|
And("kind =?", enum2.CentralKitchenForSchoolUserWithDayKindForLunch).Find(&m) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
func CentralKitchenForSchoolBatchAskForLeaveByGrade(req md.CentralKitchenForSchoolBatchAskForLeaveReqByGrade) (err error) { |
|
|
|
enterpriseDb := db.EnterpriseDb{} |
|
|
|
enterpriseDb.Set() |
|
|
|
classWithUserDb := db.ClassWithUserDb{} |
|
|
|
classWithUserDb.Set() |
|
|
|
//1、查询学校 |
|
|
|
enterprise, err1 := enterpriseDb.GetEnterprise(req.EnterpriseId) |
|
|
|
if err1 != nil { |
|
|
|
return |
|
|
|
} |
|
|
|
if enterprise == nil { |
|
|
|
return errors.New("未查询到id:【" + utils.IntToStr(req.EnterpriseId) + "】公司对应记录") |
|
|
|
} |
|
|
|
|
|
|
|
classDb := db.ClassDb{} |
|
|
|
var classWithUser *[]model.ClassWithUser |
|
|
|
for _, v := range req.GradeIds { |
|
|
|
classDb.Set(v) |
|
|
|
classes, err2 := classDb.FindClass() |
|
|
|
if err2 != nil { |
|
|
|
return err2 |
|
|
|
} |
|
|
|
var classIds []int |
|
|
|
for _, vv := range *classes { |
|
|
|
classIds = append(classIds, vv.Id) |
|
|
|
} |
|
|
|
classWithUser, err = classWithUserDb.FindUserIdentity(classIds) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
if len(m) > 0 { |
|
|
|
//2、更改 `central_kitchen_for_school_user_with_day` 的 state 为 退款中 |
|
|
|
sql := "update central_kitchen_for_school_user_with_day set state = %d where identity_id In (%s) and date = '%s' and kind = %d" |
|
|
|
idsStr := strings.Join(identityIds, ",") |
|
|
|
sql = fmt.Sprintf(sql, enum2.CentralKitchenForSchoolUserWithDayStateForCanceling, idsStr, req.Date, enum2.CentralKitchenForSchoolUserWithDayKindForLunch) |
|
|
|
fmt.Println(sql) |
|
|
|
_, err = db.ExecuteOriginalSql(db.Db, sql) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
//3、循环处理数据 |
|
|
|
var dealOutTradeNo = map[string]string{} |
|
|
|
var centralKitchenForSchoolUserRefundDays []*model.CentralKitchenForSchoolUserRefundDay |
|
|
|
now := time.Now() |
|
|
|
for _, v := range m { |
|
|
|
dealOutTradeNo[v.OrdNo] = v.OrdNo |
|
|
|
outRequestNo := utils.OrderUUID(v.Uid) |
|
|
|
centralKitchenForSchoolUserRefundDays = append(centralKitchenForSchoolUserRefundDays, &model.CentralKitchenForSchoolUserRefundDay{ |
|
|
|
OutTradeNo: v.OrdNo, |
|
|
|
OutRequestNo: outRequestNo, |
|
|
|
Uid: v.Uid, |
|
|
|
IdentityId: v.IdentityId, |
|
|
|
RecordsId: v.Id, |
|
|
|
State: enum2.CentralKitchenForSchoolUserRefundDayStateForAuditing, |
|
|
|
Amount: v.Amount, |
|
|
|
Memo: "", |
|
|
|
CreateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
UpdateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
}) |
|
|
|
var identityIds []string |
|
|
|
for _, vv := range *classWithUser { |
|
|
|
identityIds = append(identityIds, utils.IntToStr(vv.UserIdentityId)) |
|
|
|
} |
|
|
|
if len(identityIds) <= 0 { |
|
|
|
//无请假学生 |
|
|
|
continue |
|
|
|
} |
|
|
|
for _, date := range req.Dates { |
|
|
|
//2、查询出所有 `central_kitchen_for_school_user_with_day` 记录 |
|
|
|
var mm []model.CentralKitchenForSchoolUserWithDay |
|
|
|
centralKitchenForSchoolUserWithDayDb := db.CentralKitchenForSchoolUserWithDayDb{} |
|
|
|
centralKitchenForSchoolUserWithDayDb.Set(0) |
|
|
|
if req.IsBreakfast == 1 { |
|
|
|
err = centralKitchenForSchoolUserWithDayDb.Db.In("identity_id", identityIds).And("date =?", date). |
|
|
|
And("kind =?", enum2.CentralKitchenForSchoolUserWithDayKindForBreakfast).Find(&mm) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
if len(mm) > 0 { |
|
|
|
//2、更改 `central_kitchen_for_school_user_with_day` 的 state 为 退款中 |
|
|
|
sql := "update central_kitchen_for_school_user_with_day set state = %d where identity_id In (%s) and date = '%s' and kind = %d" |
|
|
|
idsStr := strings.Join(identityIds, ",") |
|
|
|
sql = fmt.Sprintf(sql, enum2.CentralKitchenForSchoolUserWithDayStateForCanceling, idsStr, date, enum2.CentralKitchenForSchoolUserWithDayKindForBreakfast) |
|
|
|
fmt.Println(sql) |
|
|
|
_, err = db.ExecuteOriginalSql(db.Db, sql) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
//3、循环处理数据 |
|
|
|
var dealOutTradeNo = map[string]string{} |
|
|
|
var centralKitchenForSchoolUserRefundDays []*model.CentralKitchenForSchoolUserRefundDay |
|
|
|
now := time.Now() |
|
|
|
for _, m := range mm { |
|
|
|
dealOutTradeNo[m.OrdNo] = m.OrdNo |
|
|
|
outRequestNo := utils.OrderUUID(m.Uid) |
|
|
|
centralKitchenForSchoolUserRefundDays = append(centralKitchenForSchoolUserRefundDays, &model.CentralKitchenForSchoolUserRefundDay{ |
|
|
|
OutTradeNo: m.OrdNo, |
|
|
|
OutRequestNo: outRequestNo, |
|
|
|
Uid: m.Uid, |
|
|
|
IdentityId: m.IdentityId, |
|
|
|
RecordsId: m.Id, |
|
|
|
State: enum2.CentralKitchenForSchoolUserRefundDayStateForAuditing, |
|
|
|
Amount: m.Amount, |
|
|
|
Memo: "", |
|
|
|
CreateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
UpdateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
//4、处理 `central_kitchen_for_school_package_ord` 的 订单状态 (ord_state) |
|
|
|
for _, vv := range dealOutTradeNo { |
|
|
|
err2 := JudgePackageOrdOrdState(vv) |
|
|
|
if err2 != nil { |
|
|
|
return err2 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//5、新增 `central_kitchen_for_school_user_refund_day` 数据 |
|
|
|
centralKitchenForSchoolUserRefundDayDb := db.CentralKitchenForSchoolUserRefundDayDb{} |
|
|
|
centralKitchenForSchoolUserRefundDayDb.Set(0) |
|
|
|
_, err = centralKitchenForSchoolUserRefundDayDb.BatchAddCentralKitchenForSchoolUserRefundDays(centralKitchenForSchoolUserRefundDays) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//4、处理 `central_kitchen_for_school_package_ord` 的 订单状态 (ord_state) |
|
|
|
for _, v := range dealOutTradeNo { |
|
|
|
err1 := JudgePackageOrdOrdState(v) |
|
|
|
if err1 != nil { |
|
|
|
return err1 |
|
|
|
if req.IsLunch == 1 { |
|
|
|
err = centralKitchenForSchoolUserWithDayDb.Db.In("identity_id", identityIds).And("date =?", date). |
|
|
|
And("kind =?", enum2.CentralKitchenForSchoolUserWithDayKindForLunch).Find(&mm) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
if len(mm) > 0 { |
|
|
|
//2、更改 `central_kitchen_for_school_user_with_day` 的 state 为 退款中 |
|
|
|
sql := "update central_kitchen_for_school_user_with_day set state = %d where identity_id In (%s) and date = '%s' and kind = %d" |
|
|
|
idsStr := strings.Join(identityIds, ",") |
|
|
|
sql = fmt.Sprintf(sql, enum2.CentralKitchenForSchoolUserWithDayStateForCanceling, idsStr, date, enum2.CentralKitchenForSchoolUserWithDayKindForLunch) |
|
|
|
fmt.Println(sql) |
|
|
|
_, err = db.ExecuteOriginalSql(db.Db, sql) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
//3、循环处理数据 |
|
|
|
var dealOutTradeNo = map[string]string{} |
|
|
|
var centralKitchenForSchoolUserRefundDays []*model.CentralKitchenForSchoolUserRefundDay |
|
|
|
now := time.Now() |
|
|
|
for _, m := range mm { |
|
|
|
dealOutTradeNo[m.OrdNo] = m.OrdNo |
|
|
|
outRequestNo := utils.OrderUUID(m.Uid) |
|
|
|
centralKitchenForSchoolUserRefundDays = append(centralKitchenForSchoolUserRefundDays, &model.CentralKitchenForSchoolUserRefundDay{ |
|
|
|
OutTradeNo: m.OrdNo, |
|
|
|
OutRequestNo: outRequestNo, |
|
|
|
Uid: m.Uid, |
|
|
|
IdentityId: m.IdentityId, |
|
|
|
RecordsId: m.Id, |
|
|
|
State: enum2.CentralKitchenForSchoolUserRefundDayStateForAuditing, |
|
|
|
Amount: m.Amount, |
|
|
|
Memo: "", |
|
|
|
CreateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
UpdateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
//4、处理 `central_kitchen_for_school_package_ord` 的 订单状态 (ord_state) |
|
|
|
for _, vv := range dealOutTradeNo { |
|
|
|
err2 := JudgePackageOrdOrdState(vv) |
|
|
|
if err2 != nil { |
|
|
|
return err2 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//5、新增 `central_kitchen_for_school_user_refund_day` 数据 |
|
|
|
centralKitchenForSchoolUserRefundDayDb := db.CentralKitchenForSchoolUserRefundDayDb{} |
|
|
|
centralKitchenForSchoolUserRefundDayDb.Set(0) |
|
|
|
_, err = centralKitchenForSchoolUserRefundDayDb.BatchAddCentralKitchenForSchoolUserRefundDays(centralKitchenForSchoolUserRefundDays) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//5、新增 `central_kitchen_for_school_user_refund_day` 数据 |
|
|
|
centralKitchenForSchoolUserRefundDayDb := db.CentralKitchenForSchoolUserRefundDayDb{} |
|
|
|
centralKitchenForSchoolUserRefundDayDb.Set(0) |
|
|
|
_, err = centralKitchenForSchoolUserRefundDayDb.BatchAddCentralKitchenForSchoolUserRefundDays(centralKitchenForSchoolUserRefundDays) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
if req.IsDinner == 1 { |
|
|
|
err = centralKitchenForSchoolUserWithDayDb.Db.In("identity_id", identityIds).And("date =?", date). |
|
|
|
And("kind =?", enum2.CentralKitchenForSchoolUserWithDayKindForDinner).Find(&mm) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
if len(mm) > 0 { |
|
|
|
//2、更改 `central_kitchen_for_school_user_with_day` 的 state 为 退款中 |
|
|
|
sql := "update central_kitchen_for_school_user_with_day set state = %d where identity_id In (%s) and date = '%s' and kind = %d" |
|
|
|
idsStr := strings.Join(identityIds, ",") |
|
|
|
sql = fmt.Sprintf(sql, enum2.CentralKitchenForSchoolUserWithDayStateForCanceling, idsStr, date, enum2.CentralKitchenForSchoolUserWithDayKindForDinner) |
|
|
|
fmt.Println(sql) |
|
|
|
_, err = db.ExecuteOriginalSql(db.Db, sql) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
//3、循环处理数据 |
|
|
|
var dealOutTradeNo = map[string]string{} |
|
|
|
var centralKitchenForSchoolUserRefundDays []*model.CentralKitchenForSchoolUserRefundDay |
|
|
|
now := time.Now() |
|
|
|
for _, m := range mm { |
|
|
|
dealOutTradeNo[m.OrdNo] = m.OrdNo |
|
|
|
outRequestNo := utils.OrderUUID(m.Uid) |
|
|
|
centralKitchenForSchoolUserRefundDays = append(centralKitchenForSchoolUserRefundDays, &model.CentralKitchenForSchoolUserRefundDay{ |
|
|
|
OutTradeNo: m.OrdNo, |
|
|
|
OutRequestNo: outRequestNo, |
|
|
|
Uid: m.Uid, |
|
|
|
IdentityId: m.IdentityId, |
|
|
|
RecordsId: m.Id, |
|
|
|
State: enum2.CentralKitchenForSchoolUserRefundDayStateForAuditing, |
|
|
|
Amount: m.Amount, |
|
|
|
Memo: "", |
|
|
|
CreateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
UpdateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
//4、处理 `central_kitchen_for_school_package_ord` 的 订单状态 (ord_state) |
|
|
|
for _, vv := range dealOutTradeNo { |
|
|
|
err2 := JudgePackageOrdOrdState(vv) |
|
|
|
if err2 != nil { |
|
|
|
return err2 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//5、新增 `central_kitchen_for_school_user_refund_day` 数据 |
|
|
|
centralKitchenForSchoolUserRefundDayDb := db.CentralKitchenForSchoolUserRefundDayDb{} |
|
|
|
centralKitchenForSchoolUserRefundDayDb.Set(0) |
|
|
|
_, err = centralKitchenForSchoolUserRefundDayDb.BatchAddCentralKitchenForSchoolUserRefundDays(centralKitchenForSchoolUserRefundDays) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
func CentralKitchenForSchoolBatchAskForLeaveByClass(req md.CentralKitchenForSchoolBatchAskForLeaveReqByClass) (err error) { |
|
|
|
enterpriseDb := db.EnterpriseDb{} |
|
|
|
enterpriseDb.Set() |
|
|
|
classWithUserDb := db.ClassWithUserDb{} |
|
|
|
classWithUserDb.Set() |
|
|
|
//1、查询学校 |
|
|
|
enterprise, err1 := enterpriseDb.GetEnterprise(req.EnterpriseId) |
|
|
|
if err1 != nil { |
|
|
|
return |
|
|
|
} |
|
|
|
if enterprise == nil { |
|
|
|
return errors.New("未查询到id:【" + utils.IntToStr(req.EnterpriseId) + "】公司对应记录") |
|
|
|
} |
|
|
|
|
|
|
|
if req.IsDinner == 1 { |
|
|
|
err = centralKitchenForSchoolUserWithDayDb.Db.In("identity_id", identityIds).And("date =?", req.Date). |
|
|
|
And("kind =?", enum2.CentralKitchenForSchoolUserWithDayKindForDinner).Find(&m) |
|
|
|
var classWithUser *[]model.ClassWithUser |
|
|
|
for _, v := range req.ClassIds { |
|
|
|
classWithUser, err = classWithUserDb.FindUserIdentity(v) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
if len(m) < 0 { |
|
|
|
//2、更改 `central_kitchen_for_school_user_with_day` 的 state 为 退款中 |
|
|
|
sql := "update central_kitchen_for_school_user_with_day set state = %d where identity_id In (%s) and date = '%s' and kind = %d" |
|
|
|
idsStr := strings.Join(identityIds, ",") |
|
|
|
sql = fmt.Sprintf(sql, enum2.CentralKitchenForSchoolUserWithDayStateForCanceling, idsStr, req.Date, enum2.CentralKitchenForSchoolUserWithDayKindForDinner) |
|
|
|
fmt.Println(sql) |
|
|
|
_, err = db.ExecuteOriginalSql(db.Db, sql) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
var identityIds []string |
|
|
|
for _, vv := range *classWithUser { |
|
|
|
identityIds = append(identityIds, utils.IntToStr(vv.UserIdentityId)) |
|
|
|
} |
|
|
|
if len(identityIds) <= 0 { |
|
|
|
//无请假学生 |
|
|
|
continue |
|
|
|
} |
|
|
|
|
|
|
|
//3、循环处理数据 |
|
|
|
var dealOutTradeNo = map[string]string{} |
|
|
|
var centralKitchenForSchoolUserRefundDays []*model.CentralKitchenForSchoolUserRefundDay |
|
|
|
now := time.Now() |
|
|
|
for _, v := range m { |
|
|
|
dealOutTradeNo[v.OrdNo] = v.OrdNo |
|
|
|
outRequestNo := utils.OrderUUID(v.Uid) |
|
|
|
centralKitchenForSchoolUserRefundDays = append(centralKitchenForSchoolUserRefundDays, &model.CentralKitchenForSchoolUserRefundDay{ |
|
|
|
OutTradeNo: v.OrdNo, |
|
|
|
OutRequestNo: outRequestNo, |
|
|
|
Uid: v.Uid, |
|
|
|
IdentityId: v.IdentityId, |
|
|
|
RecordsId: v.Id, |
|
|
|
State: enum2.CentralKitchenForSchoolUserRefundDayStateForAuditing, |
|
|
|
Amount: v.Amount, |
|
|
|
Memo: "", |
|
|
|
CreateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
UpdateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
}) |
|
|
|
for _, date := range req.Dates { |
|
|
|
//2、查询出所有 `central_kitchen_for_school_user_with_day` 记录 |
|
|
|
var mm []model.CentralKitchenForSchoolUserWithDay |
|
|
|
centralKitchenForSchoolUserWithDayDb := db.CentralKitchenForSchoolUserWithDayDb{} |
|
|
|
centralKitchenForSchoolUserWithDayDb.Set(0) |
|
|
|
if req.IsBreakfast == 1 { |
|
|
|
err = centralKitchenForSchoolUserWithDayDb.Db.In("identity_id", identityIds).And("date =?", date). |
|
|
|
And("kind =?", enum2.CentralKitchenForSchoolUserWithDayKindForBreakfast).Find(&mm) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
if len(mm) > 0 { |
|
|
|
//2、更改 `central_kitchen_for_school_user_with_day` 的 state 为 退款中 |
|
|
|
sql := "update central_kitchen_for_school_user_with_day set state = %d where identity_id In (%s) and date = '%s' and kind = %d" |
|
|
|
idsStr := strings.Join(identityIds, ",") |
|
|
|
sql = fmt.Sprintf(sql, enum2.CentralKitchenForSchoolUserWithDayStateForCanceling, idsStr, date, enum2.CentralKitchenForSchoolUserWithDayKindForBreakfast) |
|
|
|
fmt.Println(sql) |
|
|
|
_, err = db.ExecuteOriginalSql(db.Db, sql) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
//3、循环处理数据 |
|
|
|
var dealOutTradeNo = map[string]string{} |
|
|
|
var centralKitchenForSchoolUserRefundDays []*model.CentralKitchenForSchoolUserRefundDay |
|
|
|
now := time.Now() |
|
|
|
for _, m := range mm { |
|
|
|
dealOutTradeNo[m.OrdNo] = m.OrdNo |
|
|
|
outRequestNo := utils.OrderUUID(m.Uid) |
|
|
|
centralKitchenForSchoolUserRefundDays = append(centralKitchenForSchoolUserRefundDays, &model.CentralKitchenForSchoolUserRefundDay{ |
|
|
|
OutTradeNo: m.OrdNo, |
|
|
|
OutRequestNo: outRequestNo, |
|
|
|
Uid: m.Uid, |
|
|
|
IdentityId: m.IdentityId, |
|
|
|
RecordsId: m.Id, |
|
|
|
State: enum2.CentralKitchenForSchoolUserRefundDayStateForAuditing, |
|
|
|
Amount: m.Amount, |
|
|
|
Memo: "", |
|
|
|
CreateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
UpdateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
//4、处理 `central_kitchen_for_school_package_ord` 的 订单状态 (ord_state) |
|
|
|
for _, vv := range dealOutTradeNo { |
|
|
|
err2 := JudgePackageOrdOrdState(vv) |
|
|
|
if err2 != nil { |
|
|
|
return err2 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//5、新增 `central_kitchen_for_school_user_refund_day` 数据 |
|
|
|
centralKitchenForSchoolUserRefundDayDb := db.CentralKitchenForSchoolUserRefundDayDb{} |
|
|
|
centralKitchenForSchoolUserRefundDayDb.Set(0) |
|
|
|
_, err = centralKitchenForSchoolUserRefundDayDb.BatchAddCentralKitchenForSchoolUserRefundDays(centralKitchenForSchoolUserRefundDays) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//4、处理 `central_kitchen_for_school_package_ord` 的 订单状态(ord_state) |
|
|
|
for _, v := range dealOutTradeNo { |
|
|
|
err1 := JudgePackageOrdOrdState(v) |
|
|
|
if err1 != nil { |
|
|
|
return err1 |
|
|
|
if req.IsLunch == 1 { |
|
|
|
err = centralKitchenForSchoolUserWithDayDb.Db.In("identity_id", identityIds).And("date =?", date). |
|
|
|
And("kind =?", enum2.CentralKitchenForSchoolUserWithDayKindForLunch).Find(&mm) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
if len(mm) > 0 { |
|
|
|
//2、更改 `central_kitchen_for_school_user_with_day` 的 state 为 退款中 |
|
|
|
sql := "update central_kitchen_for_school_user_with_day set state = %d where identity_id In (%s) and date = '%s' and kind = %d" |
|
|
|
idsStr := strings.Join(identityIds, ",") |
|
|
|
sql = fmt.Sprintf(sql, enum2.CentralKitchenForSchoolUserWithDayStateForCanceling, idsStr, date, enum2.CentralKitchenForSchoolUserWithDayKindForLunch) |
|
|
|
fmt.Println(sql) |
|
|
|
_, err = db.ExecuteOriginalSql(db.Db, sql) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
//3、循环处理数据 |
|
|
|
var dealOutTradeNo = map[string]string{} |
|
|
|
var centralKitchenForSchoolUserRefundDays []*model.CentralKitchenForSchoolUserRefundDay |
|
|
|
now := time.Now() |
|
|
|
for _, m := range mm { |
|
|
|
dealOutTradeNo[m.OrdNo] = m.OrdNo |
|
|
|
outRequestNo := utils.OrderUUID(m.Uid) |
|
|
|
centralKitchenForSchoolUserRefundDays = append(centralKitchenForSchoolUserRefundDays, &model.CentralKitchenForSchoolUserRefundDay{ |
|
|
|
OutTradeNo: m.OrdNo, |
|
|
|
OutRequestNo: outRequestNo, |
|
|
|
Uid: m.Uid, |
|
|
|
IdentityId: m.IdentityId, |
|
|
|
RecordsId: m.Id, |
|
|
|
State: enum2.CentralKitchenForSchoolUserRefundDayStateForAuditing, |
|
|
|
Amount: m.Amount, |
|
|
|
Memo: "", |
|
|
|
CreateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
UpdateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
//4、处理 `central_kitchen_for_school_package_ord` 的 订单状态 (ord_state) |
|
|
|
for _, vv := range dealOutTradeNo { |
|
|
|
err2 := JudgePackageOrdOrdState(vv) |
|
|
|
if err2 != nil { |
|
|
|
return err2 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//5、新增 `central_kitchen_for_school_user_refund_day` 数据 |
|
|
|
centralKitchenForSchoolUserRefundDayDb := db.CentralKitchenForSchoolUserRefundDayDb{} |
|
|
|
centralKitchenForSchoolUserRefundDayDb.Set(0) |
|
|
|
_, err = centralKitchenForSchoolUserRefundDayDb.BatchAddCentralKitchenForSchoolUserRefundDays(centralKitchenForSchoolUserRefundDays) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//5、新增 `central_kitchen_for_school_user_refund_day` 数据 |
|
|
|
centralKitchenForSchoolUserRefundDayDb := db.CentralKitchenForSchoolUserRefundDayDb{} |
|
|
|
centralKitchenForSchoolUserRefundDayDb.Set(0) |
|
|
|
_, err = centralKitchenForSchoolUserRefundDayDb.BatchAddCentralKitchenForSchoolUserRefundDays(centralKitchenForSchoolUserRefundDays) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
if req.IsDinner == 1 { |
|
|
|
err = centralKitchenForSchoolUserWithDayDb.Db.In("identity_id", identityIds).And("date =?", date). |
|
|
|
And("kind =?", enum2.CentralKitchenForSchoolUserWithDayKindForDinner).Find(&mm) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
if len(mm) > 0 { |
|
|
|
//2、更改 `central_kitchen_for_school_user_with_day` 的 state 为 退款中 |
|
|
|
sql := "update central_kitchen_for_school_user_with_day set state = %d where identity_id In (%s) and date = '%s' and kind = %d" |
|
|
|
idsStr := strings.Join(identityIds, ",") |
|
|
|
sql = fmt.Sprintf(sql, enum2.CentralKitchenForSchoolUserWithDayStateForCanceling, idsStr, date, enum2.CentralKitchenForSchoolUserWithDayKindForDinner) |
|
|
|
fmt.Println(sql) |
|
|
|
_, err = db.ExecuteOriginalSql(db.Db, sql) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
//3、循环处理数据 |
|
|
|
var dealOutTradeNo = map[string]string{} |
|
|
|
var centralKitchenForSchoolUserRefundDays []*model.CentralKitchenForSchoolUserRefundDay |
|
|
|
now := time.Now() |
|
|
|
for _, m := range mm { |
|
|
|
dealOutTradeNo[m.OrdNo] = m.OrdNo |
|
|
|
outRequestNo := utils.OrderUUID(m.Uid) |
|
|
|
centralKitchenForSchoolUserRefundDays = append(centralKitchenForSchoolUserRefundDays, &model.CentralKitchenForSchoolUserRefundDay{ |
|
|
|
OutTradeNo: m.OrdNo, |
|
|
|
OutRequestNo: outRequestNo, |
|
|
|
Uid: m.Uid, |
|
|
|
IdentityId: m.IdentityId, |
|
|
|
RecordsId: m.Id, |
|
|
|
State: enum2.CentralKitchenForSchoolUserRefundDayStateForAuditing, |
|
|
|
Amount: m.Amount, |
|
|
|
Memo: "", |
|
|
|
CreateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
UpdateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
//4、处理 `central_kitchen_for_school_package_ord` 的 订单状态 (ord_state) |
|
|
|
for _, vv := range dealOutTradeNo { |
|
|
|
err2 := JudgePackageOrdOrdState(vv) |
|
|
|
if err2 != nil { |
|
|
|
return err2 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//5、新增 `central_kitchen_for_school_user_refund_day` 数据 |
|
|
|
centralKitchenForSchoolUserRefundDayDb := db.CentralKitchenForSchoolUserRefundDayDb{} |
|
|
|
centralKitchenForSchoolUserRefundDayDb.Set(0) |
|
|
|
_, err = centralKitchenForSchoolUserRefundDayDb.BatchAddCentralKitchenForSchoolUserRefundDays(centralKitchenForSchoolUserRefundDays) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|