If a force is applied to an object, but it ends up back in its original position, has work been done?

No, if an object ends up back in its original position after a force is applied to it, then no work has been done on the object. Work is defined as the force applied to an object causing it to move a certain distance in the direction of the force. Since the object has not moved any distance from its original position, there has been no work done on it.

But what if it has but it still ends up in its original position?

If the object moves a distance in response to a force but ultimately ends up back in its original position, then work has been done on the object. Work is defined as the transfer of energy to an object by a force causing it to move a certain distance. In this case, the force applied to the object resulted in it moving a distance, so work has been done on the object.