Beispiel #1
0
/* 账户充值-post 对已有的未完成账单进行充值 */
func (this *UserController) RechargeOrder() {
	ok, data := func() (bool, interface{}) {
		//根据id查询账单
		order := &models.Order{}
		if !bson.IsObjectIdHex(this.GetString("orderid")) {
			return false, "账单不存在"
		}

		order.Id = bson.ObjectIdHex(this.GetString("orderid"))
		if ok := order.FindOne(); ok != true {
			return false, "账单不存在"
		}

		if order.FromId != this.member.Id {
			return false, "不是您的账单"
		}

		if order.Success == true {
			return false, "该账单已支付完成"
		}

		if time.Now().Sub(order.Time).Hours() > 2 {
			return false, "该账单已失效"
		}

		//获取支付宝即时到帐的自动提交表单
		form := alipay.CreateAlipaySign(order.Id.Hex(), order.Pay, order.ToName, "我酷游戏-充值 "+strconv.FormatFloat(float64(order.Pay), 'f', 2, 32)+" 元")

		return true, form
	}()

	this.Data["json"] = map[string]interface{}{
		"ok":   ok,
		"data": data,
	}
	this.ServeJson()
}
Beispiel #2
0
/* 账户充值-post 处理充值请求 */
func (this *UserController) Recharge() {
	ok, data := func() (bool, interface{}) {
		if _, err := models.Redis.Get(this.member.Id.Hex() + "recharge"); err == nil {
			return false, "您操作过于频繁,10秒后再试"
		}

		//验证数据完整性
		if this.GetString("account") == "" {
			return false, "充值账户必须填写"
		}
		number, _ := this.GetFloat("number")
		if number < 0.01 {
			return false, "充值金额最低为0.01元"
		}

		//检查付款的账号是否存在
		if _ok := this.member.FindByNickname(this.GetString("account")); !_ok { //如果存在则继续
			return false, "充值帐号不存在"
		}

		//付款平台
		if this.GetString("plantform") != "alipay" {
			return false, "付款平台错误"
		}

		//付款类型
		if this.GetString("type") != "web" {
			return false, "付款类型错误"
		}

		//实例化账单
		order := &models.Order{}
		order.ToName = this.GetString("account")
		order.ToId = this.member.Id
		order.FromName = this.member.Nickname
		order.FromId = this.member.Id
		order.Pay = float32(number)
		order.Type = this.GetString("type")
		order.PayPlantform = this.GetString("plantform")
		order.Description = "网站充值"

		//插入新账单
		order.InsertOrder()

		//获取提交表单
		var form string
		switch order.PayPlantform {
		case "alipay": //支付宝
			form = alipay.CreateAlipaySign(order.Id.Hex(), float32(number), order.ToName, "我酷游戏-充值 "+strconv.FormatFloat(float64(order.Pay), 'f', 2, 32)+" 元")
		}

		//设置操作9秒内不能再次操作的缓存
		models.Redis.Setex(this.member.Id.Hex()+"recharge", 9, []byte("1"))

		return true, form
	}()

	this.Data["json"] = map[string]interface{}{
		"ok":   ok,
		"data": data,
	}
	this.ServeJson()
}