示例#1
0
文件: pay.go 项目: zhjh1209/a_game
func (this *Connect) BuyDiamondRequest() error {

	request := &protodata.BuyDiamondRequest{}
	if err := Unmarshal(this.Request.GetSerializedString(), request); err != nil {
		return this.Send(lineNum(), err)
	}

	index := int(request.GetProductIndex())

	payCenter := models.ConfigPayCenterList()
	product := payCenter[index-1]

	now := time.Now()
	orderId := fmt.Sprintf("101%s%05d", now.Format("200601021504"), rand.Intn(100000))

	user, err := models.User.User(this.Uid)
	if err != nil {
		return this.Send(lineNum(), err)
	}

	order := &models.OrderData{
		OrderId:    orderId,
		PlatId:     user.PlatId,
		Uid:        this.Uid,
		Money:      product.Money,
		Diamond:    product.Diamond,
		CreateTime: now.Unix()}

	if err := models.DB().Insert(order); err != nil {
		return this.Send(lineNum(), err)
	}

	return this.Send(StatusOK, &protodata.BuyDiamondResponse{OrderId: proto.String(orderId)})
}
示例#2
0
文件: role.go 项目: zhjh1209/a_game
func (this *Connect) UserDataRequest() error {

	var isReceive bool
	if this.Role.SignDate == time.Now().Format("20060102") {
		isReceive = true
	}
	if !isReceive {
		if err := this.Role.Sign(); err != nil {
			return this.Send(lineNum(), err)
		}
	}

	configs := models.BaseGeneralMap()

	//var rewardList []*protodata.RewardData
	//for i := this.Role.SignNum; i < this.Role.SignNum+7; i++ {

	//	c, d, s, g := signReward(i)

	//	temp := new(protodata.RewardData)
	//	temp.RewardCoin = proto.Int32(int32(c))
	//	temp.RewardDiamond = proto.Int32(int32(d))
	//	temp.Stamina = proto.Int32(int32(s))
	//	if g > 0 {
	//		temp.General = generalProto(new(models.GeneralData), configs[g])
	//	}

	//	rewardList = append(rewardList, temp)
	//}

	signDay := this.Role.SignNum % 7
	if signDay == 0 {
		signDay = 7
	}

	signProto := &protodata.SignRewardData{
		Reward:    signProto(this.Role.SignNum),
		IsReceive: proto.Bool(isReceive),
		SignDay:   proto.Int32(int32(signDay)),
	}

	var coinProductProtoList []*protodata.CoinProductData
	coinDiamond := models.ConfigCoinDiamondList()
	for _, val := range coinDiamond {
		coinProductProtoList = append(coinProductProtoList, &protodata.CoinProductData{
			ProductIndex: proto.Int32(int32(val.Index)),
			ProductName:  proto.String(val.Name),
			ProductDesc:  proto.String(val.Desc),
			ProductCoin:  proto.Int32(int32(val.Coin)),
			PriceDiamond: proto.Int32(int32(val.Diamond)),
		})
	}

	var productProtoList []*protodata.DiamondProductData
	productList := models.ConfigPayCenterList()
	for _, val := range productList {
		productProtoList = append(productProtoList, &protodata.DiamondProductData{
			ProductIndex:   proto.Int32(int32(val.Id)),
			ProductName:    proto.String(val.Name),
			ProductDesc:    proto.String(val.Desc),
			ProductDiamond: proto.Int32(int32(val.Diamond)),
			Price:          proto.Int32(int32(val.Money)),
		})
	}

	generalList := models.General.List(this.Uid)
	//if len(generalList) == 0 {
	//	Lua, _ := lua.NewLua("conf/general.lua")
	//	s := Lua.GetString("init_generals")
	//	Lua.Close()
	//	array := strings.Split(s, ",")
	//	generalList = append(generalList, models.General.Insert(this.Uid, configs[models.Atoi(array[0])]))
	//	generalList = append(generalList, models.General.Insert(this.Uid, configs[models.Atoi(array[1])]))
	//	generalList = append(generalList, models.General.Insert(this.Uid, configs[models.Atoi(array[2])]))
	//}

	if !isReceive {
		coin, diamond, action, generalId := signReward(this.Role.SignNum)
		if coin > 0 {
			this.Role.AddCoin(coin, models.FINANCE_SIGN_GET, fmt.Sprintf("signDay : %d", signDay))
		} else if diamond > 0 {
			this.Role.AddDiamond(diamond, models.FINANCE_SIGN_GET, fmt.Sprintf("signDay : %d", signDay))
		} else if action > 0 {
			this.Role.SetActionValue(this.Role.ActionValue() + action)
		} else if generalId > 0 {
			var find bool
			for _, val := range generalList {
				if generalId == val.BaseId {
					find = true
					break
				}
			}
			baseGeneral := configs[generalId]
			if find {
				this.Role.AddDiamond(baseGeneral.BuyDiamond, models.FINANCE_SIGN_GET, fmt.Sprintf("signDay : %d", signDay))
			} else {
				newGeneral, err := models.General.Insert(this.Uid, baseGeneral)
				if err != nil {
					return this.Send(lineNum(), err)
				}
				generalList = append(generalList, newGeneral)
			}
		}
	}

	tempItemDiamond := tempItemDiamond()

	return this.Send(StatusOK, &protodata.UserDataResponse{
		Role:             roleProto(this.Role),
		Items:            itemProtoList(models.Item.List(this.Uid)),
		Generals:         generalProtoList(generalList, configs),
		SignReward:       signProto,
		Chapters:         duplicateProtoList(models.NewDuplicateModel(this.Uid).List(), models.ConfigDuplicateList()),
		TempItemDiamonds: []int32{int32(tempItemDiamond[0]), int32(tempItemDiamond[1]), int32(tempItemDiamond[2]), int32(tempItemDiamond[3])},
		CoinProducts:     coinProductProtoList,
		DiamondProducts:  productProtoList,
		LeaderId:         proto.Int32(int32(this.Role.GeneralBaseId)),
		StaminaTimeMax:   proto.Int32(int32(models.Role.ActionWaitTime))})
}