updates on the sweeper and eligibility things in the order
This commit is contained in:
@@ -2967,6 +2967,8 @@ func AdminCancelBooking(c *fiber.Ctx) error {
|
||||
"booking_id", booking.Bookingid, "error", err)
|
||||
}
|
||||
|
||||
closeOpenAssignments(booking.Bookingid, "Order cancelled by Doormile operations")
|
||||
|
||||
if booking.Assignedmileruserid != nil {
|
||||
db.DB.Model(&models.MilerProfile{}).
|
||||
Where("userid = ?", *booking.Assignedmileruserid).
|
||||
@@ -3055,6 +3057,8 @@ func AdminBulkCancelBookings(c *fiber.Ctx) error {
|
||||
"booking_id", booking.Bookingid, "error", err)
|
||||
}
|
||||
|
||||
closeOpenAssignments(booking.Bookingid, "Order cancelled by Doormile operations (bulk)")
|
||||
|
||||
if booking.Assignedmileruserid != nil {
|
||||
db.DB.Model(&models.MilerProfile{}).
|
||||
Where("userid = ?", *booking.Assignedmileruserid).
|
||||
@@ -4118,3 +4122,20 @@ func opsActorID(c *fiber.Ctx) *int {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// closeOpenAssignments closes the rider's open assignment on a booking ops
|
||||
// cancelled. Without it the record stayed Assigned/Accepted for good, and
|
||||
// auto-assignment counted it against the rider's cap — enough cancelled
|
||||
// orders and the rider was never offered another. Best effort: the
|
||||
// cancellation itself has already been saved.
|
||||
func closeOpenAssignments(bookingID int, remark string) {
|
||||
if err := db.DB.Model(&models.BookingAssignment{}).
|
||||
Where("bookingid = ? AND assignmentstatus IN ?", bookingID,
|
||||
[]string{constants.AssignmentAssigned, constants.AssignmentAccepted}).
|
||||
Updates(map[string]interface{}{
|
||||
"assignmentstatus": constants.AssignmentCancelled,
|
||||
"remarks": remark,
|
||||
}).Error; err != nil {
|
||||
utils.Error("cancel: could not close the rider's assignment", "booking_id", bookingID, "error", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user