|
|
@@ -952,28 +952,30 @@ def lensman_photo_price(request):
|
952
|
952
|
photo_id = request.POST.get('photo_id', '')
|
953
|
953
|
photo_type = request.POST.get('photo_type', 'nomark') # nomark for 去除水印, origin for 获取高清图
|
954
|
954
|
|
955
|
|
- # 处理价格逻辑
|
956
|
955
|
lensman_photo_price_key = LENSMAN_PHOTO_PRICE % (user_id, photo_id, photo_type)
|
957
|
|
- lensman_photo_haggle_times_key = LENSMAN_PHOTO_HAGGLE_TIMES % (user_id, photo_id, photo_type)
|
|
956
|
+
|
958
|
957
|
# Redis 获取存储的价格
|
959
|
958
|
price = int(r.get(lensman_photo_price_key) or 0)
|
960
|
959
|
if price:
|
961
|
|
- haggle_times = int(r.get(lensman_photo_haggle_times_key) or 0)
|
962
|
|
- # 砍价逻辑
|
963
|
|
- if haggle_times < settings.LENSMAN_PHOTO_HAGGLE_MAX_TIMES:
|
|
960
|
+ # Redis 获取存储的砍价次数
|
|
961
|
+ haggle_times = r.incr(LENSMAN_PHOTO_HAGGLE_TIMES % (user_id, photo_id, photo_type))
|
|
962
|
+ # 判断砍价是否已经超过次数
|
|
963
|
+ if haggle_times <= settings.LENSMAN_PHOTO_HAGGLE_MAX_TIMES:
|
|
964
|
+ # 砍掉的价格
|
964
|
965
|
haggle_price = random.choice([50, 100])
|
|
966
|
+ # 砍价后的价格
|
965
|
967
|
price = max(price - haggle_price, 1)
|
966
|
|
- r.incr(lensman_photo_haggle_times_key)
|
|
968
|
+ # Redis 设置新价格
|
|
969
|
+ r.set(lensman_photo_price_key, price)
|
967
|
970
|
else:
|
968
|
971
|
try:
|
969
|
972
|
group_photo = GroupPhotoInfo.objects.get(pk=photo_id)
|
970
|
973
|
except GroupPhotoInfo.DoesNotExist:
|
971
|
974
|
return response(GroupPhotoStatusCode.GROUP_PHOTO_NOT_FOUND)
|
972
|
975
|
# 获取摄影师定价
|
973
|
|
- price_fixed = get_lensman_price_fixed(group_photo.user_id)
|
974
|
|
- price = price_fixed.get(photo_type, 999)
|
975
|
|
-
|
976
|
|
- r.set(lensman_photo_price_key, price)
|
|
976
|
+ price = get_lensman_price_fixed(group_photo.user_id).get(photo_type, 999)
|
|
977
|
+ # Redis 设置新价格
|
|
978
|
+ r.set(lensman_photo_price_key, price)
|
977
|
979
|
|
978
|
980
|
return response(200, 'Get Price Success', u'获取价格成功', {
|
979
|
981
|
'price': price
|