shangcheng/include/product.hpp

65 lines
1.6 KiB
C++
Raw Normal View History

2026-05-06 02:54:13 +00:00
#ifndef MALL_PRODUCT_HPP
#define MALL_PRODUCT_HPP
#include <string>
#include <cstdint>
/**
* @brief
*/
class Product {
public:
/**
* @brief
*/
Product() = default;
/**
* @brief
* @param id
* @param name
* @param price
* @param stock
*/
Product(uint64_t id, std::string name, double price, int stock);
/** @brief 获取商品编号 */
uint64_t getId() const noexcept { return id_; }
/** @brief 获取商品名称 */
const std::string& getName() const noexcept { return name_; }
/** @brief 获取商品单价 */
double getPrice() const noexcept { return price_; }
/** @brief 获取库存数量 */
int getStock() const noexcept { return stock_; }
/**
* @brief
* @param quantity
* @return true false
*/
bool reduceStock(int quantity);
/**
* @brief
* @param quantity
*/
void addStock(int quantity);
/**
* @brief
* @return "[#1001] 苹果 ¥5.50 (库存:20)"
*/
std::string toString() const;
private:
uint64_t id_ = 0; ///< 商品编号
std::string name_; ///< 商品名称
double price_ = 0.0; ///< 单价
int stock_ = 0; ///< 库存数量
};
#endif // MALL_PRODUCT_HPP