提交 b50c25c0 authored 作者: 张颂恩's avatar 张颂恩

优化核销逻辑

上级 7581e9b7
...@@ -22,6 +22,8 @@ from urllib.parse import urlencode ...@@ -22,6 +22,8 @@ from urllib.parse import urlencode
from http.client import HTTPConnection from http.client import HTTPConnection
from random import shuffle from random import shuffle
from wx.views import send_hb, transfer_batch, send_wechat_message_template from wx.views import send_hb, transfer_batch, send_wechat_message_template
from wx.models import Pay
from wx.cqpay import CQPay
from inventory.views import LabelQuery, decrypt_11h from inventory.views import LabelQuery, decrypt_11h
from utils.views import * from utils.views import *
from django.db.models import Count from django.db.models import Count
...@@ -852,6 +854,44 @@ def ajax_consumer_redeem(request): ...@@ -852,6 +854,44 @@ def ajax_consumer_redeem(request):
if w.company_id == 191032 and awardcat_id == 3 and w.phone and award.get_url: if w.company_id == 191032 and awardcat_id == 3 and w.phone and award.get_url:
send_sms(w.phone,f"尊敬的客户,您好,恭喜您获得{w.award_name},点击链接前往领取:{award.get_url},请知悉!",'天鉴防伪') send_sms(w.phone,f"尊敬的客户,您好,恭喜您获得{w.award_name},点击链接前往领取:{award.get_url},请知悉!",'天鉴防伪')
# 如果是第三方橙券公司
if award.out_product_id and award.out_product_platform_id == 1:
wp = Pay.objects.filter(company_id=w.company_id, pay_platform='cq')
if wp:
wp = wp[0]
cqpay = CQPay(wp.pay_platform_appid, wp.pay_platform_key, wp.aes_key, wp.aes_iv)
timestamp = int(time.time())
random_number = random.randint(1000, 9999)
order_no = 'tj' + str(timestamp) + str(random_number)
rs = cqpay.coupon_order_pay(order_no, award.out_product_id, 1, phone)
if rs['code'] == 7000:
r = rs['data'][0]
if r['goods_type'] == 'LINK':
w.award_link = cqpay.decrypt_p(r['goods_link'])
data['link'] = w.award_link
for r in rs['data']:
tp = ThirdPlatformPayRecord(
company_id=w.company_id,
platform_id=award.out_product_platform_id,
label_code=w.label_code,
order_no=order_no,
out_order_no=r['order_no'],
goods_no=r['goods_no'],
goods_name=r['goods_name'],
goods_type=r['goods_type'],
price=r['price'],
)
if r['goods_type'] == 'LINK':
tp.goods_link = cqpay.decrypt_p(r['goods_link'])
if 'effective_time' in r and r['effective_time']:
tp.goods_effective_time = datetime.datetime.fromtimestamp(r['effective_time']/1000)
w.tm_expire = tp.goods_effective_time
data['tm_expire'] = w.tm_expire
tp.save()
else:
data['e'] = rs.message
return JsonResponse(data)
w.tm_redeemed = now() w.tm_redeemed = now()
w.save() w.save()
else: else:
...@@ -5653,7 +5693,9 @@ def do_hexiao(request): ...@@ -5653,7 +5693,9 @@ def do_hexiao(request):
if c1: if c1:
c = c1[0] c = c1[0]
elif hexiao_id: elif hexiao_id:
hx = HeXiao_Record.objects.get(id=int(hexiao_id)) hexiao_id = hexiao_id.split(',')
hxs = HeXiao_Record.objects.filter(id__in=hexiao_id)
for hx in hxs:
if hx.is_need_agent_writeoff: if hx.is_need_agent_writeoff:
if not hx.is_agent_writeoff: if not hx.is_agent_writeoff:
agent = Company.objects.get(id=int(agent_id)) agent = Company.objects.get(id=int(agent_id))
...@@ -5688,14 +5730,18 @@ def do_hexiao(request): ...@@ -5688,14 +5730,18 @@ def do_hexiao(request):
record.save() record.save()
hx.is_agent_writeoff = True hx.is_agent_writeoff = True
hx.save() hx.save()
data['award'] = award.name if 'award' in data['award']:
if award.name not in data['award']:
data['award'].append(award.name)
else:
data['award'] = [award.name]
else: else:
data['e'] = '无核销权限' data['e'] = '无核销权限'
else: else:
data['e'] = '奖品已被核销' data['e'] = '奖品已被核销'
else: else:
data['e'] = '奖品不需要核销' data['e'] = '奖品不需要核销'
return JsonResponse(data); return JsonResponse(data)
if c: if c:
vs = VoidLabel.objects.filter(label_code=c.label_code) vs = VoidLabel.objects.filter(label_code=c.label_code)
if len(vs) == 0: if len(vs) == 0:
...@@ -10210,3 +10256,55 @@ def agentwinner_list(request): ...@@ -10210,3 +10256,55 @@ def agentwinner_list(request):
r[14] r[14]
]) ])
return render(request, 'sales/agentwinner_list.html', data) return render(request, 'sales/agentwinner_list.html', data)
def sales_consumer_winner_active_review(request):
data = {}
if request.method == 'GET':
id = int(request.GET.get('id','0'))
if id:
r = ConsumerWinnerActive.objects.get(id=id)
data["id"] = id
data["uid"] = request.user.id
data["status"] = r.status
data["photo"] = r.photo
else:
data = {'e': ''}
id = int(request.POST.get('id','0'))
status = int(request.POST.get('status','0'))
if id and status:
r = ConsumerWinnerActive.objects.get(id=id)
if r.status == 2:
data['e'] = '该记录已审核通过'
return JsonResponse(data)
if status == 2:
activity_award = r.award
original_award = activity_award.award
c = ConsumerWinner(
company_id=r.company_id,
label_code=r.label_code,
original_code=r.original_code,
activity_id=r.activity_id,
activity_name=r.activity.name,
award_id=activity_award.id,
original_award_id=original_award.id,
award_name=original_award.name,
award_points=original_award.points,
award_amount=original_award.amount,
award_img=original_award.photo.url,
award_cat=original_award.awardcat.name,
award_level_name=activity_award.level_name,
consumer_id=r.consumer_id,
product_id=r.product_id,
name=r.name,
phone=r.phone,
batch_code=r.batch_no,
agent_id=r.agent_id,
xcode=r.label_pk_code
)
c.save()
r.status = status
r.save()
else:
data['e'] = '缺少必要参数'
return JsonResponse(data)
return render(request, 'sales/consumer_winner_active_permit.html', data)
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论