Update app.py
Browse files
app.py
CHANGED
@@ -2159,6 +2159,98 @@ def from_shop_st3():
|
|
2159 |
except Exception as e:
|
2160 |
return json.dumps({"error": str(e)}), 500
|
2161 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2162 |
@app.route('/allow', methods=['GET'])
|
2163 |
def from_allow():
|
2164 |
try:
|
|
|
2159 |
except Exception as e:
|
2160 |
return json.dumps({"error": str(e)}), 500
|
2161 |
|
2162 |
+
|
2163 |
+
|
2164 |
+
|
2165 |
+
|
2166 |
+
|
2167 |
+
|
2168 |
+
@app.route('/order_new', methods=['GET'])
|
2169 |
+
def from_shop_st3():
|
2170 |
+
try:
|
2171 |
+
api_sys_control = request.args.get('api_sys')
|
2172 |
+
|
2173 |
+
if api_sys_control != api_key_sys:
|
2174 |
+
return json.dumps({"error": "Unauthorized access"}), 403
|
2175 |
+
|
2176 |
+
name = request.args.get('name', '')
|
2177 |
+
email = request.args.get('email', '')
|
2178 |
+
phone = request.args.get('phone', '').lstrip('+')
|
2179 |
+
order = request.args.get('order', '')
|
2180 |
+
status = request.args.get('status', '')
|
2181 |
+
del_flag = request.args.get('del', '')
|
2182 |
+
n_con_flag = request.args.get('n_con', '') # Добавлен параметр n_con
|
2183 |
+
|
2184 |
+
if not email or not phone:
|
2185 |
+
return json.dumps({"error": "Email and phone are required"}), 400
|
2186 |
+
|
2187 |
+
# Очистка номера телефона
|
2188 |
+
phone = clean_phone_number_ss(phone)
|
2189 |
+
|
2190 |
+
conn = sqlite3.connect(DATABASE6)
|
2191 |
+
cursor = conn.cursor()
|
2192 |
+
|
2193 |
+
cursor.execute("SELECT * FROM contacts WHERE email = ? OR phone = ?", (email, phone))
|
2194 |
+
result = cursor.fetchone()
|
2195 |
+
|
2196 |
+
if result:
|
2197 |
+
shop_st = result[17] if result[17] else '{}'
|
2198 |
+
shop_st_data = json.loads(shop_st)
|
2199 |
+
print(f"Existing record found. Loaded JSON: {shop_st_data}")
|
2200 |
+
else:
|
2201 |
+
shop_st_data = {}
|
2202 |
+
|
2203 |
+
if del_flag == '1':
|
2204 |
+
if order in shop_st_data:
|
2205 |
+
del shop_st_data[order]
|
2206 |
+
elif order and status:
|
2207 |
+
shop_st_data[order] = status
|
2208 |
+
|
2209 |
+
shop_st_json = json.dumps(shop_st_data)
|
2210 |
+
|
2211 |
+
# Получение текущей даты и времени в Московском часовом поясе
|
2212 |
+
utc_now = datetime.utcnow()
|
2213 |
+
msk_tz = pytz.timezone('Europe/Moscow')
|
2214 |
+
msk_now = utc_now.replace(tzinfo=pytz.utc).astimezone(msk_tz)
|
2215 |
+
data_on = msk_now.strftime('%Y-%m-%d %H:%M:%S')
|
2216 |
+
|
2217 |
+
# Исключаем все столбцы, кроме name, phone, email, shop_st, n_con, data_on
|
2218 |
+
columns_to_update = ['name', 'phone', 'email', 'shop_st', 'n_con', 'data_on']
|
2219 |
+
values_to_update = [name, phone, email, shop_st_json, n_con_flag, data_on]
|
2220 |
+
|
2221 |
+
if result:
|
2222 |
+
# Обновляем только те поля, которые переданы в запросе
|
2223 |
+
set_clause = ', '.join([f"{col} = ?" for col in columns_to_update])
|
2224 |
+
query = f"UPDATE contacts SET {set_clause} WHERE email = ? OR phone = ?"
|
2225 |
+
cursor.execute(query, values_to_update + [email, phone])
|
2226 |
+
else:
|
2227 |
+
# Вставляем новые данные
|
2228 |
+
query = f"INSERT INTO contacts ({', '.join(columns_to_update)}) VALUES ({', '.join(['?' for _ in columns_to_update])})"
|
2229 |
+
cursor.execute(query, values_to_update)
|
2230 |
+
|
2231 |
+
conn.commit()
|
2232 |
+
|
2233 |
+
# Замена NULL на пустые строки
|
2234 |
+
replace_null_with_empty_string(conn)
|
2235 |
+
|
2236 |
+
conn.close()
|
2237 |
+
|
2238 |
+
return json.dumps(shop_st_data), 200
|
2239 |
+
|
2240 |
+
except Exception as e:
|
2241 |
+
return json.dumps({"error": str(e)}), 500
|
2242 |
+
|
2243 |
+
|
2244 |
+
|
2245 |
+
|
2246 |
+
|
2247 |
+
|
2248 |
+
|
2249 |
+
|
2250 |
+
|
2251 |
+
|
2252 |
+
|
2253 |
+
|
2254 |
@app.route('/allow', methods=['GET'])
|
2255 |
def from_allow():
|
2256 |
try:
|