feat: #13 公开商品 API 补充 code/barcode/batch.quantity,报错反馈携带商品和门店信息

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
wangjia
2026-06-08 22:39:59 +08:00
parent 3b2ebc0202
commit fab7bd21dd
4 changed files with 39 additions and 24 deletions
+23 -21
View File
@@ -17,16 +17,17 @@ func NewErrorReportHandler(db *gorm.DB) *ErrorReportHandler {
} }
type submitErrorRequest struct { type submitErrorRequest struct {
ErrorType string `json:"error_type" binding:"required"` ErrorType string `json:"error_type" binding:"required"`
AppVersion string `json:"app_version"` AppVersion string `json:"app_version"`
Platform string `json:"platform"` Platform string `json:"platform"`
Username string `json:"username"` Username string `json:"username"`
ShopID uint64 `json:"shop_id"` ShopID uint64 `json:"shop_id"`
ShopNo string `json:"shop_no"` ShopNo string `json:"shop_no"`
Role string `json:"role"` Role string `json:"role"`
ErrorMsg string `json:"error_msg" binding:"required"` ProductInfo string `json:"product_info"`
StackTrace string `json:"stack_trace"` ErrorMsg string `json:"error_msg" binding:"required"`
OccurredAt int64 `json:"occurred_at"` // Unix 毫秒 StackTrace string `json:"stack_trace"`
OccurredAt int64 `json:"occurred_at"` // Unix 毫秒
} }
// Submit POST /api/v1/public/errors // Submit POST /api/v1/public/errors
@@ -49,17 +50,18 @@ func (h *ErrorReportHandler) Submit(c *gin.Context) {
} }
report := model.ErrorReport{ report := model.ErrorReport{
ErrorType: req.ErrorType, ErrorType: req.ErrorType,
AppVersion: req.AppVersion, AppVersion: req.AppVersion,
Platform: req.Platform, Platform: req.Platform,
Username: req.Username, Username: req.Username,
ShopID: req.ShopID, ShopID: req.ShopID,
ShopNo: req.ShopNo, ShopNo: req.ShopNo,
Role: req.Role, Role: req.Role,
ClientIP: c.ClientIP(), ProductInfo: req.ProductInfo,
ErrorMsg: req.ErrorMsg, ClientIP: c.ClientIP(),
StackTrace: stack, ErrorMsg: req.ErrorMsg,
OccurredAt: occurredAt, StackTrace: stack,
OccurredAt: occurredAt,
} }
if err := h.db.Create(&report).Error; err != nil { if err := h.db.Create(&report).Error; err != nil {
+3
View File
@@ -72,6 +72,7 @@ func (h *PublicHandler) GetProduct(c *gin.Context) {
"production_date": pdStr, "production_date": pdStr,
"batch_no": inv.BatchNo, "batch_no": inv.BatchNo,
"in_stock_date": inv.CreatedAt.Format("2006-01-02"), "in_stock_date": inv.CreatedAt.Format("2006-01-02"),
"quantity": inv.Quantity,
} }
} }
@@ -100,6 +101,8 @@ func (h *PublicHandler) GetProduct(c *gin.Context) {
"data": gin.H{ "data": gin.H{
"id": product.ID, "id": product.ID,
"name": product.Name, "name": product.Name,
"code": product.Code,
"barcode": product.Barcode,
"series": product.Series, "series": product.Series,
"spec": product.Spec, "spec": product.Spec,
"brand": product.Brand, "brand": product.Brand,
+3 -2
View File
@@ -12,8 +12,9 @@ type ErrorReport struct {
Username string `gorm:"size:50;index" json:"username"` Username string `gorm:"size:50;index" json:"username"`
ShopID uint64 `gorm:"index" json:"shop_id"` ShopID uint64 `gorm:"index" json:"shop_id"`
ShopNo string `gorm:"size:50" json:"shop_no"` ShopNo string `gorm:"size:50" json:"shop_no"`
Role string `gorm:"size:20" json:"role"` Role string `gorm:"size:20" json:"role"`
ClientIP string `gorm:"size:60" json:"client_ip"` ProductInfo string `gorm:"size:200" json:"product_info"`
ClientIP string `gorm:"size:60" json:"client_ip"`
ErrorMsg string `gorm:"type:text;not null" json:"error_msg"` ErrorMsg string `gorm:"type:text;not null" json:"error_msg"`
StackTrace string `gorm:"type:text" json:"stack_trace"` StackTrace string `gorm:"type:text" json:"stack_trace"`
OccurredAt time.Time `json:"occurred_at"` OccurredAt time.Time `json:"occurred_at"`
@@ -70,13 +70,22 @@ class _PublicProductScreenState extends State<PublicProductScreen> {
title: title, title: title,
hint: hint, hint: hint,
onSubmit: (msg) async { onSubmit: (msg) async {
final shopNo = (_data?['shop'] as Map<String, dynamic>?)?['code'] as String? ?? '';
final productName = _data?['name'] as String? ?? '';
final productCode = _data?['code'] as String? ?? '';
final productInfo = [
if (productName.isNotEmpty) productName,
if (productCode.isNotEmpty) productCode,
if (widget.publicId.isNotEmpty) widget.publicId,
].join(' / ');
await _dio.post( await _dio.post(
'${AppConfig.apiBaseUrl}/public/errors', '${AppConfig.apiBaseUrl}/public/errors',
data: { data: {
'error_type': errorType, 'error_type': errorType,
'error_msg': msg, 'error_msg': msg,
'platform': 'web-scan', 'platform': 'web-scan',
'shop_no': (_data?['shop'] as Map<String, dynamic>?)?['code'] as String? ?? '', 'shop_no': shopNo,
if (productInfo.isNotEmpty) 'product_info': productInfo,
}, },
); );
}, },