@@ -0,0 +1,23 @@ |
||
| 1 |
+# Generated by Django 2.2.12 on 2020-04-22 10:18 |
|
| 2 |
+ |
|
| 3 |
+from django.db import migrations, models |
|
| 4 |
+ |
|
| 5 |
+ |
|
| 6 |
+class Migration(migrations.Migration): |
|
| 7 |
+ |
|
| 8 |
+ dependencies = [ |
|
| 9 |
+ ('goods', '0004_auto_20200422_1216'),
|
|
| 10 |
+ ] |
|
| 11 |
+ |
|
| 12 |
+ operations = [ |
|
| 13 |
+ migrations.AddField( |
|
| 14 |
+ model_name='packgoodsinfo', |
|
| 15 |
+ name='has_sale_num', |
|
| 16 |
+ field=models.IntegerField(default=0, help_text='已购数量', verbose_name='has_sale_num'), |
|
| 17 |
+ ), |
|
| 18 |
+ migrations.AddField( |
|
| 19 |
+ model_name='packgoodsinfo', |
|
| 20 |
+ name='inventory', |
|
| 21 |
+ field=models.IntegerField(default=0, help_text='库存数量', verbose_name='inventory'), |
|
| 22 |
+ ), |
|
| 23 |
+ ] |
@@ -71,6 +71,8 @@ class PackInfo(BaseModelMixin): |
||
| 71 | 71 |
class PackGoodsInfo(BaseModelMixin): |
| 72 | 72 |
pack_id = models.CharField(_('pack_id'), max_length=32, blank=True, null=True, help_text='包唯一标识', db_index=True)
|
| 73 | 73 |
good_id = models.CharField(_('good_id'), max_length=32, blank=True, null=True, help_text='商品唯一标识', db_index=True)
|
| 74 |
+ inventory = models.IntegerField(_('inventory'), default=0, help_text='库存数量')
|
|
| 75 |
+ has_sale_num = models.IntegerField(_('has_sale_num'), default=0, help_text='已购数量')
|
|
| 74 | 76 |
|
| 75 | 77 |
class Meta: |
| 76 | 78 |
verbose_name = _('包-商品信息')
|
@@ -85,7 +87,10 @@ class PackGoodsInfo(BaseModelMixin): |
||
| 85 | 87 |
good = GoodsInfo.objects.get(good_id=self.good_id) |
| 86 | 88 |
except GoodsInfo.DoesNotExist: |
| 87 | 89 |
good = {}
|
| 88 |
- return good.data |
|
| 90 |
+ |
|
| 91 |
+ data = good.data |
|
| 92 |
+ data.update({'inventory': self.inventory, 'has_sale_num': self.has_sale_num})
|
|
| 93 |
+ return data |
|
| 89 | 94 |
|
| 90 | 95 |
|
| 91 | 96 |
class PackGoodsSaleInfo(BaseModelMixin): |
@@ -61,7 +61,9 @@ def wx_order_create_api(request): |
||
| 61 | 61 |
# 包-商品校验 |
| 62 | 62 |
for g in goods_info: |
| 63 | 63 |
try: |
| 64 |
- PackGoodsInfo.objects.get(pack_id=pack_id, good_id=g.get('good_id', ''))
|
|
| 64 |
+ good = PackGoodsInfo.objects.get(pack_id=pack_id, good_id=g.get('good_id', ''))
|
|
| 65 |
+ if good.inventory - g.get('num', 0) <= 0:
|
|
| 66 |
+ return response(PackGoodsStatusCode.PACK_GOODS_INVENTORY_SHORTAGE) |
|
| 65 | 67 |
except PackGoodsInfo.DoesNotExist: |
| 66 | 68 |
return response(PackGoodsStatusCode.PACK_GOODS_NOT_FOUND) |
| 67 | 69 |
|
@@ -142,6 +144,15 @@ def order_paid_success(order): |
||
| 142 | 144 |
saleinfo=order.goods_info |
| 143 | 145 |
) |
| 144 | 146 |
|
| 147 |
+ for g in order.goods_info: |
|
| 148 |
+ try: |
|
| 149 |
+ good = PackGoodsInfo.objects.get(pack_id=pack_id, good_id=g.get('good_id', ''))
|
|
| 150 |
+ good.has_sale_num += 1 |
|
| 151 |
+ good.inventory -= 1 |
|
| 152 |
+ good.save() |
|
| 153 |
+ except PackGoodsInfo.DoesNotExist: |
|
| 154 |
+ continue |
|
| 155 |
+ |
|
| 145 | 156 |
|
| 146 | 157 |
def order_paid_fail(order): |
| 147 | 158 |
if order.pay_status == OrderInfo.FAIL: |
@@ -34,6 +34,8 @@ class PackStatusCode(BaseStatusCode): |
||
| 34 | 34 |
|
| 35 | 35 |
class PackGoodsStatusCode(BaseStatusCode): |
| 36 | 36 |
PACK_GOODS_NOT_FOUND = StatusCodeField(403001, 'Pack Goods Not Found', description=u'包商品不存在') |
| 37 |
+ PACK_GOODS_INVENTORY_SHORTAGE = StatusCodeField(403002, 'Pack Goods Inventory Shortage', description=u'库存不足') |
|
| 38 |
+ |
|
| 37 | 39 |
|
| 38 | 40 |
|
| 39 | 41 |
class OrderStatusCode(BaseStatusCode): |