def get_all_departments(): response = DataBase.request("SELECT `id`, `name`, `staff`, `tag` FROM `department`") response["data"] = [response["data"]] if isinstance(response["data"], dict) else response["data"] departments = [] for department in response["data"]: departments.append(Department(department["id"], department["name"], department["tag"], department["staff"])) return departments
def get_department(tag): response = DataBase.request("SELECT `id`, `name`, `staff`, `tag` FROM `department` WHERE `tag`=%(tag)s", {"tag": tag}) department = None if response["code"] == 200: department = Department(response["data"]["id"], response["data"]["name"], response["data"]["tag"], response["data"]["staff"]) return department
def set_paymentKey_order(self, payment_key): return DataBase.request( "UPDATE `orders` SET `payment_key`=%(payment_key)s WHERE `id`=%(id)s", { "payment_key": payment_key, "id": self.id })
def del_task_duplicate(userID, departmentTag, orderID): return DataBase.request( "DELETE FROM `tasks_completes` WHERE `userID`=%(userID)s AND `orderID`=%(orderID)s AND `departmentTag`=%(departmentTag)s", { "userID": userID, "orderID": orderID, "departmentTag": departmentTag })
def get_message(id): response = DataBase.request( "SELECT `id`, `userID`, `message`, `document`, `active`, `date` FROM `messages_coupon` WHERE `id`=%(id)s", {"id": id}) message = None if response["code"] == 200: message = MessageCoupon(response["data"]["id"], response["data"]["userID"], response["data"]["message"], response["data"]["document"], response["data"]["date"], response["data"]["active"]) return message
def get_all_staffs(): response = DataBase.request("SELECT `id`, `name`, `staff`, `tag` FROM `department`") response["data"] = [response["data"]] if isinstance(response["data"], dict) else response["data"] staffs = [] if response["code"] == 200: for department in response["data"]: staffs += department["staff"] return staffs
def add_payment_history(userID, amount): return DataBase.request( "INSERT INTO `payment_history`(`userID`, `amount`, `date`) VALUES (%(userID)s,%(amount)s,%(date)s)", { "userID": userID, "amount": amount, "date": int(time.time()) })
def get_last_message_day_user(userID): response = DataBase.request( "SELECT `id`, `userID`, `message`, `document`, `active`, `date` FROM `messages_coupon` WHERE `userID`=%(userID)s AND `date`>%(date)s", {"userID": userID, "date": time.time() - 60 * 60 * 24}) response["data"] = [response["data"]] if isinstance(response["data"], dict) else response["data"] messages = [] for message in response["data"]: messages.append(MessageCoupon(message["id"], message["userID"], message["message"], message["document"], message["date"], message["active"])) return messages
def get_messages(page=0, max_size_messages=10): response = DataBase.request( "SELECT `id`,`userID`, `message`, `date` FROM `messages_coupon` WHERE `active`=1 LIMIT %(page)s,%(max_size_messages)s", {"page": page * max_size_messages, "max_size_messages": max_size_messages}) response["data"] = [response["data"]] if isinstance(response["data"], dict) else response["data"] messages = [] for message in response["data"]: messages.append(MessageCoupon(message["id"], message["userID"], message["message"], [], message["date"], True)) return messages
def create_task(orderID, staff, tag, message): return DataBase.request( "INSERT INTO `tasks`(`orderID`, `staff`, `departmentTag`,`message`) VALUES (%(orderID)s,%(staff)s,%(tag)s,%(message)s)", { "orderID": orderID, "staff": json.dumps(staff), "tag": tag, "message": message })
def create_messages(userID, message, document, isOrder): return DataBase.request( "INSERT INTO `messages`(`userID`, `message`, `document`, `isOrder`, `active`, `date`) VALUES (%(userID)s,%(message)s,%(document)s,%(isOrder)s,1,%(date)s)", { "userID": userID, "message": message, "document": json.dumps(document), "isOrder": isOrder, "date": int(time.time()) })
def save(self): return DataBase.request( "UPDATE `promo_codes` SET `name`=%(name)s,`code`=%(code)s,`percent`=%(percent)s,`discount`=%(discount)s,`count`=%(count)s WHERE `id`=%(id)s", { "name": self.name, "code": self.code, "percent": self.percent, "discount": self.discount, "count": self.count, "id": self.id })
def create_order(userID, description, document, price, separate_payment): return DataBase.request( "INSERT INTO `orders`( `userID`, `description`,`document`,`price` ,`date`,`active`, `separate_payment`) VALUES (%(userID)s,%(description)s,%(document)s,%(price)s,%(date)s,1,%(separate_payment)s)", { "userID": userID, "description": description, "document": json.dumps(document), "price": price, "date": int(time.time()), "separate_payment": separate_payment })
def create_promo_code(name, code, percent, discount, limitation_use, count): return DataBase.request( "INSERT INTO `promo_codes`(`name`, `code`, `percent`, `discount`,`limitation_use`,`count`) VALUES (%(name)s,%(code)s,%(percent)s,%(discount)s,%(limitation_use)s,%(count)s)", { "name": name, "code": code, "percent": percent, "discount": discount, "limitation_use": limitation_use, "count": count })
def get_ALLOrders(): response = DataBase.request( "SELECT `id`,`userID`,`date` FROM `orders` WHERE `active`=1") response["data"] = [response["data"]] if isinstance( response["data"], dict) else response["data"] orders = [] for order in response["data"]: orders.append( Order(order["id"], order["userID"], 0, "", [], True, False, "", order["date"])) return orders
def create_task_complete(userID, orderID, departmentTAG, message, document): return DataBase.request( "INSERT INTO `tasks_completes`(`userID`, `orderID`, `departmentTag`, `message`, `document`, `date`) VALUES (%(userID)s,%(orderID)s,%(departmentTAG)s,%(message)s,%(document)s,%(date)s)", { "userID": userID, "orderID": orderID, "departmentTAG": departmentTAG, "message": message, "document": json.dumps(document), "date": int(time.time()) })
def get_task(id): response = DataBase.request( "SELECT `id`, `orderID`, `staff`, `departmentTag`, `message` FROM `tasks` WHERE `id`=%(id)s", {"id": id}) task = None if response["code"] == 200: task = Task(response["data"]["id"], response["data"]["orderID"], response["data"]["staff"], response["data"]["departmentTag"], response["data"]["message"]) return task
def get_promo_code(code): response = DataBase.request( "SELECT `id`, `name`, `code`, `percent`, `discount`,`limitation_use`,`count` FROM `promo_codes` WHERE `code`=%(code)s", {"code": code}) promo_code = None if response["code"] == 200: promo_code = PromoCode( response["data"]["id"], response["data"]["name"], response["data"]["code"], response["data"]["percent"], response["data"]["discount"], response["data"]["limitation_use"], response["data"]["count"]) return promo_code
def get_ALLPromoCode(): response = DataBase.request( "SELECT `id`, `name`, `code`, `percent`, `discount`,`limitation_use`,`count` FROM `promo_codes`" ) response["data"] = [response["data"]] if isinstance( response["data"], dict) else response["data"] promo_codes = [] for code in response["data"]: promo_codes.append( PromoCode(code["id"], code["name"], code["code"], code["percent"], code["discount"], code["limitation_use"], code["count"])) return promo_codes
def get_orderID_tasks_completes(orderID): response = DataBase.request( "SELECT `id`, `userID`, `orderID`, `departmentTag`, `message`, `document`, `date` FROM `tasks_completes` WHERE `orderID`=%(orderID)s", {"orderID": orderID}) response["data"] = [response["data"]] if isinstance( response["data"], dict) else response["data"] tasks = [] for task in response["data"]: tasks.append( TaskComplete(task["id"], task["userID"], task["orderID"], task["departmentTag"], task["message"], task["document"], task["date"])) return tasks
def get_order_provisional(id): response = DataBase.request( "SELECT `id`, `userID`, `text`, `document`, `active`, `separate_payment`, `percent`, `discount`, `date` FROM `orders_processing` WHERE `id`=%(id)s", {"id": id}) order = None if response["code"] == 200: order = OrderProvisional( response["data"]["id"], response["data"]["userID"], response["data"]["text"], response["data"]["document"], response["data"]["active"], response["data"]["separate_payment"], response["data"]["percent"], response["data"]["discount"], response["data"]["date"]) return order
def get_payment(secret_key): response = DataBase.request( "SELECT `id`, `userID`, `description`, `document`, `separate_payment`,`additional`, `price`, `secret_key`, `date` FROM `payment` WHERE `secret_key`=%(secret_key)s", {"secret_key": secret_key}) payment = None if response["code"] == 200: payment = Payment( response["data"]["id"], response["data"]["userID"], response["data"]["description"], response["data"]["document"], response["data"]["separate_payment"], response["data"]["additional"], response["data"]["price"], response["data"]["secret_key"], response["data"]["date"]) return payment
def create_order_provisional(userID, text, document, separate_payment, percent, discount): return DataBase.request( "INSERT INTO `orders_processing`(`userID`, `text`, `document` ,`active`, `separate_payment`, `percent`, `discount`, `date`) VALUES (%(userID)s,%(text)s,%(document)s,1,%(separate_payment)s,%(percent)s,%(discount)s,%(date)s)", { "userID": userID, "text": text, "document": json.dumps(document), "separate_payment": separate_payment, "percent": percent, "discount": discount, "date": int(time.time()) })
def get_task_complete(id): response = DataBase.request( "SELECT `id`, `userID`, `orderID`, `departmentTag`, `message`, `document`, `date` FROM `tasks_completes` WHERE `id`=%(id)s", {"id": id}) task = None if response["code"] == 200: task = TaskComplete(response["data"]["id"], response["data"]["userID"], response["data"]["orderID"], response["data"]["departmentTag"], response["data"]["message"], response["data"]["document"], response["data"]["date"]) return task
def create_payment(userID, description, document, separate_payment, price, secret_key, additional): return DataBase.request( "INSERT INTO `payment`(`userID`, `description`, `document`, `separate_payment`,`additional`,`price`, `secret_key`,`date`) VALUES (%(userID)s,%(description)s,%(document)s,%(separate_payment)s,%(additional)s,%(price)s,%(secret_key)s,%(date)s)", { "userID": userID, "description": description, "document": json.dumps(document), "separate_payment": separate_payment, "price": price, "secret_key": secret_key, "additional": additional, "date": int(time.time()) })
def get_order_paymentKey(payment_key): response = DataBase.request( "SELECT `id`,`userID`,`description`,`document`,`price`,`active`,`date`,`separate_payment`,`payment_key` FROM `orders` WHERE `payment_key`=%(payment_key)s", {"payment_key": payment_key}) order = None if response["code"] == 200: order = Order(response["data"]["id"], response["data"]["userID"], response["data"]["price"], response["data"]["description"], response["data"]["document"], response["data"]["active"], response["data"]["separate_payment"], response["data"]["payment_key"], response["data"]["date"]) return order
def get_orders(page=0, max_size=10): response = DataBase.request( "SELECT `id`,`userID`,`date` FROM `orders` WHERE `active`=1 AND`active`=1 LIMIT %(page)s,%(max_size)s", { "page": page * max_size, "max_size": max_size }) response["data"] = [response["data"]] if isinstance( response["data"], dict) else response["data"] orders = [] for order in response["data"]: orders.append( Order(order["id"], order["userID"], 0, "", [], True, False, "", order["date"])) return orders
def get_promoCode(page=0, max_size=10): response = DataBase.request( "SELECT `id`, `name`, `code`, `percent`, `discount`,`limitation_use`,`count` FROM `promo_codes` LIMIT %(page)s,%(max_size)s", { "page": page * max_size, "max_size": max_size }) response["data"] = [response["data"]] if isinstance( response["data"], dict) else response["data"] promo_codes = [] for code in response["data"]: promo_codes.append( PromoCode(code["id"], code["name"], code["code"], code["percent"], code["discount"], code["limitation_use"], code["count"])) return promo_codes
def del_task_duplicate(userID, departmentTag, orderID): response = DataBase.request( "SELECT `id`, `orderID`, `staff`, `departmentTag`, `message` FROM `tasks` WHERE `departmentTag`=%(departmentTag)s AND (`staff` LIKE %(userOne)s OR `staff` LIKE %(userTwo)s)", { "departmentTag": departmentTag, "userOne": "%" + str(userID) + ",%", "userTwo": "%" + str(userID) + "]%" }) response["data"] = [response["data"]] if isinstance( response["data"], dict) else response["data"] if response["code"] == 200: for task in response["data"]: if task["orderID"] == orderID: if len(task["staff"]) == 1: DataBase.request("DELETE FROM `tasks` WHERE `id`=%(id)s", {"id": task["id"]}) else: task["staff"].remove(userID) DataBase.request( "UPDATE `tasks` SET `staff`=%(staff)s WHERE `id`=%(id)s", { "staff": json.dumps(task["staff"]), "id": task["id"] })
def get_tasks(page=0, max_size=10): response = DataBase.request( "SELECT t1.id, t1.orderID, t1.staff, t1.departmentTag, t1.message FROM `tasks` t1 INNER JOIN (SELECT DISTINCT `orderID` FROM tasks LIMIT %(page)s,%(max_size)s) t2 ON t2.orderID=t1.orderID", { "page": page * max_size, "max_size": max_size }) response["data"] = [response["data"]] if isinstance( response["data"], dict) else response["data"] tasks = [] for task in response["data"]: tasks.append( Task(task["id"], task["orderID"], task["staff"], task["departmentTag"], task["message"])) return tasks