Example #1
0
File: order.go Project: sdvdxl/wine
// 删除订单
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: "删除成功"})
}
Example #2
0
File: order.go Project: sdvdxl/wine
// 更新订单
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})
}
Example #3
0
func HandlerError() gin.HandlerFunc {
	return func(c *gin.Context) {
		defer func() {
			if err := recover(); err != nil {
				trace := make([]byte, 10240)
				runtime.Stack(trace, true)
				log.Logger.Error("%s, \n%s", err, trace)

				if strings.HasSuffix(c.Request.URL.Path, ".html") {
					c.HTML(http.StatusInternalServerError, "500.tmpl", nil)
				} else {
					r := render.New(c)
					r.JSON(util.JsonResult{Msg: "系统错误"})
				}
			}
		}()
		c.Next()
	}
}
Example #4
0
File: order.go Project: sdvdxl/wine
// 追加备注
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: "添加成功"})
}
Example #5
0
File: order.go Project: sdvdxl/wine
// 根据订单uuid查看注释
func OrderCommentsHandler(c *gin.Context) {
	r := render.New(c)
	oid := strings.TrimSpace(c.Query("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("没有此订单")
		return
	}

	comments := make([]bean.UserSalesComments, 0, 30)
	err = db.Engine.Cols("u.uuid", "u.nickname", "u.phone", "comments").Table("user").Alias("u").Join("inner", "sales_comments", "u.uuid=user_uuid").Where("order_uuid=?", oid).Find(&comments)
	util.PanicError(err)

	r.JSON(util.JsonResult{Success: true, Msg: "获取成功", Data: comments})
}
Example #6
0
func main() {
	defer log.Logger.Close()
	defer db.Close()

	log.Logger.Info("starting server...")

	//==================================   nav top sidebar  ======================================
	{
		g.Any("/sidebar.html", nav.SidebarTemplateHandler)
		g.Any("/header.html", nav.HeaderTemplateHandler)
		g.Any("/footer.html", nav.FooterTemplateHandler)
	}

	//==================================   404, index  ======================================
	{
		//404
		g.NoRoute(func(c *gin.Context) {
			log.Logger.Debug("page [%v] not found, redirect to 404.html", c.Request.URL.Path)
			if strings.HasSuffix(c.Request.URL.Path, ".html") {
				c.HTML(http.StatusNotFound, "404.tmpl", nil)
			} else {
				r := render.New(c)
				r.JSON(util.JsonResult{Msg: "请求资源不存在"})
			}
		})

		//首页
		g.Any("/", index.IndexHandler)
	}

	//==================================  用户相关  ======================================
	{
		userGroup := g.Group("/user")
		{
			{ //处理登陆
				userGroup.Any("/logout", login.LogoutHandler)
				userGroup.GET("/getUserInfo", userinfo.GetUserInfoHandler)
				userGroup.POST("/login", login.LoginHandler)
				userGroup.GET("/login.html", login.TemplateHandler)
				userGroup.GET("/getImageCaptcha", captcha.GetImageCaptcha)

				userGroup.GET("/user_list", user.UserListHandler)
				userGroup.POST("/user_add", user.UserAddHandler)
				userGroup.POST("/user_delete", user.UserDeleteHandler)
				userGroup.POST("/user_update", user.UserUpdateHandler)
				userGroup.POST("/change_password", user.ChangePasswordHandler)
			}

			{
				userGroup.GET("/me", user.MyProfileHandler)
			}

			{ //注册
				userGroup.POST("/regist", regist.RegistHandler)
				userGroup.POST("/registGuid", regist.RegistHandler)
				userGroup.GET("/isPhoneValid", userinfo.IsPhoneValid)
				userGroup.GET("/getPhoneCaptcha", captcha.GetPhoneCaptcha)
			}
		}
	}

	//==================================  订单  ======================================
	{
		orderGroup := g.Group("/order")
		orderGroup.GET("/order_list", order.OrderListHandler)
		orderGroup.POST("/order_update", order.OrderUpdateHandler)
		orderGroup.POST("/order_delete", order.OrderDeleteHandler)
		orderGroup.POST("/order_add_comments", order.OrderAddCommentsHandler)
		orderGroup.POST("/order_upload", order.OrderUploadHandler)
		orderGroup.GET("/order_upload.html", order.OrderUploadTemplateHandler)
		orderGroup.GET("/order_comments", order.OrderCommentsHandler) //添加订单注释
	}

	//==================================  mail  ======================================
	{
		g.GET("/mail", func(c *gin.Context) {

			mail.SendEmail([]string{c.Query("to")}, "test", "mail.tmpl", c.Query("content"))

			c.JSON(http.StatusOK, util.JsonResult{Msg: "发送邮件成功"})

		})
	}

	log.Logger.Info("server started ")
	g.Run(":8085")
}
Example #7
0
File: order.go Project: sdvdxl/wine
func OrderListHandler(c *gin.Context) {
	r := render.New(c)
	orderInfo := new(bean.OrderInfo)

	curPage := number.DefaultInt(c.Query("curPage"), 1)
	seaType := strings.TrimSpace(c.Query("seaType"))
	seaContent := strings.TrimSpace(c.Query("seaContent"))

	query := db.Engine.Where("1=1")
	queryCount := db.Engine.Where("1=1")
	defer query.Close()
	defer queryCount.Close()

	//订单时间
	orderStart := timeutils.ParseDate(c.Query("orderStart"))
	Logger.Debug("order start time: %v", orderStart)
	if orderStart != nil {
		queryCount.And("order_create_time>=?", orderStart)
		query.And("order_create_time>=?", orderStart)
	}

	orderEnd := timeutils.ParseDate(c.Query("orderEnd"))
	Logger.Debug("order end time: %v", orderEnd)
	if orderEnd != nil {
		t := orderEnd.Add(time.Hour * 24)
		orderEnd = &t
		queryCount.And("order_create_time<?", orderEnd)
		query.And("order_create_time<?", orderEnd)
	}

	//搜索类型和内容
	if seaType == "date-baught-lt" || seaType == "date-baught-gt" || seaType == "date-baught-eq" {
		orderCount := number.DefaultInt(seaContent, -1)
		if -1 == orderCount {
			r.JSON(util.JsonResult{Msg: "请输入次数(整数)"})
			return
		}

		//购买次数少于
		operator := ">"
		if seaType == "date-baught-lt" {
			operator = "<"
		} else if seaType == "date-baught-eq" {
			operator = "="
		}

		query.Sql(`select * from (select * from order_info where buyer_name in  (select buyer_name from
(select *, count(buyer_name) c from order_info group by buyer_name having c `+operator+`?) tmp_table) ) tmp_count_table order by order_create_time desc limit ?, ?`, orderCount, pageSize*(curPage-1), pageSize)
		queryCount.Sql(`select count(*) from (select * from order_info where buyer_name in  (select buyer_name from
(select *, count(buyer_name) c from order_info group by buyer_name having c `+operator+`?) tmp_table) ) tmp_count_table `, orderCount)
	} else if seaType != "" && seaContent != "" {
		seaContent = "%" + seaContent + "%"
		if "deliveryAddress" == seaType {
			query.And(`delivery_address_province like ? or delivery_address_city like ?  or delivery_address_area like ?
		 	 or delivery_address_town like ?  or delivery_address_street like ? or delivery_address_detail like ? or delivery_address_post like ? `,
				seaContent, seaContent, seaContent, seaContent, seaContent, seaContent, seaContent).OrderBy("order_create_time desc")
		} else {
			switch seaType {
			case "buyerName":
				seaType = "buyer_name"
			case "deliveryName":
				seaType = "delivery_name"
			case "buyerPayAccount":
				seaType = "buyer_pay_account"
			case "contactTel":
				seaType = "contact_tel"
			case "contactPhone":
				seaType = "contact_phone"
			}
			query.And(seaType+" like ? ", seaContent)
			queryCount.And(seaType+" like ? ", seaContent)
		}
	} else if seaContent != "" {
		whereCond := make([]interface{}, 22, 22)
		for i, _ := range whereCond {
			whereCond[i] = "%" + seaContent + "%"
		}

		queryCondSQL := `buyer_name like ? or buyer_pay_account like ? or  buyer_need_pay like ? or
		buyer_postage like ? or  buyer_pay_integral like ? or  total_price like ? or 	return_integral like ? or
		real_pay_amount like ? or  real_pay_integral like ? or  order_status like ? or
		buyer_message like ? or  delivery_name like ? or  delivery_address_province like ? or
		delivery_address_city like ? or  delivery_address_area like ? or  delivery_address_town like ? or
		delivery_address_street like ? or  delivery_address_detail like ? or
		delivery_address_post like ? or  transfer_type like ? or  contact_tel like ? or  contact_phone like ?`

		queryCount.Where(queryCondSQL, whereCond...)
		query.Where(queryCondSQL, whereCond...)
	}

	count, err := queryCount.Count(orderInfo)
	util.PanicError(err)

	query.Limit(pageSize, pageSize*(curPage-1))
	rows, err := query.Desc("order_create_time").Rows(orderInfo)
	util.PanicError(err)

	defer rows.Close()
	orderList := make([]bean.OrderInfo, 0, 100)

	for rows.Next() {
		orderInfo = new(bean.OrderInfo)
		err = rows.Scan(orderInfo)
		orderList = append(orderList, *orderInfo)
	}

	data := make(map[string]interface{})
	data["page"] = pagehelper.Paging(curPage, pageSize, int(count))
	data["orderList"] = orderList
	r.JSON(util.JsonResult{Success: true, Msg: "success", Data: data})
}