es-num-old"> 15
+from utils.redis.rorder import get_lensman_order_record
16
+from utils.sql.raw import PAI2_HOME_API, PAI2_HOME_WX_API
17
+from utils.time_utils import origin_expired_stamps
18
+from utils.url_utils import share_url
19
+
20
+
21
+def get_home_photos(request):
22
+    user_id = get_query_value(request, 'user_id')
23
+    page = get_query_value(request, 'page', default=1, val_cast_func=int)
24
+    num = get_query_value(request, 'num', default=settings.PAI2_HOME_PER_PAGE, val_cast_func=int)
25
+
26
+    # 执行原生 SQL 语句,获取首页照片列表
27
+    cursor = connection.cursor()
28
+    cursor.execute((PAI2_HOME_WX_API if request.weixin else PAI2_HOME_API).format(
29
+        user_id=user_id,
30
+        offset=0,
31
+        rows=settings.PAI2_HOME_MAX_ROWS,
32
+    ))
33
+    rows = cursor.fetchall()
34
+
35
+    # 首页照片分页
36
+    rows, left = pagination(rows, page, num)
37
+
38
+    # 首页照片信息
39
+    rows = [{
40
+        'group_id': row[0],
41
+        'group_name': row[1],
42
+        'group_default_avatar': row[2],
43
+        'group_avatar': row[3],
44
+        'group_from': row[4],
45
+        'photo_id': row[5],
46
+        'photo_url': qiniu_file_url(row[6], bucket='watermark' if row[7] else 'photo'),
47
+        'photo_w': row[8],
48
+        'photo_h': row[9],
49
+        'photo_thumbnail_url': qiniu_file_url(row[10], bucket='thumbnail'),
50
+        'photo_thumbnail_w': row[11],
51
+        'photo_thumbnail_h': row[12],
52
+        'photo_thumbnail2_url': qiniu_file_url(row[13], bucket='thumbnail2'),
53
+        'photo_thumbnail2_w': row[14],
54
+        'photo_thumbnail2_h': row[15],
55
+        'photo_share_url': share_url(row[5]),  # Warning: Index of This Line is 5
56
+        'user_id': row[16],
57
+        'nickname': row[17],
58
+        'avatar': row[18],
59
+        'comment_num': row[19],
60
+        'thumbup_num': row[20],
61
+        'photo_from': row[21],
62
+        'session_id': row[22],
63
+        'nomark': row[23],
64
+        'origin': row[24],
65
+        'created_at': row[25],
66
+        'origin_expired_stamps': origin_expired_stamps(row[25], row[16]),
67
+        'thumbup': get_group_photo_thumbup_flag(row[5], user_id),
68
+        'porder': get_lensman_order_record(row[5], user_id) if row[21] == GroupPhotoInfo.SESSION_GROUP else {},
69
+        'display_payment_btn': row[21] == GroupPhotoInfo.SESSION_GROUP and row[27] not in [GroupPhotoInfo.OUTTAKE],
70
+        'longitude': row[28],
71
+        'latitude': row[29],
72
+        'location': row[30],
73
+    } for row in rows]
74
+
75
+    session_photos = map(lambda x: {'session_id': x[0], 'photos': list(x[1])}, itertools.groupby(rows, lambda x: x.get('session_id', '')))
76
+
77
+    return rows, session_photos, left

Kodo/kodo - Gogs: Go Git Service

1 Commits (2640b9969bea9aef3943832730d4234b7fc7044d)

Autore SHA1 Messaggio Data
  Brightcells 537c495621 Statistic 7 anni fa