Пример #1
0
func (this *AvatarController) Post() {
	w := this.ResponseWriter
	r := this.Request
	data := e.Data{Status: 1, Msg: "上传成功"}
	log.Println("头像上传post")
	r.ParseMultipartForm(32 << 20)
	log.Println("表单解析")
	file, handler, err := r.FormFile("realPicFile")

	if err != nil {
		log.Println("上传错误")
		return
	}

	fileext := filepath.Ext(handler.Filename)
	log.Println("文件后缀名字" + fileext)
	if u.Check(fileext) == false {
		data.Status = 0
		data.Msg = "不允许的上传类型"
		u.OutputJson(w, &data)
		return
	}
	cookie := u.Cookie{HTTP: this.HTTP}

	filename := cookie.GetCookie().UserId.Value + ".png"
	log.Println("文件名称" + filename)

	imgfile, _ := os.OpenFile(Upload_Dir+filename, os.O_CREATE|os.O_WRONLY, 0660)
	defer imgfile.Close()
	//把图片变成400X400尺寸的
	m1, err := jpeg.Decode(file)
	if err != nil {
		panic(err)
	}
	bounds := m1.Bounds()
	//如果第二参数为0则保持横纵比
	g := gift.New(
		gift.Resize(400, 400, gift.LanczosResampling),
	)
	dst := image.NewRGBA(g.Bounds(bounds))
	g.Draw(dst, m1)
	err = png.Encode(imgfile, dst)

	if err != nil {
		log.Println("上传失败")
		return
	}
	filedir := Show_Dir + filename
	data.Data = filedir
	log.Println(data)
	u.OutputJson(w, &data)
}
Пример #2
0
func (this *AccountController) Cash() {
	data := e.Data{Msg: "申请成功", Status: 1}
	w := this.ResponseWriter
	r := this.Request
	r.ParseForm()
	userId := r.FormValue("user")
	money, _ := strconv.ParseFloat(r.FormValue("cash"), 32)
	user := m.User{Id: userId}
	user = user.GetOneUserById()
	if user.RealName == "" { //无开户人姓名
		data.Status = 0
		data.Msg = "真实姓名为空,请先设置真实姓名"
	}
	if data.Status == 1 && user.ABalance < money {
		data.Status = 0
		data.Msg = "提取金额有误"
	}
	if data.Status == 1 {
		username := user.RealName
		bank := r.FormValue("bank")

		card := r.FormValue("card")
		address := r.FormValue("address")
		cash := m.Cash{Id: this.getCashId(userId), UserId: userId, UserName: username, Bank: bank, Card: card, Address: address, Money: money, BeginTime: time.Now(), Status: "申请"}
		cash.InsertCash()
		user.ABalance = user.ABalance - money
		user.UpdateABalance()
	}
	u.OutputJson(w, &data)
}
Пример #3
0
/**
 * 特长项新增修改
 */
func (this *UserController) Skills() {
	w := this.ResponseWriter
	r := this.Request
	r.ParseForm()
	userId := r.FormValue("user")
	category := r.FormValue("category")
	subCategory := r.FormValue("subCategory")
	experience := r.FormValue("experience")
	price := r.FormValue("price")
	item := r.FormValue("item")
	title := r.FormValue("title")

	user := m.User{Id: userId}
	skill := make([]m.Skill, 1) //普通用户默认只有一个技能项
	data := e.Data{Msg: "保存成功", Status: 1}
	skill[0].Id = userId + "1"
	skill[0].Category = m.Category{category, subCategory, item}
	skill[0].Title = title

	skill[0].Experience, _ = strconv.Atoi(experience)
	skill[0].Price, _ = strconv.ParseFloat(price, 1000)
	skill[0].UserId = userId
	skill[0].InsertOrUpdateSkillsById()
	user.Skill = skill
	user.UpdateSkillById()
	u.OutputJson(w, &data)
}
Пример #4
0
func (this *SelectController) Category() {
	w := this.ResponseWriter
	r := this.Request
	categoryArry := []m.Select{}
	data := e.Data{Status: 1, Msg: "操作成功"}
	r.ParseForm()

	// t, err := t.ParseFiles("views/User.edit.area.tpl")
	// if err != nil {
	// 	log.Println(err)
	// }

	flag := r.FormValue("type")
	log.Println("技能项", flag)
	value := r.FormValue("value") //
	categoryArry = m.CategoryCache
	if "subCategory" == flag {
		categoryArry = m.SubCategoryCache[value]
	}
	if "item" == flag {
		categoryArry = m.ItermCache[value]
	}
	data.Data = categoryArry
	log.Println("category", data)
	u.OutputJson(w, &data)

}
Пример #5
0
func (this *SelectController) Area() {
	w := this.ResponseWriter
	r := this.Request
	areaArry := []m.Select{}
	data := e.Data{Status: 1, Msg: "操作成功"}
	r.ParseForm()

	// t, err := t.ParseFiles("views/User.edit.area.tpl")
	// if err != nil {
	// 	log.Println(err)
	// }

	flag := r.FormValue("type")   //区别省市区
	value := r.FormValue("value") //
	areaArry = m.ProvinceCache
	city := m.CityCache
	country := m.CountyCache
	if "city" == flag {
		areaArry = city[value]
	} else if "country" == flag {

		areaArry = country[value]
	}
	data.Data = areaArry

	u.OutputJson(w, &data)

}
Пример #6
0
/**
 * 接受预约
 */
func (this *ScheduleController) Accept() {
	data := e.Data{Msg: "操作成功", Status: 1}
	w := this.ResponseWriter
	r := this.Request
	r.ParseForm()
	orderId := r.FormValue("order")
	order := m.Order{Id: orderId, Status: "已接受"}
	order.UpdateOrderStatusById()
	u.OutputJson(w, &data)
}
Пример #7
0
func (this *LoginController) Check() {
	data := e.Data{Status: 1, Msg: "已登录"}
	cookie := u.Cookie{HTTP: this.HTTP}
	cookie = cookie.GetCookie()
	if cookie.UserId == nil { //没有登录
		data.Status = 0
		data.Msg = "没有登录"
		data.Data = "/login"
	}
	u.OutputJson(this.ResponseWriter, &data)
}
Пример #8
0
func (this *LoginController) Post() {
	r := this.Request
	w := this.ResponseWriter
	data := e.Data{}
	r.ParseForm()
	username := r.FormValue("username")
	password := r.FormValue("password")
	//remomberme := r.FormValue("remember")
	vercode := r.FormValue("vercode")

	cookie, _ := r.Cookie("gsid")
	if cookie != nil { //如果cookie为空

		key := cookie.Value + "Img"
		captchaS := u.Session[key]
		log.Println("获得session中得验证码", captchaS)
		if captchaS == vercode {
			delete(u.Session, key)
			data.Status = 1
			data.Msg = ""
			//http.Redirect(w, r, "/", http.StatusSeeOther)
		} else {
			data.Status = 0
			data.Msg = "验证码错误"
		}
		user := m.User{UserName: username, PassWord: password}
		log.Println("用户表单数据:", user.UserName, user.PassWord)

		//user.InsertOneUserById(user)
		userDetail := user.GetUserDetil(user)
		log.Println(userDetail)
		if userDetail.UserName == "" {
			data.Status = 0
			data.Msg = "用户名或密码错误"
		}
		//登录成功设置成功标志位
		if data.Msg == "" {
			// usernameCookie := http.Cookie{Name: "username", Value: userDetail.UserName}
			// usernameCookie.Expires = time.Now().AddDate(0, 3, 0)
			// http.SetCookie(w, &usernameCookie)
			idCookie := http.Cookie{Name: "userid", Value: userDetail.Id, Path: "/"}
			idCookie.Expires = time.Now().AddDate(0, 3, 0)
			log.Println("设置登录cookie", idCookie)
			http.SetCookie(w, &idCookie)

		}
	} else {
		data.Status = 0
		data.Msg = "非法访问!"
	}
	u.OutputJson(w, &data)
}
Пример #9
0
func (this *UserController) Introduction() {
	data := e.Data{Msg: "保存成功", Status: 1}
	w := this.ResponseWriter
	r := this.Request
	r.ParseForm()
	id := r.FormValue("id")
	introduction := r.FormValue("data")
	introduction = strings.Replace(introduction, "##", ";", -1)
	user := m.User{Id: id, Introduction: introduction}
	log.Println("user", user)
	user.UpdateIntroductionById()
	u.OutputJson(w, &data)
}
Пример #10
0
func (this *OrderController) Add() {
	w := this.ResponseWriter
	r := this.Request
	data := e.Data{Msg: "生成订单成功", Status: 1}
	r.ParseForm()

	money := r.FormValue("money")
	startTime := r.FormValue("startTime")
	endTime := r.FormValue("endTime")
	address := r.FormValue("address")
	ruserId := r.FormValue("ruser")
	remark := r.FormValue("remark")
	skillId := r.FormValue("skill")

	order := m.Order{}
	order.Skill.Id = skillId
	order.Skill = order.Skill.GetSkillById()

	order.RUser = ruserId
	cookie := u.Cookie{HTTP: this.HTTP}
	cookie = cookie.GetCookie()

	if cookie.UserId != nil {
		order.OUser = cookie.UserId.Value
	}

	log.Println(startTime)
	log.Println(endTime)
	order.BeginTime, _ = time.Parse("2006-01-02 15:04", startTime)
	order.EndTime, _ = time.Parse("2006-01-02 15:04", endTime)
	order.OrderTime = time.Now()
	order.Status = "预约"
	order.Remark = remark
	order.Address = address
	order.TotalPrice, _ = strconv.ParseFloat(money, 32)
	ordered, err := order.InsertOrder()
	data.Data = ordered
	if err != nil {
		data.Msg = "订单生成失败"
		data.Status = 0
	}
	u.OutputJson(w, &data)
}
Пример #11
0
func (this *AvatarController) Cut() {
	r := this.Request
	data := e.Data{Status: 1, Msg: "上传成功"}
	r.ParseForm()
	x, err := strconv.Atoi(r.FormValue("x"))
	y, err := strconv.Atoi(r.FormValue("y"))
	x2, err := strconv.Atoi(r.FormValue("x2"))
	y2, err := strconv.Atoi(r.FormValue("y2"))

	fileName := r.FormValue("fileName")
	log.Println(x, y, x2, y2, fileName)
	g := gift.New(
		gift.Crop(image.Rect(x, y, x2, y2)),
		gift.Resize(220, 220, gift.LanczosResampling),
	)
	log.Println("图片名称" + fileName)
	//打开待处理的图片
	file, err := os.Open(fileName)
	if err != nil {
		panic(err)
	}
	defer file.Close()

	m1, err := png.Decode(file)
	if err != nil {
		panic(err)
	}
	bounds := m1.Bounds()

	dst := image.NewRGBA(g.Bounds(bounds))
	g.Draw(dst, m1)
	cookie := u.Cookie{HTTP: this.HTTP}

	filename := cookie.GetCookie().UserId.Value + ".png"

	imgfile, err := os.Create(Avatar_ReDir + filename)
	os.Remove(Upload_Dir + filename)
	defer imgfile.Close()
	err = png.Encode(imgfile, dst)
	u.OutputJson(this.ResponseWriter, &data)
}
Пример #12
0
func (this *SignupController) Post() {
	w := this.ResponseWriter
	r := this.Request
	user := m.User{}
	data := e.Data{Msg: "注册成功", Status: 1}
	r.ParseForm()
	userName := r.FormValue("username")
	passWord1 := r.FormValue("password1")
	passWord2 := r.FormValue("password2")
	reg := regexp.MustCompile(mobile)
	pleng := len(passWord1)
	if userName == "" {
		data.Status = 0
		data.Msg = "用户名不能为空"
	}

	if data.Status != 0 && !reg.MatchString(userName) {
		data.Status = 0
		data.Msg = "手机号码格式错误"
	}
	if data.Status != 0 && passWord1 == "" {
		data.Status = 0
		data.Msg = "密码不能为空"
	}

	if data.Status != 0 && (pleng < 6 || pleng > 12) {
		data.Status = 0
		data.Msg = "密码为6-12位字母或者数字组合"
	}

	if data.Status != 0 && passWord2 == "" {
		data.Status = 0
		data.Msg = "确认密码不能为空"
	}
	if data.Status != 0 && passWord1 != passWord2 { //后端验证两次密码不一致
		data.Status = 0
		data.Msg = "两次密码不一致!"
	}

	log.Println(template.HTMLEscapeString(passWord1))
	if data.Status != 0 {
		user.UserName = userName
		user.TelPhone = userName
		user.PassWord = passWord2
		/*新增用户*/
		user, err := user.InsertUser()
		if err != nil {
			data.Status = 0
			data.Msg = "用户注册出错"
			data.Data = err.Error()
		} else {
			data.Data = user
		}
	}
	u.OutputJson(w, &data)
	// user.Id = "9527"
	// user.RealName = "张力"
	// user.IDCard = "5002351991000000"
	// user.UserName = "******"
	// user.Area = "重庆"

	// honours := make([]m.Honours, 1, 5)
	// h1 := m.Honours{"实名认证用户", "card"}

	// h2 := m.Honours{"会员", "vip"}
	// honours[0] = h1
	// honours = append(honours, h2)
	// user.Honours = honours
	// log.Println(cap(honours))

	// skills := make([]m.Skill, 2, 10)
	// skills[0].Category = "运动"
	// skills[0].Item = "游泳"
	// skills[0].Price = 50.00
	// skills[0].Bid = 0.00
	// skills[0].Experience = 2
	// skills[0].Sales = 90
	// skills[0].Title = "重庆市渝北区游泳馆高级游泳教练"
	// skills[0].Area = "重庆 云阳"
	// skills[0].UserId = "9530"

	// skills[1].Category = "电竟"
	// skills[1].Item = "LOL"
	// skills[1].Price = 10.00
	// skills[1].Bid = 0.00
	// skills[1].Experience = 3
	// skills[1].Sales = 1000
	// skills[1].Title = "英雄联盟LOL巨神峰白银高级带练"
	// skills[0].Area = "重庆 渝北"
	// skills[0].UserId = "9530"

	// skills[0].InsertSkills(skills)

	// user.Skill = skills
	// user.Introduction = "我就是爱音乐别让我停下来"
	// user.InsertUser(user)

	//log.Println(user)
}
Пример #13
0
func (this *UserController) Info() {
	w := this.ResponseWriter
	r := this.Request
	r.ParseForm()
	user := m.User{}
	data := e.Data{Msg: "保存成功", Status: 1}

	id := r.FormValue("id")
	realName := r.FormValue("realName")
	idCard := r.FormValue("idCard")
	age := r.FormValue("age")
	sex := r.FormValue("sex")
	province := r.FormValue("province")
	city := r.FormValue("city")
	country := r.FormValue("country")

	if realName == "" {
		data.Msg = "真实姓名不能为空"
		data.Status = 0
	}
	if data.Status == 1 {
		if idCard == "" {
			data.Msg = "身份证号不能为空"
			data.Status = 0
		} else {
			reg := regexp.MustCompile(idCardReg)
			if !reg.MatchString(idCard) {
				data.Msg = "身份证号格式错误"
				data.Status = 0
			}
		}
	}
	if data.Status == 1 {
		if province == "请选择" {
			data.Msg = "请选择完整的地区信息"
			data.Status = 0
		}
		if city == "请选择" {
			data.Msg = "请选择完整的地区信息"
			data.Status = 0
		}
		if country == "请选择" {
			data.Msg = "请选择完整的地区信息"
			data.Status = 0
		}
	}
	if data.Status == 1 {
		user.Id = id
		user.RealName = realName
		user.IDCard = idCard
		user.Age, _ = strconv.Atoi(age)
		if sex == "on" {
			user.Sex = "男"
		} else {
			user.Sex = "女"
		}
		user.Area = m.Area{province, city, country}
		honours := make([]m.Honours, 3)
		honours[0].Name = "sm"
		honours[0].Title = "未实名认证"
		honours[1].Name = "vip"
		honours[1].Title = "普通用户"
		honours[2].Name = "db"
		honours[2].Title = "未交担保金"
		user.Honours = honours

		err := user.UpdateBaseInfoById()
		if err != nil {
			panic(err)
		}
	}

	u.OutputJson(w, &data)
}