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

新增返利核销接口

上级 b1cf94e6
...@@ -1101,7 +1101,9 @@ urlpatterns = [ ...@@ -1101,7 +1101,9 @@ urlpatterns = [
url(r'^sales/lotterywinnerseeds/delete/(?P<id>\d+)/$', sal_views.lotterywinnerseeds_delete), url(r'^sales/lotterywinnerseeds/delete/(?P<id>\d+)/$', sal_views.lotterywinnerseeds_delete),
#核销管理 #核销管理
url(r'^sales/do_hexiao/$', sal_views.do_hexiao), url(r'^sales/do_hexiao/$', sal_views.do_hexiao),
# 经销商给终端店兑付 url(r'^sales/do_agent_winner_hexiao/$', sal_views.do_agent_winner_hexiao),
url(r'^sales/do_agent_withdraw_hexiao/$', sal_views.do_agent_withdraw_hexiao),
# 经销商给终端店兑付
url(r'^sales/do-redeem/$', sal_views.do_redeem), url(r'^sales/do-redeem/$', sal_views.do_redeem),
url(r'^sales/do_hexiao_dispatch/$', sal_views.do_hexiao_dispatch), url(r'^sales/do_hexiao_dispatch/$', sal_views.do_hexiao_dispatch),
url(r'^sales/do_hexiao_accept/$', sal_views.do_hexiao_accept), url(r'^sales/do_hexiao_accept/$', sal_views.do_hexiao_accept),
......
...@@ -5846,6 +5846,99 @@ def do_hexiao(request): ...@@ -5846,6 +5846,99 @@ def do_hexiao(request):
return JsonResponse(data) return JsonResponse(data)
# 核销接口
@csrf_exempt
def do_agent_winner_hexiao(request):
data = {
'e': '',
'reason': ''
}
company_id = int(request.GET.get('company_id', '0'))
user_id = int(request.GET.get('user_id', '0'))
winner_id = request.GET.get('winner_id', '')
if company_id and user_id and winner_id:
winner_id = decrypt_p(winner_id)
win = AgentWinner.objects.get(id=int(winner_id))
if win.is_need_hexiao:
if not win.is_hexiao:
if win.company_id != company_id:
c = Company.objects.get(id=company_id)
h = HeXiao_Record(
company_id=win.ancestor_id,
award_id=win.award_id,
award_name=win.award_name,
activity_id=win.activity_id,
activity_name=win.activity.name,
agent_id=c.id,
agent_name=c.name,
applyer_id=user_id,
agent_winner_id=win.id,
money=0
)
h.save()
win.is_hexiao = True
win.write_off_company_id = company_id
win.write_off_user_id = user_id
win.write_off_tm = now()
win.save()
else:
data['e'] = '您不能自己核销'
else:
data['e'] = '数据已核销'
else:
data['e'] = '数据无需核销'
else:
data['e'] = '数据丢失'
return JsonResponse(data)
# 核销提现接口
@csrf_exempt
def do_agent_withdraw_hexiao(request):
data = {
'e': ''
}
company_id = int(request.GET.get('company_id', '0'))
user_id = int(request.GET.get('user_id', '0'))
agent_id = int(request.GET.get('agent_id', '0'))
amount = float(request.GET.get('amount', '0'))
lat = request.GET.get('lat', '0')
lng = request.GET.get('lng', '0')
if company_id and user_id and agent_id and amount:
agent = Company.objects.get(id=agent_id)
u = User.objects.get(id=user_id)
if u.ancestor_id == agent.ancestor_id:
# 限制只能公司级别核销
if u.level_id != 1:
data['e']='无核销权限'
return JsonResponse(data)
s="select coalesce(rval,0.00),coalesce(dval,0.00) from "+\
"(select "+\
"(select sum(val) from sales_channelrebatebatch where company_id="+str(agent_id)+") rval,"+\
"(select sum(val) from sales_channelrebateredeemed where company_id="+str(agent_id)+") dval "+\
") t"
cur=connection.cursor()
cur.execute(s)
r=cur.fetchone()
if amount+float(r[1])>float(r[0]):
data['e']='可提现金额不足'
return JsonResponse(data)
rd=ChannelRebateRedeemed(
company_id=agent_id,
ancestor_id=u.company.ancestor_id,
user_id=u.id,
val=amount,
remark='核销提现'
)
rd.save()
else:
data['e'] = '无权限核销'
else:
data['e'] = '数据丢失'
return JsonResponse(data)
# 经销商给终端店兑付 # 经销商给终端店兑付
@csrf_exempt @csrf_exempt
......
...@@ -584,7 +584,6 @@ def get_activity(company_id,label_code,lng=0,lat=0,phone='',activity_id=0, jmcpi ...@@ -584,7 +584,6 @@ 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:
...@@ -5647,100 +5646,131 @@ def wx_label_scan_record(request): ...@@ -5647,100 +5646,131 @@ def wx_label_scan_record(request):
cur.execute(s) cur.execute(s)
fwcode=cur.fetchone()[0] fwcode=cur.fetchone()[0]
#print #print
d = label_sys_info(fwcode, comp[0], has_price=False)
#print(fwcode) # 辽宁铁研后的公司走新查询接口
print(json.dumps(d)) if int(compid)>=243885:
# 2023-08-29 d = LabelQuery(int(compid),fwcode)
if d['label_pk_id']: p = d.get_product()
pkid=d['label_pk_id'] product_id = p['id']
package_id = d.infor['label_pk_pkg']
if d['package']: pkid = d.infor['label_pk_id']
data['label_pkg'] = d['package']['id'] data['label_pkg']=package_id
data['label_pk_id'] = pkid
if d['product']['id'] !=0: if product_id:
product_id = d['product']['id'] data['product_id']=product_id
data['product_id'] = d['product']['id'] cur.execute("select contents, name, photo, remark from product_product where id = "+ str(product_id))
data['product_name'] = d['product']['name']
data['product_photo'] = d['product']['photo']
data['product_remark'] = d['product']['remark']
data['product_aging'] = d['product_aging']
data['vendor_id'] = d['vendor_id']
contents = request.GET.get("contents", "")
if contents =="1" and product_id:
cur.execute("select contents from product_product where id = "+ str(product_id))
rr = cur.fetchone() rr = cur.fetchone()
if rr and rr[0]: if rr:
data['product_contents'] = urllib.parse.quote(rr[0]) if rr[0]:
data['product_contents'] = urllib.parse.quote(rr[0])
data['product_name'] = rr[1]
data['product_photo'] = rr[2]
data['product_remark'] = rr[3]
if d['stock_dev']: stock_dev = d.get_stk_dev()
s_len = range(len(d['stock_dev'])) if stock_dev:
data['inventory'] = d['stock_dev'] for sto in stock_dev:
for s in s_len: if sto['voucher'] == '成品入库' and not data['voucher_no']:
if d['stock_dev'][s]['voucher_type'] == '成品入库': data['voucher_no'] = sto['bill_no']
data['voucher_no'] = d['stock_dev'][s]['voucher_no'] if sto['voucher'] == '销售出库' and not data['agent_name']:
if d['stock_dev'][s]['voucher_type'] == '销售出库': agent_name = sto['agent']['name']
agent_name = d['stock_dev'][s]['to_company'] data['agent_name'] = agent_name
data['agent_name'] = agent_name data['agent_id'] = sto['agent']['id']
data['agent_id'] = d['stock_dev'][s]['to_company_id'] data['fh_time'] = sto['tm']
data['fh_time'] = d['stock_dev'][s]['time']
break
#print(d['stock_dev']) # 辽宁铁研
# 青兰坊扫瓶标扣减终端库存 if compid == '243885':
# 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 xcode = d.infor['label_pk_code']
s_len = len(d['stock_dev']) data['boxes'] = xcode
if s_len and product_id and data['label_pkg'] == 1 and compid == '199264': if xcode:
is_rk = False cur.execute(f"select to_char(tm,'yyyy-mm-dd HH24:MI:SS') from mes_labelbindpx where carton_code = '"+xcode+"' limit 1")
is_ck = False
rk_row = None
lbcode = fwcode
if fwcode.startswith('9'):
cur.execute(f"select code_a from label.lbl_abcode where code_b = '{fwcode}' ")
r = cur.fetchone() r = cur.fetchone()
if r and r[0]: if r and r[0]:
lbcode = r[0] data['bind_tm'] = r[0]
else:
for stk in d['stock_dev']: d = label_sys_info(fwcode, comp[0], has_price=False)
if stk['voucher_type'] == '成品入库' and (stk['label_code'] == lbcode or stk['label_code'] == fwcode or stk['package'] == '箱标'): if d['label_pk_id']:
is_rk = True pkid=d['label_pk_id']
rk_row = stk
if stk['voucher_type'] == '销售出库' and stk['label_code'] == lbcode: if d['package']:
is_ck = True data['label_pkg'] = d['package']['id']
if d['product']['id'] !=0:
product_id = d['product']['id']
data['product_id'] = d['product']['id']
data['product_name'] = d['product']['name']
data['product_photo'] = d['product']['photo']
data['product_remark'] = d['product']['remark']
data['product_aging'] = d['product_aging']
data['vendor_id'] = d['vendor_id']
contents = request.GET.get("contents", "")
if contents =="1" and product_id:
cur.execute("select contents from product_product where id = "+ str(product_id))
rr = cur.fetchone()
if rr and rr[0]:
data['product_contents'] = urllib.parse.quote(rr[0])
if d['stock_dev']:
s_len = range(len(d['stock_dev']))
data['inventory'] = d['stock_dev']
for s in s_len:
if d['stock_dev'][s]['voucher_type'] == '成品入库':
data['voucher_no'] = d['stock_dev'][s]['voucher_no']
if d['stock_dev'][s]['voucher_type'] == '销售出库':
agent_name = d['stock_dev'][s]['to_company']
data['agent_name'] = agent_name
data['agent_id'] = d['stock_dev'][s]['to_company_id']
data['fh_time'] = d['stock_dev'][s]['time']
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
s_len = len(d['stock_dev'])
if s_len and product_id and data['label_pkg'] == 1 and compid == '199264':
is_rk = False
is_ck = False
rk_row = None
lbcode = fwcode
if fwcode.startswith('9'):
cur.execute(f"select code_a from label.lbl_abcode where code_b = '{fwcode}' ")
r = cur.fetchone()
if r and r[0]:
lbcode = r[0]
for stk in d['stock_dev']:
if stk['voucher_type'] == '成品入库' and (stk['label_code'] == lbcode or stk['label_code'] == fwcode or stk['package'] == '箱标'):
is_rk = True
rk_row = stk
if stk['voucher_type'] == '销售出库' and stk['label_code'] == lbcode:
is_ck = True
if is_rk and not is_ck:
code = 'ZDCK-'+datetime.datetime.now().strftime('%Y%m%d%H%M%S%f')[:-3]
# 节流
if rd_wx.set('ZDCK-'+lbcode, code, px=5000, nx=True):
t=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
m2=hashlib.md5((sK+t).encode('utf8'))
codes = [lbcode]
postData={
"bill_number": code,
"company_id": rk_row['company_id'],
"to_company_id": 11013,
"user_id": rk_row['user_id'],
"product_id": product_id,
"voucher_id": 2,
"voucher_time":t,
"codes": codes,
"time":t,
"key":m2.hexdigest(),
}
request.method = 'POST'
request._body=json.dumps(postData)
request.META['CONTENT_TYPE']='application/json'
r = fg_update(request)
if is_rk and not is_ck:
code = 'ZDCK-'+datetime.datetime.now().strftime('%Y%m%d%H%M%S%f')[:-3]
# 节流
if rd_wx.set('ZDCK-'+lbcode, code, px=5000, nx=True):
t=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
m2=hashlib.md5((sK+t).encode('utf8'))
codes = [lbcode]
postData={
"bill_number": code,
"company_id": rk_row['company_id'],
"to_company_id": 11013,
"user_id": rk_row['user_id'],
"product_id": product_id,
"voucher_id": 2,
"voucher_time":t,
"codes": codes,
"time":t,
"key":m2.hexdigest(),
}
request.method = 'POST'
request._body=json.dumps(postData)
request.META['CONTENT_TYPE']='application/json'
r = fg_update(request)
# 辽宁铁研
if compid == '243885':
xcode = d['boxes']['pk']
data['boxes'] = d['boxes']
if xcode:
cur.execute(f"select to_char(tm,'yyyy-mm-dd HH24:MI:SS') from mes_labelbindhx where carton_code = '"+xcode+"' limit 1")
r = cur.fetchone()
if r and r[0]:
data['bind_tm'] = r[0]
if compid == '189137': if compid == '189137':
r = requests.get('http://www.china315net.com:35222/fjbq/json/'+fwcode+'/') r = requests.get('http://www.china315net.com:35222/fjbq/json/'+fwcode+'/')
...@@ -12987,15 +13017,30 @@ def get_fwcode_by_nfc_code(request): ...@@ -12987,15 +13017,30 @@ def get_fwcode_by_nfc_code(request):
def get_nfc_code_by_label_code(request): def get_nfc_code_by_label_code(request):
data = {'e': '', 'label': ''} data = {'e': '', 'label': ''}
label_code = request.GET.get('label_code', '') label_code = request.GET.get('label_code', '')
userid = int(request.GET.get('userid', '0'))
if label_code: if label_code:
cur = connection.cursor() if userid:
s = f"select nfc from z_labelnfc_details where label = '{label_code}' order by id desc limit 1" u = User.objects.get(id=userid)
cur.execute(s) cur = connection.cursor()
r = cur.fetchone() # 南京海邦需要先查箱绑定的盒码
if r: if u.company_id == 212916:
data['nfc'] = r[0] unbind_codes = []
s = "SELECT box_code, (SELECT count(0) FROM logistics.z_labelnfc_details where label = box_code) FROM logistics.mes_labelbindhx WHERE carton_code = '"+label_code+"' "
cur.execute(s)
rs = cur.fetchall()
for r in rs:
if r[1] == 0:
unbind_codes.append(r[0])
if len(unbind_codes):
data['e'] = '存在未绑数据'
else: else:
data['e'] = '未绑定' s = f"select nfc from z_labelnfc_details where label = '{label_code}' order by id desc limit 1"
cur.execute(s)
r = cur.fetchone()
if r:
data['nfc'] = r[0]
else:
data['e'] = '未绑定'
else: else:
data['e'] = '数据丢失' data['e'] = '数据丢失'
return JsonResponse(data) return JsonResponse(data)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论