|
|
@@ -151,11 +151,35 @@ class RewardPointsController extends Controller
|
|
|
$lastSign = RewardPointCustomerSign::where('customer_id', $customer->id)
|
|
|
->orderBy('sign_date', 'desc')
|
|
|
->first();
|
|
|
- /*$currentGroup = 'sign_in';
|
|
|
- $settings = $this->settingRepository->getSettingsByGroup($currentGroup);*/
|
|
|
+ $currentGroup = 'sign_in';
|
|
|
+ $settings = $this->settingRepository->getSettingsByGroup($currentGroup);
|
|
|
+ $dayNamesMap = [
|
|
|
+ 'signin_day1_points' => 'Day 1 Sign-in Points',
|
|
|
+ 'signin_day2_points' => 'Day 2 Sign-in Points',
|
|
|
+ 'signin_day3_points' => 'Day 3 Sign-in Points',
|
|
|
+ 'signin_day4_points' => 'Day 4 Sign-in Points',
|
|
|
+ 'signin_day5_points' => 'Day 5 Sign-in Points',
|
|
|
+ 'signin_day6_points' => 'Day 6 Sign-in Points',
|
|
|
+ 'signin_day7_points' => 'Day 7 Sign-in Points',
|
|
|
+ 'signin_day8_plus_points' => 'Day 7+ Sign-in Points',
|
|
|
+ ];
|
|
|
+
|
|
|
+ $new = [];
|
|
|
+ foreach ($settings as $setting) {
|
|
|
+ $code = $setting['code'];
|
|
|
+ if (array_key_exists($code, $dayNamesMap)) {
|
|
|
+ $new[] = [
|
|
|
+ 'day' => $dayNamesMap[$code],
|
|
|
+ 'points' => $setting['value']
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
return ApiResponse::success([
|
|
|
'signed_today' => $signedToday,
|
|
|
'current_streak' => $lastSign ? $lastSign->count_date : 0,
|
|
|
+ 'signed_detail' => $new,
|
|
|
'total_points' => $this->rewardPointRepository->getCustomerPoints($customer->id)
|
|
|
]);
|
|
|
}
|
|
|
@@ -230,37 +254,28 @@ class RewardPointsController extends Controller
|
|
|
}
|
|
|
|
|
|
$totalPoints = $this->rewardPointRepository->getCustomerPoints($customer->id);
|
|
|
-
|
|
|
- // Get today's sign in status
|
|
|
- $today = Carbon::now()->format('Y-m-d');
|
|
|
- $signedToday = RewardPointCustomerSign::where('customer_id', $customer->id)
|
|
|
- ->where('sign_date', $today)
|
|
|
- ->exists();
|
|
|
-
|
|
|
- // Get current streak
|
|
|
- $lastSign = RewardPointCustomerSign::where('customer_id', $customer->id)
|
|
|
- ->orderBy('sign_date', 'desc')
|
|
|
- ->first();
|
|
|
- $currentStreak = $lastSign ? $lastSign->count_date : 0;
|
|
|
-
|
|
|
- // Get total earned points (all time)
|
|
|
- $totalEarned = RewardPointHistory::where('customer_id', $customer->id)
|
|
|
- ->where('amount', '>', 0)
|
|
|
- ->sum('amount');
|
|
|
-
|
|
|
- // Get total used points (all time)
|
|
|
- $totalUsed = RewardPointHistory::where('customer_id', $customer->id)
|
|
|
- ->where('amount', '<', 0)
|
|
|
+ // Get points expired in the last month
|
|
|
+ $oneMonthAgo = Carbon::now()->subMonth();
|
|
|
+ $recentlyExpired = RewardPointHistory::where('customer_id', $customer->id)
|
|
|
+ ->where('status', RewardPointHistory::STATUS_EXPIRED)
|
|
|
+ ->whereNotNull('expired_time')
|
|
|
+ ->where('expired_time', '>=', $oneMonthAgo)
|
|
|
->sum('amount') * -1;
|
|
|
|
|
|
+ // Get expiring points in the next month (still valid but will expire soon)
|
|
|
+ $nextMonth = Carbon::now()->addMonth();
|
|
|
+ $expiringSoon = RewardPointHistory::where('customer_id', $customer->id)
|
|
|
+ ->where('status', RewardPointHistory::STATUS_COMPLETED)
|
|
|
+ ->whereNotNull('expired_time')
|
|
|
+ ->where('expired_time', '>', Carbon::now())
|
|
|
+ ->where('expired_time', '<=', $nextMonth)
|
|
|
+ ->sum('point_remaining');
|
|
|
+
|
|
|
return ApiResponse::success([
|
|
|
- 'current_points' => $totalPoints,
|
|
|
- 'total_earned' => $totalEarned,
|
|
|
- 'total_used' => $totalUsed,
|
|
|
- 'signed_today' => $signedToday,
|
|
|
- 'current_streak' => $currentStreak,
|
|
|
- 'points_value' => $totalPoints * (float) $this->settingRepository->getConfigValue('point_value', 0.01)
|
|
|
- ]);
|
|
|
+ 'recently_expired' => $recentlyExpired,
|
|
|
+ 'expiring_soon' => $expiringSoon,
|
|
|
+ 'current_points' => $totalPoints
|
|
|
+ ]);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -332,6 +347,7 @@ class RewardPointsController extends Controller
|
|
|
7 => 'Share',
|
|
|
8 => 'Subscription',
|
|
|
9 => 'Login',
|
|
|
+ 99 => 'admin',
|
|
|
];
|
|
|
|
|
|
return $types[$type] ?? 'Unknown';
|