예제 #1
0
    def getTxnAggSummary(self, merchantId, durationKey):
        try:
            ssConst = SSConst()
            txnAggSummaryMap = {
                'pk': 'id',
                'visits': 'visits',
                'spend': 'spend',
                'reviews': 'reviews',
                'reviewsAverage': 'reviewsAverage',
            }

            txnAggSummary = ConsumerTxn.objects.raw(
                '''
                                    select 1 as id, count(*) as total, sum(amtSpentSS) as spend
                                    from ss_consumer_txn where merchant_id=%s
                                    and created > %s and ssApproval='Approve'
                                    ''',
                [merchantId, ssConst.getStartTime(durationKey)],
                translations=txnAggSummaryMap)
            txnAggSum = {
                'visits': 0,
                'spend': 0,
                'reviews': 0,
                'reviewsAverage': 0,
            }
            for x in txnAggSummary:
                txnAggSum['visits'] = x.total
                txnAggSum['spend'] = x.spend
            reviewSum = self.getReviewSummary(
                merchantId, ssConst.getStartTime(durationKey))
            txnAggSum['reviews'] = reviewSum['total']
            txnAggSum['reviewsAverage'] = reviewSum['average']
            return txnAggSum
        except TxnReview.DoesNotExist:
            return None
예제 #2
0
def reviews(request, merchantId):
    try:
        ms = MerchantService();
        ssConst = SSConst()
        data = ms.getReviewSummary(merchantId, ssConst.getStartTime("all_time"))
        return JSONResponse(SSUtil.success(data), status=status.HTTP_200_OK)
    except:
        return JSONResponse(SSUtil.err("No reviews available"),
                                status=status.HTTP_400_BAD_REQUEST)
예제 #3
0
def getReviews(request):
    limit = 100
    start = 0
    duration = "all_time"
    if 'duration' in request.GET and not request.GET["duration"] is None and request.GET["duration"] != '':
        duration = request.GET["duration"]
    if 'limit' in request.GET and not request.GET["limit"] is None and request.GET["limit"] != '':
        limit = int(request.GET["limit"])
    if 'start' in request.GET and not request.GET["start"] is None and request.GET["start"] != '':
        start = int(request.GET["start"])
    try:
        ms = MerchantService();
        ssConst = SSConst()
        res = ms.getMerchantReviews(request.user.id, ssConst.getStartTime(duration), limit, start)
        serializer = TxnReviewSerializer(res, many=True)
        return JSONResponse(SSUtil.success(serializer.data), status=status.HTTP_200_OK)
    except:
        return JSONResponse(SSUtil.err("No reviews available"),
                                status=status.HTTP_400_BAD_REQUEST)