Selaa lähdekoodia

修改路由结构

Administrator 2 vuotta sitten
vanhempi
commit
96a0574a85

+ 1 - 1
configs/config.go

@@ -16,7 +16,7 @@ var (
 )
 
 type User struct {
-	Id            int    `xorm:"'id'" json:"id"`
+	Id            int64  `xorm:"'id'" json:"id"`
 	Username      string `xorm:"'username'" json:"username"`
 	Password      string `xorm:"'password'" json:"password"`
 	Creation_time int    `xorm:"'creation_time'" json:"creation_Time"`

+ 23 - 0
data/dao/AuthorityDao.go

@@ -0,0 +1,23 @@
+package dao
+
+import (
+	"demo/configs"
+	"demo/data/domain"
+	"fmt"
+)
+
+func GetListAuthorityAll() []domain.Authority {
+	var authority domain.Authority
+	var arr []domain.Authority
+	configs.Engine.Desc("id").FindAndCount(&arr, &authority)
+	return arr
+}
+func AddAllListAuthorityAll(arr []*domain.Authority) {
+	for i := range arr {
+		insert, err := configs.Engine.Insert(arr[i])
+		if err != nil {
+			fmt.Println(err)
+		}
+		fmt.Println(insert)
+	}
+}

+ 3 - 3
data/dao/DetailDao.go

@@ -10,7 +10,7 @@ import (
 // SelectGoodsDetailById 获取相同的商品详情
 func SelectGoodsDetailById(skuId int64) (vo.DetailVo, error) {
 	detailVo := vo.DetailVo{}
-	var caId = -1
+	var caId int64 = -1
 	//================查询sku========================
 	var sku domain.GoodsSku
 	//查询 sku
@@ -22,7 +22,7 @@ func SelectGoodsDetailById(skuId int64) (vo.DetailVo, error) {
 		return vo.DetailVo{}, err
 	}
 	var skus []domain.GoodsSku
-	var commodityAreaIds = make([]int, 0)
+	var commodityAreaIds = make([]int64, 0)
 	commodityAreaIdsString := ""
 A:
 	for rows.Next() {
@@ -82,7 +82,7 @@ A:
 	}
 	var goodsCommodityAreas []domain.GoodsCommodityArea
 
-	var introductionIds = make([]int, 0)
+	var introductionIds = make([]int64, 0)
 	var introductionIdString = ""
 B:
 	for rows.Next() {

+ 5 - 5
data/dao/OrderDao.go

@@ -28,12 +28,12 @@ func CreateOrder(order *domain.GoodsOrder) (*domain.GoodsOrder, error) {
 }
 
 // OrderPaySuccess 订单支付成功
-func OrderPaySuccess(orderId int) {
+func OrderPaySuccess(orderId int64) {
 	configs.Engine.ID(orderId).Cols("state").Update(map[string]any{"state": 1})
 }
 
 // GetOrderByUserId 获取订单集合
-func GetOrderByUserId(userId int) ([]domain.GoodsOrder, error) {
+func GetOrderByUserId(userId int64) ([]domain.GoodsOrder, error) {
 	order := domain.GoodsOrder{}
 	rows, err := configs.Engine.Table("goods_order").Where("create_by = ?", userId).Desc("create_time").Rows(&order)
 	if err != nil {
@@ -53,7 +53,7 @@ func GetOrderByUserId(userId int) ([]domain.GoodsOrder, error) {
 }
 
 // GetUserWalletByUserId 获取用户的钱包信息
-func GetUserWalletByUserId(userId int) (domain.UserWallet, error) {
+func GetUserWalletByUserId(userId int64) (domain.UserWallet, error) {
 	var wallet domain.UserWallet
 	_, err := configs.Engine.Where("user_id = ?", userId).Get(&wallet)
 	if err != nil {
@@ -64,7 +64,7 @@ func GetUserWalletByUserId(userId int) (domain.UserWallet, error) {
 }
 
 // GetUserCouponByUserId  获取用户的优惠券信息
-func GetUserCouponByUserId(userId int) ([]domain.CouponUserJDM, error) {
+func GetUserCouponByUserId(userId int64) ([]domain.CouponUserJDM, error) {
 
 	var couponUserJDMs []domain.CouponUserJDM
 	err := configs.Engine.Table("goods_coupon_user").
@@ -79,7 +79,7 @@ func GetUserCouponByUserId(userId int) ([]domain.CouponUserJDM, error) {
 }
 
 // GetListGoodsOrder 获取用户的订单信息
-func GetListGoodsOrder(state string, userId, pageNum, pageSize int) (vo.BaseListVo, error) {
+func GetListGoodsOrder(state string, userId int64, pageNum, pageSize int) (vo.BaseListVo, error) {
 	var goodsOrder domain.GoodsOrder
 	Session := configs.Engine.Table("goods_order")
 	if state != "" {

+ 1 - 1
data/dao/manage/UserDao.go

@@ -57,7 +57,7 @@ func SaveUser(user *domain.User) (domain.User, error) {
 	return *user, nil
 }
 
-func SetUser(userMap map[string]interface{}, id int) (domain.User, bool, error) {
+func SetUser(userMap map[string]interface{}, id int64) (domain.User, bool, error) {
 	var user domain.User
 	_, err := configs.Engine.Table("user").Where("id = ?", id).Update(userMap)
 	if err != nil {

+ 37 - 33
data/domain/DoMain.go

@@ -12,11 +12,11 @@ type Article struct {
 	ArticeContent string    `xorm:"artice_content"  json:"articeContent"`  // 0 0 注释:文章内容
 	State         string    `xorm:"state"  json:"state"`                   // 255 0 注释:状态
 	ArticeTagIds  string    `xorm:"artice_tag_ids"  json:"articeTagIds"`   // 255 0 注释:文章标签
-	ArticeTopicId int       `xorm:"artice_topic_id"  json:"articeTopicId"` // 11 0 注释:文章主题id
+	ArticeTopicId int64     `xorm:"artice_topic_id"  json:"articeTopicId"` // 11 0 注释:文章主题id
 	Image         string    `xorm:"image"  json:"image"`                   // 255 0 注释:图片
 	PublishTime   time.Time `xorm:"publish_time"  json:"publishTime"`      // 0 0 注释:发表时间
-	EyeFill       int       `xorm:"eye_fill"  json:"eyeFill"`              // 11 0 注释:浏览量
-	LikeCount     int       `xorm:"like_count"  json:"likeCount"`          // 255 0 注释:点赞量
+	EyeFill       int64     `xorm:"eye_fill"  json:"eyeFill"`              // 11 0 注释:浏览量
+	LikeCount     int64     `xorm:"like_count"  json:"likeCount"`          // 255 0 注释:点赞量
 	CreateBy      string    `xorm:"create_by"  json:"createBy"`            // 255 0 注释:创建人
 	CreateTime    time.Time `xorm:"create_time"  json:"createTime"`        // 0 0 注释:创建时间
 	UpdateBy      string    `xorm:"update_by"  json:"updateBy"`            // 255 0 注释:更新人
@@ -52,22 +52,26 @@ func (receiver ArticleTopic) String() string {
 
 // Authority
 type Authority struct {
-	Id            int64  `json:"id"`                                   // 11 0 注释:
-	AuthorityName string `xorm:"authority_name"  json:"authorityName"` // 255 0 注释:
-	AuthorityPath string `xorm:"authority_path"  json:"authorityPath"` // 255 0 注释:
+	Id                    int64     `json:"id"`                                                   // 11 0 注释:id
+	AuthorityName         string    `xorm:"authority_name"  json:"authorityName"`                 // 255 0 注释:接口名
+	AuthorityPath         string    `xorm:"authority_path"  json:"authorityPath"`                 // 255 0 注释:接口路径
+	Method                string    `xorm:"method"  json:"method"`                                // 8 0 注释:方法
+	State                 string    `xorm:"state"  json:"state"`                                  // 5 0 注释:接口是否启用(0关闭,1启用)
+	AuthorityVerification string    `xorm:"authority_verification"  json:"authorityVerification"` // 5 0 注释:权限校验
+	CreateTime            time.Time `xorm:"create_time"  json:"createTime"`                       // 0 0 注释:创建时间
 }
 
 func (receiver Authority) String() string {
-	return fmt.Sprint("Authority{Id:", receiver.Id, ",AuthorityName:", receiver.AuthorityName, ",AuthorityPath:", receiver.AuthorityPath, "}")
+	return fmt.Sprint("Authority{Id:", receiver.Id, ",AuthorityName:", receiver.AuthorityName, ",AuthorityPath:", receiver.AuthorityPath, ",Method:", receiver.Method, ",State:", receiver.State, ",AuthorityVerification:", receiver.AuthorityVerification, ",CreateTime:", receiver.CreateTime, "}")
 }
 
 // Goods
 type Goods struct {
 	Id             int64  `json:"id"`                                     // 11 0 注释:id
-	TypeId         int    `xorm:"type_id"  json:"typeId"`                 // 11 0 注释:分类id
+	TypeId         int64  `xorm:"type_id"  json:"typeId"`                 // 11 0 注释:分类id
 	GoodsName      string `xorm:"goods_name"  json:"goodsName"`           // 255 0 注释:商品名字
-	IntroductionId int    `xorm:"introduction_id"  json:"introductionId"` // 11 0 注释:商品介绍id
-	SalesVolume    int    `xorm:"sales_volume"  json:"salesVolume"`       // 255 0 注释:近30天销量
+	IntroductionId int64  `xorm:"introduction_id"  json:"introductionId"` // 11 0 注释:商品介绍id
+	SalesVolume    int64  `xorm:"sales_volume"  json:"salesVolume"`       // 255 0 注释:近30天销量
 	TagIds         string `xorm:"tag_ids"  json:"tagIds"`                 // 255 0 注释:商品标签
 }
 
@@ -78,10 +82,10 @@ func (receiver Goods) String() string {
 // GoodsCommodityArea
 type GoodsCommodityArea struct {
 	Id                   int64  `json:"id"`                                                  // 11 0 注释:id
-	GoodsId              int    `xorm:"goods_id"  json:"goodsId"`                            // 11 0 注释:商品id
+	GoodsId              int64  `xorm:"goods_id"  json:"goodsId"`                            // 11 0 注释:商品id
 	CommodityAreaName    string `xorm:"commodity_area_name"  json:"commodityAreaName"`       // 255 0 注释:商品属地名称
 	DetailImage          string `xorm:"detail_image"  json:"detailImage"`                    // 255 0 注释:详情图片
-	DetailIntroductionId int    `xorm:"detail_introduction_id"  json:"detailIntroductionId"` // 11 0 注释:相关文本详情id
+	DetailIntroductionId int64  `xorm:"detail_introduction_id"  json:"detailIntroductionId"` // 11 0 注释:相关文本详情id
 }
 
 func (receiver GoodsCommodityArea) String() string {
@@ -99,7 +103,7 @@ type GoodsCoupon struct {
 	ConditionByType  string    `xorm:"condition_by_type"  json:"conditionByType"`   // 255 0 注释:类型可用,id
 	ConditionByGoods string    `xorm:"condition_by_goods"  json:"conditionByGoods"` // 255 0 注释:商品可用,id
 	GrantCount       string    `xorm:"grant_count"  json:"grantCount"`              // 255 0 注释:发放数量
-	Count            int       `xorm:"count"  json:"count"`                         // 255 0 注释:优惠券余量
+	Count            int64     `xorm:"count"  json:"count"`                         // 255 0 注释:优惠券余量
 	ReceiveType      string    `xorm:"receive_type"  json:"receiveType"`            // 255 0 注释:领取条件
 	Validity         string    `xorm:"validity"  json:"validity"`                   // 255 0 注释:有效性,领取开始计时(ClaimTiming),固定时间(FixedTime)
 	ValidityPeriod   time.Time `xorm:"validity_period"  json:"validityPeriod"`      // 0 0 注释:有效期
@@ -112,8 +116,8 @@ func (receiver GoodsCoupon) String() string {
 // GoodsCouponUser 优惠券领取
 type GoodsCouponUser struct {
 	Id             int64     `json:"id"`                                     // 11 0 注释:id
-	UserId         int       `xorm:"user_id"  json:"userId"`                 // 11 0 注释:用户id
-	CouponId       int       `xorm:"coupon_id"  json:"couponId"`             // 11 0 注释:优惠券id
+	UserId         int64     `xorm:"user_id"  json:"userId"`                 // 11 0 注释:用户id
+	CouponId       int64     `xorm:"coupon_id"  json:"couponId"`             // 11 0 注释:优惠券id
 	CollectionTime time.Time `xorm:"collection_time"  json:"collectionTime"` // 0 0 注释:领取时间
 	State          string    `xorm:"state"  json:"state"`                    // 255 0 注释:状态,已使用2,未使用1,已过期0
 }
@@ -141,14 +145,14 @@ func (receiver GoodsIntroduction) String() string {
 type GoodsOrder struct {
 	Id                 int64     `json:"id"`                                             // 11 0 注释:id
 	OrderName          string    `xorm:"order_name"  json:"orderName"`                   // 255 0 注释:订单名
-	SkuId              int       `xorm:"sku_id"  json:"skuId"`                           // 11 0 注释:skuid
-	Count              int       `xorm:"count"  json:"count"`                            // 11 0 注释:购买数量
+	SkuId              int64     `xorm:"sku_id"  json:"skuId"`                           // 11 0 注释:skuid
+	Count              int64     `xorm:"count"  json:"count"`                            // 11 0 注释:购买数量
 	Price              float64   `xorm:"price"  json:"price"`                            // 10 2 注释:单价
 	TotalPrice         float64   `xorm:"total_price"  json:"totalPrice"`                 // 10 2 注释:总价
 	ContactInformation string    `xorm:"contact_information"  json:"contactInformation"` // 255 0 注释:联系方式
 	CouponUserId       int64     `xorm:"coupon_user_id"  json:"couponUserId"`            // 11 0 注释:使用的优惠券
 	State              string    `xorm:"state"  json:"state"`                            // 10 0 注释:支付状态,0待支付,1待发货,2已发货,3订单完成,4订单异常
-	CreateBy           int       `xorm:"create_by"  json:"createBy"`                     // 255 0 注释:用户id
+	CreateBy           int64     `xorm:"create_by"  json:"createBy"`                     // 255 0 注释:用户id
 	CreateTime         time.Time `xorm:"create_time"  json:"createTime"`                 // 0 0 注释:订单创建时间
 }
 
@@ -163,9 +167,9 @@ type GoodsSku struct {
 	SkuName          string    `xorm:"sku_name"  json:"skuName"`                   // 255 0 注释:商品sku名字
 	Price            float64   `xorm:"price"  json:"price"`                        // 10 2 注释:现在价格
 	HistoricalPrices float64   `xorm:"historical_prices"  json:"historicalPrices"` // 10 2 注释:历史价格
-	InventoryNumber  int       `xorm:"inventory_number"  json:"inventoryNumber"`   // 11 0 注释:库存
-	CommodityAreaId  int       `xorm:"commodity_area_id"  json:"commodityAreaId"`  // 11 0 注释:属地id
-	GoodsId          int       `xorm:"goods_id"  json:"goodsId"`                   // 11 0 注释:商品id
+	InventoryNumber  int64     `xorm:"inventory_number"  json:"inventoryNumber"`   // 11 0 注释:库存
+	CommodityAreaId  int64     `xorm:"commodity_area_id"  json:"commodityAreaId"`  // 11 0 注释:属地id
+	GoodsId          int64     `xorm:"goods_id"  json:"goodsId"`                   // 11 0 注释:商品id
 	CreateBy         string    `xorm:"create_by"  json:"createBy"`                 // 255 0 注释:创建人
 	CreateTime       time.Time `xorm:"create_time"  json:"createTime"`             // 0 0 注释:创建时间
 }
@@ -179,12 +183,12 @@ type GoodsSkuCard struct {
 	Id         int64     `json:"id"`                             // 11 0 注释:id
 	CardName   string    `xorm:"card_name"  json:"cardName"`     // 255 0 注释:卡种名称
 	State      string    `xorm:"state"  json:"state"`            // 255 0 注释:状态,0未使用,1已用,2过期
-	Count      int       `xorm:"count"  json:"count"`            // 11 0 注释:库存
+	Count      int64     `xorm:"count"  json:"count"`            // 11 0 注释:库存
 	TotalCount string    `xorm:"total_count"  json:"totalCount"` // 255 0 注释:总数
 	CardKey    string    `xorm:"card_key"  json:"cardKey"`       // 255 0 注释:卡密
 	Use        string    `xorm:"use"  json:"use"`                // 5 0 注释:是否已用
 	UploadTime time.Time `xorm:"upload_time"  json:"uploadTime"` // 0 0 注释:入库时间
-	SkuId      int       `xorm:"sku_id"  json:"skuId"`           // 11 0 注释:商品规格绑定
+	SkuId      int64     `xorm:"sku_id"  json:"skuId"`           // 11 0 注释:商品规格绑定
 	Sort       string    `xorm:"sort"  json:"sort"`              // 255 0 注释:排序,出售优先级
 }
 
@@ -220,7 +224,7 @@ func (receiver GoodsTopic) String() string {
 // GoodsType 商品分类
 type GoodsType struct {
 	Id         int64     `json:"id"`                             // 11 0 注释:
-	Sort       int       `xorm:"sort"  json:"sort"`              // 11 0 注释:排序
+	Sort       int64     `xorm:"sort"  json:"sort"`              // 11 0 注释:排序
 	TypeImage  string    `xorm:"type_image"  json:"typeImage"`   // 50 0 注释:类型图片
 	TypeName   string    `xorm:"type_name"  json:"typeName"`     // 255 0 注释:商品类别名称
 	CreateTime time.Time `xorm:"create_time"  json:"createTime"` // 0 0 注释:创建时间
@@ -236,10 +240,10 @@ type ManageUser struct {
 	Name         string `xorm:"name"  json:"name"`                  // 255 0 注释:名称
 	Username     string `xorm:"username"  json:"username"`          // 255 0 注释:账号
 	Password     string `xorm:"password"  json:"password"`          // 255 0 注释:密码
-	CreationTime int    `xorm:"creation_time"  json:"creationTime"` // 11 0 注释:账号创建时间
-	LoginTime    int    `xorm:"login_time"  json:"loginTime"`       // 11 0 注释:登录时间
+	CreationTime int64  `xorm:"creation_time"  json:"creationTime"` // 11 0 注释:账号创建时间
+	LoginTime    int64  `xorm:"login_time"  json:"loginTime"`       // 11 0 注释:登录时间
 	Status       string `xorm:"status"  json:"status"`              // 255 0 注释:账号状态
-	RoleId       int    `xorm:"role_id"  json:"roleId"`             // 11 0 注释:角色id
+	RoleId       int64  `xorm:"role_id"  json:"roleId"`             // 11 0 注释:角色id
 	Phone        string `xorm:"phone"  json:"phone"`                // 255 0 注释:手机
 	Email        string `xorm:"email"  json:"email"`                // 255 0 注释:邮箱
 	Avatar       string `xorm:"avatar"  json:"avatar"`              // 255 0 注释:头像
@@ -261,8 +265,8 @@ func (receiver Role) String() string {
 
 // RoleAuthority
 type RoleAuthority struct {
-	AuthorityId int `xorm:"authority_id"  json:"authorityId"` // 11 0 注释:
-	RoleId      int `xorm:"role_id"  json:"roleId"`           // 11 0 注释:
+	AuthorityId int64 `xorm:"authority_id"  json:"authorityId"` // 11 0 注释:
+	RoleId      int64 `xorm:"role_id"  json:"roleId"`           // 11 0 注释:
 }
 
 func (receiver RoleAuthority) String() string {
@@ -274,10 +278,10 @@ type User struct {
 	Id            int64  `json:"id"`                                   // 11 0 注释:
 	Username      string `xorm:"username"  json:"username"`            // 255 0 注释:账号
 	Password      string `xorm:"password"  json:"password"`            // 255 0 注释:密码
-	CreationTime  int    `xorm:"creation_time"  json:"creationTime"`   // 11 0 注释:账号创建时间
-	LoginTime     int    `xorm:"login_time"  json:"loginTime"`         // 11 0 注释:登录时间
+	CreationTime  int64  `xorm:"creation_time"  json:"creationTime"`   // 11 0 注释:账号创建时间
+	LoginTime     int64  `xorm:"login_time"  json:"loginTime"`         // 11 0 注释:登录时间
 	Status        string `xorm:"status"  json:"status"`                // 255 0 注释:账号状态
-	RoleId        int    `xorm:"role_id"  json:"roleId"`               // 11 0 注释:角色id
+	RoleId        int64  `xorm:"role_id"  json:"roleId"`               // 11 0 注释:角色id
 	Phone         string `xorm:"phone"  json:"phone"`                  // 255 0 注释:手机
 	Email         string `xorm:"email"  json:"email"`                  // 255 0 注释:邮箱
 	Name          string `xorm:"name"  json:"name"`                    // 255 0 注释:用户名
@@ -292,7 +296,7 @@ func (receiver User) String() string {
 // UserWallet
 type UserWallet struct {
 	Id              int64   `json:"id"`                                       // 11 0 注释:id
-	UserId          int     `xorm:"user_id"  json:"userId"`                   // 11 0 注释:用户id
+	UserId          int64   `xorm:"user_id"  json:"userId"`                   // 11 0 注释:用户id
 	Balance         float64 `xorm:"balance"  json:"balance"`                  // 65 0 注释:余额
 	PromotionAmount float64 `xorm:"promotion_amount"  json:"promotionAmount"` // 20 2 注释:推广获取总金额
 	RechargeAmount  float64 `xorm:"recharge_amount"  json:"rechargeAmount"`   // 20 2 注释:充值金额

+ 2 - 2
data/domain/vo/DetailVo.go

@@ -15,7 +15,7 @@ type DetailVo struct {
 type DetailGoodsVo struct {
 	GoodsId     int64             `xorm:"'id'" json:"id"`
 	Name        string            `xorm:"'name'" json:"name"`
-	SalesVolume int               `xorm:"'sales_volume'" json:"sales_volume"`
+	SalesVolume int64             `xorm:"'sales_volume'" json:"sales_volume"`
 	Type        domain.GoodsType  `xorm:"'type'" json:"type"`
 	Tags        []domain.GoodsTag `xorm:"'tags'" json:"tags"`
 }
@@ -26,6 +26,6 @@ type DetailSkuVo struct {
 }
 
 type DetailCommodityAreaVo struct {
-	NowCommodityAreaId int                         `json:"commodityArea"`     //当前地区
+	NowCommodityAreaId int64                       `json:"commodityArea"`     //当前地区
 	CommodityAreaList  []domain.GoodsCommodityArea `json:"commodityAreaList"` //地区列表
 }

+ 9 - 2
main.go

@@ -3,6 +3,7 @@ package main
 import (
 	"demo/configs"
 	"demo/router"
+	"fmt"
 	"github.com/gin-gonic/gin"
 )
 
@@ -13,9 +14,15 @@ func main() {
 	runGin()
 }
 
+// 接口前缀
+
 func runGin() {
 	Router := gin.Default()
-	apiGroup := Router.Group("/api")
-	router.InitRouter(apiGroup)
+	apiGroup := Router.Group(router.Prefix)
+	router.InitRouter(apiGroup, Router)
+	router.InitAuthority(Router)
+	fmt.Println("router.PathIRouterMap===>", router.PathIRouterMap)
+	fmt.Println("router.PathRouterMap====>", router.PathRouterMap)
 	Router.Run(":8182")
+
 }

+ 4 - 9
router/BackRouter.go

@@ -17,15 +17,10 @@ import (
 
 func BackRouter(engine *gin.RouterGroup) {
 	user := engine.Group("/back")
-	{
-		user.POST("/login", BackLogin)
-		user.GET("/code", VerificationBackCode)
-	}
-	user.Use(LoginInterceptor())
-	{
-		//获取用户信息
-		user.GET("/state", GetBackUserState)
-	}
+	PushRouter(user, "POST", "/login", BackLogin)
+	PushRouter(user, "GET", "/code", VerificationBackCode)
+	PushRouter(user, "GET", "/state", GetBackUserState)
+
 }
 
 var ctx = context.Background()

+ 5 - 5
router/DetailRouter.go

@@ -12,11 +12,11 @@ import (
 
 func DetailRouter(engine *gin.RouterGroup) {
 	user := engine.Group("/detail")
-	{
-		user.GET("/search", GetSearchByKey)
-		//获取文章详情
-		user.GET("/:id", GetDetailData)
-	}
+	//user.GET("/search", GetSearchByKey)
+	PushRouter(user, "GET", "/search", GetSearchByKey)
+	//获取文章详情
+	//user.GET("/:id", GetDetailData)
+	PushRouter(user, "GET", "/:id", GetDetailData)
 }
 
 // GetDetailData 获取文章详情

+ 2 - 1
router/FileRouter.go

@@ -19,7 +19,8 @@ func FileRouter(engine *gin.RouterGroup) {
 	user := engine.Group("/file")
 	{
 		//文章上传
-		user.POST("/upload.bat", uploadHandler)
+		//user.POST("/upload", uploadHandler)
+		PushRouter(user, "POST", "/upload", uploadHandler)
 	}
 }
 

+ 2 - 1
router/HomeRouter.go

@@ -7,7 +7,8 @@ import (
 func HomeRouter(engine *gin.RouterGroup) {
 	user := engine.Group("/home")
 	{
-		user.POST("/", uploadHandler)
+		//user.POST("/", uploadHandler)
+		PushRouter(user, "POST", "/", getHomeData)
 	}
 }
 func getHomeData(c *gin.Context) {

+ 19 - 0
router/Interceptor.go

@@ -3,6 +3,7 @@ package router
 import (
 	"fmt"
 	"github.com/gin-gonic/gin"
+	"strings"
 )
 
 func LoginInterceptor() gin.HandlerFunc {
@@ -17,6 +18,24 @@ func LoginInterceptor() gin.HandlerFunc {
 		}
 	}
 }
+
+func Interceptor(InterceptorName string) gin.HandlerFunc {
+	switch InterceptorName {
+	case "login":
+		return LoginInterceptor()
+	case "log":
+		return LogInterceptor()
+	default:
+		return func(context *gin.Context) {}
+	}
+}
+func AddUseInterceptor(routes gin.IRoutes, AuthorityVerification string) {
+	split := strings.Split(AuthorityVerification, ",")
+	for i := range split {
+		routes.Use(Interceptor(split[i]))
+	}
+}
+
 func LogInterceptor() gin.HandlerFunc {
 	return func(c *gin.Context) {
 		fmt.Println("日志系统")

+ 6 - 5
router/OrderRouter.go

@@ -16,7 +16,8 @@ func OrderRouter(engine *gin.RouterGroup) {
 	order := engine.Group("/order")
 	{
 		//根据用户登录id获取用户登录信息
-		order.POST("/submit", GetOrderData)
+		//order.POST("/submit", GetOrderData)
+		PushRouter(order, "POST", "/list", GetOrderList)
 	}
 }
 
@@ -40,12 +41,12 @@ func GetOrderData(c *gin.Context) {
 		return
 	}
 	//查询库存数量
-	if sku.InventoryNumber < cast.ToInt(count) {
+	if sku.InventoryNumber < cast.ToInt64(count) {
 		c.JSON(200, CreateResultError(1000, "库存不足"))
 	}
 	order := &domain.GoodsOrder{}
-	order.SkuId = cast.ToInt(skuId)
-	order.Count = cast.ToInt(count)
+	order.SkuId = cast.ToInt64(skuId)
+	order.Count = cast.ToInt64(count)
 	order.CouponUserId = cast.ToInt64(couponUserId)
 	order.ContactInformation = cast.ToString(contactInformation)
 
@@ -71,7 +72,7 @@ func PayBuyTest(c *gin.Context) {
 	}
 	data := share.GetJsonAnyParam(c)
 	orderId, _ := data("orderId")
-	dao.OrderPaySuccess(cast.ToInt(orderId))
+	dao.OrderPaySuccess(cast.ToInt64(orderId))
 }
 
 // 订单列表

+ 2 - 2
router/ResultData.go

@@ -27,7 +27,7 @@ func CreateResultError(errCode int, errMsg string) gin.H {
 	}
 }
 
-func GetUserIdByToken(c *gin.Context) int {
+func GetUserIdByToken(c *gin.Context) int64 {
 	header := c.GetHeader("auth-sign")
 	if header == "" {
 		c.JSON(200, CreateResultError(401, "用户未登录"))
@@ -39,6 +39,6 @@ func GetUserIdByToken(c *gin.Context) int {
 		return 0
 	}
 	i, err := strconv.ParseInt(claims["iss"].(string), 10, 32)
-	return int(i)
+	return int64(i)
 
 }

+ 81 - 1
router/Router.go

@@ -1,10 +1,21 @@
 package router
 
 import (
+	"demo/data/dao"
+	"demo/data/domain"
+	"fmt"
 	"github.com/gin-gonic/gin"
+	"strings"
+	"time"
 )
 
-func InitRouter(apiGroup *gin.RouterGroup) {
+var PathRouterMap = make(map[string]domain.Authority)
+var PathIRouterMap = make(map[string]gin.IRoutes)
+
+const Prefix = "/api"
+
+func InitRouter(apiGroup *gin.RouterGroup, Router *gin.Engine) {
+	apiGroup.Use(LogInterceptor())
 	apiGroup.Use(LogInterceptor())
 	//用户,包含用户后台
 	UserRouth(apiGroup)
@@ -19,4 +30,73 @@ func InitRouter(apiGroup *gin.RouterGroup) {
 	//-------------------
 	//后台管理系统
 	BackRouter(apiGroup)
+	//获取全部路由
+}
+
+func PushRouter(api *gin.RouterGroup, method, path string, handlerFunc gin.HandlerFunc) {
+	var iRouter gin.IRoutes
+	switch method {
+	case "GET":
+		iRouter = api.GET(path, handlerFunc)
+		break
+	case "POST":
+		iRouter = api.POST(path, handlerFunc)
+		break
+	case "PUT":
+		iRouter = api.PUT(path, handlerFunc)
+		break
+	case "DELETE":
+		iRouter = api.DELETE(path, handlerFunc)
+		break
+	case "PATCH":
+		iRouter = api.PATCH(path, handlerFunc)
+		break
+	case "HEAD":
+		iRouter = api.HEAD(path, handlerFunc)
+		break
+	default:
+		iRouter = api.Any(path, handlerFunc)
+	}
+	fmt.Println(api.BasePath() + path)
+	key := api.BasePath() + path
+	if strings.HasPrefix(key, Prefix) {
+		key = key[len(Prefix):]
+	}
+
+	PathIRouterMap[key] = iRouter
+}
+
+func InitAuthority(Router *gin.Engine) {
+	List := dao.GetListAuthorityAll()
+	pathMap := make(map[string]domain.Authority)
+	for i := range List {
+		pathMap[List[i].AuthorityPath] = List[i]
+	}
+	routes := Router.Routes()
+	var insertRouter = make([]*domain.Authority, 0)
+	for i := range routes {
+		method := Router.Routes()[i].Method
+		path := Router.Routes()[i].Path
+		if strings.HasPrefix(path, Prefix) {
+			path = path[len(Prefix):]
+		}
+		if _, ok := pathMap[path]; !ok {
+			insertRouter = append(insertRouter, &domain.Authority{
+				AuthorityPath:         path,
+				Method:                method,
+				State:                 "1",
+				AuthorityVerification: "",
+				CreateTime:            time.Now()})
+		}
+	}
+	dao.AddAllListAuthorityAll(insertRouter)
+	for i := range insertRouter {
+		pathMap[insertRouter[i].AuthorityPath] = *insertRouter[i]
+	}
+	PathRouterMap = pathMap
+
+	for s := range PathIRouterMap {
+		AddUseInterceptor(PathIRouterMap[s], pathMap[s].AuthorityVerification)
+	}
+
 }

+ 2 - 1
router/TestRouter.go

@@ -11,7 +11,8 @@ func TestRouth(engine *gin.RouterGroup) {
 	user := engine.Group("/test")
 	user.Use(LoginInterceptor())
 	{
-		user.GET("/order/pay", OrderSubmit)
+		//user.GET("/order/pay", OrderSubmit)
+		PushRouter(user, "POST", "/order/pay", OrderSubmit)
 	}
 }
 

+ 41 - 25
router/UserRouter.go

@@ -22,27 +22,46 @@ import (
 
 func UserRouth(engine *gin.RouterGroup) {
 	user := engine.Group("/user")
-	{
-		//获取用户基本信息
-		user.GET("/info", GetUserInfo)
-		//获取用户钱包
-		user.GET("/wallet", GetUserWallet)
-		//修改名字
-		user.PUT("/name", SetNameValue)
-		//获取用户的订单信息
-		user.POST("/order", GetUserOrder)
-		//用户登录
-		user.POST("/login", login)
-		//注册
-		user.POST("/register", register)
-
-		//发送邮箱注册验证码
-		user.POST("/registerCode", registerCode)
-		//发送验证码
-		user.POST("/sendSms", SendVerificationCode)
-		//图片验证码
-		user.GET("/captcha", VerificationCode)
-	}
+	//{
+	//	//获取用户基本信息
+	//	user.GET("/info", GetUserInfo)
+	//	//获取用户钱包
+	//	user.GET("/wallet", GetUserWallet)
+	//	//修改名字
+	//	user.PUT("/name", SetNameValue)
+	//	//获取用户的订单信息
+	//	user.POST("/order", GetUserOrder)
+	//	//用户登录
+	//	user.POST("/login", login)
+	//	//注册
+	//	user.POST("/register", register)
+	//
+	//	//发送邮箱注册验证码
+	//	user.POST("/registerCode", registerCode)
+	//	//发送验证码
+	//	user.POST("/sendSms", SendVerificationCode)
+	//	//图片验证码
+	//	user.GET("/captcha", VerificationCode)
+	//}
+	//获取用户基本信息
+
+	PushRouter(user, "POST", "/info", GetUserInfo)
+	//获取用户钱包
+	PushRouter(user, "GET", "/wallet", GetUserWallet)
+	//修改名字
+	PushRouter(user, "PUT", "/name", SetNameValue)
+	//获取用户的订单信息
+	PushRouter(user, "POST", "/order", GetUserOrder)
+	//用户登录
+	PushRouter(user, "POST", "/login", login)
+	//注册
+	PushRouter(user, "POST", "/register", register)
+	//发送邮箱注册验证码
+	PushRouter(user, "POST", "/registerCode", registerCode)
+	//发送验证码
+	PushRouter(user, "POST", "/sendSms", SendVerificationCode)
+	//图片验证码
+	PushRouter(user, "GET", "/captcha", VerificationCode)
 }
 
 // GetUserInfo 获取用户的个人信息
@@ -120,8 +139,6 @@ func GetUserOrder(c *gin.Context) {
 	c.JSON(200, CreateResultData(vo))
 }
 
-////
-
 func VerificationCode(c *gin.Context) {
 	// 配置
 	driver := base64Captcha.NewDriverDigit(80, 240, 4, 0.5, 80)
@@ -134,7 +151,7 @@ func VerificationCode(c *gin.Context) {
 		c.JSON(500, gin.H{"error": err.Error()})
 		return
 	}
-	fmt.Println(answer)
+
 	err = configs.RedisDb.Set(ctx, "VerificationCode_"+id, answer, 0).Err()
 	if err != nil {
 		fmt.Println(err)
@@ -150,7 +167,6 @@ func VerificationCode(c *gin.Context) {
 		"code":    200,
 		"data":    map[string]string{"id": id, "image": b64s},
 	})
-
 }
 
 func login(c *gin.Context) {