优化代码

publicsignpoll
youngS 3 years ago
parent 08ffa72eab
commit 820e1df84e
  1. 9
      fir_ser/api/utils/pay/ali.py
  2. 6
      fir_ser/api/utils/pay/wx.py
  3. 31
      fir_ser/api/utils/serializer.py
  4. 2
      fir_ser/api/utils/storage/caches.py
  5. 4
      fir_ser/api/views/apps.py
  6. 1
      fir_ser/api/views/login.py
  7. 25
      fir_ser/fir_ser/settings.py

@ -13,7 +13,7 @@ from api.utils.storage.caches import update_order_info, update_order_status
import json import json
import logging import logging
logger = logging.getLogger(__name__) logger = logging.getLogger('pay')
class Alipay(object): class Alipay(object):
@ -47,9 +47,10 @@ class Alipay(object):
return_url=self.ali_config.get("RETURN_URL"), return_url=self.ali_config.get("RETURN_URL"),
passback_params=json.dumps(passback_params) passback_params=json.dumps(passback_params)
) )
result = {'type': self.p_type, 'url': "https://openapi.alipay.com/gateway.do?%s" % order_string,
return {'type': self.p_type, 'url': "https://openapi.alipay.com/gateway.do?%s" % order_string, 'out_trade_no': out_trade_no}
'out_trade_no': out_trade_no} logger.info(f"支付宝支付连接生成成功 {result}")
return result
def valid_order(self, request): def valid_order(self, request):
data = request.data.copy().dict() data = request.data.copy().dict()

@ -10,7 +10,7 @@ from api.utils.storage.caches import update_order_info, update_order_status
import json import json
import logging import logging
logger = logging.getLogger(__name__) logger = logging.getLogger('pay')
class Weixinpay(object): class Weixinpay(object):
@ -43,7 +43,9 @@ class Weixinpay(object):
time_expire=time_expire, time_expire=time_expire,
attach=json.dumps(passback_params), attach=json.dumps(passback_params),
) )
return {'type': self.p_type, 'url': json.loads(data).get('code_url', ''), 'out_trade_no': out_trade_no} result = {'type': self.p_type, 'url': json.loads(data).get('code_url', ''), 'out_trade_no': out_trade_no}
logger.info(f"微信支付连接生成成功 {result}")
return result
def valid_order(self, request): def valid_order(self, request):
headers = { headers = {

@ -143,7 +143,7 @@ class AppsSerializer(serializers.ModelSerializer):
def get_has_combo(self, obj): def get_has_combo(self, obj):
if obj.has_combo: if obj.has_combo:
obj.has_combo.has_combo = None obj.has_combo.has_combo = None
return AppsSerializer(obj.has_combo, context=self.context).data return AppsListSerializer(obj.has_combo, context=self.context).data
preview_url = serializers.SerializerMethodField() preview_url = serializers.SerializerMethodField()
@ -206,6 +206,35 @@ class AppsSerializer(serializers.ModelSerializer):
return {} return {}
class AppsListSerializer(AppsSerializer):
class Meta:
model = models.Apps
fields = ["app_id", "bundle_id", "issupersign", "name", "preview_url", "short", "type", "master_release",
"has_combo"]
def get_master_release(self, obj):
master_release_obj = get_app_master_obj_from_context(self, obj)
if master_release_obj:
key = ''
icon_url = get_download_url_from_context(self, obj, key, master_release_obj.icon_url)
datainfo = {
"app_version": master_release_obj.app_version,
"icon_url": icon_url,
"build_version": master_release_obj.build_version,
"binary_size": bytes2human(master_release_obj.binary_size),
"binary_url": master_release_obj.binary_url,
"release_type": master_release_obj.release_type,
}
return datainfo
else:
return {}
def get_has_combo(self, obj):
if obj.has_combo:
obj.has_combo.has_combo = None
return AppsListSerializer(obj.has_combo, context=self.context).data
class AdminAppsSerializer(AppsSerializer): class AdminAppsSerializer(AppsSerializer):
class Meta: class Meta:
model = models.Apps model = models.Apps

@ -443,7 +443,7 @@ def update_order_info(user_id, out_trade_no, payment_number, payment_type):
order_obj.description = "充值成功,充值下载次数 %s ,现共可用次数 %s" % ( order_obj.description = "充值成功,充值下载次数 %s ,现共可用次数 %s" % (
download_times, user_obj.download_times + download_times) download_times, user_obj.download_times + download_times)
order_obj.save( order_obj.save(
update_fields=["status", "payment_type", "order_type", "payment_number", "pay_time", update_fields=["status", "payment_type", "payment_number", "pay_time",
"description"]) "description"])
add_user_download_times(user_id, download_times) add_user_download_times(user_id, download_times)
logger.info(f"{user_obj} 订单 {out_trade_no} msg:{order_obj.description}") logger.info(f"{user_obj} 订单 {out_trade_no} msg:{order_obj.description}")

@ -15,7 +15,7 @@ from api.utils.app.supersignutils import IosUtils
from api.utils.storage.storage import Storage from api.utils.storage.storage import Storage
from api.utils.storage.caches import del_cache_response_by_short, get_app_today_download_times, del_cache_by_delete_app from api.utils.storage.caches import del_cache_response_by_short, get_app_today_download_times, del_cache_by_delete_app
from api.models import Apps, AppReleaseInfo, APPToDeveloper, AppIOSDeveloperInfo, UserInfo, AppScreenShot from api.models import Apps, AppReleaseInfo, APPToDeveloper, AppIOSDeveloperInfo, UserInfo, AppScreenShot
from api.utils.serializer import AppsSerializer, AppReleaseSerializer from api.utils.serializer import AppsSerializer, AppReleaseSerializer, AppsListSerializer
from rest_framework.pagination import PageNumberPagination from rest_framework.pagination import PageNumberPagination
import logging import logging
from api.utils.utils import delete_local_files, delete_app_screenshots_files from api.utils.utils import delete_local_files, delete_app_screenshots_files
@ -94,7 +94,7 @@ class AppsView(APIView):
app_page_serializer = page_obj.paginate_queryset(queryset=apps_obj.order_by("-updated_time"), request=request, app_page_serializer = page_obj.paginate_queryset(queryset=apps_obj.order_by("-updated_time"), request=request,
view=self) view=self)
app_serializer = AppsSerializer(app_page_serializer, many=True, context={"storage": Storage(request.user)}) app_serializer = AppsListSerializer(app_page_serializer, many=True, context={"storage": Storage(request.user)})
res.userinfo = {} res.userinfo = {}
res.has_next = {} res.has_next = {}

@ -425,6 +425,7 @@ class UserInfoView(APIView):
res = BaseResponse() res = BaseResponse()
serializer = UserInfoSerializer(request.user) serializer = UserInfoSerializer(request.user)
res.data = serializer.data res.data = serializer.data
del res.data['username']
res.data['login_type'] = get_login_type() res.data['login_type'] = get_login_type()
return Response(res.dict) return Response(res.dict)

@ -299,10 +299,33 @@ LOGGING = {
'formatter': 'standard', 'formatter': 'standard',
'encoding': 'utf-8', 'encoding': 'utf-8',
}, },
'warning': {
'level': 'WARNING',
'class': 'logging.handlers.RotatingFileHandler', # 保存到文件,自动切
'filename': os.path.join(BASE_LOG_DIR, "flyapp_warning.log"), # 日志文件
'maxBytes': 1024 * 1024 * 5, # 日志大小 50M
'backupCount': 10,
'formatter': 'standard',
'encoding': 'utf-8',
},
'pay': {
'level': 'DEBUG',
'class': 'logging.handlers.RotatingFileHandler', # 保存到文件,自动切
'filename': os.path.join(BASE_LOG_DIR, "flyapp_pay.log"), # 日志文件
'maxBytes': 1024 * 1024 * 5, # 日志大小 50M
'backupCount': 10,
'formatter': 'standard',
'encoding': 'utf-8',
},
}, },
'loggers': { 'loggers': {
'': { # 默认的logger应用如下配置 '': { # 默认的logger应用如下配置
'handlers': ['TF', 'console', 'error'], # 上线之后可以把'console'移除 'handlers': ['TF', 'console', 'error', 'warning'], # 上线之后可以把'console'移除
'level': 'DEBUG',
'propagate': True,
},
'pay': { # 默认的logger应用如下配置
'handlers': ['pay'], # 上线之后可以把'console'移除
'level': 'DEBUG', 'level': 'DEBUG',
'propagate': True, 'propagate': True,
}, },

Loading…
Cancel
Save