Esempio n. 1
0
File: order.go Progetto: 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: "添加成功"})
}
Esempio n. 2
0
//普通用户(游客)注册
func RegistHandler(c *gin.Context) {
	session := sessions.Default(c)
	phone := c.PostForm("phone")
	Logger.Info("register phone :%v", phone)
	phone = strings.TrimSpace(phone)
	if !userinfo.IsLegalPhoneNumber(phone) {
		render.WriteJSON(c.Writer, "请填写正确的手机号(11位)")
		return
	}

	if !strings.EqualFold(phone, stringutils.ToString(session.Get(constant.PHONE_NUMBER))) {
		c.JSON(http.StatusOK, util.JsonResult{Success: false, Msg: "下发验证码的手机号不是当前手机号"})
		return
	}

	if !strings.EqualFold(strings.ToLower(stringutils.ToString(session.Get(constant.PHONE_CAPTCHA))), strings.ToLower(c.PostForm("captcha"))) {
		c.JSON(http.StatusOK, util.JsonResult{Success: false, Msg: "验证码不正确"})
		return

		lastPhoneCaptcha := session.Get(constant.PHONE_CAPTCHA_LAST)
		lastPhoneCaptchaTimestamp, _ := lastPhoneCaptcha.(int64)
		timeDifference := (time.Now().UnixNano() - lastPhoneCaptchaTimestamp) / (1000 * 1000 * 1000 * 60)
		if timeDifference > constant.PHONE_CAPTCHA_EXPIRED_MINUTES {
			c.JSON(http.StatusOK, util.JsonResult{Success: false, Msg: fmt.Sprintf("验证码已失效,请在验证码下发后%v分钟内提交", constant.PHONE_CAPTCHA_EXPIRED_MINUTES)})
			return
		}
	}

	user := &mdl.User{Phone: phone}
	userCount, err := db.Engine.Count(user)
	util.LogError(err)

	if userCount != 0 {
		render.WriteJSON(c.Writer, util.JsonResult{Success: true, Msg: "该手机号已经被注册"})
		return
	}

	user.Salt = fmt.Sprintf("%v", rand.New(rand.NewSource(time.Now().UnixNano())).Float64())
	user.Password = c.PostForm("password")
	if len(user.Password) < 6 {
		c.JSON(http.StatusOK, util.JsonResult{Msg: "密码长度大于6"})
		return
	}
	user.Password = util.HashAndSalt(user.Password, user.Salt)
	user.Uuid = uuid.New()
	Logger.Info(user.Uuid)
	nickname := strings.TrimSpace(c.PostForm("nickname"))
	Logger.Debug("nickname: %v, size: %v", nickname, len(nickname))
	if len(nickname) == 0 {
		user.Nickname = user.Phone
	} else {
		user.Nickname = nickname
	}
	count, err := db.Engine.Insert(user)
	if err != nil || count == 0 {
		Logger.Error(err)
		c.JSON(http.StatusOK, util.JsonResult{Msg: "系统错误"})
		return
	}

	//注册成功,设置为登录
	login.SetLoginState(*user, c)

	c.JSON(http.StatusOK, util.JsonResult{Msg: "注册成功", Success: true})

}
Esempio n. 3
0
File: order.go Progetto: sdvdxl/wine
// 上传订单
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": "上传成功"})

}