huangjiajun 2 kuukautta sitten
vanhempi
commit
366f264abf
5 muutettua tiedostoa jossa 215 lisäystä ja 0 poistoa
  1. +48
    -0
      app/db/db_user_virtual_amount.go
  2. +114
    -0
      app/db/db_virtaul_coin_cfg.go
  3. +12
    -0
      app/db/model/user_virtual_amount.go
  4. +40
    -0
      app/hdl/hdl_store.go
  5. +1
    -0
      app/router/router.go

+ 48
- 0
app/db/db_user_virtual_amount.go Näytä tiedosto

@@ -0,0 +1,48 @@
package db

import (
"applet/app/db/model"
"applet/app/utils"
"xorm.io/xorm"
)

func GetUserVirtualAmountOne(session *xorm.Session, uid int, coinId int) (*model.UserVirtualAmount, error) {

var m model.UserVirtualAmount
isExist, err := session.Table("user_virtual_amount").Where("uid = ? AND coin_id = ?", uid, coinId).Get(&m)
if err != nil {
return nil, err
}
if !isExist {
return nil, nil
}
return &m, nil

}

func GetUserVirtualAmountOneEg(eg *xorm.Engine, uid int, coinId int) (*model.UserVirtualAmount, error) {

var m model.UserVirtualAmount
isExist, err := eg.Table("user_virtual_amount").Where("uid = ? AND coin_id = ?", uid, coinId).Get(&m)
if err != nil {
return nil, err
}
if !isExist {
return nil, nil
}
return &m, nil

}
func GetUserVirtualAmountSum(eg *xorm.Engine, uid int) (string, error) {
var m model.UserVirtualAmount
sum, err := eg.Table("user_virtual_amount").Where("uid = ? ", uid).Sum(&m, "amount")
if err != nil {
return "0", err
}
return utils.Float64ToStr(sum), nil

}

/*func UserVirtualAmountUpdateWithSession(session *xorm.Session, m *model.UserVirtualAmount) bool {

}*/

+ 114
- 0
app/db/db_virtaul_coin_cfg.go Näytä tiedosto

@@ -0,0 +1,114 @@
package db

import (
"applet/app/db/model"
"applet/app/md"
"applet/app/utils"
"applet/app/utils/cache"
"applet/app/utils/logx"
"fmt"
"reflect"
"xorm.io/xorm"
)

func GetVirtualCoinList(eg *xorm.Engine) ([]*model.VirtualCoin, error) {
var m []*model.VirtualCoin
err := eg.Find(&m)
if err != nil {
return nil, err
}

return m, nil
}
func GetVirtualCoinIsUseList(eg *xorm.Engine) ([]*model.VirtualCoin, error) {
var m []*model.VirtualCoin
err := eg.Where("is_use = ?", 1).Find(&m)
if err != nil {
return nil, err
}

return m, nil
}

// VirtualCoinListInUse 查询正在使用中的虚拟币
func VirtualCoinListInUse(Db *xorm.Engine, masterId string) ([]*model.VirtualCoin, error) {
var m []*model.VirtualCoin
cacheKey := fmt.Sprintf(md.VirtualCoinCfgCacheKey, masterId)

err := cache.GetJson(cacheKey, &m)
if err != nil || len(m) == 0 {
err := Db.Where("is_use=1").Find(&m)
if err != nil {
return nil, err
}
cache.SetJson(cacheKey, m, md.CfgCacheTime)
}

return m, nil
}

// VirtualCoinGetOneByParams 通过参数查询数据(单条)
func VirtualCoinGetOneByParams(Db *xorm.Engine, params map[string]interface{}) (*model.VirtualCoin, error) {
var m model.VirtualCoin
var query = fmt.Sprintf("%s =?", params["key"])
if has, err := Db.Where(query, params["value"]).Get(&m); err != nil || has == false {
return nil, logx.Error(err)
}
return &m, nil
}

// VirtualCoinFindByParams 通过传入的参数查询数据(多条)
func VirtualCoinFindByParams(Db *xorm.Engine, params map[string]interface{}) (*[]model.VirtualCoin, error) {
var m []model.VirtualCoin
if params["key"] == nil {
//查询全部数据
err := Db.Find(&m)
if err != nil {
return nil, logx.Error(err)
}
return &m, nil
} else {
if reflect.TypeOf(params["value"]).Kind() == reflect.Slice {
//指定In查询
if err := Db.In(utils.AnyToString(params["key"]), params["value"]).Find(&m); err != nil {
return nil, logx.Warn(err)
}
return &m, nil
} else {
var query = fmt.Sprintf("%s =?", params["key"])
err := Db.Where(query, params["value"]).Find(&m)
if err != nil {
return nil, logx.Error(err)
}
return &m, nil
}

}
}
func VirtualCoinGetOneById(Db *xorm.Engine, coinId string) (*model.VirtualCoin, error) {
var m model.VirtualCoin
if has, err := Db.ID(coinId).Get(&m); err != nil || has == false {
return nil, logx.Error(err)
}
return &m, nil
}

func VirtualCoinOrderRelateDeleteByOid(Db *xorm.Engine, oid int64, pvd string) (int64, error) {
_, err := Db.Where("oid=? and pvd=?", oid, pvd).Delete(model.VirtualCoinRelate{})
if err != nil {
return 0, err
}
return 1, nil
}

func VirtualCoinMapInUse(Db *xorm.Engine, masterId string) (map[string]model.VirtualCoin, error) {
virtualCoinMap := make(map[string]model.VirtualCoin)
listInUse, err := VirtualCoinListInUse(Db, masterId)
if err != nil {
return nil, err
}
for _, coin := range listInUse {
virtualCoinMap[utils.AnyToString(coin.Id)] = *coin
}
return virtualCoinMap, nil
}

+ 12
- 0
app/db/model/user_virtual_amount.go Näytä tiedosto

@@ -0,0 +1,12 @@
package model

type UserVirtualAmount struct {
Id int64 `json:"id" xorm:"pk autoincr BIGINT(20)"`
Uid int `json:"uid" xorm:"index INT(11)"`
CoinId int `json:"coin_id" xorm:"INT(11)"`
Amount string `json:"amount" xorm:"DECIMAL(16,6)"`
FreezeAmount string `json:"freeze_amount" xorm:"DECIMAL(16,6)"`
WaitAmount string `json:"wait_amount" xorm:"DECIMAL(16,6)"`
TeamFreezeAmount string `json:"team_freeze_amount" xorm:"DECIMAL(16,6)"`
UseAmount string `json:"use_amount" xorm:"DECIMAL(16,6)"`
}

+ 40
- 0
app/hdl/hdl_store.go Näytä tiedosto

@@ -2,10 +2,14 @@ package hdl

import (
"applet/app/db"
"applet/app/db/model"
"applet/app/e"
"applet/app/svc"
"applet/app/utils"
"fmt"
"github.com/gin-gonic/gin"
"github.com/tidwall/gjson"
"time"
)

func City(c *gin.Context) {
@@ -52,3 +56,39 @@ func StoreAddLike(c *gin.Context) {
func StoreCancelLike(c *gin.Context) {
svc.StoreCancelLike(c)
}
func User(c *gin.Context) {
user, _ := svc.GetDefaultUser(c, c.GetHeader("Authorization"))
res := map[string]string{
"head_img": "",
"nickname": "",
"coupon_str": "优惠券:",
"coupon": "0",
"integral_str": "积分:",
"integral": "0",
}
if user != nil && user.Info.Uid > 0 {
res["head_img"] = user.Profile.AvatarUrl
res["nickname"] = user.Info.Nickname
now := time.Now().Format("2006-01-02 15:04:05")
count, _ := svc.MasterDb(c).Table("act_coupon_user").
Where("store_type=? and uid = ? AND is_use = ? AND (valid_time_start < ? AND valid_time_end > ?)", 0,
user.Info.Uid, 0, now, now).Count(&model.CommunityTeamCouponUser{})
res["coupon"] = utils.Int64ToStr(count)
mod, _ := db.SysModFindBySkipIdentifier(c, svc.MasterDb(c), "pub.flutter.community_team_store_index")
if mod != nil {
integralCoinId := gjson.Get(mod.Data, "integralCoinId").String()
if utils.StrToInt(integralCoinId) > 0 {
coin, _ := db.VirtualCoinGetOneById(svc.MasterDb(c), integralCoinId)
if coin != nil {
amount, _ := db.GetUserVirtualAmountOneEg(svc.MasterDb(c), user.Info.Uid, utils.StrToInt(integralCoinId))
res["integral_str"] = coin.Name + ":"
if amount != nil {
res["integral"] = svc.GetCommissionPrec(c, amount.Amount, svc.SysCfgGet(c, "integral_prec"), "0")
}
}
}
}
}
e.OutSuc(c, res, nil)
return
}

+ 1
- 0
app/router/router.go Näytä tiedosto

@@ -52,6 +52,7 @@ func routeCommunityTeam(r *gin.RouterGroup) {
r.GET("/goods/cate", hdl.Cate)
r.POST("/goods", hdl.Goods)
r.POST("/goods/sku", hdl.GoodsSku)
r.GET("/user", hdl.User)
// 用户授权后调用的接口
r.Use(mw.AuthJWT)
r.POST("/store/addLike", hdl.StoreAddLike)


Ladataan…
Peruuta
Tallenna