|
|
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', '')
|
|
|
|
@@ -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'劵已核销')
|