Przeglądaj źródła

新增云服务API,修改云相册列表查询接口,新增工具方法时间戳转时间

zhangdongming 2 lat temu
rodzic
commit
b86fa1ec00

+ 4 - 1
Controller/CloudPhoto/CloudPhotoController.py

@@ -120,10 +120,13 @@ class CronCloudPhotoView(View):
             size = int(size)
             video_qs = DevicePicturePushInfo.objects.filter(user_id=user_id, type=1)
             if device_name:
-                video_qs = video_qs.filter(device_nick_name__icontains=device_name)
+                name_list = device_name.split(',')
+                video_qs = video_qs.filter(device_nick_name__in=name_list)
             if start_time:
+                start_time = LocalDateTimeUtil.time_stamp_to_time(int(start_time), '%Y%m')
                 video_qs = video_qs.filter(event_time__gte=int(start_time))
             if end_time:
+                end_time = LocalDateTimeUtil.time_stamp_to_time(int(end_time), '%Y%m')
                 video_qs = video_qs.filter(event_time__lte=int(end_time))
             video_qs = video_qs.values('id', 'uid', 'device_nick_name', 'event_time', 'created_time').order_by(
                 '-event_time')[(page - 1) * size:page * size]

+ 58 - 0
Controller/CloudPhoto/CloudServiceController.py

@@ -0,0 +1,58 @@
+# -*- encoding: utf-8 -*-
+"""
+@File    : CloudServiceController.py
+@Time    : 2022/12/8 10:23
+@Author  : stephen
+@Email   : zhangdongming@asj6.wecom.work
+@Software: PyCharm
+"""
+from django.views import View
+
+from Model.models import CouponCombo
+from Object.ResponseObject import ResponseObject
+from Object.TokenObject import TokenObject
+
+
+class CloudServiceController(View):
+
+    def get(self, request, *args, **kwargs):
+        request.encoding = 'utf-8'
+        operation = kwargs.get('operation')
+        return self.validation(request.GET, request, operation)
+
+    def post(self, request, *args, **kwargs):
+        request.encoding = 'utf-8'
+        operation = kwargs.get('operation')
+        return self.validation(request.POST, request, operation)
+
+    def validation(self, request_dict, request, operation):
+        token = TokenObject(request.META.get('HTTP_AUTHORIZATION'))
+        lang = request_dict.get('lang', token.lang)
+        response = ResponseObject(lang)
+        if token.code != 0:
+            return response.json(token.code)
+        user_id = token.userID
+        if operation == 'save-photo':
+            return self.get_combo_list_by_coupon(user_id, response)
+        else:
+            return response.json(404)
+
+    @classmethod
+    def get_combo_list_by_coupon(cls, request_dict, response):
+        """
+        根据优惠券获取套餐列表
+        @param request_dict: couponId 优惠券ID
+        @param request_dict: couponType 优惠券类型
+        @param response: 响应结果
+        """
+        coupon_id = int(request_dict.get('couponId', 0))
+        coupon_type = int(request_dict.get('couponType', 0))
+        if coupon_id == 0:
+            return response.json(444)
+        coupon_combo_qs = CouponCombo.objects.filter(coupon_type=coupon_type, coupon_id=coupon_id).values('combo_id')
+        combo_list = []
+        if not coupon_combo_qs.exists():
+            return combo_list
+        for item in coupon_combo_qs:
+            combo_list.append(item['combo_id'])
+        return combo_list

+ 13 - 1
Object/utils/LocalDateTimeUtil.py

@@ -152,6 +152,7 @@ def get_today_date(timestamp=False):
         return zero_today, last_today
     return zero_today, last_today
 
+
 def get_last_week():
     """
     获取前一周时间
@@ -162,6 +163,7 @@ def get_last_week():
     last_week_date = last_week.strftime("%Y-%m-%d %H:%M:%S")
     return last_week_date
 
+
 def get_last_month():
     """
     获取前一个月时间
@@ -243,6 +245,17 @@ def get_start_and_end_time(date, str_format):
     return 0
 
 
+def time_stamp_to_time(time_stamp, time_format):
+    """
+    时间戳转时间
+    @param time_stamp: 时间戳
+    @param time_format: 时间格式 例%Y-%m-%d %H:%M:%S
+    @return: 格式化后时间字符串
+    """
+    time_array = time.localtime(time_stamp)
+    return time.strftime(time_format, time_array)
+
+
 if __name__ == '__main__':
     zero_today, last_today = get_today_date(True)
     month_end = get_cur_month_end()
@@ -250,7 +263,6 @@ if __name__ == '__main__':
     print(zero_today)
     print(month_end_time)
 
-
     # # 获取当前月
     # print('当前月', get_cur_month())
     # # 获取上一个月