Пример #1
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)
}
Пример #2
0
func (this *ShoppingC) releaseOrder(ctx *web.Context) {
	s := ctx.Session()
	s.Remove("shopping_lock")
	s.Save()

	//fmt.Println("REMOVED")
}
Пример #3
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
}
Пример #4
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("订单不存在"))
}
Пример #5
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"))
	}
}
Пример #6
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
}
Пример #7
0
// 检查会员是否登陆
func (this *BaseC) CheckMemberLogin(ctx *web.Context) bool {
	if ctx.Session().Get("member") == nil {
		ctx.Response.Header().Add("Location", "/user/login?return_url="+
			url.QueryEscape(ctx.Request.RequestURI))
		ctx.Response.WriteHeader(302)
		return false
	}
	return true
}
Пример #8
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
}
Пример #9
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>"))
}
Пример #10
0
// 退出
func (this *UserC) Logout(ctx *web.Context) {
	ctx.Session().Set("member", nil)
	ctx.Session().Save()
	ctx.Response.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_PREFIX_MEMBER,
		ctx.App.Config().GetString(variable.ServerDomain),
	)))
}
Пример #11
0
func getPartner(ctx *web.Context) (*partner.ValuePartner, error) {
	//todo: 缓存,用Member对应的Partner编号来查询缓存
	var partnerId int = ctx.GetItem("partner_id").(int)
	var err error
	var pt *partner.ValuePartner = cache.GetValuePartnerCache(partnerId)
	if pt == nil {
		if pt, err = dps.PartnerService.GetPartner(getPartnerId(ctx)); err == nil {
			cache.SetValuePartnerCache(partnerId, pt)
		}
	}
	return pt, err
}
Пример #12
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
}
Пример #13
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.Response.Write([]byte("<script>window.parent.location.href='/login?return_url=" +
		url.QueryEscape(ctx.Request.URL.String()) + "'</script>"))
	return false
}
Пример #14
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
}
Пример #15
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)
}
Пример #16
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())
}
Пример #17
0
// 跳转到会员中心
// url : /user/jump_m
func (this *UserC) JumpToMCenter(ctx *web.Context) {
	w := ctx.Response
	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_PREFIX_MEMBER,
			ctx.App.Config().GetString(variable.ServerDomain),
			util.GetBrownerDevice(ctx),
			ctx.Session().GetSessionId(),
			m.Id,
			m.DynamicToken,
		)
	}
	w.Header().Add("Location", location)
	w.WriteHeader(302)
}
Пример #18
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 + "'}"))
	}
}
Пример #19
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()
		result.Result = true
	} else {
		if err != nil {
			result.Message = err.Error()
		} else {
			result.Message = "登陆失败"
		}
	}
	ctx.Response.JsonOutput(result)
}
Пример #20
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)

}
Пример #21
0
func getPartnerId(ctx *web.Context) int {
	currHost := ctx.Request.Host
	host := ctx.Session().Get("webui_host")
	pid := ctx.Session().Get("webui_pid")
	if host == nil || pid == nil || host != currHost {
		partnerId := dps.PartnerService.GetPartnerIdByHost(currHost)
		if partnerId != -1 {
			ctx.Session().Set("webui_host", currHost)
			ctx.Session().Set("webui_pid", partnerId)
			ctx.Session().Save()
		}
		return partnerId
	}
	return pid.(int)
}
Пример #22
0
func (this *orderC) releaseOrder(ctx *web.Context) {
	ctx.Session().Remove("pt_order_lock")
	ctx.Session().Save()
}
Пример #23
0
// 重新缓存会员
func (this *baseC) ReCacheMember(ctx *web.Context, memberId int) {
	v := dps.MemberService.GetMember(memberId)
	ctx.Session().Set("member", v)
	ctx.Session().Save()
}
Пример #24
0
func (this *mainC) Logout(ctx *web.Context) {
	ctx.Session().Destroy()
	ctx.Response.Write([]byte("<script>location.replace('/login')</script>"))
}
Пример #25
0
func (this *BaseC) GetPartner(ctx *web.Context) *partner.ValuePartner {
	return ctx.GetItem("partner_ins").(*partner.ValuePartner)
}
Пример #26
0
func (this *BaseC) GetSiteConf(ctx *web.Context) *partner.SiteConf {
	return ctx.GetItem("partner_siteconf").(*partner.SiteConf)
}
Пример #27
0
// 获取商户编号
func (this *BaseC) GetPartnerId(ctx *web.Context) int {
	return ctx.GetItem("partner_id").(int)
}
Пример #28
0
//从partner端退出
func (this *loginC) Partner_disconnect(ctx *web.Context) {
	ctx.Session().Destroy()
	ctx.Response.Write([]byte("{state:1}"))
}