Exemple #1
0
func (this *PaymentC) Create(ctx *web.Context) {
	r, w := ctx.Request, ctx.Response
	qs := r.URL.Query()
	partnerId := this.GetPartnerId(ctx)
	orderNo := qs.Get("order_no")
	paymentOpt := qs.Get("pay_opt")

	if len(orderNo) != 0 {
		ctx.Session().Set("current_payment", orderNo)
		ctx.Session().Save()

		if paymentOpt == "alipay" {
			aliPayObj := this.getAliPayment(ctx)
			domain := getDomain(ctx.Request)
			returnUrl := fmt.Sprintf("%s/pay/return_alipay", domain)
			notifyUrl := fmt.Sprintf("%s/pay/notify/%d_alipay", domain, partnerId)
			gateway := aliPayObj.CreateGateway(orderNo, 0.01, "在线支付订单", "订单号:"+orderNo, notifyUrl, returnUrl)
			html := "<html><head><meta charset=\"utf-8\"/></head><body>" + gateway + "</body></html>"
			w.Write([]byte(html))

			payment.Debug(" [ Submit] - %s - %s", orderNo, notifyUrl)

			return
		}
	}

	w.Write([]byte("订单不存在"))
}
Exemple #2
0
// 获取商户
func (this *baseC) GetPartner(ctx *web.Context) *partner.ValuePartner {
	val := ctx.Session().Get("member:rel_partner")
	if val != nil {
		return cache.GetValuePartnerCache(val.(int))
	}
	return nil
}
Exemple #3
0
func (this *ShoppingC) releaseOrder(ctx *web.Context) {
	s := ctx.Session()
	s.Remove("shopping_lock")
	s.Save()

	//fmt.Println("REMOVED")
}
Exemple #4
0
// 会员Http请求会话链接
func MemberHttpSessionConnect(ctx *web.Context, call func(memberId int)) (ok bool, memberId int) {
	//return true,30
	// 如果传递会话参数正确,能存储到Session

	form := ctx.Request.URL.Query()
	if memberId, err := strconv.Atoi(form.Get("member_id")); err == nil {
		var token string = form.Get("token")
		if CompareMemberApiToken(ctx.App.Storage(), memberId, token) {
			if call != nil {
				call(memberId)
			}
			ctx.Session().Set("client_member_id", memberId)
			ctx.Session().Save()
			return true, memberId
		}
	} else {
		// 如果没有传递参数从会话中获取
		if v := ctx.Session().Get("client_member_id"); v != nil {
			memberId = v.(int)
			return true, memberId
		}
	}

	//http://zs.ts.com/main/msc?device=1&return_url=/list/all_cate&member_id=30&token=25245e2640232df15db617473f59159c9d3d7c300ce349cb9a953b
	//SetMemberApiToken(ctx.App.Storage(),30,"f22e180335baf50c134ea5c1093de0a6")
	//fmt.Println(GetMemberApiToken(ctx.App.Storage(),30))

	return false, memberId
}
Exemple #5
0
// Member session connect
func (this *mainC) Msc(ctx *web.Context) {
	form := ctx.Request.URL.Query()
	util.SetDeviceByUrlQuery(ctx, &form)

	ok, memberId := util.MemberHttpSessionConnect(ctx, func(memberId int) {
		v := ctx.Session().Get("member")
		var m *member.ValueMember
		if v != nil {
			m = v.(*member.ValueMember)
			if m.Id != memberId { // 如果会话冲突
				m = nil
			}
		}

		if m == nil {
			m = dps.MemberService.GetMember(memberId)
			ctx.Session().Set("member", m)
			ctx.Session().Save()
		}
	})

	if ok {
		ctx.Items["client_member_id"] = memberId
	}

	rtu := form.Get("return_url")
	if len(rtu) == 0 {
		rtu = "/"
	}
	ctx.Response.Header().Add("Location", rtu)
	ctx.Response.WriteHeader(302)
}
Exemple #6
0
// 会员Http请求会话链接
func MemberHttpSessionConnect(ctx *web.Context) (ok bool, memberId int) {
	//return true,30
	// 如果传递会话参数正确,能存储到Session
	if param := ctx.Request.URL.Query().Get("member_id"); len(param) != 0 {
		memberId, _ = strconv.Atoi(param)

		var token string = ctx.Request.URL.Query().Get("token")
		if CompareMemberApiToken(ctx.App.Storage(), memberId, token) {
			ctx.Session().Set("client_member_id", memberId)
			ctx.Session().Save()
			return true, memberId
		}
	} else {
		// 如果没有传递参数从会话中获取
		if v := ctx.Session().Get("client_member_id"); v != nil {
			memberId = v.(int)
			return true, memberId
		}
	}

	// SetMemberApiToken(ctx.App.Storage(),30,"369a661b13134a8c0997ca7f0a5372bf")
	// fmt.Println(GetMemberApiToken(ctx.App.Storage(),30))

	return false, memberId
}
Exemple #7
0
func chkLogin(ctx *web.Context) (b bool, partnerId int) {
	v := ctx.Session().Get("master_id")
	if v == nil {
		return false, -1
	}
	return true, v.(int)
}
Exemple #8
0
// 获取商户编号
func (this *baseC) GetMasterId(ctx *web.Context) int {
	v := ctx.Session().Get("master_id")
	if v == nil {
		this.Requesting(ctx)
		return -1
	}
	return v.(int)
}
Exemple #9
0
// 检查会员是否登陆
func (this *baseC) CheckMemberLogin(ctx *web.Context) bool {
	if ctx.Session().Get("member") == nil {
		ctx.ResponseWriter.Header().Add("Location", "/user/login?return_url="+
			url.QueryEscape(ctx.Request.RequestURI))
		ctx.ResponseWriter.WriteHeader(302)
		return false
	}
	return true
}
Exemple #10
0
// Member session disconnect
func (this *mainC) Msd(ctx *web.Context) {
	if util.MemberHttpSessionDisconnect(ctx) {
		ctx.Session().Set("member", nil)
		ctx.Session().Save()
		ctx.Response.Write([]byte("disconnect success"))
	} else {
		ctx.Response.Write([]byte("disconnect fail"))
	}
}
Exemple #11
0
// 获取会员
func (this *baseC) GetMember(ctx *web.Context) *member.ValueMember {
	memberIdObj := ctx.Session().Get("member")
	if memberIdObj != nil {
		if o, ok := memberIdObj.(*member.ValueMember); ok {
			return o
		}
	}
	return nil
}
Exemple #12
0
// 锁定,防止重复下单,返回false,表示正在处理订单
func (this *orderC) lockOrder(ctx *web.Context) bool {
	s := ctx.Session()
	v := s.Get("pt_order_lock")
	if v != nil {
		return false
	}
	s.Set("pt_order_lock", "1")
	s.Save()
	return true
}
Exemple #13
0
func chkLogin(ctx *web.Context) (b bool, partnerId int) {
	//todo:仅仅做了id的检测,没有判断有效性
	// i, err := session.GetLSession().GetPartnerIdFromCookie(ctx.Request)
	// return err == nil, i
	v := ctx.Session().Get("partner_id")
	if v == nil {
		return false, -1
	}
	return true, v.(int)
}
Exemple #14
0
//从partner登录过来的信息
func (this *loginC) Partner_connect(ctx *web.Context) {
	r, w := ctx.Request, ctx.Response
	sessionId := r.URL.Query().Get("sessionId")
	var m *member.ValueMember
	var err error

	if sessionId == "" {
		// 第三方连接,传入memberId 和 token
		memberId, err := strconv.Atoi(r.URL.Query().Get("mid"))
		token := r.URL.Query().Get("token")
		if err == nil && token != "" {
			m, err = goclient.Member.GetMember(memberId, token)
			ctx.Session().Set("member", m)
		}
	} else {
		// 从统一平台连接过来(标准版商户PC前端)
		ctx.Session().UseInstead(sessionId)
		m = ctx.Session().Get("member").(*member.ValueMember)
	}

	// 设置访问设备
	util.SetBrownerDevice(ctx, ctx.Request.URL.Query().Get("device"))

	if err == nil || m != nil {
		rl := dps.MemberService.GetRelation(m.Id)
		if rl.RegisterPartnerId > 0 {
			ctx.Session().Set("member:rel_partner", rl.RegisterPartnerId)
			ctx.Session().Save()
			w.Write([]byte("<script>location.replace('/')</script>"))
			return
		}
	}
	w.Write([]byte("<script>location.replace('/login')</script>"))
}
Exemple #15
0
// 退出
func (this *UserC) Logout(ctx *web.Context) {
	ctx.Session().Set("member", nil)
	ctx.Session().Save()
	ctx.ResponseWriter.Write([]byte(fmt.Sprintf(`<html><head><title>正在退出...</title></head><body>
			3秒后将自动返回到首页... <br />
			<iframe src="http://%s.%s/login/partner_disconnect" width="0" height="0" frameBorder="0"></iframe>
			<script>window.onload=function(){location.replace('/')}</script></body></html>`,
		variable.DOMAIN_MEMBER_PREFIX,
		ctx.App.Config().GetString(variable.ServerDomain),
	)))
}
Exemple #16
0
// 锁定,防止重复下单,返回false,表示正在处理订单
func (this *ShoppingC) lockOrder(ctx *web.Context) bool {
	s := ctx.Session()
	v := s.Get("shopping_lock")

	//fmt.Println(v)
	if v != nil {
		return false
	}
	s.Set("shopping_lock", "1")
	s.Save()
	return true
}
Exemple #17
0
func (this *baseC) Requesting(ctx *web.Context) bool {
	//验证是否登陆
	s := ctx.Session().Get("member")
	if s != nil {
		if m := s.(*member.ValueMember); m != nil {
			ctx.Items["member"] = m
			return true
		}
	}
	ctx.ResponseWriter.Write([]byte("<script>window.parent.location.href='/login?return_url=" +
		url.QueryEscape(ctx.Request.URL.String()) + "'</script>"))
	return false
}
Exemple #18
0
func (this *userC) Login_post(ctx *web.Context) {
	r, w := ctx.Request, ctx.ResponseWriter
	r.ParseForm()
	usr, pwd := r.Form.Get("usr"), r.Form.Get("pwd")
	b, m, err := dps.MemberService.Login(usr, pwd)

	if b {
		ctx.Session().Set("member", m)
		ctx.Session().Save()
		w.Write([]byte("{result:true}"))
		return
	}
	w.Write([]byte("{result:false,message:'" + err.Error() + "'}"))
}
Exemple #19
0
func (this *userC) Login_post(ctx *web.Context) {
	r, w := ctx.Request, ctx.Response
	r.ParseForm()
	usr, pwd := r.Form.Get("usr"), r.Form.Get("pwd")
	result, _ := goclient.Member.Login(usr, pwd)

	if result.Result {
		ctx.Session().Set("member", result.Member)
		ctx.Session().Save()
		w.Write([]byte("{result:true}"))
		return
	}
	w.Write([]byte("{result:false,message:'" + result.Message + "'}"))
}
Exemple #20
0
func (this *loginC) Login_post(ctx *web.Context) {
	r, w := ctx.Request, ctx.ResponseWriter
	r.ParseForm()
	usr, pwd := r.Form.Get("uid"), r.Form.Get("pwd")
	pt, result, message := this.ValidLogin(usr, pwd)

	if result {
		ctx.Session().Set("partner_id", pt.Id)
		if err := ctx.Session().Save(); err != nil {
			result = false
			message = err.Error()
		}
	}
	web.Seria2json(w, result, message, nil)
}
Exemple #21
0
// 获取商户
func (this *baseC) GetPartner(ctx *web.Context) *partner.ValuePartner {
	val := ctx.Session().Get("member:rel_partner")
	if val != nil {
		return cache.GetValuePartnerCache(val.(int))
	} else {
		m := this.GetMember(ctx)
		if m != nil {
			rel := dps.MemberService.GetRelation(m.Id)
			ctx.Session().Set("member:rel_partner", rel.RegisterPartnerId)
			ctx.Session().Save()
			return cache.GetValuePartnerCache(rel.RegisterPartnerId)
		}
	}
	return nil
}
Exemple #22
0
//跳转到会员中心
// url : /user/jump_m
func (this *userC) member(ctx *web.Context) {
	m := this.GetMember(ctx)
	var location string
	if m == nil {
		location = "/login?return_url=/member"
	} else {
		location = fmt.Sprintf("http://%s.%s/login/partner_connect?sessionId=%s&mid=%d&token=%s",
			variable.DOMAIN_PREFIX_MEMBER,
			ctx.App.Config().GetString(variable.ServerDomain),
			ctx.Session().GetSessionId(),
			m.Id,
			m.DynamicToken,
		)
	}
	ctx.Response.Write([]byte("<script>window.parent.location.replace('" + location + "')</script>"))
}
Exemple #23
0
func (this *mainC) Login_post(ctx *web.Context) {
	r := ctx.Request
	var msg gof.Message
	r.ParseForm()
	usr, pwd := r.Form.Get("uid"), r.Form.Get("pwd")

	if domain.Md5Pwd(pwd, usr) == ctx.App.Config().GetString("webmaster_valid_md5") {
		ctx.Session().Set("master_id", 1)
		if err := ctx.Session().Save(); err != nil {
			msg.Message = err.Error()
		} else {
			msg.Result = true
		}
	} else {
		msg.Message = "用户或密码不正确!"
	}
	ctx.Response.Write(msg.Marshal())
}
Exemple #24
0
func (this *PaymentC) Return_alipay(ctx *web.Context) {
	//this.paymentFail(ctx,nil)
	//return
	aliPayObj := this.getAliPayment(ctx)
	result := aliPayObj.Return(ctx.Request)
	partnerId := this.GetPartnerId(ctx)
	if len(result.OrderNo) == 0 {
		result.OrderNo = ctx.Session().Get("current_payment").(string)
	}
	order := dps.ShoppingService.GetOrderByNo(partnerId, result.OrderNo)
	if result.Status == payment.StatusTradeSuccess {
		this.handleOrder(order, "alipay", &result)
		this.paymentSuccess(ctx, order, &result)
		return
	}

	this.paymentFail(ctx, order, &result)
}
Exemple #25
0
// 跳转到会员中心
// url : /user/jump_m
func (this *UserC) JumpToMCenter(ctx *web.Context) {
	w := ctx.ResponseWriter
	m := this.BaseC.GetMember(ctx)
	var location string
	if m == nil {
		location = "/user/login?return_url=/user/jump_m"
	} else {
		location = fmt.Sprintf("http://%s.%s/login/partner_connect?device=%s&sessionId=%s&mid=%d&token=%s",
			variable.DOMAIN_MEMBER_PREFIX,
			ctx.App.Config().GetString(variable.ServerDomain),
			util.GetBrownerDevice(ctx),
			ctx.Session().GetSessionId(),
			m.Id,
			m.DynamicToken,
		)
	}
	w.Header().Add("Location", location)
	w.WriteHeader(302)
}
Exemple #26
0
func (this *loginC) Login_post(ctx *web.Context) {
	r, w := ctx.Request, ctx.Response
	r.ParseForm()
	usr, pwd := r.Form.Get("uid"), r.Form.Get("pwd")
	pt, result, message := this.ValidLogin(usr, pwd)

	if result {
		ctx.Session().Set("partner_id", pt.Id)
		if err := ctx.Session().Save(); err != nil {
			result = false
			message = err.Error()
		}
	}

	if result {
		w.Write([]byte("{result:true}"))
	} else {
		w.Write([]byte("{result:false,message:'" + message + "'}"))
	}
}
Exemple #27
0
func (this *UserC) Login_post(ctx *web.Context) {
	r := ctx.Request
	r.ParseForm()
	var result gof.Message
	partnerId := this.BaseC.GetPartnerId(ctx)
	usr, pwd := r.Form.Get("usr"), r.Form.Get("pwd")
	b, m, err := dps.MemberService.Login(partnerId, usr, pwd)
	if b {
		ctx.Session().Set("member", m)
		ctx.Session().Save()
	} else {
		result.Result = false
		if err != nil {
			result.Message = err.Error()
		} else {
			result.Message = "登陆失败"
		}
	}
	this.BaseC.ResultOutput(ctx, result)
}
Exemple #28
0
func (this *loginC) Index_post(ctx *web.Context) {
	r := ctx.Request
	r.ParseForm()
	var result gof.Message
	usr, pwd := r.Form.Get("usr"), r.Form.Get("pwd")
	b, m, err := dps.MemberService.Login(-1, usr, pwd)
	if b {
		ctx.Session().Set("member", m)
		ctx.Session().Save()
		result.Result = true
	} else {
		if err != nil {
			result.Message = err.Error()
		} else {
			result.Message = "登陆失败"
		}
	}
	js, _ := json.Marshal(result)
	ctx.Response.Write(js)

}
Exemple #29
0
func (this *basicC) Profile_post(ctx *web.Context) {
	mm := this.GetMember(ctx)
	r := ctx.Request
	var result gof.Message
	r.ParseForm()
	m := new(member.ValueMember)
	web.ParseFormToEntity(r.Form, m)
	m.Id = mm.Id
	_, err := dps.MemberService.SaveMember(m)

	if err != nil {
		result = gof.Message{Result: false, Message: err.Error()}
	} else {
		result = gof.Message{Result: true}
		m = dps.MemberService.GetMember(mm.Id)
		ctx.Session().Set("member", m)
		ctx.Session().Save()

	}
	ctx.Response.JsonOutput(result)
}
Exemple #30
0
// Member session connect
func (this *mainC) Msc(ctx *web.Context) {
	form := ctx.Request.URL.Query()
	util.SetDeviceByUrlQuery(ctx, &form)

	ok, memberId := util.MemberHttpSessionConnect(ctx, func(memberId int) {
		if ctx.Session().Get("member") == nil {
			m := dps.MemberService.GetMember(memberId)
			ctx.Session().Set("member", m)
		}
	})

	if ok {
		ctx.Items["client_member_id"] = memberId
	}

	rtu := form.Get("return_url")
	if len(rtu) == 0 {
		rtu = "/"
	}
	ctx.ResponseWriter.Header().Add("Location", rtu)
	ctx.ResponseWriter.WriteHeader(302)
}