├── models ├── goodsItemAttr.go ├── roleAccess.go ├── role.go ├── goodsType.go ├── goodsColor.go ├── user.go ├── focus.go ├── captcha.go ├── core.go ├── nav.go ├── manager.go ├── goodsImage.go ├── goodsAttr.go ├── orderItem.go ├── address.go ├── goodsTypeAttribute.go ├── goodsCate.go ├── access.go ├── order.go ├── cart.go ├── cookie.go ├── setting.go ├── cache.go ├── goods.go └── tools.go ├── static └── look me.txt ├── middleware ├── defaultAuth.go └── adminAuth.go ├── views ├── mindex │ ├── public │ │ ├── user_left.html │ │ ├── page_footer.html │ │ ├── page_header.html │ │ └── banner.html │ ├── cart │ │ ├── addcart_success.html │ │ └── cart.html │ ├── index │ │ ├── login.html │ │ └── pass.html │ ├── product │ │ ├── list.html │ │ └── item.html │ └── buy │ │ └── confirm.html └── admin │ ├── main │ ├── welcome.html │ └── index.html │ ├── public │ ├── page_header.html │ ├── page_nav.html │ ├── email.html │ ├── success.html │ ├── error.html │ ├── page_aside.html │ └── privilege.html │ ├── role │ ├── add.html │ ├── edit.html │ ├── index.html │ └── auth.html │ ├── login.html │ ├── manager │ ├── add.html │ ├── edit.html │ └── index.html │ ├── goodsType │ ├── add.html │ ├── edit.html │ └── index.html │ ├── focus │ ├── add.html │ ├── edit.html │ └── index.html │ ├── nav │ ├── add.html │ ├── edit.html │ └── index.html │ ├── goodsCate │ ├── add.html │ ├── edit.html │ └── index.html │ ├── access │ ├── add.html │ ├── index.html │ └── edit.html │ ├── goodsTypeAttribute │ ├── add.html │ ├── edit.html │ └── index.html │ ├── setting │ └── index.html │ └── goods │ └── index.html ├── conf └── app.conf ├── main.go ├── go.mod ├── controllers ├── admin │ ├── setting.go │ ├── login.go │ ├── goodsType.go │ ├── focus.go │ ├── nav.go │ ├── main.go │ ├── manager.go │ ├── access.go │ ├── base.go │ ├── goodsTypeAttr.go │ ├── role.go │ └── goodsCate.go └── mindex │ ├── index.go │ ├── user.go │ ├── base.go │ ├── buy.go │ ├── address.go │ └── product.go ├── tests └── default_test.go ├── routers ├── defaultRouter.go └── adminRouter.go └── README.md /models/goodsItemAttr.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | type GoodsItemAttr struct { 4 | Cate string 5 | List []string 6 | } -------------------------------------------------------------------------------- /static/look me.txt: -------------------------------------------------------------------------------- 1 | 由于项目中的static文件内容较多,而且代码放在GitHub上面,有的同学可能下载速度会很慢,我就将这里面的内容放在了蓝奏云,下载完成后,解压到此目录即可 2 | 3 | https://wwx.lanzoui.com/i3wlPlxmt9e 4 | https://wwx.lanzoui.com/i3wlPlxmt9e 5 | https://wwx.lanzoui.com/i3wlPlxmt9e 6 | 7 | 个人博客网站:https://syjun.vip -------------------------------------------------------------------------------- /models/roleAccess.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | import ( 4 | _ "github.com/jinzhu/gorm" 5 | ) 6 | 7 | type RoleAccess struct { 8 | AccessId int 9 | RoleId int 10 | } 11 | 12 | func (RoleAccess) TableName() string { 13 | return "role_access" 14 | } 15 | -------------------------------------------------------------------------------- /models/role.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | import ( 4 | _ "github.com/jinzhu/gorm" 5 | ) 6 | 7 | type Role struct { 8 | Id int 9 | Title string 10 | Description string 11 | Status int 12 | AddTime int 13 | } 14 | 15 | func (Role) TableName() string { 16 | return "role" 17 | } 18 | -------------------------------------------------------------------------------- /models/goodsType.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | import ( 4 | _ "github.com/jinzhu/gorm" 5 | ) 6 | 7 | type GoodsType struct { 8 | Id int 9 | Title string 10 | Description string 11 | Status int 12 | AddTime int 13 | } 14 | 15 | func (GoodsType) TableName() string { 16 | return "goods_type" 17 | } 18 | -------------------------------------------------------------------------------- /models/goodsColor.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | import ( 4 | _ "github.com/jinzhu/gorm" 5 | ) 6 | 7 | type GoodsColor struct { 8 | Id int 9 | ColorName string 10 | ColorValue string 11 | Status int 12 | Checked bool `gorm:"-"` 13 | } 14 | 15 | func (GoodsColor) TableName() string { 16 | return "goods_color" 17 | } 18 | 19 | -------------------------------------------------------------------------------- /models/user.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | import ( 4 | _ "github.com/jinzhu/gorm" 5 | ) 6 | 7 | type User struct { 8 | Id int 9 | Phone string 10 | Password string 11 | AddTime int 12 | LastIp string 13 | Email string 14 | Status int 15 | } 16 | 17 | func (User) TableName() string { 18 | return "user" 19 | } 20 | 21 | -------------------------------------------------------------------------------- /middleware/defaultAuth.go: -------------------------------------------------------------------------------- 1 | package middleware 2 | 3 | import ( 4 | "github.com/astaxie/beego/context" 5 | "mi.com/models" 6 | ) 7 | 8 | func DefaultAuth(ctx *context.Context) { 9 | // 判断前端用户是否登录 10 | user := models.User{} 11 | models.Cookie.Get(ctx, "userinfo", &user) 12 | if len(user.Phone) != 11 { 13 | ctx.Redirect(302,"/login") 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /models/focus.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | import ( 4 | _ "github.com/jinzhu/gorm" 5 | ) 6 | 7 | type Focus struct { 8 | Id int 9 | Title string 10 | FocusType int 11 | FocusImg string 12 | Link string 13 | Sort int 14 | Status int 15 | AddTime int 16 | } 17 | 18 | func (Focus) TableName() string { 19 | return "focus" 20 | } 21 | -------------------------------------------------------------------------------- /views/mindex/public/user_left.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /views/mindex/public/page_footer.html: -------------------------------------------------------------------------------- 1 | 7 | -------------------------------------------------------------------------------- /models/captcha.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | import ( 4 | "github.com/astaxie/beego/cache" 5 | "github.com/astaxie/beego/utils/captcha" 6 | ) 7 | 8 | var Cpt *captcha.Captcha 9 | // verify生成验证码 10 | func init() { 11 | store := cache.NewMemoryCache() 12 | Cpt = captcha.NewWithFilter("/captcha/",store) 13 | Cpt.ChallengeNums = 4 14 | Cpt.StdHeight = 41 15 | Cpt.StdWidth = 250 16 | } -------------------------------------------------------------------------------- /models/core.go: -------------------------------------------------------------------------------- 1 | package models 2 | import ( 3 | "github.com/astaxie/beego" 4 | "github.com/jinzhu/gorm" 5 | _ "github.com/jinzhu/gorm/dialects/mysql" 6 | ) 7 | 8 | var DB *gorm.DB 9 | var err error 10 | 11 | func init() { 12 | DB,err = gorm.Open("mysql", "root:123456@/micom?charset=utf8&parseTime=True&loc=Local") 13 | if err != nil { 14 | beego.Error(err) 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /conf/app.conf: -------------------------------------------------------------------------------- 1 | appname = mi.com 2 | httpport = 8080 3 | runmode = dev 4 | sessionon = true 5 | sessiongcmaxlifetime = 3600 6 | SessionName = "micom" 7 | adminPath = admin 8 | excludeAuthPath = "/,/welcome,/login/loginOut,/privilege" 9 | ossDomain = "http://bee.sunyj.xyz" 10 | ossStatus = false 11 | resizeImageSize = 200,400 12 | enableRedis=true 13 | redisKey="micom" 14 | redisConn=":6379" 15 | redisDbNum="0" 16 | redisPwd="" 17 | redisTime=3600 -------------------------------------------------------------------------------- /models/nav.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | import ( 4 | _ "github.com/jinzhu/gorm" 5 | ) 6 | 7 | type Nav struct { 8 | Id int 9 | Title string 10 | Link string 11 | Position int 12 | IsOpennew int 13 | Relation string 14 | Sort int 15 | Status int 16 | AddTime int 17 | GoodsItem []Goods `gorm:"-"` 18 | GoodsNil string `gorm:"-"` 19 | } 20 | 21 | func (Nav) TableName() string { 22 | return "nav" 23 | } 24 | -------------------------------------------------------------------------------- /models/manager.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | import ( 4 | _ "github.com/jinzhu/gorm" 5 | ) 6 | 7 | type Manager struct { 8 | Id int 9 | Username string 10 | Password string 11 | Mobile string 12 | Email string 13 | Status int 14 | RoleId int 15 | AddTime int 16 | IsSuper int 17 | Role Role `gorm:"foreignkey:Id;association_foreignkey:RoleId"` 18 | } 19 | 20 | func (Manager) TableName() string { 21 | return "manager" 22 | } 23 | -------------------------------------------------------------------------------- /models/goodsImage.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | import ( 4 | _ "github.com/jinzhu/gorm" 5 | ) 6 | 7 | type GoodsImage struct { 8 | Id int `json:"id"` 9 | GoodsId int `json:"goods_id"` 10 | ImgUrl string `json:"img_url"` 11 | ColorId int `json:"color_id"` 12 | Sort int `json:"sort"` 13 | AddTime int `json:"add_time"` 14 | Status int `json:"status"` 15 | } 16 | 17 | func (GoodsImage) TableName() string { 18 | return "goods_image" 19 | } 20 | -------------------------------------------------------------------------------- /models/goodsAttr.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | import ( 4 | _ "github.com/jinzhu/gorm" 5 | ) 6 | 7 | type GoodsAttr struct { 8 | Id int 9 | GoodsId int 10 | AttributeCateId int 11 | AttributeId int 12 | AttributeTitle string 13 | AttributeType int 14 | AttributeValue string 15 | Sort int 16 | AddTime int 17 | Status int 18 | } 19 | 20 | func (GoodsAttr) TableName() string { 21 | return "goods_attr" 22 | } 23 | -------------------------------------------------------------------------------- /models/orderItem.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | import ( 4 | _ "github.com/jinzhu/gorm" 5 | ) 6 | 7 | type OrderItem struct { 8 | Id int 9 | OrderId int 10 | Uid int 11 | ProductTitle string 12 | ProductId int 13 | ProductImg string 14 | ProductPrice float64 15 | ProductNum int 16 | GoodsVersion string 17 | GoodsColor string 18 | AddTime int 19 | } 20 | 21 | func (OrderItem) TableName() string { 22 | return "order_item" 23 | } 24 | -------------------------------------------------------------------------------- /views/admin/main/welcome.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 12 | 13 | 14 |
15 |

欢迎来到小米商城GoLang后台管理中心

16 | 17 |
18 | 19 | 20 | -------------------------------------------------------------------------------- /views/admin/main/index.html: -------------------------------------------------------------------------------- 1 | {{template "../public/page_header.html" .}} 2 | {{template "../public/page_nav.html" .}} 3 |
4 |
5 |
6 | {{template "../public/page_aside.html" .}} 7 |
8 |
9 | 10 |
11 |
12 |
13 | 14 | -------------------------------------------------------------------------------- /models/address.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | import ( 4 | _ "github.com/jinzhu/gorm" 5 | ) 6 | 7 | type Address struct { 8 | Id int `json:"id"` 9 | Uid int `json:"uid"` 10 | Phone string `json:"phone"` 11 | Name string `json:"name"` 12 | Address string `json:"address"` 13 | Zipcode string `json:"zipcode"` 14 | DefaultAddress int `json:"default_address"` 15 | AddTime int `json:"add_time"` 16 | } 17 | 18 | func (Address) TableName() string { 19 | return "address" 20 | } 21 | -------------------------------------------------------------------------------- /models/goodsTypeAttribute.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | import ( 4 | _ "github.com/jinzhu/gorm" 5 | ) 6 | 7 | type GoodsTypeAttribute struct { 8 | Id int `json:"id"` 9 | CateId int `json:"cate_id"` 10 | Title string `json:"title"` 11 | AttrType int `json:"attr_type"` 12 | AttrValue string `json:"attr_value"` 13 | Status int `json:"status"` 14 | Sort int `json:"sort"` 15 | AddTime int `json:"add_time"` 16 | } 17 | 18 | func (GoodsTypeAttribute) TableName() string { 19 | return "goods_type_attribute" 20 | } 21 | -------------------------------------------------------------------------------- /models/goodsCate.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | import ( 4 | _ "github.com/jinzhu/gorm" 5 | ) 6 | 7 | type GoodsCate struct { 8 | Id int 9 | Title string 10 | CateImg string 11 | Link string 12 | Template string 13 | Pid int 14 | SubTitle string 15 | Keywords string 16 | Description string 17 | Sort int 18 | Status int 19 | AddTime int 20 | GoodsCateItem []GoodsCate `gorm:"foreignkey:Pid;association_foreignkey:Id"` 21 | } 22 | 23 | func (GoodsCate) TableName() string { 24 | return "goods_cate" 25 | } 26 | -------------------------------------------------------------------------------- /models/access.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | import ( 4 | _ "github.com/jinzhu/gorm" 5 | ) 6 | 7 | type Access struct { 8 | Id int 9 | ModuleName string //模块名称 10 | ActionName string //操作名称 11 | Type int //节点类型 : 1、表示模块 2、表示菜单 3、操作 12 | Url string //路由跳转地址 13 | ModuleId int //此module_id和当前模型的_id关联 module_id= 0 表示模块 14 | Sort int 15 | Description string 16 | Status int 17 | AddTime int 18 | AccessItem []Access `gorm:"foreignkey:ModuleId;association_foreignkey:Id"` 19 | Checked bool `gorm:"-"` // 忽略本字段 20 | } 21 | 22 | func (Access) TableName() string { 23 | return "access" 24 | } 25 | -------------------------------------------------------------------------------- /models/order.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | import ( 4 | _ "github.com/jinzhu/gorm" 5 | ) 6 | 7 | type Order struct { 8 | Id int 9 | OrderId string 10 | Uid int 11 | AllPrice float64 12 | Phone string 13 | Name string 14 | Address string 15 | Zipcode string 16 | PayStatus int // 支付状态: 0 表示未支付 1 已经支付 17 | PayType int // 支付类型: 0 alipay 1 wechat 18 | OrderStatus int // 订单状态: 0 已下单 1 已付款 2 已配货 3、发货 4、交易成功 5、退货 6、取消 19 | AddTime int 20 | OrderItem []OrderItem `gorm:"foreignkey:OrderId;association_foreignkey:id"` 21 | } 22 | 23 | func (Order) TableName() string { 24 | return "order" 25 | } 26 | -------------------------------------------------------------------------------- /views/admin/public/page_header.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 小米商城后台管理 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /views/admin/public/page_nav.html: -------------------------------------------------------------------------------- 1 | 19 | -------------------------------------------------------------------------------- /views/admin/public/email.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 邮箱提示信息 8 | 9 | 10 | 11 |
12 |
13 |
14 |

邮件发送成功

15 |
16 |

请登录您的邮箱进行验证

17 |
18 | 19 |
20 |
21 |
22 | 23 | 24 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/gob" 5 | "github.com/astaxie/beego" 6 | _ "github.com/astaxie/beego/session/redis" 7 | "mi.com/models" 8 | _ "mi.com/routers" 9 | ) 10 | 11 | func init() { 12 | gob.Register(models.Manager{}) 13 | } 14 | 15 | func main() { 16 | // 注册模板函数 17 | beego.AddFuncMap("unixToDate",models.UnixToDate) 18 | beego.AddFuncMap("formatImg",models.FormatImg) 19 | beego.AddFuncMap("formatAttr",models.FormatAttr) 20 | beego.AddFuncMap("cutStr",models.CutStr) 21 | beego.AddFuncMap("mul",models.Mul) 22 | beego.AddFuncMap("judge",models.Judge) 23 | 24 | // 配置session保存在redis里面 25 | beego.BConfig.WebConfig.Session.SessionProvider = "redis" 26 | beego.BConfig.WebConfig.Session.SessionProviderConfig = "127.0.0.1:6379" 27 | beego.Run() 28 | defer models.DB.Close() 29 | } 30 | 31 | -------------------------------------------------------------------------------- /models/cart.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | type Cart struct { 4 | Id int 5 | Title string 6 | Price float64 7 | GoodsVersion string 8 | Num int 9 | GoodsGift string 10 | GoodsFitting string 11 | GoodsColor string 12 | GoodsImg string 13 | GoodsAttr string 14 | Checked bool `gorm:"-"` // 忽略本字段 15 | } 16 | 17 | func (Cart) TableName() string { 18 | return "cart" 19 | } 20 | 21 | //判断购物车里面有没有当前数据 22 | func CartHasData(cartList []Cart, currentData Cart,isPlus bool) bool { 23 | for i := 0; i < len(cartList); i++ { 24 | if cartList[i].Id == currentData.Id && cartList[i].GoodsColor == currentData.GoodsColor && cartList[i].GoodsAttr == currentData.GoodsAttr { 25 | if isPlus { 26 | cartList[i].Num = cartList[i].Num+1 27 | return true 28 | } 29 | return true 30 | } 31 | } 32 | return false 33 | } 34 | -------------------------------------------------------------------------------- /views/admin/public/success.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 提示信息 9 | 10 | 11 | 12 |
13 |
14 |
15 |

操作成功-{{.message}}

16 |
17 |

如果您不做出选择,将在 2秒后跳转到上一个链接地址

18 |
19 | 20 |
21 |
22 |
23 | 24 | 25 | -------------------------------------------------------------------------------- /views/admin/public/error.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 提示信息 9 | 10 | 11 | 12 | 13 |
14 |
15 |
16 |

操作失败-{{.message}}!

17 |
18 |

如果您不做出选择,2秒后将自动返回上一个页面

19 | 20 |
21 | 22 |
23 |
24 |
25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module mi.com 2 | 3 | go 1.15 4 | 5 | require github.com/astaxie/beego v1.12.1 6 | 7 | require ( 8 | github.com/aliyun/aliyun-oss-go-sdk v2.1.6+incompatible 9 | github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f // indirect 10 | github.com/gomarkdown/markdown v0.0.0-20210208175418-bda154fe17d8 11 | github.com/gomarkdown/mdtohtml v0.0.0-20180202094705-7346712f31b4 // indirect 12 | github.com/hunterhug/go_image v0.0.0-20190710020854-8922226c5f4b 13 | github.com/jinzhu/gorm v1.9.16 14 | github.com/satori/go.uuid v1.2.0 // indirect 15 | github.com/shiena/ansicolor v0.0.0-20200904210342-c7312218db18 // indirect 16 | github.com/smartystreets/goconvey v1.6.4 17 | golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 // indirect 18 | gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect 19 | gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df 20 | ) 21 | -------------------------------------------------------------------------------- /models/cookie.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | "github.com/astaxie/beego/context" 7 | ) 8 | 9 | //定义结构体 缓存结构体 私有 10 | type cookie struct{} 11 | 12 | //写入数据的方法 13 | func (c cookie) Set(ctx *context.Context, key string, value interface{}) { 14 | bytes, _ := json.Marshal(value) 15 | ctx.SetSecureCookie("micom", key, string(bytes), 3600*24*30) 16 | 17 | } 18 | 19 | //获取数据的方法 20 | func (c cookie) Get(ctx *context.Context, key string, obj interface{}) bool { 21 | tempData, ok := ctx.GetSecureCookie("micom", key) 22 | if !ok { 23 | return false 24 | } 25 | json.Unmarshal([]byte(tempData), obj) 26 | return true 27 | 28 | } 29 | 30 | //删除指定Cookie 31 | func (c cookie) Remove(ctx *context.Context, key string, value interface{}) { 32 | bytes, _ := json.Marshal(value) 33 | ctx.SetSecureCookie("micom", key, string(bytes), -1) 34 | } 35 | 36 | //实例化结构体 37 | var Cookie = &cookie{} 38 | -------------------------------------------------------------------------------- /models/setting.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | import ( 4 | _ "github.com/jinzhu/gorm" 5 | ) 6 | 7 | type Setting struct { 8 | Id int `form:"id"` 9 | SiteTitle string `form:"site_title"` 10 | SiteLogo string `form:"site_logo"` 11 | SiteKeywords string `form:"site_keywords"` 12 | SiteDescription string `form:"site_description"` 13 | NoPicture string `form:"no_picture"` 14 | SiteIcp string `form:"site_icp"` 15 | SiteTel string `form:"site_tel"` 16 | SearchKeywords string `form:"search_keywords"` 17 | TongjiCode string `form:"tongji_code"` 18 | Appid string `form:"appid"` 19 | AppSecret string `form:"app_secret"` 20 | EndPoint string `form:"end_point"` 21 | BucketName string `form:"bucket_name"` 22 | OssStatus int `form:"oss_status"` 23 | } 24 | 25 | func (Setting) TableName() string { 26 | return "setting" 27 | } 28 | 29 | -------------------------------------------------------------------------------- /controllers/admin/setting.go: -------------------------------------------------------------------------------- 1 | package admin 2 | 3 | import ( 4 | "mi.com/models" 5 | ) 6 | 7 | type SettingController struct { 8 | BaseController 9 | } 10 | 11 | func (this *SettingController) Get() { 12 | setting := models.Setting{} 13 | models.DB.First(&setting) 14 | this.Data["setting"] = setting 15 | this.TplName = "admin/setting/index.html" 16 | } 17 | 18 | func (this *SettingController) DoEdit() { 19 | //1、获取数据库里面的数据 20 | setting := models.Setting{} 21 | models.DB.Find(&setting) 22 | //2、修改数据 23 | this.ParseForm(&setting) 24 | //上传图片 site_logo 25 | siteLogo, err1 := this.UploadImg("site_logo") 26 | if len(siteLogo) > 0 && err1 == nil { 27 | setting.SiteLogo = siteLogo 28 | } 29 | //上传图片no_picture 30 | noPicture, err2 := this.UploadImg("no_picture") 31 | if len(noPicture) > 0 && err2 == nil { 32 | setting.NoPicture = noPicture 33 | } 34 | //执行保存数据 35 | err3 := models.DB.Where("id=1").Save(&setting).Error 36 | if err3 != nil { 37 | this.Error("修改数据失败", "/setting") 38 | return 39 | } 40 | this.Success("修改数据成功", "/setting") 41 | 42 | } 43 | 44 | -------------------------------------------------------------------------------- /tests/default_test.go: -------------------------------------------------------------------------------- 1 | package test 2 | 3 | import ( 4 | "net/http" 5 | "net/http/httptest" 6 | "testing" 7 | "runtime" 8 | "path/filepath" 9 | _ "mi.com/routers" 10 | 11 | "github.com/astaxie/beego" 12 | . "github.com/smartystreets/goconvey/convey" 13 | ) 14 | 15 | func init() { 16 | _, file, _, _ := runtime.Caller(0) 17 | apppath, _ := filepath.Abs(filepath.Dir(filepath.Join(file, ".." + string(filepath.Separator)))) 18 | beego.TestBeegoInit(apppath) 19 | } 20 | 21 | 22 | // TestBeego is a sample to run an endpoint test 23 | func TestBeego(t *testing.T) { 24 | r, _ := http.NewRequest("GET", "/", nil) 25 | w := httptest.NewRecorder() 26 | beego.BeeApp.Handlers.ServeHTTP(w, r) 27 | 28 | beego.Trace("testing", "TestBeego", "Code[%d]\n%s", w.Code, w.Body.String()) 29 | 30 | Convey("Subject: Test Station Endpoint\n", t, func() { 31 | Convey("Status Code Should Be 200", func() { 32 | So(w.Code, ShouldEqual, 200) 33 | }) 34 | Convey("The Result Should Not Be Empty", func() { 35 | So(w.Body.Len(), ShouldBeGreaterThan, 0) 36 | }) 37 | }) 38 | } 39 | 40 | -------------------------------------------------------------------------------- /controllers/admin/login.go: -------------------------------------------------------------------------------- 1 | package admin 2 | 3 | import ( 4 | "mi.com/models" 5 | "strings" 6 | ) 7 | 8 | 9 | type LoginController struct { 10 | BaseController 11 | } 12 | 13 | func (this *LoginController) Get() { 14 | this.TplName="admin/login.html" 15 | } 16 | 17 | func (this *LoginController) Dologin() { 18 | // 1:验证用户输入的验证码是否正确 19 | flag := models.Cpt.VerifyReq(this.Ctx.Request) 20 | if flag { 21 | // 2:获取表单传过来的用户名和密码 22 | username := strings.Trim(this.GetString("username"),"") 23 | password := models.Md5(strings.Trim(this.GetString("password"),"")) 24 | // 3:根据表单里面的内容与数据库中的数据进行比较 25 | manager := []models.Manager{} 26 | // 条件查询,如果存在返回给manager数据 27 | models.DB.Where("username=? AND password=?",username,password).Find(&manager) 28 | if len(manager)>0 { 29 | if manager[0].Status != 0 { 30 | // 登录成功 31 | // 1:保存用户信息 32 | this.SetSession("userinfo",manager[0]) 33 | // 2:跳转到后台首页 34 | this.Ctx.Redirect(302,"/admin/") 35 | }else { 36 | this.Error("你已被移除管理员身份","/login") 37 | } 38 | 39 | }else { 40 | this.Error("账号或密码输入错误","/login") 41 | } 42 | 43 | }else { 44 | this.Error("验证码输入错误","/login") 45 | } 46 | } 47 | func (this *LoginController) LoginOut() { 48 | this.DelSession("userinfo") 49 | this.Success("退出登录成功","/login") 50 | } 51 | 52 | 53 | -------------------------------------------------------------------------------- /views/mindex/public/page_header.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 小米商城 GoLang 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 |
20 |
21 |
    22 | {{range $key,$value := .topNavList}} 23 |
  • {{$value.Title}}
  • 24 | {{end}} 25 |
    26 |
27 |
28 |
29 | 30 |
31 | {{str2html .userinfo}} 32 |
33 |
34 |
35 |
36 |
37 |
38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /views/admin/role/add.html: -------------------------------------------------------------------------------- 1 | {{template "../public/page_header.html" .}} 2 | 3 |
4 |
5 |
6 | 7 |
8 |
9 | 增加角色 10 |
11 |
12 |
13 |
14 |
    15 |
  • 角色名称:
  • 16 |
  • 17 | 角色描述: 18 | 19 |
  • 20 | 21 |
  • 22 |
    23 | 24 |
  • 25 | 26 |
27 | 28 |
29 |
30 |
31 | 32 | 33 |
34 | 35 |
36 |
37 |
38 | 39 | -------------------------------------------------------------------------------- /views/admin/public/page_aside.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /views/admin/role/edit.html: -------------------------------------------------------------------------------- 1 | {{template "../public/page_header.html" .}} 2 | 3 |
4 |
5 |
6 | 7 |
8 |
9 | 编辑角色 10 |
11 |
12 |
13 |
14 |
    15 | 16 |
  • 角色名称:
  • 17 |
  • 18 | 角色描述: 19 | 20 |
  • 21 | 22 |
  • 23 |
    24 | 25 |
  • 26 | 27 |
28 | 29 |
30 |
31 |
32 | 33 | 34 |
35 | 36 |
37 |
38 |
39 | 40 | -------------------------------------------------------------------------------- /views/admin/login.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 小米商城后台登录 8 | 9 | 10 | 11 | 12 |
13 | 14 |
15 |
16 |

小米商城后台登录

17 |
Powered By: Java_S
18 |
19 | 20 | 21 | 22 | {{create_captcha}} 23 | 24 |
25 | 26 |
27 | 28 | 41 |
42 | 43 |
44 | 45 | 46 | -------------------------------------------------------------------------------- /models/cache.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "github.com/astaxie/beego" 7 | "github.com/astaxie/beego/cache" 8 | _ "github.com/astaxie/beego/cache/redis" 9 | "time" 10 | ) 11 | 12 | var redisClient cache.Cache 13 | var enableRedis, _ = beego.AppConfig.Bool("enableRedis") 14 | var redisTime,_ = beego.AppConfig.Int("redisTime") 15 | 16 | func init() { 17 | if enableRedis { 18 | config := map[string]string{ 19 | "key": beego.AppConfig.String("redisKey"), 20 | "conn": beego.AppConfig.String("redisConn"), 21 | "dbNum": beego.AppConfig.String("redisDbNum"), 22 | "password": beego.AppConfig.String("redisPwd"), 23 | } 24 | bytes, _ := json.Marshal(config) 25 | redisClient, err = cache.NewCache("redis", string(bytes)) 26 | if err != nil { 27 | fmt.Println(err) 28 | fmt.Println("连接redis数据库失败") 29 | } else { 30 | fmt.Println("连接redis数据库成功") 31 | } 32 | } 33 | } 34 | 35 | // 定义结构体 36 | type cacheDb struct {} 37 | 38 | // redis写入数据 39 | func (c cacheDb) Set(key string,value interface{}) { 40 | if enableRedis { 41 | bytes,_ := json.Marshal(value) 42 | redisClient.Put(key,string(bytes),time.Second*time.Duration(redisTime)) 43 | } 44 | } 45 | 46 | // redis获取数据 47 | func (c cacheDb) Get(key string,obj interface{}) bool { 48 | if enableRedis { 49 | if redisStr := redisClient.Get(key);redisStr != nil{ 50 | redisValue,_ := redisStr.([]uint8) 51 | json.Unmarshal([]byte(redisValue),obj) 52 | return true 53 | } 54 | return false 55 | } 56 | return false 57 | } 58 | 59 | // 实例化cacheDb结构体 60 | var CacheDb = &cacheDb{} -------------------------------------------------------------------------------- /views/admin/role/index.html: -------------------------------------------------------------------------------- 1 | {{template "../public/page_header.html" .}} 2 | 3 |
4 |
5 |
6 |
7 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | {{range $key, $val := .role}} 24 | 25 | 26 | 27 | 28 | 35 | 36 | {{end}} 37 | 38 | 39 |
角色名称角色描述添加时间操作
{{$val.Title}}{{$val.Description}}{{$val.AddTime | unixToDate}} 29 | 30 | 授权 31 | 编辑 32 | 删除 33 | 34 |
40 |
41 | 42 |
43 |
44 | 45 | 46 | -------------------------------------------------------------------------------- /views/admin/role/auth.html: -------------------------------------------------------------------------------- 1 | {{template "../public/page_header.html" .}} 2 | 3 |
4 |
5 |
6 | 7 | 8 |

{{.roleName}}---权限管理

9 | 10 | 11 | {{range $key,$value := .accessList}} 12 | 13 | 19 | 30 | 31 | {{end}} 32 | 33 | 34 |
14 | 18 | 20 | 21 | {{range $k,$v := $value.AccessItem}} 22 |    23 | 26 |    27 | {{end}} 28 | 29 |
35 | 36 | 37 |
38 |
39 |
40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /controllers/mindex/index.go: -------------------------------------------------------------------------------- 1 | package mindex 2 | 3 | import ( 4 | "mi.com/models" 5 | ) 6 | 7 | type IndexController struct { 8 | BaseController 9 | } 10 | 11 | func (this *IndexController) Get() { 12 | // 调用公共的功能 13 | this.SuperInit() 14 | 15 | //获取轮播图 16 | focus := []models.Focus{} 17 | if hasFocus := models.CacheDb.Get("focus",&focus); hasFocus == true { 18 | this.Data["focusList"] = focus 19 | } else { 20 | models.DB.Where("status=1 AND focus_type=1").Order("sort desc").Find(&focus) 21 | this.Data["focusList"] = focus 22 | models.CacheDb.Set("focus",focus) 23 | } 24 | 25 | // 获取手机楼层数据 26 | redisPhone := []models.Goods{} 27 | if hasPhone := models.CacheDb.Get("phone", &redisPhone); hasPhone == true { 28 | this.Data["phoneList"] = redisPhone 29 | } else { 30 | phone := models.GetGoodsByCategory(33, "hot", 8) 31 | this.Data["phoneList"] = phone 32 | models.CacheDb.Set("phone", phone) 33 | } 34 | 35 | // 获取家电楼层数据 36 | redisAppliances := []models.Goods{} 37 | if hasAppliances := models.CacheDb.Get("appliances", &redisAppliances); hasAppliances == true { 38 | this.Data["appliancesList"] = redisAppliances 39 | } else { 40 | appliances := models.GetGoodsByCategory(50, "hot", 8) 41 | this.Data["appliancesList"] = appliances 42 | models.CacheDb.Set("appliances", appliances) 43 | } 44 | 45 | // 获取智能楼层数据 46 | redisSmart := []models.Goods{} 47 | if hasSmart := models.CacheDb.Get("smart", &redisSmart); hasSmart == true { 48 | this.Data["smartList"] = redisSmart 49 | } else { 50 | smart := models.GetGoodsByCategory(52, "hot", 8) 51 | this.Data["smartList"] = smart 52 | models.CacheDb.Set("smart", smart) 53 | } 54 | 55 | this.TplName = "mindex/index/index.html" 56 | } 57 | -------------------------------------------------------------------------------- /views/admin/manager/add.html: -------------------------------------------------------------------------------- 1 | {{template "../public/page_header.html" .}} 2 | 3 |
4 |
5 |
6 |
7 | 增加管理员 8 |
9 |
10 |
11 |
12 |
    13 |
  • 管理员名称:
  • 14 |
  • 管理员密码:
  • 15 |
  • 管理员电话:
  • 16 |
  • 管理员邮箱:
  • 17 |
  • 管理员角色: 18 | 19 | 24 | 25 | 26 |
  • 27 |
  • 28 |
    29 | 30 |
  • 31 | 32 |
33 | 34 | 35 |
36 |
37 |
38 | 39 | 40 |
41 | 42 |
43 |
44 | 45 | 46 | -------------------------------------------------------------------------------- /views/admin/goodsType/add.html: -------------------------------------------------------------------------------- 1 | {{template "../public/page_header.html"}} 2 | 3 |
4 |
5 | 6 |
7 |
8 | 增加商品类型 9 |
10 |
11 |
12 |
13 |
    14 |
  • 类型名称:
  • 15 | 16 |
  • 17 | 类型描述: 18 | 19 |
  • 20 | 21 | 22 | 23 | 24 |
  • 状  态: 25 | 26 | 27 |  
  • 28 |
  • 29 | 30 |
  • 31 |
    32 | 33 |
  • 34 |
35 | 36 | 37 |
38 |
39 |
40 | 41 | 42 |
43 | 44 |
45 |
46 | 47 | -------------------------------------------------------------------------------- /middleware/adminAuth.go: -------------------------------------------------------------------------------- 1 | package middleware 2 | 3 | import ( 4 | "mi.com/models" 5 | "github.com/astaxie/beego" 6 | "github.com/astaxie/beego/context" 7 | "net/url" 8 | "strings" 9 | ) 10 | 11 | func AdminAuth(ctx *context.Context) { 12 | adminPath := beego.AppConfig.String("adminPath") 13 | userinfo,ok := ctx.Input.Session("userinfo").(models.Manager) 14 | pathname := ctx.Request.URL.String() 15 | // 判断进入后台的用户是否登录 16 | if !(ok&&userinfo.Username != "") { // 若没有登录重定向登录页面 17 | if pathname!= "/"+adminPath+"/login" && pathname!="/"+adminPath+"/login/doLogin" { 18 | ctx.Redirect(302, "/"+adminPath+"/login") 19 | } 20 | }else { // 若登录,判断此用户的权限是否可以访问相应的路由 21 | pathname = strings.Replace(pathname,"/"+adminPath,"",1) 22 | urlObj,_ := url.Parse(pathname) 23 | // 判断管理员是否是超级管理员 24 | if userinfo.IsSuper != 1 && !excludeAuthPath(urlObj.Path) { 25 | // 1:根据角色ID获取当前角色的权限列表,然后把权限ID放在一个map类型的对象里面 26 | roleId := userinfo.RoleId 27 | roleAccess := []models.RoleAccess{} 28 | models.DB.Where("role_id=?",roleId).Find(&roleAccess) 29 | roleAccessMap := make(map[int]int) 30 | for _, val := range roleAccess { 31 | roleAccessMap[val.AccessId] = val.AccessId 32 | } 33 | // 2:获取当前访问的url(row--->23-24),并获取对应的权限id 34 | access := models.Access{} 35 | models.DB.Where("url=?",urlObj.Path).Find(&access) 36 | // 3:判断当前用户访问的路由,是否在用户所拥有的权限列表中 37 | if _,ok := roleAccessMap[access.Id];!ok { 38 | //ctx.WriteString("请注意素质,你没有权限访问!") 39 | ctx.Redirect(302,"/admin/privilege") 40 | return 41 | } 42 | } 43 | } 44 | } 45 | 46 | func excludeAuthPath(urlPath string) bool { 47 | excludeAuthPathSlice := strings.Split(beego.AppConfig.String("excludeAuthPath"),",") 48 | for _, val := range excludeAuthPathSlice { 49 | if val == urlPath { 50 | return true 51 | } 52 | } 53 | return false 54 | } 55 | 56 | -------------------------------------------------------------------------------- /models/goods.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | import ( 4 | _ "github.com/jinzhu/gorm" 5 | ) 6 | 7 | type Goods struct { 8 | Id int 9 | Title string 10 | SubTitle string 11 | GoodsSn string 12 | CateId int 13 | ClickCount int 14 | GoodsNumber int 15 | Price float64 16 | MarketPrice float64 17 | RelationGoods string 18 | GoodsAttr string 19 | GoodsVersion string 20 | GoodsImg string 21 | GoodsGift string 22 | GoodsFitting string 23 | GoodsColor string 24 | GoodsKeywords string 25 | GoodsDesc string 26 | GoodsContent string 27 | IsDelete int 28 | IsHot int 29 | IsBest int 30 | IsNew int 31 | GoodsTypeId int 32 | Sort int 33 | Status int 34 | AddTime int 35 | } 36 | 37 | func (Goods) TableName() string { 38 | return "goods" 39 | } 40 | 41 | /* 42 | 根据商品分类获取推荐商品 43 | @param {Number} cateId - 分类id 44 | @param {String} goodsType - hot best new 45 | @param {Number} limitNum - 数量 46 | */ 47 | func GetGoodsByCategory(cateId int, goodsType string, limitNum int) []Goods { 48 | goods := []Goods{} 49 | 50 | // 判断cateId是不是顶级分类 51 | goodsCate := []GoodsCate{} 52 | DB.Where("pid=?",cateId).Find(&goodsCate) 53 | var tempSlice []int 54 | if len(goodsCate) >0 { 55 | for i := 0; i 2 | 3 | 4 | 5 | 6 | 7 | NO_PRIVILEGE 8 | 46 | 47 | 48 |
49 |
50 | 51 |
52 |
53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /views/admin/goodsType/edit.html: -------------------------------------------------------------------------------- 1 | {{template "../public/page_header.html"}} 2 | 3 |
4 |
5 | 6 |
7 |
8 | 修改商品类型 9 |
10 |
11 |
12 |
13 |
    14 | 15 | 16 | 17 |
  • 类型名称:
  • 18 | 19 |
  • 20 | 类型描述: 21 | 22 |
  • 23 | 24 |
  • 状  态: 25 | 26 | 27 |  
  • 28 |
  • 29 | 30 |
  • 31 |
    32 | 33 |
  • 34 | 35 |
36 | 37 | 38 |
39 |
40 |
41 | 42 | 43 |
44 | 45 |
46 |
47 | 48 | -------------------------------------------------------------------------------- /views/admin/focus/add.html: -------------------------------------------------------------------------------- 1 | {{template "../public/page_header.html"}} 2 | 3 |
4 |
5 | 6 |
7 |
8 | 增加轮播图 9 |
10 |
11 |
12 |
13 | 14 |
    15 |
  • 类  型: 16 | 21 |
  • 22 |
  • 名  称:
  • 23 |
  • 跳转地址:
  • 24 |
  • 轮 播 图:
  • 25 | 26 |
  • 排  序:
  • 27 | 28 |
  • 状  态: 29 | 30 | 31 |  
  • 32 |
  • 33 |
    34 | 35 |
  • 36 | 37 |
38 | 39 | 40 |
41 |
42 |
43 | 44 | 45 |
46 | 47 |
48 |
49 | 50 | 51 | -------------------------------------------------------------------------------- /views/admin/manager/edit.html: -------------------------------------------------------------------------------- 1 | {{template "../public/page_header.html" .}} 2 | 3 |
4 |
5 |
6 |
7 | 编辑管理员 8 |
9 |
10 |
11 |
12 |
    13 | 14 |
  • 管理员名称:
  • 15 |
  • 管理员密码:
  • 16 |
  • 管理员电话:
  • 17 |
  • 管理员邮箱:
  • 18 |
  • 管理员角色: 19 | 20 | 30 | 31 |
  • 32 |
  • 33 |
    34 | 35 |
  • 36 | 37 |
38 | 39 | 40 |
41 |
42 |
43 | 44 | 45 |
46 | 47 |
48 |
49 | 50 | 51 | -------------------------------------------------------------------------------- /views/admin/manager/index.html: -------------------------------------------------------------------------------- 1 | {{template "../public/page_header.html" .}} 2 |
3 |
4 | 5 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | {{range $key,$value := .managerList}} 23 | 24 | 25 | 26 | 27 | 28 | 29 | 36 | 41 | 42 | {{end}} 43 | 44 |
管理员名称管理员电话管理员邮箱管理员角色创建时间状态操作
{{$value.Username}}{{$value.Mobile}}{{$value.Email}}{{$value.Role.Title}}{{$value.AddTime | unixToDate}} 30 | {{if eq $value.Status 1}} 31 | 32 | {{else}} 33 | 34 | {{end}} 35 | 37 | 编辑 38 | 删除 39 | 40 |
45 |
46 | 47 |
48 |
49 | 50 | 51 | -------------------------------------------------------------------------------- /views/admin/nav/add.html: -------------------------------------------------------------------------------- 1 | {{template "../public/page_header.html" .}} 2 | 3 |
4 |
5 |
6 |
7 | 增加导航 8 |
9 |
10 |
11 |
12 |
    13 | 14 | 15 |
  • 导航名称:
  • 16 | 17 |
  • 导航位置: 18 | 19 | 24 |
  • 25 | 26 |
  • 关联商品:
  • 27 | 28 |
  • 导航链接地址:
  • 29 | 30 |
  • 新窗口打开: 31 | 35 | 36 |
  • 排序:
  • 37 | 38 |
  • 状态:  
  • 41 | 42 | 43 |
  • 44 |
    45 | 46 |
  • 47 | 48 |
49 | 50 | 51 | 52 | 53 |
54 |
55 |
56 | 57 | 58 |
59 | 60 |
61 |
62 | 63 | 64 | -------------------------------------------------------------------------------- /views/mindex/cart/addcart_success.html: -------------------------------------------------------------------------------- 1 | {{template "../public/page_header.html" .}} 2 | {{template "../public/banner.html" .}} 3 | 79 | 80 |
81 | 82 |
83 |
84 |
85 | 86 |
87 |
88 |

已成功加入购物车!

89 | {{.goods.Title}} -- {{.GoodsColor}} -- {{.goods.GoodsVersion}} 90 |
91 |
92 | 93 | 97 |
98 | 99 |
100 | 101 | {{template "../public/page_footer.html" .}} 102 | 103 | 104 | -------------------------------------------------------------------------------- /views/admin/goodsType/index.html: -------------------------------------------------------------------------------- 1 | {{template "../public/page_header.html"}} 2 | 3 |
4 |
5 |
6 | 9 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | {{range $key,$value := .goodsTypeList}} 24 | 25 | 26 | 27 | 28 | 29 | 37 | 38 | 39 | 47 | 48 | 49 | {{end}} 50 | 51 |
商品类型名称商品类型描述状态操作
{{$value.Title}}{{$value.Description}} 30 | 31 | {{if eq $value.Status 1}} 32 | 33 | {{else}} 34 | 35 | {{end}} 36 | 40 | 属性列表  41 | 42 | 编辑   43 | 删除 45 | 46 |
52 | 53 |
54 |
55 |
56 |
57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /views/mindex/index/login.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 登录账号 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 26 | 27 | 28 | 39 | 40 | 41 | 42 |
43 |
44 |
45 | 46 |
47 |
48 | 49 |
50 |
51 |
52 |
53 | 54 | 55 | 56 | 61 | 62 | -------------------------------------------------------------------------------- /views/mindex/product/list.html: -------------------------------------------------------------------------------- 1 | {{template "../public/page_header.html" .}} 2 | {{template "../public/banner.html" .}} 3 | 4 | 5 | 6 |
7 | 8 |
9 |
    10 | 分类: 11 | {{$currentId := .curretGoodsCate.Id}} 12 | {{range $key,$value := .subGoodsCate}} 13 | {{if eq $value.Id $currentId}} 14 | {{if eq $value.Link ""}} 15 |
  • {{$value.Title}}
  • 16 | {{end}} 17 | 18 | {{else}} 19 | {{if eq $value.Link ""}} 20 |
  • {{$value.Title}}
  • 21 | {{end}} 22 | {{end}} 23 | {{end}} 24 |
25 |
26 | 27 | 28 |
29 | {{range $key,$value := .goodsList}} 30 | {{ $numJudge := $key | judge }} 31 | {{if $numJudge }} 32 |
34 | {{else}} 35 |
37 | {{end}} 38 |
39 | 40 | {{$value.Title}} 41 | 42 |
43 | 44 |
{{$value.Price}}元
45 |
46 | {{end}} 47 |
48 | 51 |
52 |
53 | 54 | 55 |
56 | 57 | 58 | 59 | 74 | 75 | {{template "../public/page_footer.html" .}} 76 | 77 | 78 | -------------------------------------------------------------------------------- /routers/defaultRouter.go: -------------------------------------------------------------------------------- 1 | package routers 2 | 3 | import ( 4 | "mi.com/controllers/mindex" 5 | "github.com/astaxie/beego" 6 | "mi.com/middleware" 7 | ) 8 | 9 | func init() { 10 | beego.Router("/", &mindex.IndexController{}) 11 | beego.Router("/login", &mindex.LoginController{}) 12 | beego.Router("/pass", &mindex.LoginController{},"get:Pass") 13 | beego.Router("/pass/login", &mindex.LoginController{},"post:Login") 14 | beego.Router("/pass/loginOut", &mindex.LoginController{},"get:LoginOut") 15 | beego.Router("/pass/setpass", &mindex.LoginController{},"post:SetPass") 16 | beego.Router("/pass/verifyUrl", &mindex.LoginController{},"get:VerifyUrl") 17 | beego.Router("/category_:id([0-9]+).html", &mindex.ProductController{},"get:CategoryList") 18 | beego.Router("/item_:id([0-9]+).html", &mindex.ProductController{},"get:ProductItem") 19 | beego.Router("/product/getImgList", &mindex.ProductController{},"get:GetImgList") 20 | beego.Router("/cart", &mindex.CartController{}) 21 | beego.Router("/cart/addCart", &mindex.CartController{}, "get:AddCart") 22 | beego.Router("/cart/decCart", &mindex.CartController{}, "get:DecCart") 23 | beego.Router("/cart/incCart", &mindex.CartController{}, "get:IncCart") 24 | beego.Router("/cart/changeOneCart", &mindex.CartController{}, "get:ChangeOneCart") 25 | beego.Router("/cart/changeAllCart", &mindex.CartController{}, "get:ChangeAllCart") 26 | beego.Router("/cart/delCart", &mindex.CartController{}, "get:DelCart") 27 | 28 | // 配置中间件判断权限 29 | beego.InsertFilter("/buy/*",beego.BeforeRouter,middleware.DefaultAuth) 30 | beego.Router("/buy/checkout", &mindex.BuyController{}, "get:CheckOut") 31 | beego.Router("/buy/doOrder", &mindex.BuyController{}, "post:DoOrder") 32 | beego.Router("/buy/confirm", &mindex.BuyController{}, "get:Confirm") 33 | 34 | beego.InsertFilter("/address/*",beego.BeforeRouter,middleware.DefaultAuth) 35 | beego.Router("/address/addAddress", &mindex.AddressController{}, "post:AddAddress") 36 | beego.Router("/address/getOneAddressList", &mindex.AddressController{}, "get:GetOneAddressList") 37 | beego.Router("/address/doEditAddressList", &mindex.AddressController{}, "post:DoEditAddressList") 38 | beego.Router("/address/changeDefaultAddress", &mindex.AddressController{}, "get:ChangeDefaultAddress") 39 | 40 | beego.InsertFilter("/user/*",beego.BeforeRouter,middleware.DefaultAuth) 41 | beego.Router("/user", &mindex.UserController{}) 42 | beego.Router("/user/order", &mindex.UserController{},"get:OrderList") 43 | beego.Router("/user/orderinfo", &mindex.UserController{},"get:OrderInfo") 44 | beego.Router("/user/delOrder", &mindex.UserController{},"get:DelOrder") 45 | } 46 | -------------------------------------------------------------------------------- /views/admin/focus/edit.html: -------------------------------------------------------------------------------- 1 | {{template "../public/page_header.html"}} 2 | 3 |
4 |
5 | 6 |
7 |
8 | 增加轮播图 9 |
10 |
11 |
12 |
13 | 14 |
    15 |
  • 类  型: 16 | 21 |
  • 22 |
  • 名  称:
  • 23 |
  • 跳转地址:
  • 24 |
  • 轮 播 图: 25 |
    26 | {{if ne .focus.FocusImg ""}} 27 | 28 | {{end}} 29 | 30 |
  • 31 | 32 |
  • 排  序:
  • 33 | 34 |
  • 状  态: 35 | 36 | 37 |  
  • 38 |
  • 39 |
    40 | 41 |
  • 42 | 43 |
44 | 45 | 46 |
47 |
48 |
49 | 50 | 51 |
52 | 53 |
54 |
55 | 56 | 57 | -------------------------------------------------------------------------------- /controllers/admin/goodsType.go: -------------------------------------------------------------------------------- 1 | package admin 2 | 3 | import ( 4 | "mi.com/models" 5 | "strconv" 6 | "strings" 7 | ) 8 | 9 | type GoodsTypeController struct { 10 | BaseController 11 | } 12 | 13 | func (this *GoodsTypeController) Get() { 14 | 15 | goodsType := []models.GoodsType{} 16 | models.DB.Find(&goodsType) 17 | this.Data["goodsTypeList"] = goodsType 18 | this.TplName = "admin/goodsType/index.html" 19 | } 20 | 21 | func (this *GoodsTypeController) Add() { 22 | this.TplName = "admin/goodsType/add.html" 23 | } 24 | 25 | func (this *GoodsTypeController) DoAdd() { 26 | title := strings.Trim(this.GetString("title"), " ") 27 | description := strings.Trim(this.GetString("description"), " ") 28 | status, err1 := this.GetInt("status") 29 | if err1 != nil { 30 | this.Error("传入参数不正确", "/goodsType/add") 31 | return 32 | } 33 | if title == "" { 34 | this.Error("标题不能为空", "/goodsType/add") 35 | return 36 | } 37 | goodsType := models.GoodsType{} 38 | goodsType.Title = title 39 | goodsType.Description = description 40 | goodsType.Status = status 41 | goodsType.AddTime = int(models.GetUnix()) 42 | err := models.DB.Create(&goodsType).Error 43 | if err != nil { 44 | this.Error("增加商品类型失败", "/goodsType/add") 45 | } else { 46 | this.Success("增加商品类型成功", "/goodsType") 47 | } 48 | } 49 | 50 | func (this *GoodsTypeController) Edit() { 51 | id, err := this.GetInt("id") 52 | if err != nil { 53 | this.Error("传入参数错误", "/goodsType") 54 | return 55 | } 56 | 57 | goodsType := models.GoodsType{Id: id} 58 | models.DB.Find(&goodsType) 59 | this.Data["goodsType"] = goodsType 60 | this.TplName = "admin/goodsType/edit.html" 61 | } 62 | 63 | func (this *GoodsTypeController) DoEdit() { 64 | 65 | id, err1 := this.GetInt("id") 66 | 67 | title := strings.Trim(this.GetString("title"), " ") 68 | description := strings.Trim(this.GetString("description"), " ") 69 | status, err2 := this.GetInt("status") 70 | if err1 != nil || err2 != nil { 71 | this.Error("传入参数错误", "/goodsType") 72 | return 73 | } 74 | 75 | if title == "" { 76 | this.Error("标题不能为空", "/role/add") 77 | return 78 | } 79 | //修改 80 | goodsType := models.GoodsType{Id: id} 81 | models.DB.Find(&goodsType) 82 | goodsType.Title = title 83 | goodsType.Description = description 84 | goodsType.Status = status 85 | 86 | err3 := models.DB.Save(&goodsType).Error 87 | if err3 != nil { 88 | this.Error("修改数据失败", "/goodsType/edit?id="+strconv.Itoa(id)) 89 | } else { 90 | this.Success("修改数据成功", "/goodsType") 91 | } 92 | 93 | } 94 | 95 | func (this *GoodsTypeController) Delete() { 96 | id, err1 := this.GetInt("id") 97 | if err1 != nil { 98 | this.Error("传入参数错误", "/goodsType") 99 | return 100 | } 101 | goodsType := models.GoodsType{Id: id} 102 | models.DB.Delete(&goodsType) 103 | this.Success("删除数据成功", "/goodsType") 104 | 105 | } 106 | 107 | -------------------------------------------------------------------------------- /views/admin/goodsCate/add.html: -------------------------------------------------------------------------------- 1 | {{template "../public/page_header.html"}} 2 | 3 |
4 |
5 | 6 |
7 |
8 | 增加分类 9 |
10 |
11 |
12 |
13 |
    14 | 15 |
  • 分类名称:
  • 16 | 17 |
  • 上级分类: 18 | 24 |
  • 25 | 26 |
  • 分类图片:
  • 27 | 28 |
  • 跳转地址:
  • 29 | 30 |
  • 分类模板: 空表示默认模板
  • 31 | 32 |
  • Seo标题:
  • 33 | 34 |
  • Seo关键词:
  • 35 | 36 |
  • Seo描述:
  • 37 | 38 |
  • 排  序:
  • 39 | 40 |
  • 状  态: 41 | 42 |   43 | 44 |
  • 45 | 46 | 47 | 48 |
  • 49 |
    50 | 51 |
  • 52 | 53 |
54 | 55 | 56 |
57 |
58 |
59 | 60 | 61 |
62 | 63 |
64 |
65 | 66 | 67 | -------------------------------------------------------------------------------- /controllers/admin/focus.go: -------------------------------------------------------------------------------- 1 | package admin 2 | 3 | import ( 4 | "mi.com/models" 5 | "strconv" 6 | ) 7 | 8 | type FocusController struct { 9 | BaseController 10 | } 11 | 12 | func (this *FocusController) Get() { 13 | focus := []models.Focus{} 14 | models.DB.Find(&focus) 15 | this.Data["focusList"] = focus 16 | this.TplName = "admin/focus/index.html" 17 | } 18 | 19 | func (this *FocusController) Add() { 20 | this.TplName = "admin/focus/add.html" 21 | } 22 | 23 | func (this *FocusController) DoAdd() { 24 | focusType, err1 := this.GetInt("focus_type") 25 | title := this.GetString("title") 26 | link := this.GetString("link") 27 | sort, err2 := this.GetInt("sort") 28 | status, err3 := this.GetInt("status") 29 | 30 | if err1 != nil || err3 != nil { 31 | this.Error("非法请求", "/focus/add") 32 | } 33 | if err2 != nil { 34 | this.Error("排序表单里面输入的数据不合法", "/focus/add") 35 | } 36 | 37 | // 执行图片上传 38 | focusImgSrc,_ := this.UploadImg("focus_img") 39 | 40 | focus := models.Focus{ 41 | Title: title, 42 | FocusType: focusType, 43 | FocusImg: focusImgSrc, 44 | Link: link, 45 | Sort: sort, 46 | Status: status, 47 | AddTime: int(models.GetUnix()), 48 | } 49 | models.DB.Create(&focus) 50 | this.Success("增加轮播图成功", "/focus") 51 | 52 | } 53 | 54 | func (this *FocusController) Edit() { 55 | 56 | id, err := this.GetInt("id") 57 | if err != nil { 58 | this.Error("非法请求", "/focus") 59 | return 60 | } 61 | focus := models.Focus{Id: id} 62 | models.DB.Find(&focus) 63 | this.Data["focus"] = focus 64 | 65 | this.TplName = "admin/focus/edit.html" 66 | 67 | } 68 | 69 | func (this *FocusController) DoEdit() { 70 | id, err1 := this.GetInt("id") 71 | focusType, err2 := this.GetInt("focus_type") 72 | title := this.GetString("title") 73 | link := this.GetString("link") 74 | sort, err3 := this.GetInt("sort") 75 | status, err4 := this.GetInt("status") 76 | 77 | if err1 != nil || err2 != nil || err4 != nil { 78 | this.Error("非法请求", "/focus") 79 | } 80 | if err3 != nil { 81 | this.Error("排序表单里面输入的数据不合法", "/focus/edit?id="+strconv.Itoa(id)) 82 | } 83 | //执行图片上传 84 | focusImgSrc, _ := this.UploadImg("focus_img") 85 | 86 | focus := models.Focus{Id: id} 87 | models.DB.Find(&focus) 88 | focus.Title = title 89 | focus.FocusType = focusType 90 | focus.Link = link 91 | focus.Sort = sort 92 | focus.Status = status 93 | if focusImgSrc != "" { 94 | focus.FocusImg = focusImgSrc 95 | } 96 | err := models.DB.Save(&focus).Error 97 | if err != nil { 98 | this.Error("修改数据失败", "/focus/edit?id="+strconv.Itoa(id)) 99 | return 100 | } 101 | this.Success("修改数据成功", "/focus") 102 | } 103 | 104 | func (this *FocusController) Delete() { 105 | 106 | id, err1 := this.GetInt("id") 107 | if err1 != nil { 108 | this.Error("传入参数错误", "/focus") 109 | return 110 | } 111 | focus := models.Focus{Id: id} 112 | models.DB.Delete(&focus) 113 | this.Success("删除轮播图成功", "/focus") 114 | } 115 | 116 | -------------------------------------------------------------------------------- /views/admin/access/add.html: -------------------------------------------------------------------------------- 1 | {{template "../public/page_header.html" .}} 2 | 3 |
4 |
5 |
6 |
7 | 增加权限 8 |
9 |
10 |
11 |
12 |
    13 | 14 |
  • 模块名称:
  • 15 |
  • 16 | 节点类型: 17 | 18 | 23 | 24 |
  • 25 | 26 |
  • 操作名称:
  • 27 | 28 |
  • 操作地址:
  • 29 | 30 | 31 |
  • 所属模块: 32 | 40 |
  • 41 | 42 | 43 |
  • 排  序:
  • 44 | 45 | 46 |
  • 描  述 : 47 | 48 | 49 |
  • 50 | 51 | 52 |
  • 状  态: 53 | 54 | 55 |   56 |
  • 57 | 58 |
  • 59 |
    60 | 61 |
  • 62 | 63 |
64 | 65 | 66 |
67 |
68 |
69 | 70 | 71 |
72 | 73 |
74 |
75 | 76 | 77 | -------------------------------------------------------------------------------- /views/mindex/public/banner.html: -------------------------------------------------------------------------------- 1 | 2 | 90 | 91 | -------------------------------------------------------------------------------- /controllers/mindex/user.go: -------------------------------------------------------------------------------- 1 | package mindex 2 | 3 | import ( 4 | "math" 5 | "mi.com/models" 6 | "strconv" 7 | "strings" 8 | ) 9 | 10 | type UserController struct { 11 | BaseController 12 | } 13 | 14 | func (this *UserController) Get() { 15 | this.SuperInit() 16 | 17 | user := models.User{} 18 | models.Cookie.Get(this.Ctx,"userinfo",&user) 19 | order := []models.Order{} 20 | models.DB.Where("uid=? And order_status=0", user.Id).Preload("OrderItem").Find(&order) 21 | this.Data["noPay"] = len(order) 22 | this.Data["user"] = user 23 | this.TplName = "mindex/user/welcome.html" 24 | } 25 | 26 | func (this *UserController) OrderList() { 27 | this.SuperInit() 28 | 29 | // 1:获取当前用户 30 | user := models.User{} 31 | models.Cookie.Get(this.Ctx, "userinfo", &user) 32 | 33 | // 2:获取当前用户下面的订单信息 34 | page, _ := this.GetInt("page") 35 | if page == 0 { 36 | page = 1 37 | } 38 | pageSize := 3 39 | 40 | // 3:获取关键词,搜索功能 41 | where := "uid=?" 42 | keywords := this.GetString("keywords") 43 | if keywords != "" { 44 | orderItem := []models.OrderItem{} 45 | models.DB.Where("product_title like ?", "%"+keywords+"%").Find(&orderItem) 46 | 47 | var str string 48 | for i := 0; i < len(orderItem); i++ { 49 | str += "," + strconv.Itoa(orderItem[i].OrderId) 50 | } 51 | str = strings.Trim(str, ",") 52 | where += " And id in (" + str + ")" 53 | } 54 | 55 | // 4:获取筛选条件 56 | orderStatus,stasusError := this.GetInt("order_status") 57 | if stasusError == nil { 58 | where += " And order_status="+strconv.Itoa(orderStatus) 59 | this.Data["orderStatus"] = orderStatus 60 | }else { 61 | this.Data["orderStatus"] = "" 62 | } 63 | 64 | 65 | var count int // 商品总数量 66 | models.DB.Where(where, user.Id).Table("order").Count(&count) 67 | 68 | order := []models.Order{} 69 | models.DB.Where(where, user.Id).Offset((page - 1) * pageSize).Limit(pageSize).Preload("OrderItem").Order("add_time desc").Find(&order) 70 | this.Data["order"] = order 71 | this.Data["page"] = page 72 | this.Data["totalPages"] = math.Ceil(float64(count) / float64(pageSize)) 73 | this.Data["keywords"] = keywords 74 | 75 | this.TplName = "mindex/user/order.html" 76 | 77 | } 78 | 79 | func (this *UserController) OrderInfo() { 80 | this.SuperInit() 81 | id,_ := this.GetInt("id") 82 | user := models.User{} 83 | models.Cookie.Get(this.Ctx,"userinfo",&user) 84 | order := models.Order{} 85 | models.DB.Where("id=? And uid=?",id,user.Id).Preload("OrderItem").Find(&order) 86 | this.Data["order"] = order 87 | if order.OrderId =="" { 88 | this.Redirect("/",302) 89 | } 90 | this.TplName = "mindex/user/order_info.html" 91 | } 92 | 93 | func (this *UserController) DelOrder() { 94 | id,_ := this.GetInt("id") 95 | user := models.User{} 96 | models.Cookie.Get(this.Ctx,"userinfo",&user) 97 | order := models.Order{} 98 | models.DB.Where("id=? And uid=?",id,user.Id).Delete(&order) 99 | orderItem := models.OrderItem{} 100 | models.DB.Where("order_id=?",id).Delete(&orderItem) 101 | this.Success("删除订单成功", "/user/order") 102 | } 103 | -------------------------------------------------------------------------------- /views/mindex/index/pass.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 注册账号 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 26 | 27 | 28 | 38 | 39 | 40 |
41 |
42 |
43 | 44 |
45 |
46 | 47 |
48 |
49 |
50 |
51 | 52 | 53 | 54 | 77 | 78 | -------------------------------------------------------------------------------- /views/admin/nav/edit.html: -------------------------------------------------------------------------------- 1 | {{template "../public/page_header.html" .}} 2 | 3 |
4 |
5 |
6 |
7 | 编辑角色 8 |
9 |
10 |
11 |
12 |
    13 | 14 | 15 | 16 | 17 | 18 |
  • 导航名称:
  • 19 | 20 |
  • 导航位置: 21 | {{$position := .nav.Position}} 22 | 27 |
  • 28 | 29 |
  • 关联商品:
  • 30 | 31 |
  • 导航链接地址:
  • 32 | 33 |
  • 新窗口打开: 34 | {{$isOpennew := .nav.IsOpennew}} 35 | 39 | 40 |
  • 排序:
  • 41 | 42 |
  • 状  态: 43 | 44 | 45 |
  • 46 |
    47 | 48 | 49 | 50 |
51 | 52 | 53 |
54 |
55 |
56 | 57 | 58 |
59 | 60 |
61 |
62 | 63 | 64 | -------------------------------------------------------------------------------- /controllers/admin/nav.go: -------------------------------------------------------------------------------- 1 | package admin 2 | 3 | import ( 4 | "mi.com/models" 5 | "math" 6 | "strconv" 7 | ) 8 | 9 | type NavController struct { 10 | BaseController 11 | } 12 | 13 | func (this *NavController) Get() { 14 | //当前页 15 | page, _ := this.GetInt("page") 16 | if page == 0 { 17 | page = 1 18 | } 19 | //每一页显示的数量 20 | pageSize := 20 21 | //查询数据 22 | nav := []models.Nav{} 23 | models.DB.Offset((page - 1) * pageSize).Limit(pageSize).Find(&nav) 24 | //查询nav表里面的数量 25 | var count int 26 | models.DB.Table("nav").Count(&count) 27 | 28 | this.Data["navList"] = nav 29 | this.Data["totalPages"] = math.Ceil(float64(count) / float64(pageSize)) 30 | this.Data["page"] = page 31 | this.TplName = "admin/nav/index.html" 32 | } 33 | 34 | func (this *NavController) Add() { 35 | this.TplName = "admin/nav/add.html" 36 | } 37 | 38 | func (this *NavController) DoAdd() { 39 | title := this.GetString("title") 40 | link := this.GetString("link") 41 | position, _ := this.GetInt("position") 42 | isOpennew, _ := this.GetInt("is_opennew") 43 | relation := this.GetString("relation") 44 | sort, _ := this.GetInt("sort") 45 | status, _ := this.GetInt("status") 46 | 47 | nav := models.Nav{ 48 | Title: title, 49 | Link: link, 50 | Position: position, 51 | IsOpennew: isOpennew, 52 | Relation: relation, 53 | Sort: sort, 54 | Status: status, 55 | AddTime: int(models.GetUnix()), 56 | } 57 | 58 | err := models.DB.Create(&nav).Error 59 | if err != nil { 60 | this.Error("增加数据失败", "/nav/add") 61 | } else { 62 | this.Success("增加成功", "/nav") 63 | } 64 | } 65 | 66 | func (this *NavController) Edit() { 67 | id, err := this.GetInt("id") 68 | if err != nil { 69 | this.Error("传入参数错误", "/nav") 70 | return 71 | } 72 | nav := models.Nav{Id: id} 73 | models.DB.Find(&nav) 74 | this.Data["nav"] = nav 75 | this.Data["prevPage"] = this.Ctx.Request.Referer() 76 | this.TplName = "admin/nav/edit.html" 77 | } 78 | 79 | func (this *NavController) DoEdit() { 80 | 81 | id, err1 := this.GetInt("id") 82 | if err1 != nil { 83 | this.Error("传入参数错误", "/nav") 84 | return 85 | } 86 | title := this.GetString("title") 87 | link := this.GetString("link") 88 | position, _ := this.GetInt("position") 89 | isOpennew, _ := this.GetInt("is_opennew") 90 | relation := this.GetString("relation") 91 | sort, _ := this.GetInt("sort") 92 | status, _ := this.GetInt("status") 93 | prevPage := this.GetString("prevPage") 94 | 95 | //修改 96 | nav := models.Nav{Id: id} 97 | models.DB.Find(&nav) 98 | nav.Title = title 99 | nav.Link = link 100 | nav.Position = position 101 | nav.IsOpennew = isOpennew 102 | nav.Relation = relation 103 | nav.Sort = sort 104 | nav.Status = status 105 | 106 | err2 := models.DB.Save(&nav).Error 107 | if err2 != nil { 108 | this.Error("修改数据失败", "/nav/edit?id="+strconv.Itoa(id)) 109 | } else { 110 | this.Success("修改数据成功", prevPage) 111 | } 112 | 113 | } 114 | func (this *NavController) Delete() { 115 | id, err1 := this.GetInt("id") 116 | if err1 != nil { 117 | this.Error("传入参数错误", "/nav") 118 | return 119 | } 120 | nav := models.Nav{Id: id} 121 | models.DB.Delete(&nav) 122 | 123 | this.Success("删除数据成功", this.Ctx.Request.Referer()) 124 | 125 | } 126 | 127 | -------------------------------------------------------------------------------- /views/admin/focus/index.html: -------------------------------------------------------------------------------- 1 | {{template "../public/page_header.html"}} 2 | 3 |
4 |
5 |
6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | {{range $key,$value := .focusList}} 20 | 21 | 22 | 31 | 37 | 38 | 43 | 50 | 51 | 56 | 57 | {{end}} 58 | 59 |
轮播图名称轮播图类型轮播图图片跳转地址排序状态操作
{{$value.Title}} 23 | {{if eq $value.FocusType 1}} 24 | 网站 25 | {{else if eq $value.FocusType 2}} 26 | APP 27 | {{else}} 28 | 小程序 29 | {{end}} 30 | 32 | {{if ne $value.FocusImg ""}} 33 | 34 | {{end}} 35 | 36 | {{$value.Link}} 39 | 40 | {{$value.Sort}} 41 | 42 | 44 | {{if eq $value.Status 1}} 45 | 46 | {{else}} 47 | 48 | {{end}} 49 | 52 | 编辑   53 | 54 | 删除 55 |
60 | 61 |
62 |
63 |
64 | 65 | 66 | -------------------------------------------------------------------------------- /views/admin/goodsTypeAttribute/add.html: -------------------------------------------------------------------------------- 1 | {{template "../public/page_header.html"}} 2 | 3 |
4 |
5 | 6 |
7 |
8 | 增加商品类型属性 9 |
10 |
11 |
12 |
13 |
    14 | 15 |
  •  属性名称:
  • 16 | 17 |
  •  所属类型: 18 | 25 |
  • 26 | 27 | 28 |
  •  录入方式: 29 |   30 |   31 |   32 |
  • 33 | 34 | 35 |
  • 36 | 可选值列表: 37 | 38 |
  • 39 | 40 |
  • 排  序:
  • 41 | 42 |
  • 43 |
    44 | 45 |
  • 46 | 47 | 48 |
49 | 50 | 51 |
52 |
53 |
54 | 55 | 56 |
57 |
58 |
59 | 70 | 71 | -------------------------------------------------------------------------------- /controllers/admin/main.go: -------------------------------------------------------------------------------- 1 | package admin 2 | 3 | import ( 4 | "github.com/astaxie/beego" 5 | "github.com/jinzhu/gorm" 6 | "mi.com/models" 7 | ) 8 | 9 | type MainController struct { 10 | beego.Controller 11 | } 12 | 13 | func (this *MainController) Get() { 14 | // 根据登录用户的权限,动态显示左侧的菜单 15 | // 从session里面获取登录信息 16 | userinfo,ok := this.GetSession("userinfo").(models.Manager) 17 | if ok { 18 | // 获取角色id 19 | roleId := userinfo.RoleId 20 | 21 | // 2:获取全部权限 22 | access := []models.Access{} 23 | //models.DB.Preload("AccessItem").Where("module_id=0").Find(&access) 24 | models.DB.Preload("AccessItem", func(db *gorm.DB) *gorm.DB { 25 | return db.Order("access.sort DESC") 26 | }).Order("sort desc").Where("module_id=0").Find(&access) 27 | 28 | // 3:获取当前角色拥有的权限,并把权限id放在一个map对象里面 29 | roleAccess := []models.RoleAccess{} 30 | models.DB.Where("role_id=?",roleId).Find(&roleAccess) 31 | roleAccessMap := make(map[int]int) 32 | for _, v := range roleAccess { 33 | roleAccessMap[v.AccessId] = v.AccessId 34 | } 35 | 36 | // 4:循环遍历所有的权限数据,判断当前权限的id是否在角色权限的map对象当中 37 | // 如果存在,将checked字段变为true 38 | for i := 0; i 15 { 120 | return string(rs[0:15])+"..." 121 | } 122 | return str 123 | } 124 | // 乘法的函数 125 | func Mul(price float64,num int) float64 { 126 | return price*(float64(num)) 127 | } 128 | // 判断4 或 9 129 | func Judge(num int)bool { 130 | if num == 4 || num ==9 { 131 | return true 132 | }else { 133 | return false 134 | } 135 | 136 | } 137 | 138 | // 生成四位随机数 139 | func GetRandomNum() string { 140 | var str string 141 | for i := 0; i < 4; i++ { 142 | current := rand.Intn(10) 143 | str += strconv.Itoa(current) 144 | } 145 | return str 146 | } -------------------------------------------------------------------------------- /controllers/mindex/base.go: -------------------------------------------------------------------------------- 1 | package mindex 2 | 3 | import ( 4 | "fmt" 5 | "github.com/astaxie/beego" 6 | "github.com/jinzhu/gorm" 7 | "mi.com/models" 8 | "net/url" 9 | "strings" 10 | ) 11 | 12 | type BaseController struct { 13 | beego.Controller 14 | } 15 | 16 | 17 | func (this *BaseController) SuperInit() { 18 | //获取顶部导航 19 | topNav := []models.Nav{} 20 | 21 | if hasTopNav := models.CacheDb.Get("topNav",&topNav); hasTopNav == true { 22 | this.Data["topNavList"] = topNav 23 | } else { 24 | models.DB.Where("status=1 AND position=1").Order("sort desc").Find(&topNav) 25 | this.Data["topNavList"] = topNav 26 | models.CacheDb.Set("topNav",topNav) 27 | } 28 | 29 | // 左侧分类 30 | goodsCate := []models.GoodsCate{} 31 | 32 | if hasGoodsCate := models.CacheDb.Get("goodsCate",&goodsCate); hasGoodsCate == true { 33 | this.Data["goodsCateList"] = goodsCate 34 | } else { 35 | models.DB.Preload("GoodsCateItem", func(db *gorm.DB) *gorm.DB { 36 | return db.Where("goods_cate.status=1").Order("goods_cate.sort DESC") 37 | }).Where("pid=0 AND status=1").Order("sort desc").Find(&goodsCate) 38 | this.Data["goodsCateList"] = goodsCate 39 | models.CacheDb.Set("goodsCate",goodsCate) 40 | } 41 | 42 | // 获取中间导航数据 43 | middleNav := []models.Nav{} 44 | if hasMiddleNav := models.CacheDb.Get("middleNav", &middleNav); hasMiddleNav == true { 45 | this.Data["middleNavList"] = middleNav 46 | } else { 47 | models.DB.Where("status=1 AND position=2").Order("sort desc").Find(&middleNav) 48 | 49 | for i := 0; i < len(middleNav); i++ { 50 | // 获取关联商品 51 | // middleNav[i].Relation 19,20,21 52 | middleNav[i].Relation = strings.ReplaceAll(middleNav[i].Relation, ",", ",") 53 | relation := strings.Split(middleNav[i].Relation, ",") 54 | goods := []models.Goods{} 55 | models.DB.Where("id in (?)", relation).Select("id,title,goods_img,price").Order("sort desc").Find(&goods) 56 | middleNav[i].GoodsItem = goods 57 | if len(goods) > 1 { 58 | middleNav[i].GoodsNil = "NO" 59 | }else { 60 | middleNav[i].GoodsNil = "YES" 61 | } 62 | } 63 | this.Data["middleNavList"] = middleNav 64 | 65 | models.CacheDb.Set("middleNav", middleNav) 66 | } 67 | 68 | // 判断用户是否登录 69 | user := models.User{} 70 | models.Cookie.Get(this.Ctx,"userinfo",&user) 71 | if len(user.Phone) ==11 { 72 | str := fmt.Sprintf(` `, user.Email) 87 | this.Data["userinfo"] = str 88 | 89 | }else { 90 | str := fmt.Sprintf(``) 95 | this.Data["userinfo"] = str 96 | 97 | } 98 | ulrPath,_ := url.Parse(this.Ctx.Request.URL.String()) 99 | this.Data["pathname"] = ulrPath.Path 100 | 101 | } 102 | 103 | func (this *BaseController) Success(message,redirect string) { 104 | this.Data["message"] = message 105 | this.Data["redirect"] = redirect 106 | this.TplName = "admin/public/success.html" 107 | } 108 | func (this *BaseController) Error(message,redirect string) { 109 | this.Data["message"] = message 110 | this.Data["redirect"] = redirect 111 | this.TplName = "admin/public/error.html" 112 | } -------------------------------------------------------------------------------- /controllers/admin/manager.go: -------------------------------------------------------------------------------- 1 | package admin 2 | 3 | import ( 4 | "mi.com/models" 5 | "strconv" 6 | ) 7 | 8 | type ManagerController struct { 9 | BaseController 10 | } 11 | 12 | func (this *ManagerController) Get() { 13 | manager := []models.Manager{} 14 | models.DB.Preload("Role").Find(&manager) 15 | this.Data["managerList"] = manager 16 | this.TplName = "admin/manager/index.html" 17 | } 18 | 19 | func (this *ManagerController) Add() { 20 | role := []models.Role{} 21 | models.DB.Find(&role) 22 | this.Data["role"] = role 23 | 24 | this.TplName = "admin/manager/add.html" 25 | } 26 | 27 | func (this *ManagerController) DoAdd() { 28 | roleId,err_num := this.GetInt("role_id") 29 | if err_num != nil { 30 | this.Error("非法请求","/manager/add") 31 | } 32 | 33 | username := this.GetString("username") 34 | password := models.Md5(this.GetString("password")) 35 | mobile := this.GetString("mobile") 36 | email := this.GetString("email") 37 | 38 | if len(username)<2 || len(password)<6 { 39 | this.Error("用户名或者密码长度不合法","/manage/add") 40 | return 41 | } 42 | // 判断数据里面是否存在已有用户 43 | managerList := []models.Manager{} 44 | models.DB.Where("username=?",username).Find(&managerList) 45 | if len(managerList)>0 { 46 | this.Error("用户名已经存在","/manager/add") 47 | return 48 | } 49 | 50 | manager := models.Manager{} 51 | manager.Username = username 52 | manager.Password = password 53 | manager.Mobile = mobile 54 | manager.Email = email 55 | manager.AddTime = int(models.GetUnix()) 56 | manager.RoleId = roleId 57 | manager.Status = 1 58 | 59 | err := models.DB.Create(&manager).Error 60 | if err !=nil { 61 | this.Error("增加管理员失败","/manager/add") 62 | return 63 | } 64 | this.Success("增加管理员成功","/manager") 65 | } 66 | 67 | func (this *ManagerController) Edit() { 68 | // 获取所以角色 69 | role := []models.Role{} 70 | models.DB.Find(&role) 71 | this.Data["role"] = role 72 | 73 | // 获取管理员信息 74 | id,err := this.GetInt("id") 75 | if err != nil { 76 | this.Error("非法请求","/manager") 77 | return 78 | } 79 | manager := models.Manager{Id: id} 80 | models.DB.Find(&manager) 81 | this.Data["manager"] = manager 82 | 83 | this.TplName = "admin/manager/edit.html" 84 | } 85 | 86 | func (this *ManagerController) DoEdit() { 87 | id,err1 := this.GetInt("id") 88 | if err1 != nil { 89 | this.Error("非法请求","/manager") 90 | return 91 | } 92 | 93 | roleId,err2 := this.GetInt("role_id") 94 | if err2 != nil { 95 | this.Error("非法请求","/managerd") 96 | return 97 | } 98 | 99 | password := this.GetString("password") 100 | mobile := this.GetString("mobile") 101 | email := this.GetString("email") 102 | 103 | // 获取数据 104 | manager := models.Manager{Id: id} 105 | models.DB.Find(&manager) 106 | manager.RoleId = roleId 107 | manager.Mobile = mobile 108 | manager.Email = email 109 | 110 | if password != "" { 111 | if len(password)<6 { 112 | this.Error("密码长度不能小于6位","/manager/edit?id="+strconv.Itoa(id)) 113 | } 114 | manager.Password =models.Md5(password) 115 | } 116 | err := models.DB.Save(&manager).Error 117 | if err != nil { 118 | this.Error("修改数据失败","/manager/edit?id="+strconv.Itoa(id)) 119 | }else { 120 | this.Success("修改数据成功","/manager") 121 | } 122 | } 123 | 124 | func (this *ManagerController) Delete() { 125 | id,err := this.GetInt("id") 126 | if err != nil { 127 | this.Error("传入参数错误","/manager") 128 | return 129 | } 130 | manager := models.Manager{Id: id} 131 | models.DB.Delete(&manager) 132 | this.Success("删除角色成功","/manager") 133 | } -------------------------------------------------------------------------------- /views/mindex/cart/cart.html: -------------------------------------------------------------------------------- 1 | {{template "../public/page_header.html" .}} 2 | 3 | 4 | 5 | 6 | 20 |
21 | 22 | {{if .cartList}} 23 |
24 |
25 | 26 | 27 | 28 | 29 | 33 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | {{range $key,$value := .cartList}} 44 | 45 | 46 | 47 | 50 | 51 | 59 | 60 | 63 | 64 | 76 | 77 | 81 | 84 | 85 | 86 | {{end}} 87 |
30 | 31 | 全选 32 | 34 | 商品名称 35 | 单价数量小计操作
48 | 49 | 52 |
53 | 54 |
55 |
56 | {{$value.Title}} -- {{$value.GoodsColor}} {{$value.GoodsVersion}} 57 |
58 |
61 | {{$value.Price}}元 62 | 65 | 66 |
67 |
-
68 | 69 |
70 | 71 |
72 |
+
73 |
74 | 75 |
78 | {{mul $value.Price $value.Num}}元 79 | 80 | 82 | 删除 83 |
88 | 89 |
90 |
91 |
92 | 96 |
97 |
98 |
合计(不含运费):{{.allPrice}}元
99 | 100 |
101 |
102 |
103 |
104 | 105 |
106 | {{else}} 107 |
108 |

您的购物车还是空的!

109 |
110 | {{end}} 111 | 112 | 113 | 114 | 115 | {{template "../public/page_footer.html" .}} 116 | 117 | 118 | 119 | -------------------------------------------------------------------------------- /views/admin/goodsTypeAttribute/edit.html: -------------------------------------------------------------------------------- 1 | {{template "../public/page_header.html"}} 2 | 3 |
4 |
5 | 6 |
7 |
8 | 增加商品类型属性 9 |
10 |
11 |
12 |
13 |
    14 | 15 | 16 |
  •  属性名称:
  • 17 | 18 |
  •  所属类型: 19 | 26 |
  • 27 | 28 |
  •  录入方式: 29 |   30 |   31 |   32 | 33 | 34 |
  • 35 | 36 |
  • 37 | 可选值列表: 38 | 39 |
  • 40 | 41 |
  • 排  序:
  • 42 |
  • 43 |
    44 | 45 |
  • 46 | 47 | 48 |
49 | 50 | 51 |
52 |
53 |
54 | 55 | 56 |
57 |
58 |
59 | 71 | 72 | -------------------------------------------------------------------------------- /views/admin/goodsCate/edit.html: -------------------------------------------------------------------------------- 1 | {{template "../public/page_header.html"}} 2 | 3 |
4 |
5 | 6 |
7 |
8 | 修改分类 9 |
10 |
11 |
12 |
13 |
    14 | 15 | 16 | 17 |
  • 分类名称:
  • 18 | 19 |
  • 上级分类: 20 | 27 |
  • 28 | 29 |
  • 分类图片:
  • 30 | 31 | {{$ossStatus := config "Bool" "ossStatus" false}} 32 | {{if ne .goodsCate.CateImg ""}} 33 | 34 | {{end}} 35 | 36 |
  • 跳转地址:
  • 37 | 38 |
  • 分类模板: 空表示默认模板
  • 39 | 40 |
  • Seo标题:
  • 41 | 42 |
  • Seo关键词:
  • 43 | 44 |
  • Seo描述:
  • 45 | 46 |
  • 排  序:
  • 47 | 48 |
  • 状  态: 49 |  
  • 50 | 51 | 52 | 53 |
  • 54 |
    55 | 56 |
  • 57 | 58 |
59 | 60 | 61 |
62 |
63 |
64 | 65 | 66 |
67 | 68 |
69 |
70 | 71 | 72 | -------------------------------------------------------------------------------- /views/admin/access/index.html: -------------------------------------------------------------------------------- 1 | {{template "../public/page_header.html" .}} 2 |
3 |
4 | 5 | 6 |
7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | {{range $key,$value := .accessList}} 23 | 24 | 25 | 34 | 35 | 36 | 40 | 41 | 45 | 46 | {{range $k,$v := $value.AccessItem}} 47 | 48 | 49 | 58 | 59 | 60 | 64 | 65 | 70 | 71 | {{end}} 72 | 73 | {{end}} 74 | 75 | 76 |
模块名称节点类型操作名称操作地址排序描述操作
{{$value.ModuleName}} 26 | {{if eq $value.Type 1}} 27 | 模块 28 | {{else if eq $value.Type 2}} 29 | 菜单 30 | {{else}} 31 | 操作 32 | {{end}} 33 | {{$value.ActionName}}{{$value.Url}} 37 | {{$value.Sort}} 38 | 39 | {{$value.Description}} 42 | 编辑  43 | 删除 44 |
--{{$v.ModuleName}}  50 | {{if eq $v.Type 1}} 51 | 模块 52 | {{else if eq $v.Type 2}} 53 | 菜单 54 | {{else}} 55 | 操作 56 | {{end}} 57 |  {{$v.ActionName}} {{$v.Url}} 61 | {{$v.Sort}} 62 | 63 |  {{$v.Description}} 66 | 编辑  67 | 删除 68 | 69 |
77 |
78 | 79 |
80 |
81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /views/admin/nav/index.html: -------------------------------------------------------------------------------- 1 | {{template "../public/page_header.html" .}} 2 | 3 | 4 |
5 |
6 | 增加导航 7 |
8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | {{range $key,$value := .navList}} 24 | 25 | 26 | 27 | 28 | 37 | 41 | 48 | 49 | 54 | 55 | {{end}} 56 | 57 |
导航名称关联商品跳转地址导航位置排序状态操作
{{$value.Title}}{{$value.Relation}}{{$value.Link}} 29 | {{if eq $value.Position 1}} 30 | 顶部 31 | {{else if eq $value.Position 2}} 32 | 中间 33 | {{else if eq $value.Position 3}} 34 | 底部 35 | {{end}} 36 | 38 | 39 | {{$value.Sort}} 40 | 42 | {{if eq $value.Status 1}} 43 | 44 | {{else}} 45 | 46 | {{end}} 47 | 50 | 编辑   51 | 52 | 删除 53 |
58 | 59 |
60 | 61 | 64 | 65 |
66 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /views/admin/goodsTypeAttribute/index.html: -------------------------------------------------------------------------------- 1 | {{template "../public/page_header.html"}} 2 | 3 |
4 |
5 |
6 | 7 | 8 |
9 | 类型----{{.goodsType.Title}} 10 | 11 | 增加商品类型属性 13 |
14 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | {{$cateTitle := .goodsType.Title}} 33 | {{range $key,$value := .goodsTypeAttrList}} 34 | 35 | 36 | 37 | 38 | 39 | 40 | 51 | 52 | 53 | 56 | 66 | 67 | 74 | 75 | 76 | {{end}} 77 | 78 |
属性名称商品类型属性值的录入方式可选值列表增加时间排序状态操作
{{$value.Title}}{{$cateTitle}} 41 | {{if eq $value.AttrType 1}} 42 | 单行文本框 43 | {{else if eq $value.AttrType 2}} 44 | 多行文本框 45 | {{else if eq $value.AttrType 3}} 46 | select下拉框 47 | {{end}} 48 | 49 | 50 | {{$value.AttrValue}}{{$value.AddTime | unixToDate}} 54 | {{$value.Sort}} 55 | 57 | 58 | {{if eq $value.Status 1}} 59 | 61 | {{else}} 62 | 64 | {{end}} 65 | 68 | 编辑 70 |   71 | 删除 73 |
79 | 80 |
81 |
82 |
83 |
84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /views/admin/access/edit.html: -------------------------------------------------------------------------------- 1 | {{template "../public/page_header.html" .}} 2 | 3 |
4 |
5 |
6 |
7 | 编辑权限 8 |
9 |
10 |
11 |
12 |
    13 | 14 |
  • 模块名称:
  • 15 |
  • 16 | 节点类型: 17 | 18 | {{$type := .access.Type}} 19 | 24 | 25 |
  • 26 | 27 |
  • 操作名称:
  • 28 | 29 |
  • 操作地址:
  • 30 | 31 | 32 |
  • 所属模块: 33 | {{$moduleId := .access.ModuleId}} 34 | 46 |
  • 47 | 48 | 49 |
  • 排  序:
  • 50 | 51 | 52 |
  • 描  述 : 53 | 54 | 55 |
  • 56 | 57 | 58 |
  • 状  态: 59 | {{$status := .access.Status}} 60 | 61 | 62 |   63 |
  • 64 | 65 |
  • 66 |
    67 | 68 |
  • 69 | 70 |
71 | 72 | 73 |
74 |
75 |
76 | 77 | 78 |
79 | 80 |
81 |
82 | 83 | 84 | -------------------------------------------------------------------------------- /controllers/admin/access.go: -------------------------------------------------------------------------------- 1 | package admin 2 | 3 | import ( 4 | "mi.com/models" 5 | "strconv" 6 | ) 7 | 8 | type AccessController struct { 9 | BaseController 10 | } 11 | 12 | func (this *AccessController) Get() { 13 | access := []models.Access{} 14 | models.DB.Preload("AccessItem").Where("module_id=0").Find(&access) 15 | this.Data["accessList"] = access 16 | this.TplName = "admin/access/index.html" 17 | } 18 | 19 | func (this *AccessController) Add() { 20 | // 加载顶级模块 21 | access := []models.Access{} 22 | models.DB.Where("module_id=0").Find(&access) 23 | this.Data["accessList"] = access 24 | this.TplName = "admin/access/add.html" 25 | } 26 | 27 | func (this *AccessController) DoAdd() { 28 | moduleName := this.GetString("module_name") 29 | iType, err1 := this.GetInt("type") 30 | actionName := this.GetString("action_name") 31 | url := this.GetString("url") 32 | moduleId, err2 := this.GetInt("module_id") 33 | sort, err3 := this.GetInt("sort") 34 | description := this.GetString("description") 35 | status, err4 := this.GetInt("status") 36 | if err1 != nil || err2 != nil || err3 != nil || err4 != nil { 37 | this.Error("传入参数错误", "/access/add") 38 | return 39 | } 40 | access := models.Access{ 41 | ModuleName: moduleName, 42 | Type: iType, 43 | ActionName: actionName, 44 | Url: url, 45 | ModuleId: moduleId, 46 | Sort: sort, 47 | Description: description, 48 | Status: status, 49 | } 50 | err := models.DB.Create(&access).Error 51 | if err != nil { 52 | this.Error("增加数据失败", "/access/add") 53 | } else { 54 | this.Success("增加数据成功", "/access") 55 | } 56 | 57 | } 58 | 59 | func (this *AccessController) Edit() { 60 | //获取要修改的数据 61 | id, err1 := this.GetInt("id") 62 | if err1 != nil { 63 | this.Error("传入参数错误", "/access") 64 | return 65 | } 66 | access := models.Access{Id: id} 67 | models.DB.Find(&access) 68 | this.Data["access"] = access 69 | 70 | //获取顶级模块 71 | accessList := []models.Access{} 72 | models.DB.Where("module_id=0").Find(&accessList) 73 | this.Data["accessList"] = accessList 74 | 75 | this.TplName = "admin/access/edit.html" 76 | 77 | } 78 | 79 | func (this *AccessController) DoEdit() { 80 | id, err1 := this.GetInt("id") 81 | moduleName := this.GetString("module_name") 82 | iType, err2 := this.GetInt("type") 83 | actionName := this.GetString("action_name") 84 | url := this.GetString("url") 85 | moduleId, err3 := this.GetInt("module_id") 86 | sort, err4 := this.GetInt("sort") 87 | description := this.GetString("description") 88 | status, err5 := this.GetInt("status") 89 | if err1 != nil || err2 != nil || err3 != nil || err4 != nil || err5 != nil { 90 | this.Error("传入参数错误", "/access") 91 | return 92 | } 93 | access := models.Access{Id: id} 94 | models.DB.Find(&access) 95 | access.ModuleName = moduleName 96 | access.Type = iType 97 | access.ActionName = actionName 98 | access.Url = url 99 | access.ModuleId = moduleId 100 | access.Sort = sort 101 | access.Description = description 102 | access.Status = status 103 | err := models.DB.Save(&access).Error 104 | if err != nil { 105 | this.Error("修改失败", "/access/edit?id="+strconv.Itoa(id)) 106 | return 107 | } 108 | this.Success("修改成功", "/access/") 109 | 110 | } 111 | 112 | func (this *AccessController) Delete() { 113 | id, err1 := this.GetInt("id") 114 | if err1 != nil { 115 | this.Error("传入参数错误", "/access") 116 | return 117 | } 118 | 119 | // 获取当前数据 120 | access := models.Access{Id: id} 121 | models.DB.Find(&access) 122 | if access.ModuleId == 0 { 123 | accessSmall := []models.Access{} 124 | models.DB.Where("module_id=?", access.Id).Find(&accessSmall) 125 | if len(accessSmall) > 0 { 126 | this.Error("当前模块下面还有菜单或者操作,无法删除", "/access") 127 | return 128 | } 129 | }else { 130 | models.DB.Delete(&access) 131 | this.Success("删除成功","/access") 132 | } 133 | 134 | } 135 | -------------------------------------------------------------------------------- /views/mindex/buy/confirm.html: -------------------------------------------------------------------------------- 1 | {{template "../public/page_header.html" .}} 2 | 3 | 4 | 5 | 6 | 12 | 13 |
14 |
15 |
16 |
17 |
18 |

订单提交成功!去付款咯~

19 |

20 |

请在14分59秒内完成支付, 超时后将取消订单

21 | 23 |
24 |
25 |

26 | 应付总额:{{.order.AllPrice}} 27 |

28 |
29 |
30 | 订单详情 31 |
32 |
33 | 34 |
35 |
    36 |
  • 37 |
    订单号:
    38 |
    39 | {{.order.OrderId}} 40 |
    41 |
  • 42 |
  • 43 |
    收货信息:
    44 |
    45 | 收货信息:{{.order.Name}} {{.order.Phone}}    {{.order.Address}}
    46 |
  • 47 |
  • 48 |
    商品名称:
    49 |
    50 | {{range $key,$value:=.orderItem}} 51 |

    {{$value.ProductTitle}} {{$value.GoodsVersion}} {{$value.GoodsColor}} 数量:{{$value.ProductNum}} 价格:{{$value.ProductPrice}}

    52 | {{end}} 53 |
    54 |
  • 55 |
  • 56 |
    配送时间:
    57 |
    58 | 不限送货时间
    59 |
  • 60 |
  • 61 |
    发票信息:
    62 |
    63 | 电子发票 个人
    64 |
  • 65 |
66 |
67 |
68 | 69 |
70 |
71 | 选择以下支付方式付款 72 |
73 | 74 |
75 | 76 |
77 |
    78 |
  • 微信支付
  • 79 |
  • 支付宝
  • 80 | 81 |
82 |
83 |
84 | 85 |
86 |
87 |
88 | 89 | 98 | 99 | 100 |
101 |
小米商城|MIUI|米聊|多看书城|小米路由器|视频电话|小米天猫店|小米淘宝直营店|小米网盟|小米移动|隐私政策|Select Region
102 |
©mi.com 京ICP证110507号 京ICP备10046444号 京公网安备11010802020134号 京网文[2014]0059-0009号
103 |
违法和不良信息举报电话:185-0130-1238,本网站所列数据,除特殊说明,所有数据均出自我司实验室测试
104 |
105 | 106 | 107 | 108 | -------------------------------------------------------------------------------- /controllers/admin/base.go: -------------------------------------------------------------------------------- 1 | package admin 2 | 3 | import ( 4 | "errors" 5 | "github.com/aliyun/aliyun-oss-go-sdk/oss" 6 | "github.com/astaxie/beego" 7 | "mi.com/models" 8 | "os" 9 | "path" 10 | "strconv" 11 | "strings" 12 | ) 13 | 14 | type BaseController struct { 15 | beego.Controller 16 | } 17 | 18 | func (this *BaseController) Success(message,redirect string) { 19 | this.Data["message"] = message 20 | if strings.Contains(redirect,"http"){ 21 | this.Data["redirect"] = redirect 22 | }else { 23 | this.Data["redirect"] = "/"+ beego.AppConfig.String("adminPath") + redirect 24 | } 25 | this.TplName = "admin/public/success.html" 26 | } 27 | func (this *BaseController) Error(message,redirect string) { 28 | this.Data["message"] = message 29 | if strings.Contains(redirect,"http"){ 30 | this.Data["redirect"] = redirect 31 | }else { 32 | this.Data["redirect"] = "/"+ beego.AppConfig.String("adminPath") + redirect 33 | } 34 | this.TplName = "admin/public/error.html" 35 | } 36 | 37 | func (this *BaseController) Goto(redirect string) { 38 | this.Redirect("/"+ beego.AppConfig.String("adminPath") + redirect,302) 39 | } 40 | 41 | func (this *BaseController) UploadImg(picName string) (string, error) { 42 | ossStatus,_:= beego.AppConfig.Bool("ossStatus") 43 | if ossStatus== true { 44 | return this.OssUploadImg(picName) 45 | }else { 46 | return this.LoclUploadImg(picName) 47 | } 48 | } 49 | 50 | // 本地上传 51 | func (this *BaseController) LoclUploadImg(picName string) (string, error) { 52 | //1、获取上传的文件 53 | f, h, err := this.GetFile(picName) 54 | if err != nil { 55 | return "", err 56 | } 57 | //2、关闭文件流 58 | defer f.Close() 59 | //3、获取后缀名 判断类型是否正确 .jpg .png .gif .jpeg 60 | extName := path.Ext(h.Filename) 61 | 62 | allowExtMap := map[string]bool{ 63 | ".jpg": true, 64 | ".png": true, 65 | ".gif": true, 66 | ".jpeg": true, 67 | } 68 | 69 | if _, ok := allowExtMap[extName]; !ok { 70 | 71 | return "", errors.New("图片后缀名不合法") 72 | } 73 | //4、创建图片保存目录 static/upload/20210201 74 | day := models.GetDay() 75 | dir := "static/upload/" + day 76 | 77 | if err := os.MkdirAll(dir, 0666); err != nil { 78 | return "", err 79 | } 80 | //5、生成文件名称 144325235235.png 81 | fileUnixName := strconv.FormatInt(models.GetUnixNano(), 10) 82 | //static/upload/20200623/144325235235.png 83 | saveDir := path.Join(dir, fileUnixName+extName) 84 | //6、保存图片 85 | this.SaveToFile(picName, saveDir) 86 | 87 | return saveDir, nil 88 | } 89 | 90 | // Oss云存储 91 | func (this *BaseController) OssUploadImg(picName string) (string, error) { 92 | //0:获取系统信息 93 | setting := models.Setting{} 94 | models.DB.First(&setting) 95 | 96 | //1、获取上传的文件 97 | f, h, err := this.GetFile(picName) 98 | if err != nil { 99 | return "", err 100 | } 101 | //2、关闭文件流 102 | defer f.Close() 103 | //3、获取后缀名 判断类型是否正确 .jpg .png .gif .jpeg 104 | extName := path.Ext(h.Filename) 105 | 106 | allowExtMap := map[string]bool{ 107 | ".jpg": true, 108 | ".png": true, 109 | ".gif": true, 110 | ".jpeg": true, 111 | } 112 | 113 | if _, ok := allowExtMap[extName]; !ok { 114 | return "", errors.New("图片后缀名不合法") 115 | } 116 | 117 | // 把文件流上传到oss里面 118 | 119 | // 创建OSSClient实例 120 | client, err := oss.New(setting.EndPoint, setting.Appid, setting.AppSecret) 121 | if err != nil { 122 | return "", err 123 | } 124 | 125 | // 获取存储空间 126 | bucket, err := client.Bucket(setting.BucketName) 127 | if err != nil { 128 | return "", err 129 | } 130 | 131 | //创建图片保存目录 132 | day := models.GetDay() 133 | dir := "static/upload/" + day 134 | //生成文件名称 144325235235.png 135 | fileUnixName := strconv.FormatInt(models.GetUnixNano(), 10) 136 | //static/upload/20200623/144325235235.png 137 | saveDir := path.Join(dir, fileUnixName+extName) 138 | 139 | // 上传文件流 140 | err = bucket.PutObject(saveDir, f) 141 | if err != nil { 142 | return "", err 143 | } 144 | return saveDir, nil 145 | } 146 | 147 | func (this *BaseController) GetSetting() models.Setting { 148 | setting := models.Setting{Id: 1} 149 | models.DB.First(&setting) 150 | return setting 151 | } -------------------------------------------------------------------------------- /controllers/admin/goodsTypeAttr.go: -------------------------------------------------------------------------------- 1 | package admin 2 | 3 | import ( 4 | "mi.com/models" 5 | "strconv" 6 | "strings" 7 | ) 8 | 9 | type GoodsTypeAttrController struct { 10 | BaseController 11 | } 12 | 13 | func (this *GoodsTypeAttrController) Get() { 14 | cateId,err1 := this.GetInt("cate_id") 15 | if err1 != nil { 16 | this.Error("非法请求","/goodsType") 17 | } 18 | //获取当前的类型 19 | goodsType := models.GoodsType{Id: cateId} 20 | models.DB.Find(&goodsType) 21 | this.Data["goodsType"] = goodsType 22 | 23 | //查询当前类型下面的商品类型属性 24 | goodsTypeAttr := []models.GoodsTypeAttribute{} 25 | models.DB.Where("cate_id=?", cateId).Find(&goodsTypeAttr) 26 | this.Data["goodsTypeAttrList"] = goodsTypeAttr 27 | 28 | this.TplName = "admin/goodsTypeAttribute/index.html" 29 | 30 | } 31 | 32 | func (this *GoodsTypeAttrController) Add() { 33 | cateId, err1 := this.GetInt("cate_id") 34 | if err1 != nil { 35 | this.Error("非法请求", "/goodsType") 36 | } 37 | 38 | goodsType := []models.GoodsType{} 39 | models.DB.Find(&goodsType) 40 | this.Data["goodsTypeList"] = goodsType 41 | this.Data["cateId"] = cateId 42 | this.TplName = "admin/goodsTypeAttribute/add.html" 43 | 44 | 45 | } 46 | 47 | func (this *GoodsTypeAttrController) DoAdd() { 48 | title := this.GetString("title") 49 | cateId, err1 := this.GetInt("cate_id") 50 | attrType, err2 := this.GetInt("attr_type") 51 | attrValue := this.GetString("attr_value") 52 | 53 | if err1 != nil || err2 != nil { 54 | this.Error("非法请求", "/goodsType") 55 | return 56 | } 57 | if strings.Trim(title, " ") == "" { 58 | this.Error("商品类型属性名称不能为空", "/goodsTypeAttribute/add?cate_id="+strconv.Itoa(cateId)) 59 | return 60 | } 61 | 62 | goodsTypeAttr := models.GoodsTypeAttribute{ 63 | Title: title, 64 | CateId: cateId, 65 | AttrType: attrType, 66 | AttrValue: attrValue, 67 | Status: 1, 68 | AddTime: int(models.GetUnix()), 69 | } 70 | models.DB.Create(&goodsTypeAttr) 71 | this.Success("增加成功", "/goodsTypeAttribute?cate_id="+strconv.Itoa(cateId)) 72 | 73 | } 74 | 75 | func (this *GoodsTypeAttrController) Edit() { 76 | 77 | id, err1 := this.GetInt("id") 78 | if err1 != nil { 79 | this.Error("非法请求", "/goodsType") 80 | return 81 | } 82 | //获取商品类型属性 83 | goodsTypeAttr := models.GoodsTypeAttribute{Id: id} 84 | models.DB.Find(&goodsTypeAttr) 85 | this.Data["goodsTypeAttr"] = goodsTypeAttr 86 | 87 | //获取所有类型 88 | goodsType := []models.GoodsType{} 89 | models.DB.Find(&goodsType) 90 | this.Data["goodsType"] = goodsType 91 | 92 | this.TplName = "admin/goodsTypeAttribute/edit.html" 93 | } 94 | 95 | func (this *GoodsTypeAttrController) DoEdit() { 96 | 97 | id, err1 := this.GetInt("id") 98 | title := this.GetString("title") 99 | cateId, err2 := this.GetInt("cate_id") 100 | attrType, err3 := this.GetInt("attr_type") 101 | attrValue := this.GetString("attr_value") 102 | sort, err4 := this.GetInt("sort") 103 | 104 | if err1 != nil || err2 != nil || err3 != nil { 105 | this.Error("非法请求", "/goodsTypeAttribute") 106 | return 107 | } 108 | if strings.Trim(title, " ") == "" { 109 | this.Error("商品类型属性名称不能为空", "/goodsTypeAttribute/edit?id="+strconv.Itoa(id)) 110 | return 111 | } 112 | if err4 != nil { 113 | this.Error("排序值不对", "/goodsTypeAttribute/edit?id="+strconv.Itoa(id)) 114 | return 115 | } 116 | goodsTypeAttr := models.GoodsTypeAttribute{Id: id} 117 | models.DB.Find(&goodsTypeAttr) 118 | goodsTypeAttr.Title = title 119 | goodsTypeAttr.CateId = cateId 120 | goodsTypeAttr.AttrType = attrType 121 | goodsTypeAttr.AttrValue = attrValue 122 | goodsTypeAttr.Sort = sort 123 | 124 | err := models.DB.Save(&goodsTypeAttr).Error 125 | if err != nil { 126 | this.Error("修改数据失败", "/goodsTypeAttribute/edit?id="+strconv.Itoa(id)) 127 | return 128 | } 129 | this.Success("需改数据成功", "/goodsTypeAttribute?cate_id="+strconv.Itoa(cateId)) 130 | 131 | } 132 | 133 | func (this *GoodsTypeAttrController) Delete() { 134 | 135 | id, err1 := this.GetInt("id") 136 | cateId, err2 := this.GetInt("cate_id") 137 | if err1 != nil { 138 | this.Error("传入参数错误", "/goodsTypeAttribute?cate_id="+strconv.Itoa(cateId)) 139 | return 140 | } 141 | if err2 != nil { 142 | this.Error("传入参数错误", "/goodsType") 143 | return 144 | } 145 | 146 | goodsTypeAttr := models.GoodsTypeAttribute{Id: id} 147 | models.DB.Delete(&goodsTypeAttr) 148 | this.Success("删除数据成功", "/goodsTypeAttribute?cate_id="+strconv.Itoa(cateId)) 149 | } 150 | 151 | -------------------------------------------------------------------------------- /controllers/admin/role.go: -------------------------------------------------------------------------------- 1 | package admin 2 | 3 | import ( 4 | "mi.com/models" 5 | "strconv" 6 | ) 7 | 8 | type RoleController struct { 9 | BaseController 10 | } 11 | 12 | func (this *RoleController) Get() { 13 | // 角色页面初始化函数 14 | // 实例化Role结构体 15 | role := []models.Role{} 16 | // 查找到role表中的所以数据 17 | models.DB.Find(&role) 18 | // 渲染到前台页面 19 | this.Data["role"] = role 20 | // 渲染模板 21 | this.TplName = "admin/role/index.html" 22 | } 23 | 24 | func (this *RoleController) Add() { 25 | // 渲染增加角色页面 26 | this.TplName = "admin/role/add.html" 27 | } 28 | 29 | func (this *RoleController) DoAdd() { 30 | // 获取前台通过POST方式传过来的数据 31 | title := this.GetString("title") 32 | description := this.GetString("description") 33 | // 并进行判断,如果标题为空,首先执行预先设置好的错误页面,接着跳转回增加页面 34 | if title == "" { 35 | this.Error("标题不能为空","/role/add") 36 | return 37 | } 38 | // 通过给Role模型赋值,执行增加数据操作 39 | role := models.Role{} 40 | role.Title = title 41 | role.Description = description 42 | role.Status = 1 43 | role.AddTime = int(models.GetUnix()) 44 | // 执行增加操作,并返回错误信息,如果有的话 45 | err := models.DB.Create(&role).Error 46 | if err != nil { 47 | this.Error("增加角色失败","/role/add") 48 | }else { 49 | this.Success("增加角色成功","/role") 50 | } 51 | } 52 | 53 | func (this *RoleController) Edit() { 54 | id,err := this.GetInt("id") 55 | if err != nil { 56 | this.Error("传入参数错误","/role") 57 | return 58 | } 59 | 60 | role := models.Role{Id: id} 61 | models.DB.Find(&role) 62 | this.Data["role"] =role 63 | this.TplName = "admin/role/edit.html" 64 | } 65 | 66 | func (this *RoleController) DoEdit() { 67 | id,err := this.GetInt("id") 68 | if err != nil { 69 | this.Error("传入参数错误","/role") 70 | return 71 | } 72 | title := this.GetString("title") 73 | description := this.GetString("description") 74 | 75 | if title == "" { 76 | this.Error("标题不能为空","/role/add") 77 | return 78 | } 79 | role := models.Role{Id:id} 80 | models.DB.Find(&role) 81 | 82 | role.Title = title 83 | role.Description = description 84 | 85 | err_save := models.DB.Save(&role).Error 86 | if err_save != nil { 87 | this.Error("修改数据失败","/role/edit?id="+strconv.Itoa(id)) 88 | }else { 89 | this.Success("修改数据成功","/role") 90 | } 91 | } 92 | 93 | func (this *RoleController) Delete() { 94 | id,err := this.GetInt("id") 95 | if err != nil { 96 | this.Error("传入参数错误","/role") 97 | return 98 | } 99 | role := models.Role{Id: id} 100 | models.DB.Delete(&role) 101 | this.Success("删除角色成功","/role") 102 | } 103 | 104 | func (this *RoleController) Auth() { 105 | // 1:获取角色ID 106 | roleId,err := this.GetInt("id") 107 | if err != nil { 108 | this.Error("传入参数错误","/role") 109 | return 110 | } 111 | // 2:获取全部权限 112 | access := []models.Access{} 113 | models.DB.Preload("AccessItem").Where("module_id=0").Find(&access) 114 | 115 | // 3:获取当前角色拥有的权限,并把权限id放在一个map对象里面 116 | roleAccess := []models.RoleAccess{} 117 | models.DB.Where("role_id=?",roleId).Find(&roleAccess) 118 | 119 | 120 | roleAccessMap := make(map[int]int) 121 | for _, v := range roleAccess { 122 | roleAccessMap[v.AccessId] = v.AccessId 123 | } 124 | 125 | // 4:循环遍历所有的权限数据,判断当前权限的id是否在角色权限的map对象当中 126 | // 如果存在,将checked字段变为true 127 | for i := 0; i 0 { 150 | this.Error("当前分类下面还子分类,无法删除", "/goodsCate") 151 | return 152 | } 153 | } 154 | goodsCate2 := models.GoodsCate{Id: id} 155 | models.DB.Delete(&goodsCate2) 156 | this.Success("删除成功", "/goodsCate") 157 | 158 | } -------------------------------------------------------------------------------- /controllers/mindex/buy.go: -------------------------------------------------------------------------------- 1 | package mindex 2 | 3 | import ( 4 | "mi.com/models" 5 | "strconv" 6 | ) 7 | 8 | type BuyController struct { 9 | BaseController 10 | } 11 | 12 | func (this *BuyController) CheckOut() { 13 | // 调用公共的功能 14 | this.SuperInit() 15 | 16 | // 获取结算的商品 17 | cartList := []models.Cart{} 18 | orderList := []models.Cart{} // 需要结算的商品 19 | models.Cookie.Get(this.Ctx, "cartList", &cartList) 20 | var allPrice float64 21 | 22 | for i := 0; i < len(cartList); i++ { 23 | if cartList[i].Checked { 24 | allPrice += cartList[i].Price * float64(cartList[i].Num) 25 | orderList = append(orderList, cartList[i]) 26 | } 27 | } 28 | // 判断去结算页面有没有要结算的商品 29 | if len(orderList) == 0 { 30 | this.Redirect("/", 302) 31 | return 32 | } 33 | 34 | this.Data["orderList"] = orderList 35 | this.Data["allPrice"] = allPrice 36 | 37 | // 获取收货地址 38 | user := models.User{} 39 | models.Cookie.Get(this.Ctx, "userinfo", &user) 40 | addressList := []models.Address{} 41 | models.DB.Where("uid=?", user.Id).Order("default_address desc").Find(&addressList) 42 | this.Data["addressList"] = addressList 43 | 44 | // 防止重复提交订单 生成签名 45 | orderSign := models.Md5(models.GetRandomNum()) 46 | this.SetSession("orderSign", orderSign) 47 | this.Data["orderSign"] = orderSign 48 | this.TplName = "mindex/buy/checkout.html" 49 | 50 | } 51 | 52 | func (this *BuyController) DoOrder() { 53 | // 0: 防止重复订单 54 | orderSign := this.GetString("orderSign") 55 | sessionOrderSign := this.GetString("orderSign") 56 | if sessionOrderSign != orderSign { 57 | this.Redirect("/", 302) 58 | return 59 | } 60 | this.DelSession("orderSign") 61 | 62 | // 1:获取收获地址信息 63 | user := models.User{} 64 | models.Cookie.Get(this.Ctx, "userinfo", &user) 65 | addressResult := []models.Address{} 66 | models.DB.Where("uid=? AND default_address=1", user.Id).Find(&addressResult) 67 | if len(addressResult) == 0 { 68 | this.Error("您还没有填写地址,无法完成支付","/buy/checkout") 69 | return 70 | } 71 | 72 | // 2:获取购物商品的信息 orderList就是要购买的商品信息 73 | cartList := []models.Cart{} 74 | orderList := []models.Cart{} 75 | models.Cookie.Get(this.Ctx, "cartList", &cartList) 76 | var allPrice float64 77 | for i := 0; i < len(cartList); i++ { 78 | if cartList[i].Checked { 79 | allPrice += cartList[i].Price * float64(cartList[i].Num) 80 | orderList = append(orderList, cartList[i]) 81 | } 82 | } 83 | 84 | // 3:把订单信息放在订单表中,把商品信息放在商品表中 85 | order := models.Order{ 86 | OrderId: models.GetOrderId(), 87 | Uid: user.Id, 88 | AllPrice: allPrice, 89 | Phone: addressResult[0].Phone, 90 | Name: addressResult[0].Name, 91 | Address: addressResult[0].Address, 92 | Zipcode: addressResult[0].Zipcode, 93 | PayStatus: 0, 94 | PayType: 0, 95 | OrderStatus: 0, 96 | AddTime: int(models.GetUnix()), 97 | } 98 | err := models.DB.Create(&order).Error 99 | if err == nil { 100 | for i := 0; i < len(orderList); i++ { 101 | orderItem := models.OrderItem{ 102 | OrderId: order.Id, 103 | Uid: user.Id, 104 | ProductTitle: orderList[i].Title, 105 | ProductId: orderList[i].Id, 106 | ProductImg: orderList[i].GoodsImg, 107 | ProductPrice: orderList[i].Price, 108 | ProductNum: orderList[i].Num, 109 | GoodsVersion: orderList[i].GoodsVersion, 110 | GoodsColor: orderList[i].GoodsColor, 111 | } 112 | models.DB.Create(&orderItem) 113 | } 114 | 115 | } else { 116 | // 非法请求 117 | this.Redirect("/buy/chackout", 302) 118 | } 119 | // 4、删除购物车里面的选中数据 120 | 121 | noSelectedCartList := []models.Cart{} 122 | for i := 0; i < len(cartList); i++ { 123 | if !cartList[i].Checked { 124 | noSelectedCartList = append(noSelectedCartList, cartList[i]) 125 | } 126 | } 127 | models.Cookie.Set(this.Ctx, "cartList", noSelectedCartList) 128 | this.Redirect("/buy/confirm?id="+strconv.Itoa(order.Id), 302) 129 | 130 | } 131 | 132 | func (this *BuyController) Confirm() { 133 | this.SuperInit() 134 | id, err := this.GetInt("id") 135 | if err != nil { 136 | this.Redirect("/", 302) 137 | return 138 | } 139 | //获取用户信息 140 | user := models.User{} 141 | models.Cookie.Get(this.Ctx, "userinfo", &user) 142 | 143 | //获取主订单信息 144 | order := models.Order{} 145 | models.DB.Where("id=?", id).Find(&order) 146 | this.Data["order"] = order 147 | //判断当前数据是否合法 148 | if user.Id != order.Uid { 149 | this.Redirect("/", 302) 150 | return 151 | } 152 | 153 | //获取主订单下面的商品信息 154 | orderItem := []models.OrderItem{} 155 | models.DB.Where("order_id=?", id).Find(&orderItem) 156 | this.Data["orderItem"] = orderItem 157 | 158 | this.TplName = "mindex/buy/confirm.html" 159 | 160 | } 161 | -------------------------------------------------------------------------------- /views/admin/goodsCate/index.html: -------------------------------------------------------------------------------- 1 | {{template "../public/page_header.html"}} 2 |
3 | 4 | 5 | 6 |
7 | 8 |
9 |
10 | 增加商品分类 11 |
12 | 13 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | {{range $key,$value := .goodsCateList}} 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 45 | 49 | 50 | 51 | 52 | {{range $k,$v := $value.GoodsCateItem}} 53 | 54 | 55 | 56 | 59 | 60 | 66 | 76 | 80 | 81 | {{end}} 82 | {{end}} 83 | 84 |
分类名称分类图片排序状态操作
{{$value.Title}}{{$value.Sort}} 38 | {{if eq $value.Status 1}} 39 | 40 | {{else}} 41 | 42 | {{end}} 43 | 44 |   46 | 编辑   47 | 删除 48 |
  ---{{$v.Title}} 57 | 58 | 61 | 62 | {{$v.Sort}} 63 | 64 | 65 | 67 | 68 | {{if eq $v.Status 1}} 69 | 70 | {{else}} 71 | 72 | {{end}} 73 | 74 | 75 |   77 | 编辑   78 | 删除 79 |
85 |
86 |
87 |
88 |
89 | 90 | 91 | -------------------------------------------------------------------------------- /controllers/mindex/address.go: -------------------------------------------------------------------------------- 1 | package mindex 2 | 3 | import ( 4 | "mi.com/models" 5 | ) 6 | 7 | type AddressController struct { 8 | BaseController 9 | } 10 | 11 | // 增加收货地址 12 | func (this *AddressController) AddAddress() { 13 | /* 14 | 1、获取表单提交的数据 15 | 16 | 2、判断收货地址的数量 17 | 18 | 3、更新当前用户的所有收货地址的默认收货地址状态为0 19 | 20 | 4、增加当前收货地址,让默认收货地址状态是1 21 | 22 | 5、返回当前用户的所有收货地址返回 23 | 24 | */ 25 | // 1、获取表单提交的数据 26 | user := models.User{} 27 | models.Cookie.Get(this.Ctx, "userinfo", &user) 28 | 29 | name := this.GetString("name") 30 | phone := this.GetString("phone") 31 | address := this.GetString("address") 32 | zipcode := this.GetString("zipcode") 33 | 34 | // 2、判断收货地址的数量 35 | var addressCount int 36 | models.DB.Where("uid=?", user.Id).Table("address").Count(&addressCount) 37 | if addressCount > 10 { 38 | this.Data["json"] = map[string]interface{}{ 39 | "success": false, 40 | "message": "增加收货地址失败 收货地址数量超过限制", 41 | } 42 | this.ServeJSON() 43 | return 44 | } 45 | 46 | // 3、更新当前用户的所有收货地址的默认收货地址状态为0 47 | models.DB.Table("address").Where("uid=?", user.Id).Updates(map[string]interface{}{"default_address": 0}) 48 | 49 | // 4、增加当前收货地址,让默认收货地址状态是1 50 | 51 | addressResult := models.Address{ 52 | Uid: user.Id, 53 | Name: name, 54 | Phone: phone, 55 | Address: address, 56 | Zipcode: zipcode, 57 | DefaultAddress: 1, 58 | } 59 | models.DB.Create(&addressResult) 60 | 61 | // 5、返回当前用户的所有收货地址返回 62 | allAddressResult := []models.Address{} 63 | models.DB.Where("uid=?", user.Id).Find(&allAddressResult) 64 | 65 | this.Data["json"] = map[string]interface{}{ 66 | "success": true, 67 | "result": allAddressResult, 68 | } 69 | this.ServeJSON() 70 | 71 | } 72 | 73 | // 获取一个收货地址 返回指定收货地址id的收货地址 74 | func (this *AddressController) GetOneAddressList() { 75 | 76 | addressId,err := this.GetInt("address_id") 77 | if err != nil { 78 | this.Data["json"] = map[string]interface{}{ 79 | "success":false, 80 | "message":"传入参数错误", 81 | } 82 | this.ServeJSON() 83 | return 84 | } 85 | 86 | address := models.Address{} 87 | models.DB.Where("id=?",addressId).Find(&address) 88 | this.Data["json"] = map[string]interface{}{ 89 | "success":true, 90 | "result":address, 91 | } 92 | this.ServeJSON() 93 | 94 | } 95 | 96 | // 编辑收货地址 97 | func (this *AddressController) DoEditAddressList() { 98 | /* 99 | 1、获取表单增加的数据 100 | 101 | 2、更新当前用户的所有收货地址的默认收货地址状态为0 102 | 103 | 3、修改当前收货地址,让默认收货地址状态是1 104 | 105 | 4、查询当前用户的所有收货地址并返回 106 | 107 | */ 108 | user := models.User{} 109 | models.Cookie.Get(this.Ctx, "userinfo", &user) 110 | 111 | addressId, err := this.GetInt("address_id") 112 | if err != nil { 113 | this.Data["json"] = map[string]interface{}{ 114 | "success": false, 115 | "message": "传入参数错误", 116 | } 117 | this.ServeJSON() 118 | return 119 | } 120 | name := this.GetString("name") 121 | phone := this.GetString("phone") 122 | address := this.GetString("address") 123 | zipcode := this.GetString("zipcode") 124 | 125 | // 2、更新当前用户的所有收货地址的默认收货地址状态为0 126 | models.DB.Table("address").Where("uid=?", user.Id).Updates(map[string]interface{}{"default_address": 0}) 127 | // 3、修改当前收货地址,让默认收货地址状态是1 128 | addressModel := models.Address{} 129 | models.DB.Where("id=?", addressId).Find(&addressModel) 130 | addressModel.Name = name 131 | addressModel.Phone = phone 132 | addressModel.Address = address 133 | addressModel.Zipcode = zipcode 134 | addressModel.DefaultAddress = 1 135 | models.DB.Save(&addressModel) 136 | // 4、查询当前用户的所有收货地址并返回 137 | allAddressResult := []models.Address{} 138 | models.DB.Where("uid=?", user.Id).Order("default_address desc").Find(&allAddressResult) 139 | 140 | this.Data["json"] = map[string]interface{}{ 141 | "success": true, 142 | "result": allAddressResult, 143 | } 144 | this.ServeJSON() 145 | 146 | } 147 | 148 | // 修改默认的收货地址 149 | func (this *AddressController) ChangeDefaultAddress() { 150 | /* 151 | 1、获取当前用户收货地址id 以及用户id 152 | 2、更新当前用户的所有收货地址的默认收货地址状态为0 153 | 3、更新当前收货地址的默认收货地址状态为1 154 | */ 155 | user := models.User{} 156 | models.Cookie.Get(this.Ctx, "userinfo", &user) 157 | addressId, err := this.GetInt("address_id") 158 | if err != nil { 159 | this.Data["json"] = map[string]interface{}{ 160 | "success": false, 161 | "message": "传入参数错误", 162 | } 163 | this.ServeJSON() 164 | return 165 | } 166 | models.DB.Table("address").Where("uid=?", user.Id).Updates(map[string]interface{}{"default_address": 0}) 167 | 168 | models.DB.Table("address").Where("id=?", addressId).Updates(map[string]interface{}{"default_address": 1}) 169 | 170 | this.Data["json"] = map[string]interface{}{ 171 | "success": true, 172 | "result": "更新默认收货地址成功", 173 | } 174 | this.ServeJSON() 175 | 176 | } 177 | 178 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 环境配置 2 | 3 | - win10 4 | - Go 1.15 5 | - BeeGo 1.12 6 | - Mysql 8.0 7 | - Redis 8 | 9 | `项目演示网址`:http://mi.sunyj.xyz 10 | 11 | `项目后台网址`:http://mi.sunyj.xyz/admin/ 管理员账号:tourists 密码:123456 12 | 13 | `项目视频演示`https://www.bilibili.com/video/BV1Up4y1n7iU#reply4178353497 14 | 15 | 由于项目中的static文件内容较多,而且代码放在GitHub上面,有的同学可能下载速度会很慢,我就将这里面的内容放在了蓝奏云,下载完成后,解压到此目录即可https://wwx.lanzoui.com/i3wlPlxmt9e 16 | 17 | 项目介绍网址:https://syjun.vip/archives/286.html 18 | 19 | ## 1:生成数据表 20 | 在MySql数据库中创建名为`micom`的数据,接着运行sql文件 21 | 数据导入成功后,需要修改项目中的数据库连接代码 22 | 修改models文件夹中的core.go 23 | ```go 24 | func init() { 25 | DB,err = gorm.Open("mysql", "root:123456@/micom?charset=utf8&parseTime=True&loc=Local") 26 | //DB,err = gorm.Open("mysql", "用户名:数据库密码@/数据库名称?charset=utf8&parseTime=True&loc=Local") 27 | if err != nil { 28 | beego.Error(err) 29 | } 30 | } 31 | ``` 32 | 33 | ## 2:安装第三方包 34 | 在IDE(VSCode或者Goland或者其他IDE)中打开此项目,运行(运行之前记得开启redis)main.go文件,不出意外的应该会自动安装go.mod里面的第三方包 35 | 如果不行的话,可在go.mod里面查看第三方包选择手动安装 36 | 37 | ## 3:运行项目 38 | 准备工作完成后,就可以运行项目啦 39 | 你可以选择运行main.go文件,也可以在终端输入`bee run`,运行此项目 40 | 最后打开 http://127.0.0.1:8080/ 即可 默认用户:1007643852@qq.com 密码:123456 41 | 后台地址 http://127.0.0.1:8080/admin 管理员账号:admin 密码:123456(进入后台可修改) 42 | 43 | 44 | ---------- 45 | 到此为止,项目应该是能跑起来了,如果你只想体验一下这个项目,完成前三步就行了 46 | 如果你想实现oss云存储和用户注册的功能,可以接着往下看 47 | 48 | ## 4:oss云存储 49 | 我自己部署的项目是将图片放在oss云存储里面的,在app.conf文件中,`ossStatus = true` 50 | 但是,在GitHub上面的代码,`ossStatus = false`,也就是默认关闭了这个功能 51 | 项目中的图片能够正常显示,是因为我把云存储上面的图片都下载下来放在了项目中 52 | 53 | 如果你想使用oss云存储功能,需要先在阿里云开通此服务,并将static中的文件全部上传 54 | 之所以需要在阿里云开通服务,是因为项目中使用的是阿里云的SDK 55 | 开通并上传文件后,在后台中的其他配置中,将所需的参数填入即可 56 | ![][8] 57 | 58 | 最后,在app.conf文件中将`ossStatus`改为`true` 59 | 60 | ## 5:发送邮件,完善注册功能 61 | 想要发送邮件,必须给你自己的邮箱开头STMP服务 62 | 之后,在controller/mindex/login.go文件中第143行代码进行修改 63 | ![][9] 64 | 65 | 接着,在浏览代码中你会看见这样的代码 66 | 也就是需要将项目部署上线并有域名才能实现这个功能 67 | ```go 68 | verifyUrl := "部署上线的域名地址/pass/verifyUrl?verify="+models.Md5(passwd+"micom")+"&email="+email 69 | // 示例代码 70 | verifyUrl := "http://mi.sunyj.xyz/pass/verifyUrl?verify="+models.Md5(passwd+"micom")+"&email="+email 71 | ``` 72 | 73 | ## 6:部署上线 74 | 75 | ### linux服务器部署beego项目 76 | 要想项目跑在服务器上,那么肯定需要准备一台服务器,这里我已Linux为例 77 | 如果说,你想通过指定的网址进行访问,那么还需要一个域名 78 | 如果没有的话也没关系,可以通过IP地址加端口号也可以进行访问 79 | 80 | ### 1:将本地数据库文件复制到服务器的数据中 81 | 82 | 这里我使用的是Navicat这个软件进行操作 83 | 84 | 1. 首先将本地数据库中的数据加结构转储为SQL文件 85 | ![][50] 86 | 2. 使用Navicat连接服务器的数据库 87 | 3. 连接成功后,运行刚才转储的SQL文件 88 | 需要注意的是,SQL文件中的字符集和排序规则**一定**要和服务器数据的类型一样,不然会导入数据失败 89 | 如果类型不一样,先查看服务器中的类型是什么,接着用notepad++或者其他工具打开刚才的SQL文件,进行批量替换就行了 90 | ![][51] 91 | 92 | ### 2:打包BeeGO项目 93 | 在打包之前,我们需要更改一些项目连接数据库的参数 94 | 在腾讯云服务器中,包含数据库文件的数据库为micom,用户为micom,密码为124212,跟本地数据库的信息不同,所以需要在core.go文件中进行修改 95 | ```go 96 | func init() { 97 | DB,err = gorm.Open("mysql", "micom:124212@/micom?charset=utf8&parseTime=True&loc=Local") 98 | if err != nil { 99 | beego.Error(err) 100 | } 101 | } 102 | ``` 103 | 104 | 在GoLand中,打开终端,输入 **bee pack -be GOOS=linux**,即可将BeeGo项目打包成Linux平台可运行的程序 105 | ![][52] 106 | 107 | ### 3:运行项目 108 | 打包成功后,会在当前项目的根目录下面生成.tar.gz文件,我们将这个文件上传到服务器的文件夹中进行解压即可 109 | 关于文件夹,建议放在www/wwwroot/创建一个文件夹 这样的目录下,我自己的目录:www/wwwroot/micom 110 | 111 | 接着,进入到micom中,输入 nohub ./项目名称 & 即可运行项目 `nohub ./micom &` 112 | 113 | `项目中用到了redis,需要在服务器中安装` 114 | 115 | 项目跑起来后,可以通过服务器的IP地址,加上你在项目中.conf配置文件中设置的端口号进行访问 116 | 117 | ### 4:DNS解析 118 | 如果我们想用域名进行访问网站,需要进行域名解析,和Nginx配置 119 | 域名解析就不用多解释了,经常玩服务器的同学应该很老练 120 | 121 | 关于Nginx,我用到了宝塔面板,在面板进行了配置 122 | 在/www/server/panel/vhost/nginx 这个目录下,新建了一个配置文件 **micom.conf** 123 | 将IP地址指向了刚刚解析的域名,这样我们就可以通过域名进行访问 124 | ![][53] 125 | ```conf 126 | server { 127 | listen 80; 128 | server_name mi.sunyj.xyz; 129 | 130 | #charset koi8-r; 131 | #access_log /var/log/nginx/host.access.log main; 132 | 133 | location / { 134 | #设置主机头和客户端真实地址,以便服务器获取客户端真实 IP 135 | proxy_set_header Host $host; 136 | proxy_set_header X-Real-IP $remote_addr; 137 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 138 | #禁用缓存 139 | proxy_buffering off; 140 | 141 | proxy_pass http://42.***.**.**:****/; 142 | } 143 | location /socket.io { 144 | # 此处改为 socket.io 后端的 ip 和端口即可 145 | proxy_pass http://127.0.0.1:3001; 146 | 147 | proxy_set_header Upgrade $http_upgrade; 148 | proxy_set_header Connection "upgrade"; 149 | proxy_http_version 1.1; 150 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 151 | proxy_set_header Host $host; 152 | } 153 | 154 | #error_page 404 /404.html; 155 | 156 | # redirect server error pages to the static page /50x.html 157 | # 158 | error_page 500 502 503 504 /50x.html; 159 | location = /50x.html { 160 | root /usr/share/nginx/html; 161 | } 162 | 163 | } 164 | ``` 165 | 166 | [8]: https://syjun.vip/usr/uploads/2021/02/3947349086.png 167 | [9]: https://syjun.vip/usr/uploads/2021/02/1067360970.png 168 | [50]: https://syjun.vip/usr/uploads/2021/02/3637480777.jpg 169 | [51]: https://syjun.vip/usr/uploads/2021/02/3498415197.jpg 170 | [52]: https://syjun.vip/usr/uploads/2021/02/2534936114.jpg 171 | [53]: https://syjun.vip/usr/uploads/2021/02/3150842554.jpg 172 | -------------------------------------------------------------------------------- /views/mindex/product/item.html: -------------------------------------------------------------------------------- 1 | {{template "../public/page_header.html" .}} 2 | {{template "../public/banner.html" .}} 3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 |
11 |
12 |
13 | {{range $key,$value := .goodsImage}} 14 | {{if eq $value.ColorId 0 }} 15 |
16 | 17 |
18 | {{end}} 19 | {{end}} 20 |
21 | 22 |
23 | 24 | 25 |
26 |
27 | 28 |
29 | 30 | 31 | 32 |
33 |
34 |
{{.goods.Title}}
35 |
{{.goods.SubTitle}}
36 |
{{.goods.Price}}元 37 | {{if eq .goods.Price .goods.MarketPrice}} 38 | {{else}} 39 | {{.goods.MarketPrice}}元 40 | {{end}} 41 | 42 |
43 | {{if .relationGoods}} 44 |
选择版本
45 | {{end}} 46 | 47 |
48 | {{$goodsId := .goods.Id}} 49 | {{range $key,$value := .relationGoods}} 50 | 56 | {{end}} 57 |
58 |
59 |
选择颜色
60 |
61 | 62 | {{range $key,$value:=.goodsColor}} 63 | 69 | {{end}} 70 | 71 |
72 |
73 |
74 |
{{.goods.Title}} {{.goods.GoodsVersion}}
75 |
{{.goods.Price}}元
76 |
77 |
78 |
总计:{{.goods.Price}}元
79 |
80 |
81 | 82 | 83 | 84 | 85 |
86 |
87 |
88 |
89 | 90 | 91 | 92 |
93 | 94 | 95 |
96 | 97 |

看了又看

98 | 99 | 100 | {{range $key, $val := .goodsGift}} 101 | 115 | {{end}} 116 |
117 | 118 | 119 |
120 |
    121 | 122 |
  • 详情描述
  • 123 | 124 |
  • 规格参数
  • 125 | 126 |
  • 用户评价
  • 127 |
128 | 129 | 130 |
131 | 132 |
133 | {{str2html .goods.GoodsContent}} 134 |
135 | 136 |
137 |
    138 | {{range $key,$value := .goodsAttr}} 139 |
  • 140 |
    141 |

    {{$value.AttributeTitle}}

    142 |
    143 |
    144 | {{$value.AttributeValue | formatAttr | str2html}} 145 |
    146 |
  • 147 | {{end}} 148 |
149 |
150 | 151 | 152 |
153 |
    154 |
  • 155 |

    依然极具性价比,希望小米越来越好,因为小米,所以米粉❤

    156 |

    2021-02-09 157 | 14:00:35 烟紫 8GB+129GB

    158 | 159 |
  • 160 | 161 |
162 |
163 |
164 |
165 |
166 | 167 | 180 | 181 | {{template "../public/page_footer.html" .}} 182 | 183 | 184 | 185 | -------------------------------------------------------------------------------- /views/admin/setting/index.html: -------------------------------------------------------------------------------- 1 | {{template "../public/page_header.html" .}} 2 | 3 |
4 |
5 |
6 |
7 | 系统设置 8 |
9 |
10 |
11 |
12 | 13 | 14 | 20 | 21 |
22 |
23 |
    24 |
  • 25 | 网站标题: 26 |
  • 27 | 28 |
  • 网站logo: 29 | 30 |
    31 | {{if ne .setting.SiteLogo ""}} 32 | 33 | {{end}} 34 |
  • 35 | 36 |
  • 网站关键词:
  • 37 | 38 |
  • 网站描述:
  • 39 | 40 |
  • 商品默认图片: 41 |
    42 | {{if ne .setting.NoPicture ""}} 43 | 44 | {{end}} 45 |
  • 46 |
  • 备案信息:
  • 47 |
  • 网站电话:
  • 48 | 49 |
  • 搜索关键词:
  • 50 | 51 |
  • 统计代码:
  • 52 | 53 |
54 |
55 |
56 |
    57 |
  • 是否开启Oss: 58 |   59 | 60 |  
  • 61 | 62 | 63 |
  • 64 | BucketName: 65 |
  • 66 |
  • 67 | Appid: 68 |
  • 69 |
  • 70 | AppSecret: 71 |
  • 72 |
  • 73 | EndPoint: 74 |
  • 75 |
76 |
77 |
78 | 79 | 80 | 81 |
82 | 83 |
84 |
85 | 86 | 87 |
88 | 89 |
90 |
91 | 92 | 93 | -------------------------------------------------------------------------------- /controllers/mindex/product.go: -------------------------------------------------------------------------------- 1 | package mindex 2 | 3 | import ( 4 | "math" 5 | "mi.com/models" 6 | "strconv" 7 | "strings" 8 | ) 9 | 10 | type ProductController struct { 11 | BaseController 12 | } 13 | 14 | func (this *ProductController) CategoryList() { 15 | // 调用公共功能 16 | this.SuperInit() 17 | 18 | //分页 19 | page, _ := this.GetInt("page") 20 | if page == 0 { 21 | page = 1 22 | } 23 | //每一页显示的数量 24 | pageSize := 10 25 | 26 | // 获取id值 27 | id := this.Ctx.Input.Param(":id") 28 | cateId, _ := strconv.Atoi(id) 29 | curretGoodsCate := models.GoodsCate{} 30 | subGoodsCate := []models.GoodsCate{} 31 | models.DB.Where("id=?", cateId).Find(&curretGoodsCate) 32 | 33 | var tempSlice []int 34 | if curretGoodsCate.Pid == 0 { //顶级分类 35 | //二级分类 36 | models.DB.Where("pid=?", curretGoodsCate.Id).Find(&subGoodsCate) 37 | for i := 0; i < len(subGoodsCate); i++ { 38 | tempSlice = append(tempSlice, subGoodsCate[i].Id) 39 | } 40 | } else { 41 | //获取当前二级分类对应的兄弟分类 42 | models.DB.Where("pid=?", curretGoodsCate.Pid).Find(&subGoodsCate) 43 | } 44 | tempSlice = append(tempSlice, cateId) 45 | where := "cate_id in (?)" 46 | goods := []models.Goods{} 47 | models.DB.Where(where, tempSlice).Select("id,title,price,goods_img,sub_title").Offset((page - 1) * pageSize).Limit(pageSize).Order("sort desc").Find(&goods) 48 | //查询goods表里面的数量 49 | var count int 50 | models.DB.Where(where, tempSlice).Table("goods").Count(&count) 51 | 52 | // 获取关联商品 53 | 54 | 55 | this.Data["goodsList"] = goods 56 | this.Data["subGoodsCate"] = subGoodsCate 57 | this.Data["curretGoodsCate"] = curretGoodsCate 58 | this.Data["totalPages"] = math.Ceil(float64(count) / float64(pageSize)) 59 | this.Data["page"] = page 60 | 61 | //指定分类模板 62 | tpl := curretGoodsCate.Template 63 | if tpl == "" { 64 | tpl = "mindex/product/list.html" 65 | } 66 | 67 | this.TplName = tpl 68 | } 69 | 70 | func (this *ProductController) ProductItem() { 71 | this.SuperInit() 72 | 73 | id := this.Ctx.Input.Param(":id") 74 | //1、获取商品信息 75 | goods := models.Goods{} 76 | models.DB.Where("id=?", id).Find(&goods) 77 | this.Data["goods"] = goods 78 | 79 | //2、获取关联商品 RelationGoods 80 | relationGoods := []models.Goods{} 81 | goods.RelationGoods = strings.ReplaceAll(goods.RelationGoods, ",", ",") 82 | relationIds := strings.Split(goods.RelationGoods, ",") 83 | models.DB.Where("id in (?)", relationIds).Select("id,title,price,goods_version").Find(&relationGoods) 84 | this.Data["relationGoods"] = relationGoods 85 | 86 | //3、获取关联赠品 GoodsGift 87 | goodsGift := []models.Goods{} 88 | goods.GoodsGift = strings.ReplaceAll(goods.GoodsGift, ",", ",") 89 | giftIds := strings.Split(goods.GoodsGift, ",") 90 | models.DB.Where("id in (?)", giftIds).Select("id,title,price,goods_img").Find(&goodsGift) 91 | this.Data["goodsGift"] = goodsGift 92 | 93 | //4、获取关联颜色 GoodsColor 94 | goodsColor := []models.GoodsColor{} 95 | goods.GoodsColor = strings.ReplaceAll(goods.GoodsColor, ",", ",") 96 | colorIds := strings.Split(goods.GoodsColor, ",") 97 | models.DB.Where("id in (?)", colorIds).Find(&goodsColor) 98 | this.Data["goodsColor"] = goodsColor 99 | 100 | //5、获取关联配件 GoodsFitting 101 | goodsFitting := []models.Goods{} 102 | goods.GoodsFitting = strings.ReplaceAll(goods.GoodsFitting, ",", ",") 103 | fittingIds := strings.Split(goods.GoodsFitting, ",") 104 | models.DB.Where("id in (?)", fittingIds).Select("id,title,price,goods_img").Find(&goodsFitting) 105 | this.Data["goodsFitting"] = goodsFitting 106 | 107 | //6、获取商品关联的图片 GoodsImage 108 | goodsImage := []models.GoodsImage{} 109 | models.DB.Where("goods_id=?", goods.Id).Find(&goodsImage) 110 | this.Data["goodsImage"] = goodsImage 111 | 112 | //7、获取规格参数信息 GoodsAttr 113 | goodsAttr := []models.GoodsAttr{} 114 | models.DB.Where("goods_id=?", goods.Id).Find(&goodsAttr) 115 | this.Data["goodsAttr"] = goodsAttr 116 | 117 | //8、获取商品其他规格参数 118 | //var goodsItemAttr []models.GoodsItemAttr 119 | //goodsAttrStr := "颜色:红色,白色,黄色|尺寸:41,42,43|套餐:套餐1,套餐2" 120 | //goodsAttrStr = strings.ReplaceAll(goodsAttrStr, ":", ":") 121 | //goodsAttrStr = strings.ReplaceAll(goodsAttrStr, ",", ",") 122 | // 123 | //if strings.Contains(goodsAttrStr, ":") { 124 | // goodsAttrSlice := strings.Split(goodsAttrStr, "|") 125 | // //分配存储空间 126 | // goodsItemAttr = make([]models.GoodsItemAttr, len(goodsAttrSlice)) 127 | // for i := 0; i < len(goodsAttrSlice); i++ { 128 | // tempSlice := strings.Split(goodsAttrSlice[i], ":") 129 | // //分类 130 | // goodsItemAttr[i].Cate = tempSlice[0] 131 | // //列表 132 | // listSlice := strings.Split(tempSlice[1], ",") 133 | // // goodsItemAttr[i].List = append(goodsItemAttr[i].List, listSlice...) 134 | // goodsItemAttr[i].List = listSlice 135 | // 136 | // } 137 | //} 138 | //this.Data["json"] = goodsItemAttr 139 | 140 | this.TplName = "mindex/product/item.html" 141 | } 142 | 143 | func (this *ProductController) GetImgList() { 144 | goods_id,err1 := this.GetInt("goods_id") 145 | goods_color,err2 := this.GetInt("color_id") 146 | 147 | // 查询商品图库信息 148 | goodsImage := []models.GoodsImage{} 149 | err3 := models.DB.Where("color_id=? AND goods_id=?",goods_color,goods_id).Find(&goodsImage).Error 150 | if err1 != nil || err2 != nil || err3 != nil{ 151 | this.Data["json"] = map[string]interface{}{ 152 | "result":"失败", 153 | "success":false, 154 | } 155 | this.ServeJSON() 156 | }else { 157 | this.Data["json"] = map[string]interface{}{ 158 | "result":goodsImage, 159 | "success":true, 160 | } 161 | this.ServeJSON() 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /routers/adminRouter.go: -------------------------------------------------------------------------------- 1 | package routers 2 | 3 | import ( 4 | "github.com/astaxie/beego" 5 | "mi.com/controllers/admin" 6 | "mi.com/middleware" 7 | ) 8 | 9 | func init() { 10 | adminPath := beego.AppConfig.String("adminPath") 11 | ns := 12 | beego.NewNamespace("/"+adminPath, 13 | beego.NSBefore(middleware.AdminAuth), 14 | // 后台管理 15 | beego.NSRouter("/",&admin.MainController{}), 16 | beego.NSRouter("/welcome",&admin.MainController{},"get:Welcome"), 17 | beego.NSRouter("/main/changeStatus",&admin.MainController{},"get:ChangeStatus"), 18 | beego.NSRouter("/main/editNum",&admin.MainController{},"get:EditNum"), 19 | beego.NSRouter("/login",&admin.LoginController{}), 20 | beego.NSRouter("/login/doLogin",&admin.LoginController{},"post:Dologin"), 21 | beego.NSRouter("/login/loginOut",&admin.LoginController{},"get:LoginOut"), 22 | beego.NSRouter("/focus",&admin.FocusController{}), 23 | beego.NSRouter("/privilege",&admin.MainController{},"get:NoPrivilege"), 24 | 25 | // 角色管理 26 | beego.NSRouter("/role",&admin.RoleController{}), 27 | beego.NSRouter("/role/add",&admin.RoleController{},"get:Add"), 28 | beego.NSRouter("/role/edit",&admin.RoleController{},"get:Edit"), 29 | beego.NSRouter("/role/doAdd",&admin.RoleController{},"post:DoAdd"), 30 | beego.NSRouter("/role/doEdit",&admin.RoleController{},"post:DoEdit"), 31 | beego.NSRouter("/role/delete",&admin.RoleController{},"get:Delete"), 32 | beego.NSRouter("/role/auth",&admin.RoleController{},"get:Auth"), 33 | beego.NSRouter("/role/doAuth",&admin.RoleController{},"post:DoAuth"), 34 | 35 | // 管理员管理 36 | beego.NSRouter("/manager",&admin.ManagerController{}), 37 | beego.NSRouter("/manager/add",&admin.ManagerController{},"get:Add"), 38 | beego.NSRouter("/manager/doAdd",&admin.ManagerController{},"post:DoAdd"), 39 | beego.NSRouter("/manager/edit",&admin.ManagerController{},"get:Edit"), 40 | beego.NSRouter("/manager/doEdit",&admin.ManagerController{},"post:DoEdit"), 41 | beego.NSRouter("/manager/delete",&admin.ManagerController{},"get:Delete"), 42 | 43 | // 权限管理 44 | beego.NSRouter("/access",&admin.AccessController{}), 45 | beego.NSRouter("/access/add",&admin.AccessController{},"get:Add"), 46 | beego.NSRouter("/access/doAdd",&admin.AccessController{},"post:DoAdd"), 47 | beego.NSRouter("/access/edit",&admin.AccessController{},"get:Edit"), 48 | beego.NSRouter("/access/doEdit",&admin.AccessController{},"post:DoEdit"), 49 | beego.NSRouter("/access/delete",&admin.AccessController{},"get:Delete"), 50 | 51 | // 轮播图管理 52 | beego.NSRouter("/focus",&admin.FocusController{}), 53 | beego.NSRouter("/focus/add",&admin.FocusController{},"get:Add"), 54 | beego.NSRouter("/focus/doAdd",&admin.FocusController{},"post:DoAdd"), 55 | beego.NSRouter("/focus/edit",&admin.FocusController{},"get:Edit"), 56 | beego.NSRouter("/focus/doEdit",&admin.FocusController{},"post:DoEdit"), 57 | beego.NSRouter("/focus/delete",&admin.FocusController{},"get:Delete"), 58 | 59 | // 商品分类管理 60 | beego.NSRouter("/goodsCate",&admin.GoodsCateController{}), 61 | beego.NSRouter("/goodsCate/add",&admin.GoodsCateController{},"get:Add"), 62 | beego.NSRouter("/goodsCate/doAdd",&admin.GoodsCateController{},"post:DoAdd"), 63 | beego.NSRouter("/goodsCate/edit",&admin.GoodsCateController{},"get:Edit"), 64 | beego.NSRouter("/goodsCate/doEdit",&admin.GoodsCateController{},"post:DoEdit"), 65 | beego.NSRouter("/goodsCate/delete",&admin.GoodsCateController{},"get:Delete"), 66 | 67 | // 商品类型管理 68 | beego.NSRouter("/goodsType",&admin.GoodsTypeController{}), 69 | beego.NSRouter("/goodsType/add",&admin.GoodsTypeController{},"get:Add"), 70 | beego.NSRouter("/goodsType/doAdd",&admin.GoodsTypeController{},"post:DoAdd"), 71 | beego.NSRouter("/goodsType/edit",&admin.GoodsTypeController{},"get:Edit"), 72 | beego.NSRouter("/goodsType/doEdit",&admin.GoodsTypeController{},"post:DoEdit"), 73 | beego.NSRouter("/goodsType/delete",&admin.GoodsTypeController{},"get:Delete"), 74 | 75 | // 商品类型属性管理 76 | beego.NSRouter("/goodsTypeAttribute",&admin.GoodsTypeAttrController{}), 77 | beego.NSRouter("/goodsTypeAttribute/add",&admin.GoodsTypeAttrController{},"get:Add"), 78 | beego.NSRouter("/goodsTypeAttribute/doAdd",&admin.GoodsTypeAttrController{},"post:DoAdd"), 79 | beego.NSRouter("/goodsTypeAttribute/edit",&admin.GoodsTypeAttrController{},"get:Edit"), 80 | beego.NSRouter("/goodsTypeAttribute/doEdit",&admin.GoodsTypeAttrController{},"post:DoEdit"), 81 | beego.NSRouter("/goodsTypeAttribute/delete",&admin.GoodsTypeAttrController{},"get:Delete"), 82 | 83 | // 商品管理 84 | beego.NSRouter("/goods",&admin.GoodsController{}), 85 | beego.NSRouter("/goods/add",&admin.GoodsController{},"get:Add"), 86 | beego.NSRouter("/goods/doAdd",&admin.GoodsController{},"post:DoAdd"), 87 | beego.NSRouter("/goods/edit",&admin.GoodsController{},"get:Edit"), 88 | beego.NSRouter("/goods/doEdit",&admin.GoodsController{},"post:DoEdit"), 89 | beego.NSRouter("/goods/delete",&admin.GoodsController{},"get:Delete"), 90 | beego.NSRouter("/goods/doUpload",&admin.GoodsController{},"post:DoUpload"), 91 | beego.NSRouter("/goods/doUploadPhoto",&admin.GoodsController{},"post:DoUploadPhoto"), 92 | beego.NSRouter("/goods/getGoodsTypeAttribute",&admin.GoodsController{},"get:GetGoodsTypeAttribute"), 93 | beego.NSRouter("/goods/changeGoodsImageColor",&admin.GoodsController{},"get:ChangeGoodsImageColor"), 94 | beego.NSRouter("/goods/removeGoodsImage",&admin.GoodsController{},"get:RemoveGoodsImage"), 95 | 96 | //导航管理 97 | beego.NSRouter("/nav", &admin.NavController{}), 98 | beego.NSRouter("/nav/add", &admin.NavController{}, "get:Add"), 99 | beego.NSRouter("/nav/edit", &admin.NavController{}, "get:Edit"), 100 | beego.NSRouter("/nav/doAdd", &admin.NavController{}, "post:DoAdd"), 101 | beego.NSRouter("/nav/doEdit", &admin.NavController{}, "post:DoEdit"), 102 | beego.NSRouter("/nav/delete", &admin.NavController{}, "get:Delete"), 103 | 104 | //系统设置 105 | beego.NSRouter("/setting", &admin.SettingController{}), 106 | beego.NSRouter("/setting/doEdit", &admin.SettingController{}, `post:DoEdit`), 107 | 108 | ) 109 | beego.AddNamespace(ns) 110 | 111 | 112 | } 113 | -------------------------------------------------------------------------------- /views/admin/goods/index.html: -------------------------------------------------------------------------------- 1 | {{template "../public/page_header.html"}} 2 | 3 | 4 | 5 |
6 |
7 | 增加商品 8 |
9 | 10 |
11 |
12 |
13 | 14 | 15 |
16 | 17 |
18 | 19 |
20 |
21 |
22 | 23 | 24 | 25 |
26 | 29 |
30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | {{range $key,$value := .goodsList}} 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 62 | 63 | 70 | 71 | 78 | 79 | 86 | 87 | 90 | 91 | 94 | 95 | 99 | 100 | {{end}} 101 | 102 |
商品名称价格原价点击量上架精品新品热销推荐排序库存操作
{{$value.Title}}{{$value.Price}}{{$value.MarketPrice}}{{$value.ClickCount}} 56 | {{if eq $value.Status 1}} 57 | 58 | {{else}} 59 | 60 | {{end}} 61 | 64 | {{if eq $value.IsBest 1}} 65 | 66 | {{else}} 67 | 68 | {{end}} 69 | 72 | {{if eq $value.IsNew 1}} 73 | 74 | {{else}} 75 | 76 | {{end}} 77 | 80 | {{if eq $value.IsHot 1}} 81 | 82 | {{else}} 83 | 84 | {{end}} 85 | 88 | {{$value.Sort}} 89 | 92 | {{$value.GoodsNumber}} 93 | 96 | 编辑   97 | 删除 98 |
103 | 104 |
105 |
106 |
107 | 123 | 124 | 125 | --------------------------------------------------------------------------------