fix inapp_shop
This commit is contained in:
parent
82162d6d3a
commit
b193e159ad
@ -13,6 +13,7 @@ import (
|
||||
"q5"
|
||||
"sort"
|
||||
"strings"
|
||||
"wheelserver/service"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@ -152,4 +153,52 @@ func (this *InAppShopApi) Callback(c *gin.Context) {
|
||||
}
|
||||
|
||||
f5.RspErr(c, 0, "")
|
||||
|
||||
ordergoods := mt.Table.ShopGoods.GetById(int64(orderModel.GoodsId))
|
||||
if ordergoods == nil {
|
||||
f5.GetSysLog().Error("fail dispatch goods:%s", orderId)
|
||||
return
|
||||
}
|
||||
|
||||
itemcfg := mt.Table.Item.GetById(int64(ordergoods.GetItemId()))
|
||||
if itemcfg == nil {
|
||||
f5.GetSysLog().Error("item error, fail dispatch goods:%s, %d", orderId, ordergoods.GetItemId())
|
||||
return
|
||||
}
|
||||
|
||||
user := new(model.User)
|
||||
nowTime := f5.GetApp().GetRealSeconds()
|
||||
if err, found := user.Find(orderModel.AccountId, nowTime); err != nil {
|
||||
f5.GetSysLog().Error("internal error, fail dispatch goods:%s", orderId)
|
||||
return
|
||||
} else if !found {
|
||||
f5.GetSysLog().Error("not found user, fail dispatch goods:%s, %s", orderId, orderModel.AccountId)
|
||||
return
|
||||
}
|
||||
|
||||
switch itemcfg.GetItemType() {
|
||||
case constant.ITEM_TYPE_DICE:
|
||||
user.AddDice(ordergoods.GetAmount())
|
||||
case constant.ITEM_TYPE_SPEC_DICE:
|
||||
user.AddSpecDice(ordergoods.GetAmount())
|
||||
case constant.ITEM_TYPE_CHIP:
|
||||
for i := int32(0); i < ordergoods.GetAmount(); i++ {
|
||||
chip := new(model.Chip)
|
||||
chip.AccountId = orderModel.AccountId
|
||||
chip.ItemId = itemcfg.GetId()
|
||||
chip.ItemNum = 1
|
||||
chip.ExpireTime = int32(nowTime) + itemcfg.GetTime()*60
|
||||
chip.CreateTime = int32(nowTime)
|
||||
chip.ModifyTime = int32(nowTime)
|
||||
if chip.Create() != nil {
|
||||
f5.GetSysLog().Error("internal error, fail dispatch chip:%s, %s", orderId, orderModel.AccountId)
|
||||
}
|
||||
}
|
||||
case constant.ITEM_TYPE_SCORE_DOUBLE_CARD:
|
||||
buflist := []int32{}
|
||||
for i := int32(0); i < ordergoods.GetAmount(); i++ {
|
||||
buflist = append(buflist, itemcfg.GetBuffList()...)
|
||||
}
|
||||
service.Buff.Add(orderModel.AccountId, buflist)
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,15 @@
|
||||
package shop
|
||||
|
||||
import (
|
||||
"q5"
|
||||
"f5"
|
||||
"main/constant"
|
||||
"main/common"
|
||||
"main/vo"
|
||||
"main/mt"
|
||||
"main/constant"
|
||||
"main/model"
|
||||
"main/mt"
|
||||
"main/service"
|
||||
"main/vo"
|
||||
"q5"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
@ -94,5 +96,6 @@ func (this *ShopApi) Buy(c *gin.Context) {
|
||||
rspObj.SideEffect = new(vo.SideEffect)
|
||||
rspObj.SideEffect.User = new(vo.User)
|
||||
rspObj.SideEffect.User.FromModel(user)
|
||||
rspObj.SideEffect.User.HourlyEarnings = service.Chip.GetHourEarning(user.AccountId)
|
||||
c.JSON(200, rspObj)
|
||||
}
|
||||
|
@ -1,13 +1,15 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"q5"
|
||||
"f5"
|
||||
"main/constant"
|
||||
"main/common"
|
||||
"main/constant"
|
||||
"main/model"
|
||||
"main/vo"
|
||||
"main/mt"
|
||||
"main/vo"
|
||||
"q5"
|
||||
"wheelserver/service"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
@ -27,7 +29,8 @@ func (this *UserApi) Login(c *gin.Context) {
|
||||
}{}
|
||||
nowTime := f5.GetApp().GetRealSeconds()
|
||||
rspObj.ServerTime = int32(nowTime)
|
||||
if err, found := user.Find(s.GetAccountId(), nowTime); err != nil {
|
||||
err, found := user.Find(s.GetAccountId(), nowTime)
|
||||
if err != nil {
|
||||
f5.RspErr(c, 500, "server internal error")
|
||||
return
|
||||
} else if !found {
|
||||
@ -55,6 +58,9 @@ func (this *UserApi) Login(c *gin.Context) {
|
||||
}
|
||||
f5.GetMsgQueue().FireEvent(constant.MSG_LOGIN, q5.Args{user})
|
||||
rspObj.UserInfo.FromModel(user)
|
||||
if found {
|
||||
rspObj.UserInfo.HourlyEarnings = service.Chip.GetHourEarning(user.AccountId)
|
||||
}
|
||||
c.JSON(200, rspObj)
|
||||
}
|
||||
|
||||
@ -77,5 +83,6 @@ func (this *UserApi) Info(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
rspObj.UserInfo.FromModel(user)
|
||||
rspObj.UserInfo.HourlyEarnings = service.Chip.GetHourEarning(user.AccountId)
|
||||
c.JSON(200, rspObj)
|
||||
}
|
||||
|
@ -37,6 +37,7 @@ const (
|
||||
ITEM_TYPE_SCORE_DOUBLE_CARD = 4
|
||||
ITEM_TYPE_SCORE_SMALL_GIFT_PACK = 5
|
||||
ITEM_TYPE_SCORE_BIG_GIFT_PACK = 6
|
||||
ITEM_TYPE_DICE = 7
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -1,11 +1,12 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"q5"
|
||||
"f5"
|
||||
"errors"
|
||||
"f5"
|
||||
"main/constant"
|
||||
"main/mt"
|
||||
"q5"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
@ -69,6 +70,13 @@ func (this *User) Create() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this *User) AddDice(num int32) error {
|
||||
if num < 1 {
|
||||
return errors.New("")
|
||||
}
|
||||
return this.DecDice(-num)
|
||||
}
|
||||
|
||||
func (this *User) DecDice(num int32) error {
|
||||
if this.Dice < num {
|
||||
return errors.New("")
|
||||
@ -91,7 +99,7 @@ func (this *User) AddSpecDice(num int32) error {
|
||||
}
|
||||
|
||||
func (this *User) DecSpecDice(num int32) error {
|
||||
if this.Score < int64(num) {
|
||||
if this.SpecDice < num {
|
||||
return errors.New("")
|
||||
}
|
||||
oldSpecDice := this.SpecDice
|
||||
|
@ -110,6 +110,7 @@ type ShopGoods struct {
|
||||
shop_id int32
|
||||
goods_id int32
|
||||
item_id int32
|
||||
amount int32
|
||||
|
||||
_flags1_ uint64
|
||||
_flags2_ uint64
|
||||
@ -482,6 +483,14 @@ func (this *ShopGoods) HasItemId() bool {
|
||||
return (this._flags1_ & (uint64(1) << 3)) > 0
|
||||
}
|
||||
|
||||
func (this *ShopGoods) GetAmount() int32 {
|
||||
return this.amount
|
||||
}
|
||||
|
||||
func (this *ShopGoods) HasAmount() bool {
|
||||
return (this._flags1_ & (uint64(1) << 4)) > 0
|
||||
}
|
||||
|
||||
func (this *Config) GetShopSecret() string {
|
||||
return this.shop_secret
|
||||
}
|
||||
@ -567,6 +576,7 @@ func (this *ShopGoods) LoadFromKv(kv map[string]interface{}) {
|
||||
f5.ReadMetaTableField(&this.shop_id, "shop_id", &this._flags1_, 1, kv)
|
||||
f5.ReadMetaTableField(&this.goods_id, "goods_id", &this._flags1_, 2, kv)
|
||||
f5.ReadMetaTableField(&this.item_id, "item_id", &this._flags1_, 3, kv)
|
||||
f5.ReadMetaTableField(&this.amount, "amount", &this._flags1_, 4, kv)
|
||||
}
|
||||
|
||||
func (this *Config) LoadFromKv(kv map[string]interface{}) {
|
||||
|
@ -89,6 +89,7 @@ message ShopGoods
|
||||
optional int32 shop_id = 1;
|
||||
optional int32 goods_id = 2;
|
||||
optional int32 item_id = 3;
|
||||
optional int32 amount = 4;
|
||||
}
|
||||
|
||||
message Config
|
||||
|
@ -2,10 +2,10 @@ package service
|
||||
|
||||
import (
|
||||
"f5"
|
||||
"main/vo"
|
||||
"main/constant"
|
||||
"main/model"
|
||||
"main/mt"
|
||||
"main/constant"
|
||||
"main/vo"
|
||||
)
|
||||
|
||||
type award struct {
|
||||
@ -29,6 +29,7 @@ func (this *award) AddItem(accountId string, itemId int32, itemNum int32, baseVo
|
||||
user.AddSpecDice(itemNum)
|
||||
baseVo.GetOrCreateSideEffect().User = new(vo.User)
|
||||
baseVo.GetOrCreateSideEffect().User.FromModel(user)
|
||||
baseVo.GetOrCreateSideEffect().User.HourlyEarnings = Chip.GetHourEarning(user.AccountId)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -2,8 +2,10 @@ package service
|
||||
|
||||
import (
|
||||
"f5"
|
||||
"main/model"
|
||||
"main/constant"
|
||||
"main/model"
|
||||
"main/mt"
|
||||
"q5"
|
||||
)
|
||||
|
||||
type chip struct {
|
||||
@ -33,3 +35,16 @@ func (this *chip) CalcScore(accountId string) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func (this *chip) GetHourEarning(accountId string) string {
|
||||
err, chips := this.List(accountId)
|
||||
if err == nil {
|
||||
earnings := int32(0)
|
||||
for _, chipitem := range chips {
|
||||
itemcfg := mt.Table.Item.GetById(int64(chipitem.ItemId))
|
||||
earnings += itemcfg.GetProduce() / (itemcfg.GetTime() / int32(60))
|
||||
}
|
||||
return q5.SafeToString(earnings)
|
||||
}
|
||||
return "0"
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user