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

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

上级 5536f331
...@@ -497,6 +497,15 @@ class Company_UploadFiles_Form(ModelForm): ...@@ -497,6 +497,15 @@ class Company_UploadFiles_Form(ModelForm):
self.fields['category'].queryset = FileCategory.objects.all() 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= ...@@ -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) " "("+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) cur.execute(s)
return JsonResponse(data) 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 = [ ...@@ -1210,7 +1210,14 @@ urlpatterns = [
url(r'^inventory/batchno/details/(?P<batch_id>\d+)/$',inventory_views.cat_batchno_details), 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: if settings.DEBUG:
......
...@@ -14249,3 +14249,111 @@ def process_points_changed(sender, **kwargs): ...@@ -14249,3 +14249,111 @@ def process_points_changed(sender, **kwargs):
return data return data
points_changed.connect(process_points_changed) 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
...@@ -82,7 +82,6 @@ ...@@ -82,7 +82,6 @@
<th style='width:20%'>{% trans "顶级发货信息" %}</th> <th style='width:20%'>{% trans "顶级发货信息" %}</th>
<th style='width:8%'>{% trans "更新时间" %}</th> <th style='width:8%'>{% trans "更新时间" %}</th>
<th style='width:8%'>{% trans "操作人" %}</th> <th style='width:8%'>{% trans "操作人" %}</th>
</tr> </tr>
</thead> </thead>
<tfoot> <tfoot>
...@@ -93,9 +92,8 @@ ...@@ -93,9 +92,8 @@
<th><input type="text" placeholder="{% trans "操作人" %}"></th> <th><input type="text" placeholder="{% trans "操作人" %}"></th>
</tfoot> </tfoot>
</table> </table>
</div> </div>
</div>
</div>
......
{% load i18n %}
{% ifequal obj 'Award' %}
<style>
#tb tbody td img{
height:30px;
cursor:pointer;
}
</style>
{% endifequal %}
<style>
.word-wrap{
width: 100%;white-space: normal;word-wrap: break-word;word-break: break-all;
}
.ant-tag-success {
color : #52c41a !important;
background: #f6ffed !important;
border-color: #b7eb8f;
}
.ant-tag-orange {
color: #d46b08 !important;
background: #fff7e6 !important;
border-color: #ffd591;
}
.ant-tag-error {
color: #ff4d4f !important;
background: #fff2f0 !important;
border-color: #ffccc7;
}
.ant-tag-warning {
color: #faad14 !important;
background: #fffbe6 !important;
border-color: #ffe58f;
}
.ant-tag-default {
}
.ant-tag {
box-sizing: border-box;
margin: 0 8px 0 0;
color: #000000d9;
font-size: 14px;
font-variant: tabular-nums;
line-height: 1.5715;
list-style: none;
font-feature-settings: "tnum";
display: inline-block;
height: auto;
padding: 0 7px;
font-size: 12px;
line-height: 20px;
white-space: nowrap;
background: #fafafa;
border: 1px solid #d9d9d9;
border-radius: 2px;
opacity: 1;
transition: all .3s;
}
</style>
<script type="text/javascript">
$(document).ready(function(){
var page_length=10;
var table=$('#tb').DataTable({
dom: 'Bfrtip',
autoWidth: true,
pageLength: page_length,
buttons: [{extend:'excelHtml5',text: '导出到Excel'}],
language:lng,
{# {% if days %}#}
{# columnDefs:[{#}
{# "targets":4,#}
{# "createdCell": function (td, cellData, rowData, row, col) {#}
{#var x = cellData.split(">")[1].split("<")[0];#}
{# var color = cellData.split("-")[1];#}
{##}
{#$(td).parent().css('background', color);#}
{# }#}
{# }],#}
{# {% endif %}#}
{% if order %}
order: {{order|safe}},
{% endif %}
data:{{data|safe}}
});
table.columns().every( function () {
var that = this;
$('input', this.footer() ).on( 'keyup change clear', function () {
if ( that.search() !== this.value ) {
that.search( this.value ).draw();
}
});
});
//$('#data-content').on("click", ".btn-obj-add", function () {
//});
$(".btn-obj-add").click(function () {
event.preventDefault();
$.RefreshContent($(this).attr('href'));
})
$('#tb').on("click","td a",function(event){
event.preventDefault();
if($(this).hasClass('btn-dlg')){
$.OpenDlg($(this).attr('href'),'信息弹窗',1000,700);
return;
}
$.RefreshContent($(this).attr('href'));
});
$('#tb tbody').on('click','img',function(){
var src=$(this).attr('src');
var tt=$(this).closest('tr').find('a').text();
if(tt==''){
tt=$(this).attr('tt');
};
var i="<div style='text-align:center;'><img src='"+src+"' style='height:400px;'></img></div>";
$.OpenCfmDlg(tt,i);
});
{% if dt %}
$('.datepicker').datepicker({dateFormat: 'yy-mm-dd'});
$('.datepicker').datepicker('setDate',new Date());
setDatePickerZh();
$('#dt_fr').val('{{date_from}}');
$('#dt_to').val('{{date_to}}');
$('.btn-qry').click(function(){
var date_from,date_to;
date_fr=$('#dt_fr').val();
date_to=$('#dt_to').val();
var params=[];
if(date_fr!=''){params.push('date_from='+date_fr)};
if(date_to!=''){params.push('date_to='+date_to)};
if(params.length==0){
bootbox.alert("{% trans '请先输入查询条件!'%}");
}else{
$.RefreshContent('{{request.path}}?'+params.join('&'));
}
});
{% endif %}
//2020-11-07
$("[data-toggle='popover']").popover({
html:true,
placement:'bottom'
});
$('.btn-dlg').off('click')
$('.btn-dlg').click(function(event){
$(event.target.parentNode).addClass('row_selected');
event.preventDefault();
$.OpenDlg($(this).attr('href'),'信息弹窗',1000,700);
//$.RefreshContent($(this).attr('href'));
//return false;
//$("#dlgDiv").dialog("open")
});
$('.btn-photo').click(function(){
var src=$(this).data('src');
var i="<div style='text-align:center;'><img src='"+src+"' style='height:400px;'></img></div>";
$.OpenCfmDlg('图片',i);
});
});
function deleteItem(id){
var r = confirm('您确定要删除吗?');
if(r){
var durl = '{{request.path}}delete/'+id+'/'
$.RefreshContent(durl);
}
}
function deleteObj(obj, id) {
var r = confirm('您确定要删除吗?');
if(r) {
$.ajax({
url: `/obj/delete/${obj}/${id}/`,
success: function(res) {
if(res.e == '') {
$.RefreshContent('{{request.path}}');
}
}
})
}
}
function catPointsDetails(cid){
$.ajax({
url:'/company/bonusPoints/edit_list/'+cid+'/',
success:function (res){
console.log(res)
var batch_tb = $('#batch_tb').DataTable({
//"lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
//"bLengthChange":true,
dom: 'Bfrtip',
autoWidth: false,
destroy:true,
buttons: [{extend:'excelHtml5',text:'导出到Excel'}],
language:lng,
data:res.data
});
$('#modal1').modal('show')
}
})
}
</script>
<ol class="breadcrumb">
<li>{{subtt.0}}</li>
<li>{{subtt.1}}</li>
</ol>
{% if show_add %}
<div class="title_right">
<div class="pull-right">
<span class='input-group'>
<a type="button" class='btn btn-obj-add l-a create-btn' href='{{murl}}'>
<span class='glyphicon glyphicon-plus' style='padding-right:5px;'></span>{% trans '新建' %}
</a>
</span>
</div>
</div>
{% endif %}
{% if dt %}
<form role="form" class="form-inline" style="margin-top:0px;padding-left:10px;">
<div class="col-sm-2 input-group">
<span class="input-group-addon">{% trans "开始日期"%}</span>
<input class="datepicker form-control" id="dt_fr" />
</div>
<div class="col-sm-2 input-group">
<span class="input-group-addon">{% trans "结束日期"%}</span>
<input class="datepicker form-control" id="dt_to" />
</div>
<div class="col-sm-2 input-group">
<span class='input-group-btn'>
<a type="button" class='btn btn-primary btn-qry'>
<span class='glyphicon glyphicon-search' style='padding-right:5px;'></span>{% trans '查找' %}
</a>
</span>
</div>
</form>
<div class="clearfix"></div>
{% endif %}
{% if btn_name %}
<div class="title_right">
<div class="pull-right">
<span class='input-group'>
<a type="button" class='btn btn-obj-add l-a create-btn' href='{{btn_url}}'>
<span class='glyphicon glyphicon-search' style='padding-right:5px;'></span>{% trans btn_name %}
</a>
</span>
</div>
</div>
{% endif %}
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="x_panel">
<div class="table-responsive">
<table id='tb' class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
<thead>
{% for c in clmns %}
<th>{{c}}</th>
{% endfor %}
</thead>
<tbody></tbody>
<tfoot>
{% for c in clmns %}
<th><input type="text" placeholder="{{c}}"></th>
{% endfor %}
</tfoot>
</table>
</div>
</div>
</div>
<div class="modal fade" tabindex="-1" role="dialog" id="modal1">
<div class="modal-dialog" role="document" >
<div class="modal-content" style="width: 600px;">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
</button>
<h4 class="modal-title">批次详情</h4>
</div>
<div class="modal-body">
<table id="batch_tb" class="table table-striped table-bordered dt-responsive" width="100%" >
<thead>
<tr>
<th style='width:10%'>{% trans "来源类型" %}</th>
<th style='width:10%'>{% trans "收货/发货" %}</th>
<th style='width:8%'>{% trans "积分" %}</th>
<th style='width:15%'>{% trans "更新时间" %}</th>
</tr>
</thead>
<tbody></tbody>
<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>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论