|
|
@@ -493,6 +493,108 @@ func DealCentralKitchenForSchoolOrderCallBack(outTradeNo, tradeStatus string) (s |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
func DealCentralKitchenForSchoolOrderCallBackForWx(outTradeNo, tradeStatus string) (state int, err error) { |
|
|
|
centralKitchenForSchoolPackageOrd := db.CentralKitchenForSchoolPackageOrd{} |
|
|
|
centralKitchenForSchoolPackageOrd.Set(outTradeNo) |
|
|
|
ord, err := centralKitchenForSchoolPackageOrd.GetCentralKitchenForSchoolPackageOrd() |
|
|
|
if err != nil { |
|
|
|
return |
|
|
|
} |
|
|
|
if ord == nil { |
|
|
|
err = errors.New("未查询到对应订单记录") |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
if ord.State == enum2.CentralKitchenForSchoolPackageOrdStateForWait { |
|
|
|
if tradeStatus == "CLOSED" || tradeStatus == "PAYERROR" { |
|
|
|
ord.State = enum2.CentralKitchenForSchoolPackageOrdStateForFail |
|
|
|
} |
|
|
|
|
|
|
|
if tradeStatus == "SUCCESS" { |
|
|
|
ord.State = enum2.CentralKitchenForSchoolPackageOrdStateForSuccess |
|
|
|
ord.OrdState = enum2.CentralKitchenForSchoolPackageOrdOrdStateForSuccess |
|
|
|
|
|
|
|
//TODO::将预留数据插入到 `central_kitchen_for_school_user_with_day` |
|
|
|
var data []*model.CentralKitchenForSchoolUserWithDay |
|
|
|
err = json.Unmarshal([]byte(ord.WithDayData), &data) |
|
|
|
if err != nil { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
var hasMonths = map[string]map[string]interface{}{} |
|
|
|
var hasKinds = map[string]map[string]string{} |
|
|
|
var hasTotalPrice = map[string]map[string]float64{} |
|
|
|
for _, v := range data { |
|
|
|
date, _ := time.ParseInLocation("2006-01-02", v.Date, time.Local) |
|
|
|
if hasMonths[utils.TimeParseStd(v.Date).Month().String()] == nil { |
|
|
|
hasMonths[utils.TimeParseStd(v.Date).Month().String()] = make(map[string]interface{}) |
|
|
|
hasMonths[utils.TimeParseStd(v.Date).Month().String()]["meal_time_start"] = date.Format("2006-01-02") |
|
|
|
hasMonths[utils.TimeParseStd(v.Date).Month().String()]["meal_time_end"] = date.Format("2006-01-02") |
|
|
|
} else { |
|
|
|
startTime, _ := time.ParseInLocation("2006-01-02", utils.AnyToString(hasMonths[utils.TimeParseStd(v.Date).Month().String()]["meal_time_start"]), time.Local) |
|
|
|
if startTime.After(date) { |
|
|
|
hasMonths[utils.TimeParseStd(v.Date).Month().String()]["meal_time_start"] = date.Format("2006-01-02") |
|
|
|
} |
|
|
|
|
|
|
|
endTime, _ := time.ParseInLocation("2006-01-02", utils.AnyToString(hasMonths[utils.TimeParseStd(v.Date).Month().String()]["meal_time_end"]), time.Local) |
|
|
|
if endTime.Before(date) { |
|
|
|
hasMonths[utils.TimeParseStd(v.Date).Month().String()]["meal_time_end"] = date.Format("2006-01-02") |
|
|
|
} |
|
|
|
} |
|
|
|
if hasTotalPrice[utils.TimeParseStd(v.Date).Month().String()] == nil { |
|
|
|
hasTotalPrice[utils.TimeParseStd(v.Date).Month().String()] = make(map[string]float64) |
|
|
|
} |
|
|
|
if hasKinds[utils.TimeParseStd(v.Date).Month().String()] == nil { |
|
|
|
hasKinds[utils.TimeParseStd(v.Date).Month().String()] = make(map[string]string) |
|
|
|
} |
|
|
|
|
|
|
|
hasMonths[utils.TimeParseStd(v.Date).Month().String()]["month"] = int(utils.TimeParseStd(v.Date).Month()) |
|
|
|
hasKinds[utils.TimeParseStd(v.Date).Month().String()][utils.IntToStr(v.Kind)] = utils.IntToStr(v.Kind) |
|
|
|
hasTotalPrice[utils.TimeParseStd(v.Date).Month().String()][utils.IntToStr(v.Kind)] += utils.StrToFloat64(v.Amount) |
|
|
|
v.OrdNo = outTradeNo |
|
|
|
} |
|
|
|
|
|
|
|
centralKitchenForSchoolUserWithDayDb := db.CentralKitchenForSchoolUserWithDayDb{} |
|
|
|
centralKitchenForSchoolUserWithDayDb.Set(0) |
|
|
|
_, err = centralKitchenForSchoolUserWithDayDb.BatchAddCentralKitchenForSchoolUserWithDays(data) |
|
|
|
if err != nil { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
//TODO::插入数据至 `central_kitchen_for_school_package_ord_for_reserve` |
|
|
|
centralKitchenForSchoolPackageOrdForReserve := db.CentralKitchenForSchoolPackageOrdForReserve{} |
|
|
|
centralKitchenForSchoolPackageOrdForReserve.Set(outTradeNo) |
|
|
|
for k, v := range hasMonths { |
|
|
|
for _, v1 := range hasKinds[k] { |
|
|
|
_, err = centralKitchenForSchoolPackageOrdForReserve.CentralKitchenForSchoolPackageOrdForReserveInsert(&model.CentralKitchenForSchoolPackageOrdForReserve{ |
|
|
|
EnterpriseId: ord.EnterpriseId, |
|
|
|
Uid: ord.Uid, |
|
|
|
UserIdentityName: ord.UserIdentityName, |
|
|
|
UserIdentityId: ord.UserIdentityId, |
|
|
|
Kind: utils.StrToInt(v1), |
|
|
|
OutTradeNo: ord.OutTradeNo, |
|
|
|
ReserveMonth: utils.AnyToString(v["month"]), |
|
|
|
MealTimeStart: utils.AnyToString(v["meal_time_start"]), |
|
|
|
MealTimeEnd: utils.AnyToString(v["meal_time_end"]), |
|
|
|
TotalPrice: utils.Float64ToStr(hasTotalPrice[k][v1]), |
|
|
|
CreateAt: time.Now().Format("2006-01-02 15:04:05"), |
|
|
|
UpdateAt: time.Now().Format("2006-01-02 15:04:05"), |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
_, err = centralKitchenForSchoolPackageOrd.CentralKitchenForSchoolPackageOrdUpdate(ord, "state", "ord_state") |
|
|
|
if err != nil { |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
state = ord.State |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
func CheckAllCallbackParams(c *gin.Context) interface{} { |
|
|
|
body, _ := ioutil.ReadAll(c.Request.Body) |
|
|
|
utils.FilePutContents("CheckAllCallbackParams", utils.SerializeStr(string(body))) |
|
|
|