提交 805c57af authored 作者: 蒋代伟's avatar 蒋代伟

诗仙太白积分报表 积分提现扣减

上级 5536f331
......@@ -497,6 +497,15 @@ class Company_UploadFiles_Form(ModelForm):
self.fields['category'].queryset = FileCategory.objects.all()
class BonusPoints_Form(ModelForm):
class Meta:
model=BonusPoints
fields = ['points','remark']
def __init__(self, *args, **kwargs):
self._user = kwargs.pop('user')
super(BonusPoints_Form, self).__init__(*args, **kwargs)
self.fields['points'].queryset = BonusPoints.objects.filter(company_id=self._user.company.id)
......@@ -7453,3 +7453,109 @@ def request_rebate_points(obj,channelpromotions_id,selef_p_ratio,parent_p_ratio=
"("+str(c.ancestor_id)+","+str(r[0])+",now(),"+str(c.id)+","+str(channelpromotions_id)+") on conflict(company_id) do update set points = (EXCLUDED.points + a.points) "
cur.execute(s)
return JsonResponse(data)
# 当前积分
@login_required
def bonusPoints(request):
data = {'data': [], 'clmns': [], 'e': [],
'subtt': ['渠道促销', '积分'], 'murl': '', 'dt': False, 'add': True}
data['clmns'] = ['当前积分', '父级公司名字', '经销商名字', '备注', '更新时间', '积分变化明细']
data['show_add'] = False
data['murl'] = '/company/bonusPoints/edit/'
cur = connection.cursor()
company_id = request.user.company_id
ancestor_id = request.user.ancestor_id
if ancestor_id == company_id:
bps = BonusPoints.objects.filter(ancestor_id=ancestor_id)
else:
bps = BonusPoints.objects.filter(company_id=company_id)
for t in bps:
remark = t.remark
if not t.remark:
remark = ""
s = f"""select name,(select name from company_company where id={t.company_id})
from company_company where id={t.ancestor_id}
"""
cur.execute(s)
r = cur.fetchone()
btn = '<button style="margin:0;padding:1px 10px;" onclick="catPointsDetails('+str(t.company_id)+')" class="update btn btn-sm btn-warning">详情</button>'
data['data'].append([
"<a href='/company/bonusPoints/edit/" +
str(t.id) + "/'>" + str(t.points) + "</a>",
r[0], r[1],
remark,
t.tm.strftime("%Y-%m-%d %H:%M:%S"),
# "<a class='btn btn-default btn-xs' href='company/bonusPoints/edit_list/" + str(t.id) + "/'>详情</a>"
btn
])
return render(request, 'obj/list_points.html', data)
# 积分编辑
@login_required
def bonusPoints_edit(request, id=None):
if id:
obj = BonusPoints.objects.get(id=int(id))
else:
obj = BonusPoints(company_id=request.user.company_id)
if request.method == 'GET':
form = BonusPoints_Form(instance=obj, user=request.user)
else:
form = BonusPoints_Form(request.POST, instance=obj, user=request.user)
if form.is_valid():
form.save()
return render(request, 'company/points.html', {'form': form})
@login_required
def bonusPoints_edit_list(request, cid, type=None):
data = {'data': [], 'e': [],}
cur = connection.cursor()
# for t in BonusPointsLog.objects.filter(company_id=request.user.company_id):
#
# b = []
# if t.parent_points == b:
# s = f""" select (select name from company_company where {t.company_id}=id),
# (select last_name from company_user where {t.user_id}=id) from company_BonusPointsLog b where company_id={t.company_id}
# """
# print("s1",s)
# cur.execute(s)
# r = cur.fetchone()
# data['data'].append(
# [r[0], str(t.self_points), t.parent_points, t.tm.strftime("%Y-%m-%d %H:%M:%S"), r[1]])
# else:
# list = []
# for r in t.parent_points:
# aa = r["points"]
#
#
# s = f""" select (select name from company_company where {t.company_id}=id),(select name from company_company where {r["company_fr_id"]}=id),
# (select last_name from company_user where {t.user_id}=id) from company_BonusPointsLog b where company_id={t.company_id}
# """
# print("s2", s)
# cur.execute(s)
# r = cur.fetchone()
# if r:
# list.append(r[1]+"|<b>"+str(aa)+"</b>")
#
# data['data'].append([r[0], str(t.self_points), list, t.tm.strftime("%Y-%m-%d %H:%M:%S"), r[2]])
# # data['data'] = SafeString(data['data'])
# print(data)
s = "SELECT * from (SELECT * from (select '发货所得'::text as act,case contenttype_id when 19 then '收货确认' when '320' then '宴会申请' else'未知' end, " + \
"to_char(tm,'yyyy-mm-dd HH24:MI:SS'),jsonb_array_elements(parent_points )->> 'points' as points , jsonb_array_elements(parent_points )->> 'company_fr_id'as company_fr_id from " + \
" logistics.company_bonuspointslog where parent_points @>'[{\"company_fr_id\":" + str(
cid) + "}]' ) a where a.company_fr_id = '" + str(cid) + "' " + \
" union SELECT '收货所得'::text as act, case contenttype_id when 19 then '收货确认' when '320' then '宴会申请' else'未知' end, " + \
"to_char(tm,'yyyy-mm-dd HH24:MI:SS'),cast(self_points as TEXT) points,cast(company_id as TEXT) from logistics.company_bonuspointslog where company_id = " + str(
cid) + " and self_points is not null and self_points> 0 )m " +\
"left outer join (SELECT name ,id from company_company )z on z.id = m.company_fr_id::int"
cur.execute(s)
r = cur.fetchall()
for i in r :
data['data'].append([ i[1],i[0],i[3],i[2]])
return JsonResponse(data)
\ No newline at end of file
......@@ -1210,7 +1210,14 @@ urlpatterns = [
url(r'^inventory/batchno/details/(?P<batch_id>\d+)/$',inventory_views.cat_batchno_details),
#用户积分信息
url(r'^company/bonuspoints/infor/(?P<comapny_id>\d+)/$',company_views.bonuspoints_infor)
url(r'^company/bonuspoints/infor/(?P<comapny_id>\d+)/$',company_views.bonuspoints_infor),
url(r'^company/sxtb/rebate/wx_withdraw/$', inventory_views.wx_withdraw_cash),
# 诗仙太白积分活动
url(r'^company/bonusPoints/$', company_views.bonusPoints),
url(r'^company/bonusPoints/edit/$', company_views.bonusPoints_edit),
url(r'^company/bonusPoints/edit/(?P<id>\d+)/$', company_views.bonusPoints_edit),
url(r'^company/bonusPoints/edit_list/(?P<cid>\d+)/$', company_views.bonusPoints_edit_list),
]
if settings.DEBUG:
......
......@@ -14249,3 +14249,111 @@ def process_points_changed(sender, **kwargs):
return data
points_changed.connect(process_points_changed)
@csrf_exempt
def bonuspoints_infor(request,comapny_id):
data = {'e': '', 'info': [],'details':[],'total':0}
k = sK
e = time_key_check(request, k)
if e:
data['e'] = e
return JsonResponse(data)
dt_fr = request.GET.get('dt_fr','')
dt_to = request.GET.get('dt_to',now())
cur= connection.cursor()
sDt = " and (dt BETWEEN'"+dt_fr+"'and '"+dt_to+"') "
#查询是否有积分信息
s = "SELECT b.name,b.point_ratio,a.points,a.ancestor_id FROM (select points,channelpromotions_id,ancestor_id from company_bonuspoints where company_id = "+str(comapny_id)+")A "+\
"left outer join (select id,point_ratio,name from sales_channelpromotions )B "+\
"on b.id = a.channelpromotions_id"
cur.execute(s)
r = cur.fetchone()
if r:
data['info']={"name":r[0],"point":r[2],"ratio":r[1]}
s = "SELECT * from (select (select name from sales_channelpromotions where id = channelpromotions_id),case contenttype_id when 19 then '收货确认' when '320' then '宴会申请' else'未知' end, " + \
"to_char(tm,'yyyy-mm-dd HH24:MI:SS'),jsonb_array_elements(parent_points )->> 'points' as points , jsonb_array_elements(parent_points )->> 'company_fr_id'as company_fr_id from " + \
" logistics.company_bonuspointslog where parent_points @>'[{\"company_fr_id\":" + str(
comapny_id) + "}]' " + sDt + ") a where a.company_fr_id = '" + str(comapny_id) + "' " + \
" union SELECT (select name from sales_channelpromotions where id = channelpromotions_id),case contenttype_id when 19 then '收货确认' when '320' then '宴会申请' else'未知' end, " + \
"to_char(tm,'yyyy-mm-dd HH24:MI:SS'),cast(self_points as TEXT) points,cast(company_id as TEXT) from logistics.company_bonuspointslog where company_id = " + str(
comapny_id) + " and self_points is not null and self_points> 0 " + sDt
cur.execute(s)
res = cur.fetchall()
if res:
for re in res:
data['details'].append({"activity_name":re[0],"event_name":re[1],"dt":re[2], "points":re[3]})
# 返回总金额
s = "SELECT sum(amount) from logistics.company_pointsredeemed where company_id = " + str(comapny_id) + " and ancestor_id = " + str(r[3]) + ";"
cur.execute(s)
totals = cur.fetchone()
if totals[0]:
data['total'] = totals[0]
else:
data['e'] = '暂无积分信息'
return JsonResponse(data)
from django.db import transaction
# @transaction.atomic
@csrf_exempt
def wx_withdraw_cash(request):
data={'e':''}
k = sK
e = time_key_check(request, k)
# if e:
# data['e'] = e
# return JsonResponse(data)
cur = connection.cursor()
if request.method =='GET':
pass
else:
r = json.loads(request.body)
c_id = r["company_id"]
open_id = r['open_id']
user_id = r['user_id']
amount = r['amount']
s = "SELECT b.name,b.point_ratio,a.points,a.ancestor_id,a.channelpromotions_id FROM " +\
"(select points,channelpromotions_id,ancestor_id from company_bonuspoints " +\
"where company_id = " + str(c_id) + ")A " +\
" left outer join (select id,point_ratio,name from sales_channelpromotions )B " + \
"on b.id = a.channelpromotions_id"
cur.execute(s)
r = cur.fetchone()
if r:
de_points = int(amount) * r[1]
# 核对当前积分知否足够提现该次金额
if de_points > r[2]:
data['e']="积分不足"
return JsonResponse(data)
# 事务
try:
with transaction.atomic():
# 扣除积分
s = "update logistics.company_bonuspoints set points = ( points - "+str(de_points)+") where company_id = "+ str(c_id)
cur.execute(s)
# 积分以及积分人写入积分日志表
pr = PointsRedeemed(ancestor_id = r[3],company_id=c_id,user_id=user_id,points=de_points,amount=amount,
remark="提现积分扣除")
pr.save()
bp = BonusPointsLog(ancestor_id=r[3], company_id=c_id, user_id=user_id,
channelpromotions_id=r[4], content_object=pr,
object_id=pr.id, self_points=-de_points, remark="提现积分扣除")
bp.save()
# i = 1/0
# 提现
except:
# 发生错误时回滚
data['e']="未知错误"
finally:
# 返回总金额
s = "SELECT sum(amount) from logistics.company_pointsredeemed where company_id = "+str(c_id)+" and ancestor_id = "+str(r[3])+";"
cur.execute(s)
totals = cur.fetchone()
if totals:
data['total']= totals[0]
return JsonResponse(data)
\ No newline at end of file
......@@ -75,27 +75,25 @@
<div id="inventory-list" class="table-responsive">
<div class='x_panel'>
<table id="tb-dlgs" class="table table-striped table-bordered dt-responsive" width="100%">
<thead>
<tr>
<th style='width:12%'>{% trans "收货公司" %}</th>
<th style='width:8%'>{% trans "收货获得积分" %}</th>
<th style='width:20%'>{% trans "顶级发货信息" %}</th>
<th style='width:8%'>{% trans "更新时间" %}</th>
<th style='width:8%'>{% trans "操作人" %}</th>
</tr>
</thead>
<tfoot>
<th><input type="text" placeholder="{% trans "收货公司" %}"></th>
<th><input type="text" placeholder="{% trans "收货获得积分" %}"></th>
<th><input type="text" placeholder="{% trans "顶级发货信息" %}"></th>
<th><input type="text" placeholder="{% trans "更新时间" %}"></th>
<th><input type="text" placeholder="{% trans "操作人" %}"></th>
</tfoot>
</table>
</div>
</div>
<thead>
<tr>
<th style='width:12%'>{% trans "收货公司" %}</th>
<th style='width:8%'>{% trans "收货获得积分" %}</th>
<th style='width:20%'>{% trans "顶级发货信息" %}</th>
<th style='width:8%'>{% trans "更新时间" %}</th>
<th style='width:8%'>{% trans "操作人" %}</th>
</tr>
</thead>
<tfoot>
<th><input type="text" placeholder="{% trans "收货公司" %}"></th>
<th><input type="text" placeholder="{% trans "收货获得积分" %}"></th>
<th><input type="text" placeholder="{% trans "顶级发货信息" %}"></th>
<th><input type="text" placeholder="{% trans "更新时间" %}"></th>
<th><input type="text" placeholder="{% trans "操作人" %}"></th>
</tfoot>
</table>
</div>
</div>
......
差异被折叠。
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论