コード例 #1
0
class SellItems(HTTPMethodView):
    decorators = [auth.login_required(handle_no_auth=handle_no_auth)]

    async def post(self, request):
        data = request.json if request.json is not None else {}
        args = request.args if request.args is not None else {}

        try:
            search = data.get('search', '')
            page = int(args.get('page', 1))
            page_size = int(args.get('page_size', 20))
            order_by = args.get('order_key', 'created_time')
            order = args.get('order', 'desc')
            if order.lower() not in ['desc', 'asc']:
                order = 'desc'

            search_sql = "where CONCAT(IFNULL(`item_number`,''),IFNULL(`hairdresser`,''),IFNULL(`assistant`,''),IFNULL(`item_type`,''),IFNULL(`pay_type`,''),IFNULL(`comment`,''),IFNULL(`fellow`,''),IFNULL(`created_time`,'')) LIKE '%%%s%%'" % search

            res_total_count = await request.app.mysql.query_select(
                'select count(*) from sell_item_list %s' % (search_sql))
            total_count = int(res_total_count[0][0])
            if total_count <= (page - 1) * page_size:
                page = 1

            page_sql = "limit %s, %s" % ((page - 1) * page_size, page_size)
            sell_item_list = await request.app.mysql.query_select(
                'select * from sell_item_list %s order by %s %s %s' %
                (search_sql, order_by, order, page_sql))
            response_list = []
            for raw_id, value in enumerate(sell_item_list):
                n_id, item_number, hairdresser, assistant, item_type, money, pay_type, fellow, comment, created_time = value
                response_list.append({
                    "raw_id": raw_id + 1,
                    "item_number": item_number,
                    "hairdresser": hairdresser,
                    "assistant": assistant,
                    "item_type": item_type,
                    "money": money,
                    "pay_type": pay_type,
                    "fellow": fellow,
                    "comment": comment,
                    "created_time": str(created_time),
                })
        except Exception as e:
            return response.json({
                "data": [],
                "page": 1,
                "total_count": total_count,
                "status": "failed",
                "message": "获取失败,错误信息为%s" % str(e)
            })

        return response.json({
            "data": response_list,
            "page": page,
            "total_count": int(total_count),
            "status": "success"
        })
コード例 #2
0
ファイル: setting.py プロジェクト: cniu/barbershop
class Users(HTTPMethodView):
    decorators = [
        auth.login_required(handle_no_auth=handle_no_auth),
        authorized.authorized(1)
    ]

    async def post(self, request):
        data = request.json if request.json is not None else {}
        args = request.args if request.args is not None else {}

        try:
            search = data.get('search', '')
            page = int(args.get('page', 1))
            page_size = int(args.get('page_size', 20))
            order_by = args.get('order_key', 'created_time')
            order = args.get('order', 'desc')
            if order.lower() not in ['desc', 'asc']:
                order = 'desc'

            search_sql = "where username != 'admin' and CONCAT(IFNULL(`username`,''),IFNULL(`password`,''),IFNULL(`page_level`,''),IFNULL(`comment`,'')) LIKE '%%%s%%'" % search

            res_total_count = await request.app.mysql.query_select(
                'select count(*) from users %s' % (search_sql))
            total_count = int(res_total_count[0][0])
            if total_count <= (page - 1) * page_size:
                page = 1

            page_sql = "limit %s, %s" % ((page - 1) * page_size, page_size)
            users = await request.app.mysql.query_select(
                'select * from users %s order by %s %s %s' %
                (search_sql, order_by, order, page_sql))
            response_list = []
            for raw_id, value in enumerate(users):
                n_id, username, password, page_level, comment, created_time = value
                response_list.append({
                    "raw_id": raw_id + 1,
                    "item_number": str(n_id),
                    "username": username,
                    "password": password,
                    "page_level": page_level,
                    "comment": comment,
                    "created_time": str(created_time),
                })
        except Exception as e:
            return response.json({
                "data": [],
                "page": 1,
                "total_count": 0,
                "status": "failed",
                "message": "获取失败,错误信息为%s" % str(e)
            })

        return response.json({
            "data": response_list,
            "page": page,
            "total_count": int(total_count),
            "status": "success"
        })
コード例 #3
0
class Employees(HTTPMethodView):
    decorators = [auth.login_required(handle_no_auth=handle_no_auth)]

    async def post(self, request):
        data = request.json if request.json is not None else {}
        args = request.args if request.args is not None else {}

        try:
            search = data.get('search', '')
            page = int(args.get('page', 1))
            page_size = int(args.get('page_size', 20))
            order_by = args.get('order_key', 'created_time')
            order = args.get('order', 'desc')
            if order.lower() not in ['desc', 'asc']:
                order = 'desc'

            search_sql = "where CONCAT(IFNULL(`name`,''),IFNULL(`phone_number`,''),IFNULL(`employee_type`,''),IFNULL(`status`,''),IFNULL(`created_time`,'')) LIKE '%%%s%%'" % search

            res_total_count = await request.app.mysql.query_select(
                'select count(*) from employee_list %s' % (search_sql))
            total_count = int(res_total_count[0][0])
            if total_count <= (page - 1) * page_size:
                page = 1

            page_sql = "limit %s, %s" % ((page - 1) * page_size, page_size)
            employee_list = await request.app.mysql.query_select(
                'select * from employee_list %s order by %s %s %s' %
                (search_sql, order_by, order, page_sql))
            response_list = []
            for raw_id, value in enumerate(employee_list):
                n_id, name, phone_number, first_day, employee_type, base_salary, percentage, status, created_time = value
                response_list.append({
                    "raw_id": raw_id + 1,
                    "name": name,
                    "phone_number": int(phone_number),
                    "first_day": first_day,
                    "employee_type": employee_type,
                    "base_salary": int(base_salary),
                    "percentage": float(percentage),
                    "status": status,
                    "created_time": str(created_time),
                })
        except Exception as e:
            return response.json({
                "data": [],
                "page": 1,
                "total_count": 0,
                "status": "failed",
                "message": "获取失败,错误信息为%s" % str(e)
            })

        return response.json({
            "data": response_list,
            "page": page,
            "total_count": int(total_count),
            "status": "success"
        })
コード例 #4
0
class Employee(HTTPMethodView):
    decorators = [auth.login_required(handle_no_auth=handle_no_auth)]

    async def get(self, request, phone_number):
        employee_list = await request.app.mysql.query_select(
            'select * from employee_list where phone_number = "%s"' %
            phone_number)
        response_list = []
        for raw_id, value in enumerate(employee_list):
            n_id, name, phone_number, first_day, employee_type, base_salary, percentage, status, created_time = value
            response_list.append({
                "raw_id": raw_id + 1,
                "name": name,
                "phone_number": phone_number,
                "first_day": first_day,
                "employee_type": employee_type,
                "base_salary": base_salary,
                "percentage": percentage,
                "status": status,
                "created_time": str(created_time),
            })
        return response.json({"data": response_list})

    async def post(self, request, phone_number):
        data = request.json
        name, phone_number, first_day, employee_type, base_salary, percentage, status = (
            data.get('name', ''), data.get('phone_number', phone_number),
            data.get('first_day', ''), data.get('employee_type', ''),
            data.get('base_salary', ''), data.get('percentage',
                                                  0), data.get('status', 0))
        sql = 'insert into employee_list (name, phone_number, first_day, employee_type, base_salary, percentage, status) values ("%s", "%s", "%s", "%s", "%s", "%s", "%s")' \
            % (name, phone_number, first_day, employee_type, base_salary, percentage, status)
        try:
            res = await request.app.mysql.query_other(sql)
        except Exception as e:
            return response.json({
                "status": "failed",
                "message": "增加员工失败,错误信息为%s" % str(e)
            })

        return response.json({"status": "success", "message": "成功增加一位员工!"})

    async def put(self, request, phone_number):
        data = request.json
        name, phone_number, first_day, employee_type, base_salary, percentage, status = (
            data.get('name', ''), data.get('phone_number', phone_number),
            data.get('first_day', ''), data.get('employee_type', ''),
            data.get('base_salary', ''), data.get('percentage',
                                                  ""), data.get('status', ""))
        sql = 'update employee_list set name = "%s", first_day = "%s", employee_type = "%s", base_salary = "%s", percentage = "%s", status = "%s" \
            where phone_number = "%s"' \
            % (name, first_day, employee_type, base_salary, percentage, status, phone_number)
        try:
            res = await request.app.mysql.query_other(sql)
        except Exception as e:
            return response.json({"status": "failed", "message": str(e)})
        return response.json({"status": "success", "message": "更新员工信息成功"})

    async def delete(self, request, phone_number):
        data = request.json
        sql = 'delete from employee_list where phone_number = "%s"' % (
            phone_number)
        try:
            res = await request.app.mysql.query_other(sql)
        except Exception as e:
            return response.json({
                "status": "failed",
                "message": "删除员工失败,错误信息为%s" % str(e)
            })
        return response.json({"status": "success", "message": "删除员工成功"})
コード例 #5
0
class Fellow(HTTPMethodView):
    decorators = [auth.login_required(handle_no_auth=handle_no_auth)]

    async def get(self, request, phone_number):
        fellow_list = await request.app.mysql.query_select(
            'select * from fellow_list where phone_number = "%s"' %
            phone_number)
        response_list = []
        for raw_id, value in enumerate(fellow_list):
            n_id, name, phone_number, birthday, password, card_type, money, created_by, created_time = value
            response_list.append({
                "raw_id": raw_id + 1,
                "name": name,
                "phone_number": phone_number,
                "birthday": birthday,
                "card_type": card_type,
                "money": money,
                "created_by": created_by,
                "created_time": str(created_time),
            })
        return response.json({"data": response_list, "status": "success"})

    async def post(self, request, phone_number):
        data = request.json
        name, phone_number, birthday, password, card_type, money, created_by = (
            data.get('name', ''), data.get('phone_number', phone_number),
            data.get('birthday', ''), data.get('password', ''),
            data.get('card_type', ''), data.get('money',
                                                0), data.get('created_by', ''))
        try:
            sql = 'insert into fellow_list (name, phone_number, birthday, password, card_type, money, created_by) values ("%s", "%s", "%s", "%s", "%s", "%s", "%s")' \
                % (name, phone_number, birthday, password, card_type, int(money), created_by)
            res = await request.app.mysql.query_other(sql)
        except Exception as e:
            return response.json({
                "status": "failed",
                "message": "开卡失败,错误信息为%s" % str(e)
            })

        return response.json({"status": "success", "message": "开卡成功"})

    @staticmethod
    @authorized(1)
    async def put(request, phone_number):
        data = request.json
        name, birthday, password, new_phone_number, card_type, money, created_by = (
            data.get('name', ''), data.get('birthday', ''),
            data.get('password', ''), data.get('new_phone_number', ''),
            data.get('card_type', ''), data.get('money',
                                                0), data.get('created_by', ''))
        if new_phone_number == "": new_phone_number = phone_number
        try:
            sql = 'update fellow_list set name = "%s", birthday = "%s", password = "******", phone_number = "%s", card_type = "%s", money = "%s", created_by = "%s" \
                where phone_number = "%s"' \
                % (name, birthday, password, new_phone_number, card_type, int(money), created_by, phone_number)
            res = await request.app.mysql.query_other(sql)
        except Exception as e:
            return response.json({"status": "failed", "message": str(e)})
        return response.json({"status": "success", "message": "更新会员信息成功"})

    @staticmethod
    @authorized(1)
    async def delete(request, phone_number):
        data = request.json
        sql = 'delete from fellow_list where phone_number = "%s"' % (
            phone_number)
        try:
            res = await request.app.mysql.query_other(sql)
        except Exception as e:
            return response.json({
                "status": "failed",
                "message": "删除会员失败,错误信息为%s" % str(e)
            })
        return response.json({"status": "success", "message": "删除会员成功"})
コード例 #6
0
class SellItem(HTTPMethodView):
    decorators = [auth.login_required(handle_no_auth=handle_no_auth)]

    async def get(self, request, item_number):
        data = request.json
        sell_item_list = await request.app.mysql.query_select(
            'select * from sell_item_list where item_number = %s' % item_number
        )
        response_list = []
        for raw_id, value in enumerate(sell_item_list):
            n_id, item_number, hairdresser, assistant, item_type, money, pay_type, fellow, comment, created_time = value
            response_list.append({
                "raw_id": raw_id + 1,
                "item_number": item_number,
                "hairdresser": hairdresser,
                "assistant": assistant,
                "item_type": item_type,
                "money": money,
                "pay_type": pay_type,
                "fellow": fellow,
                "comment": comment,
                "created_time": str(created_time),
            })
        return response.json({"data": response_list})

    async def post(self, request, item_number=1):
        data = request.json

        item_number = str(uuid.uuid4())[:18]
        hairdresser = data.get('hairdresser', '')
        assistant = data.get('assistant', '')
        item_type = data.get('item_type', '')
        money = data.get('money', 0)
        pay_type = data.get('pay_type', '现金')
        fellow = data.get('fellow', '')
        comment = data.get('comment', '')

        sql = 'insert into sell_item_list (item_number, hairdresser, assistant, item_type, money, pay_type, fellow, comment) values ("%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s")' \
            % (item_number, hairdresser, assistant, item_type, money, pay_type, fellow, comment)
        try:
            res = await request.app.mysql.query_other(sql)
        except Exception as e:
            return response.json({
                "status": "failed",
                "message": "开单失败,错误信息为%s" % str(e)
            })

        return response.json({
            "status": "success",
            "message": "开单成功",
            "item_number": item_number
        })

    @staticmethod
    @authorized(1)
    async def put(request, item_number):
        data = request.json

        hairdresser = data.get('hairdresser', '')
        assistant = data.get('assistant', '')
        item_type = data.get('item_type', [])
        money = data.get('money', 0)
        pay_type = data.get('pay_type', '现金')
        fellow = data.get('fellow', '')
        comment = data.get('comment', '')

        item_type = ','.join(item_type)
        money = int(money)
        sql = 'update sell_item_list set hairdresser = "%s", assistant = "%s", item_type = "%s", money = "%s", pay_type = "%s", fellow = "%s", comment = "%s" \
            where item_number = "%s"' \
            % (hairdresser, assistant, item_type, money, pay_type, fellow, comment, item_number)
        try:
            res = await request.app.mysql.query_other(sql)
        except Exception as e:
            print(e)
            return response.json({
                "status": "failed",
                "message": "更新失败,错误信息为%s" % str(e)
            })

        return response.json({"status": "success", "message": "更新成功"})

    def patch(self, request):
        return response.text('I am patch method')

    @staticmethod
    @authorized(1)
    async def delete(request, item_number):
        return response.json({"status": "success", "message": "删除成功"})
コード例 #7
0
ファイル: setting.py プロジェクト: cniu/barbershop
class User(HTTPMethodView):
    decorators = [
        auth.login_required(handle_no_auth=handle_no_auth),
        authorized.authorized(1)
    ]

    async def get(self, request, item_number):
        data = request.json
        item_list = await request.app.mysql.query_select(
            'select * from users where id = %s' % item_number)
        response_list = []
        for raw_id, value in enumerate(item_list):
            n_id, username, password, page_level, comment, created_time = value
            response_list.append({
                "raw_id": raw_id + 1,
                "item_number": str(n_id),
                "username": username,
                "password": password,
                "page_level": page_level,
                "comment": comment,
                "created_time": str(created_time),
            })
        return response.json({"data": response_list})

    async def post(self, request, item_number=1):
        data = request.json

        username = data.get('username', '')
        password = data.get('password', '')
        page_level = data.get('page_level', 1)
        comment = data.get('comment', '')
        page_level = int(page_level)

        sql = 'insert into users (username, password, page_level, comment) values ("%s", "%s", "%s", "%s")' \
            % (username, password, page_level, comment)
        try:
            res = await request.app.mysql.query_other(sql)
        except Exception as e:
            return response.json({
                "status": "failed",
                "message": "添加登陆用户失败,错误信息为%s" % str(e)
            })

        return response.json({"status": "success", "message": "添加登陆用户成功"})

    async def put(self, request, item_number):
        data = request.json

        username = data.get('username', '')
        password = data.get('password', '')
        page_level = data.get('page_level', '')
        comment = data.get('comment', '')

        sql = 'update users set username = "******", password = "******", page_level = "%s", comment = "%s" \
            where id = "%s"' \
            % (username, password, page_level, comment, item_number)
        try:
            res = await request.app.mysql.query_other(sql)
        except Exception as e:
            print(e)
            return response.json({
                "status": "failed",
                "message": "更新失败,错误信息为%s" % str(e)
            })

        return response.json({"status": "success", "message": "更新成功"})

    def patch(self, request):
        return response.text('I am patch method')

    async def delete(self, request, item_number):
        data = request.json

        sql = 'delete from users where id = "%s"' % (item_number)
        try:
            res = await request.app.mysql.query_other(sql)
        except Exception as e:
            print(e)
            return response.json({
                "status": "failed",
                "message": "更新失败,错误信息为%s" % str(e)
            })

        return response.json({"status": "success", "message": "更新成功"})
コード例 #8
0
ファイル: setting.py プロジェクト: cniu/barbershop
class EmployeeType(HTTPMethodView):
    decorators = [auth.login_required(handle_no_auth=handle_no_auth)]

    async def get(self, request, item_number):
        data = request.json
        item_list = await request.app.mysql.query_select(
            'select * from employee_types where id = %s' % item_number)
        response_list = []
        for raw_id, value in enumerate(item_list):
            n_id, type_name, responsibility, comment, created_time = value
            response_list.append({
                "raw_id": raw_id + 1,
                "item_number": str(n_id),
                "type_name": type_name,
                "responsibility": responsibility,
                "comment": comment,
                "created_time": str(created_time),
            })
        return response.json({"data": response_list})

    async def post(self, request, item_number=1):
        data = request.json

        type_name = data.get('type_name', '')
        responsibility = data.get('responsibility', '')
        comment = data.get('comment', '')

        sql = 'insert into employee_types (type_name, responsibility, comment) values ("%s", "%s", "%s")' \
            % (type_name, responsibility, comment)
        try:
            res = await request.app.mysql.query_other(sql)
        except Exception as e:
            return response.json({
                "status": "failed",
                "message": "添加人员类型失败,错误信息为%s" % str(e)
            })

        return response.json({"status": "success", "message": "添加人员类型成功"})

    async def put(self, request, item_number):
        data = request.json

        type_name = data.get('type_name', '')
        responsibility = data.get('responsibility', '')
        comment = data.get('comment', '')

        sql = 'update employee_types set type_name = "%s", responsibility = "%s", comment = "%s" \
            where id = "%s"' \
            % (type_name, responsibility, comment, item_number)
        try:
            res = await request.app.mysql.query_other(sql)
        except Exception as e:
            print(e)
            return response.json({
                "status": "failed",
                "message": "更新失败,错误信息为%s" % str(e)
            })

        return response.json({"status": "success", "message": "更新成功"})

    def patch(self, request):
        return response.text('I am patch method')

    async def delete(self, request, item_number):
        data = request.json

        sql = 'delete from employee_types where id = "%s"' % (item_number)
        try:
            res = await request.app.mysql.query_other(sql)
        except Exception as e:
            print(e)
            return response.json({
                "status": "failed",
                "message": "更新失败,错误信息为%s" % str(e)
            })

        return response.json({"status": "success", "message": "更新成功"})