コード例 #1
0
    def add_books_by_excel(self, user_id, file):
        """
        根据上传的 excel 更新书目库
        """
        user_service = UserService()
        user = user_service.query_user_by_id(user_id)
        try:
            df = pd.read_excel(file)
            for ix, row in df.iterrows():
                book = {}
                book['isbn'] = int(row.get('ISBN', ''))
                book['name'] = str(row.get('书名', ''))
                book['author'] = str(row.get('作者', '无'))
                book['press'] = str(row.get('出版社', ''))
                book['quantity'] = int(row.get('数量', ''))
                book['description'] = str(row.get('描述', '无'))
                book['price'] = float(row.get('定价', ''))
                book['supplier_id'] = str(user_id)
                book['supplier'] = str(user.get('区域', ''))
                book['discount'] = float(row.get('折扣', ''))

                self.book_update(book)

            return True

        except Exception as e:
            app.logger.error(e)
            return False
コード例 #2
0
def query_user_info():
    """
    @api {GET} /profile/query 查询用户信息
    @apiGroup Users
    @apiVersion 0.0.1
    @apiDescription 用于查询用户资料
    @apiSuccess (200) {String} msg 信息
    @apiSuccess (200) {int} code 0 代表无错误 1代表有错误
    @apiSuccessExample {json} 返回样例:
                   {
                        "status": "ok",
                        "payload":{
                            "realname": "132",
                            "username": "******",
                            "phone": "pwd",
                            "mail": "*****@*****.**",
                            "nickname": "guest",
                            "gender": "23",
                            "password": "******",
                            "qq": "12312"
                        }
                    }
    @apiError (400) {String} msg 信息
    @apiErrorExample {json} 返回样例:
                   {"status": "fail", "message": "用户不存在"}
    """
    user_id = current_user.id
    userinfo = UserService.query_user_by_id(userid=user_id)

    if userinfo:
        return make_api_response(payload=userinfo)
    else:
        return make_api_response(message="用户不存在", statusCode=400)
コード例 #3
0
    def book_add(self, user_id, book_info):
        """
        新增书目
        """
        if book_info:
            book = Book()
            book.isbn = book_info.get('isbn')
            book.name = book_info.get('name')
            book.author = book_info.get('author')
            book.press = book_info.get('press')
            book.quantity = book_info.get('quantity')
            book.description = book_info.get('description')
            book.price = book_info.get('price')
            book.discount = book_info.get('discount')
            book.supplier_id = user_id

            user_service = UserService()
            user_name = user_service.query_user_by_id(user_id).get('username')
            book.supplier = user_name
            book.is_active = 1

            db.session.add(book)
            db.session.flush()
            db.session.commit()

            return True

        return False