• 缘来是他
    了解作者
  • GO
    开发工具
  • 906KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 1
    下载次数
  • 2020-05-02 07:44
    上传日期
go语言iris框架药品管理订单基础脚手架,增删改查,模板处理
goods.rar
内容介绍
package controllers import ( "github.com/kataras/iris" "github.com/kataras/iris/mvc" "github.com/kataras/iris/sessions" "goods/models" "time" ) type UserController struct { Ctx iris.Context Common Session *sessions.Session } const UserIDKey = "UserID" func (c *UserController) getCurrentUserID() int64 { userID := c.Session.GetInt64Default(UserIDKey, 0) return userID } func (c *UserController) isLoggedIn() bool { return c.getCurrentUserID() > 0 } func (c *UserController) logout() { c.Session.Destroy() } func NewUserController() *UserController { return &UserController{} } func (this *UserController) Get() mvc.Result { if !this.isLoggedIn() { this.Ctx.Redirect("/login") return mvc.View{ Name: "user/login.html", Data: iris.Map{"Title": "客户端"}, } } var user models.User if err := models.GetDB().First(&user,this.getCurrentUserID()).Error; err != nil { this.ReturnJson(1,"session错误") return mvc.View{ Name: "user/login.html", Data: iris.Map{"Title": "客户端"}, } }else { return mvc.View{ Name: "user/index.html", Data: iris.Map{ "Title": "客户端", "User":user}, } } } func (this *UserController) GetWelcome() mvc.Result { return mvc.View{ Name: "user/welcome.html", Data: iris.Map{"Title": "欢迎页面"}, } } func (this *UserController) GetLogout(){ if this.isLoggedIn() { this.logout() } this.Ctx.Redirect("/login") } func (this *UserController) GetLogin() mvc.Result { if this.isLoggedIn() { this.logout() } return mvc.View{ Name: "user/login.html", Data: iris.Map{"Title": "客户登录"}, } } func (this *UserController) PostLogin(){ var ( stuno = this.Ctx.FormValue("stuno") stupwd = this.Ctx.FormValue("stupwd") ) var user models.User if err := models.GetDB().Where(&models.User{UserNo: stuno}).First(&user).Error; err != nil { this.ReturnJson(1,"用户名不存在") }else if user.UserPwd!=stupwd { this.ReturnJson(1,"密码错误") }else{ this.Session.Set(UserIDKey, user.ID) data := make(map[string]interface{}) data["url"] = "/" this.ReturnJson(0,"登陆成功",data) } } func (this *UserController) GetAddorder() mvc.Result { if !this.isLoggedIn() { this.Ctx.Redirect("/login") return mvc.View{ Name: "user/login.html", Data: iris.Map{"Title": "客户端"}, } } var user models.User if err := models.GetDB().First(&user,this.getCurrentUserID()).Error; err != nil { this.Ctx.Redirect("/login") return mvc.View{ Name: "user/login.html", Data: iris.Map{"Title": "客户端"}, } }else { return mvc.View{ Name: "user/addorder.html", Data: iris.Map{ "Title": "提交订单", "User":user }, } } } func (this *UserController) PostAddorder(){ var ( xuke = this.Ctx.FormValue("xuke") yisheng = this.Ctx.FormValue("yisheng") address = this.Ctx.FormValue("address") name = this.Ctx.FormValue("name") tel = this.Ctx.FormValue("tel") ) ordertemp := models.Yaoorder{ OrderXuke: xuke, OrderYisheng:yisheng,OrderDizhi:address,OrderShouhuo:name,OrderDianhua:tel,OrderType:"未完成",OrderTime:time.Now().Format("2006-01-02 15:04:05") } //err := models.GetDB().Create(ordertemp).RowsAffected //if err==1{ // this.ReturnJson(1,"系统错误") //} if err := models.GetDB().Create(ordertemp).RowsAffected; err == 0 { this.ReturnJson(1,"系统错误") }else { if err1 := models.GetDB().Where("order_shouhuo = ? AND order_type = ?", name,"未完成").First(&ordertemp).Error; err1 != nil { this.ReturnJson(1,"系统错误") }else{ this.Session.Set("orderid", ordertemp.ID) this.ReturnJson(0,"添加成功") } } } func (this *UserController) GetOrderdetail() mvc.Result { if !this.isLoggedIn() { this.Ctx.Redirect("/login") return mvc.View{ Name: "user/login.html", Data: iris.Map{"Title": "客户端"}, } } var user models.User if err := models.GetDB().First(&user,this.getCurrentUserID()).Error; err != nil { this.Ctx.Redirect("/login") return mvc.View{ Name: "user/login.html", Data: iris.Map{"Title": "客户端"}, } }else { var detail []models.Orderxiang models.GetDB().Find(&detail) return mvc.View{ Name: "user/orderdetail.html", Data: iris.Map{ "Title": "订单详情", "detail":detail }, } } } func (this *UserController) PostOrderdet(){ var ( orderid = this.Ctx.FormValue("order") pinming = this.Ctx.FormValue("shipping") shuliang = this.Ctx.FormValue("num") beizhu = this.Ctx.FormValue("bak") ) detailtemp := models.Orderxiang{ OrderID: orderid, OrderPinming:pinming,OrderShuliang:shuliang,OrderBeizhu:beizhu } if err := models.GetDB().Create(detailtemp).RowsAffected; err == 0 { this.ReturnJson(1,"系统错误") }else { this.ReturnJson(0,"添加成功") } } func (this *UserController) GetListyao() { var yao []models.Yaopin models.GetDB().Find(&yao) this.Ctx.JSON(yao) } func (this *UserController) GetAdddetail() mvc.Result { return mvc.View{ Name: "user/adddetail.html", Data: iris.Map{"Title": "添加品名"}, } }
评论
    相关推荐
    • googlemap(demo).rar
      javascript操作GOOGLEMAP地图所有演示程序
    • Web_Crawler.zip
      c++ spider 源代码 网络爬虫 适合研究搜索引擎
    • swish-efiles.1.3.2.tar.gz
      用C语言写的搜索引擎,包含多种建立索引的方式
    • Internet蜘蛛程序.zip
      Internet蜘蛛程序 所谓蜘蛛即SPIDER! 相信大家都知道是什么意思
    • xunlong0.6.rar
      完整的.net搜索引擎采用LUCENE.net为索引核心,分布式架构.包含wordnet,分词,spider,简单webserver等
    • VM303TXP.rar
      摄像头驱动的重要文件,在安装时可能会提示需要此文件进行安装
    • JQuery_1.4.2_API.rar
      jQuery的1.4.2发布了!jQuer1.4.2版本修复了1.4版本的一些错误和优化了一些不错的改进。
    • websearch.zip
      简单的全路径全文搜索的程序
    • javascript.rar
      一个不错的javascript教程 很适合初学者。 从基础讲其,带实例。很适用
    • madengine.zip
      根据特定URL地址读取所有页面自动建立索引文件的搜索程序