@ -125,16 +125,4 @@ class Customer extends Authenticatable implements JWTSubject
return $this->hasMany(Recharge::class, "customer_id")->whereNotNull("paid_at");
}
public function getOnlineRefundableRecharge($amount)
{
//todo:根据交易状态是否可以退款、以及多次退款金额是否足够进行更精准筛选
//but:出问题的几率微乎其微可以忽略
$recharge = Recharge::where("customer_id", $this->id)
->whereNotNull("paid_at")
->whereIn("payment", ["weixin", "alipay"])
->doesntHave("refunds")
->orderBy("id", "desc")
->first();
return $recharge;
@ -1064,7 +1064,7 @@ class OrdersController extends CommonController
$to_refund_total = max(0, -$to_recharge_total);
$to_recharge_total = max(0, $to_recharge_total);
if ($to_refund_total > 0) {
$recharge_for_online_refund = $order->customer->getOnlineRefundableRecharge($to_refund_total);
$recharge_for_online_refund = $order->getOnlineRefundableRecharge($to_refund_total);
} else {
$recharge_for_online_refund = null;
@ -410,4 +410,18 @@ class Orders extends SoftDeletesModel
return $result;
$recharge = Recharge::where("order_id", $this->id)
->where("money",">=",$amount)