示例#1
0
	def insertSku(self, sku, token):
		user = self.validateToken(token)
		if 'error' in user:
			return user

		# Validate certain size
		skudao = SkuDao()
		userdao = UserDao()
		checkExistSku = skudao.checkExistSku(sku)
		if (checkExistSku > 0):
			return ResponseUtils.generateErrorResponse("You cannot add SKU already exist!!!")

		addedSize = skudao.getAddedSize(user['id'])
		certainSize = userdao.getCertainSize(user['id'])
		if (addedSize >= certainSize):
			return ResponseUtils.generateErrorResponse("You cannot add more SKU, please contact admin to improve your account!")

		# Validate SKU by product's data in database
		productDao = ProductDao()
		product, exception = productDao.getProductBySellerSku(user, sku)
		if exception != None:
			return ResponseUtils.generateErrorResponse(exception)

		# Add missing arguments and insert to our database
		sku['name'] = product['name']
		sku['link'] = product['url']
		sku['special_price'] = product['special_price']

		skudao.insert(sku, user)
		return ResponseUtils.generateSuccessResponse()
示例#2
0
    def getTopSellingProducts(self, token):
        user, exception = Validation.validateToken(token)
        if (exception != None):
            return ResponseUtils.returnError(exception)

        productDao = ProductDao()
        result, exception = productDao.getTopSellingProducts(user)
        if exception != None:
            return ResponseUtils.returnError(exception)
        else:
            return ResponseUtils.returnSuccess(result)
示例#3
0
    def searchProduct(self, token, searchKey):
        user, exception = Validation.validateToken(token)
        if (exception != None):
            return ResponseUtils.returnError(exception)

        productDao = ProductDao()
        result, exception = productDao.searchProduct(user, searchKey)
        if exception != None:
            return ResponseUtils.returnError(exception)
        else:
            return ResponseUtils.returnSuccess(result)
示例#4
0
    def getProducts(self, token):
        user, exception = Validation.validateToken(token)
        if (exception != None):
            return ResponseUtils.returnError(exception)

        # TODO: add pagination
        productDao = ProductDao()
        products, exception = productDao.getProducts(user)
        if (exception != None):
            return ResponseUtils.returnError(exception)
        else:
            return ResponseUtils.returnSuccess(products)
示例#5
0
    def updateProductQuantityAndOriginalPrice(self, token, products):
        user, exception = Validation.validateToken(token)
        if (exception != None):
            return ResponseUtils.returnError(exception)

        productDao = ProductDao()
        for product in products:
            exception = productDao.updateQuantityAndOrginalPrice(
                user, product['id'], product['quantity'],
                product['original_price'])
            if (exception != None):
                return ResponseUtils.returnError(exception)

        return ResponseUtils.returnSuccess(None)
    def changeOriginPrice(self, token, orderItems, accountStatementId):
        user, exception = Validation.validateToken(token)
        if (exception != None):
            return ResponseUtils.returnError(exception)

        orderItemDao = OrderItemDao()
        for orderItem in orderItems:
            # Get current OrderItem
            curOrderItem, exception = orderItemDao.getOrderItemByOrderItemId(
                user, orderItem['order_item_id'])
            if (exception != None):
                return ResponseUtils.returnError(exception)

            # Recompute earned/income and update
            commission = curOrderItem['actual_paid_price'] - curOrderItem[
                'earned'] - curOrderItem['original_price']
            orderItem['earned'] = curOrderItem['actual_paid_price'] - (
                commission + orderItem['original_price'])
            exception = orderItemDao.changeOriginalPrice(user, orderItem)
            if (exception != None):
                return ResponseUtils.returnError(exception)

            # Update product's orginal price if its value is Zero
            if (curOrderItem['original_price'] == 0):
                productDao = ProductDao()
                exception = productDao.updateOriginalPriceByShopSku(
                    user, orderItem['shop_sku'], orderItem['original_price'])
                if (exception != None):
                    return ResponseUtils.returnError(exception)

        # Compute an account statement income
        income, exception = orderItemDao.getTotalEarningOfAccountStatement(
            user, accountStatementId)
        if (exception != None):
            return ResponseUtils.returnError(exception)

        # Recompute account statment income
        accountStatementDao = AccountStatementDao()
        updatedDate = TimestampUtils.getCurrentDatetime()
        exception = accountStatementDao.update(user, accountStatementId,
                                               income, updatedDate)
        if (exception != None):
            return ResponseUtils.returnError(exception)

        return ResponseUtils.generateSuccessResponse(None)
示例#7
0
    def insert(self, sku, token):
        user = ManagerHelper.validateToken(token)
        if 'error' in user:
            return user

        #Valide product by Sku
        productDao = ProductDao()
        product, exception = productDao.getProductBySellerSku(user, sku)
        if exception != None:
            return ResponseUtils.generateErrorResponse(exception)

        # Add missing arguments and insert to our database
        sku['name'] = product['name'].encode('utf-8')
        sku['link'] = product['url'].encode('utf-8')
        sku['special_price'] = product['special_price']

        priceByTime = PriceByTimeDao()
        result = priceByTime.insert(sku, user)
        if 'error' in result:
            return ResponseUtils.generateErrorResponse(result['error'])
        else:
            return ResponseUtils.generateSuccessResponse()
示例#8
0
from database.user_dao import UserDao
from database.shop_dao import ShopDao
from database.product_dao import ProductDao
from database.constant_dao import ConstantDao
from database.account_statement_dao import AccountStatementDao
from database.account_statement_exception_dao import AccountStatementExceptionDao
from config import ConstantConfig
from utils.lazada_api_helper import LazadaApiHelper

# Database instances
userDao = UserDao()
shopDao = ShopDao()
prroductDao = ProductDao()
constantDao = ConstantDao()
accountStatementDao = AccountStatementDao()
accountStatementExceptionDao = AccountStatementExceptionDao()


class AppController(object):
    def initDatabase(self):
        # Init tables
        shopDao.createTable()
        prroductDao.createTable()
        constantDao.createTable()
        accountStatementDao.createTable()
        accountStatementExceptionDao.createTable()
        # Init default values
        self.initDefaultConstantValue()

    #-----------------------------------------------------------------------------
    # Insert default constant for all user