nagasurendra commited on
Commit
6790316
·
verified ·
1 Parent(s): 1ee163b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +70 -0
app.py CHANGED
@@ -120,7 +120,77 @@ def login():
120
  return render_template("login.html")
121
 
122
  # Assuming you're fetching the order details and processing them like this
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
123
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
  @app.route('/order_summary')
125
  def order_summary():
126
  email = session.get('user_email')
 
120
  return render_template("login.html")
121
 
122
  # Assuming you're fetching the order details and processing them like this
123
+ @app.route('/reward_status')
124
+ def reward_status():
125
+ # Get the user email from session (assuming the session is already set during checkout)
126
+ email = session.get('user_email')
127
+
128
+ if not email:
129
+ return "User not logged in", 400
130
+
131
+ # Query Salesforce to fetch the user's reward points
132
+ try:
133
+ # Query the Customer_Login__c object based on the user's email
134
+ query = f"SELECT Id, Reward_Points__c FROM Customer_Login__c WHERE Email__c = '{email}'"
135
+ user_data = sf.query(query)
136
+
137
+ # Check if the user record was found
138
+ if not user_data.get("records"):
139
+ return "User not found", 400
140
+
141
+ # Get the user's reward points from Salesforce
142
+ user_points = user_data["records"][0].get("Reward_Points__c", 0)
143
+
144
+ except Exception as e:
145
+ return f"Error querying Salesforce: {str(e)}", 500
146
 
147
+ # Define point ranges for each tier
148
+ tiers = {
149
+ "Bronze": 100, # Example: 0 to 100 for Bronze
150
+ "Silver": 200, # Example: 100 to 200 for Silver
151
+ "Gold": 300, # Example: 200 to 300 for Gold
152
+ "Platinum": 500
153
+ }
154
+
155
+ # Logic for calculating the next tier's range and current progress
156
+ current_tier = "Silver" # Example, dynamically determine this
157
+
158
+ # Calculate the range for the current tier
159
+ if current_tier == "Silver":
160
+ start_point = 100 # Silver starts at 100
161
+ end_point = 200 # Silver ends at 200
162
+ elif current_tier == "Gold":
163
+ start_point = 200 # Gold starts at 200
164
+ end_point = 300 # Gold ends at 300
165
+ else:
166
+ start_point = 0 # Default start point for other tiers
167
+ end_point = 100 # Default end point for other tiers
168
+
169
+ # Calculate progress as a percentage
170
+ if user_points >= start_point:
171
+ progress_percentage = ((user_points - start_point) / (end_point - start_point)) * 100
172
+ else:
173
+ progress_percentage = 0
174
+
175
+ # Calculate points to next tier
176
+ points_needed_for_next_tier = end_point - user_points
177
+ next_tier = "Gold" # Next tier name (you can dynamically calculate this)
178
+ # Round the points before passing to the template
179
+ user_points = round(user_points)
180
+ points_needed_for_next_tier = round(points_needed_for_next_tier)
181
+
182
+ # Pass these values to your template
183
+ return render_template(
184
+ 'reward_status.html',
185
+ user_points=user_points,
186
+ current_tier=current_tier,
187
+ progress_percentage=progress_percentage,
188
+ points_needed_for_next_tier=points_needed_for_next_tier,
189
+ start_point=start_point,
190
+ end_point=end_point,
191
+ next_tier=next_tier,
192
+ tiers=tiers
193
+ )
194
  @app.route('/order_summary')
195
  def order_summary():
196
  email = session.get('user_email')