├── .idea ├── .gitignore ├── modules.xml ├── reggie.iml └── vcs.xml ├── README.md ├── docs ├── docs.go ├── swagger.json └── swagger.yaml ├── go.mod ├── go.sum ├── images ├── img.png ├── img1.png ├── img2.png ├── img_1.png ├── img_10.png ├── img_11.png ├── img_12.png ├── img_13.png ├── img_14.png ├── img_15.png ├── img_16.png ├── img_17.png ├── img_18.png ├── img_19.png ├── img_2.png ├── img_20.png ├── img_21.png ├── img_22.png ├── img_23.png ├── img_24.png ├── img_25.png ├── img_26.png ├── img_27.png ├── img_28.png ├── img_29.png ├── img_3.png ├── img_30.png ├── img_31.png ├── img_32.png ├── img_33.png ├── img_34.png ├── img_35.png ├── img_36.png ├── img_37.png ├── img_38.png ├── img_39.png ├── img_4.png ├── img_40.png ├── img_41.png ├── img_42.png ├── img_43.png ├── img_44.png ├── img_45.png ├── img_46.png ├── img_47.png ├── img_48.png ├── img_49.png ├── img_5.png ├── img_50.png ├── img_51.png ├── img_52.png ├── img_53.png ├── img_54.png ├── img_55.png ├── img_56.png ├── img_57.png ├── img_58.png ├── img_59.png ├── img_6.png ├── img_60.png ├── img_61.png ├── img_62.png ├── img_63.png ├── img_64.png ├── img_65.png ├── img_66.png ├── img_67.png ├── img_68.png ├── img_69.png ├── img_7.png ├── img_70.png ├── img_71.png ├── img_72.png ├── img_73.png ├── img_74.png ├── img_75.png ├── img_8.png └── img_9.png ├── internal ├── config │ ├── config.go │ └── config.yaml ├── db │ ├── addressBook_dao.go │ ├── category_dao.go │ ├── db.go │ ├── dish_dao.go │ ├── dish_flavor_dao.go │ ├── employee_dao.go │ ├── order_dao.go │ ├── order_detail_dao.go │ ├── setmeal_dao.go │ ├── setmeal_dish_dao.go │ ├── shoppingcart_dao.go │ └── user_dao.go ├── middleware │ ├── jwt.go │ └── swagger.go ├── models │ ├── common │ │ └── common.go │ ├── constant │ │ ├── message_c │ │ │ └── common.go │ │ └── status_c │ │ │ └── common.go │ ├── dto │ │ ├── common.go │ │ ├── order_page_query.go │ │ ├── orders_submitdto.go │ │ └── shoppingcartdto.go │ ├── model │ │ ├── address_book.gen.go │ │ ├── category.go │ │ ├── dish.go │ │ ├── dish_flavor.go │ │ ├── employee.go │ │ ├── order_detail.gen.go │ │ ├── orders.go │ │ ├── setmeal.gen.go │ │ ├── setmeal_dish.go │ │ ├── shopping_cart.gen.go │ │ └── user.gen.go │ └── vo │ │ ├── common.go │ │ ├── dishvo.go │ │ ├── orderVO.go │ │ └── order_submitVO.go ├── router │ ├── admin │ │ ├── category_router.go │ │ ├── common_router.go │ │ ├── dish_router.go │ │ ├── employee_router.go │ │ ├── order_router.go │ │ ├── setmeal_router.go │ │ ├── shop_router.go │ │ └── work_space_router.go │ ├── router.go │ ├── service │ │ ├── address_service.go │ │ ├── category_service.go │ │ ├── dish_service.go │ │ ├── employee_service.go │ │ ├── order_service.go │ │ ├── setmeal_service.go │ │ ├── shop_service.go │ │ ├── shoppcart_service.go │ │ ├── user_service.go │ │ └── work_space_service.go │ └── user │ │ ├── address_router.go │ │ ├── category_router.go │ │ ├── dish_router.go │ │ ├── order_router.go │ │ ├── setmeal_router.go │ │ ├── shoopingcart_router.go │ │ └── user_router.go └── utils │ └── str.go ├── main.go ├── pkg ├── obs │ ├── acl.go │ └── config.go ├── redis │ ├── acl.go │ └── config.go └── wx │ ├── acl.go │ └── config.go └── sql ├── gen.go └── sky.sql /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Editor-based HTTP Client requests 5 | /httpRequests/ 6 | # Datasource local storage ignored files 7 | /dataSources/ 8 | /dataSources.local.xml 9 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/reggie.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /docs/docs.go: -------------------------------------------------------------------------------- 1 | // Package docs Code generated by swaggo/swag. DO NOT EDIT 2 | package docs 3 | 4 | import "github.com/swaggo/swag" 5 | 6 | const docTemplate = `{ 7 | "schemes": {{ marshal .Schemes }}, 8 | "swagger": "2.0", 9 | "info": { 10 | "description": "{{escape .Description}}", 11 | "title": "{{.Title}}", 12 | "contact": { 13 | "name": "onenewcode", 14 | "url": "https://github.com/onenewcode" 15 | }, 16 | "license": { 17 | "name": "Apache 2.0", 18 | "url": "http://www.apache.org/licenses/LICENSE-2.0.html" 19 | }, 20 | "version": "{{.Version}}" 21 | }, 22 | "host": "{{.Host}}", 23 | "basePath": "{{.BasePath}}", 24 | "paths": { 25 | "/admin/employee": { 26 | "post": { 27 | "consumes": [ 28 | "application/json" 29 | ], 30 | "produces": [ 31 | "application/json" 32 | ], 33 | "summary": "存储用户", 34 | "responses": {} 35 | } 36 | } 37 | } 38 | }` 39 | 40 | // SwaggerInfo holds exported Swagger Info so clients can modify it 41 | var SwaggerInfo = &swag.Spec{ 42 | Version: "0.1", 43 | Host: "localhost:8080", 44 | BasePath: "/", 45 | Schemes: []string{"http"}, 46 | Title: "regiee", 47 | Description: "sky-take-out", 48 | InfoInstanceName: "swagger", 49 | SwaggerTemplate: docTemplate, 50 | } 51 | 52 | func init() { 53 | swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo) 54 | } 55 | -------------------------------------------------------------------------------- /docs/swagger.json: -------------------------------------------------------------------------------- 1 | { 2 | "schemes": [ 3 | "http" 4 | ], 5 | "swagger": "2.0", 6 | "info": { 7 | "description": "sky-take-out", 8 | "title": "regiee", 9 | "contact": { 10 | "name": "onenewcode", 11 | "url": "https://github.com/onenewcode" 12 | }, 13 | "license": { 14 | "name": "Apache 2.0", 15 | "url": "http://www.apache.org/licenses/LICENSE-2.0.html" 16 | }, 17 | "version": "0.1" 18 | }, 19 | "host": "localhost:8080", 20 | "basePath": "/", 21 | "paths": { 22 | "/admin/employee": { 23 | "post": { 24 | "consumes": [ 25 | "application/json" 26 | ], 27 | "produces": [ 28 | "application/json" 29 | ], 30 | "summary": "存储用户", 31 | "responses": {} 32 | } 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /docs/swagger.yaml: -------------------------------------------------------------------------------- 1 | basePath: / 2 | host: localhost:8080 3 | info: 4 | contact: 5 | name: onenewcode 6 | url: https://github.com/onenewcode 7 | description: sky-take-out 8 | license: 9 | name: Apache 2.0 10 | url: http://www.apache.org/licenses/LICENSE-2.0.html 11 | title: regiee 12 | version: "0.1" 13 | paths: 14 | /admin/employee: 15 | post: 16 | consumes: 17 | - application/json 18 | produces: 19 | - application/json 20 | responses: {} 21 | summary: 存储用户 22 | schemes: 23 | - http 24 | swagger: "2.0" 25 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module reggie 2 | 3 | go 1.21.1 4 | 5 | require ( 6 | github.com/cloudwego/hertz v0.7.2 7 | github.com/hertz-contrib/jwt v1.0.2 8 | github.com/hertz-contrib/logger/accesslog v0.0.0-20240128134225-6b18af47a115 9 | github.com/hertz-contrib/swagger v0.0.0-20230410084747-96f1a1b976ab 10 | github.com/jinzhu/copier v0.4.0 11 | github.com/minio/minio-go v6.0.14+incompatible 12 | github.com/redis/go-redis/v9 v9.5.1 13 | github.com/spf13/viper v1.16.0 14 | github.com/swaggo/files v0.0.0-20210815190702-a29dd2bc99b2 15 | github.com/swaggo/swag v1.8.2 16 | gorm.io/driver/mysql v1.5.4 17 | gorm.io/gen v0.3.25 18 | gorm.io/gorm v1.25.7 19 | ) 20 | 21 | require ( 22 | golang.org/x/crypto v0.19.0 // indirect 23 | google.golang.org/protobuf v1.30.0 // indirect 24 | github.com/KyleBanks/depth v1.2.1 // indirect 25 | github.com/PuerkitoBio/purell v1.1.1 // indirect 26 | github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect 27 | github.com/bytedance/go-tagexpr/v2 v2.9.2 // indirect 28 | github.com/bytedance/gopkg v0.0.0-20220413063733-65bf48ffb3a7 // indirect 29 | github.com/bytedance/sonic v1.8.1 // indirect 30 | github.com/cespare/xxhash/v2 v2.2.0 // indirect 31 | github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect 32 | github.com/cloudwego/netpoll v0.5.0 // indirect 33 | github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect 34 | github.com/fsnotify/fsnotify v1.6.0 // indirect 35 | github.com/go-ini/ini v1.67.0 // indirect 36 | github.com/go-openapi/jsonpointer v0.19.5 // indirect 37 | github.com/go-openapi/jsonreference v0.19.6 // indirect 38 | github.com/go-openapi/spec v0.20.4 // indirect 39 | github.com/go-openapi/swag v0.19.15 // indirect 40 | github.com/go-sql-driver/mysql v1.7.1 // indirect 41 | github.com/golang-jwt/jwt/v4 v4.4.1 // indirect 42 | github.com/golang/protobuf v1.5.3 // indirect 43 | github.com/google/uuid v1.6.0 44 | github.com/hashicorp/hcl v1.0.0 // indirect 45 | github.com/henrylee2cn/ameda v1.4.10 // indirect 46 | github.com/henrylee2cn/goutil v0.0.0-20210127050712-89660552f6f8 // indirect 47 | github.com/jinzhu/inflection v1.0.0 // indirect 48 | github.com/jinzhu/now v1.1.5 // indirect 49 | github.com/josharian/intern v1.0.0 // indirect 50 | github.com/klauspost/cpuid/v2 v2.0.9 // indirect 51 | github.com/magiconair/properties v1.8.7 // indirect 52 | github.com/mailru/easyjson v0.7.6 // indirect 53 | github.com/mitchellh/go-homedir v1.1.0 // indirect 54 | github.com/mitchellh/mapstructure v1.5.0 // indirect 55 | github.com/nyaruka/phonenumbers v1.0.55 // indirect 56 | github.com/pelletier/go-toml/v2 v2.0.8 // indirect 57 | github.com/spf13/afero v1.9.5 // indirect 58 | github.com/spf13/cast v1.5.1 // indirect 59 | github.com/spf13/jwalterweatherman v1.1.0 // indirect 60 | github.com/spf13/pflag v1.0.5 // indirect 61 | github.com/subosito/gotenv v1.4.2 // indirect 62 | github.com/tidwall/gjson v1.14.4 // indirect 63 | github.com/tidwall/match v1.1.1 // indirect 64 | github.com/tidwall/pretty v1.2.0 // indirect 65 | github.com/twitchyliquid64/golang-asm v0.15.1 // indirect 66 | golang.org/x/arch v0.0.0-20210923205945-b76863e36670 // indirect 67 | golang.org/x/mod v0.15.0 // indirect 68 | golang.org/x/net v0.21.0 // indirect 69 | golang.org/x/sys v0.17.0 // indirect 70 | golang.org/x/text v0.14.0 // indirect 71 | golang.org/x/tools v0.15.0 // indirect 72 | gopkg.in/ini.v1 v1.67.0 // indirect 73 | gopkg.in/yaml.v2 v2.4.0 // indirect 74 | gopkg.in/yaml.v3 v3.0.1 // indirect 75 | gorm.io/datatypes v1.1.1-0.20230130040222-c43177d3cf8c // indirect 76 | gorm.io/hints v1.1.2 // indirect 77 | gorm.io/plugin/dbresolver v1.5.0 // indirect 78 | ) 79 | -------------------------------------------------------------------------------- /images/img.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img.png -------------------------------------------------------------------------------- /images/img1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img1.png -------------------------------------------------------------------------------- /images/img2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img2.png -------------------------------------------------------------------------------- /images/img_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_1.png -------------------------------------------------------------------------------- /images/img_10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_10.png -------------------------------------------------------------------------------- /images/img_11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_11.png -------------------------------------------------------------------------------- /images/img_12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_12.png -------------------------------------------------------------------------------- /images/img_13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_13.png -------------------------------------------------------------------------------- /images/img_14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_14.png -------------------------------------------------------------------------------- /images/img_15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_15.png -------------------------------------------------------------------------------- /images/img_16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_16.png -------------------------------------------------------------------------------- /images/img_17.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_17.png -------------------------------------------------------------------------------- /images/img_18.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_18.png -------------------------------------------------------------------------------- /images/img_19.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_19.png -------------------------------------------------------------------------------- /images/img_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_2.png -------------------------------------------------------------------------------- /images/img_20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_20.png -------------------------------------------------------------------------------- /images/img_21.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_21.png -------------------------------------------------------------------------------- /images/img_22.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_22.png -------------------------------------------------------------------------------- /images/img_23.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_23.png -------------------------------------------------------------------------------- /images/img_24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_24.png -------------------------------------------------------------------------------- /images/img_25.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_25.png -------------------------------------------------------------------------------- /images/img_26.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_26.png -------------------------------------------------------------------------------- /images/img_27.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_27.png -------------------------------------------------------------------------------- /images/img_28.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_28.png -------------------------------------------------------------------------------- /images/img_29.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_29.png -------------------------------------------------------------------------------- /images/img_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_3.png -------------------------------------------------------------------------------- /images/img_30.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_30.png -------------------------------------------------------------------------------- /images/img_31.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_31.png -------------------------------------------------------------------------------- /images/img_32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_32.png -------------------------------------------------------------------------------- /images/img_33.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_33.png -------------------------------------------------------------------------------- /images/img_34.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_34.png -------------------------------------------------------------------------------- /images/img_35.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_35.png -------------------------------------------------------------------------------- /images/img_36.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_36.png -------------------------------------------------------------------------------- /images/img_37.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_37.png -------------------------------------------------------------------------------- /images/img_38.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_38.png -------------------------------------------------------------------------------- /images/img_39.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_39.png -------------------------------------------------------------------------------- /images/img_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_4.png -------------------------------------------------------------------------------- /images/img_40.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_40.png -------------------------------------------------------------------------------- /images/img_41.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_41.png -------------------------------------------------------------------------------- /images/img_42.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_42.png -------------------------------------------------------------------------------- /images/img_43.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_43.png -------------------------------------------------------------------------------- /images/img_44.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_44.png -------------------------------------------------------------------------------- /images/img_45.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_45.png -------------------------------------------------------------------------------- /images/img_46.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_46.png -------------------------------------------------------------------------------- /images/img_47.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_47.png -------------------------------------------------------------------------------- /images/img_48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_48.png -------------------------------------------------------------------------------- /images/img_49.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_49.png -------------------------------------------------------------------------------- /images/img_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_5.png -------------------------------------------------------------------------------- /images/img_50.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_50.png -------------------------------------------------------------------------------- /images/img_51.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_51.png -------------------------------------------------------------------------------- /images/img_52.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_52.png -------------------------------------------------------------------------------- /images/img_53.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_53.png -------------------------------------------------------------------------------- /images/img_54.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_54.png -------------------------------------------------------------------------------- /images/img_55.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_55.png -------------------------------------------------------------------------------- /images/img_56.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_56.png -------------------------------------------------------------------------------- /images/img_57.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_57.png -------------------------------------------------------------------------------- /images/img_58.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_58.png -------------------------------------------------------------------------------- /images/img_59.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_59.png -------------------------------------------------------------------------------- /images/img_6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_6.png -------------------------------------------------------------------------------- /images/img_60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_60.png -------------------------------------------------------------------------------- /images/img_61.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_61.png -------------------------------------------------------------------------------- /images/img_62.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_62.png -------------------------------------------------------------------------------- /images/img_63.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_63.png -------------------------------------------------------------------------------- /images/img_64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_64.png -------------------------------------------------------------------------------- /images/img_65.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_65.png -------------------------------------------------------------------------------- /images/img_66.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_66.png -------------------------------------------------------------------------------- /images/img_67.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_67.png -------------------------------------------------------------------------------- /images/img_68.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_68.png -------------------------------------------------------------------------------- /images/img_69.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_69.png -------------------------------------------------------------------------------- /images/img_7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_7.png -------------------------------------------------------------------------------- /images/img_70.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_70.png -------------------------------------------------------------------------------- /images/img_71.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_71.png -------------------------------------------------------------------------------- /images/img_72.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_72.png -------------------------------------------------------------------------------- /images/img_73.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_73.png -------------------------------------------------------------------------------- /images/img_74.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_74.png -------------------------------------------------------------------------------- /images/img_75.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_75.png -------------------------------------------------------------------------------- /images/img_8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_8.png -------------------------------------------------------------------------------- /images/img_9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onenewcode/reggie/60837cd2fcbe7e2c5c5893675756acffc4e57129/images/img_9.png -------------------------------------------------------------------------------- /internal/config/config.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | import ( 4 | "github.com/spf13/viper" 5 | "time" 6 | ) 7 | 8 | // 全局变量,提供给内部的其他包使用 9 | var ( 10 | ServerSetting *ServerSettingS 11 | AppSetting *AppSettingS 12 | DatabaseSetting *DatabaseSettingS 13 | ) 14 | 15 | type ServerSettingS struct { 16 | RunMode string 17 | HttpPort string 18 | ReadTimeout time.Duration 19 | WriteTimeout time.Duration 20 | } 21 | 22 | type AppSettingS struct { 23 | DefaultPageSize int 24 | MaxPageSize int 25 | LogSavePath string 26 | LogFileName string 27 | LogFileExt string 28 | } 29 | 30 | type DatabaseSettingS struct { 31 | DBType string 32 | Url string 33 | TablePrefix string 34 | Charset string 35 | ParseTime bool 36 | MaxIdleConns int 37 | MaxOpenConns int 38 | } 39 | 40 | // 初始化一个配置类,让viper读取指定的配置文件 41 | func configPath() (*viper.Viper, error) { 42 | vp := viper.New() 43 | vp.SetConfigName("config") 44 | vp.AddConfigPath("internal/config/") 45 | vp.SetConfigType("yaml") 46 | err := vp.ReadInConfig() 47 | if err != nil { 48 | return nil, err 49 | } 50 | 51 | return vp, nil 52 | } 53 | 54 | func readSection(vp *viper.Viper, k string, v interface{}) error { 55 | err := vp.UnmarshalKey(k, v) 56 | if err != nil { 57 | return err 58 | } 59 | 60 | return nil 61 | } 62 | 63 | // 初始化配置,把所有的数据读取后放入global的全局变量中 64 | func InitConfig() { 65 | vp, err := configPath() 66 | if err != nil { 67 | panic("配置文件读取错误") 68 | } 69 | err = readSection(vp, "Server", &ServerSetting) 70 | if err != nil { 71 | panic("Server类读取错误,检查server类映射是否正确") 72 | } 73 | err = readSection(vp, "App", &AppSetting) 74 | if err != nil { 75 | panic("App类读取错误,检查App类映射是否正确") 76 | } 77 | err = readSection(vp, "Database", &DatabaseSetting) 78 | if err != nil { 79 | panic("Database类读取错误,检查Database类映射是否正确") 80 | } 81 | 82 | ServerSetting.ReadTimeout *= time.Second 83 | ServerSetting.WriteTimeout *= time.Second 84 | } 85 | -------------------------------------------------------------------------------- /internal/config/config.yaml: -------------------------------------------------------------------------------- 1 | Server: 2 | RunMode: debug 3 | HttpPort: :8080 4 | ReadTimeout: 60 5 | WriteTimeout: 60 6 | App: 7 | DefaultPageSize: 10 8 | MaxPageSize: 100 9 | LogSavePath: storage/logs 10 | LogFileName: tools 11 | LogFileExt: .log 12 | Database: 13 | DBType: mysql 14 | # 记得改成自己的数据库链接,第一个root是用户名,第二个root是密码 15 | Url: root:root@tcp(121.37.143.160:3306)/sky_take_out?charset=utf8&parseTime=True&loc=Local 16 | TablePrefix: #设置表前缀 17 | Charset: utf8 18 | ParseTime: True 19 | MaxIdleConns: 10 20 | MaxOpenConns: 30 -------------------------------------------------------------------------------- /internal/db/addressBook_dao.go: -------------------------------------------------------------------------------- 1 | package db 2 | 3 | import "reggie/internal/models/model" 4 | 5 | type addressI interface { 6 | List(address *model.AddressBook) (*[]model.AddressBook, error) 7 | // 新增地址 8 | Save(address *model.AddressBook) error 9 | // 根据id查询 10 | GetById(id int64) *model.AddressBook 11 | // 根据id修改地址 12 | Update(address *model.AddressBook) 13 | // 根据 用户id修改 是否默认地址 14 | UpdateIsDefaultByUserId(address *model.AddressBook) 15 | // 根据id删除地址 16 | DeleteById(id int64) 17 | } 18 | type addressDao struct { 19 | } 20 | 21 | func (*addressDao) List(address *model.AddressBook) (*[]model.AddressBook, error) { 22 | var list []model.AddressBook 23 | 24 | origin_sql := DBEngine 25 | if address.UserID != 0 { 26 | origin_sql = origin_sql.Where("user_id =? ", address.UserID) 27 | } 28 | if address.Phone != "" { 29 | origin_sql = origin_sql.Where("phone=?", address.Phone) 30 | } 31 | origin_sql.Find(&list) 32 | return &list, nil 33 | } 34 | func (*addressDao) Save(address *model.AddressBook) error { 35 | if err := DBEngine.Create(address).Error; err != nil { 36 | return err 37 | } else { 38 | return nil 39 | } 40 | } 41 | func (*addressDao) GetById(id int64) *model.AddressBook { 42 | var address model.AddressBook 43 | DBEngine.Where("id=?", id).First(&address) 44 | return &address 45 | } 46 | func (*addressDao) Update(address *model.AddressBook) { 47 | DBEngine.Updates(&address) 48 | } 49 | func (*addressDao) UpdateIsDefaultByUserId(address *model.AddressBook) { 50 | DBEngine.Model(&address).Where("user_id =?", address.UserID).Update("is_default", address.IsDefault) 51 | } 52 | func (*addressDao) DeleteById(id int64) { 53 | DBEngine.Delete(&model.AddressBook{}, id) 54 | } 55 | -------------------------------------------------------------------------------- /internal/db/category_dao.go: -------------------------------------------------------------------------------- 1 | package db 2 | 3 | import ( 4 | "reggie/internal/models/dto" 5 | "reggie/internal/models/model" 6 | ) 7 | 8 | type catI interface { 9 | Save(category *model.Category) 10 | PageQuery(page *dto.CategoryPageQueryDTO) (*[]model.Category, int64) 11 | Delete(id *int64) *error 12 | Update(category *model.Category) 13 | UpdateStatus(cat *model.Category) 14 | List(tp *int64) *[]model.Category 15 | } 16 | type categoryDao struct { 17 | } 18 | 19 | func (*categoryDao) Save(category *model.Category) { 20 | DBEngine.Create(category) 21 | } 22 | func (*categoryDao) PageQuery(page *dto.CategoryPageQueryDTO) (*[]model.Category, int64) { 23 | var ( 24 | cat []model.Category 25 | count int64 26 | ) 27 | origin_sql := DBEngine 28 | // 判断是否含有name,有name不为nil,就进行模糊查询。 29 | if page.Name != nil { 30 | origin_sql = origin_sql.Where("name LIKE ?", "%"+*page.Name+"%") 31 | } 32 | if page.Type != nil { 33 | origin_sql = origin_sql.Where("type=?", page.Type) 34 | } 35 | origin_sql.Model(&model.Category{}).Count(&count) 36 | origin_sql.Limit(page.PageSize).Offset((page.Page - 1) * page.PageSize).Order("create_time desc").Find(&cat) 37 | return &cat, count 38 | } 39 | func (*categoryDao) Delete(id *int64) *error { 40 | err := DBEngine.Delete(&model.Category{}, id).Error 41 | if err != nil { 42 | return &err 43 | } 44 | return nil 45 | } 46 | func (*categoryDao) Update(category *model.Category) { 47 | DBEngine.Updates(category) 48 | } 49 | func (*categoryDao) UpdateStatus(cat *model.Category) { 50 | DBEngine.Select("status", "update_time", "update_user").Updates(cat) 51 | } 52 | func (*categoryDao) List(tp *int64) *[]model.Category { 53 | var cat []model.Category 54 | if *tp == 0 { 55 | DBEngine.Find(&cat) 56 | } else { 57 | DBEngine.Where("type=?", tp).Find(&cat) 58 | } 59 | 60 | return &cat 61 | } 62 | -------------------------------------------------------------------------------- /internal/db/db.go: -------------------------------------------------------------------------------- 1 | package db 2 | 3 | import ( 4 | "gorm.io/driver/mysql" 5 | "gorm.io/gorm" 6 | "gorm.io/gorm/logger" 7 | "log" 8 | "os" 9 | "reggie/internal/config" 10 | "time" 11 | ) 12 | 13 | var DBEngine *gorm.DB 14 | var EmpDao empI = &employeeDao{} 15 | var CatDao catI = &categoryDao{} 16 | var DisDao dishI = &dishDao{} 17 | var UserDao userI = &userDao{} 18 | var DishFDao dishFI = &dishFDao{} 19 | var MealDishDao meal_dishI = &mealDishDao{} 20 | var MealDao mealI = &mealDao{} 21 | var ShopCartDao shoppingcartI = &shoppingcartDao{} 22 | var AddressDA0 addressI = &addressDao{} 23 | var OrderDao orderI = &orderDao{} 24 | var OrderDetailDao order_detialI = &order_detialDao{} 25 | 26 | func InitDB() { 27 | // 创建一个新的logger实例,设置为verbose模式以输出详细日志,包括SQL语句 28 | dbLogger := logger.New( 29 | log.New(os.Stdout, "\r\n", log.LstdFlags), // io writer 30 | logger.Config{ 31 | LogLevel: logger.Info, // 设置日志级别 32 | SlowThreshold: time.Second, // 慢查询阈值 33 | Colorful: true, // 是否使用彩色日志 34 | }, 35 | ) 36 | db, err := gorm.Open(mysql.New(mysql.Config{ 37 | DSN: config.DatabaseSetting.Url, // DSN data source name 38 | DefaultStringSize: 256, // string 类型字段的默认长度 39 | DisableDatetimePrecision: true, // 禁用 datetime 精度,MySQL 5.6 之前的数据库不支持 40 | DontSupportRenameIndex: true, // 重命名索引时采用删除并新建的方式,MySQL 5.7 之前的数据库和 MariaDB 不支持重命名索引 41 | DontSupportRenameColumn: true, // 用 `change` 重命名列,MySQL 8 之前的数据库和 MariaDB 不支持重命名列 42 | SkipInitializeWithVersion: false, // 根据当前 MySQL 版本自动配置 43 | }), &gorm.Config{ 44 | // 取消生成外键。 45 | DisableForeignKeyConstraintWhenMigrating: true, 46 | Logger: dbLogger, 47 | }) 48 | if err != nil { 49 | panic("数据库链接失败") 50 | } 51 | DBEngine = db 52 | } 53 | -------------------------------------------------------------------------------- /internal/db/dish_dao.go: -------------------------------------------------------------------------------- 1 | package db 2 | 3 | import ( 4 | "github.com/cloudwego/hertz/pkg/common/hlog" 5 | "reggie/internal/models/constant/status_c" 6 | "reggie/internal/models/dto" 7 | "reggie/internal/models/model" 8 | ) 9 | 10 | type dishI interface { 11 | PageQuery(page *dto.DishPageQueryDTO) (*[]model.Dish, int64) 12 | Delete(id int64) *error 13 | Update(dish *model.Dish) 14 | UpdateStatus(cat *model.Dish) 15 | List(d *model.Dish) (*[]model.Dish, error) 16 | GetById(id int64) *model.Dish 17 | Save(dish *model.Dish) *model.Dish 18 | GetBySetmealId(id int64) []*model.Dish 19 | } 20 | type dishDao struct { 21 | } 22 | 23 | func (*dishDao) Save(dish *model.Dish) *model.Dish { 24 | 25 | if err := DBEngine.Select("*").Create(dish); err != nil { 26 | hlog.Error(err) 27 | return nil 28 | } 29 | return dish 30 | } 31 | func (*dishDao) PageQuery(page *dto.DishPageQueryDTO) (*[]model.Dish, int64) { 32 | var ( 33 | dish []model.Dish 34 | count int64 35 | ) 36 | origin_sql := DBEngine 37 | // 判断是否含有name,有name不为nil,就进行模糊查询。 38 | if page.Name != nil { 39 | origin_sql = origin_sql.Where("name LIKE ?", "%"+*page.Name+"%") 40 | } 41 | if page.CategoryId != nil { 42 | origin_sql = origin_sql.Where("category_id=?", page.CategoryId) 43 | } 44 | if page.Status != nil { 45 | origin_sql = origin_sql.Where("status=?", page.Status) 46 | } 47 | origin_sql.Model(&model.Dish{}).Count(&count) 48 | origin_sql.Limit(page.PageSize).Offset((page.Page - 1) * page.PageSize).Order("create_time desc").Find(&dish) 49 | return &dish, count 50 | } 51 | func (*dishDao) Delete(id int64) *error { 52 | err := DBEngine.Delete(&model.Dish{}, id).Error 53 | if err != nil { 54 | return &err 55 | } 56 | return nil 57 | } 58 | func (*dishDao) Update(dish *model.Dish) { 59 | DBEngine.Updates(dish) 60 | } 61 | func (*dishDao) UpdateStatus(cat *model.Dish) { 62 | DBEngine.Select("status", "update_time", "update_user").Updates(cat) 63 | } 64 | 65 | // 根据菜品分类查询菜品 66 | func (*dishDao) List(d *model.Dish) (*[]model.Dish, error) { 67 | var ( 68 | dish []model.Dish 69 | ) 70 | origin_sql := DBEngine 71 | // 判断是否含有name,有name不为nil,就进行模糊查询。 72 | if d.Name != "" { 73 | origin_sql = origin_sql.Where("name LIKE ?", "%"+d.Name+"%") 74 | } 75 | if d.CategoryID != 0 { 76 | origin_sql = origin_sql.Where("category_id=?", d.CategoryID) 77 | } 78 | if d.Status != status_c.ALL { 79 | origin_sql = origin_sql.Where("status =?", d.Status) 80 | } 81 | if err := origin_sql.Order("create_time desc").Find(&dish).Error; err != nil { 82 | return nil, err 83 | } 84 | return &dish, nil 85 | } 86 | func (*dishDao) GetById(id int64) *model.Dish { 87 | var dish model.Dish 88 | DBEngine.Where("id=?", id).First(&dish) 89 | return &dish 90 | } 91 | func (*dishDao) GetBySetmealId(id int64) []*model.Dish { 92 | var list []*model.Dish 93 | DBEngine.Joins(model.TableNameSetmealDish, DBEngine.Where(&model.SetmealDish{SetmealID: id})).Find(&list) 94 | return list 95 | } 96 | -------------------------------------------------------------------------------- /internal/db/dish_flavor_dao.go: -------------------------------------------------------------------------------- 1 | package db 2 | 3 | import "reggie/internal/models/model" 4 | 5 | type dishFI interface { 6 | InsertBatch(flavors *[]model.DishFlavor) 7 | DeleteByDishId(id int64) 8 | GetByDishId(id int64) *[]model.DishFlavor 9 | } 10 | type dishFDao struct { 11 | } 12 | 13 | func (*dishFDao) InsertBatch(flavors *[]model.DishFlavor) { 14 | DBEngine.Select("*").Create(flavors) 15 | } 16 | func (*dishFDao) DeleteByDishId(id int64) { 17 | DBEngine.Table(model.TableNameDishFlavor).Where("id=?", id) 18 | } 19 | func (*dishFDao) GetByDishId(id int64) *[]model.DishFlavor { 20 | var nums []model.DishFlavor 21 | 22 | DBEngine.Where("dish_id=?", id).Find(&nums) 23 | return &nums 24 | } 25 | -------------------------------------------------------------------------------- /internal/db/employee_dao.go: -------------------------------------------------------------------------------- 1 | package db 2 | 3 | import ( 4 | "reggie/internal/models/dto" 5 | "reggie/internal/models/model" 6 | ) 7 | 8 | type empI interface { 9 | GetByUserName(username string) *model.Employee 10 | Insert(emp *model.Employee) 11 | 12 | PageQuery(page *dto.EmployeePageQueryDTO) (*[]model.Employee, int64) 13 | 14 | UpdateStatus(emp *model.Employee) 15 | GetById(id int64) *model.Employee 16 | Update(emp *model.Employee) 17 | } 18 | type employeeDao struct { 19 | } 20 | 21 | func (*employeeDao) GetByUserName(username string) *model.Employee { 22 | var emp model.Employee 23 | DBEngine.Where("username=?", username).First(&emp) 24 | return &emp 25 | } 26 | func (*employeeDao) Insert(emp *model.Employee) { 27 | DBEngine.Create(emp) 28 | } 29 | 30 | func (*employeeDao) PageQuery(page *dto.EmployeePageQueryDTO) (*[]model.Employee, int64) { 31 | var ( 32 | users []model.Employee 33 | count int64 34 | ) 35 | origin_sql := DBEngine 36 | // 判断是否含有name,有name不为nil,就进行模糊查询。 37 | if page.Name != nil { 38 | origin_sql = origin_sql.Where("name LIKE ?", "%"+*page.Name+"%").Find(&users) 39 | } 40 | origin_sql.Model(&model.Employee{}).Count(&count) 41 | origin_sql.Limit(page.PageSize).Offset((page.Page - 1) * page.PageSize).Order("create_time desc").Find(&users) 42 | return &users, count 43 | } 44 | 45 | func (*employeeDao) UpdateStatus(emp *model.Employee) { 46 | DBEngine.Select("status", "update_time", "update_user").Updates(emp) 47 | } 48 | func (*employeeDao) GetById(id int64) *model.Employee { 49 | var emp model.Employee 50 | DBEngine.Where("id=?", id).First(&emp) 51 | return &emp 52 | } 53 | func (*employeeDao) Update(emp *model.Employee) { 54 | DBEngine.Updates(emp) 55 | } 56 | -------------------------------------------------------------------------------- /internal/db/order_dao.go: -------------------------------------------------------------------------------- 1 | package db 2 | 3 | import ( 4 | "reggie/internal/models/dto" 5 | "reggie/internal/models/model" 6 | "time" 7 | ) 8 | 9 | type orderI interface { 10 | Insert(order *model.Order) (*model.Order, error) 11 | PageQuery(page *dto.OrdersPageQueryDTO) (*[]model.Order, int64, error) 12 | CountByMap(m map[string]interface{}) int64 13 | SumByMap(m map[string]interface{}) float64 14 | } 15 | type orderDao struct { 16 | } 17 | 18 | func (*orderDao) Insert(order *model.Order) (*model.Order, error) { 19 | err := DBEngine.Create(order).Error 20 | if err != nil { 21 | return nil, err 22 | } else { 23 | return order, nil 24 | } 25 | } 26 | func (*orderDao) PageQuery(page *dto.OrdersPageQueryDTO) (*[]model.Order, int64, error) { 27 | var ( 28 | order []model.Order 29 | count int64 30 | ) 31 | origin_sql := DBEngine 32 | // 判断是否含有name,有name不为nil,就进行模糊查询。 33 | if page.Number != "" { 34 | origin_sql = origin_sql.Where("number= ?", page.Number) 35 | } 36 | if page.Page != 0 { 37 | origin_sql = origin_sql.Where("phone =?", page.Page) 38 | } 39 | if page.UserId != 0 { 40 | origin_sql = origin_sql.Where("userId=?", page.UserId) 41 | } 42 | if page.Status != 0 { 43 | origin_sql = origin_sql.Where("status =?", page.Status) 44 | } 45 | if page.BeginTime.Equal(time.Time{}) { 46 | origin_sql = origin_sql.Where("beginTime =?", page.BeginTime) 47 | } 48 | if page.EndTime.Equal(time.Time{}) { 49 | origin_sql = origin_sql.Where("endTime =?", page.EndTime) 50 | } 51 | origin_sql.Model(&model.Category{}).Count(&count) 52 | origin_sql.Find(&order) 53 | return &order, count, nil 54 | } 55 | func (*orderDao) CountByMap(m map[string]interface{}) int64 { 56 | var nums int64 57 | origin_sql := DBEngine 58 | // 判断是否含有name,有name不为nil,就进行模糊查询。 59 | if m["begin"] != nil { 60 | origin_sql = origin_sql.Where(" order_time >?", m["begin"]) 61 | } 62 | if m["end"] != nil { 63 | origin_sql = origin_sql.Where(" order_time ?", m["begin"]) 77 | } 78 | if m["end"] != nil { 79 | origin_sql = origin_sql.Where(" order_time ?", m["begin"]) 32 | } 33 | if m["end"] != nil { 34 | origin_sql = origin_sql.Where(" create_time " 26 | // - "query:" 27 | // - "cookie:" 28 | // - "param:" 29 | // - "form:" 30 | JwtTokenAdmin = "header: token" 31 | JwtTokenUSer = "header: authorization" 32 | ) 33 | 34 | // 从jwt获取雇员id 35 | func GetJwtPayload(c *app.RequestContext) int64 { 36 | 37 | jwt_payload, _ := c.Get("JWT_PAYLOAD") 38 | // 类型转换,我们的数据在claims中是以map[string]interface{}嵌套结构组成的。 39 | claims := jwt_payload.(jwt.MapClaims) 40 | origin_emp := claims[IdentityKey].(map[string]interface{}) 41 | emp_id := origin_emp["id"].(float64) 42 | return int64(emp_id) 43 | } 44 | 45 | // 设置标识处理函数 46 | // 这里我们把通过定义identityKey获取负载的数据 47 | func jwtIdentityHandlerAdmin(ctx context.Context, c *app.RequestContext) interface{} { 48 | claims := jwt.ExtractClaims(ctx, c) 49 | return claims[IdentityKey] 50 | } 51 | 52 | // 生成jwt负载的函数,指定了Authenticator方法生成的数据如何存储和怎么样存储c.Get("JWT_PAYLOAD")访问 53 | func jwtPayloadFuncAdmin(data interface{}) jwt.MapClaims { 54 | if v, ok := data.(*vo.EmployeeLoginVO); ok { 55 | return jwt.MapClaims{ 56 | IdentityKey: v, 57 | } 58 | } 59 | return jwt.MapClaims{} 60 | } 61 | 62 | func jwtLoginResponseAdmin(ctx context.Context, c *app.RequestContext, code int, token string, expire time.Time) { 63 | var elv, _ = c.Get(IdentityKey) 64 | rely := elv.(*vo.EmployeeLoginVO) 65 | rely.Token = token 66 | c.JSON(http.StatusOK, common.Result{1, "", rely}) 67 | } 68 | 69 | // 返回值会被存在Claim数组中 70 | func jwtAuthenticatorAdmin(ctx context.Context, c *app.RequestContext) (interface{}, error) { 71 | var empl model.Employee 72 | if err := c.BindAndValidate(&empl); err != nil { 73 | log.Println(jwt.ErrMissingLoginValues.Error()) 74 | return nil, common.Result{0, jwt.ErrMissingLoginValues.Error(), nil} 75 | } 76 | emp := db.EmpDao.GetByUserName(empl.Username) 77 | var errorR common.Result 78 | if emp.Username != empl.Username { 79 | log.Println(message_c.ACCOUNT_NOT_FOUND) 80 | // 账号不存在 81 | errorR = common.Result{0, message_c.ACCOUNT_NOT_FOUND, nil} 82 | return nil, errorR 83 | } 84 | 85 | //密码比对 86 | if empl.Password != emp.Password { 87 | log.Println(message_c.PASSWORD_ERROR) 88 | //密码错误 89 | errorR = common.Result{0, message_c.PASSWORD_ERROR, nil} 90 | return nil, errorR 91 | } 92 | 93 | if emp.Status == status_c.DISABLE { 94 | log.Println(message_c.ACCOUNT_LOCKED) 95 | //账号被锁定 96 | errorR = common.Result{0, message_c.ACCOUNT_LOCKED, nil} 97 | return nil, errorR 98 | } 99 | 100 | elv := vo.EmployeeLoginVO{ 101 | Id: emp.ID, 102 | UserName: emp.Username, 103 | Name: emp.Name, 104 | Token: "", 105 | } 106 | // 这里我们把对象值存入c中,方便在返回函数中进行包装 107 | c.Set(IdentityKey, &elv) 108 | return &elv, nil 109 | 110 | } 111 | func InitJwtAdmin() *jwt.HertzJWTMiddleware { 112 | authMiddleware, err := jwt.New(&jwt.HertzJWTMiddleware{ 113 | Realm: "test zone", 114 | // 用于签名的密钥 115 | Key: []byte("secret key"), 116 | Timeout: time.Hour, 117 | MaxRefresh: time.Hour, 118 | // 用于在JWT中存储用户唯一标识身份的键值 119 | IdentityKey: IdentityKey, 120 | // 用于生成JWT载荷部分的声明 121 | PayloadFunc: jwtPayloadFuncAdmin, 122 | // 作用在登录成功后的每次请求中,用于设置从 token 提取用户信息的函数 123 | IdentityHandler: jwtIdentityHandlerAdmin, 124 | // 用于设置登录时认证用户信息的函数 125 | Authenticator: jwtAuthenticatorAdmin, 126 | // 登陆回复 127 | LoginResponse: jwtLoginResponseAdmin, 128 | LogoutResponse: func(ctx context.Context, c *app.RequestContext, code int) { 129 | c.JSON(code, common.Result{1, "", nil}) 130 | }, 131 | // 设置从哪里获取jwt的信息 132 | TokenLookup: JwtTokenAdmin, 133 | // 不设置jwt表名前缀 134 | WithoutDefaultTokenHeadName: true, 135 | // 当用户未通过身份验证或授权时,调用此函数返回错误信息 136 | Unauthorized: func(ctx context.Context, c *app.RequestContext, code int, message string) { 137 | //重定向 138 | c.Redirect(http.StatusFound, []byte("/admin/employee/login")) 139 | }, 140 | }) 141 | if err != nil { 142 | log.Fatal("JWT Error:" + err.Error()) 143 | } 144 | 145 | // When you use jwt.New(), the function is already automatically called for checking, 146 | // which means you don't need to call it again. 147 | errInit := authMiddleware.MiddlewareInit() 148 | 149 | if errInit != nil { 150 | log.Fatal("authMiddleware.MiddlewareInit() Error:" + errInit.Error()) 151 | } 152 | return authMiddleware 153 | } 154 | 155 | // 声明从如何获取数据 156 | func jwtIdentityHandlerUser(ctx context.Context, c *app.RequestContext) interface{} { 157 | claims := jwt.ExtractClaims(ctx, c) 158 | return claims[IdentityKey] 159 | } 160 | 161 | // 生成jwt负载的函数,指定了Authenticator方法生成的数据如何存储和怎么样存储c.Get("JWT_PAYLOAD")访问 162 | func jwtPayloadFuncUser(data interface{}) jwt.MapClaims { 163 | v, ok := data.(*vo.UserLoginVO) 164 | if ok { 165 | return jwt.MapClaims{ 166 | IdentityKey: v, 167 | } 168 | } 169 | return jwt.MapClaims{} 170 | } 171 | 172 | func jwtLoginResponseUser(ctx context.Context, c *app.RequestContext, code int, token string, expire time.Time) { 173 | var us, _ = c.Get(IdentityKey) 174 | rely := us.(vo.UserLoginVO) 175 | rely.Token = token 176 | c.JSON(http.StatusOK, common.Result{1, "", rely}) 177 | } 178 | 179 | // 返回值会被存在Claim数组中 180 | func jwtAuthenticatorUser(ctx context.Context, c *app.RequestContext) (interface{}, error) { 181 | var ul = vo.UserLoginVO{} 182 | var userLoginDto dto.UserLoginDTO 183 | err := c.Bind(&userLoginDto) 184 | if err != nil { 185 | return nil, err 186 | } 187 | hlog.Info("微信用户登录:{}", userLoginDto) 188 | us := service.WxLoginUser(&userLoginDto) 189 | ul.User2UserLoginVO(us) 190 | // 这里我们把对象值存入c中,方便在返回函数中进行包装 191 | c.Set(IdentityKey, ul) 192 | return &ul, nil 193 | 194 | } 195 | 196 | func InitJwtUser() *jwt.HertzJWTMiddleware { 197 | authMiddleware, err := jwt.New(&jwt.HertzJWTMiddleware{ 198 | Realm: "test zone", 199 | // 用于签名的密钥 200 | Key: []byte("secret key"), 201 | Timeout: time.Hour, 202 | MaxRefresh: time.Hour, 203 | // 用于在JWT中存储用户唯一标识身份的键值 204 | IdentityKey: IdentityKey, 205 | // 用于生成JWT载荷部分的声明 206 | PayloadFunc: jwtPayloadFuncUser, 207 | // 作用在登录成功后的每次请求中,用于设置从 token 提取用户信息的函数 208 | IdentityHandler: jwtIdentityHandlerUser, 209 | // 用于设置登录时认证用户信息的函数 210 | Authenticator: jwtAuthenticatorUser, 211 | // 登陆回复 212 | LoginResponse: jwtLoginResponseUser, 213 | LogoutResponse: func(ctx context.Context, c *app.RequestContext, code int) { 214 | c.JSON(code, common.Result{1, "", nil}) 215 | }, 216 | // 设置从哪里获取jwt的信息 217 | TokenLookup: JwtTokenUSer, 218 | // 不设置jwt表名前缀 219 | WithoutDefaultTokenHeadName: true, 220 | // 当用户未通过身份验证或授权时,调用此函数返回错误信息 221 | Unauthorized: func(ctx context.Context, c *app.RequestContext, code int, message string) { 222 | // 不通过,响应401状态码 223 | c.String(http.StatusNotFound, message) 224 | }, 225 | }) 226 | if err != nil { 227 | log.Fatal("JWT Error:" + err.Error()) 228 | } 229 | 230 | // When you use jwt.New(), the function is already automatically called for checking, 231 | // which means you don't need to call it again. 232 | errInit := authMiddleware.MiddlewareInit() 233 | 234 | if errInit != nil { 235 | log.Fatal("authMiddleware.MiddlewareInit() Error:" + errInit.Error()) 236 | } 237 | return authMiddleware 238 | } 239 | -------------------------------------------------------------------------------- /internal/middleware/swagger.go: -------------------------------------------------------------------------------- 1 | package middleware 2 | 3 | import ( 4 | "github.com/cloudwego/hertz/pkg/route" 5 | "github.com/hertz-contrib/swagger" 6 | swaggerFiles "github.com/swaggo/files" 7 | ) 8 | 9 | func InitSwagger(r *route.RouterGroup) { 10 | url := swagger.URL("http://localhost:8080/swagger/doc.json") // The url pointing to API definition 11 | 12 | r.GET("/*any", swagger.WrapHandler(swaggerFiles.Handler, url)) 13 | } 14 | -------------------------------------------------------------------------------- /internal/models/common/common.go: -------------------------------------------------------------------------------- 1 | package common 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "reggie/internal/utils" 7 | "strings" 8 | "time" 9 | ) 10 | 11 | type Result struct { 12 | Code uint `json:"code"` 13 | Msg string `json:"msg"` 14 | Data interface{} `json:"data"` 15 | } 16 | 17 | func (r Result) Error() string { 18 | jsonBytes, _ := json.Marshal(r) 19 | 20 | // 将JSON字节转为字符串并打印 21 | return string(jsonBytes) 22 | } 23 | 24 | type PageResult struct { 25 | Total int64 `json:"total,omitempty"` //总记录数 26 | Records interface{} `json:"records,omitempty"` //当前页数据集合 27 | } 28 | 29 | // 设置时间格式 2006-01-02 15:04:05 30 | type DateTime time.Time 31 | 32 | func (t DateTime) MarshalJSON() ([]byte, error) { 33 | var stamp = fmt.Sprintf("\"%s\"", time.Time(t).Format("2006-01-02 15:04:05")) 34 | return []byte(stamp), nil 35 | } 36 | func (t *DateTime) UnmarshalJSON(b []byte) error { 37 | parse, err := time.Parse("2006-01-02 15:04:05", strings.Trim(utils.Bytes2String(b), "\"")) 38 | if err != nil { 39 | return err 40 | } 41 | t = (*DateTime)(&parse) 42 | return err 43 | } 44 | -------------------------------------------------------------------------------- /internal/models/constant/message_c/common.go: -------------------------------------------------------------------------------- 1 | package message_c 2 | 3 | /** 4 | * 信息提示常量类 5 | */ 6 | const ( 7 | PASSWORD_ERROR = "密码错误" 8 | ACCOUNT_NOT_FOUND = "账号不存在" 9 | ACCOUNT_LOCKED = "账号被锁定" 10 | UNKNOWN_ERROR = "未知错误" 11 | USER_NOT_LOGIN = "用户未登录" 12 | CATEGORY_BE_RELATED_BY_SETMEAL = "当前分类关联了套餐,不能删除" 13 | CATEGORY_BE_RELATED_BY_DISH = "当前分类关联了菜品,不能删除" 14 | SHOPPING_CART_IS_NULL = "购物车数据为空,不能下单" 15 | ADDRESS_BOOK_IS_NULL = "用户地址为空,不能下单" 16 | LOGIN_FAILED = "登录失败" 17 | UPLOAD_FAILED = "文件上传失败" 18 | SETMEAL_ENABLE_FAILED = "套餐内包含未启售菜品,无法启售" 19 | PASSWORD_EDIT_FAILED = "密码修改失败" 20 | DISH_ON_SALE = "起售中的菜品不能删除" 21 | SETMEAL_ON_SALE = "起售中的套餐不能删除" 22 | DISH_BE_RELATED_BY_SETMEAL = "当前菜品关联了套餐,不能删除" 23 | ORDER_STATUS_ERROR = "订单状态错误" 24 | ORDER_NOT_FOUND = "订单不存在" 25 | ALREADY_EXISTS = "已存在" 26 | ) 27 | -------------------------------------------------------------------------------- /internal/models/constant/status_c/common.go: -------------------------------------------------------------------------------- 1 | package status_c 2 | 3 | /** 4 | * 状态常量,启用或者禁用 5 | */ 6 | const ( 7 | //启用 8 | ENABLE int32 = 1 9 | 10 | //禁用 11 | DISABLE int32 = 0 12 | ALL int32 = 3 13 | //设置新用户的默认密码 14 | DEFAULT_PASSWORD = "123456" 15 | //启用 16 | ) 17 | const ( 18 | /** 19 | * 订单状态 1待付款 2待接单 3已接单 4派送中 5已完成 6已取消 20 | */ 21 | PENDING_PAYMENT = iota + 1 22 | TO_BE_CONFIRMED 23 | CONFIRMED 24 | DELIVERY_IN_PROGRESS 25 | COMPLETED 26 | CANCELLED 27 | ) 28 | -------------------------------------------------------------------------------- /internal/models/dto/common.go: -------------------------------------------------------------------------------- 1 | package dto 2 | 3 | import ( 4 | "encoding/json" 5 | "reggie/internal/models/model" 6 | "time" 7 | ) 8 | 9 | type EmployeePageQueryDTO struct { 10 | //员工姓名 11 | Name *string `json:"name,omitempty" form:"name,omitempty"` 12 | //页码 13 | Page int `json:"page,omitempty" form:"page,omitempty"` 14 | //每页显示记录数 15 | PageSize int `json:"pageSize,omitempty" form:"pageSize,omitempty"` 16 | } 17 | type CategoryPageQueryDTO struct { 18 | //员工姓名 19 | Name *string `json:"name,omitempty" form:"name,omitempty"` 20 | //页码 21 | Page int `json:"page,omitempty" form:"page,omitempty"` 22 | //每页显示记录数 23 | PageSize int `json:"pageSize,omitempty" form:"pageSize,omitempty"` 24 | //分类类型 1菜品分类 2套餐分类 25 | Type *int `json:"type,omitempty" form:"type,omitempty"` 26 | } 27 | type DishDTO struct { 28 | ID int64 `json:"id,omitempty"` 29 | Name string `json:"name,omitempty"` 30 | CategoryID int64 `json:"categoryId,omitempty"` 31 | Price float64 `json:"price,omitempty"` 32 | Image string `json:"image,omitempty"` 33 | Description string `json:"description,omitempty"` 34 | Status int32 `json:"status,omitempty"` 35 | Flavors []model.DishFlavor `json:"flavors,omitempty"` 36 | } 37 | 38 | // 如果传入的id不等于nil, 39 | func (d *DishDTO) ToNewDish(id *int64) *model.Dish { 40 | v, _ := json.Marshal(d) 41 | var dish model.Dish 42 | json.Unmarshal(v, &dish) 43 | dish.CreateUser, dish.UpdateUser = *id, *id 44 | dish.CreateTime, dish.UpdateTime = time.Now(), time.Now() 45 | return &dish 46 | } 47 | 48 | /* 49 | 添加分页id 50 | */ 51 | type DishPageQueryDTO struct { 52 | Page int `json:"page,omitempty" form:"page,omitempty"` 53 | 54 | PageSize int `json:"pageSize,omitempty" form:"pageSize,omitempty"` 55 | 56 | Name *string `json:"name,omitempty" form:"name,omitempty"` 57 | 58 | //分类id 59 | CategoryId *int `json:"category_id,omitempty" form:"categoryId,omitempty"` 60 | 61 | //状态 0表示禁用 1表示启用 62 | Status *int `json:"status,omitempty" form:"status,omitempty"` 63 | } 64 | 65 | /** 66 | * C端用户登录 67 | */ 68 | type UserLoginDTO struct { 69 | Code string `json:"code,required"` 70 | } 71 | 72 | // userDto转换成user,更新用户时间 73 | func (u *UserLoginDTO) ToNewUser() *model.User { 74 | var us model.User 75 | us.Openid = u.Code 76 | us.CreateTime = time.Now() 77 | return &us 78 | } 79 | 80 | type SetmealDTO struct { 81 | Id int64 `json:"id,omitempty"` 82 | CategoryId int64 `json:"categoryId,omitempty"` 83 | Name string `json:"name,omitempty"` 84 | Price float64 `json:"price,omitempty"` 85 | Status int32 `json:"status,omitempty"` 86 | Description string `json:"description,omitempty"` 87 | Image string `json:"image,omitempty"` 88 | // 菜品套餐关系 89 | SetmealDishes *[]model.SetmealDish `json:"setmealDishes,omitempty"` 90 | } 91 | 92 | func (sm *SetmealDTO) ToNewSetmeal() *model.Setmeal { 93 | m := &model.Setmeal{} 94 | m.ID = sm.Id 95 | m.CategoryID = sm.CategoryId 96 | m.Name = sm.Name 97 | m.Price = sm.Price 98 | m.Status = sm.Status 99 | m.Description = sm.Description 100 | m.Image = sm.Image 101 | m.CreateTime = time.Now() 102 | m.UpdateTime = time.Now() 103 | 104 | return m 105 | } 106 | 107 | type WXLoginDto struct { 108 | SessionKey string `json:"session_key,omitempty"` 109 | OpenID string `json:"openid,omitempty"` 110 | } 111 | type SetmealPageQueryDTO struct { 112 | Page int `json:"page,omitempty" form:"page,omitempty"` 113 | 114 | PageSize int `json:"pageSize,omitempty" form:"pageSize,omitempty"` 115 | 116 | Name *string `json:"name,omitempty" form:"name,omitempty"` 117 | 118 | //分类id 119 | CategoryId *int `json:"category_id,omitempty" form:"categoryId,omitempty"` 120 | 121 | //状态 0表示禁用 1表示启用 122 | Status *int `json:"status,omitempty" form:"status,omitempty"` 123 | } 124 | -------------------------------------------------------------------------------- /internal/models/dto/order_page_query.go: -------------------------------------------------------------------------------- 1 | package dto 2 | 3 | import ( 4 | "encoding/json" 5 | "reggie/internal/models/common" 6 | "time" 7 | ) 8 | 9 | type OrdersPageQueryDTO struct { 10 | Page int `json:"page,omitempty"` 11 | PageSize int `json:"page_size,omitempty"` 12 | Number string `json:"number,omitempty"` 13 | Phone string `json:"phone,omitempty"` 14 | Status int `json:"status,omitempty"` 15 | BeginTime time.Time `json:"begin_time"` 16 | EndTime time.Time `json:"end_time"` 17 | UserId int64 `json:"user_id,omitempty"` 18 | } 19 | type tmpJSON OrdersPageQueryDTO 20 | type tmp struct { 21 | tmpJSON 22 | BeginTime common.DateTime `json:"begin_time"` 23 | EndTime common.DateTime `json:"end_time"` 24 | } 25 | 26 | func (o OrdersPageQueryDTO) MarshalJSON() ([]byte, error) { 27 | p := &tmp{ 28 | tmpJSON: (tmpJSON)(o), 29 | BeginTime: common.DateTime(o.BeginTime), 30 | EndTime: common.DateTime(o.EndTime), 31 | } 32 | marshal, err := json.Marshal(p) 33 | if err != nil { 34 | return nil, err 35 | } 36 | return marshal, err 37 | } 38 | 39 | func (o *OrdersPageQueryDTO) UnmarshalJSON(b []byte) error { 40 | var t tmp 41 | err := json.Unmarshal(b, &t) 42 | t.tmpJSON.BeginTime, t.tmpJSON.EndTime = (time.Time)(t.BeginTime), (time.Time)(t.EndTime) 43 | if err != nil { 44 | return err 45 | } 46 | o = (*OrdersPageQueryDTO)(&t.tmpJSON) 47 | return nil 48 | } 49 | -------------------------------------------------------------------------------- /internal/models/dto/orders_submitdto.go: -------------------------------------------------------------------------------- 1 | package dto 2 | 3 | import "time" 4 | 5 | type OrdersSubmitDTO struct { 6 | 7 | //地址簿id 8 | AddressBookId int64 `json:"addressBookId,omitempty"` 9 | //付款方式 10 | PayMethod int32 `json:"payMethod,omitempty"` 11 | //备注 12 | Remark string `json:"remark,omitempty"` 13 | //预计送达时间 14 | EstimatedDeliveryTime time.Time `json:"estimatedDeliveryTime"` 15 | //配送状态 1立即送出 0选择具体时间 16 | DeliveryStatus int32 `json:"deliveryStatus,omitempty"` 17 | //餐具数量 18 | TablewareNumber int32 `json:"tablewareNumber,omitempty"` 19 | //餐具数量状态 1按餐量提供 0选择具体数量 20 | TablewareStatus int32 `json:"tablewareStatus,omitempty"` 21 | //打包费 22 | PackAmount int32 `json:"packAmount,omitempty"` 23 | //总金额 24 | Amount float64 `json:"amount,omitempty"` 25 | } 26 | -------------------------------------------------------------------------------- /internal/models/dto/shoppingcartdto.go: -------------------------------------------------------------------------------- 1 | package dto 2 | 3 | import "reggie/internal/models/model" 4 | 5 | type ShoppingCartDTO struct { 6 | DishId int64 `json:"dishId,omitempty"` 7 | SetmealId int64 `json:"setmealId,omitempty"` 8 | DishFlavor string `json:"dishFlavor,omitempty"` 9 | } 10 | 11 | func (s *ShoppingCartDTO) ToShoppingCart() model.ShoppingCart { 12 | var sh model.ShoppingCart 13 | sh.DishID = s.DishId 14 | sh.SetmealID = s.SetmealId 15 | sh.DishFlavor = s.DishFlavor 16 | return sh 17 | } 18 | -------------------------------------------------------------------------------- /internal/models/model/address_book.gen.go: -------------------------------------------------------------------------------- 1 | // Code generated by gorm.io/gen. DO NOT EDIT. 2 | // Code generated by gorm.io/gen. DO NOT EDIT. 3 | // Code generated by gorm.io/gen. DO NOT EDIT. 4 | 5 | package model 6 | 7 | const TableNameAddressBook = "address_book" 8 | 9 | // AddressBook 地址簿 10 | type AddressBook struct { 11 | ID int64 `gorm:"column:id;primaryKey;autoIncrement:true;comment:主键" json:"id"` // 主键 12 | UserID int64 `gorm:"column:user_id;not null;comment:用户id" json:"user_id"` // 用户id 13 | Consignee string `gorm:"column:consignee;comment:收货人" json:"consignee"` // 收货人 14 | Sex string `gorm:"column:sex;comment:性别" json:"sex"` // 性别 15 | Phone string `gorm:"column:phone;not null;comment:手机号" json:"phone"` // 手机号 16 | ProvinceCode string `gorm:"column:province_code;comment:省级区划编号" json:"province_code"` // 省级区划编号 17 | ProvinceName string `gorm:"column:province_name;comment:省级名称" json:"province_name"` // 省级名称 18 | CityCode string `gorm:"column:city_code;comment:市级区划编号" json:"city_code"` // 市级区划编号 19 | CityName string `gorm:"column:city_name;comment:市级名称" json:"city_name"` // 市级名称 20 | DistrictCode string `gorm:"column:district_code;comment:区级区划编号" json:"district_code"` // 区级区划编号 21 | DistrictName string `gorm:"column:district_name;comment:区级名称" json:"district_name"` // 区级名称 22 | Detail string `gorm:"column:detail;comment:详细地址" json:"detail"` // 详细地址 23 | Label string `gorm:"column:label;comment:标签" json:"label"` // 标签 24 | IsDefault bool `gorm:"column:is_default;not null;comment:默认 0 否 1是" json:"is_default"` // 默认 0 否 1是 25 | } 26 | 27 | // TableName AddressBook's table name 28 | func (*AddressBook) TableName() string { 29 | return TableNameAddressBook 30 | } 31 | -------------------------------------------------------------------------------- /internal/models/model/category.go: -------------------------------------------------------------------------------- 1 | // Code generated by gorm.io/gen. DO NOT EDIT. 2 | // Code generated by gorm.io/gen. DO NOT EDIT. 3 | // Code generated by gorm.io/gen. DO NOT EDIT. 4 | 5 | package model 6 | 7 | import ( 8 | "time" 9 | ) 10 | 11 | const TableNameCategory = "category" 12 | 13 | // Category 菜品及套餐分类 14 | type Category struct { 15 | ID int64 `gorm:"column:id;primaryKey;autoIncrement:true;comment:主键" json:"id"` // 主键 16 | Type int32 `gorm:"column:type;comment:类型 1 菜品分类 2 套餐分类" json:"type"` // 类型 1 菜品分类 2 套餐分类 17 | Name string `gorm:"column:name;not null;comment:分类名称" json:"name"` // 分类名称 18 | Sort int32 `gorm:"column:sort;not null;comment:顺序" json:"sort"` // 顺序 19 | Status int32 `gorm:"column:status;comment:分类状态 0:禁用,1:启用" json:"status"` // 分类状态 0:禁用,1:启用 20 | CreateTime time.Time `gorm:"column:create_time;comment:创建时间" json:"create_time"` // 创建时间 21 | UpdateTime time.Time `gorm:"column:update_time;comment:更新时间" json:"update_time"` // 更新时间 22 | CreateUser int64 `gorm:"column:create_user;comment:创建人" json:"create_user"` // 创建人 23 | UpdateUser int64 `gorm:"column:update_user;comment:修改人" json:"update_user"` // 修改人 24 | } 25 | 26 | // TableName Category's table name 27 | func (*Category) TableName() string { 28 | return TableNameCategory 29 | } 30 | -------------------------------------------------------------------------------- /internal/models/model/dish.go: -------------------------------------------------------------------------------- 1 | // Code generated by gorm.io/gen. DO NOT EDIT. 2 | // Code generated by gorm.io/gen. DO NOT EDIT. 3 | // Code generated by gorm.io/gen. DO NOT EDIT. 4 | 5 | package model 6 | 7 | import ( 8 | "time" 9 | ) 10 | 11 | const TableNameDish = "dish" 12 | 13 | // Dish 菜品 14 | type Dish struct { 15 | ID int64 `gorm:"column:id;primaryKey;autoIncrement:true;comment:主键" json:"id"` // 主键 16 | Name string `gorm:"column:name;not null;comment:菜品名称" json:"name"` // 菜品名称 17 | CategoryID int64 `gorm:"column:category_id;not null;comment:菜品分类id" json:"categoryId"` // 菜品分类id 18 | Price float64 `gorm:"column:price;comment:菜品价格" json:"price"` // 菜品价格 19 | Image string `gorm:"column:image;comment:图片" json:"image"` // 图片 20 | Description string `gorm:"column:description;comment:描述信息" json:"description"` // 描述信息 21 | Status int32 `gorm:"column:status;default:1;comment:0 停售 1 起售" json:"status"` // 0 停售 1 起售 22 | CreateTime time.Time `gorm:"column:create_time;comment:创建时间" json:"create_time"` // 创建时间 23 | UpdateTime time.Time `gorm:"column:update_time;comment:更新时间" json:"update_time"` // 更新时间 24 | CreateUser int64 `gorm:"column:create_user;comment:创建人" json:"create_user"` // 创建人 25 | UpdateUser int64 `gorm:"column:update_user;comment:修改人" json:"update_user"` // 修改人 26 | } 27 | 28 | // TableName Dish's table name 29 | func (*Dish) TableName() string { 30 | return TableNameDish 31 | } 32 | -------------------------------------------------------------------------------- /internal/models/model/dish_flavor.go: -------------------------------------------------------------------------------- 1 | // Code generated by gorm.io/gen. DO NOT EDIT. 2 | // Code generated by gorm.io/gen. DO NOT EDIT. 3 | // Code generated by gorm.io/gen. DO NOT EDIT. 4 | 5 | package model 6 | 7 | const TableNameDishFlavor = "dish_flavor" 8 | 9 | // DishFlavor 菜品口味关系表 10 | type DishFlavor struct { 11 | ID int64 `gorm:"column:id;primaryKey;autoIncrement:true;comment:主键" json:"id"` // 主键 12 | DishID int64 `gorm:"column:dish_id;not null;comment:菜品" json:"dish_id"` // 菜品 13 | Name string `gorm:"column:name;comment:口味名称" json:"name"` // 口味名称 14 | Value string `gorm:"column:value;comment:口味数据list" json:"value"` // 口味数据list 15 | } 16 | 17 | // TableName DishFlavor's table name 18 | func (*DishFlavor) TableName() string { 19 | return TableNameDishFlavor 20 | } 21 | -------------------------------------------------------------------------------- /internal/models/model/employee.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import ( 4 | "time" 5 | ) 6 | 7 | const TableNameEmployee = "employee" 8 | 9 | // Employee 员工信息 10 | type Employee struct { 11 | ID int64 `gorm:"column:id;primaryKey;autoIncrement:true;comment:主键" json:"id"` // 主键 12 | Name string `gorm:"column:name;not null;comment:姓名" json:"name"` // 姓名 13 | Username string `gorm:"column:username;not null;comment:用户名" json:"username"` // 用户名 14 | Password string `gorm:"column:password;not null;comment:密码" json:"password"` // 密码 15 | Phone string `gorm:"column:phone;not null;comment:手机号" json:"phone"` // 手机号 16 | Sex string `gorm:"column:sex;not null;comment:性别" json:"sex"` // 性别 17 | IDNumber string `gorm:"column:id_number;not null;comment:身份证号" json:"idNumber"` // 身份证号 18 | Status int32 `gorm:"column:status;not null;default:1;comment:状态 0:禁用,1:启用" json:"status"` // 状态 0:禁用,1:启用 19 | CreateTime time.Time `gorm:"column:create_time;comment:创建时间" json:"create_time"` // 创建时间 20 | UpdateTime time.Time `gorm:"column:update_time;comment:更新时间" json:"update_time"` // 更新时间 21 | CreateUser int64 `gorm:"column:create_user;comment:创建人" json:"create_user"` // 创建人 22 | UpdateUser int64 `gorm:"column:update_user;comment:修改人" json:"update_user"` // 修改人 23 | } 24 | 25 | // TableName Employee's table name 26 | func (*Employee) TableName() string { 27 | return TableNameEmployee 28 | } 29 | -------------------------------------------------------------------------------- /internal/models/model/order_detail.gen.go: -------------------------------------------------------------------------------- 1 | // Code generated by gorm.io/gen. DO NOT EDIT. 2 | // Code generated by gorm.io/gen. DO NOT EDIT. 3 | // Code generated by gorm.io/gen. DO NOT EDIT. 4 | 5 | package model 6 | 7 | const TableNameOrderDetail = "order_detail" 8 | 9 | // OrderDetail 订单明细表 10 | type OrderDetail struct { 11 | ID int64 `gorm:"column:id;primaryKey;autoIncrement:true;comment:主键" json:"id"` // 主键 12 | Name string `gorm:"column:name;comment:名字" json:"name"` // 名字 13 | Image string `gorm:"column:image;comment:图片" json:"image"` // 图片 14 | OrderID int64 `gorm:"column:order_id;not null;comment:订单id" json:"order_id"` // 订单id 15 | DishID int64 `gorm:"column:dish_id;comment:菜品id" json:"dish_id"` // 菜品id 16 | SetmealID int64 `gorm:"column:setmeal_id;comment:套餐id" json:"setmeal_id"` // 套餐id 17 | DishFlavor string `gorm:"column:dish_flavor;comment:口味" json:"dish_flavor"` // 口味 18 | Number int32 `gorm:"column:number;not null;default:1;comment:数量" json:"number"` // 数量 19 | Amount float64 `gorm:"column:amount;not null;comment:金额" json:"amount"` // 金额 20 | } 21 | 22 | // TableName OrderDetail's table name 23 | func (*OrderDetail) TableName() string { 24 | return TableNameOrderDetail 25 | } 26 | -------------------------------------------------------------------------------- /internal/models/model/orders.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import ( 4 | "time" 5 | ) 6 | 7 | const ( 8 | TableNameOrder = "orders" 9 | /** 10 | * 订单状态 1待付款 2待接单 3已接单 4派送中 5已完成 6已取消 11 | */ 12 | 13 | PENDING_PAYMENT = iota + 1 14 | TO_BE_CONFIRMED 15 | CONFIRMED 16 | DELIVERY_IN_PROGRESS 17 | COMPLETED 18 | CANCELLED 19 | ) 20 | const ( 21 | UN_PAID = iota 22 | PAID 23 | REFUND 24 | 25 | serialVersionUID = 1 26 | ) 27 | 28 | // Order 订单表 29 | type Order struct { 30 | ID int64 `gorm:"column:id;primaryKey;autoIncrement:true;comment:主键" json:"id"` // 主键 31 | Number string `gorm:"column:number;comment:订单号" json:"number"` // 订单号 32 | Status int32 `gorm:"column:status;not null;default:1;comment:订单状态 1待付款 2待接单 3已接单 4派送中 5已完成 6已取消 7退款" json:"status"` // 订单状态 1待付款 2待接单 3已接单 4派送中 5已完成 6已取消 7退款 33 | UserID int64 `gorm:"column:user_id;not null;comment:下单用户" json:"user_id"` // 下单用户 34 | AddressBookID int64 `gorm:"column:address_book_id;not null;comment:地址id" json:"address_book_id"` // 地址id 35 | OrderTime time.Time `gorm:"column:order_time;not null;comment:下单时间" json:"order_time"` // 下单时间 36 | CheckoutTime time.Time `gorm:"column:checkout_time;comment:结账时间" json:"checkout_time"` // 结账时间 37 | PayMethod int32 `gorm:"column:pay_method;not null;default:1;comment:支付方式 1微信,2支付宝" json:"pay_method"` // 支付方式 1微信,2支付宝 38 | PayStatus int32 `gorm:"column:pay_status;not null;comment:支付状态 0未支付 1已支付 2退款" json:"pay_status"` // 支付状态 0未支付 1已支付 2退款 39 | Amount float64 `gorm:"column:amount;not null;comment:实收金额" json:"amount"` // 实收金额 40 | Remark string `gorm:"column:remark;comment:备注" json:"remark"` // 备注 41 | Phone string `gorm:"column:phone;comment:手机号" json:"phone"` // 手机号 42 | Address string `gorm:"column:address;comment:地址" json:"address"` // 地址 43 | UserName string `gorm:"column:user_name;comment:用户名称" json:"user_name"` // 用户名称 44 | Consignee string `gorm:"column:consignee;comment:收货人" json:"consignee"` // 收货人 45 | CancelReason string `gorm:"column:cancel_reason;comment:订单取消原因" json:"cancel_reason"` // 订单取消原因 46 | RejectionReason string `gorm:"column:rejection_reason;comment:订单拒绝原因" json:"rejection_reason"` // 订单拒绝原因 47 | CancelTime time.Time `gorm:"column:cancel_time;comment:订单取消时间" json:"cancel_time"` // 订单取消时间 48 | EstimatedDeliveryTime time.Time `gorm:"column:estimated_delivery_time;comment:预计送达时间" json:"estimated_delivery_time"` // 预计送达时间 49 | DeliveryStatus bool `gorm:"column:delivery_status;not null;default:1;comment:配送状态 1立即送出 0选择具体时间" json:"delivery_status"` // 配送状态 1立即送出 0选择具体时间 50 | DeliveryTime time.Time `gorm:"column:delivery_time;comment:送达时间" json:"delivery_time"` // 送达时间 51 | PackAmount int32 `gorm:"column:pack_amount;comment:打包费" json:"pack_amount"` // 打包费 52 | TablewareNumber int32 `gorm:"column:tableware_number;comment:餐具数量" json:"tableware_number"` // 餐具数量 53 | TablewareStatus bool `gorm:"column:tableware_status;not null;default:1;comment:餐具数量状态 1按餐量提供 0选择具体数量" json:"tableware_status"` // 餐具数量状态 1按餐量提供 0选择具体数量 54 | } 55 | 56 | // TableName Order's table name 57 | func (*Order) TableName() string { 58 | return TableNameOrder 59 | } 60 | -------------------------------------------------------------------------------- /internal/models/model/setmeal.gen.go: -------------------------------------------------------------------------------- 1 | // Code generated by gorm.io/gen. DO NOT EDIT. 2 | // Code generated by gorm.io/gen. DO NOT EDIT. 3 | // Code generated by gorm.io/gen. DO NOT EDIT. 4 | 5 | package model 6 | 7 | import ( 8 | "time" 9 | ) 10 | 11 | const TableNameSetmeal = "setmeal" 12 | 13 | // Setmeal 套餐 14 | type Setmeal struct { 15 | ID int64 `gorm:"column:id;primaryKey;autoIncrement:true;comment:主键" json:"id"` // 主键 16 | CategoryID int64 `gorm:"column:category_id;not null;comment:菜品分类id" json:"category_id"` // 菜品分类id 17 | Name string `gorm:"column:name;not null;comment:套餐名称" json:"name"` // 套餐名称 18 | Price float64 `gorm:"column:price;not null;comment:套餐价格" json:"price"` // 套餐价格 19 | Status int32 `gorm:"column:status;default:1;comment:售卖状态 0:停售 1:起售" json:"status"` // 售卖状态 0:停售 1:起售 20 | Description string `gorm:"column:description;comment:描述信息" json:"description"` // 描述信息 21 | Image string `gorm:"column:image;comment:图片" json:"image"` // 图片 22 | CreateTime time.Time `gorm:"column:create_time;comment:创建时间" json:"create_time"` // 创建时间 23 | UpdateTime time.Time `gorm:"column:update_time;comment:更新时间" json:"update_time"` // 更新时间 24 | CreateUser int64 `gorm:"column:create_user;comment:创建人" json:"create_user"` // 创建人 25 | UpdateUser int64 `gorm:"column:update_user;comment:修改人" json:"update_user"` // 修改人 26 | } 27 | 28 | // TableName Setmeal's table name 29 | func (*Setmeal) TableName() string { 30 | return TableNameSetmeal 31 | } 32 | -------------------------------------------------------------------------------- /internal/models/model/setmeal_dish.go: -------------------------------------------------------------------------------- 1 | // Code generated by gorm.io/gen. DO NOT EDIT. 2 | // Code generated by gorm.io/gen. DO NOT EDIT. 3 | // Code generated by gorm.io/gen. DO NOT EDIT. 4 | 5 | package model 6 | 7 | const TableNameSetmealDish = "setmeal_dish" 8 | 9 | // SetmealDish 套餐菜品关系 10 | type SetmealDish struct { 11 | ID int64 `gorm:"column:id;primaryKey;autoIncrement:true;comment:主键" json:"id"` // 主键 12 | SetmealID int64 `gorm:"column:setmeal_id;comment:套餐id" json:"setmeal_id"` // 套餐id 13 | DishID int64 `gorm:"column:dish_id;comment:菜品id" json:"dishID"` // 菜品id 14 | Name string `gorm:"column:name;comment:菜品名称 (冗余字段)" json:"name"` // 菜品名称 (冗余字段) 15 | Price float64 `gorm:"column:price;comment:菜品单价(冗余字段)" json:"price"` // 菜品单价(冗余字段) 16 | Copies int32 `gorm:"column:copies;comment:菜品份数" json:"copies"` // 菜品份数 17 | } 18 | 19 | // TableName SetmealDish's table name 20 | func (*SetmealDish) TableName() string { 21 | return TableNameSetmealDish 22 | } 23 | -------------------------------------------------------------------------------- /internal/models/model/shopping_cart.gen.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import ( 4 | "time" 5 | ) 6 | 7 | const TableNameShoppingCart = "shopping_cart" 8 | 9 | // ShoppingCart 购物车 10 | type ShoppingCart struct { 11 | ID int64 `gorm:"column:id;primaryKey;autoIncrement:true;comment:主键" json:"id"` // 主键 12 | Name string `gorm:"column:name;comment:商品名称" json:"name"` // 商品名称 13 | Image string `gorm:"column:image;comment:图片" json:"image"` // 图片 14 | UserID int64 `gorm:"column:user_id;not null;comment:主键" json:"user_id"` // 主键 15 | DishID int64 `gorm:"column:dish_id;comment:菜品id" json:"dish_id"` // 菜品id 16 | SetmealID int64 `gorm:"column:setmeal_id;comment:套餐id" json:"setmeal_id"` // 套餐id 17 | DishFlavor string `gorm:"column:dish_flavor;comment:口味" json:"dish_flavor"` // 口味 18 | Number int32 `gorm:"column:number;not null;default:1;comment:数量" json:"number"` // 数量 19 | Amount float64 `gorm:"column:amount;not null;comment:金额" json:"amount"` // 金额 20 | CreateTime time.Time `gorm:"column:create_time;comment:创建时间" json:"create_time"` // 创建时间 21 | } 22 | 23 | // TableName ShoppingCart's table name 24 | func (*ShoppingCart) TableName() string { 25 | return TableNameShoppingCart 26 | } 27 | -------------------------------------------------------------------------------- /internal/models/model/user.gen.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import ( 4 | "time" 5 | ) 6 | 7 | const TableNameUser = "user" 8 | 9 | // User 用户信息 10 | type User struct { 11 | ID int64 `gorm:"column:id;primaryKey;autoIncrement:true;comment:主键" json:"id"` // 主键 12 | Openid string `gorm:"column:openid;comment:微信用户唯一标识" json:"openid"` // 微信用户唯一标识 13 | Name string `gorm:"column:name;comment:姓名" json:"name"` // 姓名 14 | Phone string `gorm:"column:phone;comment:手机号" json:"phone"` // 手机号 15 | Sex string `gorm:"column:sex;comment:性别" json:"sex"` // 性别 16 | IDNumber string `gorm:"column:id_number;comment:身份证号" json:"id_number"` // 身份证号 17 | Avatar string `gorm:"column:avatar;comment:头像" json:"avatar"` // 头像 18 | CreateTime time.Time `gorm:"column:create_time" json:"create_time"` 19 | } 20 | 21 | // TableName User's table name 22 | func (*User) TableName() string { 23 | return TableNameUser 24 | } 25 | -------------------------------------------------------------------------------- /internal/models/vo/common.go: -------------------------------------------------------------------------------- 1 | package vo 2 | 3 | import ( 4 | "reggie/internal/models/model" 5 | "time" 6 | ) 7 | 8 | type BusinessDataVO struct { 9 | Turnover float64 `json:"turnover,omitempty"` //营业额 10 | 11 | ValidOrderCount int64 `json:"valid_order_count,omitempty"` //有效订单数 12 | 13 | OrderCompletionRate float64 `json:"order_completion_rate,omitempty"` //订单完成率 14 | 15 | UnitPrice float64 `json:"unit_price,omitempty"` //平均客单价 16 | 17 | NewUsers int64 `json:"new_users,omitempty"` //新增用户数 18 | 19 | } 20 | type OrderOverViewVO struct { 21 | 22 | //待接单数量 23 | WaitingOrders int64 `json:"waiting_orders,omitempty"` 24 | 25 | //待派送数量 26 | DeliveredOrders int64 `json:"delivered_orders,omitempty"` 27 | 28 | //已完成数量 29 | CompletedOrders int64 `json:"completed_orders,omitempty"` 30 | 31 | //已取消数量 32 | CancelledOrders int64 `json:"cancelled_orders,omitempty"` 33 | 34 | //全部订单 35 | AllOrders int64 `json:"all_orders,omitempty"` 36 | } 37 | 38 | type EmployeeLoginVO struct { 39 | Id int64 `json:"id,omitempty"` 40 | 41 | UserName string `json:"user_name,omitempty"` 42 | 43 | Name string `json:"name,omitempty"` 44 | 45 | Token string `json:"token,omitempty"` 46 | } 47 | type DishOverViewVO struct { 48 | 49 | // 已启售数量 50 | Sold int64 `json:"sold,omitempty"` 51 | 52 | // 已停售数量 53 | Discontinued int64 `json:"discontinued,omitempty"` 54 | } 55 | type SetmealOverViewVO struct { 56 | 57 | // 已启售数量 58 | Sold int64 `json:"sold,omitempty"` 59 | 60 | // 已停售数量 61 | Discontinued int64 `json:"discontinued,omitempty"` 62 | } 63 | 64 | type SetmealVO struct { 65 | ID int64 `gorm:"column:id;primaryKey;autoIncrement:true;comment:主键" json:"id"` // 主键 66 | CategoryID int64 `gorm:"column:category_id;not null;comment:菜品分类id" json:"category_id"` // 菜品分类id 67 | Name string `gorm:"column:name;not null;comment:套餐名称" json:"name"` // 套餐名称 68 | Price float64 `gorm:"column:price;not null;comment:套餐价格" json:"price"` // 套餐价格 69 | Status int32 `gorm:"column:status;default:1;comment:售卖状态 0:停售 1:起售" json:"status"` // 售卖状态 0:停售 1:起售 70 | Description string `gorm:"column:description;comment:描述信息" json:"description"` // 描述信息 71 | Image string `gorm:"column:image;comment:图片" json:"image"` // 图片 72 | UpdateTime time.Time `gorm:"column:update_time;comment:更新时间" json:"update_time"` // 更新时间 73 | SetmealDishes []model.SetmealDish `gorm:"foreignKey:setmeal_id"` 74 | } 75 | type UserLoginVO struct { 76 | Id int64 `json:"id,omitempty"` 77 | Openid string `json:"openid,omitempty"` 78 | Token string `json:"token,omitempty"` 79 | } 80 | 81 | func (ul *UserLoginVO) User2UserLoginVO(u *model.User) { 82 | ul.Id = (*u).ID 83 | ul.Openid = (*u).Openid 84 | } 85 | -------------------------------------------------------------------------------- /internal/models/vo/dishvo.go: -------------------------------------------------------------------------------- 1 | package vo 2 | 3 | import ( 4 | "encoding/json" 5 | "reggie/internal/models/model" 6 | "time" 7 | ) 8 | 9 | type DishVO struct { 10 | Id int64 `json:"id,omitempty"` 11 | //菜品名称 12 | Name string `json:"name,omitempty"` 13 | //菜品分类id 14 | CategoryId int64 `json:"category_id,omitempty"` 15 | //菜品价格 16 | Price float64 `json:"price,omitempty"` 17 | //图片 18 | Image string `json:"image,omitempty"` 19 | //描述信息 20 | Description string `json:"description,omitempty"` 21 | //0 停售 1 起售 22 | Status int32 `json:"status,omitempty"` 23 | //更新时间 24 | UpdateTime time.Time `json:"update_time"` 25 | //分类名称 26 | CategoryName string `json:"category_name,omitempty"` 27 | //菜品关联的口味 28 | Flavors *[]model.DishFlavor `json:"flavors,omitempty"` 29 | } 30 | 31 | func (dv *DishVO) ForDishAndFlavor(d *model.Dish, f *[]model.DishFlavor) { 32 | dv.Id, dv.Name, dv.CategoryId, dv.Price, dv.Image, dv.Description, dv.Status, dv.UpdateTime, dv.Flavors = 33 | d.ID, d.Name, d.CategoryID, d.Price, d.Image, d.Description, d.Status, d.UpdateTime, f 34 | } 35 | func Dish2DishVO(d *model.Dish) *DishVO { 36 | var dv DishVO 37 | dv.Id, dv.Name, dv.CategoryId, dv.Price, dv.Image, dv.Description, dv.Status, dv.UpdateTime = d.ID, d.Name, d.CategoryID, d.Price, d.Image, d.Description, d.Status, d.UpdateTime 38 | return &dv 39 | } 40 | 41 | // 添加josn序列化,方便redis存储 42 | func (dv *DishVO) MarshalBinary() ([]byte, error) { 43 | return json.Marshal(dv) 44 | } 45 | func (dv *DishVO) UnmarshalBinary(data []byte) error { 46 | return json.Unmarshal(data, dv) 47 | } 48 | -------------------------------------------------------------------------------- /internal/models/vo/orderVO.go: -------------------------------------------------------------------------------- 1 | package vo 2 | 3 | import "reggie/internal/models/model" 4 | 5 | type OrderVO struct { 6 | 7 | //订单菜品信息 8 | OrderDishes string `json:"orderDishes,omitempty"` 9 | //订单详情 10 | OrderDetailList *[]model.OrderDetail `json:"orderDetailList,omitempty"` 11 | } 12 | -------------------------------------------------------------------------------- /internal/models/vo/order_submitVO.go: -------------------------------------------------------------------------------- 1 | package vo 2 | 3 | import "time" 4 | 5 | type OrderSubmitVO struct { 6 | //订单id 7 | Id int64 `json:"id,omitempty"` 8 | //订单号 9 | OrderNumber string `json:"orderNumber,omitempty"` 10 | //订单金额 11 | OrderAmount float64 `json:"orderAmount,omitempty"` 12 | //下单时间 13 | OrderTime time.Time `json:"orderTime"` 14 | } 15 | -------------------------------------------------------------------------------- /internal/router/admin/category_router.go: -------------------------------------------------------------------------------- 1 | package admin 2 | 3 | import ( 4 | "context" 5 | "github.com/cloudwego/hertz/pkg/app" 6 | "log" 7 | "net/http" 8 | "reggie/internal/middleware" 9 | "reggie/internal/models/common" 10 | "reggie/internal/models/dto" 11 | "reggie/internal/models/model" 12 | "reggie/internal/router/service" 13 | "strconv" 14 | "time" 15 | ) 16 | 17 | // over 18 | 19 | // 新增菜品 20 | // @Summary 新增菜品 21 | // @Accept application/json 22 | // @Produce application/json 23 | // @router /admin/category [post] 24 | func SaveCategory(ctx context.Context, c *app.RequestContext) { 25 | var category model.Category 26 | c.Bind(&category) 27 | // 赋予创建用户和更新用户的数据 28 | category.CreateUser, category.UpdateUser = middleware.GetJwtPayload(c), middleware.GetJwtPayload(c) 29 | // 赋予创建时间和更新时间数据 30 | category.CreateTime, category.UpdateTime = time.Now(), time.Now() 31 | log.Println("新增分类:", category) 32 | service.SaveCategory(&category) 33 | c.JSON(http.StatusOK, common.Result{1, "", nil}) 34 | } 35 | 36 | // 菜品分类分页 37 | // @Summary 新增菜品 38 | // @Accept application/json 39 | // @Produce application/json 40 | // @router /admin/category/page [get] 41 | func PageCat(ctx context.Context, c *app.RequestContext) { 42 | var categoryPage dto.CategoryPageQueryDTO 43 | c.Bind(&categoryPage) 44 | log.Println("菜品分类查询", categoryPage) 45 | cat := service.PageQueryDat(&categoryPage) 46 | c.JSON(http.StatusOK, common.Result{1, "", cat}) 47 | } 48 | 49 | // 按照id删除菜品分类 50 | // @Summary 新增菜品 51 | // @Accept application/json 52 | // @Produce application/json 53 | // @router /admin/category [delete] 54 | func DeleteCat(ctx context.Context, c *app.RequestContext) { 55 | id := c.Query("id") 56 | log.Printf("查询员工账号:{%s}", id) 57 | id_r, _ := strconv.ParseInt(id, 10, 64) 58 | if err := service.DeleteCat(&id_r); err != nil { 59 | log.Println(err) 60 | c.JSON(http.StatusOK, common.Result{0, "", nil}) 61 | } else { 62 | c.JSON(http.StatusOK, common.Result{1, "", nil}) 63 | } 64 | } 65 | 66 | // 修改菜品分类信息 67 | // @Summary 修改菜品分类信息 68 | // @Accept application/json 69 | // @Produce application/json 70 | // @router /admin/category [put] 71 | func UpdateCat(ctx context.Context, c *app.RequestContext) { 72 | var category model.Category 73 | c.Bind(&category) 74 | // 赋予创建时间和更新时间数据 75 | category.CreateTime, category.UpdateTime = time.Now(), time.Now() 76 | log.Println("修改菜品分类信息:", category) 77 | service.UpdateCategory(&category) 78 | c.JSON(http.StatusOK, common.Result{1, "", nil}) 79 | } 80 | 81 | // 启用禁用菜品分类 82 | // @Summary 启用禁用菜品分类 83 | // @Accept application/json 84 | // @Produce application/json 85 | // @router /admin/category/status [post] 86 | func StartOrStopCat(ctx context.Context, c *app.RequestContext) { 87 | status, id := c.Param("status"), c.Query("id") 88 | log.Printf("启用禁用菜品分类:{%s},{%s}", status, id) 89 | status_r, _ := strconv.ParseInt(status, 10, 32) 90 | id_r, _ := strconv.ParseInt(id, 10, 64) 91 | service.StartOrStopCat(int32(status_r), id_r, middleware.GetJwtPayload(c)) 92 | c.JSON(http.StatusOK, common.Result{1, "", nil}) 93 | } 94 | 95 | // 启用禁用菜品分类 96 | // @Summary 启用禁用菜品分类 97 | // @Accept application/json 98 | // @Produce application/json 99 | // @router /admin/category/list [get] 100 | func ListCat(ctx context.Context, c *app.RequestContext) { 101 | ty_pe := c.Query("type") 102 | log.Printf("按照类型查询菜品:{%s}", ty_pe) 103 | tp, _ := strconv.ParseInt(ty_pe, 10, 64) 104 | 105 | c.JSON(http.StatusOK, common.Result{1, "", service.ListCat(&tp)}) 106 | } 107 | -------------------------------------------------------------------------------- /internal/router/admin/common_router.go: -------------------------------------------------------------------------------- 1 | package admin 2 | 3 | import ( 4 | "context" 5 | "github.com/cloudwego/hertz/pkg/app" 6 | "github.com/cloudwego/hertz/pkg/common/hlog" 7 | "mime/multipart" 8 | "net/http" 9 | "reggie/internal/models/common" 10 | "reggie/internal/models/constant/message_c" 11 | "reggie/pkg/obs" 12 | ) 13 | 14 | // over 15 | func getFile(from *multipart.Form) *multipart.FileHeader { 16 | // 获取文件对应的文件头 17 | fileH := from.File["file"][0] 18 | return fileH 19 | } 20 | func UploadImg(ctx context.Context, c *app.RequestContext) { 21 | form, err := c.MultipartForm() 22 | hlog.Info("文件上传:{ %s}", form) 23 | if err != nil { 24 | c.JSON(http.StatusOK, common.Result{0, message_c.UPLOAD_FAILED, nil}) 25 | } 26 | if str := obs.OBS.UploadImg(getFile(form)); str != nil { 27 | c.JSON(http.StatusOK, common.Result{1, "", str}) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /internal/router/admin/dish_router.go: -------------------------------------------------------------------------------- 1 | package admin 2 | 3 | import ( 4 | "context" 5 | "github.com/cloudwego/hertz/pkg/app" 6 | "log" 7 | "net/http" 8 | "reggie/internal/middleware" 9 | "reggie/internal/models/common" 10 | "reggie/internal/models/dto" 11 | "reggie/internal/models/model" 12 | "reggie/internal/router/service" 13 | "reggie/pkg/redis" 14 | "strconv" 15 | "strings" 16 | "time" 17 | ) 18 | 19 | // @Summary 新增菜品 20 | func SaveDish(ctx context.Context, c *app.RequestContext) { 21 | var dist dto.DishDTO 22 | c.Bind(&dist) 23 | id := middleware.GetJwtPayload(c) 24 | var dish = dist.ToNewDish(&id) 25 | log.Println("新增分类:", dish) 26 | service.SaveWithFlavorDish(dish, &dist.Flavors) 27 | c.JSON(http.StatusOK, common.Result{1, "", nil}) 28 | } 29 | 30 | // @Summary 分页查询 31 | func PageDish(ctx context.Context, c *app.RequestContext) { 32 | var dishPage dto.DishPageQueryDTO 33 | c.Bind(&dishPage) 34 | log.Println("菜品分类查询", dishPage) 35 | cat := service.PageQueryDish(&dishPage) 36 | c.JSON(http.StatusOK, common.Result{1, "", cat}) 37 | } 38 | 39 | // @Summary 批量删除菜品 40 | func DeleteDish(ctx context.Context, c *app.RequestContext) { 41 | id := c.Query("ids") 42 | nums := make([]int64, 0, 5) 43 | log.Printf("根据id删除菜品:{%s}", id) 44 | ids := strings.Split(id, ",") 45 | // 转换成数字数组 46 | for _, v := range ids { 47 | id_r, _ := strconv.ParseInt(v, 10, 64) 48 | nums = append(nums, id_r) 49 | } 50 | 51 | if err := service.DeleteDish(&nums); err != nil { 52 | log.Println(err) 53 | c.JSON(http.StatusOK, common.Result{0, "", nil}) 54 | } else { 55 | c.JSON(http.StatusOK, common.Result{1, "", nil}) 56 | } 57 | } 58 | 59 | // @Summary 根据id查询菜品 60 | func GetByIdDish(ctx context.Context, c *app.RequestContext) { 61 | id := c.Param("id") 62 | log.Printf("查询菜品:{%s}", id) 63 | id_r, _ := strconv.ParseInt(id, 10, 64) 64 | emp := service.GetByIdWithFlavor(id_r) 65 | c.JSON(http.StatusOK, common.Result{1, "", emp}) 66 | } 67 | 68 | // @Summary 更新菜品 69 | func UpdateDish(ctx context.Context, c *app.RequestContext) { 70 | var dish model.Dish 71 | c.Bind(&dish) 72 | // 赋予创建时间和更新时间数据 73 | dish.CreateTime, dish.UpdateTime = time.Now(), time.Now() 74 | log.Println("修改菜品分类信息:", dish) 75 | service.UpdateDish(&dish) 76 | c.JSON(http.StatusOK, common.Result{1, "", nil}) 77 | } 78 | 79 | // @Summary 菜品启停售 80 | func StartOrStopDish(ctx context.Context, c *app.RequestContext) { 81 | status, id := c.Param("status"), c.Query("id") 82 | redis.RC.ClearCacheDishByCategoryId("*") 83 | log.Printf("启用禁用菜品分类:{%s},{%s}", status, id) 84 | status_r, _ := strconv.ParseInt(status, 10, 32) 85 | id_r, _ := strconv.ParseInt(id, 10, 64) 86 | service.StartOrStopDish(int32(status_r), id_r, middleware.GetJwtPayload(c)) 87 | c.JSON(http.StatusOK, common.Result{1, "", nil}) 88 | } 89 | 90 | // @Summary 根据类型查询分类 91 | func ListDish(ctx context.Context, c *app.RequestContext) { 92 | ty_pe := c.Query("categoryId") 93 | log.Printf("按照类型查询菜品:{%s}", ty_pe) 94 | tp, _ := strconv.ParseInt(ty_pe, 10, 64) 95 | dish := service.ListDish(&tp) 96 | c.JSON(http.StatusOK, common.Result{1, "", dish}) 97 | } 98 | -------------------------------------------------------------------------------- /internal/router/admin/employee_router.go: -------------------------------------------------------------------------------- 1 | package admin 2 | 3 | import ( 4 | "context" 5 | "github.com/cloudwego/hertz/pkg/app" 6 | "log" 7 | "net/http" 8 | "reggie/internal/middleware" 9 | "reggie/internal/models/common" 10 | "reggie/internal/models/constant/message_c" 11 | "reggie/internal/models/dto" 12 | "reggie/internal/models/model" 13 | "reggie/internal/router/service" 14 | "strconv" 15 | "time" 16 | ) 17 | 18 | // over 19 | 20 | // 存储用户 21 | // @Summary 存储用户 22 | // @Accept application/json 23 | // @Produce application/json 24 | // @router /admin/employee [post] 25 | func SaveEmp(ctx context.Context, c *app.RequestContext) { 26 | var empL model.Employee 27 | // 参数绑定转化为结构体 28 | err := c.Bind(&empL) 29 | if err != nil { 30 | log.Println("Employee 参数绑定失败") 31 | c.JSON(http.StatusBadRequest, common.Result{1, message_c.UNKNOWN_ERROR, nil}) 32 | } else { 33 | // 获取jwt_payload的信息,并把信息赋予empL 34 | emp_id := middleware.GetJwtPayload(c) 35 | empL.CreateUser, empL.UpdateUser = emp_id, emp_id 36 | log.Printf("新增用户:{%s}", empL.Username) 37 | flag := service.SaveEmp(&empL) 38 | if flag == true { 39 | c.JSON(http.StatusOK, common.Result{1, "", nil}) 40 | } 41 | c.JSON(http.StatusBadRequest, common.Result{1, message_c.ALREADY_EXISTS, nil}) 42 | } 43 | } 44 | 45 | // 分页查询 46 | // @Summary 分页查询 47 | // @Accept application/json 48 | // @Produce application/json 49 | // @router /admin/employee/page [get] 50 | func PageEmp(ctx context.Context, c *app.RequestContext) { 51 | var page dto.EmployeePageQueryDTO 52 | // 参数绑定转化为结构体 53 | err := c.Bind(&page) 54 | if err != nil { 55 | log.Println("Employee 参数绑定失败") 56 | c.JSON(http.StatusBadRequest, common.Result{1, message_c.UNKNOWN_ERROR, nil}) 57 | } else { 58 | log.Println("员工分页查询,参数为:", page.Name) 59 | 60 | c.JSON(http.StatusOK, common.Result{1, "", service.PageQueryEmp(&page)}) 61 | } 62 | } 63 | 64 | // 禁用员工账号 65 | // @Summary 禁用员工账号 66 | // @Accept application/json 67 | // @Produce application/json 68 | // @router /admin/employee/status [post] 69 | func StartOrStopEmp(ctx context.Context, c *app.RequestContext) { 70 | status, id := c.Param("status"), c.Query("id") 71 | log.Printf("启用禁用员工账号:{%s},{%s}", status, id) 72 | status_r, _ := strconv.ParseInt(status, 10, 32) 73 | id_r, _ := strconv.ParseInt(id, 10, 64) 74 | service.StartOrStopEmp(int32(status_r), id_r, middleware.GetJwtPayload(c)) 75 | c.JSON(http.StatusOK, common.Result{1, "", nil}) 76 | } 77 | 78 | // 根据id查找雇员 79 | // @Summary 根据id查找雇员 80 | // @Accept application/json 81 | // @Produce application/json 82 | // @router /admin/employee/status [get] 83 | func GetByIdEmp(ctx context.Context, c *app.RequestContext) { 84 | id := c.Param("id") 85 | log.Printf("查询员工账号:{%s}", id) 86 | id_r, _ := strconv.ParseInt(id, 10, 64) 87 | emp := service.GetByIdEmp(id_r) 88 | c.JSON(http.StatusOK, common.Result{1, "", emp}) 89 | } 90 | 91 | // 更新雇员信息 92 | // @Summary 根据id更新雇员信息 93 | // @Accept application/json 94 | // @Produce application/json 95 | // @router /admin/employee [put] 96 | func UpdateEmp(ctx context.Context, c *app.RequestContext) { 97 | var emp model.Employee 98 | c.BindAndValidate(&emp) 99 | emp.UpdateUser, emp.UpdateTime = middleware.GetJwtPayload(c), time.Now() 100 | log.Println("编辑员工信息:", emp) 101 | service.UpdateEmp(&emp) 102 | c.JSON(http.StatusOK, common.Result{1, "", nil}) 103 | } 104 | -------------------------------------------------------------------------------- /internal/router/admin/order_router.go: -------------------------------------------------------------------------------- 1 | package admin 2 | 3 | import ( 4 | "context" 5 | "github.com/cloudwego/hertz/pkg/app" 6 | "net/http" 7 | "reggie/internal/models/common" 8 | "reggie/internal/models/constant/message_c" 9 | "reggie/internal/models/dto" 10 | "reggie/internal/router/service" 11 | ) 12 | 13 | // @Summary 订单搜索 14 | func ConditionSearchOrder(ctx context.Context, c *app.RequestContext) { 15 | var oq dto.OrdersPageQueryDTO 16 | err := c.Bind(&oq) 17 | if err != nil { 18 | c.JSON(http.StatusBadRequest, common.Result{1, message_c.UNKNOWN_ERROR, nil}) 19 | } 20 | r, err := service.ConditionSearchOrder(&oq) 21 | if err != nil { 22 | c.JSON(http.StatusBadRequest, common.Result{1, message_c.UNKNOWN_ERROR, nil}) 23 | } 24 | c.JSON(http.StatusOK, r) 25 | } 26 | -------------------------------------------------------------------------------- /internal/router/admin/setmeal_router.go: -------------------------------------------------------------------------------- 1 | package admin 2 | 3 | import ( 4 | "context" 5 | "github.com/cloudwego/hertz/pkg/app" 6 | "github.com/cloudwego/hertz/pkg/common/hlog" 7 | "log" 8 | "net/http" 9 | "reggie/internal/middleware" 10 | "reggie/internal/models/common" 11 | "reggie/internal/models/constant/message_c" 12 | "reggie/internal/models/dto" 13 | "reggie/internal/router/service" 14 | "strconv" 15 | "strings" 16 | ) 17 | 18 | // over 19 | 20 | // @Summary 套餐管理接机口 21 | func SaveSetMealWithDish(ctx context.Context, c *app.RequestContext) { 22 | var setD dto.SetmealDTO 23 | // 参数绑定转化为结构体 24 | err := c.Bind(&setD) 25 | if err != nil { 26 | hlog.Error("新增套餐错误") 27 | } 28 | log.Printf("新增套餐:{%s}", setD) 29 | meal := setD.ToNewSetmeal() 30 | meal.CreateUser, meal.UpdateUser = middleware.GetJwtPayload(c), middleware.GetJwtPayload(c) 31 | err = service.SaveSetMealWithDish(meal, setD.SetmealDishes) 32 | if err == nil { 33 | c.JSON(http.StatusOK, common.Result{0, message_c.ALREADY_EXISTS, nil}) 34 | } 35 | c.JSON(http.StatusOK, common.Result{1, "", nil}) 36 | } 37 | 38 | // @Summary 分页查询 39 | func PageSetMeal(ctx context.Context, c *app.RequestContext) { 40 | var page dto.SetmealPageQueryDTO 41 | // 参数绑定转化为结构体 42 | c.Bind(&page) 43 | 44 | log.Println("套餐分页查询,参数为:", page.Name) 45 | 46 | c.JSON(http.StatusOK, common.Result{1, "", service.PageQuerySetMeal(&page)}) 47 | } 48 | 49 | // @Summary 批量删除套餐批量删除套餐 50 | func DeleteBatchMeal(ctx context.Context, c *app.RequestContext) { 51 | id := c.Query("ids") 52 | nums := make([]int64, 0, 5) 53 | log.Printf("根据id删除菜品:{%s}", id) 54 | ids := strings.Split(id, ",") 55 | // 转换成数字数组 56 | for _, v := range ids { 57 | id_r, _ := strconv.ParseInt(v, 10, 64) 58 | nums = append(nums, id_r) 59 | } 60 | 61 | if err := service.DeleteBatchMeal(&nums); err != nil { 62 | log.Println(err) 63 | c.JSON(http.StatusNotFound, common.Result{0, "", nil}) 64 | } else { 65 | c.JSON(http.StatusOK, common.Result{1, "", nil}) 66 | } 67 | } 68 | 69 | // @Summary 根据id查询套餐 70 | func GetByIDDishMeal(ctx context.Context, c *app.RequestContext) { 71 | id := c.Param("id") 72 | log.Printf("查询菜单:{%s}", id) 73 | id_r, _ := strconv.ParseInt(id, 10, 64) 74 | v, err := service.GetByIdWithDishMeal(id_r) 75 | if err != nil { 76 | c.JSON(http.StatusNotFound, common.Result{0, message_c.UNKNOWN_ERROR, nil}) 77 | } else { 78 | c.JSON(http.StatusOK, common.Result{1, "", v}) 79 | } 80 | 81 | } 82 | 83 | // @Summary 修改套餐 84 | func UpdateMeal(ctx context.Context, c *app.RequestContext) { 85 | var meal_t dto.SetmealDTO 86 | c.Bind(&meal_t) 87 | // 赋予创建时间和更新时间数据 88 | meal := meal_t.ToNewSetmeal() 89 | meal.CreateUser, meal.CreateUser = middleware.GetJwtPayload(c), middleware.GetJwtPayload(c) 90 | log.Println("修改菜品分类信息:", meal) 91 | service.UpdateMeal(meal, meal_t.SetmealDishes) 92 | c.JSON(http.StatusOK, common.Result{1, "", nil}) 93 | } 94 | 95 | // @Summary 套餐起售停售 96 | func StartOrStopMeal(ctx context.Context, c *app.RequestContext) { 97 | status, id := c.Param("status"), c.Query("id") 98 | log.Printf("启用禁用套餐分类:{%s},{%s}", status, id) 99 | status_r, _ := strconv.ParseInt(status, 10, 32) 100 | id_r, _ := strconv.ParseInt(id, 10, 64) 101 | service.StartOrStopMeal(int32(status_r), id_r) 102 | c.JSON(http.StatusOK, common.Result{1, "", nil}) 103 | } 104 | -------------------------------------------------------------------------------- /internal/router/admin/shop_router.go: -------------------------------------------------------------------------------- 1 | package admin 2 | 3 | import ( 4 | "context" 5 | "github.com/cloudwego/hertz/pkg/app" 6 | "github.com/cloudwego/hertz/pkg/common/hlog" 7 | "net/http" 8 | "reggie/internal/models/common" 9 | "reggie/internal/router/service" 10 | "strconv" 11 | ) 12 | 13 | // @Summary 设置店铺的营业状态 14 | func SetStatusShop(ctx context.Context, c *app.RequestContext) { 15 | s := c.Param("status") 16 | status, _ := strconv.Atoi(s) 17 | var statusString string 18 | if status == 1 { 19 | statusString = "营业中" 20 | } else { 21 | statusString = "打烊中" 22 | } 23 | hlog.Infof("设置店铺的营业状态为:", statusString) 24 | service.SetStatusShop(&status) 25 | c.JSON(http.StatusOK, common.Result{1, "", nil}) 26 | } 27 | 28 | // @Summary 获取店铺的营业状态 29 | func GetStatusShop(ctx context.Context, c *app.RequestContext) { 30 | status := *service.GetStatusShop() 31 | var statusString string 32 | if status == 1 { 33 | statusString = "营业中" 34 | } else { 35 | statusString = "打烊中" 36 | } 37 | hlog.Infof("获取到店铺的营业状态为:{}", statusString) 38 | c.JSON(http.StatusOK, common.Result{1, "", status}) 39 | } 40 | -------------------------------------------------------------------------------- /internal/router/admin/work_space_router.go: -------------------------------------------------------------------------------- 1 | package admin 2 | 3 | import ( 4 | "context" 5 | "github.com/cloudwego/hertz/pkg/app" 6 | "net/http" 7 | "reggie/internal/models/common" 8 | "reggie/internal/router/service" 9 | "time" 10 | ) 11 | 12 | // @Summary 设置店铺的营业状态 13 | func BusinessData(ctx context.Context, c *app.RequestContext) { 14 | now := time.Now() 15 | //获得当天的开始时间 16 | begin := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location()) 17 | //获得当天的结束时间 18 | end := time.Date(now.Year(), now.Month(), now.Day()+1, 0, 0, 0, 0, now.Location()) 19 | c.JSON(http.StatusOK, common.Result{1, "", service.GetBusinessData(begin, end)}) 20 | } 21 | 22 | // @Summary 查询订单管理数据 23 | func OrderOverView(ctx context.Context, c *app.RequestContext) { 24 | 25 | c.JSON(http.StatusOK, common.Result{1, "", service.GetOrderOverView()}) 26 | } 27 | 28 | // @Summary 查询菜品总览 29 | func DishOverView(ctx context.Context, c *app.RequestContext) { 30 | 31 | c.JSON(http.StatusOK, common.Result{1, "", service.GetDishOverView()}) 32 | } 33 | 34 | // @Summary 查询套餐总览 35 | func SetmealOverView(ctx context.Context, c *app.RequestContext) { 36 | c.JSON(http.StatusOK, common.Result{1, "", service.GetSetmealOverView()}) 37 | } 38 | -------------------------------------------------------------------------------- /internal/router/router.go: -------------------------------------------------------------------------------- 1 | package router 2 | 3 | import ( 4 | "context" 5 | "github.com/cloudwego/hertz/pkg/app" 6 | "github.com/cloudwego/hertz/pkg/app/server" 7 | "github.com/hertz-contrib/logger/accesslog" 8 | "net/http" 9 | "reggie/internal/middleware" 10 | "reggie/internal/router/admin" 11 | "reggie/internal/router/user" 12 | ) 13 | 14 | func InitRouter(r *server.Hertz) { 15 | // 添加日志 16 | r.Use(accesslog.New(accesslog.WithFormat("[${time}] ${status} - ${latency} ${method} ${path} ${queryParams}"))) 17 | swa := r.Group("/swagger") 18 | { 19 | middleware.InitSwagger(swa) 20 | } 21 | myJwt := middleware.InitJwtAdmin() 22 | 23 | adm := r.Group("/admin") 24 | emp := adm.Group("/employee") 25 | emp.POST("/login", myJwt.LoginHandler) 26 | // 注意我们要把登陆放到中间件的前面,因为一旦启用中间件,接下来的请求都需要经过jwt的校验 27 | adm.Use(myJwt.MiddlewareFunc()) 28 | { 29 | // 这里必须新生成一个emp,因为新生成的才含有我们的中间件 30 | emp := adm.Group("/employee") 31 | // 启动jwt 32 | emp.POST("/logout", myJwt.LogoutHandler) 33 | // 添加雇员接口 34 | emp.POST("", admin.SaveEmp) 35 | // 添加修改雇员接口 36 | emp.PUT("", admin.UpdateEmp) 37 | // 查询雇员接口 38 | emp.GET("/:id", admin.GetByIdEmp) 39 | // 禁用员工账号 40 | emp.POST("/status/*status", admin.StartOrStopEmp) 41 | emp.GET("/page", admin.PageEmp) 42 | // 这是个测试方法,之后会测试我们的jwt是否拦截 43 | emp.GET("/test", func(c context.Context, ctx *app.RequestContext) { 44 | ctx.String(http.StatusOK, "Fds") 45 | }) 46 | } 47 | category := adm.Group("/category") 48 | { 49 | // 新增菜品路由 50 | category.POST("", admin.SaveCategory) 51 | // 菜品分类分页 52 | category.GET("/page", admin.PageCat) 53 | // 添加按照id删除 54 | category.DELETE("", admin.DeleteCat) 55 | // 添加修改菜品分类 56 | category.PUT("", admin.UpdateCat) 57 | // 启用禁用分类 58 | category.POST("/status/*status", admin.StartOrStopCat) 59 | // 根据类型查询分类 60 | category.GET("/list", admin.ListCat) 61 | } 62 | com := adm.Group("/common") 63 | { 64 | com.POST("/upload", admin.UploadImg) 65 | } 66 | dish := adm.Group("/dish") 67 | { 68 | // 添加菜品 69 | dish.POST("", admin.SaveDish) 70 | // 菜品分页查询 71 | dish.GET("/page", admin.PageDish) 72 | // 菜品批量删除 73 | dish.DELETE("", admin.DeleteDish) 74 | // 按照id查询菜品 75 | dish.GET("/:id", admin.GetByIdDish) 76 | // 添加修改菜品 77 | dish.PUT("", admin.UpdateDish) 78 | // 启用禁用分类 79 | dish.POST("/status/*status", admin.StartOrStopDish) 80 | // 根据类型查询分类 81 | dish.GET("/list", admin.ListDish) 82 | } 83 | // 套餐接口 84 | meal := adm.Group("/setmeal") 85 | { 86 | meal.POST("", admin.SaveSetMealWithDish) 87 | meal.GET("/page", admin.PageSetMeal) 88 | meal.GET("/:id", admin.GetByIDDishMeal) 89 | meal.DELETE("", admin.DeleteBatchMeal) 90 | meal.PUT("", admin.UpdateMeal) 91 | meal.POST("/status/:status", admin.StartOrStopMeal) 92 | } 93 | shop := adm.Group("/shop") 94 | { 95 | shop.PUT("/:status", admin.SetStatusShop) 96 | shop.GET("/status", admin.GetStatusShop) 97 | } 98 | workspace := adm.Group("/workspace") 99 | { 100 | workspace.GET("/businessData", admin.BusinessData) 101 | workspace.GET("/overviewOrders", admin.OrderOverView) 102 | workspace.GET("/overviewDishes", admin.DishOverView) 103 | workspace.GET("/overviewSetmeals", admin.SetmealOverView) 104 | } 105 | 106 | users := r.Group("/user") 107 | user_jwt := middleware.InitJwtUser() 108 | us := users.Group("/user") 109 | us.POST("/login", user_jwt.LoginHandler) 110 | users.Use(user_jwt.MiddlewareFunc()) 111 | u_category := users.Group("/category") 112 | { 113 | u_category.GET("/list", user.ListCategory) 114 | } 115 | u_shop := users.Group("/shop") 116 | { 117 | u_shop.GET("/status", admin.GetStatusShop) 118 | } 119 | u_dish := users.Group("/dish") 120 | { 121 | u_dish.GET("/list", user.ListDish) 122 | } 123 | u_shoppingCart := users.Group("/shoppingCart") 124 | { 125 | u_shoppingCart.POST("/add", user.AddShoppingCart) 126 | u_shoppingCart.GET("/list", user.ListShoppingCart) 127 | u_shoppingCart.DELETE("/clean", user.CleanShoppingCart) 128 | } 129 | u_address := users.Group("/addressBook") 130 | { 131 | u_address.GET("/list", user.ListAddress) 132 | u_address.POST("", user.SaveAddress) 133 | u_address.GET("/:id", user.GetByIdAddress) 134 | u_address.PUT("", user.UpdateAddress) 135 | u_address.PUT("/default", user.SetDefaultAddress) 136 | u_address.DELETE("", user.DeleteByIdAddress) 137 | u_address.GET("/default", user.GetDefaultAddress) 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /internal/router/service/address_service.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | "reggie/internal/db" 5 | "reggie/internal/models/model" 6 | ) 7 | 8 | // 条件查询 9 | func ListAddress(address *model.AddressBook) *[]model.AddressBook { 10 | list, _ := db.AddressDA0.List(address) 11 | return list 12 | } 13 | 14 | // 新增地址 15 | func SaveAddress(address *model.AddressBook) { 16 | db.AddressDA0.Save(address) 17 | } 18 | 19 | // 根据id查询 20 | func GetByIdAddress(id int64) (*model.AddressBook, error) { 21 | addressBook := db.AddressDA0.GetById(id) 22 | return addressBook, nil 23 | } 24 | 25 | // 根据id修改地址 26 | func UpdateAddress(address *model.AddressBook) { 27 | db.AddressDA0.Update(address) 28 | } 29 | 30 | func SetDefaultAddress(address *model.AddressBook) { 31 | //1、将当前用户的所有地址修改为非默认地址 update address_book set is_default = ? where user_id = ? 32 | address.IsDefault = false 33 | db.AddressDA0.UpdateIsDefaultByUserId(address) 34 | 35 | //2、将当前地址改为默认地址 update address_book set is_default = ? where id = ? 36 | address.IsDefault = true 37 | db.AddressDA0.Update(address) 38 | } 39 | 40 | // 根据id删除地址 41 | func DeleteByIdAddress(id int64) { 42 | db.AddressDA0.DeleteById(id) 43 | } 44 | -------------------------------------------------------------------------------- /internal/router/service/category_service.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | "reggie/internal/db" 5 | "reggie/internal/models/common" 6 | "reggie/internal/models/dto" 7 | "reggie/internal/models/model" 8 | "time" 9 | ) 10 | 11 | func SaveCategory(category *model.Category) { 12 | db.CatDao.Save(category) 13 | } 14 | func PageQueryDat(categoryPage *dto.CategoryPageQueryDTO) *common.PageResult { 15 | var pageResult = common.PageResult{} 16 | pageResult.Records, pageResult.Total = db.CatDao.PageQuery(categoryPage) 17 | return &pageResult 18 | } 19 | func DeleteCat(id *int64) *error { 20 | err := db.CatDao.Delete(id) 21 | if err != nil { 22 | return err 23 | } 24 | return nil 25 | } 26 | func UpdateCategory(cat *model.Category) { 27 | db.CatDao.Update(cat) 28 | } 29 | func StartOrStopCat(status int32, id int64, update_user int64) { 30 | cat := model.Category{ 31 | ID: id, 32 | Status: status, 33 | UpdateUser: update_user, 34 | UpdateTime: time.Now(), 35 | } 36 | db.CatDao.UpdateStatus(&cat) 37 | } 38 | func ListCat(tp *int64) *[]model.Category { 39 | return db.CatDao.List(tp) 40 | } 41 | -------------------------------------------------------------------------------- /internal/router/service/dish_service.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | "github.com/cloudwego/hertz/pkg/common/hlog" 5 | "reggie/internal/db" 6 | "reggie/internal/models/common" 7 | "reggie/internal/models/constant/message_c" 8 | "reggie/internal/models/constant/status_c" 9 | "reggie/internal/models/dto" 10 | "reggie/internal/models/model" 11 | "reggie/internal/models/vo" 12 | "reggie/pkg/redis" 13 | "strconv" 14 | "time" 15 | ) 16 | 17 | // 第一个参数菜品,第二个参数菜品口味数组 18 | func SaveWithFlavorDish(dish *model.Dish, flavors *[]model.DishFlavor) *model.Dish { 19 | redis.RC.ClearCacheDishByCategoryId(strconv.FormatInt((*dish).CategoryID, 10)) 20 | db.DisDao.Save(dish) 21 | for _, v := range *flavors { 22 | v.DishID = dish.ID 23 | } 24 | db.DishFDao.InsertBatch(flavors) 25 | return dish 26 | } 27 | func PageQueryDish(categoryPage *dto.DishPageQueryDTO) *common.PageResult { 28 | var pageResult = common.PageResult{} 29 | pageResult.Records, pageResult.Total = db.DisDao.PageQuery(categoryPage) 30 | return &pageResult 31 | } 32 | func DeleteDish(ids *[]int64) *error { 33 | for i := 0; i < len(*ids); i++ { 34 | err := db.DisDao.GetById((*ids)[i]) 35 | //判断当前菜品是否能够删除---是否存在起售中的菜品?? 36 | if err.Status == status_c.ENABLE { 37 | //当前菜品处于起售中,不能删除 38 | hlog.Error(err) 39 | return nil 40 | } 41 | } 42 | //判断当前菜品是否能够删除---是否被套餐关联了?? 43 | nums := db.MealDishDao.GetSetmealIdsByDishIds(ids) 44 | if len(*nums) != 0 { 45 | //当前菜品被套餐关联了,不能删除 46 | hlog.Error(message_c.DISH_BE_RELATED_BY_SETMEAL) 47 | return nil 48 | } 49 | redis.RC.ClearCacheDishByCategoryId("*") 50 | //删除菜品表中的菜品数据 51 | for i := 0; i < len(*ids); i++ { 52 | db.DisDao.Delete((*ids)[i]) 53 | //删除菜品关联的口味数据 54 | db.DishFDao.DeleteByDishId((*ids)[i]) 55 | } 56 | return nil 57 | } 58 | func UpdateDish(dish *model.Dish) { 59 | redis.RC.ClearCacheDishByCategoryId("*") 60 | db.DisDao.Update(dish) 61 | } 62 | func StartOrStopDish(status int32, id int64, update_user int64) { 63 | cat := model.Dish{ 64 | ID: id, 65 | Status: status, 66 | UpdateUser: update_user, 67 | UpdateTime: time.Now(), 68 | } 69 | db.DisDao.UpdateStatus(&cat) 70 | } 71 | func ListDish(tp *int64) *[]model.Dish { 72 | d := model.Dish{ 73 | CategoryID: *tp, 74 | Status: status_c.ENABLE, 75 | } 76 | dl, err := db.DisDao.List(&d) 77 | if err != nil { 78 | hlog.Error(err) 79 | } 80 | return dl 81 | } 82 | func GetByIdWithFlavor(id int64) *vo.DishVO { 83 | dvo := &vo.DishVO{} 84 | //根据id查询菜品数据 85 | dish := db.DisDao.GetById(id) 86 | 87 | //根据菜品id查询口味数据 88 | dishFlavors := db.DishFDao.GetByDishId(id) 89 | dvo.ForDishAndFlavor(dish, dishFlavors) 90 | return dvo 91 | } 92 | 93 | // 条件查询菜品和口味 94 | func ListWithFlavorDish(d *model.Dish) *[]vo.DishVO { 95 | di, err := db.DisDao.List(d) 96 | di_l := len(*di) 97 | if err != nil { 98 | hlog.Error(err) 99 | } 100 | dvo := make([]vo.DishVO, 0, di_l) 101 | // 进行转换 102 | for i := 0; i < di_l; i++ { 103 | dish_f := db.DishFDao.GetByDishId((*di)[i].ID) 104 | dishVo := vo.Dish2DishVO(&(*di)[i]) 105 | dishVo.Flavors = dish_f 106 | dvo = append(dvo, *dishVo) 107 | } 108 | return &dvo 109 | } 110 | -------------------------------------------------------------------------------- /internal/router/service/employee_service.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | "reggie/internal/db" 5 | "reggie/internal/models/common" 6 | "reggie/internal/models/constant/status_c" 7 | "reggie/internal/models/dto" 8 | "reggie/internal/models/model" 9 | "time" 10 | ) 11 | 12 | // 添加成功返回true,添加失败返回flase 13 | func SaveEmp(emp *model.Employee) bool { 14 | //设置账号的状态,默认正常状态 1表示正常 0表示锁定 15 | emp.Status = status_c.ENABLE 16 | 17 | //设置密码,默认密码123456 18 | emp.Password = status_c.DEFAULT_PASSWORD 19 | 20 | //设置当前记录的创建时间和修改时间 21 | emp.CreateTime, emp.UpdateTime = time.Now(), time.Now() 22 | 23 | //设置当前记录创建人id和修改人id 24 | //emp.CreateUser, emp.UpdateUser = 1, 1 //目前是假数据,之后会继续完善 25 | // 判断是否用户是否重名 26 | if db.EmpDao.GetByUserName(emp.Username).Username == emp.Username { 27 | return false 28 | } 29 | db.EmpDao.Insert(emp) 30 | return true 31 | } 32 | func PageQueryEmp(page *dto.EmployeePageQueryDTO) *common.PageResult { 33 | var pageResult = common.PageResult{} 34 | 35 | pageResult.Records, pageResult.Total = db.EmpDao.PageQuery(page) 36 | 37 | return &pageResult 38 | } 39 | 40 | func StartOrStopEmp(status int32, id int64, update_user int64) { 41 | emp := model.Employee{ 42 | ID: id, 43 | Status: status, 44 | UpdateUser: update_user, 45 | UpdateTime: time.Now(), 46 | } 47 | db.EmpDao.UpdateStatus(&emp) 48 | } 49 | 50 | func GetByIdEmp(id int64) *model.Employee { 51 | return db.EmpDao.GetById(id) 52 | } 53 | 54 | func UpdateEmp(emp *model.Employee) { 55 | db.EmpDao.Update(emp) 56 | } 57 | -------------------------------------------------------------------------------- /internal/router/service/order_service.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | "errors" 5 | "github.com/jinzhu/copier" 6 | "reggie/internal/db" 7 | "reggie/internal/models/common" 8 | "reggie/internal/models/constant/message_c" 9 | "reggie/internal/models/dto" 10 | "reggie/internal/models/model" 11 | "reggie/internal/models/vo" 12 | "strconv" 13 | "time" 14 | ) 15 | 16 | func SubmitOrder(order *model.Order) (*vo.OrderSubmitVO, error) { 17 | //1. 处理各种业务异常(地址簿为空、购物车数据为空) 18 | addressBook := db.AddressDA0.GetById(order.AddressBookID) 19 | if addressBook == nil { 20 | return nil, errors.New(message_c.ADDRESS_BOOK_IS_NULL) 21 | } 22 | shoppingCart := model.ShoppingCart{ 23 | UserID: order.UserID, 24 | } 25 | shoppingCartList := db.ShopCartDao.List(&shoppingCart) 26 | list_len := len(*shoppingCartList) 27 | if list_len == 0 { 28 | return nil, errors.New(message_c.SHOPPING_CART_IS_NULL) 29 | } 30 | 31 | //2. 向订单表插入1条数据 32 | order.OrderTime = time.Now() 33 | order.PayStatus = model.UN_PAID 34 | order.Status = model.PENDING_PAYMENT 35 | order.Number = strconv.FormatInt(time.Now().UnixNano(), 10) 36 | order.Address = addressBook.Detail 37 | order.Phone = addressBook.Consignee 38 | //orders.setUserId(userId); 39 | 40 | db.OrderDao.Insert(order) 41 | orderDetailList := make([]model.OrderDetail, 0, list_len) 42 | //3. 向订单明细表插入n条数据 43 | for i := 0; i < list_len; i++ { 44 | //订单明细 45 | orderDetail := model.OrderDetail{} 46 | err := copier.Copy(&orderDetail, &(*shoppingCartList)[i]) 47 | if err != nil { 48 | return nil, errors.New("类型赋值错误") 49 | } 50 | orderDetail.OrderID = order.ID 51 | orderDetailList[i] = orderDetail 52 | } 53 | db.OrderDetailDao.InsertBatch(&orderDetailList) 54 | //4. 清空当前用户的购物车数据 55 | db.ShopCartDao.DeleteByUserId(order.UserID) 56 | //5. 封装VO返回结果 57 | orderSubmitVO := vo.OrderSubmitVO{} 58 | err := copier.Copy(&orderSubmitVO, &order) 59 | if err != nil { 60 | return nil, errors.New("类型赋值错误") 61 | } 62 | return &orderSubmitVO, nil 63 | } 64 | 65 | func PageQuery4UserOrder(page *dto.OrdersPageQueryDTO) (common.PageResult, error) { 66 | // 分页条件查询 67 | query, count, err := db.OrderDao.PageQuery(page) 68 | if err != nil { 69 | return common.PageResult{}, err 70 | } 71 | list := make([]vo.OrderVO, 0, 10) 72 | // 查询出订单明细,并封装入OrderVO进行响应 73 | l := len(*query) 74 | if l > 0 { 75 | for i := 0; i < l; i++ { 76 | orderDetails := db.OrderDetailDao.GetByOrderId((*query)[i].UserID) 77 | orderVO := vo.OrderVO{} 78 | copier.Copy(&orderVO, orderDetails) 79 | orderVO.OrderDetailList = orderDetails 80 | list[i] = orderVO 81 | } 82 | } 83 | 84 | return common.PageResult{count, list}, nil 85 | } 86 | func ConditionSearchOrder(oq *dto.OrdersPageQueryDTO) (common.PageResult, error) { 87 | // 分页条件查询 88 | query, count, err := db.OrderDao.PageQuery(oq) 89 | if err != nil { 90 | return common.PageResult{}, err 91 | } 92 | list := make([]vo.OrderVO, 0, 10) 93 | // 查询出订单明细,并封装入OrderVO进行响应 94 | l := len(*query) 95 | if l > 0 { 96 | for i := 0; i < l; i++ { 97 | orderDetails := db.OrderDetailDao.GetByOrderId((*query)[i].UserID) 98 | orderVO := vo.OrderVO{} 99 | copier.Copy(&orderVO, orderDetails) 100 | orderVO.OrderDetailList = orderDetails 101 | list[i] = orderVO 102 | } 103 | } 104 | return common.PageResult{count, list}, nil 105 | } 106 | -------------------------------------------------------------------------------- /internal/router/service/setmeal_service.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | "errors" 5 | "github.com/cloudwego/hertz/pkg/common/hlog" 6 | "reggie/internal/db" 7 | "reggie/internal/models/common" 8 | "reggie/internal/models/constant/message_c" 9 | "reggie/internal/models/constant/status_c" 10 | "reggie/internal/models/dto" 11 | "reggie/internal/models/model" 12 | "reggie/internal/models/vo" 13 | ) 14 | 15 | // 第一个参数菜品,第二个参数菜品口味数组 16 | func SaveSetMealWithDish(dish *model.Setmeal, flavors *[]model.SetmealDish) error { 17 | // 首先插入套餐表 18 | dh, err := db.MealDao.Insert(dish) 19 | if err != nil { 20 | hlog.Error(err) 21 | return nil 22 | } 23 | l := len(*flavors) 24 | for i := 0; i < l; i++ { 25 | // 添加套餐的id 26 | (*flavors)[i].SetmealID = dh.ID 27 | } 28 | // 插入套餐和菜品的关联表 29 | db.MealDishDao.InsertBatch(flavors) 30 | return nil 31 | } 32 | func PageQuerySetMeal(page *dto.SetmealPageQueryDTO) *common.PageResult { 33 | var pageResult = common.PageResult{} 34 | pageResult.Records, pageResult.Total = db.MealDao.PageQuery(page) 35 | return &pageResult 36 | } 37 | func DeleteBatchMeal(ids *[]int64) error { 38 | for i := 0; i < len(*ids); i++ { 39 | err := db.MealDao.GetByID((*ids)[i]) 40 | //判断当前菜品是否能够删除---是否存在起售中的菜品?? 41 | if err.Status == status_c.ENABLE { 42 | //起售中的套餐不能删除 43 | hlog.Error(err) 44 | return nil 45 | } 46 | } 47 | for _, v := range *ids { 48 | db.MealDao.DeleteByID(v) 49 | db.MealDishDao.DeleteBySetmealId(v) 50 | } 51 | return nil 52 | } 53 | func GetByIdWithDishMeal(id int64) (*vo.SetmealVO, error) { 54 | v, err := db.MealDao.GtByIdWithDish(id) 55 | if err != nil { 56 | hlog.Infof(err.Error()) 57 | return nil, err 58 | } 59 | return v, nil 60 | 61 | } 62 | func UpdateMeal(meal *model.Setmeal, dish *[]model.SetmealDish) { 63 | db.MealDao.Update(meal) 64 | db.MealDishDao.DeleteBySetmealId(meal.ID) 65 | id := meal.ID 66 | l := len(*dish) 67 | for i := 0; i < l; i++ { 68 | (*dish)[i].SetmealID = id 69 | } 70 | db.MealDishDao.InsertBatch(dish) 71 | } 72 | func StartOrStopMeal(status int32, id int64) error { 73 | //起售套餐时,判断套餐内是否有停售菜品,有停售菜品提示"套餐内包含未启售菜品,无法启售" 74 | if status == status_c.ENABLE { 75 | //select a.* from dish a left join setmeal_dish b on a.id = b.dish_id where b.setmeal_id = ? 76 | dishList := db.DisDao.GetBySetmealId(id) 77 | if dishList != nil && len(dishList) > 0 { 78 | for _, item := range dishList { 79 | if status_c.DISABLE == item.Status { 80 | return errors.New(message_c.SETMEAL_ENABLE_FAILED) 81 | } 82 | } 83 | } 84 | } 85 | setmeal := model.Setmeal{ID: id, Status: status} 86 | db.MealDao.Update(&setmeal) 87 | return nil 88 | } 89 | func ListSetmeal(meal *model.Setmeal) *[]model.Setmeal { 90 | return db.MealDao.List(meal) 91 | } 92 | -------------------------------------------------------------------------------- /internal/router/service/shop_service.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import "reggie/pkg/redis" 4 | 5 | func SetStatusShop(status *int) { 6 | redis.RC.SetStatus(status) 7 | } 8 | func GetStatusShop() *int { 9 | return redis.RC.GetStatus() 10 | } 11 | -------------------------------------------------------------------------------- /internal/router/service/shoppcart_service.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | "reggie/internal/db" 5 | "reggie/internal/models/model" 6 | "time" 7 | ) 8 | 9 | func AddShoppingCart(shoppingCart model.ShoppingCart) { 10 | //判断当前商品是否在购物车中 11 | shoppingCartList := db.ShopCartDao.List(&shoppingCart) 12 | if shoppingCartList != &[]model.ShoppingCart{} { 13 | shoppingCart := (*shoppingCartList)[0] 14 | shoppingCart.Number += 1 15 | (*shoppingCartList)[0] = shoppingCart 16 | db.ShopCartDao.UpdateNumberById(&shoppingCart) 17 | } else { 18 | //如果不存在,插入数据,数量就是1 19 | //判断当前添加到购物车的是菜品还是套餐 20 | dishId := shoppingCart.DishID 21 | if dishId != 0 { 22 | dish := db.DisDao.GetById(dishId) 23 | shoppingCart.Name = dish.Name 24 | shoppingCart.Image = dish.Image 25 | shoppingCart.Amount = dish.Price 26 | } else { 27 | setmealId := shoppingCart.SetmealID 28 | setmeal := db.MealDao.GetByID(setmealId) 29 | shoppingCart.Name = setmeal.Name 30 | shoppingCart.Image = setmeal.Image 31 | shoppingCart.Amount = setmeal.Price 32 | } 33 | shoppingCart.Number = 1 34 | shoppingCart.CreateTime = time.Now() 35 | db.ShopCartDao.Insert(&shoppingCart) 36 | } 37 | } 38 | func ShowShoppingCart(id int64) *[]model.ShoppingCart { 39 | shop_cart := model.ShoppingCart{} 40 | shop_cart.UserID = id 41 | return db.ShopCartDao.List(&shop_cart) 42 | } 43 | func CleanShoppingCart(userId int64) { 44 | db.ShopCartDao.DeleteByUserId(userId) 45 | } 46 | -------------------------------------------------------------------------------- /internal/router/service/user_service.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | "github.com/cloudwego/hertz/pkg/common/hlog" 5 | "reggie/internal/db" 6 | "reggie/internal/models/constant/message_c" 7 | "reggie/internal/models/dto" 8 | "reggie/internal/models/model" 9 | "reggie/pkg/wx" 10 | ) 11 | 12 | func WxLoginUser(userLoginDTO *dto.UserLoginDTO) *model.User { 13 | op_id := wx.WxClient.GetOpenid(&userLoginDTO.Code) 14 | if op_id == nil { 15 | hlog.Error(message_c.LOGIN_FAILED) 16 | } 17 | var us *model.User 18 | us = db.UserDao.GetByOpenid(op_id) 19 | // 查询不到,就字段添加新用户 20 | if us == nil { 21 | us = db.UserDao.Insert(userLoginDTO.ToNewUser()) 22 | } 23 | 24 | return us 25 | } 26 | -------------------------------------------------------------------------------- /internal/router/service/work_space_service.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | "reggie/internal/db" 5 | "reggie/internal/models/constant/status_c" 6 | "reggie/internal/models/vo" 7 | "time" 8 | ) 9 | 10 | func GetBusinessData(begin time.Time, end time.Time) vo.BusinessDataVO { 11 | /** 12 | * 营业额:当日已完成订单的总金额 13 | * 有效订单:当日已完成订单的数量 14 | * 订单完成率:有效订单数 / 总订单数 15 | * 平均客单价:营业额 / 有效订单数 16 | * 新增用户:当日新增用户的数量 17 | */ 18 | m := make(map[string]interface{}) 19 | m["begin"] = begin 20 | m["end"] = end 21 | //查询总订单数 22 | totalOrderCount := db.OrderDao.CountByMap(m) 23 | m["status"] = status_c.COMPLETED 24 | //营业额 25 | turnover := db.OrderDao.SumByMap(m) 26 | //有效订单数 27 | validOrderCount := db.OrderDao.CountByMap(m) 28 | 29 | unitPrice, orderCompletionRate := 0.0, 0.0 30 | 31 | if totalOrderCount != 0 && validOrderCount != 0 { 32 | //订单完成率 33 | orderCompletionRate = float64(validOrderCount) / float64(totalOrderCount) 34 | //平均客单价 35 | unitPrice = turnover / float64(validOrderCount) 36 | } 37 | //新增用户数 38 | newUsers := db.UserDao.CountByMap(m) 39 | return vo.BusinessDataVO{ 40 | Turnover: turnover, 41 | ValidOrderCount: validOrderCount, 42 | OrderCompletionRate: orderCompletionRate, 43 | UnitPrice: unitPrice, 44 | NewUsers: newUsers, 45 | } 46 | } 47 | func GetOrderOverView() vo.OrderOverViewVO { 48 | now := time.Now() 49 | begin := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location()) 50 | m := make(map[string]interface{}) 51 | m["begin"] = begin 52 | m["status"] = status_c.TO_BE_CONFIRMED 53 | //待接单 54 | waitingOrders := db.OrderDao.CountByMap(m) 55 | //待派送 56 | m["status"] = status_c.CONFIRMED 57 | deliveredOrders := db.OrderDao.CountByMap(m) 58 | 59 | //已完成 60 | m["status"] = status_c.COMPLETED 61 | completedOrders := db.OrderDao.CountByMap(m) 62 | 63 | //已取消 64 | m["status"] = status_c.CANCELLED 65 | cancelledOrders := db.OrderDao.CountByMap(m) 66 | 67 | //全部订单 68 | m["status"] = nil 69 | allOrders := db.OrderDao.CountByMap(m) 70 | return vo.OrderOverViewVO{ 71 | WaitingOrders: waitingOrders, 72 | DeliveredOrders: deliveredOrders, 73 | CompletedOrders: completedOrders, 74 | CancelledOrders: cancelledOrders, 75 | AllOrders: allOrders, 76 | } 77 | } 78 | func GetDishOverView() vo.DishOverViewVO { 79 | m := make(map[string]interface{}) 80 | m["status"] = status_c.ENABLE 81 | sold := db.OrderDao.CountByMap(m) 82 | 83 | m["status"] = status_c.DISABLE 84 | discontinued := db.OrderDao.CountByMap(m) 85 | 86 | return vo.DishOverViewVO{ 87 | Sold: sold, 88 | Discontinued: discontinued, 89 | } 90 | } 91 | func GetSetmealOverView() vo.SetmealOverViewVO { 92 | m := make(map[string]interface{}) 93 | m["status"] = status_c.ENABLE 94 | sold := db.OrderDao.CountByMap(m) 95 | 96 | m["status"] = status_c.DISABLE 97 | discontinued := db.OrderDao.CountByMap(m) 98 | 99 | return vo.SetmealOverViewVO{ 100 | Sold: sold, 101 | Discontinued: discontinued, 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /internal/router/user/address_router.go: -------------------------------------------------------------------------------- 1 | package user 2 | 3 | import ( 4 | "context" 5 | "github.com/cloudwego/hertz/pkg/app" 6 | "github.com/cloudwego/hertz/pkg/common/hlog" 7 | "net/http" 8 | "reggie/internal/middleware" 9 | "reggie/internal/models/common" 10 | "reggie/internal/models/constant/message_c" 11 | "reggie/internal/models/model" 12 | "reggie/internal/router/service" 13 | "strconv" 14 | ) 15 | 16 | // 查询当前登录用户的所有地址信息 17 | // 18 | // list 19 | func ListAddress(ctx context.Context, c *app.RequestContext) { 20 | address := model.AddressBook{} 21 | address.UserID = middleware.GetJwtPayload(c) 22 | list := service.ListAddress(&address) 23 | c.JSON(http.StatusOK, common.Result{1, "", list}) 24 | } 25 | 26 | // 根据id查询地址 27 | func SaveAddress(ctx context.Context, c *app.RequestContext) { 28 | address := model.AddressBook{} 29 | c.Bind(&address) 30 | address.UserID = middleware.GetJwtPayload(c) 31 | service.SaveAddress(&address) 32 | c.JSON(http.StatusOK, common.Result{1, "", nil}) 33 | } 34 | 35 | // @GetMapping("/{id}") 36 | func GetByIdAddress(ctx context.Context, c *app.RequestContext) { 37 | id := c.Param("id") 38 | hlog.Infof("根据id查询地址:", id) 39 | id_r, _ := strconv.ParseInt(id, 10, 64) 40 | v, err := service.GetByIdAddress(id_r) 41 | if err != nil { 42 | c.JSON(http.StatusNotFound, common.Result{0, message_c.UNKNOWN_ERROR, nil}) 43 | } else { 44 | c.JSON(http.StatusOK, common.Result{1, "", v}) 45 | } 46 | } 47 | 48 | // 根据id修改地址 49 | func UpdateAddress(ctx context.Context, c *app.RequestContext) { 50 | address := model.AddressBook{} 51 | c.Bind(&address) 52 | address.UserID = middleware.GetJwtPayload(c) 53 | service.UpdateAddress(&address) 54 | c.JSON(http.StatusOK, common.Result{1, "", nil}) 55 | } 56 | 57 | // 设置默认地址 58 | func SetDefaultAddress(ctx context.Context, c *app.RequestContext) { 59 | address := model.AddressBook{} 60 | c.Bind(&address) 61 | address.UserID = middleware.GetJwtPayload(c) 62 | service.SetDefaultAddress(&address) 63 | c.JSON(http.StatusOK, common.Result{1, "", nil}) 64 | } 65 | 66 | // 根据id删除地址 67 | func DeleteByIdAddress(ctx context.Context, c *app.RequestContext) { 68 | id := c.Query("id") 69 | hlog.Infof("根据id查询地址:", id) 70 | id_r, _ := strconv.ParseInt(id, 10, 64) 71 | service.DeleteByIdAddress(id_r) 72 | c.JSON(http.StatusOK, common.Result{1, "", nil}) 73 | } 74 | 75 | // 查询默认地址 76 | 77 | // @GetMapping("default") 78 | // @ApiOperation("查询默认地址") 79 | func GetDefaultAddress(ctx context.Context, c *app.RequestContext) { 80 | address := model.AddressBook{} 81 | address.UserID = middleware.GetJwtPayload(c) 82 | address.IsDefault = true 83 | list := service.ListAddress(&address) 84 | if len(*list) == 1 { 85 | c.JSON(http.StatusOK, common.Result{1, "", (*list)[0]}) 86 | } else { 87 | c.JSON(http.StatusNotFound, common.Result{1, "没有查询到默认地址", nil}) 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /internal/router/user/category_router.go: -------------------------------------------------------------------------------- 1 | package user 2 | 3 | import ( 4 | "context" 5 | "github.com/cloudwego/hertz/pkg/app" 6 | "log" 7 | "net/http" 8 | "reggie/internal/models/common" 9 | "reggie/internal/router/service" 10 | "strconv" 11 | ) 12 | 13 | // 分类查询 14 | func ListCategory(ctx context.Context, c *app.RequestContext) { 15 | ty_pe := c.Query("type") 16 | log.Printf("按照类型查询菜品:{%s}", ty_pe) 17 | tp, _ := strconv.ParseInt(ty_pe, 10, 64) 18 | dish := service.ListCat(&tp) 19 | c.JSON(http.StatusOK, common.Result{1, "", dish}) 20 | } 21 | -------------------------------------------------------------------------------- /internal/router/user/dish_router.go: -------------------------------------------------------------------------------- 1 | package user 2 | 3 | import ( 4 | "context" 5 | "github.com/cloudwego/hertz/pkg/app" 6 | "log" 7 | "net/http" 8 | "reggie/internal/models/common" 9 | "reggie/internal/models/constant/status_c" 10 | "reggie/internal/models/model" 11 | "reggie/internal/router/service" 12 | "reggie/pkg/redis" 13 | "strconv" 14 | ) 15 | 16 | // 根据id查询菜品 17 | func ListDish(ctx context.Context, c *app.RequestContext) { 18 | c_id := c.Query("categoryId") 19 | log.Printf("按照类型查询菜品:{%s}", c_id) 20 | id, _ := strconv.ParseInt(c_id, 10, 64) 21 | //查询redis中是否存在菜品数据 22 | list, err := redis.RC.GetListDishVO(c_id) 23 | // redis有数据直接返回 24 | if err == nil { 25 | c.JSON(http.StatusOK, common.Result{1, "", list}) 26 | } 27 | // 无数据查询数据库 28 | d := model.Dish{ 29 | CategoryID: id, 30 | Status: status_c.ENABLE, 31 | } 32 | //如果不存在,查询数据库,将查询到的数据放入redis中 33 | list = service.ListWithFlavorDish(&d) 34 | ////////////////////////////////////////////////////////// 35 | err = redis.RC.SetListDishVO(c_id, list) 36 | if err != nil { 37 | c.JSON(http.StatusOK, common.Result{0, "", list}) 38 | } 39 | c.JSON(http.StatusOK, common.Result{1, "", list}) 40 | 41 | } 42 | -------------------------------------------------------------------------------- /internal/router/user/order_router.go: -------------------------------------------------------------------------------- 1 | package user 2 | 3 | import ( 4 | "context" 5 | "github.com/cloudwego/hertz/pkg/app" 6 | "net/http" 7 | "reggie/internal/middleware" 8 | "reggie/internal/models/common" 9 | "reggie/internal/models/dto" 10 | "reggie/internal/models/model" 11 | "reggie/internal/router/service" 12 | ) 13 | 14 | func SubmitOrders(ctx context.Context, c *app.RequestContext) { 15 | var order model.Order 16 | c.Bind(&order) 17 | order.UserID = middleware.GetJwtPayload(c) 18 | service.SubmitOrder(&order) 19 | c.JSON(http.StatusOK, common.Result{1, "", nil}) 20 | } 21 | func PageOrders(ctx context.Context, c *app.RequestContext) { 22 | var page dto.OrderPageQueryDTO 23 | c.Bind(&page) 24 | page.UserId = middleware.GetJwtPayload(c) 25 | service.PageQuery4UserOrder(&page) 26 | } 27 | func DetailsOrders(ctx context.Context, c *app.RequestContext) { 28 | 29 | } 30 | func CancelOrders(ctx context.Context, c *app.RequestContext) { 31 | 32 | } 33 | -------------------------------------------------------------------------------- /internal/router/user/setmeal_router.go: -------------------------------------------------------------------------------- 1 | package user 2 | 3 | import ( 4 | "context" 5 | "github.com/cloudwego/hertz/pkg/app" 6 | "log" 7 | "net/http" 8 | "reggie/internal/models/common" 9 | "reggie/internal/models/constant/status_c" 10 | "reggie/internal/models/model" 11 | "reggie/internal/router/service" 12 | "strconv" 13 | ) 14 | 15 | // 条件查询 16 | func ListSetmeal(ctx context.Context, c *app.RequestContext) { 17 | ty_pe := c.Query("categoryId") 18 | log.Printf("按照类型查询菜品:{%s}", ty_pe) 19 | tp, _ := strconv.ParseInt(ty_pe, 10, 64) 20 | meal := model.Setmeal{ 21 | CategoryID: tp, 22 | Status: status_c.ENABLE, 23 | } 24 | new_meal := service.ListSetmeal(&meal) 25 | c.JSON(http.StatusOK, common.Result{1, "", new_meal}) 26 | } 27 | 28 | // 根据套餐id查询包含的菜品列表 29 | func DishListSetmeal(ctx context.Context, c *app.RequestContext) { 30 | id_s := c.Param("id") 31 | log.Printf("根据套餐id查询包含的菜品列表:{%s}", id_s) 32 | id, _ := strconv.ParseInt(id_s, 10, 64) 33 | meal, err := service.GetByIdWithDishMeal(id) 34 | if err != nil { 35 | c.JSON(http.StatusOK, common.Result{1, "", nil}) 36 | } 37 | c.JSON(http.StatusOK, common.Result{1, "", meal}) 38 | 39 | } 40 | -------------------------------------------------------------------------------- /internal/router/user/shoopingcart_router.go: -------------------------------------------------------------------------------- 1 | package user 2 | 3 | import ( 4 | "context" 5 | "github.com/cloudwego/hertz/pkg/app" 6 | "github.com/cloudwego/hertz/pkg/common/hlog" 7 | "net/http" 8 | "reggie/internal/middleware" 9 | "reggie/internal/models/common" 10 | "reggie/internal/models/dto" 11 | "reggie/internal/router/service" 12 | ) 13 | 14 | // 添加购物车 15 | // /user/shoppingCart/add 16 | func AddShoppingCart(ctx context.Context, c *app.RequestContext) { 17 | var shop_dto dto.ShoppingCartDTO 18 | c.Bind(&shop_dto) 19 | shop_cart := shop_dto.ToShoppingCart() 20 | shop_cart.UserID = middleware.GetJwtPayload(c) 21 | hlog.Infof("添加购物车:", shop_cart) 22 | service.AddShoppingCart(shop_cart) 23 | c.JSON(http.StatusOK, common.Result{1, "", nil}) 24 | } 25 | func ListShoppingCart(ctx context.Context, c *app.RequestContext) { 26 | // user 27 | user_id := middleware.GetJwtPayload(c) 28 | c.JSON(http.StatusOK, common.Result{1, "", service.ShowShoppingCart(user_id)}) 29 | } 30 | 31 | // 清空购物车 32 | func CleanShoppingCart(ctx context.Context, c *app.RequestContext) { 33 | user_id := middleware.GetJwtPayload(c) 34 | // 获取user_id 35 | service.CleanShoppingCart(user_id) 36 | c.JSON(http.StatusOK, common.Result{1, "", nil}) 37 | } 38 | -------------------------------------------------------------------------------- /internal/router/user/user_router.go: -------------------------------------------------------------------------------- 1 | package user 2 | 3 | func tt() { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /internal/utils/str.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import "unsafe" 4 | 5 | func String2Bytes(s string) []byte { 6 | return *(*[]byte)(unsafe.Pointer(&s)) 7 | } 8 | func Bytes2String(b []byte) string { 9 | return *(*string)(unsafe.Pointer(&b)) 10 | } 11 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/cloudwego/hertz/pkg/app/middlewares/server/recovery" 5 | "github.com/cloudwego/hertz/pkg/app/server" 6 | _ "reggie/docs" 7 | "reggie/internal/config" 8 | "reggie/internal/db" 9 | "reggie/internal/router" 10 | ) 11 | 12 | func init() { 13 | config.InitConfig() 14 | db.InitDB() 15 | } 16 | 17 | // @title regiee 18 | // @version 0.1 19 | // @description sky-take-out 20 | 21 | // @contact.name onenewcode 22 | // @contact.url https://github.com/onenewcode 23 | 24 | // @license.name Apache 2.0 25 | // @license.url http://www.apache.org/licenses/LICENSE-2.0.html 26 | 27 | // @host localhost:8080 28 | // @BasePath / 29 | // @schemes http 30 | func main() { 31 | h := server.New( 32 | server.WithHostPorts(config.ServerSetting.HttpPort), 33 | server.WithReadTimeout(config.ServerSetting.ReadTimeout), 34 | server.WithWriteTimeout(config.ServerSetting.WriteTimeout), 35 | ) 36 | router.InitRouter(h) 37 | h.Use(recovery.Recovery()) // 可确保即使在处理请求过程中发生未预期的错误或异常,服务也能维持运行状态 38 | h.Spin() //可以实现优雅的推出 39 | } 40 | -------------------------------------------------------------------------------- /pkg/obs/acl.go: -------------------------------------------------------------------------------- 1 | package obs 2 | 3 | import ( 4 | "github.com/google/uuid" 5 | "github.com/minio/minio-go" 6 | "log" 7 | "mime/multipart" 8 | "path" 9 | "strings" 10 | "time" 11 | ) 12 | 13 | type OBSClient interface { 14 | UploadImg(fh *multipart.FileHeader) *string 15 | } 16 | 17 | /* 18 | 实现类 19 | */ 20 | type MyMinio struct { 21 | } 22 | 23 | func (*MyMinio) UploadImg(fh *multipart.FileHeader) *string { 24 | var str strings.Builder 25 | str.WriteString(time.Now().Format("2006/01/02/")) 26 | // 生成一个新的UUIDv4 27 | id := uuid.New() 28 | str.WriteString(id.String()) 29 | str.WriteString(path.Ext(fh.Filename)) 30 | // 构建文件在Minio的存储路径 31 | filepath := str.String() 32 | // 获取文件的读取流 33 | file_body, _ := fh.Open() 34 | _, err := minioClient.PutObject(bucketName, filepath, file_body, fh.Size, minio.PutObjectOptions{ 35 | ContentType: fh.Header.Get("Content-Type"), 36 | }) 37 | // 拼接返回路径 38 | filepath = "http://" + path.Join(endpoint, bucketName, filepath) 39 | if err != nil { 40 | log.Fatalln(err) 41 | return nil 42 | } 43 | return &filepath 44 | 45 | } 46 | -------------------------------------------------------------------------------- /pkg/obs/config.go: -------------------------------------------------------------------------------- 1 | package obs 2 | 3 | import ( 4 | "github.com/minio/minio-go" 5 | "log" 6 | ) 7 | 8 | var ( 9 | minioClient *minio.Client 10 | OBS OBSClient 11 | ) 12 | 13 | const ( 14 | endpoint = "121.37.143.160:9000" //兼容对象存储服务endpoint,也可以设置自己的服务器地址 15 | accessKeyID = "minioadmin" // 对象存储的Access key 16 | secretAccessKey = "minioadmin" /// 对象存储的Secret key 17 | ssl = false //true代表使用HTTPS 18 | bucketName = "sky-take-out" // 设置同名称 19 | ) 20 | 21 | func init() { 22 | // 初使化minio client对象。 23 | mc, err := minio.New(endpoint, accessKeyID, secretAccessKey, ssl) 24 | if err != nil { 25 | log.Println(err) 26 | } else { 27 | minioClient = mc 28 | } 29 | OBS = &MyMinio{} 30 | } 31 | -------------------------------------------------------------------------------- /pkg/redis/acl.go: -------------------------------------------------------------------------------- 1 | package redis 2 | 3 | import ( 4 | "context" 5 | "encoding/json" 6 | "github.com/cloudwego/hertz/pkg/common/hlog" 7 | "reggie/internal/models/vo" 8 | ) 9 | 10 | const ( 11 | dish_vo = "dishVo:" 12 | ) 13 | 14 | type RedisClient interface { 15 | SetStatus(status *int) 16 | GetStatus() *int 17 | GetListDishVO(categoryId string) (*[]vo.DishVO, error) 18 | SetListDishVO(categoryId string, dvo *[]vo.DishVO) error 19 | ClearCacheDishByCategoryId(categoryId string) 20 | } 21 | type redisClient struct { 22 | } 23 | 24 | func (*redisClient) SetStatus(status *int) { 25 | rc.Set( 26 | context.Background(), 27 | shop_key, 28 | status, 29 | 0, 30 | ) 31 | } 32 | func (*redisClient) GetStatus() *int { 33 | val, _ := rc.Get(context.Background(), shop_key).Int() 34 | return &val 35 | } 36 | 37 | // 获取失败直接返回nil 38 | func (*redisClient) GetListDishVO(categoryId string) (*[]vo.DishVO, error) { 39 | var dvo []vo.DishVO 40 | b, err := rc.Get(context.Background(), dish_vo+categoryId).Bytes() 41 | if err != nil { 42 | return nil, err 43 | } 44 | if err = json.Unmarshal(b, &dvo); err != nil { 45 | hlog.Error("redis 解析ListDishVO失败") 46 | return nil, err 47 | } 48 | return &dvo, nil 49 | } 50 | func (*redisClient) SetListDishVO(categoryId string, dvo *[]vo.DishVO) error { 51 | b, err := json.Marshal(dvo) 52 | if err != nil { 53 | hlog.Error("redis 编码ListDishVO失败") 54 | return err 55 | } 56 | err = rc.Set(context.Background(), dish_vo+categoryId, b, 0).Err() 57 | if err != nil { 58 | return err 59 | } 60 | return nil 61 | } 62 | func (*redisClient) ClearCacheDishByCategoryId(categoryId string) { 63 | rc.Del(context.Background(), dish_vo+categoryId) 64 | } 65 | -------------------------------------------------------------------------------- /pkg/redis/config.go: -------------------------------------------------------------------------------- 1 | package redis 2 | 3 | import "github.com/redis/go-redis/v9" 4 | 5 | var ( 6 | rc *redis.Client 7 | RC RedisClient 8 | ) 9 | 10 | const ( 11 | addr = "121.37.143.160:6379" 12 | pass_word = "" 13 | db = 0 14 | shop_key = "SHOP_STATUS" 15 | ) 16 | 17 | func init() { 18 | rdb := redis.NewClient(&redis.Options{ 19 | Addr: addr, 20 | Password: pass_word, // 没有密码,默认值 21 | DB: db, // 默认DB 0 22 | }) 23 | rc = rdb 24 | RC = &redisClient{} 25 | } 26 | -------------------------------------------------------------------------------- /pkg/wx/acl.go: -------------------------------------------------------------------------------- 1 | package wx 2 | 3 | import ( 4 | "encoding/json" 5 | "io" 6 | "net/http" 7 | "net/url" 8 | "reggie/internal/models/dto" 9 | ) 10 | 11 | type wxInterface interface { 12 | GetOpenid(code *string) *string 13 | } 14 | type wxClient struct { 15 | } 16 | 17 | // 获取opendid, 18 | func (*wxClient) GetOpenid(code *string) *string { 19 | params := url.Values{} 20 | params.Add("appid", app_id) 21 | params.Add("secret", secret) 22 | params.Add("js_code", *code) 23 | params.Add("grant_type", "authorization_code") 24 | 25 | // 构建完整的URL 26 | fullURL := wx_login + params.Encode() 27 | 28 | resp, err := http.Get(fullURL) 29 | if err != nil { 30 | panic(err) 31 | } 32 | defer resp.Body.Close() 33 | 34 | body, err := io.ReadAll(resp.Body) 35 | if err != nil { 36 | panic(err) 37 | } 38 | var wxl dto.WXLoginDto 39 | json.Unmarshal(body, &wxl) 40 | 41 | return &wxl.OpenID 42 | } 43 | -------------------------------------------------------------------------------- /pkg/wx/config.go: -------------------------------------------------------------------------------- 1 | package wx 2 | 3 | const ( 4 | wx_login = "https://api.weixin.qq.com/sns/jscode2session?" 5 | app_id = "wx7c324ecaed51956d" 6 | secret = "75654f62622687f1ef7a484a1d96d614" 7 | ) 8 | 9 | var ( 10 | WxClient wxInterface 11 | ) 12 | 13 | func init() { 14 | WxClient = &wxClient{} 15 | } 16 | -------------------------------------------------------------------------------- /sql/gen.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "gorm.io/driver/mysql" 5 | "gorm.io/gen" 6 | "gorm.io/gorm" 7 | ) 8 | 9 | // 根据数据库生成表结构 10 | func main() { 11 | g := gen.NewGenerator(gen.Config{ 12 | // 设置输出路径 13 | OutPath: "./dal/query", 14 | Mode: gen.WithDefaultQuery, 15 | // 模型结构体字段的数字类型的符号表示是否与表字段的一致, `false`指示都用有符号类型 16 | FieldSignable: false, // detect integer field's unsigned type, adjust generated data type 17 | // 生成 gorm 标签的字段索引属性 18 | FieldWithIndexTag: false, // generate with gorm index tag 19 | // 生成 gorm 标签的字段类型属性 20 | FieldWithTypeTag: true, // generate with gorm column type tag 21 | }) 22 | // 建立数据库连接 23 | gormdb, _ := gorm.Open(mysql.Open("root:root@(121.37.143.160:3306)/dish?charset=utf8mb4&parseTime=True&loc=Local")) 24 | g.UseDB(gormdb) // 选择数据库连接 25 | g.ApplyBasic( 26 | // 从当前数据库的所有表生成结构 27 | g.GenerateAllTable()..., 28 | ) 29 | // 生成代码 30 | g.Execute() 31 | } 32 | -------------------------------------------------------------------------------- /sql/sky.sql: -------------------------------------------------------------------------------- 1 | CREATE DATABASE IF NOT EXISTS `sky_take_out` ; 2 | USE `sky_take_out`; 3 | 4 | DROP TABLE IF EXISTS `address_book`; 5 | CREATE TABLE `address_book` ( 6 | `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键', 7 | `user_id` bigint NOT NULL COMMENT '用户id', 8 | `consignee` varchar(50) COLLATE utf8_bin DEFAULT NULL COMMENT '收货人', 9 | `sex` varchar(2) COLLATE utf8_bin DEFAULT NULL COMMENT '性别', 10 | `phone` varchar(11) COLLATE utf8_bin NOT NULL COMMENT '手机号', 11 | `province_code` varchar(12) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '省级区划编号', 12 | `province_name` varchar(32) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '省级名称', 13 | `city_code` varchar(12) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '市级区划编号', 14 | `city_name` varchar(32) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '市级名称', 15 | `district_code` varchar(12) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '区级区划编号', 16 | `district_name` varchar(32) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '区级名称', 17 | `detail` varchar(200) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '详细地址', 18 | `label` varchar(100) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '标签', 19 | `is_default` tinyint(1) NOT NULL DEFAULT '0' COMMENT '默认 0 否 1是', 20 | PRIMARY KEY (`id`) 21 | ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb3 COLLATE=utf8_bin COMMENT='地址簿'; 22 | 23 | DROP TABLE IF EXISTS `category`; 24 | CREATE TABLE `category` ( 25 | `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键', 26 | `type` int DEFAULT NULL COMMENT '类型 1 菜品分类 2 套餐分类', 27 | `name` varchar(32) COLLATE utf8_bin NOT NULL COMMENT '分类名称', 28 | `sort` int NOT NULL DEFAULT '0' COMMENT '顺序', 29 | `status` int DEFAULT NULL COMMENT '分类状态 0:禁用,1:启用', 30 | `create_time` datetime DEFAULT NULL COMMENT '创建时间', 31 | `update_time` datetime DEFAULT NULL COMMENT '更新时间', 32 | `create_user` bigint DEFAULT NULL COMMENT '创建人', 33 | `update_user` bigint DEFAULT NULL COMMENT '修改人', 34 | PRIMARY KEY (`id`), 35 | UNIQUE KEY `idx_category_name` (`name`) 36 | ) ENGINE=InnoDB AUTO_INCREMENT=23 DEFAULT CHARSET=utf8mb3 COLLATE=utf8_bin COMMENT='菜品及套餐分类'; 37 | 38 | INSERT INTO `category` VALUES (11,1,'酒水饮料',10,1,'2022-06-09 22:09:18','2022-06-09 22:09:18',1,1); 39 | INSERT INTO `category` VALUES (12,1,'传统主食',9,1,'2022-06-09 22:09:32','2022-06-09 22:18:53',1,1); 40 | INSERT INTO `category` VALUES (13,2,'人气套餐',12,1,'2022-06-09 22:11:38','2022-06-10 11:04:40',1,1); 41 | INSERT INTO `category` VALUES (15,2,'商务套餐',13,1,'2022-06-09 22:14:10','2022-06-10 11:04:48',1,1); 42 | INSERT INTO `category` VALUES (16,1,'蜀味烤鱼',4,1,'2022-06-09 22:15:37','2022-08-31 14:27:25',1,1); 43 | INSERT INTO `category` VALUES (17,1,'蜀味牛蛙',5,1,'2022-06-09 22:16:14','2022-08-31 14:39:44',1,1); 44 | INSERT INTO `category` VALUES (18,1,'特色蒸菜',6,1,'2022-06-09 22:17:42','2022-06-09 22:17:42',1,1); 45 | INSERT INTO `category` VALUES (19,1,'新鲜时蔬',7,1,'2022-06-09 22:18:12','2022-06-09 22:18:28',1,1); 46 | INSERT INTO `category` VALUES (20,1,'水煮鱼',8,1,'2022-06-09 22:22:29','2022-06-09 22:23:45',1,1); 47 | INSERT INTO `category` VALUES (21,1,'汤类',11,1,'2022-06-10 10:51:47','2022-06-10 10:51:47',1,1); 48 | 49 | DROP TABLE IF EXISTS `dish`; 50 | CREATE TABLE `dish` ( 51 | `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键', 52 | `name` varchar(32) COLLATE utf8_bin NOT NULL COMMENT '菜品名称', 53 | `category_id` bigint NOT NULL COMMENT '菜品分类id', 54 | `price` decimal(10,2) DEFAULT NULL COMMENT '菜品价格', 55 | `image` varchar(255) COLLATE utf8_bin DEFAULT NULL COMMENT '图片', 56 | `description` varchar(255) COLLATE utf8_bin DEFAULT NULL COMMENT '描述信息', 57 | `status` int DEFAULT '1' COMMENT '0 停售 1 起售', 58 | `create_time` datetime DEFAULT NULL COMMENT '创建时间', 59 | `update_time` datetime DEFAULT NULL COMMENT '更新时间', 60 | `create_user` bigint DEFAULT NULL COMMENT '创建人', 61 | `update_user` bigint DEFAULT NULL COMMENT '修改人', 62 | PRIMARY KEY (`id`), 63 | UNIQUE KEY `idx_dish_name` (`name`) 64 | ) ENGINE=InnoDB AUTO_INCREMENT=70 DEFAULT CHARSET=utf8mb3 COLLATE=utf8_bin COMMENT='菜品'; 65 | 66 | INSERT INTO `dish` VALUES (46,'王老吉',11,6.00,'https://sky-itcast.oss-cn-beijing.aliyuncs.com/41bfcacf-7ad4-4927-8b26-df366553a94c.png','',1,'2022-06-09 22:40:47','2022-06-09 22:40:47',1,1); 67 | INSERT INTO `dish` VALUES (47,'北冰洋',11,4.00,'https://sky-itcast.oss-cn-beijing.aliyuncs.com/4451d4be-89a2-4939-9c69-3a87151cb979.png','还是小时候的味道',1,'2022-06-10 09:18:49','2022-06-10 09:18:49',1,1); 68 | INSERT INTO `dish` VALUES (48,'雪花啤酒',11,4.00,'https://sky-itcast.oss-cn-beijing.aliyuncs.com/bf8cbfc1-04d2-40e8-9826-061ee41ab87c.png','',1,'2022-06-10 09:22:54','2022-06-10 09:22:54',1,1); 69 | INSERT INTO `dish` VALUES (49,'米饭',12,2.00,'https://sky-itcast.oss-cn-beijing.aliyuncs.com/76752350-2121-44d2-b477-10791c23a8ec.png','精选五常大米',1,'2022-06-10 09:30:17','2022-06-10 09:30:17',1,1); 70 | INSERT INTO `dish` VALUES (50,'馒头',12,1.00,'https://sky-itcast.oss-cn-beijing.aliyuncs.com/475cc599-8661-4899-8f9e-121dd8ef7d02.png','优质面粉',1,'2022-06-10 09:34:28','2022-06-10 09:34:28',1,1); 71 | INSERT INTO `dish` VALUES (51,'老坛酸菜鱼',20,56.00,'https://sky-itcast.oss-cn-beijing.aliyuncs.com/4a9cefba-6a74-467e-9fde-6e687ea725d7.png','原料:汤,草鱼,酸菜',1,'2022-06-10 09:40:51','2022-06-10 09:40:51',1,1); 72 | INSERT INTO `dish` VALUES (52,'经典酸菜鮰鱼',20,66.00,'https://sky-itcast.oss-cn-beijing.aliyuncs.com/5260ff39-986c-4a97-8850-2ec8c7583efc.png','原料:酸菜,江团,鮰鱼',1,'2022-06-10 09:46:02','2022-06-10 09:46:02',1,1); 73 | INSERT INTO `dish` VALUES (53,'蜀味水煮草鱼',20,38.00,'https://sky-itcast.oss-cn-beijing.aliyuncs.com/a6953d5a-4c18-4b30-9319-4926ee77261f.png','原料:草鱼,汤',1,'2022-06-10 09:48:37','2022-06-10 09:48:37',1,1); 74 | INSERT INTO `dish` VALUES (54,'清炒小油菜',19,18.00,'https://sky-itcast.oss-cn-beijing.aliyuncs.com/3613d38e-5614-41c2-90ed-ff175bf50716.png','原料:小油菜',1,'2022-06-10 09:51:46','2022-06-10 09:51:46',1,1); 75 | INSERT INTO `dish` VALUES (55,'蒜蓉娃娃菜',19,18.00,'https://sky-itcast.oss-cn-beijing.aliyuncs.com/4879ed66-3860-4b28-ba14-306ac025fdec.png','原料:蒜,娃娃菜',1,'2022-06-10 09:53:37','2022-06-10 09:53:37',1,1); 76 | INSERT INTO `dish` VALUES (56,'清炒西兰花',19,18.00,'https://sky-itcast.oss-cn-beijing.aliyuncs.com/e9ec4ba4-4b22-4fc8-9be0-4946e6aeb937.png','原料:西兰花',1,'2022-06-10 09:55:44','2022-06-10 09:55:44',1,1); 77 | INSERT INTO `dish` VALUES (57,'炝炒圆白菜',19,18.00,'https://sky-itcast.oss-cn-beijing.aliyuncs.com/22f59feb-0d44-430e-a6cd-6a49f27453ca.png','原料:圆白菜',1,'2022-06-10 09:58:35','2022-06-10 09:58:35',1,1); 78 | INSERT INTO `dish` VALUES (58,'清蒸鲈鱼',18,98.00,'https://sky-itcast.oss-cn-beijing.aliyuncs.com/c18b5c67-3b71-466c-a75a-e63c6449f21c.png','原料:鲈鱼',1,'2022-06-10 10:12:28','2022-06-10 10:12:28',1,1); 79 | INSERT INTO `dish` VALUES (59,'东坡肘子',18,138.00,'https://sky-itcast.oss-cn-beijing.aliyuncs.com/a80a4b8c-c93e-4f43-ac8a-856b0d5cc451.png','原料:猪肘棒',1,'2022-06-10 10:24:03','2022-06-10 10:24:03',1,1); 80 | INSERT INTO `dish` VALUES (60,'梅菜扣肉',18,58.00,'https://sky-itcast.oss-cn-beijing.aliyuncs.com/6080b118-e30a-4577-aab4-45042e3f88be.png','原料:猪肉,梅菜',1,'2022-06-10 10:26:03','2022-06-10 10:26:03',1,1); 81 | INSERT INTO `dish` VALUES (61,'剁椒鱼头',18,66.00,'https://sky-itcast.oss-cn-beijing.aliyuncs.com/13da832f-ef2c-484d-8370-5934a1045a06.png','原料:鲢鱼,剁椒',1,'2022-06-10 10:28:54','2022-06-10 10:28:54',1,1); 82 | INSERT INTO `dish` VALUES (62,'金汤酸菜牛蛙',17,88.00,'https://sky-itcast.oss-cn-beijing.aliyuncs.com/7694a5d8-7938-4e9d-8b9e-2075983a2e38.png','原料:鲜活牛蛙,酸菜',1,'2022-06-10 10:33:05','2022-06-10 10:33:05',1,1); 83 | INSERT INTO `dish` VALUES (63,'香锅牛蛙',17,88.00,'https://sky-itcast.oss-cn-beijing.aliyuncs.com/f5ac8455-4793-450c-97ba-173795c34626.png','配料:鲜活牛蛙,莲藕,青笋',1,'2022-06-10 10:35:40','2022-06-10 10:35:40',1,1); 84 | INSERT INTO `dish` VALUES (64,'馋嘴牛蛙',17,88.00,'https://sky-itcast.oss-cn-beijing.aliyuncs.com/7a55b845-1f2b-41fa-9486-76d187ee9ee1.png','配料:鲜活牛蛙,丝瓜,黄豆芽',1,'2022-06-10 10:37:52','2022-06-10 10:37:52',1,1); 85 | INSERT INTO `dish` VALUES (65,'草鱼2斤',16,68.00,'https://sky-itcast.oss-cn-beijing.aliyuncs.com/b544d3ba-a1ae-4d20-a860-81cb5dec9e03.png','原料:草鱼,黄豆芽,莲藕',1,'2022-06-10 10:41:08','2022-06-10 10:41:08',1,1); 86 | INSERT INTO `dish` VALUES (66,'江团鱼2斤',16,119.00,'https://sky-itcast.oss-cn-beijing.aliyuncs.com/a101a1e9-8f8b-47b2-afa4-1abd47ea0a87.png','配料:江团鱼,黄豆芽,莲藕',1,'2022-06-10 10:42:42','2022-06-10 10:42:42',1,1); 87 | INSERT INTO `dish` VALUES (67,'鮰鱼2斤',16,72.00,'https://sky-itcast.oss-cn-beijing.aliyuncs.com/8cfcc576-4b66-4a09-ac68-ad5b273c2590.png','原料:鮰鱼,黄豆芽,莲藕',1,'2022-06-10 10:43:56','2022-06-10 10:43:56',1,1); 88 | INSERT INTO `dish` VALUES (68,'鸡蛋汤',21,4.00,'https://sky-itcast.oss-cn-beijing.aliyuncs.com/c09a0ee8-9d19-428d-81b9-746221824113.png','配料:鸡蛋,紫菜',1,'2022-06-10 10:54:25','2022-06-10 10:54:25',1,1); 89 | INSERT INTO `dish` VALUES (69,'平菇豆腐汤',21,6.00,'https://sky-itcast.oss-cn-beijing.aliyuncs.com/16d0a3d6-2253-4cfc-9b49-bf7bd9eb2ad2.png','配料:豆腐,平菇',1,'2022-06-10 10:55:02','2022-06-10 10:55:02',1,1); 90 | 91 | DROP TABLE IF EXISTS `dish_flavor`; 92 | CREATE TABLE `dish_flavor` ( 93 | `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键', 94 | `dish_id` bigint NOT NULL COMMENT '菜品', 95 | `name` varchar(32) COLLATE utf8_bin DEFAULT NULL COMMENT '口味名称', 96 | `value` varchar(255) COLLATE utf8_bin DEFAULT NULL COMMENT '口味数据list', 97 | PRIMARY KEY (`id`) 98 | ) ENGINE=InnoDB AUTO_INCREMENT=104 DEFAULT CHARSET=utf8mb3 COLLATE=utf8_bin COMMENT='菜品口味关系表'; 99 | 100 | INSERT INTO `dish_flavor` VALUES (40,10,'甜味','[\"无糖\",\"少糖\",\"半糖\",\"多糖\",\"全糖\"]'); 101 | INSERT INTO `dish_flavor` VALUES (41,7,'忌口','[\"不要葱\",\"不要蒜\",\"不要香菜\",\"不要辣\"]'); 102 | INSERT INTO `dish_flavor` VALUES (42,7,'温度','[\"热饮\",\"常温\",\"去冰\",\"少冰\",\"多冰\"]'); 103 | INSERT INTO `dish_flavor` VALUES (45,6,'忌口','[\"不要葱\",\"不要蒜\",\"不要香菜\",\"不要辣\"]'); 104 | INSERT INTO `dish_flavor` VALUES (46,6,'辣度','[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]'); 105 | INSERT INTO `dish_flavor` VALUES (47,5,'辣度','[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]'); 106 | INSERT INTO `dish_flavor` VALUES (48,5,'甜味','[\"无糖\",\"少糖\",\"半糖\",\"多糖\",\"全糖\"]'); 107 | INSERT INTO `dish_flavor` VALUES (49,2,'甜味','[\"无糖\",\"少糖\",\"半糖\",\"多糖\",\"全糖\"]'); 108 | INSERT INTO `dish_flavor` VALUES (50,4,'甜味','[\"无糖\",\"少糖\",\"半糖\",\"多糖\",\"全糖\"]'); 109 | INSERT INTO `dish_flavor` VALUES (51,3,'甜味','[\"无糖\",\"少糖\",\"半糖\",\"多糖\",\"全糖\"]'); 110 | INSERT INTO `dish_flavor` VALUES (52,3,'忌口','[\"不要葱\",\"不要蒜\",\"不要香菜\",\"不要辣\"]'); 111 | INSERT INTO `dish_flavor` VALUES (86,52,'忌口','[\"不要葱\",\"不要蒜\",\"不要香菜\",\"不要辣\"]'); 112 | INSERT INTO `dish_flavor` VALUES (87,52,'辣度','[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]'); 113 | INSERT INTO `dish_flavor` VALUES (88,51,'忌口','[\"不要葱\",\"不要蒜\",\"不要香菜\",\"不要辣\"]'); 114 | INSERT INTO `dish_flavor` VALUES (89,51,'辣度','[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]'); 115 | INSERT INTO `dish_flavor` VALUES (92,53,'忌口','[\"不要葱\",\"不要蒜\",\"不要香菜\",\"不要辣\"]'); 116 | INSERT INTO `dish_flavor` VALUES (93,53,'辣度','[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]'); 117 | INSERT INTO `dish_flavor` VALUES (94,54,'忌口','[\"不要葱\",\"不要蒜\",\"不要香菜\"]'); 118 | INSERT INTO `dish_flavor` VALUES (95,56,'忌口','[\"不要葱\",\"不要蒜\",\"不要香菜\",\"不要辣\"]'); 119 | INSERT INTO `dish_flavor` VALUES (96,57,'忌口','[\"不要葱\",\"不要蒜\",\"不要香菜\",\"不要辣\"]'); 120 | INSERT INTO `dish_flavor` VALUES (97,60,'忌口','[\"不要葱\",\"不要蒜\",\"不要香菜\",\"不要辣\"]'); 121 | INSERT INTO `dish_flavor` VALUES (101,66,'辣度','[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]'); 122 | INSERT INTO `dish_flavor` VALUES (102,67,'辣度','[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]'); 123 | INSERT INTO `dish_flavor` VALUES (103,65,'辣度','[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]'); 124 | 125 | DROP TABLE IF EXISTS `employee`; 126 | CREATE TABLE `employee` ( 127 | `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键', 128 | `name` varchar(32) COLLATE utf8_bin NOT NULL COMMENT '姓名', 129 | `username` varchar(32) COLLATE utf8_bin NOT NULL COMMENT '用户名', 130 | `password` varchar(64) COLLATE utf8_bin NOT NULL COMMENT '密码', 131 | `phone` varchar(11) COLLATE utf8_bin NOT NULL COMMENT '手机号', 132 | `sex` varchar(2) COLLATE utf8_bin NOT NULL COMMENT '性别', 133 | `id_number` varchar(18) COLLATE utf8_bin NOT NULL COMMENT '身份证号', 134 | `status` int NOT NULL DEFAULT '1' COMMENT '状态 0:禁用,1:启用', 135 | `create_time` datetime DEFAULT NULL COMMENT '创建时间', 136 | `update_time` datetime DEFAULT NULL COMMENT '更新时间', 137 | `create_user` bigint DEFAULT NULL COMMENT '创建人', 138 | `update_user` bigint DEFAULT NULL COMMENT '修改人', 139 | PRIMARY KEY (`id`), 140 | UNIQUE KEY `idx_username` (`username`) 141 | ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb3 COLLATE=utf8_bin COMMENT='员工信息'; 142 | 143 | INSERT INTO `employee` VALUES (1,'管理员','admin','123456','13812312312','1','110101199001010047',1,'2022-02-15 15:51:20','2022-02-17 09:16:20',10,1); 144 | 145 | DROP TABLE IF EXISTS `order_detail`; 146 | CREATE TABLE `order_detail` ( 147 | `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键', 148 | `name` varchar(32) COLLATE utf8_bin DEFAULT NULL COMMENT '名字', 149 | `image` varchar(255) COLLATE utf8_bin DEFAULT NULL COMMENT '图片', 150 | `order_id` bigint NOT NULL COMMENT '订单id', 151 | `dish_id` bigint DEFAULT NULL COMMENT '菜品id', 152 | `setmeal_id` bigint DEFAULT NULL COMMENT '套餐id', 153 | `dish_flavor` varchar(50) COLLATE utf8_bin DEFAULT NULL COMMENT '口味', 154 | `number` int NOT NULL DEFAULT '1' COMMENT '数量', 155 | `amount` decimal(10,2) NOT NULL COMMENT '金额', 156 | PRIMARY KEY (`id`) 157 | ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb3 COLLATE=utf8_bin COMMENT='订单明细表'; 158 | 159 | DROP TABLE IF EXISTS `orders`; 160 | CREATE TABLE `orders` ( 161 | `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键', 162 | `number` varchar(50) COLLATE utf8_bin DEFAULT NULL COMMENT '订单号', 163 | `status` int NOT NULL DEFAULT '1' COMMENT '订单状态 1待付款 2待接单 3已接单 4派送中 5已完成 6已取消 7退款', 164 | `user_id` bigint NOT NULL COMMENT '下单用户', 165 | `address_book_id` bigint NOT NULL COMMENT '地址id', 166 | `order_time` datetime NOT NULL COMMENT '下单时间', 167 | `checkout_time` datetime DEFAULT NULL COMMENT '结账时间', 168 | `pay_method` int NOT NULL DEFAULT '1' COMMENT '支付方式 1微信,2支付宝', 169 | `pay_status` tinyint NOT NULL DEFAULT '0' COMMENT '支付状态 0未支付 1已支付 2退款', 170 | `amount` decimal(10,2) NOT NULL COMMENT '实收金额', 171 | `remark` varchar(100) COLLATE utf8_bin DEFAULT NULL COMMENT '备注', 172 | `phone` varchar(11) COLLATE utf8_bin DEFAULT NULL COMMENT '手机号', 173 | `address` varchar(255) COLLATE utf8_bin DEFAULT NULL COMMENT '地址', 174 | `user_name` varchar(32) COLLATE utf8_bin DEFAULT NULL COMMENT '用户名称', 175 | `consignee` varchar(32) COLLATE utf8_bin DEFAULT NULL COMMENT '收货人', 176 | `cancel_reason` varchar(255) COLLATE utf8_bin DEFAULT NULL COMMENT '订单取消原因', 177 | `rejection_reason` varchar(255) COLLATE utf8_bin DEFAULT NULL COMMENT '订单拒绝原因', 178 | `cancel_time` datetime DEFAULT NULL COMMENT '订单取消时间', 179 | `estimated_delivery_time` datetime DEFAULT NULL COMMENT '预计送达时间', 180 | `delivery_status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '配送状态 1立即送出 0选择具体时间', 181 | `delivery_time` datetime DEFAULT NULL COMMENT '送达时间', 182 | `pack_amount` int DEFAULT NULL COMMENT '打包费', 183 | `tableware_number` int DEFAULT NULL COMMENT '餐具数量', 184 | `tableware_status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '餐具数量状态 1按餐量提供 0选择具体数量', 185 | PRIMARY KEY (`id`) 186 | ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb3 COLLATE=utf8_bin COMMENT='订单表'; 187 | 188 | DROP TABLE IF EXISTS `setmeal`; 189 | CREATE TABLE `setmeal` ( 190 | `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键', 191 | `category_id` bigint NOT NULL COMMENT '菜品分类id', 192 | `name` varchar(32) COLLATE utf8_bin NOT NULL COMMENT '套餐名称', 193 | `price` decimal(10,2) NOT NULL COMMENT '套餐价格', 194 | `status` int DEFAULT '1' COMMENT '售卖状态 0:停售 1:起售', 195 | `description` varchar(255) COLLATE utf8_bin DEFAULT NULL COMMENT '描述信息', 196 | `image` varchar(255) COLLATE utf8_bin DEFAULT NULL COMMENT '图片', 197 | `create_time` datetime DEFAULT NULL COMMENT '创建时间', 198 | `update_time` datetime DEFAULT NULL COMMENT '更新时间', 199 | `create_user` bigint DEFAULT NULL COMMENT '创建人', 200 | `update_user` bigint DEFAULT NULL COMMENT '修改人', 201 | PRIMARY KEY (`id`), 202 | UNIQUE KEY `idx_setmeal_name` (`name`) 203 | ) ENGINE=InnoDB AUTO_INCREMENT=32 DEFAULT CHARSET=utf8mb3 COLLATE=utf8_bin COMMENT='套餐'; 204 | 205 | DROP TABLE IF EXISTS `setmeal_dish`; 206 | CREATE TABLE `setmeal_dish` ( 207 | `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键', 208 | `setmeal_id` bigint DEFAULT NULL COMMENT '套餐id', 209 | `dish_id` bigint DEFAULT NULL COMMENT '菜品id', 210 | `name` varchar(32) COLLATE utf8_bin DEFAULT NULL COMMENT '菜品名称 (冗余字段)', 211 | `price` decimal(10,2) DEFAULT NULL COMMENT '菜品单价(冗余字段)', 212 | `copies` int DEFAULT NULL COMMENT '菜品份数', 213 | PRIMARY KEY (`id`) 214 | ) ENGINE=InnoDB AUTO_INCREMENT=47 DEFAULT CHARSET=utf8mb3 COLLATE=utf8_bin COMMENT='套餐菜品关系'; 215 | 216 | DROP TABLE IF EXISTS `shopping_cart`; 217 | CREATE TABLE `shopping_cart` ( 218 | `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键', 219 | `name` varchar(32) COLLATE utf8_bin DEFAULT NULL COMMENT '商品名称', 220 | `image` varchar(255) COLLATE utf8_bin DEFAULT NULL COMMENT '图片', 221 | `user_id` bigint NOT NULL COMMENT '主键', 222 | `dish_id` bigint DEFAULT NULL COMMENT '菜品id', 223 | `setmeal_id` bigint DEFAULT NULL COMMENT '套餐id', 224 | `dish_flavor` varchar(50) COLLATE utf8_bin DEFAULT NULL COMMENT '口味', 225 | `number` int NOT NULL DEFAULT '1' COMMENT '数量', 226 | `amount` decimal(10,2) NOT NULL COMMENT '金额', 227 | `create_time` datetime DEFAULT NULL COMMENT '创建时间', 228 | PRIMARY KEY (`id`) 229 | ) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8mb3 COLLATE=utf8_bin COMMENT='购物车'; 230 | 231 | DROP TABLE IF EXISTS `user`; 232 | CREATE TABLE `user` ( 233 | `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键', 234 | `openid` varchar(45) COLLATE utf8_bin DEFAULT NULL COMMENT '微信用户唯一标识', 235 | `name` varchar(32) COLLATE utf8_bin DEFAULT NULL COMMENT '姓名', 236 | `phone` varchar(11) COLLATE utf8_bin DEFAULT NULL COMMENT '手机号', 237 | `sex` varchar(2) COLLATE utf8_bin DEFAULT NULL COMMENT '性别', 238 | `id_number` varchar(18) COLLATE utf8_bin DEFAULT NULL COMMENT '身份证号', 239 | `avatar` varchar(500) COLLATE utf8_bin DEFAULT NULL COMMENT '头像', 240 | `create_time` datetime DEFAULT NULL, 241 | PRIMARY KEY (`id`) 242 | ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb3 COLLATE=utf8_bin COMMENT='用户信息'; --------------------------------------------------------------------------------