10
+    initial = True
11
+
12
+    dependencies = [
13
+    ]
14
+
15
+    operations = [
16
+        migrations.CreateModel(
17
+            name='DistributorSaleStatisticInfo',
18
+            fields=[
19
+                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
20
+                ('status', models.BooleanField(db_index=True, default=True, help_text='Status', verbose_name='status')),
21
+                ('created_at', models.DateTimeField(auto_now_add=True, help_text='Create Time', verbose_name='created_at')),
22
+                ('updated_at', models.DateTimeField(auto_now=True, help_text='Update Time', verbose_name='updated_at')),
23
+                ('distributor_id', models.CharField(db_index=True, help_text='\u7ecf\u9500\u5546\u552f\u4e00\u6807\u8bc6', max_length=32, verbose_name='distributor_id')),
24
+                ('distributor_name', models.CharField(blank=True, help_text='\u7ecf\u9500\u5546\u540d\u79f0', max_length=255, null=True, verbose_name='distributor_name')),
25
+                ('ymd', models.CharField(blank=True, db_index=True, help_text='\u5e74\u6708\u65e5', max_length=8, null=True, verbose_name='ymd')),
26
+                ('num', models.IntegerField(default=0, help_text='\u6570\u91cf', verbose_name='num')),
27
+            ],
28
+            options={
29
+                'verbose_name': '\u7ecf\u9500\u5546\u9500\u91cf\u7edf\u8ba1',
30
+                'verbose_name_plural': '\u7ecf\u9500\u5546\u9500\u91cf\u7edf\u8ba1',
31
+            },
32
+        ),
33
+        migrations.CreateModel(
34
+            name='ModelSaleStatisticInfo',
35
+            fields=[
36
+                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
37
+                ('status', models.BooleanField(db_index=True, default=True, help_text='Status', verbose_name='status')),
38
+                ('created_at', models.DateTimeField(auto_now_add=True, help_text='Create Time', verbose_name='created_at')),
39
+                ('updated_at', models.DateTimeField(auto_now=True, help_text='Update Time', verbose_name='updated_at')),
40
+                ('model_id', models.CharField(db_index=True, help_text='\u578b\u53f7\u552f\u4e00\u6807\u8bc6', max_length=32, verbose_name='model_id')),
41
+                ('model_name', models.CharField(blank=True, help_text='\u578b\u53f7\u540d\u79f0', max_length=255, null=True, verbose_name='model_name')),
42
+                ('ymd', models.CharField(blank=True, db_index=True, help_text='\u5e74\u6708\u65e5', max_length=8, null=True, verbose_name='ymd')),
43
+                ('num', models.IntegerField(default=0, help_text='\u6570\u91cf', verbose_name='num')),
44
+            ],
45
+            options={
46
+                'verbose_name': '\u578b\u53f7\u9500\u91cf\u7edf\u8ba1',
47
+                'verbose_name_plural': '\u578b\u53f7\u9500\u91cf\u7edf\u8ba1',
48
+            },
49
+        ),
50
+        migrations.CreateModel(
51
+            name='RegisterStatisticInfo',
52
+            fields=[
53
+                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
54
+                ('status', models.BooleanField(db_index=True, default=True, help_text='Status', verbose_name='status')),
55
+                ('created_at', models.DateTimeField(auto_now_add=True, help_text='Create Time', verbose_name='created_at')),
56
+                ('updated_at', models.DateTimeField(auto_now=True, help_text='Update Time', verbose_name='updated_at')),
57
+                ('ymd', models.CharField(blank=True, db_index=True, help_text='\u5e74\u6708\u65e5', max_length=8, null=True, verbose_name='ymd')),
58
+                ('num', models.IntegerField(default=0, help_text='\u6570\u91cf', verbose_name='num')),
59
+            ],
60
+            options={
61
+                'verbose_name': '\u6ce8\u518c\u7528\u6237\u7edf\u8ba1',
62
+                'verbose_name_plural': '\u6ce8\u518c\u7528\u6237\u7edf\u8ba1',
63
+            },
64
+        ),
65
+        migrations.CreateModel(
66
+            name='SaleStatisticInfo',
67
+            fields=[
68
+                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
69
+                ('status', models.BooleanField(db_index=True, default=True, help_text='Status', verbose_name='status')),
70
+                ('created_at', models.DateTimeField(auto_now_add=True, help_text='Create Time', verbose_name='created_at')),
71
+                ('updated_at', models.DateTimeField(auto_now=True, help_text='Update Time', verbose_name='updated_at')),
72
+                ('ymd', models.CharField(blank=True, db_index=True, help_text='\u5e74\u6708\u65e5', max_length=8, null=True, verbose_name='ymd')),
73
+                ('num', models.IntegerField(default=0, help_text='\u6570\u91cf', verbose_name='num')),
74
+            ],
75
+            options={
76
+                'verbose_name': '\u9500\u91cf\u7edf\u8ba1',
77
+                'verbose_name_plural': '\u9500\u91cf\u7edf\u8ba1',
78
+            },
79
+        ),
80
+    ]

+ 0 - 0
statistic/migrations/__init__.py


+ 89 - 0
statistic/models.py

@@ -0,0 +1,89 @@
1
+# -*- coding: utf-8 -*-
2
+
3
+from django.db import models
4
+from django.utils.translation import ugettext_lazy as _
5
+from django_models_ext import BaseModelMixin
6
+
7
+
8
+class RegisterStatisticInfo(BaseModelMixin):
9
+    ymd = models.CharField(_(u'ymd'), max_length=8, blank=True, null=True, help_text=u'年月日', db_index=True)  # 例:20171208, tc.local_string(format='%Y%m%d')
10
+    num = models.IntegerField(_(u'num'), default=0, help_text=u'数量')
11
+
12
+    class Meta:
13
+        verbose_name = _(u'注册用户统计')
14
+        verbose_name_plural = _(u'注册用户统计')
15
+
16
+    def __unicode__(self):
17
+        return unicode(self.pk)
18
+
19
+    @property
20
+    def data(self):
21
+        return {
22
+            'ymd': self.ymd,
23
+            'num': self.num,
24
+        }
25
+
26
+
27
+class SaleStatisticInfo(BaseModelMixin):
28
+    ymd = models.CharField(_(u'ymd'), max_length=8, blank=True, null=True, help_text=u'年月日', db_index=True)  # 例:20171208, tc.local_string(format='%Y%m%d')
29
+    num = models.IntegerField(_(u'num'), default=0, help_text=u'数量')
30
+
31
+    class Meta:
32
+        verbose_name = _(u'销量统计')
33
+        verbose_name_plural = _(u'销量统计')
34
+
35
+    def __unicode__(self):
36
+        return unicode(self.pk)
37
+
38
+    @property
39
+    def data(self):
40
+        return {
41
+            'ymd': self.ymd,
42
+            'num': self.num,
43
+        }
44
+
45
+
46
+class ModelSaleStatisticInfo(BaseModelMixin):
47
+    model_id = models.CharField(_(u'model_id'), max_length=32, help_text=u'型号唯一标识', db_index=True)
48
+    model_name = models.CharField(_(u'model_name'), max_length=255, blank=True, null=True, help_text=u'型号名称')
49
+    ymd = models.CharField(_(u'ymd'), max_length=8, blank=True, null=True, help_text=u'年月日', db_index=True)  # 例:20171208, tc.local_string(format='%Y%m%d')
50
+    num = models.IntegerField(_(u'num'), default=0, help_text=u'数量')
51
+
52
+    class Meta:
53
+        verbose_name = _(u'型号销量统计')
54
+        verbose_name_plural = _(u'型号销量统计')
55
+
56
+    def __unicode__(self):
57
+        return unicode(self.pk)
58
+
59
+    @property
60
+    def data(self):
61
+        return {
62
+            'model_id': self.model_id,
63
+            'model_name': self.model_name,
64
+            'ymd': self.ymd,
65
+            'num': self.num,
66
+        }
67
+
68
+
69
+class DistributorSaleStatisticInfo(BaseModelMixin):
70
+    distributor_id = models.CharField(_(u'distributor_id'), max_length=32, help_text=u'经销商唯一标识', db_index=True)
71
+    distributor_name = models.CharField(_(u'distributor_name'), max_length=255, blank=True, null=True, help_text=u'经销商名称')
72
+    ymd = models.CharField(_(u'ymd'), max_length=8, blank=True, null=True, help_text=u'年月日', db_index=True)  # 例:20171208, tc.local_string(format='%Y%m%d')
73
+    num = models.IntegerField(_(u'num'), default=0, help_text=u'数量')
74
+
75
+    class Meta:
76
+        verbose_name = _(u'经销商销量统计')
77
+        verbose_name_plural = _(u'经销商销量统计')
78
+
79
+    def __unicode__(self):
80
+        return unicode(self.pk)
81
+
82
+    @property
83
+    def data(self):
84
+        return {
85
+            'distributor_id': self.distributor_id,
86
+            'distributor_name': self.distributor_name,
87
+            'ymd': self.ymd,
88
+            'num': self.num,
89
+        }

+ 7 - 0
statistic/tests.py

@@ -0,0 +1,7 @@
1
+# -*- coding: utf-8 -*-
2
+from __future__ import unicode_literals
3
+
4
+from django.test import TestCase
5
+
6
+
7
+# Create your tests here.

+ 50 - 0
statistic/views.py

@@ -0,0 +1,50 @@
1
+# -*- coding: utf-8 -*-
2
+
3
+from django_logit import logit
4
+from django_response import response
5
+from TimeConvert import TimeConvert as tc
6
+
7
+from statistic.models import (DistributorSaleStatisticInfo, ModelSaleStatisticInfo, RegisterStatisticInfo,
8
+                              SaleStatisticInfo)
9
+
10
+
11
+@logit
12
+def tj_data(request):
13
+    ymd = tc.local_string(format='%Y%m%d')
14
+
15
+    # 注册用户统计 & 今日注册用户
16
+    try:
17
+        register_num = RegisterStatisticInfo.objects.get(ymd=ymd).num
18
+    except RegisterStatisticInfo.DoesNotExist:
19
+        register_num = 0
20
+
21
+    # 注册用户数趋势
22
+    register_trends = RegisterStatisticInfo.objects.filter(status=True).order_by('-pk')[:30]
23
+    register_trends = [r.data for r in register_trends]
24
+
25
+    # 销量统计 & 今日销量
26
+    try:
27
+        sale_num = SaleStatisticInfo.objects.get(ymd=ymd).num
28
+    except RegisterStatisticInfo.DoesNotExist:
29
+        sale_num = 0
30
+
31
+    # 商品销量趋势
32
+    sale_trends = SaleStatisticInfo.objects.filter(status=True).order_by('-pk')[:30]
33
+    sale_trends = [s.data for s in sale_trends]
34
+
35
+    # 型号销量统计 & 热销商品榜
36
+    model_sales = ModelSaleStatisticInfo.objects.filter(status=True).order_by('-num')[:3]
37
+    model_sales = [m.data for m in model_sales]
38
+
39
+    # 经销商销量统计 & 经销商榜
40
+    distributor_sales = DistributorSaleStatisticInfo.objects.filter(status=True).order_by('-num')[:3]
41
+    distributor_sales = [d.data for d in distributor_sales]
42
+
43
+    return response(200, 'Get TJ Data Success', u'获取统计数据成功', {
44
+        'register_num': register_num,
45
+        'register_trends': register_trends,
46
+        'sale_num': sale_num,
47
+        'sale_trends': sale_trends,
48
+        'model_sales': model_sales,
49
+        'distributor_sales': distributor_sales,
50
+    })

+ 5 - 0
utils/error/errno_utils.py

@@ -25,6 +25,11 @@ class ProductModelStatusCode(BaseStatusCode):
25 25
     MODEL_NOT_FOUND = StatusCodeField(501001, 'Model Not Found', description=u'型号不存在')
26 26
 
27 27
 
28
+class ProductDistributorStatusCode(BaseStatusCode):
29
+    """ 经销商相关错误码 5011xx """
30
+    DISTRIBUTOR_NOT_FOUND = StatusCodeField(501101, 'Distributor Not Found', description=u'经销商不存在')
31
+
32
+
28 33
 class ProductStatusCode(BaseStatusCode):
29 34
     """ 产品相关错误码 5020xx """
30 35
     PRODUCT_NOT_FOUND = StatusCodeField(502001, 'Product Not Found', description=u'产品不存在')

add api comment_submit_api/comment_list_api/thumbup_submit_api/thumbup_list_api/thumbup_cancel_api · c72d89f6e5 - Gogs: Go Git Service

add api comment_submit_api/comment_list_api/thumbup_submit_api/thumbup_list_api/thumbup_cancel_api

Brightcells 10 jaren geleden
bovenliggende
commit
c72d89f6e5
8 gewijzigde bestanden met toevoegingen van 352 en 7 verwijderingen
  1. 5 0
      api/urls.py
  2. 4 1
      docs/errorcode
  3. 13 1
      group/admin.py
  4. 32 0
      group/migrations/0008_photocommentinfo.py
  5. 32 0
      group/migrations/0009_photothumbupinfo.py
  6. 48 0
      group/models.py
  7. 218 1
      group/views.py
  8. 0 4
      operation/views.py

+ 5 - 0
api/urls.py

@@ -33,6 +33,11 @@ urlpatterns += [
33 33
 urlpatterns += [
34 34
     url(r'^f/upload$', group_views.flyimg_upload_api, name='flyimg_upload_api'),  # 飞图上传
35 35
     url(r'^f/list$', group_views.flyimg_upload_api, name='flyimg_list_api'),  # 飞图列表
36
+    url(r'^f/comment/submit$', group_views.comment_submit_api, name='comment_submit_api'),  # 飞图评论提交
37
+    url(r'^f/comment/list$', group_views.comment_submit_api, name='comment_list_api'),  # 飞图评论列表
38
+    url(r'^f/thumbup/submit$', group_views.thumbup_submit_api, name='thumbup_submit_api'),  # 飞图点赞提交
39
+    url(r'^f/thumbup/list$', group_views.thumbup_list_api, name='thumbup_list_api'),  # 飞图点赞列表
40
+    url(r'^f/thumbup/cancel$', group_views.thumbup_cancel_api, name='thumbup_cancel_api'),  # 飞图点赞取消
36 41
 ]
37 42
 
38 43
 urlpatterns += [

+ 4 - 1
docs/errorcode

@@ -24,4 +24,7 @@
24 24
         40224 —— 没有拒绝权限
25 25
     4027 —— 重复加群申请
26 26
     4028 —— 加群申请不存在
27
-    4029 —— 该用户不在群组
27
+    4029 —— 该用户不在群组
28
+
29
+4、飞图信息 —— 403
30
+    4030 —— 飞图不存在

+ 13 - 1
group/admin.py

@@ -2,7 +2,7 @@
2 2
 
3 3
 from django.contrib import admin
4 4
 
5
-from group.models import GroupInfo, GroupUserInfo, GroupPhotoInfo
5
+from group.models import GroupInfo, GroupUserInfo, GroupPhotoInfo, PhotoCommentInfo, PhotoThumbUpInfo
6 6
 
7 7
 
8 8
 class GroupInfoAdmin(admin.ModelAdmin):
@@ -20,6 +20,18 @@ class GroupPhotoInfoAdmin(admin.ModelAdmin):
20 20
     list_filter = ('status', )
21 21
 
22 22
 
23
+class PhotoCommentInfoAdmin(admin.ModelAdmin):
24
+    list_display = ('photo_id', 'user_id', 'nickname', 'avatar', 'comment', 'status', 'created_at', 'updated_at')
25
+    list_filter = ('status', )
26
+
27
+
28
+class PhotoThumbUpInfoAdmin(admin.ModelAdmin):
29
+    list_display = ('photo_id', 'user_id', 'nickname', 'avatar', 'thumbup', 'status', 'created_at', 'updated_at')
30
+    list_filter = ('thumbup', 'status')
31
+
32
+
23 33
 admin.site.register(GroupInfo, GroupInfoAdmin)
24 34
 admin.site.register(GroupUserInfo, GroupUserInfoAdmin)
25 35
 admin.site.register(GroupPhotoInfo, GroupPhotoInfoAdmin)
36
+admin.site.register(PhotoCommentInfo, PhotoCommentInfoAdmin)
37
+admin.site.register(PhotoThumbUpInfo, PhotoThumbUpInfoAdmin)

+ 32 - 0
group/migrations/0008_photocommentinfo.py

@@ -0,0 +1,32 @@
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', '0007_auto_20160112_2040'),
11
+    ]
12
+
13
+    operations = [
14
+        migrations.CreateModel(
15
+            name='PhotoCommentInfo',
16
+            fields=[
17
+                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
18
+                ('status', models.BooleanField(default=True, help_text='\u72b6\u6001', verbose_name='status')),
19
+                ('created_at', models.DateTimeField(help_text='\u521b\u5efa\u65f6\u95f4', verbose_name='created_at', auto_now_add=True)),
20
+                ('updated_at', models.DateTimeField(help_text='\u66f4\u65b0\u65f6\u95f4', verbose_name='updated_at', auto_now=True)),
21
+                ('photo_id', models.CharField(max_length=255, blank=True, help_text='\u98de\u56fe\u552f\u4e00\u6807\u8bc6', null=True, verbose_name='photo_id', db_index=True)),
22
+                ('user_id', models.CharField(help_text='\u7528\u6237\u552f\u4e00\u6807\u8bc6', max_length=255, null=True, verbose_name='user_id', blank=True)),
23
+                ('nickname', models.CharField(help_text='\u7528\u6237\u7fa4\u7ec4\u6635\u79f0', max_length=255, null=True, verbose_name='nickname', blank=True)),
24
+                ('avatar', models.CharField(help_text='\u7528\u6237\u5934\u50cf', max_length=255, null=True, verbose_name='avatar', blank=True)),
25
+                ('comment', models.TextField(help_text='\u7528\u6237\u8bc4\u8bba', null=True, verbose_name='comment', blank=True)),
26
+            ],
27
+            options={
28
+                'verbose_name': 'photocommentinfo',
29
+                'verbose_name_plural': 'photocommentinfo',
30
+            },
31
+        ),
32
+    ]

+ 32 - 0
group/migrations/0009_photothumbupinfo.py

@@ -0,0 +1,32 @@
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', '0008_photocommentinfo'),
11
+    ]
12
+
13
+    operations = [
14
+        migrations.CreateModel(
15
+            name='PhotoThumbUpInfo',
16
+            fields=[
17
+                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
18
+                ('status', models.BooleanField(default=True, help_text='\u72b6\u6001', verbose_name='status')),
19
+                ('created_at', models.DateTimeField(help_text='\u521b\u5efa\u65f6\u95f4', verbose_name='created_at', auto_now_add=True)),
20
+                ('updated_at', models.DateTimeField(help_text='\u66f4\u65b0\u65f6\u95f4', verbose_name='updated_at', auto_now=True)),
21
+                ('photo_id', models.CharField(max_length=255, blank=True, help_text='\u98de\u56fe\u552f\u4e00\u6807\u8bc6', null=True, verbose_name='photo_id', db_index=True)),
22
+                ('user_id', models.CharField(help_text='\u7528\u6237\u552f\u4e00\u6807\u8bc6', max_length=255, null=True, verbose_name='user_id', blank=True)),
23
+                ('nickname', models.CharField(help_text='\u7528\u6237\u7fa4\u7ec4\u6635\u79f0', max_length=255, null=True, verbose_name='nickname', blank=True)),
24
+                ('avatar', models.CharField(help_text='\u7528\u6237\u5934\u50cf', max_length=255, null=True, verbose_name='avatar', blank=True)),
25
+                ('thumbup', models.BooleanField(default=True, help_text='\u7528\u6237\u70b9\u8d5e', db_index=True, verbose_name='thumbup')),
26
+            ],
27
+            options={
28
+                'verbose_name': 'photothumbupinfo',
29
+                'verbose_name_plural': 'photothumbupinfo',
30
+            },
31
+        ),
32
+    ]

+ 48 - 0
group/models.py

@@ -137,3 +137,51 @@ class GroupPhotoInfo(CreateUpdateMixin):
137 137
             'photo_path': self.photo_url,
138 138
             'photo_thumbnail_path': self.photo_thumbnail_url,
139 139
         }
140
+
141
+
142
+class PhotoCommentInfo(CreateUpdateMixin):
143
+    photo_id = models.CharField(_(u'photo_id'), max_length=255, blank=True, null=True, help_text=u'飞图唯一标识', db_index=True)
144
+    user_id = models.CharField(_(u'user_id'), max_length=255, blank=True, null=True, help_text=u'用户唯一标识')
145
+    nickname = models.CharField(_(u'nickname'), max_length=255, blank=True, null=True, help_text=u'用户群组昵称')
146
+    avatar = models.CharField(_(u'avatar'), max_length=255, blank=True, null=True, help_text=u'用户头像')
147
+    comment = models.TextField(_(u'comment'), blank=True, null=True, help_text=u'用户评论')
148
+
149
+    class Meta:
150
+        verbose_name = _(u'photocommentinfo')
151
+        verbose_name_plural = _(u'photocommentinfo')
152
+
153
+    def __unicode__(self):
154
+        return unicode(self.pk)
155
+
156
+    @property
157
+    def comment_info(self):
158
+        return {
159
+            'user_id': self.user_id,
160
+            'nickname': self.nickname,
161
+            'avatar': self.avatar,
162
+            'comment': self.comment,
163
+            'created_at': self.created_at,
164
+        }
165
+
166
+
167
+class PhotoThumbUpInfo(CreateUpdateMixin):
168
+    photo_id = models.CharField(_(u'photo_id'), max_length=255, blank=True, null=True, help_text=u'飞图唯一标识', db_index=True)
169
+    user_id = models.CharField(_(u'user_id'), max_length=255, blank=True, null=True, help_text=u'用户唯一标识')
170
+    nickname = models.CharField(_(u'nickname'), max_length=255, blank=True, null=True, help_text=u'用户群组昵称')
171
+    avatar = models.CharField(_(u'avatar'), max_length=255, blank=True, null=True, help_text=u'用户头像')
172
+    thumbup = models.BooleanField(_(u'thumbup'), default=True, help_text=u'用户点赞', db_index=True)
173
+
174
+    class Meta:
175
+        verbose_name = _(u'photothumbupinfo')
176
+        verbose_name_plural = _(u'photothumbupinfo')
177
+
178
+    def __unicode__(self):
179
+        return unicode(self.pk)
180
+
181
+    @property
182
+    def thumbup_info(self):
183
+        return {
184
+            'user_id': self.user_id,
185
+            'nickname': self.nickname,
186
+            'avatar': self.avatar,
187
+        }

+ 218 - 1
group/views.py

@@ -8,7 +8,7 @@ from django.http import JsonResponse
8 8
 from rest_framework import viewsets
9 9
 
10 10
 from account.models import UserInfo
11
-from group.models import GroupInfo, GroupUserInfo, GroupPhotoInfo
11
+from group.models import GroupInfo, GroupUserInfo, GroupPhotoInfo, PhotoCommentInfo, PhotoThumbUpInfo
12 12
 from group.serializers import GroupInfoSerializer, GroupUserInfoSerializer, GroupPhotoInfoSerializer
13 13
 
14 14
 from utils.thumbnail_utils import make_thumb
@@ -517,6 +517,223 @@ def flyimg_upload_api(request):
517 517
     })
518 518
 
519 519
 
520
+def comment_submit_api(request):
521
+    group_id = request.POST.get('group_id', '')
522
+    user_id = request.POST.get('user_id', '')
523
+    photo_id = request.POST.get('photo_id', '')
524
+    comment = request.POST.get('comment', '')
525
+
526
+    current_id = int(request.POST.get('current_id', -1))
527
+
528
+    try:
529
+        group = GroupInfo.objects.get(group_id=group_id)
530
+    except GroupInfo.DoesNotExist:
531
+        return JsonResponse({
532
+            'status': 4020,
533
+            'message': u'群组不存在',
534
+        })
535
+
536
+    try:
537
+        group_user = GroupUserInfo.objects.get(group_id=group_id, user_id=user_id, user_status=GroupUserInfo.PASSED)
538
+    except GroupUserInfo.DoesNotExist:
539
+        return JsonResponse({
540
+            'status': 4029,
541
+            'message': u'该用户不在群组',
542
+        })
543
+
544
+    try:
545
+        group_photo = GroupPhotoInfo.objects.get(pk=photo_id)
546
+    except GroupPhotoInfo.DoesNotExist:
547
+        return JsonResponse({
548
+            'status': 4030,
549
+            'message': u'飞图不存在',
550
+        })
551
+
552
+    if comment:
553
+        PhotoCommentInfo.objects.create(
554
+            photo_id=photo_id,
555
+            user_id=user_id,
556
+            nickname=group_user.nickname,
557
+            avatar=group_user.avatar,
558
+            comment=comment,
559
+        )
560
+
561
+    photo_comments = PhotoCommentInfo.objects.filter(
562
+        photo_id=photo_id,
563
+        pk__gt=current_id
564
+    )
565
+    latest_comment = photo_comments.last()
566
+
567
+    return JsonResponse({
568
+        'status': 200,
569
+        'message': u'评论成功',
570
+        'data': {
571
+            'current_id': latest_comment and latest_comment.pk or current_id,
572
+            'comments': [comment.comment_info for comment in photo_comments],
573
+        }
574
+    })
575
+
576
+
577
+def thumbup_submit_api(request):
578
+    group_id = request.POST.get('group_id', '')
579
+    user_id = request.POST.get('user_id', '')
580
+    photo_id = request.POST.get('photo_id', '')
581
+
582
+    try:
583
+        group = GroupInfo.objects.get(group_id=group_id)
584
+    except GroupInfo.DoesNotExist:
585
+        return JsonResponse({
586
+            'status': 4020,
587
+            'message': u'群组不存在',
588
+        })
589
+
590
+    try:
591
+        group_user = GroupUserInfo.objects.get(group_id=group_id, user_id=user_id, user_status=GroupUserInfo.PASSED)
592
+    except GroupUserInfo.DoesNotExist:
593
+        return JsonResponse({
594
+            'status': 4029,
595
+            'message': u'该用户不在群组',
596
+        })
597
+
598
+    try:
599
+        group_photo = GroupPhotoInfo.objects.get(pk=photo_id)
600
+    except GroupPhotoInfo.DoesNotExist:
601
+        return JsonResponse({
602
+            'status': 4030,
603
+            'message': u'飞图不存在',
604
+        })
605
+
606
+    photo_thumbup, created = PhotoThumbUpInfo.objects.get_or_create(
607
+        photo_id=photo_id,
608
+        user_id=user_id,
609
+        # defaults={
610
+        #     'nickname': group_user.nickname,
611
+        #     'avatar': group_user.avatar,
612
+        # }
613
+    )
614
+    photo_thumbup.nickname = group_user.nickname
615
+    photo_thumbup.avatar = group_user.avatar
616
+    photo_thumbup.thumbup = True
617
+    photo_thumbup.save()
618
+
619
+    photo_thumbups = PhotoThumbUpInfo.objects.filter(
620
+        photo_id=photo_id,
621
+        thumbup=True,
622
+    )
623
+
624
+    return JsonResponse({
625
+        'status': 200,
626
+        'message': u'点赞提交成功',
627
+        'data': {
628
+            'thumbup': True,
629
+            'thumbups': [thumbup.thumbup_info for thumbup in photo_thumbups],
630
+        }
631
+    })
632
+
633
+
634
+def thumbup_list_api(request):
635
+    group_id = request.POST.get('group_id', '')
636
+    user_id = request.POST.get('user_id', '')
637
+    photo_id = request.POST.get('photo_id', '')
638
+
639
+    try:
640
+        group = GroupInfo.objects.get(group_id=group_id)
641
+    except GroupInfo.DoesNotExist:
642
+        return JsonResponse({
643
+            'status': 4020,
644
+            'message': u'群组不存在',
645
+        })
646
+
647
+    try:
648
+        group_user = GroupUserInfo.objects.get(group_id=group_id, user_id=user_id, user_status=GroupUserInfo.PASSED)
649
+    except GroupUserInfo.DoesNotExist:
650
+        return JsonResponse({
651
+            'status': 4029,
652
+            'message': u'该用户不在群组',
653
+        })
654
+
655
+    try:
656
+        group_photo = GroupPhotoInfo.objects.get(pk=photo_id)
657
+    except GroupPhotoInfo.DoesNotExist:
658
+        return JsonResponse({
659
+            'status': 4030,
660
+            'message': u'飞图不存在',
661
+        })
662
+
663
+    try:
664
+        thumbup = PhotoThumbUpInfo.objects.get(
665
+            photo_id=photo_id,
666
+            user_id=user_id,
667
+        ).thumbup
668
+    except PhotoThumbUpInfo.DoesNotExist:
669
+        thumbup = False
670
+
671
+    photo_thumbups = PhotoThumbUpInfo.objects.filter(
672
+        photo_id=photo_id,
673
+        thumbup=True,
674
+    )
675
+
676
+    return JsonResponse({
677
+        'status': 200,
678
+        'message': u'获取点赞列表成功',
679
+        'data': {
680
+            'thumbup': thumbup,
681
+            'thumbups': [thumbup.thumbup_info for thumbup in photo_thumbups],
682
+        }
683
+    })
684
+
685
+
686
+def thumbup_cancel_api(request):
687
+    group_id = request.POST.get('group_id', '')
688
+    user_id = request.POST.get('user_id', '')
689
+    photo_id = request.POST.get('photo_id', '')
690
+
691
+    try:
692
+        group = GroupInfo.objects.get(group_id=group_id)
693
+    except GroupInfo.DoesNotExist:
694
+        return JsonResponse({
695
+            'status': 4020,
696
+            'message': u'群组不存在',
697
+        })
698
+
699
+    try:
700
+        group_user = GroupUserInfo.objects.get(group_id=group_id, user_id=user_id, user_status=GroupUserInfo.PASSED)
701
+    except GroupUserInfo.DoesNotExist:
702
+        return JsonResponse({
703
+            'status': 4029,
704
+            'message': u'该用户不在群组',
705
+        })
706
+
707
+    try:
708
+        group_photo = GroupPhotoInfo.objects.get(pk=photo_id)
709
+    except GroupPhotoInfo.DoesNotExist:
710
+        return JsonResponse({
711
+            'status': 4030,
712
+            'message': u'飞图不存在',
713
+        })
714
+
715
+    photo_thumbup, created = PhotoThumbUpInfo.objects.get_or_create(
716
+        photo_id=photo_id,
717
+        user_id=user_id,
718
+    )
719
+    photo_thumbup.thumbup = False
720
+    photo_thumbup.save()
721
+
722
+    photo_thumbups = PhotoThumbUpInfo.objects.filter(
723
+        photo_id=photo_id,
724
+        thumbup=True,
725
+    )
726
+
727
+    return JsonResponse({
728
+        'status': 200,
729
+        'message': u'点赞取消成功',
730
+        'data': {
731
+            'thumbup': False,
732
+            'thumbups': [thumbup.thumbup_info for thumbup in photo_thumbups],
733
+        }
734
+    })
735
+
736
+
520 737
 class GroupInfoViewSet(viewsets.ModelViewSet):
521 738
     queryset = GroupInfo.objects.all().order_by('-created_at')
522 739
     serializer_class = GroupInfoSerializer

+ 0 - 4
operation/views.py

@@ -1,10 +1,6 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 
3
-from django.conf import settings
4
-from django.core.files.storage import default_storage
5
-from django.db import transaction
6 3
 from django.http import JsonResponse
7
-from django.shortcuts import render, redirect
8 4
 
9 5
 from operation.models import LatestAppInfo, SplashInfo
10 6