提交 b206ad1e authored 作者: 李思鑫's avatar 李思鑫

增加zsk类

上级 caf0312a
...@@ -1180,6 +1180,8 @@ urlpatterns = [ ...@@ -1180,6 +1180,8 @@ urlpatterns = [
url(r'^test/consumer_winner_hit/$', sal_views.test_consumer_winner_hit), url(r'^test/consumer_winner_hit/$', sal_views.test_consumer_winner_hit),
url(r'^test/zsk_pay/$', wx_views.test_zsk),
url(r'^wx/kangnian/terminal/$', wx_views.kangnian_getTerminal), url(r'^wx/kangnian/terminal/$', wx_views.kangnian_getTerminal),
url(r'^wx/kangnian/product_list/$', wx_views.kangnian_getProductList), url(r'^wx/kangnian/product_list/$', wx_views.kangnian_getProductList),
......
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCefZbdsT6RiaCRqWKKIi4rWrntio3oX1RbCFSGHI3o2jS34Aew0QwBDDftdPS6ohgMRksIykoTTmXE8/1xgLc43Ed1kAQ2AHUkTdIRzhI3Sp5Ac6sD9B/Ys3Adb05PRvfCEcqDlRVjsLYCeFFpi9djZev97ojmKSajJ3kS7OnmuQIDAQAB
-----END PUBLIC KEY-----
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEA6NLHoZOiPT0wgnfg0nRl3CqcyNGWDBoCDkJ5Cw/AHt5IAEQ1
R81w+5vBcLxGCttz4Qapcbpy+ck9zYiiVtOjInhS14tbgJad9jCTWm8+ejShVp/M
k9Xe1irORrxbj9YJ3L3BbYr5K3wTuAMd43Wp+7Ia7LpplmGSvOZumTRYRyFQgSs6
Vfv0x4fRQI4/JdUp+sX3DUUns0kXy8ggoI/B6kUYS6+Th+YWjcztdliJtRMb9sM5
BIJGWuGUNCDo93+UNyTxrEI8cTczfxqlzKRZSoadHa4xJF3TBKrgm4D5fZNF/ZEs
WmfsC7qalc0x0sHuPBnXTKM97d4t0WosTJkvAQIDAQABAoIBABT6Fr/9Vf8IAhSj
OeekUqAfW8BxN8Bv4HMJ9K91NBVj6B9UBevp++3Dhw6B/BqS0rI54C7twlm0ksOv
tZa2m0pqBmbCuNQRXfqWPlSF1N58WvP70loYiSsJMMwpQOOpAHr5wtF8lb4gAAPS
jhEWIyJZFflxwz0oHek0ps7Za0G/N+cFLZAdju9OXoO3mQMvuP8AQ7qT3A3sGJP4
d6K5YzMZSNT2SrwLR18VUpaFIDkCLp4XW5LZ7SJP5Ps2OoAPGawDA8g5OFC3z3J2
lZvT9BlOhkETimhwkXjuJV68RD+YmMulIxU5Q+erljACImfP43r6aOgIs7mezm2R
bSvQXmUCgYEA7N6GuphLIOV8tOfmDpCWKgmsArTVD2t/wLa4yYpffN57gz9NZ/oa
LsOIrl62MRmybWoVa/WlP9d3cNbS5NsyJeispKftMqzdiWi2d78X358GtgebxpzG
2s+e4k4pWvVSPW98YcqBn0xa0RWVtfREyyQ6ZJCxOMxShCgPKWXJZc0CgYEA+6CZ
9ctoRWGXXGC3VRYbwVEWtu3g40cTUILX7ZA1weXilE+9pr5BgmOPqm9i16GMjTKe
92rn6H2VBm5o9nlLX1KR2IiY3YEZ77QgQuOGNrJrk9GXRGOVoR4553ACaqzD/d5N
NTMYGSLlUMvu2K74S7Y1tTMfle7wKw9M0utA+gUCgYEAjENZVLVKB7jdF+MagBVu
VoZTrWaXpAHsLJoG4pFl6fN1AEtD8wZO6tIu5dJ/4KNu3Qusk7lqmVtmBxOu3oZO
M9SMJxSpiRCEPxIaut4VrP3mY3Qt8nZz6q53T1spcgtDH84cwWvBRitYu+ckOBLl
icVyLorf5tpXIpr2H3V+xSECgYBu9PPPGiHhrlYTSyaso3IbvckZYy3uqrHOp9PV
kujRlrBiHAOSGoVCnOqGClX4pekXfkHw8jhPIclsK5WnUfc1knBznlBiJIKuW6x6
MmBFkEm1xg9A/fTGNlDsSE0YgxRtxvAezGgM9YFPLo4lCIq+wBtQyrlb4SAQrM+A
lnJxjQKBgA9YtJU5xpIR9KkKqqyCZINi+XmAwffh6XoT0e8DgOHXHnc8GgODCasL
wtCqmARfdnSy8UE2NSdHHPJUVx299t6wL0VLv11MEZqKu8mJwCIiAdR5YsHbaKTp
H+qprpac3lhMgEh25H93mxjZBxaRSjLzy2+n6XQtr2vYt5sdztVQ
-----END RSA PRIVATE KEY-----
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA6NLHoZOiPT0wgnfg0nRl
3CqcyNGWDBoCDkJ5Cw/AHt5IAEQ1R81w+5vBcLxGCttz4Qapcbpy+ck9zYiiVtOj
InhS14tbgJad9jCTWm8+ejShVp/Mk9Xe1irORrxbj9YJ3L3BbYr5K3wTuAMd43Wp
+7Ia7LpplmGSvOZumTRYRyFQgSs6Vfv0x4fRQI4/JdUp+sX3DUUns0kXy8ggoI/B
6kUYS6+Th+YWjcztdliJtRMb9sM5BIJGWuGUNCDo93+UNyTxrEI8cTczfxqlzKRZ
SoadHa4xJF3TBKrgm4D5fZNF/ZEsWmfsC7qalc0x0sHuPBnXTKM97d4t0WosTJkv
AQIDAQAB
-----END PUBLIC KEY-----
from django.shortcuts import render from django.shortcuts import render
from django.conf import settings from django.conf import settings
import json import json
import requests import requests
...@@ -124,10 +124,10 @@ def app_autocomplete(request,what): ...@@ -124,10 +124,10 @@ def app_autocomplete(request,what):
return JsonResponse(data,safe=False) return JsonResponse(data,safe=False)
#2020-07-10 #2020-07-10
rd=redis.StrictRedis(host='localhost', port=settings.RD['port'], password='tjredis139', decode_responses=True) rd=redis.StrictRedis(host='localhost', port=settings.RD['port'], password=settings.RD['password'], decode_responses=True)
#2020-12-21 微信redis库 #2020-12-21 微信redis库
rd_wx=redis.StrictRedis(host='localhost', port=settings.RD['port'], db=5, password='tjredis139', decode_responses=True) rd_wx=redis.StrictRedis(host='localhost', port=settings.RD['port'], db=5, password=settings.RD['password'], decode_responses=True)
WX_ERRS={ WX_ERRS={
1:'标签号码不存在', 1:'标签号码不存在',
...@@ -299,7 +299,8 @@ def ajax_label_img(request,company_id=None): ...@@ -299,7 +299,8 @@ def ajax_label_img(request,company_id=None):
def test_get_activity(request,company_id): def test_get_activity(request,company_id):
label_code=request.GET.get('label_code','') label_code=request.GET.get('label_code','')
data=get_activity(company_id,label_code) jmcpid=request.GET.get('jmcpid','')
data=get_activity(company_id,label_code,0,0,'',0,jmcpid)
return JsonResponse(data) return JsonResponse(data)
...@@ -339,26 +340,30 @@ def get_activity(company_id,label_code,lng=0,lat=0,phone='',activity_id=0, jmcpi ...@@ -339,26 +340,30 @@ def get_activity(company_id,label_code,lng=0,lat=0,phone='',activity_id=0, jmcpi
pass pass
else: else:
return data return data
if company_id == '208869' and lng and lat and not wuliu_label_code: if (company_id == '208869' or company_id == '107413') and lng and lat and not wuliu_label_code:
lng_lat = gcj02_to_bd09(lng, lat) lng_lat = gcj02_to_bd09(lng, lat)
adr = getAddressInfoByBaiDuApi(lng_lat) adr = getAddressInfoByBaiDuApi(lng_lat)
province = adr['province']
city = adr['city'] city = adr['city']
district = adr['district'] district = adr['district']
#print(district) #print(adr)
if district == '凤翔区': if district == '凤翔区':
return data return data
if company_id == '208869' and province !="陕西省":
#print(data)
return data
if company_id == '30366' and activity_id == 0: if company_id == '30366' and activity_id == 0:
data['activity']=Activities.objects.get(id=116) data['activity']=Activities.objects.get(id=116)
return data return data
# 荣欣佳业 只在吐鲁番市出奖 # 荣欣佳业 只在吐鲁番市出奖
if company_id == '238332': if company_id == '238332' and lng and lat:
lng_lat = gcj02_to_bd09(lng, lat) lng_lat = gcj02_to_bd09(lng, lat)
adr = getAddressInfoByBaiDuApi(lng_lat) adr = getAddressInfoByBaiDuApi(lng_lat)
city = adr['city'] city = adr['city']
if city != '吐鲁番市': if city != '吐鲁番市':
return data return data
conpany_id=str(company_id)
cur=connection.cursor() cur=connection.cursor()
#抽奖活动 #抽奖活动
...@@ -368,6 +373,8 @@ def get_activity(company_id,label_code,lng=0,lat=0,phone='',activity_id=0, jmcpi ...@@ -368,6 +373,8 @@ def get_activity(company_id,label_code,lng=0,lat=0,phone='',activity_id=0, jmcpi
product_id=0 product_id=0
package_id=0 package_id=0
pk_id='0' pk_id='0'
fh_tm = '' #发货时间
rk_tm = ''
if r: if r:
#该公司有物流管理 #该公司有物流管理
if r[0]: if r[0]:
...@@ -384,7 +391,8 @@ def get_activity(company_id,label_code,lng=0,lat=0,phone='',activity_id=0, jmcpi ...@@ -384,7 +391,8 @@ def get_activity(company_id,label_code,lng=0,lat=0,phone='',activity_id=0, jmcpi
cnt = cur.fetchone() cnt = cur.fetchone()
if cnt and cnt[0]>0: if cnt and cnt[0]>0:
c=Company.objects.get(id=int(company_id)) c=Company.objects.get(id=int(company_id))
d=LabelQuery(company.id,jmcpid) lb = wuliu_label_code if wuliu_label_code else jmcpid
d=LabelQuery(company.id,lb)
p = d.get_product() p = d.get_product()
product_id = p['id'] product_id = p['id']
package_id = 1 package_id = 1
...@@ -395,7 +403,7 @@ def get_activity(company_id,label_code,lng=0,lat=0,phone='',activity_id=0, jmcpi ...@@ -395,7 +403,7 @@ def get_activity(company_id,label_code,lng=0,lat=0,phone='',activity_id=0, jmcpi
data['label_pk_code'] = d.infor['label_pk_code'] data['label_pk_code'] = d.infor['label_pk_code']
stock_dev = d.get_stk_dev() stock_dev = d.get_stk_dev()
#print(json.dumps(stock_dev)) #print(lb, json.dumps(stock_dev))
stock_dev_len = len(stock_dev) stock_dev_len = len(stock_dev)
if stock_dev_len>0: if stock_dev_len>0:
for sto in stock_dev: for sto in stock_dev:
...@@ -403,10 +411,16 @@ def get_activity(company_id,label_code,lng=0,lat=0,phone='',activity_id=0, jmcpi ...@@ -403,10 +411,16 @@ def get_activity(company_id,label_code,lng=0,lat=0,phone='',activity_id=0, jmcpi
data['batch_no_arr'].append(sto['bill_no']) data['batch_no_arr'].append(sto['bill_no'])
if sto['vtype_id']==2 and c.name == sto['company']: if sto['vtype_id']==2 and c.name == sto['company']:
data['is_ck']= True data['is_ck']= True
agent = stock_dev[stock_dev_len-1]['agent'] if not fh_tm:
fh_tm = sto["tm"]
elif sto['vtype_id']==1 and c.name == sto['company']:
if not rk_tm:
rk_tm = sto["tm"]
if sto["agent"]["id"]:
data['agent_id'] = sto["agent"]["id"]
data['batch_no'] = stock_dev[stock_dev_len-1]['bill_no'] data['batch_no'] = stock_dev[stock_dev_len-1]['bill_no']
if agent['id']:
data['agent_id'] = agent['id']
if product_id == 0: if product_id == 0:
lb = wuliu_label_code if wuliu_label_code else label_code lb = wuliu_label_code if wuliu_label_code else label_code
#print(lb) #print(lb)
...@@ -430,6 +444,11 @@ def get_activity(company_id,label_code,lng=0,lat=0,phone='',activity_id=0, jmcpi ...@@ -430,6 +444,11 @@ def get_activity(company_id,label_code,lng=0,lat=0,phone='',activity_id=0, jmcpi
if stock_dev_len>0: if stock_dev_len>0:
for sto in stock_dev: for sto in stock_dev:
if sto['company_id']: agents.append(sto['company_id']) if sto['company_id']: agents.append(sto['company_id'])
if not fh_tm and str(sto["company_id"]) == company_id and sto["voucher_type"] == '销售出库':
fh_tm = sto["time"]
if not rk_tm and str(sto["company_id"]) == company_id and sto["voucher_type"] == '成品入库':
rk_tm = sto["time"]
agent = stock_dev[stock_dev_len-1]['company_id'] agent = stock_dev[stock_dev_len-1]['company_id']
if agent: if agent:
data['agent_id'] = agent data['agent_id'] = agent
...@@ -533,7 +552,11 @@ def get_activity(company_id,label_code,lng=0,lat=0,phone='',activity_id=0, jmcpi ...@@ -533,7 +552,11 @@ def get_activity(company_id,label_code,lng=0,lat=0,phone='',activity_id=0, jmcpi
tm=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') tm=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
sWhere=" where company_id="+str(company_id)+" and status=1 and target = 1 and ('"+tm+"' between tm_start and tm_end) "+\ sWhere=" where company_id="+str(company_id)+" and status=1 and target = 1 and ('"+tm+"' between tm_start and tm_end) "+\
" and lblpkg_id="+str(package_id)+" " " and lblpkg_id="+str(package_id)+" "
if company_id == '20324':
fh_tm = rk_tm
if fh_tm:
sWhere = sWhere + " and (('"+fh_tm+"' between fhtm_start and fhtm_end) or fhtm_end is null) "
#print(fh_tm)
#s="select id,priority from sales_activities "+sWhere+\ #s="select id,priority from sales_activities "+sWhere+\
# "and case when array_length(products,1) is null then true else ARRAY["+str(product_id)+"] <@ products end "+\ # "and case when array_length(products,1) is null then true else ARRAY["+str(product_id)+"] <@ products end "+\
# "and case when array_length(agents,1) is null then true else "+\ # "and case when array_length(agents,1) is null then true else "+\
...@@ -588,6 +611,7 @@ def get_activity(company_id,label_code,lng=0,lat=0,phone='',activity_id=0, jmcpi ...@@ -588,6 +611,7 @@ def get_activity(company_id,label_code,lng=0,lat=0,phone='',activity_id=0, jmcpi
# "order by priority desc limit 1" # "order by priority desc limit 1"
cur.execute(s) cur.execute(s)
r=cur.fetchone() r=cur.fetchone()
if r: if r:
...@@ -1649,7 +1673,14 @@ def wx_process_label_scan(request,company_id,app_id=None): ...@@ -1649,7 +1673,14 @@ def wx_process_label_scan(request,company_id,app_id=None):
response = HttpResponseRedirect('/static/20324/hb/index.html') response = HttpResponseRedirect('/static/20324/hb/index.html')
#if consumer_id == "94511": #if consumer_id == "94511":
#response = HttpResponseRedirect('/static/20324/hb_test/index.html') #response = HttpResponseRedirect('/static/20324/hb_test/index.html')
fh_tm = ''
stock_dev = d.get_stk_dev()
if stock_dev:
for sto in stock_dev:
if sto['vtype_id']==1 and sto['company'] == '四川江口醇隆鼎酒业有限公司':
fh_tm = sto["tm"]
response.set_cookie('product_id', p['id'], max_age=3600) response.set_cookie('product_id', p['id'], max_age=3600)
response.set_cookie('fh_tm', fh_tm, max_age=3600)
customlize=True customlize=True
if p['id'] == 10211: if p['id'] == 10211:
response = HttpResponseRedirect('/static/20324/hb20/index.html') response = HttpResponseRedirect('/static/20324/hb20/index.html')
...@@ -1976,9 +2007,6 @@ def wx_process_label_scan(request,company_id,app_id=None): ...@@ -1976,9 +2007,6 @@ def wx_process_label_scan(request,company_id,app_id=None):
w.agent_id = agent_id w.agent_id = agent_id
if batch_no: if batch_no:
w.batch_code = batch_no w.batch_code = batch_no
# 箱标
if d['label_pk_code']:
w.xcode = d['label_pk_code']
w.save() w.save()
...@@ -2242,6 +2270,9 @@ def ajax_get_activity(request): ...@@ -2242,6 +2270,9 @@ def ajax_get_activity(request):
r = cur.fetchone() r = cur.fetchone()
if not r or r[0].strip() != vcode: if not r or r[0].strip() != vcode:
return JsonResponse({'e':'验证码错误'}) return JsonResponse({'e':'验证码错误'})
else:
if company_id == "238332":
return JsonResponse({'e':'数据异常,请稍后再试'})
if company_id == "95971" or company_id == "30366": if company_id == "95971" or company_id == "30366":
cur.execute("select coalesce((select code_a from label.lbl_abcode where code_b='" + label_code + "'),'')") cur.execute("select coalesce((select code_a from label.lbl_abcode where code_b='" + label_code + "'),'')")
...@@ -2287,11 +2318,18 @@ def ajax_get_activity(request): ...@@ -2287,11 +2318,18 @@ def ajax_get_activity(request):
if r[0] < 1: if r[0] < 1:
return JsonResponse({'e':'不在活动范围内 no bind'}) return JsonResponse({'e':'不在活动范围内 no bind'})
elif company_id == "208869" or company_id == "107413" or company_id == "210165": elif company_id == "208869" or company_id == "107413" or company_id == "210165":
s = f"select label_code from logistics.mes_bottlcap where cap = '{jmcpid}' limit 1" s = f"select label_code from logistics.mes_bottlcap where cap = '{jmcpid}' order by id limit 1"
cur.execute(s) cur.execute(s)
r = cur.fetchone() r = cur.fetchone()
if r: if r:
wuliu_label_code = r[0] wuliu_label_code = r[0]
elif company_id == "208869":
s = f"select count(0) from bottlecap.fc{label_code[:4]} where cap = '{jmcpid}' "
cur.execute(s)
r = cur.fetchone()
if not r[0]:
return JsonResponse({'e':'网络繁忙,请稍后再试 no bind'})
#else: #else:
# s="select id from sales_lotteryseeds where label_code='"+label_code+"'" # s="select id from sales_lotteryseeds where label_code='"+label_code+"'"
# cur.execute(s) # cur.execute(s)
...@@ -2357,14 +2395,9 @@ def ajax_get_activity(request): ...@@ -2357,14 +2395,9 @@ def ajax_get_activity(request):
amount = 0 amount = 0
award = activity_award.award award = activity_award.award
award_cat = winner.award_cat #这里的类型 是名称
if award.points: if award.points:
points = award.points points = award.points
#lisin 2024-9-14
if (award_cat=='概率红包' or award_cat=='复购红包') and winner.award_amount:
amount = winner.award_amount
else:
if award.amount: if award.amount:
amount = str(award.amount) amount = str(award.amount)
award_ = { award_ = {
...@@ -2414,7 +2447,6 @@ def ajax_get_activity(request): ...@@ -2414,7 +2447,6 @@ def ajax_get_activity(request):
} }
data['award']['data'] = award_ data['award']['data'] = award_
return JsonResponse(data) return JsonResponse(data)
max_day_win_cnt = 10 max_day_win_cnt = 10
max_month_win_cnt = 0 max_month_win_cnt = 0
if company_id == "158353": if company_id == "158353":
...@@ -2424,6 +2456,8 @@ def ajax_get_activity(request): ...@@ -2424,6 +2456,8 @@ def ajax_get_activity(request):
elif company_id == "107413": elif company_id == "107413":
max_day_win_cnt = 3 max_day_win_cnt = 3
max_month_win_cnt = 20 max_month_win_cnt = 20
elif company_id == "238273":
max_day_win_cnt = 6
cur.execute(f"select count(0) from sales_consumerwinner where consumer_id = {consumer_id} and company_id = {company_id} and tm> '{datetime.datetime.now().strftime('%Y-%m-%d')}'") cur.execute(f"select count(0) from sales_consumerwinner where consumer_id = {consumer_id} and company_id = {company_id} and tm> '{datetime.datetime.now().strftime('%Y-%m-%d')}'")
cnt = cur.fetchone() cnt = cur.fetchone()
...@@ -2451,7 +2485,8 @@ def ajax_get_activity(request): ...@@ -2451,7 +2485,8 @@ def ajax_get_activity(request):
if company_id =="134666": if company_id =="134666":
activity_award = d['activity'].draw(agent,lng,lat) activity_award = d['activity'].draw(agent,lng,lat)
#activity_award = d['activity'].draw(agent) #activity_award = d['activity'].draw(agent)
elif company_id == "30366": elif int(company_id) == 30366:
s=f""" s=f"""
select count(0) from sales_consumerwinner where label_code='{label_code}' select count(0) from sales_consumerwinner where label_code='{label_code}'
""" """
...@@ -2484,13 +2519,17 @@ def ajax_get_activity(request): ...@@ -2484,13 +2519,17 @@ def ajax_get_activity(request):
activity_award = ActivityAwards.objects.get(id=r[0]) activity_award = ActivityAwards.objects.get(id=r[0])
if company_id == "145564" and not activity_award: if company_id == "145564" and not activity_award:
cur.execute(f""" s =f"""
SELECT award_id, win_method, win_consumer_ids, id FROM sales_activity_person_lottery_plan where activity_id = {str(act_id)} SELECT award_id, win_method, win_consumer_ids, id FROM sales_activity_person_lottery_plan where activity_id = {str(act_id)}
AND tm_start < now() AND tm_start < now()
AND tm_end > now() AND tm_end > now()
AND ARRAY[{consumer_id}] <@ consumer_ids AND ARRAY[{consumer_id}] <@ consumer_ids
limit 1 """
""") if bn:
s = s + f"and case when batch_no is null or batch_no = '' then true else batch_no in %s end"
cur.execute(s, (bn,))
else:
cur.execute(s)
r = cur.fetchone() r = cur.fetchone()
if r: if r:
win_award_id = r[0] win_award_id = r[0]
...@@ -2513,7 +2552,7 @@ def ajax_get_activity(request): ...@@ -2513,7 +2552,7 @@ def ajax_get_activity(request):
activity_award = aw[0] activity_award = aw[0]
if not activity_award: if not activity_award:
activity_award = d['activity'].draw(agent,lng,lat,phone=phone,label_code=label_code,activity_id=activity_id,consumer_id=consumer_id) activity_award = d['activity'].draw(agent,lng,lat,phone=phone,label_code=label_code)
activity_award_id = None activity_award_id = None
award_name = '' award_name = ''
award_points = '0' award_points = '0'
...@@ -2573,6 +2612,7 @@ def ajax_get_activity(request): ...@@ -2573,6 +2612,7 @@ def ajax_get_activity(request):
data['award']['code'] = 400 data['award']['code'] = 400
data['award']['reason'] = '未中奖' data['award']['reason'] = '未中奖'
if company_id == "19318": if company_id == "19318":
w = ConsumerWinnerActive( w = ConsumerWinnerActive(
company_id=int(company_id), company_id=int(company_id),
...@@ -2594,7 +2634,6 @@ def ajax_get_activity(request): ...@@ -2594,7 +2634,6 @@ def ajax_get_activity(request):
w.save() w.save()
return JsonResponse(data) return JsonResponse(data)
w = ConsumerWinner( w = ConsumerWinner(
company_id=int(company_id), company_id=int(company_id),
consumer_id=consumer_id, consumer_id=consumer_id,
...@@ -2613,7 +2652,7 @@ def ajax_get_activity(request): ...@@ -2613,7 +2652,7 @@ def ajax_get_activity(request):
name=name, name=name,
phone=phone, phone=phone,
original_award_id=original_award_id, original_award_id=original_award_id,
award_level_name=award_level_name award_level_name=award_level_name,
) )
if activity_id: if activity_id:
w.activity_id = activity_id w.activity_id = activity_id
...@@ -2624,11 +2663,11 @@ def ajax_get_activity(request): ...@@ -2624,11 +2663,11 @@ def ajax_get_activity(request):
w.product_id =product_id w.product_id =product_id
if redeem_now == '1' and award_cat !='微信红包': if redeem_now == '1' and award_cat !='微信红包':
w.tm_redeemed = now() w.tm_redeemed = now()
print(d) if jmcpid:
w.original_code = jmcpid
# 箱标 # 箱标
if d['label_pk_code']: if d['label_pk_code']:
w.xcode = d['label_pk_code'] w.xcode = d['label_pk_code']
print(w.xcode)
w.save() w.save()
data['award']['winner_id'] = encrypt_p(str(w.id)) data['award']['winner_id'] = encrypt_p(str(w.id))
...@@ -2729,7 +2768,7 @@ def bugsell_check(consumer_id,company_id,label_code,gis_data): ...@@ -2729,7 +2768,7 @@ def bugsell_check(consumer_id,company_id,label_code,gis_data):
if data['e']: if data['e']:
return data return data
#print(cfg_auth)
...@@ -2752,7 +2791,7 @@ def bugsell_check(consumer_id,company_id,label_code,gis_data): ...@@ -2752,7 +2791,7 @@ def bugsell_check(consumer_id,company_id,label_code,gis_data):
for id in ids: for id in ids:
if id: if id:
s="(select public.st_distance(public.st_geogfromtext('SRID=4326;POINT("+str(lng)+" "+str(lat)+")'),"+\ s="(select public.st_distance(public.st_geogfromtext('SRID=4326;POINT("+str(lng)+" "+str(lat)+")'),"+\
"(select geom from public.adm where id="+id+")))::int" "(select geom from gis.adm_map_cn where id="+id+")))::int"
a.append(s) a.append(s)
if a: if a:
s="select LEAST("+",".join(a)+")" s="select LEAST("+",".join(a)+")"
...@@ -2823,7 +2862,7 @@ def bugsell_check(consumer_id,company_id,label_code,gis_data): ...@@ -2823,7 +2862,7 @@ def bugsell_check(consumer_id,company_id,label_code,gis_data):
pass pass
cur.close() cur.close()
#print(data) print(data)
return data return data
...@@ -2971,7 +3010,7 @@ def wx_label_scan(request,company_id,app_id=None): ...@@ -2971,7 +3010,7 @@ def wx_label_scan(request,company_id,app_id=None):
ck=request.COOKIES.get(WX_CK_UID+'_'+company_id+"_"+app_id, '') ck=request.COOKIES.get(WX_CK_UID+'_'+company_id+"_"+app_id, '')
#response.set_cookie(WX_CK_UID+'_'+company_id+"_"+app_id,encrypt_p(consumer_id), expires=datetime.datetime.now()+datetime.timedelta(days=7)) #response.set_cookie(WX_CK_UID+'_'+company_id+"_"+app_id,encrypt_p(consumer_id), expires=datetime.datetime.now()+datetime.timedelta(days=7))
if company_id == "107196" or company_id == "162434" or (company_id == "36484" and app_id == '1'): if company_id == "107196" or (company_id == "162434" and app_id != "2") or (company_id == "36484" and app_id == '1'):
response = render(request, 'label_scan/' + company_id+ '/index.html') response = render(request, 'label_scan/' + company_id+ '/index.html')
if package: if package:
response.set_cookie('package', package, expires=datetime.datetime.now()+datetime.timedelta(seconds=360)) response.set_cookie('package', package, expires=datetime.datetime.now()+datetime.timedelta(seconds=360))
...@@ -2992,6 +3031,12 @@ def wx_label_scan(request,company_id,app_id=None): ...@@ -2992,6 +3031,12 @@ def wx_label_scan(request,company_id,app_id=None):
response.set_cookie('label_code', label_code, expires=datetime.datetime.now()+datetime.timedelta(seconds=360)) response.set_cookie('label_code', label_code, expires=datetime.datetime.now()+datetime.timedelta(seconds=360))
return response return response
if (company_id == "179979" and app_id == '4'):
response = HttpResponseRedirect('/static/'+company_id+'/'+app_id+'/index.html')
response.set_cookie('package', package, expires=datetime.datetime.now()+datetime.timedelta(seconds=360))
response.set_cookie('label_code', label_code, expires=datetime.datetime.now()+datetime.timedelta(seconds=360))
return response
#2020-08-18 当前标签是否有符合条件的营销活动 #2020-08-18 当前标签是否有符合条件的营销活动
#微信授权之前,不能取地理位置,先取出不包括地理位置条件的记录 #微信授权之前,不能取地理位置,先取出不包括地理位置条件的记录
...@@ -3928,8 +3973,8 @@ def get_my_info(request,what): ...@@ -3928,8 +3973,8 @@ def get_my_info(request,what):
data['e']=e data['e']=e
return JsonResponse(data) return JsonResponse(data)
u_id=request.GET.get('user_id','') u_id=request.GET.get('user_id','')
agent_id=request.GET.get('agent_id','')
role=request.GET.get('role','') role=request.GET.get('role','')
agent_id=request.GET.get('agent_id','')
if not u_id: if not u_id:
data['e']='user_id missing' data['e']='user_id missing'
return JsonResponse(data) return JsonResponse(data)
...@@ -4097,7 +4142,6 @@ def get_my_info(request,what): ...@@ -4097,7 +4142,6 @@ def get_my_info(request,what):
company_id_str = "company_id" company_id_str = "company_id"
if agent_id: if agent_id:
company_id_str = agent_id+" as company_id" company_id_str = agent_id+" as company_id"
s="select a.company_id,a.ancestor_id,b.name,b.lv,a.username,b.is_terminal,"+\ s="select a.company_id,a.ancestor_id,b.name,b.lv,a.username,b.is_terminal,"+\
"(select perm_inbound_lv1 from company_companycfg where company_id=a.ancestor_id) "+\ "(select perm_inbound_lv1 from company_companycfg where company_id=a.ancestor_id) "+\
"from "+\ "from "+\
...@@ -4135,8 +4179,9 @@ def get_my_info(request,what): ...@@ -4135,8 +4179,9 @@ def get_my_info(request,what):
if r[2]: if r[2]:
d['staff_division']['agents']=r[2] d['staff_division']['agents']=r[2]
needLicenseInfo = True needLicenseInfo = True
aids = [19651,110887,113677,115486,148119,100425,165981,164626,136485,30366,181875,191032,20324,232183,199264]
if d['ancestor_id'] == 19651 or d['ancestor_id'] == 110887 or d['ancestor_id'] == 113677 or d['ancestor_id'] == 115486 or d['ancestor_id'] == 148119 or d['ancestor_id'] == 100425 or d['ancestor_id'] == 165981 or d['ancestor_id'] == 164626 or d['ancestor_id'] == 136485 or d['ancestor_id'] == 30366 or d['ancestor_id'] == 181875 or d['ancestor_id'] == 191032 or d['ancestor_id'] == 20324: if d['ancestor_id'] in aids:
needLicenseInfo = False needLicenseInfo = False
d['needLicenseInfo'] = needLicenseInfo d['needLicenseInfo'] = needLicenseInfo
...@@ -4144,9 +4189,9 @@ def get_my_info(request,what): ...@@ -4144,9 +4189,9 @@ def get_my_info(request,what):
if d['ancestor_id'] == 115513 or d['ancestor_id'] == 203436: if d['ancestor_id'] == 115513 or d['ancestor_id'] == 203436:
d['licenseType'] = 'id-card' d['licenseType'] = 'id-card'
if d['ancestor_id'] == 19318: if d['ancestor_id'] == 19318:
data['e']='注册码已过期' d['e']='注册码已过期'
else: else:
data['e']='user_id error' d['e']='user_id error'
cur.close() cur.close()
return JsonResponse(d) return JsonResponse(d)
elif what=='storegeo': elif what=='storegeo':
...@@ -5616,15 +5661,15 @@ def wx_label_scan_record(request): ...@@ -5616,15 +5661,15 @@ def wx_label_scan_record(request):
"bind_tm": "", "bind_tm": "",
"boxes": None "boxes": None
} }
lng = request.GET.get("lng", 0) lng = request.GET.get("lng", "0")
lat = request.GET.get("lat", 0) lat = request.GET.get("lat", "0")
fwcode = request.GET.get("fwcode", "") fwcode = request.GET.get("fwcode", "")
uid = request.GET.get("uid", "") uid = request.GET.get("uid", "")
compid = request.GET.get("compid", "") compid = request.GET.get("compid", "")
nfc_code = request.GET.get("nfc_code", "") nfc_code = request.GET.get("nfc_code", "")
jmcpid = request.COOKIES.get('jmcpid','') jmcpid = request.COOKIES.get('jmcpid','')
is_nfc = request.GET.get("is_nfc", "") is_nfc = request.GET.get("is_nfc", "")
activity_id = request.GET.get("activity_id", "") record = request.GET.get("record", "1")
if is_nfc == '1': if is_nfc == '1':
fwcode = decryptQueryString(fwcode) fwcode = decryptQueryString(fwcode)
...@@ -5688,12 +5733,11 @@ def wx_label_scan_record(request): ...@@ -5688,12 +5733,11 @@ def wx_label_scan_record(request):
product_id = None product_id = None
pkid=None pkid=None
agent_name = '' agent_name = ''
agent_id = None comp = Company.objects.filter(id=int(compid))
comp = Company.objects.get(id=int(compid))
if comp: if comp:
search_code = fwcode search_code = fwcode
if jmcpid: if jmcpid:
cur.execute("select product_id, (select name from product_product where id = product_id),label_code from mes_bottlcap where cap= '"+jmcpid+"'") cur.execute("select product_id, (select name from product_product where id = product_id), label_code from mes_bottlcap where cap= '"+jmcpid+"' order by id")
p = cur.fetchone() p = cur.fetchone()
if p: if p:
product_id = p[0] product_id = p[0]
...@@ -5704,7 +5748,6 @@ def wx_label_scan_record(request): ...@@ -5704,7 +5748,6 @@ def wx_label_scan_record(request):
search_code = p[2] search_code = p[2]
#if not product_id: #if not product_id:
if True:
if compid=='134666' and fwcode[0:4]=='1247': if compid=='134666' and fwcode[0:4]=='1247':
c = str(hex(int(fwcode))) c = str(hex(int(fwcode)))
c = c[-10:] c = c[-10:]
...@@ -5713,20 +5756,19 @@ def wx_label_scan_record(request): ...@@ -5713,20 +5756,19 @@ def wx_label_scan_record(request):
""" """
cur.execute(s) cur.execute(s)
fwcode=cur.fetchone()[0] fwcode=cur.fetchone()[0]
#print
# 辽宁铁研后的公司走新查询接口 # 辽宁铁研后的公司走新查询接口
if int(compid)>=243885: if int(compid)>=243885:
d = LabelQuery(int(compid), search_code) d = LabelQuery(int(compid),fwcode)
print(d)
p = d.get_product() p = d.get_product()
product_id = p['id'] if 'id' in d.package:
package_id = d.infor['label_pk_pkg'] package_id = d.package['id']
pkid = d.infor['label_pk_id']
data['label_pkg']=package_id data['label_pkg']=package_id
pkid = d.infor['label_pk_id']
data['label_pk_id'] = pkid data['label_pk_id'] = pkid
if product_id: if p['id']:
product_id = p['id']
data['product_id']=product_id data['product_id']=product_id
cur.execute("select contents, name, photo, remark from product_product where id = "+ str(product_id)) cur.execute("select contents, name, photo, remark from product_product where id = "+ str(product_id))
rr = cur.fetchone() rr = cur.fetchone()
...@@ -5749,18 +5791,18 @@ def wx_label_scan_record(request): ...@@ -5749,18 +5791,18 @@ def wx_label_scan_record(request):
data['agent_id'] = sto['agent']['id'] data['agent_id'] = sto['agent']['id']
data['fh_time'] = sto['tm'] data['fh_time'] = sto['tm']
xcode = d.infor['label_pk_code']
data['boxes'] = xcode
# 辽宁铁研 # 辽宁铁研
if compid == '243885': if compid == '243885':
xcode = d.infor['label_pk_code']
data['boxes'] = xcode
if xcode: if xcode:
cur.execute(f"select to_char(tm,'yyyy-mm-dd HH24:MI:SS') from mes_labelbindpx where carton_code = '"+xcode+"' limit 1") cur.execute(f"select to_char(tm,'yyyy-mm-dd HH24:MI:SS') from mes_labelbindpx where carton_code = '"+xcode+"' limit 1")
r = cur.fetchone() r = cur.fetchone()
if r and r[0]: if r and r[0]:
data['bind_tm'] = r[0] data['bind_tm'] = r[0]
else: else:
d = label_sys_info(search_code, comp, has_price=False) d = label_sys_info(search_code, comp[0], has_price=False)
print(d)
if d['label_pk_id']: if d['label_pk_id']:
pkid=d['label_pk_id'] pkid=d['label_pk_id']
...@@ -5794,13 +5836,11 @@ def wx_label_scan_record(request): ...@@ -5794,13 +5836,11 @@ def wx_label_scan_record(request):
data['agent_name'] = agent_name data['agent_name'] = agent_name
data['agent_id'] = d['stock_dev'][s]['to_company_id'] data['agent_id'] = d['stock_dev'][s]['to_company_id']
data['fh_time'] = d['stock_dev'][s]['time'] data['fh_time'] = d['stock_dev'][s]['time']
break break
#print(d['stock_dev'])
# 青兰坊扫瓶标扣减终端库存 # 青兰坊扫瓶标扣减终端库存
# http://localhost:8000/wx/label/scan_record/?uid=%22gAAAAABm69JXNwYZh4LL__7YjX-SG3xkbrJnMUycv-75qfkzQNN6NkfEKmR741XVASxtVAeCXptkOF4Fc12fz48Z0uMhZynaeQ%3D%3D%22&compid=199264&fwcode=129701910053&lat=20.0076&lng=110.29357 if product_id and data['label_pkg'] == 1 and compid == '199264':
s_len = len(d['stock_dev'])
if s_len and product_id and data['label_pkg'] == 1 and compid == '199264':
is_rk = False is_rk = False
is_ck = False is_ck = False
rk_row = None rk_row = None
...@@ -5842,9 +5882,9 @@ def wx_label_scan_record(request): ...@@ -5842,9 +5882,9 @@ def wx_label_scan_record(request):
request.META['CONTENT_TYPE']='application/json' request.META['CONTENT_TYPE']='application/json'
r = fg_update(request) r = fg_update(request)
if compid == '189137': if compid == '189137':
r = requests.get('http://www.china315net.com:35222/fjbq/json/'+fwcode+'/') try:
r = requests.get('http://www.china315net.com:35222/fjbq/json/'+fwcode+'/', timeout=3)
if r.status_code == 200: if r.status_code == 200:
d = r.json() d = r.json()
if d['err'] == '': if d['err'] == '':
...@@ -5859,7 +5899,12 @@ def wx_label_scan_record(request): ...@@ -5859,7 +5899,12 @@ def wx_label_scan_record(request):
tm_1st = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') tm_1st = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
data['tm_1st'] = tm_1st data['tm_1st'] = tm_1st
else: else:
record = '1' data['img'] = '/static/images/loading.gif'
data['tm_1st'] = '查询中'
except Exception as e:
data['img'] = '/static/images/loading.gif'
data['tm_1st'] = '查询中'
else:
if compid == '206818' and not data['inventory']: if compid == '206818' and not data['inventory']:
record = '0' record = '0'
if compid == '194378' and not agent_name: if compid == '194378' and not agent_name:
...@@ -5871,7 +5916,8 @@ def wx_label_scan_record(request): ...@@ -5871,7 +5916,8 @@ def wx_label_scan_record(request):
params['uid'] = uid params['uid'] = uid
params['record'] = record params['record'] = record
params['history'] = history params['history'] = history
r = requests.get('http://www.china315net.com:35207/tjfw/get/', params) try:
r = requests.get('http://www.china315net.com:35207/tjfw/get/', params, timeout=3)
if r.status_code == 200: if r.status_code == 200:
d = r.json() d = r.json()
if d['err'] == '': if d['err'] == '':
...@@ -5884,7 +5930,11 @@ def wx_label_scan_record(request): ...@@ -5884,7 +5930,11 @@ def wx_label_scan_record(request):
data['tm_1st'] = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') data['tm_1st'] = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
data['history'] = d['history'] data['history'] = d['history']
else: else:
data['e'] = 'retrieve image failed' data['img'] = '/static/images/loading.gif'
data['tm_1st'] = '查询中'
except Exception as e:
data['img'] = '/static/images/loading.gif'
data['tm_1st'] = '查询中'
data_save = { data_save = {
'consumer_id': 0, 'consumer_id': 0,
...@@ -5893,7 +5943,7 @@ def wx_label_scan_record(request): ...@@ -5893,7 +5943,7 @@ def wx_label_scan_record(request):
'label_pkg': None, 'label_pkg': None,
'label_id': None, 'label_id': None,
'label_pk_id': pkid, #2023-08-29 'label_pk_id': pkid, #2023-08-29
'activity_id': activity_id, 'activity_id': None,
'product_id': product_id, 'product_id': product_id,
'province': province, 'province': province,
'city': city, 'city': city,
...@@ -5929,27 +5979,11 @@ def wx_label_scan_record(request): ...@@ -5929,27 +5979,11 @@ def wx_label_scan_record(request):
) )
else: else:
data_save['ip'] = uid data_save['ip'] = uid
labelscan_id = labelscan_save(data_save) labelscan_save(data_save)
is_cap = False
if compid == "238273":
is_cap = True
if is_cap and agent_id and product_id:
cur.execute("")
cur.execute(f"select id from sales_bottleopened where label_code = '{fwcode}' limit 1")
r = cur.fetchone()
if not r:
b = BottleOpened(
ancestor_id=comp.id,
company_id=agent_id,
product_id=product_id,
labelscan_id=labelscan_id,
label_code=fwcode
)
b.save()
return JsonResponse(data) return JsonResponse(data)
#2020-12-21 同步微信OPENID,昵称,头像; user: openid'id #2020-12-21 同步微信OPENID,昵称,头像; user: openid'id
def refresh_wxopenid(company_id,user_id,wx_openid,wx_nickname,wx_headimgurl,category=1): def refresh_wxopenid(company_id,user_id,wx_openid,wx_nickname,wx_headimgurl,category=1):
wx_key=str(company_id)+'_'+wx_openid wx_key=str(company_id)+'_'+wx_openid
...@@ -7068,13 +7102,13 @@ def channel_rebate_action(request,what): ...@@ -7068,13 +7102,13 @@ def channel_rebate_action(request,what):
@csrf_exempt # @csrf_exempt
def test_send_hb(request): def test_send_hb(request):
openid = u'oKPne6UJmC6DT56OoafhmcVY2y-o' openid = u'o39S9jhRCWRQd5yozq5eoRhH0Oc0'
#appid = 'wxe9a919e0d3c419ee' #appid = 'wxe9a919e0d3c419ee'
appid = '' appid = 'wx73986617af90c47b'
money = 100 money = 100
company_id = 107413 company_id = 255607
data = { data = {
'e':'' 'e':''
} }
...@@ -7088,8 +7122,8 @@ def send_hb(openid,money,company_id,appid=''): ...@@ -7088,8 +7122,8 @@ def send_hb(openid,money,company_id,appid=''):
向个人用户发红包 向个人用户发红包
""" """
if str(company_id) == "19318": #if str(company_id) == "19318":
return send_hb_sxtb(openid,money,appid) # return send_hb_sxtb(openid,money,appid)
if str(company_id) == "19257": if str(company_id) == "19257":
return send_hb_mjh(openid,money) return send_hb_mjh(openid,money)
...@@ -7115,6 +7149,7 @@ def send_hb(openid,money,company_id,appid=''): ...@@ -7115,6 +7149,7 @@ def send_hb(openid,money,company_id,appid=''):
'return_msg':'网络超时', 'return_msg':'网络超时',
'send_listid':'', 'send_listid':'',
} }
#print(err)
if err['code'] == 200: if err['code'] == 200:
er['return_code']='SUCCESS' er['return_code']='SUCCESS'
er['result_code']='SUCCESS' er['result_code']='SUCCESS'
...@@ -7127,7 +7162,7 @@ def send_hb(openid,money,company_id,appid=''): ...@@ -7127,7 +7162,7 @@ def send_hb(openid,money,company_id,appid=''):
if appid: if appid:
wx_app_id = appid wx_app_id = appid
with open(path+'apiclient_key.pem') as f: with open(r'E:\work\datacenter\wx\cert\sxgt\apiclient_key.pem') as f:
PRIVATE_KEY = f.read() PRIVATE_KEY = f.read()
#logging.basicConfig(filename=os.path.join('F:\hzy\log\wechatpay', 'demo.log'), level=logging.DEBUG, filemode='a', format='%(asctime)s - %(process)s - %(levelname)s: %(message)s') #logging.basicConfig(filename=os.path.join('F:\hzy\log\wechatpay', 'demo.log'), level=logging.DEBUG, filemode='a', format='%(asctime)s - %(process)s - %(levelname)s: %(message)s')
#LOGGER = logging.getLogger("demo") #LOGGER = logging.getLogger("demo")
...@@ -7139,7 +7174,7 @@ def send_hb(openid,money,company_id,appid=''): ...@@ -7139,7 +7174,7 @@ def send_hb(openid,money,company_id,appid=''):
apiv3_key=wp.key_v3, apiv3_key=wp.key_v3,
appid=wx_app_id, appid=wx_app_id,
notify_url='', notify_url='',
cert_dir=path, cert_dir='E:\\work\\datacenter\\wx\\cert\\sxgt\\',
logger=None, logger=None,
partner_mode=False, partner_mode=False,
proxy=None) proxy=None)
...@@ -7153,7 +7188,7 @@ def send_hb(openid,money,company_id,appid=''): ...@@ -7153,7 +7188,7 @@ def send_hb(openid,money,company_id,appid=''):
total_num=1, total_num=1,
transfer_detail_list=transfer_detail_list transfer_detail_list=transfer_detail_list
) )
#print(err) print(err)
er = { er = {
'return_code':'fail', 'return_code':'fail',
'result_code':'fail', 'result_code':'fail',
...@@ -7803,6 +7838,7 @@ def wx_consumer_award_share_get(request): ...@@ -7803,6 +7838,7 @@ def wx_consumer_award_share_get(request):
#2021-01-26 #2021-01-26
def get_notifications(request): def get_notifications(request):
data={'e':'','notifications':[]} data={'e':'','notifications':[]}
...@@ -11065,7 +11101,7 @@ def app_get_labelinfo(request,company_id): ...@@ -11065,7 +11101,7 @@ def app_get_labelinfo(request,company_id):
#前端文件上传接口 #前端文件上传接口
@csrf_exempt @csrf_exempt
def frontend_upload(request): def frontend_upload(request):
data={'e':'','msg':''} data={'e':'','msg':'','url':''}
e=time_key_check(request,sK) e=time_key_check(request,sK)
if e: if e:
data['e']=e data['e']=e
...@@ -11107,6 +11143,7 @@ def frontend_upload(request): ...@@ -11107,6 +11143,7 @@ def frontend_upload(request):
for chunk in ff.chunks(): for chunk in ff.chunks():
f.write(chunk) f.write(chunk)
f.close() f.close()
data['url'] = '/media/fileupload/'+c.name+'/'+dt+'/'+dt+f_name+'_'+u.username+f_ext
data['msg']='文件上传成功' data['msg']='文件上传成功'
return JsonResponse(data) return JsonResponse(data)
...@@ -12208,7 +12245,7 @@ def request_miniprogram_ai_status(request): ...@@ -12208,7 +12245,7 @@ def request_miniprogram_ai_status(request):
consumer_id = request.GET.get('consumer_id','') consumer_id = request.GET.get('consumer_id','')
uuid = request.GET.get('uuid','') uuid = request.GET.get('uuid','')
# company_id = request.GET.get('company_id','') # company_id = request.GET.get('company_id','')
if not label_code or not consumer_id or not uuid: if not label_code or not uuid:
return JsonResponse({'e':'数据丢失'}) return JsonResponse({'e':'数据丢失'})
if len(consumer_id)>10: if len(consumer_id)>10:
...@@ -12219,10 +12256,11 @@ def request_miniprogram_ai_status(request): ...@@ -12219,10 +12256,11 @@ def request_miniprogram_ai_status(request):
state = request.GET.get('state','') state = request.GET.get('state','')
s = AIStatus( s = AIStatus(
label_code=label_code, label_code=label_code,
consumer_id=int(consumer_id),
uuid=uuid, uuid=uuid,
state=state, state=state,
) )
if consumer_id:
s.consumer_id = int(consumer_id)
s.save() s.save()
data={'msg':'inserted'} data={'msg':'inserted'}
elif status: elif status:
...@@ -12834,7 +12872,8 @@ def ajax_get_agent_winner(request): ...@@ -12834,7 +12872,8 @@ def ajax_get_agent_winner(request):
b.name, b.name,
a.is_need_hexiao, a.is_need_hexiao,
a.is_hexiao, a.is_hexiao,
a.use_status a.use_status,
award_num
from from
sales_agentwinner a sales_agentwinner a
left join sales_activities b on a.activity_id = b.id left join sales_activities b on a.activity_id = b.id
...@@ -12856,7 +12895,8 @@ def ajax_get_agent_winner(request): ...@@ -12856,7 +12895,8 @@ def ajax_get_agent_winner(request):
'activity_name': r[7], 'activity_name': r[7],
'is_need_hexiao': r[8], 'is_need_hexiao': r[8],
'is_hexiao': r[9], 'is_hexiao': r[9],
'use_status': r[10] 'use_status': r[10],
'award_num': r[11]
}) })
else: else:
data['e'] = '缺少必要参数' data['e'] = '缺少必要参数'
...@@ -13119,20 +13159,20 @@ def get_nfc_code_by_label_code(request): ...@@ -13119,20 +13159,20 @@ def get_nfc_code_by_label_code(request):
if r[1] == 0: if r[1] == 0:
unbind_codes.append(r[0]) unbind_codes.append(r[0])
if len(unbind_codes): if len(unbind_codes):
data['e'] = '存在未绑数据' data['e'] = '存在未绑数据:'+(','.join(unbind_codes))
else: else:
cur = connection.cursor()
s = f"select nfc from z_labelnfc_details where label = '{label_code}' order by id desc limit 1" s = f"select nfc from z_labelnfc_details where label = '{label_code}' order by id desc limit 1"
cur.execute(s) cur.execute(s)
r = cur.fetchone() r = cur.fetchone()
if r: if r:
data['nfc'] = r[0] data['nfc'] = r[0]
else: else:
data['e'] = '未绑定' data['e'] = ''
else: else:
data['e'] = '数据丢失' data['e'] = '数据丢失'
return JsonResponse(data) return JsonResponse(data)
# 20240711 2116 【川酒集团】-终端店返利(实物或者酒票)开发 # 20240711 2116 【川酒集团】-终端店返利(实物或者酒票)开发
@csrf_exempt @csrf_exempt
def wx_get_ancestor_awardredeem(request): def wx_get_ancestor_awardredeem(request):
...@@ -13459,7 +13499,6 @@ def get_awardreed_status(request): ...@@ -13459,7 +13499,6 @@ def get_awardreed_status(request):
return JsonResponse(data) return JsonResponse(data)
def ajax_recent_inventory_record(request): def ajax_recent_inventory_record(request):
company_id = request.GET.get("company_id", "") company_id = request.GET.get("company_id", "")
voucher_code = request.GET.get("voucher_code", "") voucher_code = request.GET.get("voucher_code", "")
...@@ -13588,3 +13627,26 @@ def wx_consumer_winner_active(request, what): ...@@ -13588,3 +13627,26 @@ def wx_consumer_winner_active(request, what):
return JsonResponse(data) return JsonResponse(data)
data['e'] = '未知的请求内容' data['e'] = '未知的请求内容'
return JsonResponse(data) return JsonResponse(data)
from .zskpay import ZSKPay
def test_zsk(request):
zsk_pay_instance = ZSKPay()
respones = zsk_pay_instance.transfer({
'transferDetailList': [
{
'transferNo':'tj_consumer_winner_001',
"transferAmount": 30,
"transferRemark": "红包",
"openid": "oCZuC5RiJ8RId4qacC0inhy74vRc",
}
]
})
# resp = zsk_pay_instance.transfer_info({
# 'batchNo': 'tjhd-001',
# 'transferNo':'tj_consumer_winner_001',
# })
return JsonResponse({'success': 1})
#橙券支付 #橙券支付
#中数科支付
#接口文档 https://doc.apipost.net/docs/detail/34ff33e7bce7000?target_id=ef551d7ba901a
import hashlib import hashlib
import datetime import datetime
...@@ -8,46 +10,175 @@ import urllib.request ...@@ -8,46 +10,175 @@ import urllib.request
import urllib.parse import urllib.parse
import random import random
import base64 import base64
import os
from Crypto.Cipher import AES from Crypto.Cipher import AES
from Crypto.Util.Padding import unpad from Crypto.Util.Padding import unpad
domain='https://api.chengquan.cn' from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.asymmetric import rsa
from cryptography.hazmat.primitives import serialization, hashes
from cryptography.hazmat.primitives.asymmetric import padding
env = 'dev'
domain='http://ywymtest-api.azhiyun.cn'
sign = {
'dev': {
'ym-id': '645206198756315136',
'ym-key': '15a5ba24711540f0bd3246b92a7c7daa'
},
'prod':{}
}
class ZSKPay: class ZSKPay:
def __init__(self, appid, k, aes_key='', aes_iv=''): def __init__(self):
self.appid = appid self.MAX_ENCRYPTION_SIZE = 117 #214
self.k =k
self.aes_key = aes_key
self.aes_iv = aes_iv
# 计算签名 # 计算签名
def generate_sign(self,data): def generate_sign(self,data):
return '' # # 1. 整理参数
# sorted_keys = sorted(data.keys())
def http_post(self,data, type, url): # sorted_data = []
timestamp = int(round(time.time() * 1000)) # for key in sorted_keys:
data['timestamp'] = timestamp # sorted_data.append(f"{key}={data[key]}")
data['ym-id'] = self.appid # # 2. 连接参数
if type: # params_string = '&'.join(sorted_data)
data['type'] = type # # 3. 添加签名秘钥
sign = self.generate_sign(data) # params_string += f"&key={self.k}"
data['ym-key'] = sign # # 4. MD5 加密
data = json.dumps(data) # sign = hashlib.md5(params_string.encode('utf-8')).hexdigest().upper()
data = bytes(data,"utf8")
headers={'Content-Type':'application/json'} return 'sign'
request = urllib.request.Request(domain+url, data, headers)
res = urllib.request.urlopen(request).read().decode('utf-8') def encrypt_data(self, data):
return json.loads(res) encrypted_chunks = []
current_directory = os.getcwd()
def transfer(self): with open(current_directory+"/wx/cert/zsk/req/public_key.txt", "rb") as public_file:
data = { public_key_content = public_file.read()
public_key_loaded = serialization.load_pem_public_key(
public_key_content,
backend=default_backend()
)
# 将数据分块
for i in range(0, len(data), self.MAX_ENCRYPTION_SIZE):
chunk = data[i:i + self.MAX_ENCRYPTION_SIZE]
try:
# 使用公钥加密内容
ciphertext = public_key_loaded.encrypt(
chunk,
padding.PKCS1v15()
)
encrypted_chunks.append(ciphertext)
except Exception as e:
print("加密块失败:", e)
# 将所有加密后的块连接在一起
resp = b''.join(encrypted_chunks)
return base64.b64encode(resp).decode('utf-8')
def decrypt_data(self, data):
current_directory = os.getcwd()
with open(current_directory+"/wx/cert/zsk/resp/private_key.txt", "rb") as public_file:
private_key_content = public_file.read()
# 加载私钥
private_key_loaded = serialization.load_pem_private_key(
private_key_content,
password=None,
backend=default_backend()
)
# 解密
data = json.jmson.loads(data)
plaintext = private_key_loaded.decrypt(
base64.b64decode(data),
padding.PKCS1v15()
)
return plaintext.decode('utf-8')
def http_post(self, data={}, url=''):
data = json.dumps(data).encode('utf-8')
# 加密数据
data = self.encrypt_data(data)
# print("加密后数据:", type(data), data)
headers = {
'Content-Type': 'application/json',
**sign[env]
}
request = urllib.request.Request(domain + url, bytes(json.dumps({'data': data}), "utf8"), headers, method='POST')
# 发送请求并获取响应
try:
response = urllib.request.urlopen(request)
# 读取响应体
res_body = response.read().decode('utf-8')
print("返回结果:", res_body)
return json.loads(res_body)
except urllib.error.HTTPError as e:
print("HTTP错误:", e.code, e.read().decode())
except urllib.error.URLError as e:
print("网络错误:", e.reason)
#转账
def transfer(self,data):
print('开始转账:')
handle_data = {
"taxId": 1836580691238883330,
"batchNo":data.get('batchNo', self.generate_batchNo()),
"appid": data.get('appid','wxb8516c6064271fe4'),
"batchName": data.get('batchName','活动批次'),
"batchRemark": data.get('batchRemark','默认备注'),
"totalAmount": 0,
"totalNum": 0, #转账总笔数
"transferSceneId": "", #转账场景ID
"notifyUrl": "", #回调地址
#转账明细列表
"transferDetailList":data.get('transferDetailList',[])
# [
# {
# "transferNo": "tj_consumer_winner_001", //商家明细单号
# "transferAmount": 30, //转账金额单位为“分”
# "transferRemark": "红包", //转账备注,【转账备注】 单条转账备注(微信用户会收到该备注),UTF8编码,最多允许32个字符
# "openid": "oCZuC5RiJ8RId4qacC0inhy74vRc", //【收款用户openid】商户appid下,某用户的openid
# "userName": "
# }
# ]
} }
return self.http_post_form(data, '', '') if len(data['transferDetailList']) == 0:
raise ValueError("transferDetailList 必传")
for item in data['transferDetailList']:#计算总金额和总笔数
# if not item.get('transferNo') or not item.get('transferAmount') or not item.get('transferRemark') or not item.get('openid'):
# raise ValueError("缺少转账参数")
handle_data['totalAmount'] += item['transferAmount']
handle_data['totalNum'] += 1
print('加密前数据----:',handle_data)
return self.http_post(data=handle_data,url='/wx-pay/transfer')
#转账信息查询
def tranfer_info(self,data={}):
if not data.get('batchNo') or data.get('batch',''):
raise ValueError("缺少参数")
encrypt_body = self.http_post(data=data,url='/wx-pay/transfer-info')
decrypted_body = self.decrypt_data(encrypt_body['data'])
print('解密后的查询数据',decrypted_body)
return json.loads(decrypted_body)
# 生成订单号 # 生成订单号
def generate_order_number(): def generate_batchNo():
timestamp = int(time.time()) timestamp = int(time.time())
random_number = random.randint(1000, 9999) random_number = random.randint(1000, 9999)
order_number = str(timestamp) + str(random_number) batchNo ='tj'+ str(timestamp) + str(random_number)
return order_number return batchNo
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论