diff --git a/backend/.gitignore b/backend/.gitignore index 31c46ed..86fef7e 100644 --- a/backend/.gitignore +++ b/backend/.gitignore @@ -10,6 +10,8 @@ /data /tmp +/test + *.db OPSYS \ No newline at end of file diff --git a/backend/go.mod b/backend/go.mod index 8829787..8c0d904 100644 --- a/backend/go.mod +++ b/backend/go.mod @@ -1,6 +1,6 @@ module ops -go 1.23.0 +go 1.24.0 toolchain go1.24.9 @@ -18,10 +18,10 @@ require ( github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect github.com/go-playground/validator/v10 v10.27.0 // indirect - github.com/go-sql-driver/mysql v1.8.1 // indirect + github.com/go-sql-driver/mysql v1.9.3 // indirect github.com/goccy/go-json v0.10.2 // indirect github.com/goccy/go-yaml v1.18.0 // indirect - github.com/google/uuid v1.3.0 // indirect + github.com/google/uuid v1.6.0 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect github.com/jackc/pgx/v5 v5.6.0 // indirect @@ -43,17 +43,18 @@ require ( github.com/ugorji/go/codec v1.3.0 // indirect go.uber.org/mock v0.5.0 // indirect golang.org/x/arch v0.20.0 // indirect - golang.org/x/crypto v0.40.0 // indirect - golang.org/x/mod v0.25.0 // indirect - golang.org/x/net v0.42.0 // indirect - golang.org/x/sync v0.16.0 // indirect - golang.org/x/sys v0.35.0 // indirect - golang.org/x/text v0.27.0 // indirect - golang.org/x/tools v0.34.0 // indirect + golang.org/x/crypto v0.46.0 // indirect + golang.org/x/mod v0.31.0 // indirect + golang.org/x/net v0.48.0 // indirect + golang.org/x/sync v0.19.0 // indirect + golang.org/x/sys v0.39.0 // indirect + golang.org/x/text v0.33.0 // indirect + golang.org/x/tools v0.40.0 // indirect google.golang.org/protobuf v1.36.9 // indirect + gorm.io/datatypes v1.2.7 // indirect gorm.io/driver/mysql v1.6.0 // indirect gorm.io/driver/postgres v1.6.0 // indirect - gorm.io/gorm v1.31.0 // indirect + gorm.io/gorm v1.31.1 // indirect modernc.org/libc v1.22.5 // indirect modernc.org/mathutil v1.5.0 // indirect modernc.org/memory v1.5.0 // indirect diff --git a/backend/go.sum b/backend/go.sum index ea8c2d0..bba8fdd 100644 --- a/backend/go.sum +++ b/backend/go.sum @@ -28,6 +28,8 @@ github.com/go-playground/validator/v10 v10.27.0 h1:w8+XrWVMhGkxOaaowyKH35gFydVHO github.com/go-playground/validator/v10 v10.27.0/go.mod h1:I5QpIEbmr8On7W0TktmJAumgzX4CA1XNl4ZmDuVHKKo= github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y= github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg= +github.com/go-sql-driver/mysql v1.9.3 h1:U/N249h2WzJ3Ukj8SowVFjdtZKfu9vlLZxjPXV1aweo= +github.com/go-sql-driver/mysql v1.9.3/go.mod h1:qn46aNg1333BRMNU69Lq93t8du/dwxI64Gl8i5p1WMU= github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/goccy/go-yaml v1.18.0 h1:8W7wMFS12Pcas7KU+VVkaiCng+kG8QiFeFwzFb+rwuw= @@ -35,6 +37,8 @@ github.com/goccy/go-yaml v1.18.0/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7Lk github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo= @@ -89,30 +93,47 @@ golang.org/x/arch v0.20.0 h1:dx1zTU0MAE98U+TQ8BLl7XsJbgze2WnNKF/8tGp/Q6c= golang.org/x/arch v0.20.0/go.mod h1:bdwinDaKcfZUGpH09BB7ZmOfhalA8lQdzl62l8gGWsk= golang.org/x/crypto v0.40.0 h1:r4x+VvoG5Fm+eJcxMaY8CQM7Lb0l1lsmjGBQ6s8BfKM= golang.org/x/crypto v0.40.0/go.mod h1:Qr1vMER5WyS2dfPHAlsOj01wgLbsyWtFn/aY+5+ZdxY= +golang.org/x/crypto v0.46.0 h1:cKRW/pmt1pKAfetfu+RCEvjvZkA9RimPbh7bhFjGVBU= +golang.org/x/crypto v0.46.0/go.mod h1:Evb/oLKmMraqjZ2iQTwDwvCtJkczlDuTmdJXoZVzqU0= golang.org/x/mod v0.25.0 h1:n7a+ZbQKQA/Ysbyb0/6IbB1H/X41mKgbhfv7AfG/44w= golang.org/x/mod v0.25.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww= +golang.org/x/mod v0.31.0 h1:HaW9xtz0+kOcWKwli0ZXy79Ix+UW/vOfmWI5QVd2tgI= +golang.org/x/mod v0.31.0/go.mod h1:43JraMp9cGx1Rx3AqioxrbrhNsLl2l/iNAvuBkrezpg= golang.org/x/net v0.42.0 h1:jzkYrhi3YQWD6MLBJcsklgQsoAcw89EcZbJw8Z614hs= golang.org/x/net v0.42.0/go.mod h1:FF1RA5d3u7nAYA4z2TkclSCKh68eSXtiFwcWQpPXdt8= +golang.org/x/net v0.48.0 h1:zyQRTTrjc33Lhh0fBgT/H3oZq9WuvRR5gPC70xpDiQU= +golang.org/x/net v0.48.0/go.mod h1:+ndRgGjkh8FGtu1w1FGbEC31if4VrNVMuKTgcAAnQRY= golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw= golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= +golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4= +golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI= golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= +golang.org/x/sys v0.39.0 h1:CvCKL8MeisomCi6qNZ+wbb0DN9E5AATixKsvNtMoMFk= +golang.org/x/sys v0.39.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= golang.org/x/text v0.27.0 h1:4fGWRpyh641NLlecmyl4LOe6yDdfaYNrGb2zdfo4JV4= golang.org/x/text v0.27.0/go.mod h1:1D28KMCvyooCX9hBiosv5Tz/+YLxj0j7XhWjpSUF7CU= +golang.org/x/text v0.33.0 h1:B3njUFyqtHDUI5jMn1YIr5B0IE2U0qck04r6d4KPAxE= +golang.org/x/text v0.33.0/go.mod h1:LuMebE6+rBincTi9+xWTY8TztLzKHc/9C1uBCG27+q8= golang.org/x/tools v0.34.0 h1:qIpSLOxeCYGg9TrcJokLBG4KFA6d795g0xkBkiESGlo= golang.org/x/tools v0.34.0/go.mod h1:pAP9OwEaY1CAW3HOmg3hLZC5Z0CCmzjAF2UQMSqNARg= +golang.org/x/tools v0.40.0/go.mod h1:Ik/tzLRlbscWpqqMRjyWYDisX8bG13FrdXp3o4Sr9lc= google.golang.org/protobuf v1.36.9 h1:w2gp2mA27hUeUzj9Ex9FBjsBm40zfaDtEWow293U7Iw= google.golang.org/protobuf v1.36.9/go.mod h1:fuxRtAxBytpl4zzqUh6/eyUujkJdNiuEkXntxiD/uRU= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gorm.io/datatypes v1.2.7 h1:ww9GAhF1aGXZY3EB3cJPJ7//JiuQo7DlQA7NNlVaTdk= +gorm.io/datatypes v1.2.7/go.mod h1:M2iO+6S3hhi4nAyYe444Pcb0dcIiOMJ7QHaUXxyiNZY= gorm.io/driver/mysql v1.6.0 h1:eNbLmNTpPpTOVZi8MMxCi2aaIm0ZpInbORNXDwyLGvg= gorm.io/driver/mysql v1.6.0/go.mod h1:D/oCC2GWK3M/dqoLxnOlaNKmXz8WNTfcS9y5ovaSqKo= gorm.io/driver/postgres v1.6.0 h1:2dxzU8xJ+ivvqTRph34QX+WrRaJlmfyPqXmoGVjMBa4= gorm.io/driver/postgres v1.6.0/go.mod h1:vUw0mrGgrTK+uPHEhAdV4sfFELrByKVGnaVRkXDhtWo= gorm.io/gorm v1.31.0 h1:0VlycGreVhK7RF/Bwt51Fk8v0xLiiiFdbGDPIZQ7mJY= gorm.io/gorm v1.31.0/go.mod h1:XyQVbO2k6YkOis7C2437jSit3SsDK72s7n7rsSHd+Gs= +gorm.io/gorm v1.31.1 h1:7CA8FTFz/gRfgqgpeKIBcervUn3xSyPUmr6B2WXJ7kg= +gorm.io/gorm v1.31.1/go.mod h1:XyQVbO2k6YkOis7C2437jSit3SsDK72s7n7rsSHd+Gs= modernc.org/libc v1.22.5 h1:91BNch/e5B0uPbJFgqbxXuOnxBQjlS//icfQEGmvyjE= modernc.org/libc v1.22.5/go.mod h1:jj+Z7dTNX8fBScMVNRAYZ/jF91K8fdT2hYMThc3YjBY= modernc.org/mathutil v1.5.0 h1:rV0Ko/6SfM+8G+yKiyI830l3Wuz1zRutdslNoQ0kfiQ= diff --git a/backend/models/sql.go b/backend/models/sql.go index 68ce82f..d72d0a9 100644 --- a/backend/models/sql.go +++ b/backend/models/sql.go @@ -5,6 +5,7 @@ import ( "time" "github.com/glebarez/sqlite" + "gorm.io/datatypes" "gorm.io/driver/mysql" "gorm.io/driver/postgres" "gorm.io/gorm" @@ -89,6 +90,24 @@ type APIRequestLog_ struct { CreatedAt time.Time `gorm:"column:created_at;type:datetime;default:CURRENT_TIMESTAMP" json:"created_at"` } +type TabPurchaseOrder struct { + ID uint `gorm:"primarykey" json:"id"` + Title string `gorm:"size:200;comment:标题" json:"title"` + Remark string `gorm:"type:text;comment:备注" json:"remark"` + Photos datatypes.JSON `gorm:"type:json;comment:照片哈希数组" json:"photos"` + Link string `gorm:"size:1000;comment:链接" json:"link"` + PartName string `gorm:"size:200;not null;comment:物品名称" json:"part_name"` + Styles datatypes.JSON `gorm:"type:json;comment:样式数组" json:"styles"` + Costs datatypes.JSON `gorm:"type:json;comment:费用明细数组" json:"costs"` + UpdateTime *time.Time `gorm:"type:datetime;autoUpdateTime;comment:更新时间" json:"update_time"` + TrackingNumber string `gorm:"size:100;uniqueIndex;comment:快递单号" json:"tracking_number"` + OrderStatus int8 `gorm:"default:1;comment:订单状态" json:"order_status"` + + CreatedAt *time.Time `gorm:"type:datetime;autoCreateTime"` + UpdatedAt *time.Time `gorm:"type:datetime;autoUpdateTime"` + DeletedAt gorm.DeletedAt `gorm:"index"` +} + func DatabaseInit() error { var err error fmt.Println("database_init") diff --git a/backend/routers/apiPurchase.go b/backend/routers/apiPurchase.go index 51dbc21..2e94606 100644 --- a/backend/routers/apiPurchase.go +++ b/backend/routers/apiPurchase.go @@ -4,16 +4,47 @@ import ( "fmt" "github.com/gin-gonic/gin" + "github.com/mitchellh/mapstructure" ) +type CostItem struct { + Cost float64 `json:"cost" binding:"required,min=0"` // 必须,非负 + CostT float64 `json:"cost_t" binding:"required,min=0"` // 必须,非负 + CurrencyType string `json:"currency_type" binding:"required"` // 必须 + Int int `json:"int" binding:"required"` // 必须 + Type string `json:"type" binding:"required"` // 必须 +} +type From_purchase_addorder struct { + Costs []CostItem `json:"costs"` // + Link string `json:"link"` // 可选 + OrderStatus string `json:"order_status" binding:"required"` // + PartName string `json:"part_name"` // 可选 + Photos []string `json:"photos"` // 可选 + Remark string `json:"remark"` // 可选 + Styles string `json:"styles"` // 可选 + Title string `json:"title" binding:"required"` // 必须 + TrackingNumber string `json:"tracking_number"` // 可选 + UpdateTime string `json:"update_time"` // 可选 +} + func ApiPurchase(r *gin.RouterGroup) { r.POST("/addorder", func(ctx *gin.Context) { isAuth, user, data := AuthenticationAuthority(ctx) if isAuth { - fmt.Println(isAuth) + + //需要处理提交的数据,接口有固定的数据格式,不允许乱搞 + //fmt.Println(isAuth) fmt.Println(user) - fmt.Println(data) + //DebugPrintJson(data) + var jsondata From_purchase_addorder + if err := mapstructure.Decode(data, &jsondata); err == nil { + + fmt.Println("转换后数据:\n", jsondata) + + } else { + ReturnJson(ctx, "jsonErr", nil) + } } else { ReturnJson(ctx, "jsonErr", nil) diff --git a/backend/routers/return.go b/backend/routers/return.go index 6429543..d0faa4e 100644 --- a/backend/routers/return.go +++ b/backend/routers/return.go @@ -1,11 +1,19 @@ package routers import ( + "encoding/json" + "fmt" "ops/models" "github.com/gin-gonic/gin" ) +func DebugPrintJson(data map[string]interface{}) { + p, _ := json.MarshalIndent(data, "", " ") + fmt.Println("\n", string(p)) + +} + func ReturnJson(ctx *gin.Context, errMsg string, data map[string]interface{}) { var errCode = ErrorCode[errMsg] returnData := map[string]interface{}{} diff --git a/frontent/ops_vue_js/src/views/purchase/addorder.vue b/frontent/ops_vue_js/src/views/purchase/addorder.vue index 576d24e..3344dc7 100644 --- a/frontent/ops_vue_js/src/views/purchase/addorder.vue +++ b/frontent/ops_vue_js/src/views/purchase/addorder.vue @@ -135,7 +135,7 @@ function submit_order() { console.log(submit_sheet); my_network_func.postJson("/purchase/addorder", submit_sheet, (r) => { - console.log(r) + console.log(r); }); } @@ -224,6 +224,16 @@ watch( v-model="submit_sheet.remark" > + + +
@@ -264,17 +274,6 @@ watch( :placeholder="t('purchase_addorder.add_style')" v-model="submit_sheet.styles" > - - - -
@@ -361,8 +360,8 @@ watch( type="number" class="form-control" step="0.01" - min="0" - value="0" + min="0.0" + value="0.0" v-model="cost_sheet.cost" />