DmitrMakeev commited on
Commit
214e460
·
verified ·
1 Parent(s): 326d2da

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +89 -0
app.py CHANGED
@@ -117,6 +117,95 @@ for db in DATABASES:
117
 
118
 
119
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
 
121
  @app.route('/get_current_time', methods=['GET'])
122
  def get_current_time():
 
117
 
118
 
119
 
120
+ @app.route('/order_new', methods=['GET'])
121
+ def shop_order_new():
122
+ try:
123
+ api_sys_control = request.args.get('api_sys')
124
+
125
+ if api_sys_control != api_key_sys:
126
+ return json.dumps({"error": "Unauthorized access"}), 403
127
+
128
+ name = request.args.get('name', '')
129
+ email = request.args.get('email', '')
130
+ phone = request.args.get('phone', '').lstrip('+')
131
+ order = request.args.get('order', '')
132
+ status = request.args.get('status', '')
133
+ del_flag = request.args.get('del', '')
134
+ n_con_flag = request.args.get('n_con', '') # Добавлен параметр n_con
135
+
136
+ if not email or not phone:
137
+ return json.dumps({"error": "Email and phone are required"}), 400
138
+
139
+ # Очистка номера телефона
140
+ phone = clean_phone_number_ss(phone)
141
+
142
+ conn = sqlite3.connect(DATABASE6)
143
+ cursor = conn.cursor()
144
+
145
+ cursor.execute("SELECT * FROM contacts WHERE email = ? OR phone = ?", (email, phone))
146
+ result = cursor.fetchone()
147
+
148
+ if result:
149
+ shop_st = result[17] if result[17] else '{}'
150
+ shop_st_data = json.loads(shop_st)
151
+ print(f"Existing record found. Loaded JSON: {shop_st_data}")
152
+ else:
153
+ shop_st_data = {}
154
+
155
+ if del_flag == '1':
156
+ if order in shop_st_data:
157
+ del shop_st_data[order]
158
+ elif order and status:
159
+ shop_st_data[order] = status
160
+
161
+ shop_st_json = json.dumps(shop_st_data)
162
+
163
+ # Получение текущей даты и времени в Московском часовом поясе
164
+ utc_now = datetime.utcnow()
165
+ msk_tz = pytz.timezone('Europe/Moscow')
166
+ msk_now = utc_now.replace(tzinfo=pytz.utc).astimezone(msk_tz)
167
+ data_on = msk_now.strftime('%Y-%m-%d %H:%M:%S')
168
+
169
+ # Исключаем все столбцы, кроме name, phone, email, shop_st, n_con, data_on
170
+ columns_to_update = ['name', 'phone', 'email', 'shop_st', 'n_con', 'data_on']
171
+ values_to_update = [name, phone, email, shop_st_json, n_con_flag, data_on]
172
+
173
+ if result:
174
+ # Обновляем только те поля, которые переданы в запросе
175
+ set_clause = ', '.join([f"{col} = ?" for col in columns_to_update])
176
+ query = f"UPDATE contacts SET {set_clause} WHERE email = ? OR phone = ?"
177
+ cursor.execute(query, values_to_update + [email, phone])
178
+ else:
179
+ # Вставляем новые данные
180
+ query = f"INSERT INTO contacts ({', '.join(columns_to_update)}) VALUES ({', '.join(['?' for _ in columns_to_update])})"
181
+ cursor.execute(query, values_to_update)
182
+
183
+ conn.commit()
184
+
185
+ # Замена NULL на пустые строки
186
+ replace_null_with_empty_string(conn)
187
+
188
+ conn.close()
189
+
190
+ return json.dumps(shop_st_data), 200
191
+
192
+ except Exception as e:
193
+ return json.dumps({"error": str(e)}), 500
194
+
195
+
196
+
197
+
198
+
199
+
200
+
201
+
202
+
203
+
204
+
205
+
206
+
207
+
208
+
209
 
210
  @app.route('/get_current_time', methods=['GET'])
211
  def get_current_time():