468
+        user = UserInfo.objects.get(user_id=user_id, status=True)
469
+    except UserInfo.DoesNotExist:
470
+        return response(SaleclerkStatusCode.CLERK_NOT_FOUND)
471
+
472
+    try:
473
+        brand = BrandInfo.objects.get(pk=brandID)
474
+    except BrandInfo.DoesNotExist:
475
+        brand = None
476
+    except ValueError:
477
+        brand = None
478
+
479
+    if not brand:
480
+        try:
481
+            brand = BrandInfo.objects.get(brand_id=brandID)
482
+        except BrandInfo.DoesNotExist:
483
+            return response(ProductBrandStatusCode.BRAND_NOT_FOUND)
484
+
485
+    try:
486
+        clerk = SaleclerkInfo.objects.get(brand_id=brand.brand_id, unionid=user.unionid, status=True)
487
+    except SaleclerkInfo.DoesNotExist:
488
+        return response(SaleclerkStatusCode.CLERK_NOT_FOUND)
489
+
490
+    try:
491
+        user_coupon = UserCouponInfo.objects.get(user_coupon_id=user_coupon_id)
492
+        if user_coupon.has_used:
493
+            return response(CouponStatusCode.COUPON_HAS_USED) 
494
+        elif user_coupon.is_coupon_admin_writeoff:
495
+            return response(CouponStatusCode.COUPON_PERMISSION_DENIED)
496
+        elif not user_coupon.has_expired:
497
+            user_coupon.clerk_id = clerk.clerk_id
498
+            user_coupon.clerk_name = clerk.clerk_name
499
+            user_coupon.distributor_id = clerk.distributor_id
500
+            user_coupon.distributor_name = clerk.distributor_name
501
+            user_coupon.has_used = True
502
+            user_coupon.used_at = tc.utc_datetime()
503
+            user_coupon.save()
504
+        else:
505
+          return response(CouponStatusCode.COUPON_EXPIRED)
506
+    except UserCouponInfo.DoesNotExist:
507
+        return response(CouponStatusCode.COUPON_NOT_FOUND)
508
+
509
+    return response(200, 'Write Off Coupon Success', u'劵核销成功')
510
+
511
+@logit
423 512
 def clerk_checkout_serialNo_api(request):
424 513
     brandID = request.POST.get('brand_id', settings.KODO_DEFAULT_BRAND_PK)
425 514
     user_id = request.POST.get('user_id', '')

+ 7 - 0
utils/error/errno_utils.py

@@ -255,3 +255,10 @@ class TokenStatusCode(BaseStatusCode):
255 255
 class PermissionStatusCode(BaseStatusCode):
256 256
     """ 4099xx 权限相关错误码 """
257 257
     PERMISSION_DENIED = StatusCodeField(409900, 'Permission Denied', description=u'权限不足')
258
+
259
+class CouponStatusCode(BaseStatusCode):
260
+    """ 4050xx 优惠劵相关错误码 """
261
+    COUPON_NOT_FOUND = StatusCodeField(405001, 'Coupon Not Found', description=u'劵不存在')
262
+    COUPON_EXPIRED = StatusCodeField(405002, 'Coupon Expired', description=u'劵已过期')
263
+    COUPON_PERMISSION_DENIED = StatusCodeField(405003, 'Permission Denied', description=u'核销劵权限不足')
264
+    COUPON_HAS_USED = StatusCodeField(405004, 'Coupon Has Used', description=u'劵已核销')

kodo - Gogs: Go Git Service

説明なし

FFIB: 88b564d033 fix coercing to Unicode: need string or buffer, long found 5 年 前
..
migrations 6a9e324f6f :art: Re Makemigrations 5 年 前
__init__.py b9200f9ed2 Sales 7 年 前
admin.py 290ff6960f pyzbar 7 年 前
apps.py b9200f9ed2 Sales 7 年 前
models.py 88b564d033 fix coercing to Unicode: need string or buffer, long found 5 年 前
tests.py 290ff6960f pyzbar 7 年 前
views.py 290ff6960f pyzbar 7 年 前