Skip to content

Commit

Permalink
better node qrcode
Browse files Browse the repository at this point in the history
  • Loading branch information
Ehco1996 committed Feb 26, 2019
1 parent 6f20afa commit 5591841
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 145 deletions.
24 changes: 9 additions & 15 deletions apps/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ def gen_invite_code(request):
"status": "success",
}
else:
registerinfo = {"title": "失败",
"subtitle": "已经不能生成更多的邀请码了", "status": "error"}
registerinfo = {"title": "失败", "subtitle": "已经不能生成更多的邀请码了", "status": "error"}
return JsonResponse(registerinfo)


Expand Down Expand Up @@ -161,8 +160,7 @@ def change_theme(request):
user = request.user
user.theme = theme
user.save()
registerinfo = {"title": "修改成功!",
"subtitle": "主题更换成功,刷新页面可见", "status": "success"}
registerinfo = {"title": "修改成功!", "subtitle": "主题更换成功,刷新页面可见", "status": "success"}
return JsonResponse(registerinfo)


Expand All @@ -177,8 +175,7 @@ def get_invitecode(request):
需要验证token
"""
admin_user = User.objects.filter(is_superuser=True).first()
code = InviteCode.objects.filter(
code_id=admin_user.pk, isused=False).first()
code = InviteCode.objects.filter(code_id=admin_user.pk, isused=False).first()
if code:
return JsonResponse({"msg": code.code})
else:
Expand Down Expand Up @@ -290,8 +287,7 @@ def alive_ip_api(request):
for user_id, ip_list in data["data"].items():
user = User.objects.get(id=user_id)
for ip in ip_list:
model_list.append(
AliveIp(node_id=node_id, user=user.username, ip=ip))
model_list.append(AliveIp(node_id=node_id, user=user.username, ip=ip))
AliveIp.objects.bulk_create(model_list)
res = {"ret": 1, "data": []}
return JsonResponse(res)
Expand Down Expand Up @@ -320,11 +316,11 @@ def ailpay_callback(request):
signature = data.pop("sign")
success = pay.alipay.verify(data, signature)
if success and data["trade_status"] in ("TRADE_SUCCESS", "TRADE_FINISHED"):
order = UserOrder.objects.get(out_trade_no=data['out_trade_no'])
order = UserOrder.objects.get(out_trade_no=data["out_trade_no"])
order.handle_paid()
return HttpResponse('success')
return HttpResponse("success")
else:
return HttpResponse('failure')
return HttpResponse("failure")


class OrderView(View):
Expand All @@ -333,11 +329,9 @@ def get(self, request):
order = UserOrder.get_recent_created_order(user)
order.check_order_status()
if order and order.status == UserOrder.STATUS_FINISHED:
info = {"title": "充值成功!",
"subtitle": "请去商品界面购买商品!", "status": "success"}
info = {"title": "充值成功!", "subtitle": "请去商品界面购买商品!", "status": "success"}
else:
info = {"title": "支付查询失败!",
"subtitle": "亲,确认支付了么?", "status": "error"}
info = {"title": "支付查询失败!", "subtitle": "亲,确认支付了么?", "status": "error"}
return JsonResponse({"info": info})

def post(self, request):
Expand Down
12 changes: 3 additions & 9 deletions apps/sspanel/migrations/0005_auto_20190224_0625.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,9 @@

class Migration(migrations.Migration):

dependencies = [
('sspanel', '0004_auto_20190222_2209'),
]
dependencies = [("sspanel", "0004_auto_20190222_2209")]

operations = [
migrations.DeleteModel(
name='PayRecord',
),
migrations.DeleteModel(
name='PayRequest',
),
migrations.DeleteModel(name="PayRecord"),
migrations.DeleteModel(name="PayRequest"),
]
35 changes: 12 additions & 23 deletions apps/sspanel/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ class User(AbstractUser):
default=0,
validators=[MaxValueValidator(9), MinValueValidator(0)],
)
level_expire_time = models.DateTimeField(
verbose_name="等级有效期", default=timezone.now)
level_expire_time = models.DateTimeField(verbose_name="等级有效期", default=timezone.now)
theme = models.CharField(
verbose_name="主题",
choices=THEME_CHOICES,
Expand All @@ -67,8 +66,7 @@ def get_total_user_num(cls):
@classmethod
def get_today_register_user(cls):
"""返回今日注册的用户"""
today = datetime.datetime.combine(
datetime.date.today(), datetime.time.min)
today = datetime.datetime.combine(datetime.date.today(), datetime.time.min)
return cls.objects.filter(date_joined__gt=today)

@classmethod
Expand Down Expand Up @@ -106,7 +104,7 @@ def sub_link(self):
"""生成该用户的订阅地址"""
p = PreparedRequest()
token = base64.b64encode(self.username.encode()).decode()
url = settings.HOST + "server/subscribe/"
url = settings.HOST + "/server/subscribe/"
params = {"token": token}
p.prepare_url(url, params)
return p.url
Expand Down Expand Up @@ -190,8 +188,7 @@ def richPeople(cls):
return sorted(rec.items(), key=lambda rec: rec[1], reverse=True)[:10]

"""捐赠记录"""
user = models.ForeignKey(
User, on_delete=models.CASCADE, verbose_name="捐赠人")
user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name="捐赠人")
time = models.DateTimeField("捐赠时间", editable=False, auto_now_add=True)
money = models.DecimalField(
verbose_name="捐赠金额",
Expand All @@ -213,8 +210,7 @@ class Meta:
class MoneyCode(models.Model):
"""充值码"""

user = models.CharField(
verbose_name="用户名", max_length=128, blank=True, null=True)
user = models.CharField(verbose_name="用户名", max_length=128, blank=True, null=True)
time = models.DateTimeField("捐赠时间", editable=False, auto_now_add=True)
code = models.CharField(
verbose_name="充值码",
Expand Down Expand Up @@ -255,10 +251,8 @@ class Goods(models.Model):
STATUS_TYPE = ((1, "上架"), (-1, "下架"))

name = models.CharField(verbose_name="商品名字", max_length=128, default="待编辑")
content = models.CharField(
verbose_name="商品描述", max_length=256, default="待编辑")
transfer = models.BigIntegerField(
verbose_name="增加的流量", default=settings.GB)
content = models.CharField(verbose_name="商品描述", max_length=256, default="待编辑")
transfer = models.BigIntegerField(verbose_name="增加的流量", default=settings.GB)
money = models.DecimalField(
verbose_name="金额",
decimal_places=2,
Expand Down Expand Up @@ -321,8 +315,7 @@ def purchase_by_user(self, user):
inviter = User.objects.filter(pk=user.invited_by).first()
if inviter:
rebaterecord = RebateRecord(
user_id=inviter.pk, money=self.money
* Decimal(settings.INVITE_PERCENT)
user_id=inviter.pk, money=self.money * Decimal(settings.INVITE_PERCENT)
)
inviter.balance += rebaterecord.money
inviter.save()
Expand All @@ -333,8 +326,7 @@ def purchase_by_user(self, user):
class PurchaseHistory(models.Model):
"""购买记录"""

good = models.ForeignKey(
Goods, on_delete=models.CASCADE, verbose_name="商品名")
good = models.ForeignKey(Goods, on_delete=models.CASCADE, verbose_name="商品名")
user = models.CharField(verbose_name="购买者", max_length=128)
money = models.DecimalField(
verbose_name="金额",
Expand Down Expand Up @@ -398,8 +390,7 @@ class Ticket(models.Model):

TICKET_CHOICE = ((1, "开启"), (-1, "关闭"))
user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name="用户")
time = models.DateTimeField(
verbose_name="时间", editable=False, auto_now_add=True)
time = models.DateTimeField(verbose_name="时间", editable=False, auto_now_add=True)
title = models.CharField(verbose_name="标题", max_length=128)
body = models.TextField(verbose_name="内容主体")
status = models.SmallIntegerField(
Expand Down Expand Up @@ -433,8 +424,7 @@ class UserOrder(models.Model):
out_trade_no = models.CharField(
verbose_name="流水号", max_length=64, unique=True, db_index=True
)
qrcode_url = models.CharField(
verbose_name="支付连接", max_length=64, null=True)
qrcode_url = models.CharField(verbose_name="支付连接", max_length=64, null=True)
amount = models.DecimalField(
verbose_name="金额", decimal_places=2, max_digits=10, default=0
)
Expand Down Expand Up @@ -514,8 +504,7 @@ def check_order_status(self):
if self.status != self.STATUS_CREATED:
return
with transaction.atomic():
res = pay.alipay.api_alipay_trade_query(
out_trade_no=self.out_trade_no)
res = pay.alipay.api_alipay_trade_query(out_trade_no=self.out_trade_no)
if res.get("trade_status", "") == "TRADE_SUCCESS":
self.status = self.STATUS_PAID
self.save()
Expand Down
3 changes: 0 additions & 3 deletions apps/sspanel/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
# 用户信息
path("users/userinfo/", views.userinfo, name="userinfo"),
path("users/userinfoedit/", views.userinfo_edit, name="userinfo_edit"),
# 二维码
path("qrcode/ssr/<node_id>/", views.get_ssr_qrcode, name="ssrqrcode"),
path("qrcode/ss/<node_id>/", views.get_ss_qrcode, name="ssqrcode"),
# 捐赠/充值
path("donate/", views.donate, name="donate"),
path("shop/", views.shop, name="shop"),
Expand Down
46 changes: 0 additions & 46 deletions apps/sspanel/views.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import tomd
import qrcode

from django.db.models import Q
from django.urls import reverse
from django.conf import settings
from django.shortcuts import render
from django.contrib import messages
from django.utils.six import BytesIO
from django.http import HttpResponse, HttpResponseRedirect
from django.contrib.auth import authenticate, login, logout
from django.contrib.auth.decorators import login_required, permission_required
Expand Down Expand Up @@ -138,50 +136,6 @@ def userinfo(request):
return render(request, "sspanel/userinfo.html", context=context)


@login_required
def get_ssr_qrcode(request, node_id):
"""返回节点配置信息的ssr二维码"""

# 获取用户对象
ss_user = request.user.ss_user
user = request.user
# 获取节点对象
node = Node.objects.get(node_id=node_id)
# 加入节点信息等级判断
if user.level < node.level:
return HttpResponse("哟小伙子,可以啊!但是投机取巧是不对的哦!")
ssr_link = node.get_ssr_link(ss_user)
ssr_img = qrcode.make(ssr_link)
buf = BytesIO()
ssr_img.save(buf)
image_stream = buf.getvalue()
# 构造图片reponse
response = HttpResponse(image_stream, content_type="image/png")
return response


@login_required
def get_ss_qrcode(request, node_id):
"""返回节点配置信息的ss二维码"""

# 获取用户对象
ss_user = request.user.ss_user
user = request.user
# 获取节点对象
node = Node.objects.get(node_id=node_id)
# 加入节点信息等级判断
if user.level < node.level:
return HttpResponse("哟小伙子,可以啊!但是投机取巧是不对的哦!")
ss_link = node.get_ss_link(ss_user)
ss_img = qrcode.make(ss_link)
buf = BytesIO()
ss_img.save(buf)
image_stream = buf.getvalue()
# 构造图片reponse
response = HttpResponse(image_stream, content_type="image/png")
return response


@login_required
def userinfo_edit(request):
"""跳转到资料编辑界面"""
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ django-jet
Markdown
Pillow
python-alipay-sdk
qrcode
requests
tomd
uWSGI
Expand Down
Loading

0 comments on commit 5591841

Please sign in to comment.