charge.go 2.03 KB
Newer Older
hujiebin's avatar
hujiebin committed
1 2 3 4 5
package charge_r

import (
	"git.hilo.cn/hilo-common/domain"
	"git.hilo.cn/hilo-common/mycontext"
hujiebin's avatar
hujiebin committed
6
	"git.hilo.cn/hilo-common/resource/config"
hujiebin's avatar
hujiebin committed
7 8
	"github.com/gin-gonic/gin"
	"hilo-group/domain/cache/user_c"
chenweijian's avatar
chenweijian committed
9
	"hilo-group/domain/model/diamond_m"
hujiebin's avatar
hujiebin committed
10
	"hilo-group/domain/service/diamond_s"
chenweijian's avatar
chenweijian committed
11
	"hilo-group/myerr/bizerr"
hujiebin's avatar
hujiebin committed
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
	"hilo-group/req"
	"hilo-group/resp"
)

// @Tags 充值
// @Summary 是否可以分享充值链接
// @Param externalId query string true "分享对象的external id"
// @Success 200
// @Router /v1/charge/share [get]
func CanShareChargeLink(c *gin.Context) (*mycontext.MyContext, error) {
	myContext := mycontext.CreateMyContext(c.Keys)

	userId, lang, err := req.GetUserIdLang(c, myContext)
	if err != nil {
		return myContext, err
	}

	extId := c.Query("externalId")
	model := domain.CreateModelContext(myContext)
	toUser, err := user_c.GetUserByExternalId(model, extId)
	if err != nil {
		return myContext, err
	}

chenweijian's avatar
chenweijian committed
36 37 38 39 40 41 42 43
	isDealer, err := diamond_m.IsDiamondDealer(model.DB(), userId)
	if err != nil {
		return myContext, err
	}
	if !isDealer {
		return myContext, bizerr.InvalidParameter
	}

hujiebin's avatar
hujiebin committed
44 45 46 47 48
	// 家族限制检查
	if err = diamond_s.NewDiamondService(myContext).CheckDealerTransferFamilyLimit(userId, toUser.ID, lang); err != nil {
		myContext.Log.Errorf("CanShareChargeLink err:%v", err)
		return myContext, err
	}
hujiebin's avatar
hujiebin committed
49
	type res struct {
chenweijian's avatar
chenweijian committed
50 51 52
		ShareUrl    string `json:"shareUrl"`
		ShareIcon   string `json:"shareIcon"`
		RechargeUrl string `json:"rechargeUrl"`
hujiebin's avatar
hujiebin committed
53
	}
hujiebin's avatar
hujiebin committed
54

chenweijian's avatar
chenweijian committed
55 56 57 58 59 60
	// 安卓3.8.0版本有bug,这里暂时兼容
	shareUrl := config.GetH5Config().AGENT_SHARE_URL
	deviceType, major, minor, _, err := req.GetAppVersion(c)
	if err != nil {
		return myContext, err
	}
chenweijian's avatar
chenweijian committed
61 62 63 64
	myUser, err := user_c.GetUserTinyById(model, userId)
	if err != nil {
		return myContext, err
	}
chenweijian's avatar
chenweijian committed
65 66 67 68 69
	if deviceType == "android" {
		if (major > 3) || (major == 3 && minor >= 8) {
			shareUrl = shareUrl + myUser.ExternalId
		}
	}
chenweijian's avatar
chenweijian committed
70
	rechargeUrl := config.GetH5Config().AGENT_SHARE_URL + myUser.ExternalId
chenweijian's avatar
chenweijian committed
71

chenweijian's avatar
chenweijian committed
72
	resp.ResponseOk(c, res{shareUrl, config.GetH5Config().AGENT_SHARE_ICON, rechargeUrl})
hujiebin's avatar
hujiebin committed
73 74
	return myContext, nil
}