Внедрение проекта

main
pilot 2 months ago
parent 2b2d4823cd
commit f1de38c535

@ -2,7 +2,7 @@ from django.http import JsonResponse
from django.core.handlers.wsgi import WSGIRequest from django.core.handlers.wsgi import WSGIRequest
from django.views.decorators.csrf import csrf_exempt from django.views.decorators.csrf import csrf_exempt
from max_bot.models import Client, ProductCategory from max_bot.models import Client, ProductCategory, Product
# Create your views here. # Create your views here.
@ -18,14 +18,18 @@ def api_default_load(request: WSGIRequest, token):
categorys = ProductCategory.objects.filter(client=50, src=1, status=1) categorys = ProductCategory.objects.filter(client=50, src=1, status=1)
for category in categorys: for category in categorys:
if not ProductCategory.objects.filter(client=client, src=1, status=1, title=category.title): if not ProductCategory.objects.filter(client=client, src=1, status=1, title=category.title):
print(category.title) pk = category.pk
new_category = ProductCategory.objects.create() new_category = category
new_category.pk = None new_category.pk = None
new_category.client = client new_category.client = client
new_category.save() new_category.save()
products = Product.objects.filter(client=50, status=1, up=pk)
for product in products:
new_product = product
new_product.pk = None
new_product.client = client
new_product.up = new_category.pk
new_product.save()
rt = {'success': False, 'data': ''} rt = {'success': False, 'data': ''}
return JsonResponse(rt, status=200) return JsonResponse(rt, status=200)

@ -54,7 +54,8 @@ def get_bonus(client: Client, phone: str, default_bonus: float, contact: Contact
else: else:
birthday = f"1990-{month}-{date}" birthday = f"1990-{month}-{date}"
rs = rkiper_customer_create(rkiper_server=config['url'], rkiper_token=config['token'], phone=phone, rs = rkiper_customer_create(rkiper_server=config['url'], rkiper_token=config['token'], phone=phone,
name=contact.name, birthday=birthday, card_type=config['card_type']) name=contact.name, birthday=birthday, bonus=config['bonus'],
discount=config['discount'])
bonus = 0 bonus = 0
return bonus return bonus

@ -3,30 +3,31 @@ import json
from restoran_max_bot.utils import normalize_mobile_phone from restoran_max_bot.utils import normalize_mobile_phone
# http://192.168.9.186:8890/docs
def rkiper_customer_info(rkiper_server, rkiper_token, phone): def rkiper_customer_info(rkiper_server, rkiper_token, phone):
url = f"http://{rkiper_server}/accounts/searchv2" url = f"http://{rkiper_server}/accounts/searchv2"
phone = normalize_mobile_phone(phone) phone = normalize_mobile_phone(phone)
phone = '*' + phone[1:] phone = '*' + phone[1:]
payload = json.dumps({ payload = json.dumps({
"case_sensitive": False, "case_sensitive": False,
"fields": [ "fields": [
"email", "email",
"tel1" "tel1"
], ],
"limit": 100, "limit": 10,
"mask": f"{phone}", "mask": f"{phone}",
"match_all": False "match_all": False
}) })
headers = { headers = {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'X-API-Key': rkiper_token 'X-API-Key': rkiper_token
} }
response = requests.request("POST", url, headers=headers, data=payload).json() response = requests.request("POST", url, headers=headers, data=payload).json()
return response return response
def rkiper_customer_create(rkiper_server, rkiper_token, phone, name, birthday, card_type="16"): def rkiper_customer_create(rkiper_server, rkiper_token, phone, name, birthday, discount, bonus):
url = f"http://{rkiper_server}/cardimp" url = f"http://{rkiper_server}/cardimp"
phone = normalize_mobile_phone(phone) phone = normalize_mobile_phone(phone)
payload = json.dumps([{ payload = json.dumps([{
@ -36,14 +37,14 @@ def rkiper_customer_create(rkiper_server, rkiper_token, phone, name, birthday, c
"phone1": f"{phone}", "phone1": f"{phone}",
"phone2": f"{phone}", "phone2": f"{phone}",
"email": f"{phone}", "email": f"{phone}",
"card_type": card_type, "discount": f"{discount}",
"bonus": f"{bonus}",
"birthday": f"{birthday}", "birthday": f"{birthday}",
"department": "max bot", "dop_info": "max bot",
}]) }])
headers = { headers = {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'X-API-Key': rkiper_token 'X-API-Key': rkiper_token
} }
response = requests.request("POST", url, headers=headers, data=payload) response = requests.request("POST", url, headers=headers, data=payload)
return response.json() return response.json()

Loading…
Cancel
Save