285 lines
9.5 KiB
Go
285 lines
9.5 KiB
Go
package customerser
|
|
|
|
import (
|
|
"91porn-server/app/appg"
|
|
"91porn-server/common/crypt"
|
|
"91porn-server/common/httputil"
|
|
"91porn-server/common/log"
|
|
"91porn-server/middleware/ua"
|
|
"91porn-server/models/commod"
|
|
"91porn-server/models/l/visitlogmod"
|
|
"91porn-server/models/v/productmod"
|
|
"91porn-server/models/v/rchgordmod"
|
|
"91porn-server/models/v/usermod"
|
|
"91porn-server/models/v/walletmod"
|
|
"context"
|
|
"encoding/hex"
|
|
"errors"
|
|
"fmt"
|
|
"github.com/gin-gonic/gin"
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
"go.mongodb.org/mongo-driver/mongo/options"
|
|
"net/http"
|
|
"net/url"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
type GetUrlResp struct {
|
|
Code int `json:"code"` // 状态码
|
|
Msg string `json:"msg"` // 状态描述
|
|
Data struct {
|
|
Url string `json:"url"`
|
|
Params string `json:"params"`
|
|
} `json:"data"`
|
|
}
|
|
|
|
func GetUrl(uid uint64, ua ua.UA) (resp GetUrlResp, err error) {
|
|
reqUrl := appg.Conf.Customer.Url + "/app/customer/user/getUrl"
|
|
ul := url.Values{}
|
|
ul.Add("userId", fmt.Sprintf("%v", uid))
|
|
ul.Add("appId", appg.Conf.Customer.AppId)
|
|
ul.Add("deviceType", ua.DevType)
|
|
ul.Add("systemType", ua.SysType)
|
|
ul.Add("systemVersion", ua.Ver)
|
|
dcodeurl, _ := url.QueryUnescape(ul.Encode())
|
|
sign, err := crypt.AesEncrypt(dcodeurl, appg.Conf.Customer.Secret)
|
|
if err != nil {
|
|
log.Warn("GetUrl fail", log.E(err))
|
|
return
|
|
}
|
|
reqUrl = reqUrl + "?sign=" + hex.EncodeToString(sign) + "&appId=" + appg.Conf.Customer.AppId
|
|
//请求对应产品
|
|
httpCode, err := httputil.DefaultClientGetWithResp(&resp, reqUrl, nil)
|
|
if err != nil {
|
|
log.Warn("GetUrl DefaultClientGetWithResp fail", log.Any("reqUrl", reqUrl), log.E(err))
|
|
return
|
|
}
|
|
if httpCode != http.StatusOK {
|
|
log.Warn("GetUrl DefaultClientGetWithResp fail httpCode != http.StatusOK ", log.Any("reqUrl", reqUrl), log.E(err))
|
|
err = errors.New("获取失败")
|
|
return
|
|
}
|
|
if resp.Code != 200 {
|
|
log.Warn("GetUrl DefaultClientGetWithResp fail resp.Code != 200", log.Any("reqUrl", reqUrl), log.Any("resp.Msg", resp.Msg), log.E(err))
|
|
err = errors.New("获取失败")
|
|
return
|
|
}
|
|
return resp, nil
|
|
}
|
|
|
|
type BackpackReq struct {
|
|
UserID int `form:"userId"`
|
|
Account string `form:"account"`
|
|
Phone string `form:"phone"`
|
|
InviteCode string `form:"inviteCode"` // 邀请码
|
|
}
|
|
|
|
type BackpackResp struct {
|
|
UserId string `json:"userId"` // 用户Id
|
|
Account string `json:"account"` // 账号
|
|
Email string `json:"email"` // 邮箱
|
|
UserName string `json:"userName"` // 用户姓名
|
|
UserIp string `json:"userIp"` // 用户IP
|
|
UserIpLocation string `json:"userIpLocation"` // 用户IP属地
|
|
DevType string `json:"devType"` // 设备类型
|
|
DevId string `json:"devId"` // 设备id
|
|
SystemType string `json:"systemType" bson:"systemType"` // 系统类型
|
|
SystemVersion string `json:"systemVersion" bson:"systemVersion"` // 系统版本
|
|
AppId string `json:"appId"` // appId
|
|
AppName string `json:"appName"` // appName
|
|
VipExpiredTime time.Time `json:"vipExpiredTime"` // VIP过期时间
|
|
VipLevel string `json:"vipLevel"` // VIP等级
|
|
VipName string `json:"vipName"` // VIP名
|
|
Balance float64 `json:"balance"` // 金币余额
|
|
UserRights string `json:"userRights"` // 用户权益,eg:金币抵扣券*3,AI抵扣券*4
|
|
InviteCode string `json:"inviteCode"` // 邀请码
|
|
}
|
|
|
|
func (p *BackpackReq) GetData(ctx *gin.Context, uid uint64, account, phone, inviteCode string) (resp BackpackResp, err error) {
|
|
var user *usermod.User
|
|
if uid > 0 {
|
|
// 获取用户信息
|
|
user, err = usermod.FindUserByUID(uid)
|
|
|
|
} else if account != "" {
|
|
user, err = usermod.FindUserByAccount(account)
|
|
} else if phone != "" {
|
|
if !strings.HasPrefix(phone, "+86") {
|
|
phone = "+86" + phone
|
|
}
|
|
user, err = usermod.FindUserByMobile(phone)
|
|
} else if inviteCode != "" {
|
|
user, err = usermod.FindUserPromotionCode(inviteCode)
|
|
} else {
|
|
return resp, nil
|
|
}
|
|
if err != nil {
|
|
log.Error("BackpackReq.GetData fail", log.Any("uid", uid), log.E(err))
|
|
return
|
|
}
|
|
if user == nil {
|
|
return
|
|
}
|
|
// 获取用户余额
|
|
wallet, err := walletmod.GetWallet(uid)
|
|
if err != nil {
|
|
log.Error("BackpackReq.GetData fail", log.Any("uid", uid), log.E(err))
|
|
return
|
|
}
|
|
filter := bson.M{
|
|
"uid": user.UID,
|
|
}
|
|
// 获取用户的最后的登录信息
|
|
visit, err := visitlogmod.GetInfoByCond(filter, options.FindOne().SetSort(bson.D{{Key: "_id", Value: -1}}))
|
|
if err != nil {
|
|
log.Error("BackpackReq.GetData visitlogmod.GetInfoByCond fail", log.Any("uid", uid), log.E(err))
|
|
}
|
|
resp = BackpackResp{
|
|
UserId: fmt.Sprintf("%v", user.UID),
|
|
UserName: user.Name,
|
|
Account: user.Account,
|
|
Email: user.Email,
|
|
UserIp: visit.IP,
|
|
DevType: user.LastSysType,
|
|
DevId: user.DevID,
|
|
SystemType: user.SysType,
|
|
SystemVersion: user.LastVer,
|
|
AppId: appg.Conf.Customer.AppId,
|
|
AppName: commod.KFK_APP_NAME,
|
|
VipExpiredTime: user.VipExpireDate,
|
|
VipName: user.VipName,
|
|
VipLevel: fmt.Sprintf("%v", user.VipLevel),
|
|
//UserRights :user.
|
|
InviteCode: user.PromCode,
|
|
}
|
|
userRights := []string{}
|
|
if wallet != nil {
|
|
resp.Balance = float64(wallet.Amount)
|
|
//if wallet.AiChangeFaceImgFreeTimes > 0 {
|
|
// userRights = append(userRights, fmt.Sprintf("AI图片换脸免费次数*%v", wallet.AiChangeFaceImgFreeTimes))
|
|
//}
|
|
if wallet.AiUndressFreeTimes > 0 {
|
|
userRights = append(userRights, fmt.Sprintf("AI脱衣免费次数*%v", wallet.AiUndressFreeTimes))
|
|
}
|
|
if wallet.DownloadCount > 0 {
|
|
userRights = append(userRights, fmt.Sprintf("下载次数*%v", wallet.DownloadCount))
|
|
}
|
|
if wallet.LotteryTimes > 0 {
|
|
userRights = append(userRights, fmt.Sprintf("抽奖次数*%v", wallet.LotteryTimes))
|
|
}
|
|
|
|
userRights = append(userRights, fmt.Sprintf("AI女友余额=%v", wallet.AiMateBalance))
|
|
userRights = append(userRights, fmt.Sprintf("金币余额=%v", wallet.Amount))
|
|
userRights = append(userRights, fmt.Sprintf("金币收益=%v", wallet.Income))
|
|
}
|
|
resp.UserRights = strings.Join(userRights, ",")
|
|
return resp, nil
|
|
}
|
|
|
|
type RechargeReq struct {
|
|
UserID int `form:"userId"`
|
|
}
|
|
|
|
type RechargeResp []RechargeItem
|
|
|
|
type RechargeItem struct {
|
|
UserId string `json:"userId"` // 用户Id
|
|
UserName string `json:"userName"` // 用户姓名
|
|
UserIp string `json:"userIp"` // 用户IP
|
|
DevType string `json:"devType"` // 设备类型
|
|
AppId string `json:"appId"` // appId
|
|
AppName string `json:"appName"` // appName
|
|
PayType string `json:"payType"` // 支付方式
|
|
OrderId string `json:"orderId"` // 订单号
|
|
ChannelOid string `json:"channelOid"` // 渠道订单号
|
|
Money float64 `json:"money"` // 订单金额
|
|
PayMoney float64 `json:"payMoney"` // 支付金额
|
|
Status string `json:"status"` // 订单状态
|
|
ProductName string `json:"productName"` // 商品名称
|
|
Remark string `json:"remark"` // 备注
|
|
CreateTime time.Time `json:"createTime"` // 下单时间
|
|
PayTime time.Time `json:"payTime"` // 支付时间
|
|
NotifyTime time.Time `json:"notifyTime"` // 回调时间
|
|
}
|
|
|
|
func (p *RechargeReq) GetData(ctx context.Context, uid uint64) (resp RechargeResp, err error) {
|
|
_, list, err := rchgordmod.FindRechargesOrders(bson.M{
|
|
"uid": uid,
|
|
}, options.Find().SetLimit(200).SetSort(bson.M{"_id": -1}))
|
|
if err != nil {
|
|
log.Error("RechargeReq.GetData fail", log.Any("uid", uid), log.E(err))
|
|
return
|
|
}
|
|
productIds := []primitive.ObjectID{}
|
|
for _, v := range list {
|
|
if v.BuyType == commod.BuyProduct {
|
|
productIds = append(productIds, v.ProductID)
|
|
}
|
|
}
|
|
productMap := getProductMap(productIds)
|
|
for _, v := range list {
|
|
var status string
|
|
switch v.Status {
|
|
case 2:
|
|
//2付款失败
|
|
status = "付款失败"
|
|
case 3:
|
|
// 3付款成功
|
|
status = "付款成功"
|
|
case 4:
|
|
// 4已经退款
|
|
status = "已经退款"
|
|
default:
|
|
status = "进行中"
|
|
}
|
|
item := RechargeItem{
|
|
UserId: fmt.Sprintf("%v", v.UID),
|
|
UserName: v.Name,
|
|
UserIp: v.UserIP,
|
|
DevType: v.DevType,
|
|
AppId: appg.Conf.Customer.AppId,
|
|
AppName: commod.KFK_APP_NAME,
|
|
PayType: v.RechargeType,
|
|
OrderId: v.ID.Hex(),
|
|
ChannelOid: v.OID,
|
|
Money: float64(v.Money) / 100,
|
|
PayMoney: float64(v.PayMoney) / 100,
|
|
Status: status,
|
|
ProductName: v.ProductID.Hex(),
|
|
Remark: v.Remark,
|
|
CreateTime: v.CreatedAt,
|
|
PayTime: v.PaymentAt,
|
|
NotifyTime: v.SuccessAt,
|
|
}
|
|
switch v.BuyType {
|
|
case commod.BuyProduct:
|
|
product, ok := productMap[v.ProductID]
|
|
if ok {
|
|
item.ProductName = product.Name
|
|
}
|
|
case commod.BuyGold:
|
|
item.ProductName = "金币"
|
|
case commod.BuyFruitCoin:
|
|
item.ProductName = "果币"
|
|
case commod.BuyGameCoin:
|
|
item.ProductName = "游戏币"
|
|
}
|
|
resp = append(resp, item)
|
|
}
|
|
return
|
|
}
|
|
|
|
func getProductMap(productIds []primitive.ObjectID) map[primitive.ObjectID]productmod.Product {
|
|
productMap := make(map[primitive.ObjectID]productmod.Product)
|
|
if len(productIds) == 0 {
|
|
return productMap
|
|
}
|
|
list, _ := productmod.FindByProductIDs(productIds)
|
|
for _, v := range list {
|
|
productMap[v.ID] = v
|
|
}
|
|
return productMap
|
|
}
|