an>
|
-from rest_framework import viewsets
|
|
10
|
|
-from TimeConvert import TimeConvert as tc
|
|
11
|
|
-
|
|
12
|
|
-from account.models import LensmanInfo, UserInfo
|
|
13
|
|
-from group.models import GroupInfo, GroupPhotoInfo, GroupUserInfo
|
|
14
|
|
-from photo.models import PhotosInfo
|
|
15
|
|
-from photo.serializers import PhotosInfoSerializer
|
|
16
|
|
-from utils.error.errno_utils import LensmanStatusCode, PhotoStatusCode
|
|
17
|
|
-from utils.redis.connect import r
|
|
18
|
|
-from utils.redis.rgroup import get_group_info, set_group_info, set_group_users_info
|
|
19
|
|
-from utils.redis.rkeys import (GROUP_LAST_PHOTO_PK, GROUP_USERS_DELETED_SET, GROUP_USERS_PASSED_SET,
|
|
20
|
|
- GROUP_USERS_QUIT_SET, GROUP_USERS_REFUSED_SET, UUID_LIST)
|
|
21
|
|
-from utils.redis.rprice import get_lensman_price_fixed
|
|
22
|
|
-from utils.redis.ruuid import generate_uuids, update_uuids
|
|
23
|
|
-from utils.storage_qiniu_utils import file_save
|
|
24
|
|
-
|
|
25
|
|
-
|
|
26
|
|
-@logit
|
|
27
|
|
-def uuid_init(request):
|
|
28
|
|
- """ 生成唯一标识 """
|
|
29
|
|
- num = int(request.GET.get('num', 1000))
|
|
30
|
|
-
|
|
31
|
|
- # 生成 UUID
|
|
32
|
|
- generate_uuids(num)
|
|
33
|
|
-
|
|
34
|
|
- return response(200, 'UUID Refresh Success', u'UUID 更新成功')
|
|
35
|
|
-
|
|
36
|
|
-
|
|
37
|
|
-# curl -X POST -F user_id=xxxxxxx -F num=100 http://api.pai.ai/uuid
|
|
38
|
|
-@logit
|
|
39
|
|
-@transaction.atomic
|
|
40
|
|
-def uuid(request):
|
|
41
|
|
- """ 获取唯一标识 """
|
|
42
|
|
- lensman_id = request.POST.get('user_id', '')
|
|
43
|
|
- num = int(request.POST.get('num', 100))
|
|
44
|
|
-
|
|
45
|
|
- # 从 Redis 中 Pop 中指定数量的 UUID
|
|
46
|
|
- uuids, succeed, left = r.multi_pop(UUID_LIST, num)
|
|
47
|
|
-
|
|
48
|
|
- # # 异步更新 UUID 数据库中状态
|
|
49
|
|
- # if uuids:
|
|
50
|
|
- # async(update_uuids, lensman_id, uuids)
|
|
51
|
|
- #
|
|
52
|
|
- # # 当可用 UUID 数量少于 500 时, 异步创建
|
|
53
|
|
- # if left < 500:
|
|
54
|
|
- # async(generate_uuids)
|
|
55
|
|
-
|
|
56
|
|
- return response(200, 'Get UUID Success', u'获取唯一标识成功', uuids)
|
|
57
|
|
-
|
|
58
|
|
-
|
|
59
|
|
-# [How to do a PUT request with curl?](http://stackoverflow.com/questions/13782198/how-to-do-a-put-request-with-curl)
|
|
60
|
|
-# Unfortunately, the -T is no substitute for -X PUT if you want to specify parameters with -d or -F.
|
|
61
|
|
-# -T sends the content of a file via PUT. To achieve the GET after a redirect, add the parameter --location
|
|
62
|
|
-#
|
|
63
|
|
-# -F, --form <name=content>
|
|
64
|
|
-# (HTTP) This lets curl emulate a filled-in form in which a user has pressed the submit button. This causes curl to POST data
|
|
65
|
|
-# using the Content-Type multipart/form-data according to RFC 2388. This enables uploading of binary files etc. To force the
|
|
66
|
|
-# 'content' part to be a file, prefix the file name with an @ sign. To just get the content part from a file, prefix the file
|
|
67
|
|
-# name with the symbol <. The difference between @ and < is then that @ makes a file get attached in the post as a file upload,
|
|
68
|
|
-# while the < makes a text field and just get the contents for that text field from a file.
|
|
69
|
|
-#
|
|
70
|
|
-# curl -X POST -F user_id=xxxxxxx -F session_id=xxxxxxx -F photo_id=xxxxxxx -F photo=@xxxxxxx.jpg http://api.pai.ai/photos/upload
|
|
71
|
|
-@logit
|
|
72
|
|
-def upload_photo(request):
|
|
73
|
|
- """ 上传图片 """
|
|
74
|
|
- lensman_id = request.POST.get('user_id', '')
|
|
75
|
|
- session_id = request.POST.get('session_id', '')
|
|
76
|
|
- photo_id = request.POST.get('photo_id', '')
|
|
77
|
|
-
|
|
78
|
|
- photo = request.FILES.get('photo', '')
|
|
79
|
|
-
|
|
80
|
|
- if not (lensman_id and session_id and photo):
|
|
81
|
|
- return response(PhotoStatusCode.PARAMS_ERROR)
|
|
82
|
|
-
|
|
83
|
|
- try:
|
|
84
|
|
- LensmanInfo.objects.get(lensman_id=lensman_id)
|
|
85
|
|
- except LensmanInfo.DoesNotExist:
|
|
86
|
|
- return response(LensmanStatusCode.LENSMAN_NOT_FOUND)
|
|
87
|
|
-
|
|
88
|
|
- photo_info = file_save(photo, prefix='photo', ext='.jpeg', watermark=True)
|
|
89
|
|
-
|
|
90
|
|
- photo, created = PhotosInfo.objects.get_or_create(
|
|
91
|
|
- lensman_id=lensman_id,
|
|
92
|
|
- session_id=session_id,
|
|
93
|
|
- photo_id=photo_id,
|
|
94
|
|
- p_photo_path=photo_info.photo_watermark_path,
|
|
95
|
|
- m_photo_path=photo_info.photo_path,
|
|
96
|
|
- )
|
|
97
|
|
-
|
|
98
|
|
- return response(200, 'Photo Upload Success', u'照片上传成功', photo.data)
|
|
99
|
|
-
|
|
100
|
|
-
|
|
101
|
|
-@logit
|
|
102
|
|
-@transaction.atomic
|
|
103
|
|
-def session_join_api(request):
|
|
104
|
|
- """ Session 详情 """
|
|
105
|
|
- user_id = request.POST.get('user_id', '')
|
|
106
|
|
- session_id = request.POST.get('session_id', '')
|
|
107
|
|
- lensman_id = request.POST.get('lensman_id', '')
|
|
108
|
|
- nickname = request.POST.get('nickname', '')
|
|
109
|
|
- current_id = -1
|
|
110
|
|
-
|
|
111
|
|
- # 摄影师校验
|
|
112
|
|
- try:
|
|
113
|
|
- lensman = UserInfo.objects.get(user_id=lensman_id)
|
|
114
|
|
- except UserInfo.DoesNotExist:
|
|
115
|
|
- return response(LensmanStatusCode.LENSMAN_NOT_FOUND)
|
|
116
|
|
-
|
|
117
|
|
- # 判断 user_id 是否存在,如果不存在,则直接分配帐户
|
|
118
|
|
- user, user_created = UserInfo.objects.get_or_create(user_id=user_id, defaults={
|
|
119
|
|
- 'user_id': CurtailUUID.uuid(UserInfo, 'user_id'),
|
|
120
|
|
- 'user_status': UserInfo.ASSIGN,
|
|
121
|
|
- 'assign_ip': client_ip(request),
|
|
122
|
|
- 'assign_at': tc.utc_datetime(),
|
|
123
|
|
- })
|
|
124
|
|
- user_id = user.user_id
|
|
125
|
|
-
|
|
126
|
|
- # 判断通过 session_id 创建的群组是否存在,如果不存在,则直接创建
|
|
127
|
|
- group, group_created = GroupInfo.objects.select_for_update().get_or_create(session_id=session_id, group_from=GroupInfo.SESSION_GROUP, defaults={
|
|
128
|
|
- 'group_id': CurtailUUID.uuid(GroupInfo, 'group_id'),
|
|
129
|
|
- # 'admin_id': lensman_id,
|
|
130
|
|
- 'group_name': lensman.final_nickname,
|
|
131
|
|
- 'group_default_avatar': 0,
|
|
132
|
|
- })
|
|
133
|
|
- group_id = group.group_id
|
|
134
|
|
-
|
|
135
|
|
- # Redis 群组数据缓存
|
|
136
|
|
- group_info = set_group_info(group) if group_created else get_group_info(group_id)
|
|
137
|
|
-
|
|
138
|
|
- # 判断 group_id/user_id 的群组用户是否存在,如果不存在,则直接创建
|
|
139
|
|
- group_user, group_user_created = GroupUserInfo.objects.get_or_create(group_id=group_id, user_id=user_id, defaults={
|
|
140
|
|
- # 'current_id': int(r.get(GROUP_LAST_PHOTO_PK % group_id) or -1),
|
|
141
|
|
- 'current_id': current_id, # 通过扫描 session_id 二维码进群的用户,默认可以查看该群组所有照片
|
|
142
|
|
- 'nickname': nickname or user.final_nickname,
|
|
143
|
|
- 'avatar': user.avatar,
|
|
144
|
|
- # 'admin': group_created,
|
|
145
|
|
- 'user_status': GroupUserInfo.PASSED,
|
|
146
|
|
- 'passed_at': tc.utc_datetime(),
|
|
147
|
|
- })
|
|
148
|
|
- if not group_user_created:
|
|
149
|
|
- group_user.current_id = current_id
|
|
150
|
|
- group_user.user_status = GroupUserInfo.PASSED
|
|
151
|
|
- group_user.save()
|
|
152
|
|
-
|
|
153
|
|
- # 管理员处理
|
|
154
|
|
- tobe_admin = not GroupUserInfo.objects.filter(admin=True, status=True).exists()
|
|
155
|
|
- if tobe_admin:
|
|
156
|
|
- group.admin_id = user_id
|
|
157
|
|
- group.save()
|
|
158
|
|
- group_user.admin = True
|
|
159
|
|
- group_user.save()
|
|
160
|
|
-
|
|
161
|
|
- # Redis 群组用户数据缓存
|
|
162
|
|
- group_users = set_group_users_info(group)
|
|
163
|
|
-
|
|
164
|
|
- # Redis 群组通过集合缓存
|
|
165
|
|
- r.srem(GROUP_USERS_REFUSED_SET % group_id, user_id)
|
|
166
|
|
- r.srem(GROUP_USERS_DELETED_SET % group_id, user_id)
|
|
167
|
|
- r.srem(GROUP_USERS_QUIT_SET % group_id, user_id)
|
|
168
|
|
- r.sadd(GROUP_USERS_PASSED_SET % group_id, user_id)
|
|
169
|
|
-
|
|
170
|
|
- #
|
|
171
|
|
- if group_created:
|
|
172
|
|
- # 获取 Session 照片
|
|
173
|
|
- photos = PhotosInfo.objects.filter(session_id=session_id, status=True)
|
|
174
|
|
-
|
|
175
|
|
- # 获取摄影师定价
|
|
176
|
|
- price_info = get_lensman_price_fixed(lensman_id)
|
|
177
|
|
-
|
|
178
|
|
- group_photo = None
|
|
179
|
|
- for photo in photos:
|
|
180
|
|
- photo_info = file_save(photo_path=photo.p_photo_path, prefix='photo', ext='.jpeg', thumbnail=True)
|
|
181
|
|
-
|
|
182
|
|
- # 群组照片记录创建
|
|
183
|
|
- group_photo, created = GroupPhotoInfo.objects.get_or_create(
|
|
184
|
|
- group_id=group_id,
|
|
185
|
|
- user_id=user_id,
|
|
186
|
|
- photo_md5=photo_info.photo_md5,
|
|
187
|
|
- defaults={
|
|
188
|
|
- 'nickname': user.final_nickname,
|
|
189
|
|
- 'avatar': user.avatar,
|
|
190
|
|
- 'photo_path': photo_info.photo_watermark_path,
|
|
191
|
|
- 'has_watermark': True,
|
|
192
|
|
- 'photo_w': photo_info.photo_w,
|
|
193
|
|
- 'photo_h': photo_info.photo_h,
|
|
194
|
|
- 'photo_thumbnail_path': photo_info.photo_thumbnail_path,
|
|
195
|
|
- 'photo_thumbnail_w': photo_info.photo_thumbnail_w,
|
|
196
|
|
- 'photo_thumbnail_h': photo_info.photo_thumbnail_h,
|
|
197
|
|
- 'photo_thumbnail2_path': photo_info.photo_thumbnail2_path,
|
|
198
|
|
- 'photo_thumbnail2_w': photo_info.photo_thumbnail2_w,
|
|
199
|
|
- 'photo_thumbnail2_h': photo_info.photo_thumbnail2_h,
|
|
200
|
|
- 'photo_from': GroupPhotoInfo.SESSION_GROUP,
|
|
201
|
|
- 'session_id': photo.session_id,
|
|
202
|
|
- 'lensman_id': photo.lensman_id,
|
|
203
|
|
- 'lensman_photo_id': photo.photo_id,
|
|
204
|
|
- 'nomark': price_info.get('nomark', 999),
|
|
205
|
|
- 'origin': price_info.get('origin', 999),
|
|
206
|
|
- }
|
|
207
|
|
- )
|
|
208
|
|
-
|
|
209
|
|
- if group_photo:
|
|
210
|
|
- # 设置群组最后一张照片PK
|
|
211
|
|
- r.set(GROUP_LAST_PHOTO_PK % group_id, group_photo.pk)
|
|
212
|
|
-
|
|
213
|
|
- # Redis 群组数据缓存
|
|
214
|
|
- set_group_info(group)
|
|
215
|
|
-
|
|
216
|
|
- # 获取从 current_id 到 now 的群组照片列表
|
|
217
|
|
- group_photos = GroupPhotoInfo.objects.filter(
|
|
218
|
|
- group_id=group_id,
|
|
219
|
|
- status=True,
|
|
220
|
|
- pk__gt=group_user.current_id,
|
|
221
|
|
- ).order_by(
|
|
222
|
|
- '-pk'
|
|
223
|
|
- )
|
|
224
|
|
- latest_photo = group_photos.first()
|
|
225
|
|
-
|
|
226
|
|
- return response(200, 'Apply Join Session Group Success', u'申请加入摄影师群成功', {
|
|
227
|
|
- 'current_id': latest_photo and latest_photo.pk or current_id,
|
|
228
|
|
- 'photos': [photo.photo_info(user_id) for photo in group_photos],
|
|
229
|
|
- 'group_id': group_id,
|
|
230
|
|
- 'group': group_info,
|
|
231
|
|
- 'user_id': user_id,
|
|
232
|
|
- 'users': group_users,
|
|
233
|
|
- })
|
|
234
|
|
-
|
|
235
|
|
-
|
|
236
|
|
-@logit
|
|
237
|
|
-def session_detail(request, session_id):
|
|
238
|
|
- photos = PhotosInfo.objects.filter(session_id=session_id, status=True)
|
|
239
|
|
- return render(request, 'photo/session_detail.html', {'photos': photos})
|
|
240
|
|
-
|
|
241
|
|
-
|
|
242
|
|
-@logit
|
|
243
|
|
-def photo_standard(request, photo_id):
|
|
244
|
|
- photo = PhotosInfo.objects.get(photo_id=photo_id)
|
|
245
|
|
- return render(request, 'photo/photo_detail.html', {'photo_url': photo.p_photo_url})
|
|
246
|
|
-
|
|
247
|
|
-
|
|
248
|
|
-@logit
|
|
249
|
|
-def photo_standard_api(request, photo_id):
|
|
250
|
|
- photo = PhotosInfo.objects.get(photo_id=photo_id)
|
|
251
|
|
- return response(200, 'Get Photo Detail Success', u'获取照片详情成功', {
|
|
252
|
|
- 'photo': photo.detail,
|
|
253
|
|
- })
|
|
254
|
|
-
|
|
255
|
|
-
|
|
256
|
|
-@logit
|
|
257
|
|
-def photo_medium(request, photo_id):
|
|
258
|
|
- photo = PhotosInfo.objects.get(photo_id=photo_id)
|
|
259
|
|
- return render(request, 'photo/photo_detail.html', {'photo_url': photo.m_photo_url})
|
|
260
|
|
-
|
|
261
|
|
-
|
|
262
|
|
-@logit
|
|
263
|
|
-def photo_large(request, photo_id):
|
|
264
|
|
- photo = PhotosInfo.objects.get(photo_id=photo_id)
|
|
265
|
|
- return render(request, 'photo/photo_detail.html', {'photo_url': photo.l_photo_url})
|
|
266
|
|
-
|
|
267
|
|
-
|
|
268
|
|
-@logit
|
|
269
|
|
-def photo_raw(request, photo_id):
|
|
270
|
|
- photo = PhotosInfo.objects.get(photo_id=photo_id)
|
|
271
|
|
- return render(request, 'photo/photo_detail.html', {'photo_url': photo.r_photo_url})
|
|
272
|
|
-
|
|
273
|
|
-
|
|
274
|
|
-class PhotoInfoViewSet(viewsets.ModelViewSet):
|
|
275
|
|
- queryset = PhotosInfo.objects.all().order_by('-pk')
|
|
276
|
|
- serializer_class = PhotosInfoSerializer
|
|
|
|
@@ -99,33 +99,6 @@ class MarketCodeStatusCode(BaseStatusCode):
|
|
99
|
99
|
""" 一物一码相关错误码 5050xx """
|
|
100
|
100
|
MARKET_CODE_NOT_FOUND = StatusCodeField(505001, 'Market Code Not Found', description=u'一物一码不存在')
|
|
101
|
101
|
|
|
102
|
|
-
|
|
103
|
|
-class LensmanStatusCode(BaseStatusCode):
|
|
104
|
|
- """ 摄影师相关错误码 4000xx """
|
|
105
|
|
- LENSMAN_NOT_FOUND = StatusCodeField(400001, 'Lensman Not Found', description=u'摄影师不存在')
|
|
106
|
|
- # 密码
|
|
107
|
|
- LENSMAN_PASSWORD_ERROR = StatusCodeField(400002, 'Lensman Password Error', description=u'摄影师密码错误')
|
|
108
|
|
- # 手机号
|
|
109
|
|
- LENSMAN_PHONE_ALREADY_EXISTS = StatusCodeField(400005, 'Lensman Phone Already Exists', description=u'手机号已经存在')
|
|
110
|
|
- # 状态
|
|
111
|
|
- LENSMAN_ALREADY_NOT_UNVERIFIED = StatusCodeField(400010, 'Lensman Already Not Unverified', description=u'摄影师帐号已激活')
|
|
112
|
|
- LENSMAN_NOT_ACTIVATED = StatusCodeField(400015, 'Lensman Not Activated', description=u'摄影师帐号未激活')
|
|
113
|
|
- # 类别
|
|
114
|
|
- LENSMAN_TYPE_NOT_EXISTS = StatusCodeField(400020, 'Lensman Type Not Exists', description=u'摄影师类别不存在')
|
|
115
|
|
-
|
|
116
|
|
-
|
|
117
|
|
-class TourGuideStatusCode(BaseStatusCode):
|
|
118
|
|
- """ 导游相关错误码 4001xx """
|
|
119
|
|
- TOURGUIDE_NOT_FOUND = StatusCodeField(400101, 'Tour Guide Not Found', description=u'导游不存在')
|
|
120
|
|
- # 密码
|
|
121
|
|
- TOURGUIDE_PASSWORD_ERROR = StatusCodeField(400102, 'Tour Guide Password Error', description=u'导游密码错误')
|
|
122
|
|
- # 手机号
|
|
123
|
|
- TOURGUIDE_PHONE_ALREADY_EXISTS = StatusCodeField(400105, 'Tour Guide Phone Already Exists', description=u'手机号已经存在')
|
|
124
|
|
- # 状态
|
|
125
|
|
- TOURGUIDE_ALREADY_NOT_UNVERIFIED = StatusCodeField(400110, 'Tour Guide Already Not Unverified', description=u'导游帐号已激活')
|
|
126
|
|
- TOURGUIDE_NOT_ACTIVATED = StatusCodeField(400115, 'Tour Guide Not Activated', description=u'导游帐号未激活')
|
|
127
|
|
-
|
|
128
|
|
-
|
|
129
|
102
|
class AdministratorStatusCode(BaseStatusCode):
|
|
130
|
103
|
""" 操作员相关错误码 4002xx """
|
|
131
|
104
|
ADMINISTRATOR_NOT_FOUND = StatusCodeField(400201, 'Administrator Not Found', description=u'管理员不存在')
|
|
|
|
@@ -177,86 +150,10 @@ class WechatStatusCode(BaseStatusCode):
|
|
177
|
150
|
UNIONID_NOT_FOUND = StatusCodeField(400702, 'Unionid Not Found', description=u'微信 UNIONID 不存在')
|
|
178
|
151
|
OPENID_NOT_FOUND = StatusCodeField(400703, 'OPENID Not Found', description=u'微信 OPENID 不存在')
|
|
179
|
152
|
|
|
180
|
|
-
|
|
181
|
|
-class PhotoStatusCode(BaseStatusCode):
|
|
182
|
|
- """ 照片相关错误码 4010xx """
|
|
183
|
|
- PARAMS_ERROR = StatusCodeField(401001, 'Params Error', description=u'参数错误')
|
|
184
|
|
-
|
|
185
|
|
-
|
|
186
|
|
-class GroupStatusCode(BaseStatusCode):
|
|
187
|
|
- """ 群组/团相关错误码 4020xx """
|
|
188
|
|
- GROUP_NOT_FOUND = StatusCodeField(402001, 'Group Not Found', description=u'群组不存在')
|
|
189
|
|
- GROUP_HAS_LOCKED = StatusCodeField(402002, 'Group Has Locked', description=u'群组已锁定')
|
|
190
|
|
- # 管理员
|
|
191
|
|
- NOT_GROUP_ADMIN = StatusCodeField(402010, 'Not Group Admin', description=u'非群组管理员')
|
|
192
|
|
- NOT_GROUP_SUBADMIN = StatusCodeField(402011, 'Not Group Sub Admin', description=u'非群组协同管理员')
|
|
193
|
|
- ADMIN_CANNOT_HANDLE_SELF = StatusCodeField(402012, 'Admin Cannot Handle Self', description=u'群组管理员无法操作自身')
|
|
194
|
|
- # 旅行团
|
|
195
|
|
- ONLY_ONE_ACTIVE_GROUP_ALLOWED = StatusCodeField(402040, 'Only One Active Group Allowed', description=u'只能创建一个活跃团')
|
|
196
|
|
- ACTIVE_GROUP_NOT_FOUND = StatusCodeField(402041, 'Active Group Not Found', description=u'活跃团不存在')
|
|
197
|
|
- GROUP_HAS_ENDED = StatusCodeField(402042, 'Group Has Ended', description=u'群组已结束')
|
|
198
|
|
- # 其他
|
|
199
|
|
- GROUP_PHOTO_NOT_EMPTY = StatusCodeField(402099, 'Group Photo Not Empty', description=u'群组照片不为空')
|
|
200
|
|
-
|
|
201
|
|
-
|
|
202
|
|
-class GroupUserStatusCode(BaseStatusCode):
|
|
203
|
|
- """ 群组/团用户相关错误码 4021xx """
|
|
204
|
|
- GROUP_USER_NOT_FOUND = StatusCodeField(402101, 'Group User Not Found', description=u'群组用户不存在')
|
|
205
|
|
- GROUP_USER_HAS_DELETED = StatusCodeField(402102, 'Group User Has Deleted', description=u'群组用户被移除')
|
|
206
|
|
- # 旅行团
|
|
207
|
|
- USER_HAS_NOT_JOIN_GROUP = StatusCodeField(402131, 'User Has Not Join Group', description=u'用户未加入旅行团')
|
|
208
|
|
-
|
|
209
|
|
-
|
|
210
|
|
-class GroupPhotoStatusCode(BaseStatusCode):
|
|
211
|
|
- """ 群组照片(飞图)相关错误码 4022xx """
|
|
212
|
|
- GROUP_PHOTO_NOT_FOUND = StatusCodeField(402201, 'Group Photo Not Found', description=u'飞图不存在')
|
|
213
|
|
- # 上传
|
|
214
|
|
- DUPLICATE_UPLOAD = StatusCodeField(402210, 'Duplicate Upload', description=u'重复上传')
|
|
215
|
|
- # 点赞
|
|
216
|
|
- THUMB_UP_NOT_FOUND = StatusCodeField(402220, 'Thumb Up Not Found', description=u'未点赞')
|
|
217
|
|
- DUPLICATE_THUMB_UP = StatusCodeField(402221, 'Duplicate Thumb Up', description=u'重复点赞')
|
|
218
|
|
- # 评论
|
|
219
|
|
- COMMENT_CONTENT_EMPTY = StatusCodeField(402230, 'Comment Content Empty', description=u'评论内容为空')
|
|
220
|
|
-
|
|
221
|
|
-
|
|
222
|
153
|
class ScreenStatusCode(BaseStatusCode):
|
|
223
|
154
|
""" 群组/团相关错误码 4030xx """
|
|
224
|
155
|
QRCODE_NOT_SCAN = StatusCodeField(403001, 'QRCode Not Scan', description=u'二维码未扫描')
|
|
225
|
156
|
|
|
226
|
|
-
|
|
227
|
|
-class OrderStatusCode(BaseStatusCode):
|
|
228
|
|
- """ 订单/支付相关错误码 4040xx """
|
|
229
|
|
- WX_UNIFIED_ORDER_FAIL = StatusCodeField(404000, 'WX Unified Order Fail', description=u'微信统一下单失败')
|
|
230
|
|
- WX_ORDER_NOT_FOUND = StatusCodeField(404001, 'WX Order Not Found', description=u'订单不存在')
|
|
231
|
|
- WX_ORDER_NOT_PAY = StatusCodeField(404002, 'WX Order Not Pay', description=u'订单未支付')
|
|
232
|
|
- WX_ORDER_PAYING = StatusCodeField(404003, 'WX Order Paying', description=u'订单支付中')
|
|
233
|
|
- WX_ORDER_PAY_FAIL = StatusCodeField(404009, 'WX Order Pay Fail', description=u'微信支付失败')
|
|
234
|
|
- SIGN_CHECK_FAIL = StatusCodeField(404010, 'Sign Check Fail', description=u'签名校验失败')
|
|
235
|
|
- FEE_CHECK_FAIL = StatusCodeField(404011, 'FEE Check Fail', description=u'金额校验失败')
|
|
236
|
|
- NO_DETAIL_PERMISSION = StatusCodeField(404015, 'No Detail Permission', description=u'无详情权限')
|
|
237
|
|
- WX_ORDER_PAID_ALREADY_EXISTS = StatusCodeField(404020, 'WX Order Paid Already Exists', description=u'照片已购买')
|
|
238
|
|
-
|
|
239
|
|
-
|
|
240
|
|
-class PayStatusCode(BaseStatusCode):
|
|
241
|
|
- """ 支付相关错误码 4041xx """
|
|
242
|
|
-
|
|
243
|
|
-
|
|
244
|
|
-class WithdrawStatusCode(BaseStatusCode):
|
|
245
|
|
- """ 提现相关错误码 4042xx """
|
|
246
|
|
- BALANCE_NOT_ENOUGH = StatusCodeField(404200, 'Balance Not Enough', description=u'提现金额不足')
|
|
247
|
|
-
|
|
248
|
|
-
|
|
249
|
|
-class MessageStatusCode(BaseStatusCode):
|
|
250
|
|
- """ 消息相关错误码 4090xx """
|
|
251
|
|
- MESSAGE_NOT_FOUND = StatusCodeField(409001, 'Message Not Found', description=u'消息不存在')
|
|
252
|
|
-
|
|
253
|
|
-
|
|
254
|
|
-class TokenStatusCode(BaseStatusCode):
|
|
255
|
|
- """ 票据相关错误码 4090xx """
|
|
256
|
|
- TOKEN_NOT_FOUND = StatusCodeField(409901, 'Token Not Found', description=u'票据不存在')
|
|
257
|
|
- TOKEN_HAS_EXPIRED = StatusCodeField(409911, 'Token Has Expired', description=u'票据过期,请刷新重扫二维码')
|
|
258
|
|
-
|
|
259
|
|
-
|
|
260
|
157
|
class PermissionStatusCode(BaseStatusCode):
|
|
261
|
158
|
""" 4099xx 权限相关错误码 """
|
|
262
|
159
|
PERMISSION_DENIED = StatusCodeField(409900, 'Permission Denied', description=u'权限不足')
|
|
|
|
@@ -1,22 +0,0 @@
|
|
1
|
|
-# -*- coding: utf-8 -*-
|
|
2
|
|
-
|
|
3
|
|
-from isoweek import Week
|
|
4
|
|
-from TimeConvert import TimeConvert as tc
|
|
5
|
|
-
|
|
6
|
|
-from utils.redis.connect import r
|
|
7
|
|
-from utils.redis.rkeys import TODAY_INCOME, TOTAL_INCOME, WEEK_INCOME, WEEK_SOLD
|
|
8
|
|
-
|
|
9
|
|
-
|
|
10
|
|
-def set_brief_info(uid, ptype, fee, dt=None):
|
|
11
|
|
- """ 更新简报信息 """
|
|
12
|
|
- ymd, week = (tc.local_string(utc_dt=dt, format='%Y%m%d'), Week.withdate(dt)) if dt else (tc.local_string(format='%Y%m%d'), Week.thisweek().isoformat())
|
|
13
|
|
-
|
|
14
|
|
- # 总收入
|
|
15
|
|
- r.incr(TOTAL_INCOME % (uid, ptype), fee)
|
|
16
|
|
- # 周收入
|
|
17
|
|
- r.incr(WEEK_INCOME % (uid, ptype, week), fee)
|
|
18
|
|
- # 日收入
|
|
19
|
|
- r.incr(TODAY_INCOME % (uid, ptype, ymd), fee)
|
|
20
|
|
-
|
|
21
|
|
- # 周售出
|
|
22
|
|
- r.incr(WEEK_SOLD % (uid, ptype, week))
|
|
|
|
@@ -1,58 +0,0 @@
|
|
1
|
|
-# -*- coding: utf-8 -*-
|
|
2
|
|
-
|
|
3
|
|
-from group.models import GroupInfo, GroupPhotoInfo, GroupUserInfo, PhotoCommentInfo, PhotoThumbUpInfo
|
|
4
|
|
-from utils.redis.connect import r
|
|
5
|
|
-from utils.redis.rgroup import set_group_photo_data, set_group_users_info
|
|
6
|
|
-from utils.redis.rkeys import (GROUP_LAST_PHOTO_PK, GROUP_PHOTO_WATCHER_SET, GROUP_USERS_APPLYING_SET,
|
|
7
|
|
- GROUP_USERS_DELETED_SET, GROUP_USERS_PASSED_SET, GROUP_USERS_REFUSED_SET)
|
|
8
|
|
-
|
|
9
|
|
-
|
|
10
|
|
-def retrieve_group_data():
|
|
11
|
|
- """ 群组数据 """
|
|
12
|
|
- groups = GroupInfo.objects.filter(status=True)
|
|
13
|
|
- for group in groups:
|
|
14
|
|
- # 群组照片
|
|
15
|
|
- set_group_photo_data(group.group_id)
|
|
16
|
|
- # 群组用户
|
|
17
|
|
- set_group_users_info(group)
|
|
18
|
|
-
|
|
19
|
|
-
|
|
20
|
|
-def retrieve_last_pk():
|
|
21
|
|
- """ 群组最后一张照片PK """
|
|
22
|
|
- groups = GroupInfo.objects.filter(status=True)
|
|
23
|
|
- for group in groups:
|
|
24
|
|
- group_photo = GroupPhotoInfo.objects.filter(group_id=group.group_id, status=True).last()
|
|
25
|
|
- r.set(GROUP_LAST_PHOTO_PK % group.group_id, group_photo and group_photo.pk or -1)
|
|
26
|
|
-
|
|
27
|
|
-
|
|
28
|
|
-def retrieve_group_user_status():
|
|
29
|
|
- """ 群组用户状态 """
|
|
30
|
|
- group_users = GroupUserInfo.objects.filter(status=True)
|
|
31
|
|
- for group_user in group_users:
|
|
32
|
|
- group_id, user_id = group_user.group_id, group_user.user_id
|
|
33
|
|
- if group_user.user_status == GroupUserInfo.PASSED:
|
|
34
|
|
- r.sadd(GROUP_USERS_PASSED_SET % group_id, user_id)
|
|
35
|
|
- elif group_user.user_status == GroupUserInfo.DELETED:
|
|
36
|
|
- r.sadd(GROUP_USERS_DELETED_SET % group_id, user_id)
|
|
37
|
|
- elif group_user.user_status == GroupUserInfo.APPLYING:
|
|
38
|
|
- r.sadd(GROUP_USERS_APPLYING_SET % group_id, user_id)
|
|
39
|
|
- elif group_user.user_status == GroupUserInfo.REFUSED:
|
|
40
|
|
- r.sadd(GROUP_USERS_REFUSED_SET % group_id, user_id)
|
|
41
|
|
-
|
|
42
|
|
-
|
|
43
|
|
-def retrieve_group_photo_watchers():
|
|
44
|
|
- group_photos = GroupPhotoInfo.objects.filter(status=True)
|
|
45
|
|
- for group_photo in group_photos:
|
|
46
|
|
- photo_comments = PhotoCommentInfo.objects.filter(photo_id=group_photo.photo_id, status=True)
|
|
47
|
|
- for photo_comment in photo_comments:
|
|
48
|
|
- r.sadd(GROUP_PHOTO_WATCHER_SET % group_photo.pk, photo_comment.user_id)
|
|
49
|
|
- photo_thumbups = PhotoThumbUpInfo.objects.filter(photo_id=group_photo.photo_id, status=True)
|
|
50
|
|
- for photo_thumbup in photo_thumbups:
|
|
51
|
|
- r.sadd(GROUP_PHOTO_WATCHER_SET % group_photo.pk, photo_thumbup.user_id)
|
|
52
|
|
-
|
|
53
|
|
-
|
|
54
|
|
-def retrieve_redis_data():
|
|
55
|
|
- retrieve_group_data()
|
|
56
|
|
- retrieve_last_pk()
|
|
57
|
|
- retrieve_group_user_status()
|
|
58
|
|
- retrieve_group_photo_watchers()
|
|
|
|
@@ -1,147 +0,0 @@
|
|
1
|
|
-# -*- coding: utf-8 -*-
|
|
2
|
|
-
|
|
3
|
|
-from django.core.serializers.json import DjangoJSONEncoder
|
|
4
|
|
-
|
|
5
|
|
-from utils.redis.connect import r
|
|
6
|
|
-from utils.redis.rkeys import (GROUP_INFO, GROUP_PHOTO_COMMENT_LIST, GROUP_PHOTO_DATA, GROUP_PHOTO_THUMB_UP,
|
|
7
|
|
- GROUP_PHOTO_THUMB_UP_LIST, GROUP_PHOTO_WATCHER_SET, GROUP_USERS_INFO,
|
|
8
|
|
- GROUP_USERS_KV_INFO)
|
|
9
|
|
-
|
|
10
|
|
-
|
|
11
|
|
-def set_group_info(group):
|
|
12
|
|
- """ 设置群组信息 """
|
|
13
|
|
- r.setexjson(GROUP_INFO % group.group_id, r.REDIS_EXPIRED_ONE_MONTH, group.data, cls=DjangoJSONEncoder)
|
|
14
|
|
- return group.data
|
|
15
|
|
-
|
|
16
|
|
-
|
|
17
|
|
-def set_group_info_by_id(group_id):
|
|
18
|
|
- """ 设置群组信息 """
|
|
19
|
|
- from group.models import GroupInfo
|
|
20
|
|
- try:
|
|
21
|
|
- group = GroupInfo.objects.get(group_id=group_id)
|
|
22
|
|
- except GroupInfo.DoesNotExist:
|
|
23
|
|
- return {}
|
|
24
|
|
- return set_group_info(group)
|
|
25
|
|
-
|
|
26
|
|
-
|
|
27
|
|
-def get_group_info(group_id):
|
|
28
|
|
- """ 获取群组信息 """
|
|
29
|
|
- return r.getjson(GROUP_INFO % group_id) or set_group_info_by_id(group_id)
|
|
30
|
|
-
|
|
31
|
|
-
|
|
32
|
|
-# 群组用户信息相关
|
|
33
|
|
-
|
|
34
|
|
-
|
|
35
|
|
-def set_group_users_info(group):
|
|
36
|
|
- """ 设置群组用户信息 """
|
|
37
|
|
- group_users = group.users(admin=False)
|
|
38
|
|
-
|
|
39
|
|
- group_users_data = {
|
|
40
|
|
- 'group_users': group_users,
|
|
41
|
|
- 'admin_id': group.admin_id,
|
|
42
|
|
- }
|
|
43
|
|
- r.setexjson(GROUP_USERS_INFO % group.group_id, r.REDIS_EXPIRED_ONE_MONTH, group_users_data, cls=DjangoJSONEncoder)
|
|
44
|
|
-
|
|
45
|
|
- group_users_kv_data = {user_info.get('user_id', ''): user_info for user_info in group_users.get('passed', [])}
|
|
46
|
|
- r.setexjson(GROUP_USERS_KV_INFO % group.group_id, r.REDIS_EXPIRED_ONE_MONTH, group_users_kv_data, cls=DjangoJSONEncoder)
|
|
47
|
|
-
|
|
48
|
|
- return group_users_data, group_users_kv_data
|
|
49
|
|
-
|
|
50
|
|
-
|
|
51
|
|
-def set_group_users_info_by_id(group_id):
|
|
52
|
|
- """ 设置群组用户信息 """
|
|
53
|
|
- from group.models import GroupInfo
|
|
54
|
|
- try:
|
|
55
|
|
- group = GroupInfo.objects.get(group_id=group_id)
|
|
56
|
|
- except GroupInfo.DoesNotExist:
|
|
57
|
|
- return {}, {}
|
|
58
|
|
- return set_group_users_info(group)
|
|
59
|
|
-
|
|
60
|
|
-
|
|
61
|
|
-def get_group_users_info(group_id, user_id):
|
|
62
|
|
- """ 获取群组用户信息 """
|
|
63
|
|
- group_users_data = r.getjson(GROUP_USERS_INFO % group_id) or set_group_users_info_by_id(group_id)[0]
|
|
64
|
|
- group_users, admin_id = group_users_data.get('group_users', {}), group_users_data.get('admin_id', '')
|
|
65
|
|
- if group_users and user_id != admin_id:
|
|
66
|
|
- [group_users.pop(k) for k in ['applying_count', 'applying']]
|
|
67
|
|
- return group_users
|
|
68
|
|
-
|
|
69
|
|
-
|
|
70
|
|
-def get_group_users_kv_info(group_id):
|
|
71
|
|
- """ 获取群组用户信息 """
|
|
72
|
|
- return r.getjson(GROUP_USERS_KV_INFO % group_id) or set_group_users_info_by_id(group_id)[1]
|
|
73
|
|
-
|
|
74
|
|
-
|
|
75
|
|
-# 群组照片相关
|
|
76
|
|
-
|
|
77
|
|
-
|
|
78
|
|
-def set_group_photo_data(group_id):
|
|
79
|
|
- """ 设置群组照片数据信息 """
|
|
80
|
|
- from group.models import GroupPhotoInfo
|
|
81
|
|
- group_photos = GroupPhotoInfo.objects.filter(group_id=group_id, status=True)
|
|
82
|
|
- group_photos = [photo.photo_data for photo in group_photos]
|
|
83
|
|
- r.setjson(GROUP_PHOTO_DATA % group_id, group_photos)
|
|
84
|
|
- return group_photos
|
|
85
|
|
-
|
|
86
|
|
-
|
|
87
|
|
-def get_group_photo_data(group_id):
|
|
88
|
|
- """ 获取群组照片数据信息 """
|
|
89
|
|
- return r.getjson(GROUP_PHOTO_DATA % group_id, default='[]') or set_group_photo_data(group_id)
|
|
90
|
|
-
|
|
91
|
|
-
|
|
92
|
|
-def set_group_photo_thumbup_flag(photo_id, user_id):
|
|
93
|
|
- """ 设置群组照片用户点赞标识信息 """
|
|
94
|
|
- r.setex(GROUP_PHOTO_THUMB_UP % (photo_id, user_id), r.REDIS_EXPIRED_ONE_MONTH, True)
|
|
95
|
|
-
|
|
96
|
|
-
|
|
97
|
|
-def del_group_photo_thumbup_flag(photo_id, user_id):
|
|
98
|
|
- """ 删除群组照片用户点赞标识信息 """
|
|
99
|
|
- r.delete(GROUP_PHOTO_THUMB_UP % (photo_id, user_id))
|
|
100
|
|
-
|
|
101
|
|
-
|
|
102
|
|
-def get_group_photo_thumbup_flag(photo_id, user_id):
|
|
103
|
|
- """ 获取群组照片用户点赞标识信息 """
|
|
104
|
|
- if r.exists(GROUP_PHOTO_THUMB_UP % (photo_id, user_id)):
|
|
105
|
|
- return True
|
|
106
|
|
-
|
|
107
|
|
- from group.models import PhotoThumbUpInfo
|
|
108
|
|
- if PhotoThumbUpInfo.objects.filter(photo_id=photo_id, user_id=user_id, thumbup=True, status=True).exists():
|
|
109
|
|
- set_group_photo_thumbup_flag(photo_id, user_id)
|
|
110
|
|
- return True
|
|
111
|
|
-
|
|
112
|
|
- return False
|
|
113
|
|
-
|
|
114
|
|
-
|
|
115
|
|
-def set_group_photo_comment_list(photo_id):
|
|
116
|
|
- """ 设置群组照片用户评论列表 """
|
|
117
|
|
- from group.models import PhotoCommentInfo
|
|
118
|
|
- photo_comments = PhotoCommentInfo.objects.filter(photo_id=photo_id, status=True)
|
|
119
|
|
- photo_comments = [comment.comment_info for comment in photo_comments]
|
|
120
|
|
- r.setjson(GROUP_PHOTO_COMMENT_LIST % photo_id, photo_comments, cls=DjangoJSONEncoder)
|
|
121
|
|
- return photo_comments
|
|
122
|
|
-
|
|
123
|
|
-
|
|
124
|
|
-def get_group_photo_comment_list(photo_id):
|
|
125
|
|
- """ 获取群组照片用户评论列表 """
|
|
126
|
|
- return r.getjson(GROUP_PHOTO_COMMENT_LIST % photo_id, default='[]') or set_group_photo_comment_list(photo_id)
|
|
127
|
|
-
|
|
128
|
|
-
|
|
129
|
|
-def set_group_photo_thumbup_list(photo_id):
|
|
130
|
|
- """ 设置群组照片用户点赞列表 """
|
|
131
|
|
- from group.models import PhotoThumbUpInfo
|
|
132
|
|
- photo_thumbups = PhotoThumbUpInfo.objects.filter(photo_id=photo_id, thumbup=True, status=True)
|
|
133
|
|
- photo_thumbups = [thumbup.thumbup_info for thumbup in photo_thumbups]
|
|
134
|
|
- r.setjson(GROUP_PHOTO_THUMB_UP_LIST % photo_id, photo_thumbups, cls=DjangoJSONEncoder)
|
|
135
|
|
- return photo_thumbups
|
|
136
|
|
-
|
|
137
|
|
-
|
|
138
|
|
-def get_group_photo_thumbup_list(photo_id):
|
|
139
|
|
- """ 获取群组照片用户点赞列表 """
|
|
140
|
|
- return r.getjson(GROUP_PHOTO_THUMB_UP_LIST % photo_id, default='[]') or set_group_photo_thumbup_list(photo_id)
|
|
141
|
|
-
|
|
142
|
|
-
|
|
143
|
|
-def get_group_photo_watchers(photo_id, discarders=None):
|
|
144
|
|
- """ 获取群组照片用户关注列表 """
|
|
145
|
|
- watchers = r.smembers(GROUP_PHOTO_WATCHER_SET % photo_id)
|
|
146
|
|
- [watchers.discard(elem) for elem in discarders or []]
|
|
147
|
|
- return watchers
|
|
|
|
@@ -1,20 +0,0 @@
|
|
1
|
|
-# -*- coding: utf-8 -*-
|
|
2
|
|
-
|
|
3
|
|
-from utils.redis.connect import r
|
|
4
|
|
-from utils.redis.rkeys import GUEST_ENTRANCE_CONTROL_INFO
|
|
5
|
|
-
|
|
6
|
|
-
|
|
7
|
|
-def set_guest_entrance_control(gen):
|
|
8
|
|
- """ 设置游客入口控制 """
|
|
9
|
|
- r.setjson(GUEST_ENTRANCE_CONTROL_INFO % gen.src, gen.data)
|
|
10
|
|
- return gen.data
|
|
11
|
|
-
|
|
12
|
|
-
|
|
13
|
|
-def get_guest_entrance_control(src=0):
|
|
14
|
|
- """ 获取游客入口控制 """
|
|
15
|
|
- return r.getjson(GUEST_ENTRANCE_CONTROL_INFO % src)
|
|
16
|
|
-
|
|
17
|
|
-
|
|
18
|
|
-def delete_guest_entrance_control(src=0):
|
|
19
|
|
- """ 删除游客入口控制 """
|
|
20
|
|
- return r.delete(GUEST_ENTRANCE_CONTROL_INFO % src)
|
|
|
|
@@ -1,71 +1,12 @@
|
|
1
|
|
-# -*- coding: utf-8 -*-
|
|
2
|
|
-
|
|
3
|
|
-# 唯一标识相关
|
|
4
|
|
-UUID_LIST = 'uuid:list' # List,唯一标识列表
|
|
5
|
|
-
|
|
6
|
|
-# 用户相关
|
|
7
|
|
-PROFILE_INFO = 'profile:info:%s' # STRING,用户信息,user_id
|
|
8
|
|
-
|
|
9
|
|
-# 导游相关
|
|
10
|
|
-TOUR_GUIDE_GROUP_GEO_INFO = 'tour:guide:group:geo:info:%s' # ZSET,旅游团地理位置信息,group_id
|
|
11
|
|
-TOUR_GUIDE_GROUP_GEO_SUBMIT_DT = 'tour:guide:group:geo:submit:dt:%s' # ZSET,旅游团地理位置最后上传时间,group_id
|
|
12
|
|
-TOUR_GUIDE_GROUP_CUR_SESSION = 'tour:guide:group:cur:session:%s' # STRING,旅游团当前Session,group_id,导游设置集合时间的时候更新
|
|
13
|
|
-TOUR_GUIDE_GROUP_CUR_GATHER_INFO = 'tour:guide:group:cur:gather:info:%s' # STRING,旅游团当前Session,group_id,导游设置集合时间的时候更新
|
|
14
|
|
-TOUR_GUIDE_GROUP_USER_GEO_LIST = 'tour:guide:group:user:geo:list:%s:%s:%s' # LIST,旅游团当前用户地理位置列表,group_id、session_id、user_id
|
|
15
|
|
-
|
|
16
|
|
-TOUR_GUIDE_GROUP_USER_OWN = 'tour:guide:group:user:own:%s' # STRING,导游当前拥有的旅行团,user_id,导游创建旅行团的时候更新
|
|
17
|
|
-TOUR_GUIDE_GROUP_USER_BELONG = 'tour:guide:group:user:belong:%s' # STRING,用户当前所属旅行团,user_id,用户加入旅行团的时候更新
|
|
18
|
|
-
|
|
19
|
|
-# 群组相关
|
|
20
|
|
-GROUP_INFO = 'group:info:%s' # STRING,群组信息,group_id
|
|
21
|
|
-
|
|
22
|
|
-# 群组用户相关
|
|
23
|
|
-GROUP_USERS_INFO = 'group:users:info:%s' # STRING,群组用户信息,group_id
|
|
24
|
|
-GROUP_USERS_KV_INFO = 'group:users:kv:info:%s' # STRING,群组用户信息,group_id
|
|
25
|
|
-GROUP_USERS_APPLYING_SET = 'group:users:applying:set:%s' # SET,群组用户申请集合,group_id
|
|
26
|
|
-GROUP_USERS_PASSED_SET = 'group:users:passed:set:%s' # SET,群组用户通过集合,group_id
|
|
27
|
|
-GROUP_USERS_REFUSED_SET = 'group:users:refused:set:%s' # SET,群组用户拒绝集合,group_id
|
|
28
|
|
-GROUP_USERS_DELETED_SET = 'group:users:deleted:set:%s' # SET,群组用户移除集合,group_id
|
|
29
|
|
-GROUP_USERS_QUIT_SET = 'group:users:quit:set:%s' # SET,群组用户退出集合,group_id
|
|
30
|
|
-
|
|
31
|
|
-# 群组照片相关
|
|
32
|
|
-GROUP_PHOTO_DATA = 'group:photo:data:%s' # STRING,群组数据记录,group_id
|
|
33
|
|
-GROUP_PHOTO_THUMB_UP = 'group:photo:thumb:up:%s:%s' # STRING,群组照片用户点赞记录,photo_id、user_id
|
|
34
|
|
-GROUP_PHOTO_COMMENT_LIST = 'group:photo:comment:list:%s' # STRING,群组照片用户评论列表,photo_id
|
|
35
|
|
-GROUP_PHOTO_THUMB_UP_LIST = 'group:photo:thumb:up:list:%s' # STRING,群组照片用户点赞列表,photo_id
|
|
36
|
|
-GROUP_PHOTO_WATCHER_SET = 'group:photo:watcher:set:%s' # SET,群组照片用户关注集合,photo_id,关注即评论点赞
|
|
37
|
|
-GROUP_LAST_PHOTO_PK = 'group:last:photo:pk:%s' # STRING,群组最后一张照片PK,group_id
|
|
38
|
|
-
|
|
39
|
|
-# 摄影师照片相关
|
|
40
|
|
-LENSMAN_PHOTO_ORDER_RECORD = 'lensman:photo:order:record:%s:%s' # STRING,摄影师照片购买记录,photo_id、user_id
|
|
41
|
|
-
|
|
42
|
|
-# 摄影师简报相关
|
|
43
|
|
-# 收入
|
|
44
|
|
-TOTAL_INCOME = 'total:income:%s:%s' # STRING,总收入,user_id、photo_type
|
|
45
|
|
-WEEK_INCOME = 'week:income:%s:%s:%s' # STRING,周收入,user_id、photo_type、Week.thisweek().isoformat()
|
|
46
|
|
-TODAY_INCOME = 'today:income:%s:%s:%s' # STRING,日收入,user_id、photo_type、tc.local_string(format='%Y%m%d')
|
|
47
|
|
-# 上传
|
|
48
|
|
-TODAY_UPLOAD_PHOTO_AMOUNT = 'today:upload:photo:amount:%s:%s' # STRING,日上传照片数量,user_id、tc.local_string(format='%Y%m%d')
|
|
49
|
|
-# 售出
|
|
50
|
|
-WEEK_SOLD = 'week:sold:%s:%s:%s' # STRING,周售出,user_id、photo_type、Week.thisweek().isoformat()
|
|
51
|
|
-
|
|
52
|
|
-# 摄影师定价相关
|
|
53
|
|
-LENSMAN_PHOTO_PRICE_FIXED = 'lensman:photo:price:fixed:%s' # STRING,摄影师照片定价(单位:分),user_id
|
|
54
|
|
-
|
|
55
|
|
-# 系统消息相关
|
|
56
|
|
-SYSTEM_MESSAGE_READ_INFO = 'system:message:read:info:%s' # STRING,系统消息读取信息,user_id
|
|
57
|
|
-SYSTEM_MESSAGE_DELETED_INFO = 'system:message:deleted:info:%s' # STRING,系统消息删除信息,user_id
|
|
58
|
|
-
|
|
59
|
|
-# 游客入口相关
|
|
60
|
|
-GUEST_ENTRANCE_CONTROL_INFO = 'guest:entrance:control:info:%s' # STRING,游客入口控制信息,src
|
|
|
1
|
+# -*- coding: utf-8 -*-'
|
|
61
|
2
|
|
|
62
|
3
|
# APP 相关
|
|
63
|
4
|
LATEST_APP_INFO = 'latest:app:info:%s' # STRING,最新 APP 信息,src
|
|
64
|
5
|
APP_SETTINGS_INFO = 'app:settings:info:%s:%s:%s' # STRING,APP 设置信息,platform、channel、version
|
|
65
|
6
|
APP_PATCH_INFO = 'app:patch:info:%s:%s:%s' # STRING,APP 补丁信息,platform、version、src
|
|
66
|
7
|
|
|
67
|
|
-# BOX 相关
|
|
68
|
|
-BOX_PROGRAM_VERSION_INFO = 'box:program:version:info' # STRING,BOX 程序版本信息
|
|
|
8
|
+# 用户相关
|
|
|
9
|
+PROFILE_INFO = 'profile:info:%s' # STRING,用户信息,user_id
|
|
69
|
10
|
|
|
70
|
11
|
# 小程序相关
|
|
71
|
12
|
MINI_PROGRAM_GIS_LIST = 'tamron:miniprogram:gis:list'
|
|
|
|
@@ -1,32 +0,0 @@
|
|
1
|
|
-# -*- coding: utf-8 -*-
|
|
2
|
|
-
|
|
3
|
|
-from utils.redis.connect import r
|
|
4
|
|
-from utils.redis.rkeys import SYSTEM_MESSAGE_DELETED_INFO, SYSTEM_MESSAGE_READ_INFO
|
|
5
|
|
-
|
|
6
|
|
-
|
|
7
|
|
-def set_system_message_read_info(user_id):
|
|
8
|
|
- """ 设置系统消息读取信息 """
|
|
9
|
|
- from message.models import SystemMessageReadInfo
|
|
10
|
|
- read_messages = SystemMessageReadInfo.objects.filter(user_id=user_id, status=True)
|
|
11
|
|
- read_message_ids = [msg.msg_id for msg in read_messages]
|
|
12
|
|
- r.setexjson(SYSTEM_MESSAGE_READ_INFO % user_id, r.REDIS_EXPIRED_ONE_MONTH, read_message_ids)
|
|
13
|
|
- return read_message_ids
|
|
14
|
|
-
|
|
15
|
|
-
|
|
16
|
|
-def get_system_message_read_info(user_id):
|
|
17
|
|
- """ 获取系统消息读取信息 """
|
|
18
|
|
- return r.getjson(SYSTEM_MESSAGE_READ_INFO % user_id, default='[]') or set_system_message_read_info(user_id)
|
|
19
|
|
-
|
|
20
|
|
-
|
|
21
|
|
-def set_system_message_delete_info(user_id):
|
|
22
|
|
- """ 设置系统消息删除信息 """
|
|
23
|
|
- from message.models import SystemMessageDeleteInfo
|
|
24
|
|
- deleted_messages = SystemMessageDeleteInfo.objects.filter(user_id=user_id, status=True)
|
|
25
|
|
- deleted_message_ids = [msg.msg_id for msg in deleted_messages]
|
|
26
|
|
- r.setexjson(SYSTEM_MESSAGE_DELETED_INFO % user_id, r.REDIS_EXPIRED_ONE_MONTH, deleted_message_ids)
|
|
27
|
|
- return deleted_message_ids
|
|
28
|
|
-
|
|
29
|
|
-
|
|
30
|
|
-def get_system_message_delete_info(user_id):
|
|
31
|
|
- """ 获取系统消息删除信息 """
|
|
32
|
|
- return r.getjson(SYSTEM_MESSAGE_DELETED_INFO % user_id, default='[]') or set_system_message_delete_info(user_id)
|
|
|
|
@@ -1,20 +0,0 @@
|
|
1
|
|
-# -*- coding: utf-8 -*-
|
|
2
|
|
-
|
|
3
|
|
-from utils.redis.connect import r
|
|
4
|
|
-from utils.redis.rkeys import BOX_PROGRAM_VERSION_INFO
|
|
5
|
|
-
|
|
6
|
|
-
|
|
7
|
|
-def set_box_program_version():
|
|
8
|
|
- """ 设置 BOX 程序版本信息 """
|
|
9
|
|
- from operation.models import BoxProgramVersionInfo
|
|
10
|
|
- try:
|
|
11
|
|
- bpverion = BoxProgramVersionInfo.objects.filter(status=True)[0].data
|
|
12
|
|
- except IndexError:
|
|
13
|
|
- bpverion = {}
|
|
14
|
|
- r.setjson(BOX_PROGRAM_VERSION_INFO, bpverion)
|
|
15
|
|
- return bpverion
|
|
16
|
|
-
|
|
17
|
|
-
|
|
18
|
|
-def get_box_program_version():
|
|
19
|
|
- """ 获取 BOX 程序版本信息 """
|
|
20
|
|
- return r.getjson(BOX_PROGRAM_VERSION_INFO) or set_box_program_version()
|
|
|
|
@@ -1,27 +0,0 @@
|
|
1
|
|
-# -*- coding: utf-8 -*-
|
|
2
|
|
-
|
|
3
|
|
-from django.core.serializers.json import DjangoJSONEncoder
|
|
4
|
|
-
|
|
5
|
|
-from utils.redis.connect import r
|
|
6
|
|
-from utils.redis.rkeys import LENSMAN_PHOTO_ORDER_RECORD
|
|
7
|
|
-
|
|
8
|
|
-
|
|
9
|
|
-def set_lensman_order_record(porder):
|
|
10
|
|
- """ 设置摄影师照片购买记录 """
|
|
11
|
|
- r.setexjson(LENSMAN_PHOTO_ORDER_RECORD % (porder.photo_id, porder.user_id), r.REDIS_EXPIRED_ONE_MONTH, porder.porder_info, cls=DjangoJSONEncoder)
|
|
12
|
|
- return porder.porder_info
|
|
13
|
|
-
|
|
14
|
|
-
|
|
15
|
|
-def set_lensman_order_record_by_id(photo_id, user_id):
|
|
16
|
|
- """ 设置摄影师照片购买记录 """
|
|
17
|
|
- from group.models import GroupPhotoOrderInfo
|
|
18
|
|
- try:
|
|
19
|
|
- porder = GroupPhotoOrderInfo.objects.get(photo_id=photo_id, user_id=user_id)
|
|
20
|
|
- except GroupPhotoOrderInfo.DoesNotExist:
|
|
21
|
|
- return {}
|
|
22
|
|
- return set_lensman_order_record(porder)
|
|
23
|
|
-
|
|
24
|
|
-
|
|
25
|
|
-def get_lensman_order_record(photo_id, user_id):
|
|
26
|
|
- """ 获取摄影师照片购买记录 """
|
|
27
|
|
- return r.getjson(LENSMAN_PHOTO_ORDER_RECORD % (photo_id, user_id)) or set_lensman_order_record_by_id(photo_id, user_id)
|
|
|
|
@@ -1,27 +0,0 @@
|
|
1
|
|
-# -*- coding: utf-8 -*-
|
|
2
|
|
-
|
|
3
|
|
-from utils.redis.connect import r
|
|
4
|
|
-from utils.redis.rkeys import LENSMAN_PHOTO_PRICE_FIXED
|
|
5
|
|
-
|
|
6
|
|
-
|
|
7
|
|
-def set_lensman_price_fixed(user_id):
|
|
8
|
|
- """ 设置摄影师价格设定 """
|
|
9
|
|
- from account.models import LensmanInfo
|
|
10
|
|
- try:
|
|
11
|
|
- lensman = LensmanInfo.objects.get(lensman_id=user_id)
|
|
12
|
|
- except LensmanInfo.DoesNotExist:
|
|
13
|
|
- lensman = None
|
|
14
|
|
-
|
|
15
|
|
- price_fixed = {
|
|
16
|
|
- 'nomark': (lensman and lensman.nomark) or 299,
|
|
17
|
|
- 'origin': (lensman and lensman.origin) or 999,
|
|
18
|
|
- }
|
|
19
|
|
-
|
|
20
|
|
- r.setjson(LENSMAN_PHOTO_PRICE_FIXED % user_id, price_fixed)
|
|
21
|
|
-
|
|
22
|
|
- return price_fixed
|
|
23
|
|
-
|
|
24
|
|
-
|
|
25
|
|
-def get_lensman_price_fixed(user_id):
|
|
26
|
|
- """ 获取摄影师价格设定 """
|
|
27
|
|
- return r.getjson(LENSMAN_PHOTO_PRICE_FIXED % user_id) or set_lensman_price_fixed(user_id)
|
|
|
|
@@ -1,19 +0,0 @@
|
|
1
|
|
-# -*- coding: utf-8 -*-
|
|
2
|
|
-
|
|
3
|
|
-from utils.redis.connect import r
|
|
4
|
|
-from utils.redis.rkeys import TOUR_GUIDE_GROUP_USER_OWN
|
|
5
|
|
-
|
|
6
|
|
-
|
|
7
|
|
-def set_tour_guide_own_group(user_id, group_id):
|
|
8
|
|
- """ 设置导游拥有的旅行团 """
|
|
9
|
|
- r.set(TOUR_GUIDE_GROUP_USER_OWN % user_id, group_id)
|
|
10
|
|
-
|
|
11
|
|
-
|
|
12
|
|
-def get_tour_guide_own_group(user_id):
|
|
13
|
|
- """ 获取导游拥有的旅行团 """
|
|
14
|
|
- return r.get(TOUR_GUIDE_GROUP_USER_OWN % user_id)
|
|
15
|
|
-
|
|
16
|
|
-
|
|
17
|
|
-def del_tour_guide_own_group(user_id):
|
|
18
|
|
- """ 删除导游拥有的旅行团 """
|
|
19
|
|
- return r.delete(TOUR_GUIDE_GROUP_USER_OWN % user_id)
|
|
|
|
@@ -1,14 +0,0 @@
|
|
1
|
|
-# -*- coding: utf-8 -*-
|
|
2
|
|
-
|
|
3
|
|
-from utils.redis.connect import r
|
|
4
|
|
-from utils.redis.rkeys import TOUR_GUIDE_GROUP_USER_BELONG
|
|
5
|
|
-
|
|
6
|
|
-
|
|
7
|
|
-def set_tour_user_belong_group(user_id, group_id):
|
|
8
|
|
- """ 设置旅行团成员所属的旅行团 """
|
|
9
|
|
- r.set(TOUR_GUIDE_GROUP_USER_BELONG % user_id, group_id)
|
|
10
|
|
-
|
|
11
|
|
-
|
|
12
|
|
-def get_tour_user_belong_group(user_id):
|
|
13
|
|
- """ 获取旅行团成员所属的旅行团 """
|
|
14
|
|
- return r.get(TOUR_GUIDE_GROUP_USER_BELONG % user_id)
|
|
|
|
@@ -1,22 +0,0 @@
|
|
1
|
|
-# -*- coding: utf-8 -*-
|
|
2
|
|
-
|
|
3
|
|
-from django_curtail_uuid import CurtailUUID
|
|
4
|
|
-
|
|
5
|
|
-from photo.models import UUIDInfo
|
|
6
|
|
-from utils.redis.connect import r
|
|
7
|
|
-from utils.redis.rkeys import UUID_LIST
|
|
8
|
|
-
|
|
9
|
|
-
|
|
10
|
|
-def generate_uuid():
|
|
11
|
|
- uuid = CurtailUUID.uuid(UUIDInfo)
|
|
12
|
|
- UUIDInfo.objects.create(uuid=uuid)
|
|
13
|
|
- return uuid
|
|
14
|
|
-
|
|
15
|
|
-
|
|
16
|
|
-def generate_uuids(num=1000):
|
|
17
|
|
- uuids = [generate_uuid() for i in range(num)]
|
|
18
|
|
- r.rpush(UUID_LIST, *uuids)
|
|
19
|
|
-
|
|
20
|
|
-
|
|
21
|
|
-def update_uuids(lensman_id, uuids):
|
|
22
|
|
- UUIDInfo.objects.filter(uuid__in=uuids).update(lensman_id=lensman_id, status=False)
|