|
|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
namespace Webkul\Shop\Http\Controllers\API;
|
|
|
|
|
|
+use Carbon\Carbon;
|
|
|
use Illuminate\Http\JsonResponse;
|
|
|
use Illuminate\Http\Request;
|
|
|
use Illuminate\Http\Response;
|
|
|
@@ -26,7 +27,7 @@ class CustomerController extends APIController
|
|
|
*
|
|
|
* GET /api/customer/profile
|
|
|
*
|
|
|
- * 返回:用户基础信息、成长值(VIP)、积分、优惠券数量、订单总数。
|
|
|
+ * 返回:用户基础信息、成长值(VIP)、积分、优惠券数量、订单总数、Plus 会员信息。
|
|
|
*
|
|
|
* @return JsonResponse
|
|
|
*/
|
|
|
@@ -57,6 +58,24 @@ class CustomerController extends APIController
|
|
|
->where('customer_id', $customer->id)
|
|
|
->count();
|
|
|
|
|
|
+ // 5. Plus 会员信息:是否会员、剩余天数、累计优惠金额
|
|
|
+ $plusExpireDate = $customer->vip_expire_date
|
|
|
+ ? Carbon::parse($customer->vip_expire_date)
|
|
|
+ : null;
|
|
|
+
|
|
|
+ $isPlusMember = $plusExpireDate && ! $plusExpireDate->isPast();
|
|
|
+
|
|
|
+ // 按自然日计算剩余天数,避免不足 24 小时时显示 0
|
|
|
+ $remainingPlusDays = $isPlusMember
|
|
|
+ ? max(0, (int) Carbon::now()->startOfDay()->diffInDays($plusExpireDate->copy()->startOfDay(), false))
|
|
|
+ : 0;
|
|
|
+
|
|
|
+ // 累计已享受的 Plus 优惠金额(排除已取消订单)
|
|
|
+ $totalPlusDiscount = (float) DB::table('orders')
|
|
|
+ ->where('customer_id', $customer->id)
|
|
|
+ ->where('status', '!=', 'canceled')
|
|
|
+ ->sum('vip_discount_amount');
|
|
|
+
|
|
|
return ApiResponse::success([
|
|
|
'user' => [
|
|
|
'id' => $customer->id,
|
|
|
@@ -85,6 +104,12 @@ class CustomerController extends APIController
|
|
|
'points' => $points,
|
|
|
'coupon_count' => $couponCount,
|
|
|
'order_count' => $orderCount,
|
|
|
+ 'plus' => [
|
|
|
+ 'is_plus_member' => (bool) $isPlusMember,
|
|
|
+ 'remaining_days' => $remainingPlusDays,
|
|
|
+ 'expires_at' => $isPlusMember ? $plusExpireDate->toDateTimeString() : null,
|
|
|
+ 'total_discount_amount' => round($totalPlusDiscount, 2),
|
|
|
+ ],
|
|
|
]);
|
|
|
}
|
|
|
|