@@ -76,3 +76,8 @@ urlpatterns += [ |
||
| 76 | 76 |
url(r'^wx/order_create$', pay_views.wx_order_create_api, name='wx_order_create_api'), # 订单创建 |
| 77 | 77 |
url(r'^wx/notify_url$', pay_views.wx_notify_url_api, name='wx_notify_url_api'), # 支付异步通知回调地址 |
| 78 | 78 |
] |
| 79 |
+ |
|
| 80 |
+# 首页相关 |
|
| 81 |
+urlpatterns += [ |
|
| 82 |
+ url(r'^pai2/home$', group_views.pai2_home_api, name='pai2_home_api'), # 首页信息 |
|
| 83 |
+] |
@@ -0,0 +1,24 @@ |
||
| 1 |
+# -*- coding: utf-8 -*- |
|
| 2 |
+from __future__ import unicode_literals |
|
| 3 |
+ |
|
| 4 |
+from django.db import models, migrations |
|
| 5 |
+ |
|
| 6 |
+ |
|
| 7 |
+class Migration(migrations.Migration): |
|
| 8 |
+ |
|
| 9 |
+ dependencies = [ |
|
| 10 |
+ ('group', '0010_auto_20160120_1830'),
|
|
| 11 |
+ ] |
|
| 12 |
+ |
|
| 13 |
+ operations = [ |
|
| 14 |
+ migrations.AddField( |
|
| 15 |
+ model_name='groupphotoinfo', |
|
| 16 |
+ name='comment_num', |
|
| 17 |
+ field=models.IntegerField(default=0, help_text='\u7167\u7247\u8bc4\u8bba\u6570\u91cf', verbose_name='comment_num'), |
|
| 18 |
+ ), |
|
| 19 |
+ migrations.AddField( |
|
| 20 |
+ model_name='groupphotoinfo', |
|
| 21 |
+ name='thumbup_num', |
|
| 22 |
+ field=models.IntegerField(default=0, help_text='\u7167\u7247\u70b9\u8d5e\u6570\u91cf', verbose_name='thumbup_num'), |
|
| 23 |
+ ), |
|
| 24 |
+ ] |
@@ -0,0 +1,19 @@ |
||
| 1 |
+# -*- coding: utf-8 -*- |
|
| 2 |
+from __future__ import unicode_literals |
|
| 3 |
+ |
|
| 4 |
+from django.db import models, migrations |
|
| 5 |
+ |
|
| 6 |
+ |
|
| 7 |
+class Migration(migrations.Migration): |
|
| 8 |
+ |
|
| 9 |
+ dependencies = [ |
|
| 10 |
+ ('group', '0011_auto_20160302_2048'),
|
|
| 11 |
+ ] |
|
| 12 |
+ |
|
| 13 |
+ operations = [ |
|
| 14 |
+ migrations.AddField( |
|
| 15 |
+ model_name='groupinfo', |
|
| 16 |
+ name='group_avatar', |
|
| 17 |
+ field=models.CharField(help_text='\u7fa4\u7ec4\u5934\u50cf', max_length=255, null=True, verbose_name='group_avatar', blank=True), |
|
| 18 |
+ ), |
|
| 19 |
+ ] |
@@ -19,6 +19,7 @@ class GroupInfo(CreateUpdateMixin): |
||
| 19 | 19 |
group_id = models.CharField(_(u'group_id'), max_length=255, blank=True, null=True, help_text=u'群组唯一标识', db_index=True, unique=True) |
| 20 | 20 |
admin_id = models.CharField(_(u'admin_id'), max_length=255, blank=True, null=True, help_text=u'用户唯一标识') |
| 21 | 21 |
group_name = models.CharField(_(u'group_name'), max_length=255, blank=True, null=True, help_text=u'群组名称') |
| 22 |
+ group_avatar = models.CharField(_(u'group_avatar'), max_length=255, blank=True, null=True, help_text=u'群组头像') |
|
| 22 | 23 |
group_desc = models.TextField(_(u'group_desc'), blank=True, null=True, help_text=u'群组描述') |
| 23 | 24 |
group_from = models.IntegerField(_(u'group_from'), choices=GROUP_FROM, default=APP_GROUP, help_text=u'群组来源') |
| 24 | 25 |
session_id = models.CharField(_(u'session_id'), max_length=255, blank=True, null=True, help_text=u'照片组唯一标识', db_index=True) |
@@ -114,6 +115,8 @@ class GroupPhotoInfo(CreateUpdateMixin): |
||
| 114 | 115 |
nickname = models.CharField(_(u'nickname'), max_length=255, blank=True, null=True, help_text=u'用户群组昵称') |
| 115 | 116 |
photo_path = models.CharField(_(u'photo_path'), max_length=255, blank=True, null=True, help_text=u'照片存放路径') |
| 116 | 117 |
photo_thumbnail_path = models.CharField(_(u'photo_thumbnail_path'), max_length=255, blank=True, null=True, help_text=u'照片缩略图存放路径') |
| 118 |
+ comment_num = models.IntegerField(_(u'comment_num'), default=0, help_text=u'照片评论数量') |
|
| 119 |
+ thumbup_num = models.IntegerField(_(u'thumbup_num'), default=0, help_text=u'照片点赞数量') |
|
| 117 | 120 |
|
| 118 | 121 |
class Meta: |
| 119 | 122 |
verbose_name = _(u'groupphotoinfo') |
@@ -137,6 +140,8 @@ class GroupPhotoInfo(CreateUpdateMixin): |
||
| 137 | 140 |
'photo_id': self.pk, |
| 138 | 141 |
'photo_url': self.photo_url, |
| 139 | 142 |
'photo_thumbnail_url': self.photo_thumbnail_url, |
| 143 |
+ 'comment_num': self.comment_num, |
|
| 144 |
+ 'thumbup_num': self.thumbup_num, |
|
| 140 | 145 |
} |
| 141 | 146 |
|
| 142 | 147 |
|
@@ -2,7 +2,7 @@ |
||
| 2 | 2 |
|
| 3 | 3 |
from django.conf import settings |
| 4 | 4 |
from django.core.files.storage import default_storage |
| 5 |
-from django.db import transaction |
|
| 5 |
+from django.db import connection, transaction |
|
| 6 | 6 |
from django.http import JsonResponse |
| 7 | 7 |
|
| 8 | 8 |
from rest_framework import viewsets |
@@ -640,6 +640,32 @@ def thumbup_cancel_api(request): |
||
| 640 | 640 |
}) |
| 641 | 641 |
|
| 642 | 642 |
|
| 643 |
+def pai2_home_api(request): |
|
| 644 |
+ user_id = request.POST.get('user_id', '')
|
|
| 645 |
+ |
|
| 646 |
+ cursor = connection.cursor() |
|
| 647 |
+ cursor.execute(r"select T1.group_id, T2.group_name, T2.group_avatar, T3.photo_thumbnail_path, T3.comment_num, T3.thumbup_num, T3.created_at from (select * from group_groupuserinfo where user_id='%s') as T1 left outer join group_groupinfo as T2 on T1.group_id = T2.group_id left outer join group_groupphotoinfo as T3 on T1.group_id = T3.group_id and T3.id > T1.current_id order by thumbup_num desc;" % user_id) |
|
| 648 |
+ rows = cursor.fetchall() |
|
| 649 |
+ |
|
| 650 |
+ rows = [{
|
|
| 651 |
+ 'group_id': row[0], |
|
| 652 |
+ 'group_name': row[1], |
|
| 653 |
+ 'group_avatar': row[2], |
|
| 654 |
+ 'photo_thumbnail_url': u'{0}/{1}'.format(settings.IMG_DOMAIN, row[3]) if row[3] else '',
|
|
| 655 |
+ 'comment_num': row[4], |
|
| 656 |
+ 'thumbup_num': row[5], |
|
| 657 |
+ 'created_at': row[6], |
|
| 658 |
+ } for row in rows] |
|
| 659 |
+ |
|
| 660 |
+ return JsonResponse({
|
|
| 661 |
+ 'status': 200, |
|
| 662 |
+ 'message': u'获取首页列表成功', |
|
| 663 |
+ 'data': {
|
|
| 664 |
+ 'photos': rows |
|
| 665 |
+ } |
|
| 666 |
+ }) |
|
| 667 |
+ |
|
| 668 |
+ |
|
| 643 | 669 |
class GroupInfoViewSet(viewsets.ModelViewSet): |
| 644 | 670 |
queryset = GroupInfo.objects.all().order_by('-pk')
|
| 645 | 671 |
serializer_class = GroupInfoSerializer |
@@ -0,0 +1,7 @@ |
||
| 1 |
+# -*- coding: utf-8 -*- |
|
| 2 |
+ |
|
| 3 |
+# 用户相关 |
|
| 4 |
+PROFILE_USER_INFO = 'profile:user:info:%s' # 用户信息,uid |
|
| 5 |
+ |
|
| 6 |
+# 群组相关 |
|
| 7 |
+GROUP_INFO = 'group:info:%s' # 群组信息,group_id |