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

新增消费者助力活动接口,修改门店打卡接口必填字段判断

上级 e1fe3937
# Generated by Django 3.1.4 on 2023-07-19 16:17
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('company', '0327_terminalregister_parent_user'),
('sales', '0340_lotteryseeds_is_terminal_rebate'),
]
operations = [
migrations.AddField(
model_name='activityawards',
name='help_num',
field=models.IntegerField(default=0, verbose_name='助力次数'),
preserve_default=False,
),
migrations.CreateModel(
name='ConsumerHelp',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('award_name', models.CharField(blank=True, max_length=200, null=True, verbose_name='奖品名称')),
('label_code', models.CharField(blank=True, db_index=True, max_length=20, null=True, verbose_name='标签号码')),
('dt', models.DateField(auto_now_add=True, db_index=True, verbose_name='日期')),
('tm', models.DateTimeField(auto_now_add=True, verbose_name='时间')),
('activity', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='sales.activities', verbose_name='活动名称')),
('award', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='sales.activityawards', verbose_name='奖品')),
('company', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='company.company', verbose_name='公司名称')),
('consumer', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='sales.consumeraccount', verbose_name='消费者帐号')),
],
options={
'verbose_name': '消费者助力记录',
'verbose_name_plural': '消费者助力记录',
},
),
]
...@@ -385,6 +385,8 @@ class ActivityAwards(models.Model): ...@@ -385,6 +385,8 @@ class ActivityAwards(models.Model):
# 2023-05-30 当前奖项对终端返利金额/点值 # 2023-05-30 当前奖项对终端返利金额/点值
terminal_rebate=models.DecimalField(_('消费者扫码返终端'), max_digits=12, decimal_places=2, blank=True, null=True) terminal_rebate=models.DecimalField(_('消费者扫码返终端'), max_digits=12, decimal_places=2, blank=True, null=True)
# 2023-07-19 达到该助力次数后中奖
help_num = models.IntegerField(_('助力次数'))
#terminal_scan_amt=models.DecimalField(_('终端扫码返利'), max_digits=12, decimal_places=2, blank=True, null=True) #terminal_scan_amt=models.DecimalField(_('终端扫码返利'), max_digits=12, decimal_places=2, blank=True, null=True)
...@@ -2264,11 +2266,18 @@ class ChannelRebateAccumulation(models.Model): ...@@ -2264,11 +2266,18 @@ class ChannelRebateAccumulation(models.Model):
verbose_name = _("消费者扫码累计返利") verbose_name = _("消费者扫码累计返利")
verbose_name_plural = _("消费者扫码累计返利)") verbose_name_plural = _("消费者扫码累计返利)")
class ConsumerHelp(models.Model):
company = models.ForeignKey('company.Company', verbose_name=_('公司名称'), on_delete=models.CASCADE)
activity = models.ForeignKey(Activities, verbose_name=_('活动名称'), on_delete=models.SET_NULL,blank=True,null=True)
award = models.ForeignKey(ActivityAwards, verbose_name=_('奖品'), on_delete=models.SET_NULL,blank=True,null=True)
award_name = models.CharField(_('奖品名称'), max_length=200,blank=True,null=True)
consumer = models.ForeignKey(ConsumerAccount, verbose_name=_('消费者帐号'), on_delete=models.SET_NULL,blank=True,null=True)
label_code = models.CharField(_('标签号码'), max_length=20,db_index=True,blank=True,null=True)
dt = models.DateField(_('日期'), auto_now_add=True, db_index=True)
tm = models.DateTimeField(_('时间'), auto_now_add=True)
class Meta:
verbose_name = _("消费者助力记录")
verbose_name_plural = _("消费者助力记录")
# 2023-05-31 消费者中奖后需要执行的额外操作 # 2023-05-31 消费者中奖后需要执行的额外操作
def consumerwinner_hit(winner): def consumerwinner_hit(winner):
......
...@@ -4912,7 +4912,7 @@ def wx_salesmanCallOn(request): ...@@ -4912,7 +4912,7 @@ def wx_salesmanCallOn(request):
report = request.POST.get('report', '') report = request.POST.get('report', '')
lng_lat = lng_lat.split(',') lng_lat = lng_lat.split(',')
if not uid or not lng_lat or not terminal_id or not report: if not uid or not lng_lat or not terminal_id:
return JsonResponse({'e': 'lack of parameters'}) return JsonResponse({'e': 'lack of parameters'})
c = Company.objects.filter(id=terminal_id) c = Company.objects.filter(id=terminal_id)
...@@ -11412,3 +11412,87 @@ def channelredeem_online(request): ...@@ -11412,3 +11412,87 @@ def channelredeem_online(request):
cur.close() cur.close()
return JsonResponse(data) return JsonResponse(data)
# 2023-07-19
@csrf_exempt
def ajax_consumer_read_share(request):
label_code = request.GET.get('label_code','')
company_id = request.GET.get('company_id','')
consumer_id = request.GET.get('consumer_id','')
if not label_code or not company_id or not consumer_id:
return JsonResponse({'e':'数据丢失'})
data = {'e':''}
if label_code and company_id and consumer_id:
cur = connection.cursor()
# 查询需要助力的用户信息、活动信息
cur.execute(f"""
select
consumer_id,
activity_id,
(select wx_openid from sales_consumeraccount where id = consumer_id),
(select name from sales_activity where id = activity_id)
from
sales_consumerwinner
where
label_code = '{label_code}' and
company_id = {company_id}
order by id
limit 1
""")
rs = cur.fetchall()
if rs:
r = rs[0]
consumer_helped_id = r[0]
activity_id = r[1]
openid = r[2]
activity_name = r[3]
# 查询已助力次数
cur.execute("select count(*) from sales_consumerhelp where label_code = '"+label_code+"'")
help_num = cur.fetchone()[0]
# 寻找这次助力的奖品
activity_award = None
awards = ActivityAwards.objects.filter(activity_id=activity_id,help_num=(help_num+1))
if awards:
activity_award = awards[0]
add_flag = False
if activity_award:
award = activity_award.award
if award.awardcat_id == 4:
money = int(award.amount * 100)
err = send_hb(openid, money, int(company_id))
if err['return_code'] == 'SUCCESS' and err['result_code'] == 'SUCCESS':
w = ConsumerWinner(
company_id=int(company_id),
consumer_id=consumer_helped_id,
label_code=label_code,
activity_id=activity_id,
activity_name=activity_name,
award_id=activity_award.id,
award_name=award.name,
award_amount=award.amount,
original_award=award,
award_cat='微信红包',
tm_redeemed=now()
)
w.save()
add_flag = True
else:
add_flag = True
if add_flag:
ch = ConsumerHelp()
ch.company_id = int(company_id)
ch.activity_id = activity_id
ch.award = activity_award
if activity_award:
ch.award_name = activity_award.name
ch.consumer_id = int(consumer_id)
ch.label_code = label_code
ch.save()
return JsonResponse(data)
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论