add goods_status

FFIB 5 jaren geleden
bovenliggende
commit
ad4a1544a0
4 gewijzigde bestanden met toevoegingen van 36 en 4 verwijderingen
  1. 1 1
      api/admin_views.py
  2. 18 0
      live/migrations/0017_roomgoodsinfo_goods_status.py
  3. 13 0
      live/models.py
  4. 4 3
      live/views.py

+ 1 - 1
api/admin_views.py

@@ -531,4 +531,4 @@ def room_goods_add(request):
531 531
         room_goods.inventory = goods.get('inventory', 0)
532 532
         room_goods.save()
533 533
 
534
-    return response(200, 'Room Goods Add Success', u'直播间商品库添加成功')
534
+    return response(200, 'Room Goods Add Success', u'直播间商品库添加成功')

+ 18 - 0
live/migrations/0017_roomgoodsinfo_goods_status.py

@@ -0,0 +1,18 @@
1
+# Generated by Django 2.2.12 on 2020-05-26 07:40
2
+
3
+from django.db import migrations, models
4
+
5
+
6
+class Migration(migrations.Migration):
7
+
8
+    dependencies = [
9
+        ('live', '0016_auto_20200524_2041'),
10
+    ]
11
+
12
+    operations = [
13
+        migrations.AddField(
14
+            model_name='roomgoodsinfo',
15
+            name='goods_status',
16
+            field=models.IntegerField(choices=[(0, '上架'), (1, '草稿'), (2, '下架')], db_index=True, default=1, help_text='商品状态', verbose_name='goods_status'),
17
+        ),
18
+    ]

+ 13 - 0
live/models.py

@@ -181,10 +181,22 @@ class liveGoodsInfo(BaseModelMixin):
181 181
 
182 182
 
183 183
 class RoomGoodsInfo(BaseModelMixin):
184
+    PUBLISH = 0
185
+    DRAFT = 1
186
+    OFF = 2
187
+    # DELETED = 9
188
+
189
+    GOODS_STATUS = (
190
+        (PUBLISH, '上架'),
191
+        (DRAFT, '草稿'),
192
+        (OFF, '下架'),
193
+    )
194
+
184 195
     room_id = models.CharField(_('room_id'), max_length=32, help_text='房间唯一标识', db_index=True)
185 196
     anchor_id = models.CharField(_('anchor_id'), max_length=32, blank=True, help_text='主播唯一标识')
186 197
     goods_id = models.CharField(_('goods_id'), max_length=32, blank=True, help_text='商品ID')
187 198
     inventory = models.IntegerField(_('inventory'), default=0, help_text='直播间库存数量')
199
+    goods_status = models.IntegerField(_('goods_status'), choices=GOODS_STATUS, default=DRAFT, help_text='商品状态', db_index=True)
188 200
     sale_infos = JSONField(_('sale_infos'), blank=True, default=[], help_text='直播间商品销售信息')
189 201
 
190 202
     class Meta:
@@ -212,6 +224,7 @@ class RoomGoodsInfo(BaseModelMixin):
212 224
             'price': goods.price,
213 225
             'price2': goods.price2,
214 226
             'inventory': self.inventory,
227
+            'goods_status': self.goods_status,
215 228
             'sale_count': len(self.sale_infos),
216 229
         }
217 230
 

+ 4 - 3
live/views.py

@@ -50,12 +50,12 @@ def room_goods_detail(request):
50 50
   try:
51 51
     room_goods_info = RoomGoodsInfo.objects.get(goods_id=goods_id, room_id=room_id)
52 52
   except:
53
-    return response()
53
+    return response(400001, 'Room Goods Not Found', '直播间商品不存在')
54 54
   
55 55
   try:
56 56
     goods_info = liveGoodsInfo.objects.get(goods_id=goods_id)
57 57
   except:
58
-    return response()
58
+    return response(400001, 'Live Goods Not Found', '直播商品不存在')
59 59
 
60 60
   return response(200, 'Get Room Goods Detail Success', '获取直播间商品成功', data={
61 61
         'goods_info': {
@@ -64,6 +64,7 @@ def room_goods_detail(request):
64 64
           'price_type': goods_info.price_type,
65 65
           'price': goods_info.price,
66 66
           'price2': goods_info.price2,
67
+          'goods_status': room_goods_info.goods_status,
67 68
           'inventory': room_goods_info.inventory,
68 69
         },
69 70
         'anchor_id': room_goods_info.anchor_id,
@@ -140,7 +141,7 @@ def live_order_create(request):
140 141
     # 金额校验
141 142
     try:
142 143
         goods_info = liveGoodsInfo.objects.get(goods_id=goods_id)
143
-        if amount * int(goods_info.price) != total_fee:
144
+        if amount * int(goods_info.price if goods_info.price_type else goods_info.price2) != total_fee:
144 145
             return response(404091, 'FEE Check Fail', description='金额校验失败')
145 146
     except:
146 147
         return response(404091, 'FEE Check Fail', description='金额校验失败')