Exemple #1
0
    def getDetailsOfOrder(userID, orderID):
        result = {}
        if (not Order.checkIfUserHaveOrderWith(userID, orderID)):
            result['status'] = 3
            result['message'] = 'Why are you so curious?'
            result['data'] = []
            return result
        if (not Order.checkIfOrderExists(orderID)):
            result['status'] = 40
            result['message'] = 'Not founded'
            result['data'] = []
            return result

        data = SqlExecuter.getAllRowsPacked(
            "select pr.id,pr.imageLink,pr.book_title,bk.count,pr.cost_sale*bk.count as 'total' from Забронированная_книга as bk inner join Товар as pr on bk.order_id = {} and pr.id = bk.product_id;"
            .format(orderID))
        for row in data:
            row['imageLink'] = imageHelper.makeFullPathToImage(
                row['imageLink'])
        rowAddressPacked = SqlExecuter.getOneRowsPacked(
            "select ord.id as 'orderID',addr.*,ord.date,ord.status,ord.total,concat(addr.district,' district,',addr.street,', ',addr.house) as 'address' from Заказ as ord  inner join Адрес as addr \
            where ord.address_id = addr.id and ord.id = {};".format(orderID))
        result['address'] = rowAddressPacked
        result['info'] = {
            'orderID': rowAddressPacked['orderID'],
            'date': rowAddressPacked['date'],
            'status': rowAddressPacked['status'],
            'total': rowAddressPacked['total']
        }
        result['status'] = 0
        result['message'] = 'OK'
        result['data'] = data
        return result
Exemple #2
0
 def getCartOfUser(userID):
     result = {}
     try:
         data = SqlExecuter.getAllRowsPacked(
             'select concat(pr.book_title," - ",pr.author) as "title",pr.cost_sale as "cost",cart.count,cart.count*pr.cost_sale as "total",pr.id,pr.imageLink,pr.author from Товар as pr inner join Корзина as cart on pr.id = product_id and user_id = {};'
             .format(userID))
     except:
         result['status'] = 1
         result['message'] = 'SQL runtime error'
         result['data'] = []
         return result
     if (data is None or len(data) == 0):
         result['status'] = 2
         result['message'] = 'Empty cart'
         result['data'] = []
         return result
     for row in data:
         row['imageLink'] = imageHelper.makeFullPathToImage(
             row['imageLink'])
     result['data'] = data
     result['count'] = len(data)
     result['status'] = 0
     result['message'] = 'OK'
     result['totalCost'] = SqlExecuter.getOneRowsPacked(
         "select SUM(cart.count*pr.cost_sale) as 'totalCost' from Товар as pr inner join Корзина as cart on pr.id = product_id and user_id = {};"
         .format(userID))['totalCost']
     return result
Exemple #3
0
 def getAllProfuctsFilteredByQuery(query, page=-1, offset=-1):
     result = {}
     try:
         allRows = SqlExecuter.getAllRowsPacked(
             'select *,cost_sale as "cost",concat(book_title," - ",author) as "title" from Товар where book_title like "%{0}%" or author like "%{0}%" order by id DESC LIMIT {1} OFFSET {2};'
             .format(query, offset, offset * (page - 1)))
     except:
         result['status'] = 1
         result['message'] = "Runtime error while executing sql query"
         result['data'] = []
         return result
     return Product.__preparePackedProducts(allRows)
Exemple #4
0
 def getAllProductsFilteredByTags(tags, page, offset):
     result = {}
     try:
         allRows = SqlExecuter.getAllRowsPacked(
             sqlQueryHelper.buildSqlQueryByTagsAndPage(
                 'select *,cost_sale as "cost",concat(book_title," - ",author) as "title" from Товар',
                 tags, page, offset))
     except:
         result['status'] = 1
         result['message'] = "Runtime error while executing sql query"
         result['data'] = []
         return result
     return Product.__preparePackedProducts(allRows)
Exemple #5
0
 def getOrdersOfUser(userID):
     result = {}
     allRows = SqlExecuter.getAllRowsPacked(
         'select ord.*,addr.district,addr.street,addr.flat,addr.floor,\
     addr.porch,addr.house,address_id as "address" \
     from Заказ as ord inner join Адрес as addr\
      where ord.address_id = addr.id and user_id = {} order by id DESC;'.
         format(userID))
     if (allRows is None or len(allRows) == 0):
         result['status'] = 2
         result['message'] = 'Empty response'
         result['data'] = []
         return result
     result['status'] = 0
     result['message'] = 'OK'
     result['data'] = allRows
     return result
Exemple #6
0
 def getAvailableTags():
     result = {}
     allRows = SqlExecuter.getAllRowsPacked('select tags from Товар;')
     if (allRows is None or len(allRows) == 0):
         result['status'] = 2
         result['message'] = 'Empty data'
         result['data'] = []
         return result
     tagsArrUNIQUE = []
     for row in allRows:
         tags = row['tags']
         tagsArr = tagsHelper.makeTagsStrToArray(tags)
         tagsArrUNIQUE = list(set(tagsArrUNIQUE + tagsArr))
     result['status'] = 0
     result['message'] = 'OK'
     result['data'] = tagsArrUNIQUE
     return result