Update: 2026-06-15 01:37:40

This commit is contained in:
Hamza-Ayed
2026-06-15 01:37:41 +03:00
parent f021ba5a35
commit 2321b78244
164 changed files with 1356 additions and 1560 deletions

View File

@@ -47,9 +47,6 @@ class Challenge {
}
// ════════════════════════════════════════════
// Controller
// ════════════════════════════════════════════
class ChallengesController extends GetxController {
bool isLoading = false;
List<Challenge> dailyChallenges = [];
@@ -66,6 +63,47 @@ class ChallengesController extends GetxController {
void _generateChallenges() {
final now = DateTime.now();
final isWeekend = now.weekday == 5 || now.weekday == 6; // الجمعة والسبت
String country = box.read(BoxName.countryCode) ?? 'Jordan';
int dailyEarningsTarget;
int dailyEarningsReward;
int weeklyEarningsTarget;
int weeklyEarningsReward;
String dailyEarningsDescAr;
String dailyEarningsDescEn;
String weeklyEarningsDescAr;
String weeklyEarningsDescEn;
if (country == 'Syria') {
dailyEarningsTarget = 150000;
dailyEarningsReward = 100; // 100 pts -> 10,000 SYP
weeklyEarningsTarget = 1000000;
weeklyEarningsReward = 500; // 500 pts -> 50,000 SYP
dailyEarningsDescAr = 'اربح 150,000 ل.س اليوم';
dailyEarningsDescEn = 'Earn 150,000 SYP today';
weeklyEarningsDescAr = 'اربح 1,000,000 ل.س هذا الأسبوع';
weeklyEarningsDescEn = 'Earn 1,000,000 SYP this week';
} else if (country == 'Egypt') {
dailyEarningsTarget = 300;
dailyEarningsReward = 30; // 30 pts -> 30 EGP
weeklyEarningsTarget = 2000;
weeklyEarningsReward = 200; // 200 pts -> 200 EGP
dailyEarningsDescAr = 'اربح 300 ج.م اليوم';
dailyEarningsDescEn = 'Earn 300 EGP today';
weeklyEarningsDescAr = 'اربح 2000 ج.م هذا الأسبوع';
weeklyEarningsDescEn = 'Earn 2000 EGP this week';
} else {
// Jordan / default
dailyEarningsTarget = 30;
dailyEarningsReward = 60; // 60 pts -> 3 JOD (60 * 0.05 = 3 JOD)
weeklyEarningsTarget = 200;
weeklyEarningsReward = 400; // 400 pts -> 20 JOD (400 * 0.05 = 20 JOD)
dailyEarningsDescAr = 'اربح 30 د.أ اليوم';
dailyEarningsDescEn = 'Earn 30 JOD today';
weeklyEarningsDescAr = 'اربح 200 د.أ هذا الأسبوع';
weeklyEarningsDescEn = 'Earn 200 JOD this week';
}
dailyChallenges = [
Challenge(
@@ -77,7 +115,7 @@ class ChallengesController extends GetxController {
icon: Icons.local_taxi_rounded,
color: const Color(0xFF2196F3),
target: 5,
reward: 50,
reward: country == 'Syria' ? 50 : (country == 'Egypt' ? 50 : 100),
type: 'daily',
metric: 'trips',
),
@@ -90,7 +128,7 @@ class ChallengesController extends GetxController {
icon: Icons.directions_car_rounded,
color: const Color(0xFFFF9800),
target: 10,
reward: 150,
reward: country == 'Syria' ? 150 : (country == 'Egypt' ? 150 : 300),
type: 'daily',
metric: 'trips',
),
@@ -98,12 +136,12 @@ class ChallengesController extends GetxController {
id: 'daily_earnings',
titleEn: 'Money Maker',
titleAr: 'صانع المال',
descriptionEn: 'Earn 3000 ${CurrencyHelper.currency} today',
descriptionAr: 'اربح 3000 ل.س اليوم',
descriptionEn: dailyEarningsDescEn,
descriptionAr: dailyEarningsDescAr,
icon: Icons.monetization_on_rounded,
color: const Color(0xFF4CAF50),
target: 3000,
reward: 100,
target: dailyEarningsTarget,
reward: dailyEarningsReward,
type: 'daily',
metric: 'earnings',
),
@@ -117,7 +155,7 @@ class ChallengesController extends GetxController {
icon: Icons.celebration_rounded,
color: const Color(0xFFE91E63),
target: 8,
reward: 200,
reward: country == 'Syria' ? 200 : (country == 'Egypt' ? 200 : 400),
type: 'daily',
metric: 'trips',
),
@@ -133,7 +171,7 @@ class ChallengesController extends GetxController {
icon: Icons.emoji_events_rounded,
color: const Color(0xFFFFD700),
target: 30,
reward: 300,
reward: country == 'Syria' ? 300 : (country == 'Egypt' ? 300 : 600),
type: 'weekly',
metric: 'trips',
),
@@ -141,12 +179,12 @@ class ChallengesController extends GetxController {
id: 'weekly_earnings',
titleEn: 'Big Earner',
titleAr: 'الربح الكبير',
descriptionEn: 'Earn 20,000 ${CurrencyHelper.currency} this week',
descriptionAr: 'اربح 20,000 ل.س هذا الأسبوع',
descriptionEn: weeklyEarningsDescEn,
descriptionAr: weeklyEarningsDescAr,
icon: Icons.account_balance_wallet_rounded,
color: const Color(0xFF9C27B0),
target: 20000,
reward: 500,
target: weeklyEarningsTarget,
reward: weeklyEarningsReward,
type: 'weekly',
metric: 'earnings',
),
@@ -159,10 +197,10 @@ class ChallengesController extends GetxController {
icon: Icons.timer_rounded,
color: const Color(0xFF00BCD4),
target: 20,
reward: 400,
reward: country == 'Syria' ? 400 : (country == 'Egypt' ? 400 : 800),
type: 'weekly',
metric: 'hours',
),
)
];
}
@@ -203,8 +241,12 @@ class ChallengesController extends GetxController {
if (todayRes != null && todayRes != 'failure') {
var data = jsonDecode(todayRes);
todayEarnings = double.tryParse(data['message']?[0]?['todayAmount']?.toString() ?? '0') ?? 0;
todayTrips = int.tryParse(data['message']?[0]?['todayCount']?.toString() ?? '0') ?? 0;
todayEarnings = double.tryParse(
data['message']?[0]?['todayAmount']?.toString() ?? '0') ??
0;
todayTrips = int.tryParse(
data['message']?[0]?['todayCount']?.toString() ?? '0') ??
0;
}
// تحديث التحديات اليومية
@@ -229,7 +271,9 @@ class ChallengesController extends GetxController {
if (weeklyEarningsRes != null && weeklyEarningsRes != 'failure') {
var data = jsonDecode(weeklyEarningsRes);
if (data['message'] is List && data['message'].isNotEmpty) {
weeklyEarnings = double.tryParse(data['message'][0]['totalAmount']?.toString() ?? '0') ?? 0;
weeklyEarnings = double.tryParse(
data['message'][0]['totalAmount']?.toString() ?? '0') ??
0;
}
}
@@ -247,7 +291,8 @@ class ChallengesController extends GetxController {
if (data['message'] is List) {
for (var day in data['message']) {
weeklyTrips += int.tryParse(day['trips']?.toString() ?? '0') ?? 0;
weeklyHours += double.tryParse(day['hours']?.toString() ?? '0') ?? 0;
weeklyHours +=
double.tryParse(day['hours']?.toString() ?? '0') ?? 0;
}
}
}
@@ -273,8 +318,18 @@ class ChallengesController extends GetxController {
update();
}
final Set<String> _claimingChallenges = {};
bool isClaiming(String challengeId) =>
_claimingChallenges.contains(challengeId);
Future<void> claimReward(Challenge challenge) async {
if (!challenge.isCompleted || challenge.isClaimed) return;
if (!challenge.isCompleted ||
challenge.isClaimed ||
_claimingChallenges.contains(challenge.id)) return;
_claimingChallenges.add(challenge.id);
update();
try {
var res = await CRUD().post(
@@ -290,10 +345,12 @@ class ChallengesController extends GetxController {
challenge.isClaimed = true;
box.write('challenge_${challenge.id}_claimed', true);
debugPrint('🎉 Claimed ${challenge.reward} points for ${challenge.id}');
update();
}
} catch (e) {
debugPrint('❌ [Challenges] Claim error: $e');
} finally {
_claimingChallenges.remove(challenge.id);
update();
}
}
}