@@ -9,7 +9,7 @@ from django_response import response  | 
            ||
| 9 | 9 | 
                from TimeConvert import TimeConvert as tc  | 
            
| 10 | 10 | 
                 | 
            
| 11 | 11 | 
                from mch.models import ConsumeInfoSubmitLogInfo, AdministratorInfo  | 
            
| 12 | 
                -from utils.error.errno_utils import AdministratorStatusCode, ProductBrandStatusCode, ProductMachineStatusCode  | 
            |
| 12 | 
                +from utils.error.errno_utils import AdministratorStatusCode, ProductBrandStatusCode, ProductCouponStatusCode, ProductMachineStatusCode  | 
            |
| 13 | 13 | 
                 | 
            
| 14 | 14 | 
                 | 
            
| 15 | 15 | 
                WECHAT = settings.WECHAT  | 
            
                @@ -77,6 +77,10 @@ def usecoupon(request):  | 
            ||
| 77 | 77 | 
                except ConsumeInfoSubmitLogInfo.DoesNotExist:  | 
            
| 78 | 78 | 
                return response(ProductMachineStatusCode.SN_NOT_FOUND)  | 
            
| 79 | 79 | 
                 | 
            
| 80 | 
                + logdata = log.data  | 
            |
| 81 | 
                +    if logdata.get('coupon_info', {}).get('coupon_has_expired', True):
               | 
            |
| 82 | 
                + return response(ProductCouponStatusCode.COUPON_HAS_EXPIRED)  | 
            |
| 83 | 
                +  | 
            |
| 80 | 84 | 
                log.has_used = True  | 
            
| 81 | 85 | 
                log.used_at = tc.utc_datetime()  | 
            
| 82 | 86 | 
                log.save()  | 
            
                @@ -532,6 +532,7 @@ class ConsumeInfoSubmitLogInfo(BaseModelMixin):  | 
            ||
| 532 | 532 | 
                         return {
               | 
            
| 533 | 533 | 
                'coupon_expire_at': '',  | 
            
| 534 | 534 | 
                'coupon_value': 0,  | 
            
| 535 | 
                + 'coupon_has_expired': True,  | 
            |
| 535 | 536 | 
                },  | 
            
| 536 | 537 | 
                 | 
            
| 537 | 538 | 
                @property  | 
            
                @@ -606,7 +607,9 @@ class ActivityInfo(BaseModelMixin):  | 
            ||
| 606 | 607 | 
                return (self.model_uni_names and model_name in self.model_uni_names) and (self.start_at <= tc.utc_datetime() < self.end_at)  | 
            
| 607 | 608 | 
                 | 
            
| 608 | 609 | 
                def coupon_info(self, created_at=None):  | 
            
| 610 | 
                + coupon_expire_at = self.final_coupon_expire_at(created_at=created_at)  | 
            |
| 609 | 611 | 
                         return {
               | 
            
| 610 | 
                - 'coupon_expire_at': self.final_coupon_expire_at(created_at=created_at),  | 
            |
| 612 | 
                + 'coupon_expire_at': coupon_expire_at,  | 
            |
| 611 | 613 | 
                'coupon_value': self.coupon_value,  | 
            
| 614 | 
                + 'coupon_has_expired': tc.utc_datetime() >= coupon_expire_at,  | 
            |
| 612 | 615 | 
                },  | 
            
                @@ -37,6 +37,13 @@ class ProductMachineStatusCode(BaseStatusCode):  | 
            ||
| 37 | 37 | 
                SN_NOT_FOUND = StatusCodeField(501301, 'SN Not Found', description=u'序列号不存在')  | 
            
| 38 | 38 | 
                 | 
            
| 39 | 39 | 
                 | 
            
| 40 | 
                +class ProductCouponStatusCode(BaseStatusCode):  | 
            |
| 41 | 
                + """ 优惠券相关错误码 5014xx """  | 
            |
| 42 | 
                + COUPON_NOT_FOUND = StatusCodeField(501401, 'Coupon Not Found', description=u'优惠券不存在')  | 
            |
| 43 | 
                +  | 
            |
| 44 | 
                + COUPON_HAS_EXPIRED = StatusCodeField(501411, 'Coupon Has Expired', description=u'优惠券已过期')  | 
            |
| 45 | 
                +  | 
            |
| 46 | 
                +  | 
            |
| 40 | 47 | 
                class ProductStatusCode(BaseStatusCode):  | 
            
| 41 | 48 | 
                """ 产品相关错误码 5020xx """  | 
            
| 42 | 49 | 
                PRODUCT_NOT_FOUND = StatusCodeField(502001, 'Product Not Found', description=u'产品不存在')  |