Пример #1
0
// 删除订单
func OrderDeleteHandler(c *gin.Context) {
	r := render.New(c)

	//超级管理员才可以删除订单
	auth := userauth.Auth(c)
	if !auth.IsRole(bean.ROLE_SUPER_ADMIN) {
		r.JSON(util.JsonResult{Msg: "您没有权限"})
		return
	}

	oids := strings.TrimSpace(c.PostForm("oid"))

	var orderIds []string
	err := json.Unmarshal([]byte(oids), &orderIds)
	if err != nil {
		Logger.Warn("order delete uuids:%v, err: %v", oids, err)
		r.JSON(util.JsonResult{Success: true, Msg: "订单参数错误"})
		return
	}

	if len(orderIds) == 0 {
		r.JSON(util.JsonResult{Success: true, Msg: "请选择订单"})
		return
	}

	deleteSQL := "delete from order_info where uuid in ("
	for _, v := range orderIds {
		deleteSQL += "'" + v + "' ,"
	}
	deleteSQL = deleteSQL[:len(deleteSQL)-1] + ")"
	Logger.Debug("order delete sql: %v", deleteSQL)
	_, err = db.Engine.Exec(deleteSQL)
	util.PanicError(err)
	r.JSON(util.JsonResult{Success: true, Msg: "删除成功"})
}
Пример #2
0
func IndexHandler(c *gin.Context) {
	auth := userauth.Auth(c)
	if auth.IsLogined() {
		Logger.Debug("current login user is: %v", auth.CurUser())
		c.Redirect(http.StatusMovedPermanently, "/order/order_list.html")
	} else {
		c.Redirect(http.StatusMovedPermanently, "/user/login.html")
	}
}
Пример #3
0
Файл: nav.go Проект: sdvdxl/wine
func SidebarTemplateHandler(c *gin.Context) {
	var curNav string
	referPath := c.Request.Referer()
	referPath = referPath[strings.Index(referPath, c.Request.Host)+len(c.Request.Host):]

	log.Logger.Debug("host:%v, sidebar refer is: %v", c.Request.Host, referPath)
	if strings.HasPrefix(referPath, "/order") {
		curNav = "order"
	} else if strings.HasPrefix(referPath, "/user") {
		curNav = "user"
	}
	auth := userauth.Auth(c)
	c.HTML(http.StatusOK, "sidebar.tmpl", gin.H{"curNav": curNav, "curUser": auth.CurUser()})
}
Пример #4
0
// 更新订单
func OrderUpdateHandler(c *gin.Context) {
	r := render.New(c)

	//超级管理员才可以添加用户
	auth := userauth.Auth(c)
	if !auth.IsRole(bean.ROLE_SUPER_ADMIN) {
		r.JSON(util.JsonResult{Msg: "您没有权限"})
		return
	}

	var orderInfo = new(bean.OrderInfo)
	err := json.Unmarshal([]byte(c.PostForm("orderInfo")), orderInfo)
	util.PanicError(err)
	Logger.Debug("bind order : %v", orderInfo)

	if orderInfo.Uuid == "" {
		r.JSON(util.JsonResult{Msg: "请选择订单"})
		return
	}

	if orderInfo.OrderNo == "" {
		r.JSON(util.JsonResult{Msg: "请输入订单编号"})
		return
	}

	checkOrder := &bean.OrderInfo{OrderNo: orderInfo.OrderNo}
	found, err := db.Engine.Get(checkOrder)
	util.PanicError(err)
	if found && checkOrder.Uuid != orderInfo.Uuid {
		r.JSON(util.JsonResult{Msg: "已经存在相同的订单编号"})
		return
	}

	orderInfo.TimeUpdate = time.Now()
	address := strings.Split(orderInfo.DeliveryAddressProvince, " ")
	if len(address) == 4 {
		orderInfo.DeliveryAddressProvince = address[0]
		orderInfo.DeliveryAddressCity = address[1]
		orderInfo.DeliveryAddressArea = address[2]
		orderInfo.DeliveryAddressStreet = address[3]
	} else {
		orderInfo.DeliveryAddressProvince = ""
	}
	conditionBean := bean.OrderInfo{Uuid: orderInfo.Uuid}
	_, err = db.Engine.Update(orderInfo, conditionBean)
	util.PanicError(err)

	r.JSON(util.JsonResult{Msg: "更新成功", Success: true})
}
Пример #5
0
func TemplateHandler(c *gin.Context) {
	session := sessions.Default(c)
	userAuth := userauth.Auth(c)
	Logger.Debug("user has logined: %v", userAuth.IsLogined())

	if userAuth.IsLogined() {
		c.Redirect(http.StatusMovedPermanently, "/")
	}

	loginErrorMsg := session.Get(constant.LOGIN_ERROR_MSG)
	session.Delete(constant.LOGIN_ERROR_MSG)
	session.Save()

	c.HTML(http.StatusOK, "login.tmpl", gin.H{"loginErrorMsg": loginErrorMsg})

}
Пример #6
0
// 追加备注
func OrderAddCommentsHandler(c *gin.Context) {
	r := render.New(c)
	oid := strings.TrimSpace(c.PostForm("oid"))
	if oid == "" {
		r.JSON(util.JsonResult{Msg: "请选择订单"})
		return
	}

	order := &bean.OrderInfo{Uuid: oid}
	found, err := db.Engine.Get(order)
	util.PanicError(err)
	if !found {
		r.JSON(util.JsonResult{Msg: "没有此订单"})
		return
	}

	comments := strings.TrimSpace(c.PostForm("comments"))
	if comments == "" {
		r.JSON(util.JsonResult{Msg: "请填写内容"})
		return
	}

	auth := userauth.Auth(c)
	salesComments := &bean.SalesComments{Uuid: uuid.New(),
		TimeCreate: time.Now(),
		TimeUpdate: time.Now(),
		Comments:   comments,
		UserUuid:   auth.CurUser().Uuid,
		OrderUuid:  oid,
	}

	count, err := db.Engine.Insert(salesComments)
	util.PanicError(err)
	if count == 0 {
		r.JSON(util.JsonResult{Msg: "添加注释失败"})
		return
	}

	r.JSON(util.JsonResult{Success: true, Msg: "添加成功"})
}
Пример #7
0
func GetUserInfoHandler(c *gin.Context) {
	auth := userauth.Auth(c)
	if auth.IsLogined() {
		c.JSON(http.StatusOK, util.JsonResult{Success: true, Data: auth.CurUser()})
	}
}
Пример #8
0
// 上传订单
func OrderUploadHandler(c *gin.Context) {

	//销售不允许上传
	auth := userauth.Auth(c)
	if auth.IsRole(bean.ROLE_SALES) {
		c.HTML(http.StatusOK, "order_upload.tmpl", gin.H{"successCount": 0, "isUpload": true, "errMsg": "您没有权限"})
		return
	}

	request := c.Request
	request.ParseMultipartForm(2 << 10)
	file, fileHeader, err := request.FormFile("file")
	if err != nil {
		Logger.Error("upload file error, %v", err)
		panic(err)
	}

	_ = fileHeader

	csvReader := csv.NewReader(file)

	sql := insertSQL
	values := make([]interface{}, 0, 40)

	_, err = csvReader.Read()
	if err != nil {
		panic(err)
	} else if err == io.EOF {
		Logger.Debug("read file end")
		return
	}

	rowsCount := 0
	for {
		if row, err := csvReader.Read(); err != nil && err == io.EOF {
			break
		} else if err != io.EOF {
			rowsCount++
			// 49 params  47 ?
			sql += `(?, now(), now(), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
			?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ),`
			values = append(values, uuid.New())
			r := new(big.Rat)
			r.SetString(row[0])
			values = append(values, r.RatString())
			values = append(values, appendValues(row, 1, 12)...)
			Logger.Debug("address: %v", row[13])
			address := strings.Fields(row[13]) //dizhi

			Logger.Debug("address args len:%v", len(address))
			if len(address) == 4 {
				values = append(values, address[0])
				values = append(values, address[1])
				values = append(values, address[2])
				values = append(values, address[3])
				for i := 0; i < 3; i++ {
					values = append(values, nil)
				}
			} else {
				for i := 0; i < 7; i++ {
					values = append(values, nil)
				}
			}

			values = append(values, appendValues(row, 14, 15)...)

			runes := []rune(row[16])
			if strings.HasPrefix(row[16], "'") {
				runes = runes[1:]
			}
			values = append(values, string(runes))

			values = append(values, appendValues(row, 17, 28)...)

			runes = []rune(row[29])
			if strings.HasSuffix(row[29], "元") {
				runes = runes[:len(runes)-1]
			}
			buyerServiceFee, err := strconv.Atoi(string(runes))
			if err != nil {
				buyerServiceFee = 0
			}
			values = append(values, buyerServiceFee)
			values = append(values, appendValues(row, 30, 32)...)

			address = strings.Fields(row[35]) //dizhirow[36] //fixed dizhi
			Logger.Debug("fixed address: %v", row[35])
			Logger.Debug("fixed address args len:%v", len(address))
			// 7
			if len(address) == 4 {
				values = append(values, address[0])
				values = append(values, address[1])
				values = append(values, address[2])
				values = append(values, address[3])
				for i := 0; i < 3; i++ {
					values = append(values, nil)
				}
			} else {
				for i := 0; i < 7; i++ {
					values = append(values, nil)
				}
			}
		}
	}

	sql = sql[:len(sql)-1]

	Logger.Debug("sql:%v", sql)
	Logger.Debug("values len:%v", len(values))
	Logger.Debug("values:%v", values)

	if len(values) > 0 {
		stmt, err := db.Engine.DB().Prepare(sql)
		util.PanicError(err)
		defer stmt.Close()
		result, err := stmt.Exec(values...)
		util.PanicError(err)

		count, err := result.RowsAffected()
		util.PanicError(err)
		Logger.Debug("inserted rows count:%v", count)
	}

	c.HTML(http.StatusOK, "order_upload.tmpl", gin.H{"successCount": rowsCount, "isUpload": true, "errMsg": "上传成功"})

}
Пример #9
0
func LogoutHandler(c *gin.Context) {
	auth := userauth.Auth(c)
	auth.Logout()
	c.Redirect(http.StatusMovedPermanently, "/")
}