三方接口
This commit is contained in:
parent
79c642932c
commit
39cbe5a8ba
|
@ -4,4 +4,6 @@ const (
|
||||||
TOKEN_PRE = "player_token_"
|
TOKEN_PRE = "player_token_"
|
||||||
TOKEN_Admin = "Admin_token_"
|
TOKEN_Admin = "Admin_token_"
|
||||||
ADMIN_V1 = "/admin/api/v1"
|
ADMIN_V1 = "/admin/api/v1"
|
||||||
|
|
||||||
|
FRONT_API_V1 = "/api/v1"
|
||||||
)
|
)
|
||||||
|
|
|
@ -103,7 +103,7 @@ func GenRequest(c *gin.Context, request interface{}) (msgs []string, err error)
|
||||||
if c.Request.Method == "GET" || c.Request.Method == "DELETE" {
|
if c.Request.Method == "GET" || c.Request.Method == "DELETE" {
|
||||||
err = c.ShouldBindQuery(request)
|
err = c.ShouldBindQuery(request)
|
||||||
} else {
|
} else {
|
||||||
err = c.ShouldBindJSON(request)
|
err = c.ShouldBind(request)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
package front
|
|
@ -0,0 +1,12 @@
|
||||||
|
package front
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"qteam/app/http/controllers"
|
||||||
|
"qteam/app/services"
|
||||||
|
)
|
||||||
|
|
||||||
|
func VoucherList(c *gin.Context) {
|
||||||
|
code, data := services.VoucherList()
|
||||||
|
controllers.HandCodeRes(c, data, code)
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
package entities
|
|
@ -0,0 +1 @@
|
||||||
|
package entities
|
|
@ -0,0 +1,43 @@
|
||||||
|
package entities
|
||||||
|
|
||||||
|
import (
|
||||||
|
"qteam/app/models/brandmodel"
|
||||||
|
"qteam/app/models/productsmodel"
|
||||||
|
"qteam/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
type VoucherListResponse struct {
|
||||||
|
MilkUrl string `json:"milkUrl"`
|
||||||
|
MilkList []MilkList `json:"milkList"`
|
||||||
|
MilkVoucherList []MilkVoucherList `json:"milkVoucherList"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type MilkList struct {
|
||||||
|
BrandLogo string `json:"brandLogo"`
|
||||||
|
BrandFlag string `json:"brandFlag"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *MilkList) ResponseFromDb(in brandmodel.Brand) {
|
||||||
|
this.BrandFlag = in.Flag
|
||||||
|
this.BrandLogo = in.Logo
|
||||||
|
}
|
||||||
|
|
||||||
|
type MilkVoucherList struct {
|
||||||
|
BrandFlag string `json:"brandFlag"`
|
||||||
|
VoucherTitle string `json:"voucherTitle"`
|
||||||
|
VoucherUrl string `json:"voucherUrl"`
|
||||||
|
VoucherIcon string `json:"voucherIcon"`
|
||||||
|
VoucherAmount string `json:"voucherAmount"`
|
||||||
|
VoucherOriginalPrice string `json:"voucherOriginalPrice"`
|
||||||
|
VoucherStatus string `json:"voucherStatus"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *MilkVoucherList) ResponseFromDb(in productsmodel.MilkProductsList) {
|
||||||
|
this.BrandFlag = in.Flag
|
||||||
|
this.VoucherTitle = in.Name
|
||||||
|
this.VoucherUrl = config.GetConf().YouChu.MilkUrl + "?voucher_id=" + in.Id
|
||||||
|
this.VoucherIcon = in.MainImage
|
||||||
|
this.VoucherAmount = in.ShowPrice
|
||||||
|
this.VoucherOriginalPrice = in.Price
|
||||||
|
this.VoucherStatus = in.Status
|
||||||
|
}
|
|
@ -1,7 +1,12 @@
|
||||||
package requestmapping
|
package requestmapping
|
||||||
|
|
||||||
|
import "qteam/app/constants/common"
|
||||||
|
|
||||||
var FrontRequestMap = map[string]func() interface{}{
|
var FrontRequestMap = map[string]func() interface{}{
|
||||||
//"/v1/login": func() interface{} {
|
//"/v1/login": func() interface{} {
|
||||||
// return new(front.LoginRequest)
|
// return new(front.LoginRequest)
|
||||||
//},
|
//},
|
||||||
|
|
||||||
|
// 奶茶专区代金券列表
|
||||||
|
common.FRONT_API_V1 + "/VoucherList": func() interface{} { return new(struct{}) },
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,9 @@ package routes
|
||||||
* 配置路由
|
* 配置路由
|
||||||
*/
|
*/
|
||||||
import (
|
import (
|
||||||
|
"qteam/app/constants/common"
|
||||||
"qteam/app/http/controllers"
|
"qteam/app/http/controllers"
|
||||||
|
"qteam/app/http/controllers/front"
|
||||||
"qteam/app/http/middlewares"
|
"qteam/app/http/middlewares"
|
||||||
"qteam/app/http/trace"
|
"qteam/app/http/trace"
|
||||||
"qteam/app/utils/metric"
|
"qteam/app/utils/metric"
|
||||||
|
@ -44,10 +46,10 @@ func RegisterRoute(router *gin.Engine) {
|
||||||
router.NoRoute(controllers.Error404)
|
router.NoRoute(controllers.Error404)
|
||||||
|
|
||||||
//api版本
|
//api版本
|
||||||
//v1 := router.Group("/v1", middlewares.ValidateRequest())
|
v1 := router.Group(common.FRONT_API_V1, middlewares.ValidateRequest())
|
||||||
//{
|
{
|
||||||
//
|
v1.POST("/VoucherList", front.VoucherList)
|
||||||
//}
|
}
|
||||||
|
|
||||||
router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
package brandmodel
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/qit-team/snow-core/db"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
once sync.Once
|
||||||
|
m *BrandModel
|
||||||
|
)
|
||||||
|
|
||||||
|
// 实体
|
||||||
|
type Brand struct {
|
||||||
|
Id int `xorm:"'id' int(10) pk autoincr"`
|
||||||
|
Logo string `xorm:"'logo' varchar(255)"`
|
||||||
|
Flag string `xorm:"'flag' varchar(50)"`
|
||||||
|
Name string `xorm:"'name' varchar(50)"`
|
||||||
|
State int `xorm:"'state' TINYINT"`
|
||||||
|
CreateTime time.Time `xorm:"'create_time' datetime"`
|
||||||
|
UpdateTime time.Time `xorm:"'update_time' datetime"`
|
||||||
|
Deleted time.Time `xorm:"'Deleted' datetime"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// 表名
|
||||||
|
func (m *Brand) TableName() string {
|
||||||
|
return "Brand"
|
||||||
|
}
|
||||||
|
|
||||||
|
// 私有化,防止被外部new
|
||||||
|
type BrandModel struct {
|
||||||
|
db.Model //组合基础Model,集成基础Model的属性和方法
|
||||||
|
}
|
||||||
|
|
||||||
|
// 单例模式
|
||||||
|
func GetInstance() *BrandModel {
|
||||||
|
once.Do(func() {
|
||||||
|
m = new(BrandModel)
|
||||||
|
//m.DiName = "" //设置数据库实例连接,默认db.SingletonMain
|
||||||
|
})
|
||||||
|
return m
|
||||||
|
}
|
|
@ -0,0 +1,52 @@
|
||||||
|
package ordersmodel
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/qit-team/snow-core/db"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
once sync.Once
|
||||||
|
m *OrdersModel
|
||||||
|
)
|
||||||
|
|
||||||
|
// 实体
|
||||||
|
type Orders struct {
|
||||||
|
Id string `xorm:"'id' UNSIGNED INT pk autoincr"`
|
||||||
|
OrderNo string `xorm:"'order_no' varchar(50)"`
|
||||||
|
UserId int `xorm:"'user_id' int(0)"`
|
||||||
|
YouchuUserId int `xorm:"'YouChu_User_id' int(11)"`
|
||||||
|
UserName string `xorm:"'user_name' varchar(11)"`
|
||||||
|
Mobile string `xorm:"'mobile' varchar(13)"`
|
||||||
|
ProductId int `xorm:"'product_id' int(0)"`
|
||||||
|
ProductName string `xorm:"'product_name' varchar(50)"`
|
||||||
|
Price string `xorm:"'price' decimal(10,2)"`
|
||||||
|
ActivityId string `xorm:"'activity_id' UNSIGNED INT"`
|
||||||
|
State string `xorm:"'state' UNSIGNED TINYINT"`
|
||||||
|
VoucherId int `xorm:"'voucher_id' int(0)"`
|
||||||
|
VoucherLink string `xorm:"'voucher_link' varchar(255)"`
|
||||||
|
CreateTime time.Time `xorm:"'create_time' datetime"`
|
||||||
|
UpdateTime time.Time `xorm:"'update_time' datetime"`
|
||||||
|
ExchangeTime time.Time `xorm:"'exchange_time' datetime"`
|
||||||
|
Deleted time.Time `xorm:"'Deleted' datetime"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// 表名
|
||||||
|
func (m *Orders) TableName() string {
|
||||||
|
return "Orders"
|
||||||
|
}
|
||||||
|
|
||||||
|
// 私有化,防止被外部new
|
||||||
|
type OrdersModel struct {
|
||||||
|
db.Model //组合基础Model,集成基础Model的属性和方法
|
||||||
|
}
|
||||||
|
|
||||||
|
// 单例模式
|
||||||
|
func GetInstance() *OrdersModel {
|
||||||
|
once.Do(func() {
|
||||||
|
m = new(OrdersModel)
|
||||||
|
//m.DiName = "" //设置数据库实例连接,默认db.SingletonMain
|
||||||
|
})
|
||||||
|
return m
|
||||||
|
}
|
|
@ -0,0 +1,55 @@
|
||||||
|
package productsmodel
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/qit-team/snow-core/db"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
once sync.Once
|
||||||
|
m *ProductsModel
|
||||||
|
)
|
||||||
|
|
||||||
|
// 实体
|
||||||
|
type Products struct {
|
||||||
|
Id string `xorm:"'id' UNSIGNED BIGINT pk autoincr"`
|
||||||
|
Name string `xorm:"'name' varchar(255)"`
|
||||||
|
MainImage string `xorm:"'main_image' varchar(255)"`
|
||||||
|
Brand string `xorm:"'brand' varchar(100)"`
|
||||||
|
BrandId int `xorm:"'brand_id' int(10)"`
|
||||||
|
Stock string `xorm:"'stock' UNSIGNED INT"`
|
||||||
|
ShowPrice string `xorm:"'show_price' decimal(10,2)"`
|
||||||
|
Price string `xorm:"'price' decimal(10,2)"`
|
||||||
|
Type string `xorm:"'type' UNSIGNED TINYINT"`
|
||||||
|
CreateTime time.Time `xorm:"'create_time' datetime"`
|
||||||
|
UpdateTime time.Time `xorm:"'update_time' datetime"`
|
||||||
|
Deleted time.Time `xorm:"'Deleted' datetime"`
|
||||||
|
Status string `xorm:"'status' UNSIGNED TINYINT"`
|
||||||
|
Description string `xorm:"'description' varchar(500)"`
|
||||||
|
ThirdProductId int `xorm:"'third_product_Id' int(0)"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type MilkProductsList struct {
|
||||||
|
Products `xorm:"extends"`
|
||||||
|
Flag string `xorm:"'flag' varchar(50)"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// 表名
|
||||||
|
func (m *Products) TableName() string {
|
||||||
|
return "Products"
|
||||||
|
}
|
||||||
|
|
||||||
|
// 私有化,防止被外部new
|
||||||
|
type ProductsModel struct {
|
||||||
|
db.Model //组合基础Model,集成基础Model的属性和方法
|
||||||
|
}
|
||||||
|
|
||||||
|
// 单例模式
|
||||||
|
func GetInstance() *ProductsModel {
|
||||||
|
once.Do(func() {
|
||||||
|
m = new(ProductsModel)
|
||||||
|
//m.DiName = "" //设置数据库实例连接,默认db.SingletonMain
|
||||||
|
})
|
||||||
|
return m
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
package usersmodel
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/qit-team/snow-core/db"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
once sync.Once
|
||||||
|
m *UsersModel
|
||||||
|
)
|
||||||
|
|
||||||
|
// 实体
|
||||||
|
type Users struct {
|
||||||
|
Id string `xorm:"'id' UNSIGNED INT pk autoincr"`
|
||||||
|
YouchuUserFlag int `xorm:"'YouChu_user_flag' int(10)"`
|
||||||
|
Name string `xorm:"'name' varchar(128)"`
|
||||||
|
Phone string `xorm:"'phone' char(11)"`
|
||||||
|
Status string `xorm:"'status' UNSIGNED TINYINT"`
|
||||||
|
CreateTime time.Time `xorm:"'create_time' datetime"`
|
||||||
|
UpdateTime time.Time `xorm:"'update_time' datetime"`
|
||||||
|
Deleted time.Time `xorm:"'Deleted' datetime"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// 表名
|
||||||
|
func (m *Users) TableName() string {
|
||||||
|
return "Users"
|
||||||
|
}
|
||||||
|
|
||||||
|
// 私有化,防止被外部new
|
||||||
|
type UsersModel struct {
|
||||||
|
db.Model //组合基础Model,集成基础Model的属性和方法
|
||||||
|
}
|
||||||
|
|
||||||
|
// 单例模式
|
||||||
|
func GetInstance() *UsersModel {
|
||||||
|
once.Do(func() {
|
||||||
|
m = new(UsersModel)
|
||||||
|
//m.DiName = "" //设置数据库实例连接,默认db.SingletonMain
|
||||||
|
})
|
||||||
|
return m
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
package services
|
||||||
|
|
||||||
|
import (
|
||||||
|
"qteam/app/models/brandmodel"
|
||||||
|
)
|
||||||
|
|
||||||
|
func MilkBrandList() (code int, brandData []brandmodel.Brand) {
|
||||||
|
err := brandmodel.GetInstance().GetDb().Where("state = ?", 1).Find(&brandData)
|
||||||
|
return handErr(err), brandData
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
package services
|
||||||
|
|
||||||
|
import "qteam/app/models/productsmodel"
|
||||||
|
|
||||||
|
func MilkProductList() (code int, productList []productsmodel.MilkProductsList) {
|
||||||
|
err := productsmodel.GetInstance().GetDb().Alias("a").
|
||||||
|
Join("INNER", "brand b", "a.brand_id = b.id").
|
||||||
|
Where("a.status = ?", 1).Find(&productList)
|
||||||
|
return handErr(err), productList
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
package services
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/ahmetb/go-linq/v3"
|
||||||
|
"qteam/app/http/entities"
|
||||||
|
"qteam/app/models/brandmodel"
|
||||||
|
"qteam/app/models/productsmodel"
|
||||||
|
"qteam/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
func VoucherList() (code int, VoucherListResponse entities.VoucherListResponse) {
|
||||||
|
VoucherListResponse.MilkUrl = config.GetConf().YouChu.MilkUrl
|
||||||
|
var BrandData []brandmodel.Brand
|
||||||
|
var VoucherData []productsmodel.MilkProductsList
|
||||||
|
code, BrandData = MilkBrandList()
|
||||||
|
if BrandData != nil {
|
||||||
|
var MilkList []entities.MilkList
|
||||||
|
linq.From(BrandData).SelectT(func(in brandmodel.Brand) (d entities.MilkList) {
|
||||||
|
d.ResponseFromDb(in)
|
||||||
|
return
|
||||||
|
}).ToSlice(&MilkList)
|
||||||
|
VoucherListResponse.MilkList = MilkList
|
||||||
|
}
|
||||||
|
code, VoucherData = MilkProductList()
|
||||||
|
if VoucherData != nil {
|
||||||
|
var MilkVoucherList []entities.MilkVoucherList
|
||||||
|
linq.From(VoucherData).SelectT(func(in productsmodel.MilkProductsList) (d entities.MilkVoucherList) {
|
||||||
|
d.ResponseFromDb(in)
|
||||||
|
return
|
||||||
|
}).ToSlice(&MilkVoucherList)
|
||||||
|
VoucherListResponse.MilkVoucherList = MilkVoucherList
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package services
|
||||||
|
|
||||||
|
import (
|
||||||
|
"qteam/app/constants/errorcode"
|
||||||
|
"qteam/app/utils"
|
||||||
|
)
|
||||||
|
|
||||||
|
func handErr(err error) int {
|
||||||
|
if err != nil {
|
||||||
|
utils.Log(nil, "sys err", err.Error())
|
||||||
|
return errorcode.SystemError
|
||||||
|
} else {
|
||||||
|
return errorcode.Success
|
||||||
|
}
|
||||||
|
}
|
|
@ -36,6 +36,11 @@ type Config struct {
|
||||||
OpenApi OpenApi `toml:"OpenApi"`
|
OpenApi OpenApi `toml:"OpenApi"`
|
||||||
Jwt Jwt `toml:"Jwt"`
|
Jwt Jwt `toml:"Jwt"`
|
||||||
AliOss AliOss `toml:"AliOss"`
|
AliOss AliOss `toml:"AliOss"`
|
||||||
|
YouChu YouChu `toml:"YouChu"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type YouChu struct {
|
||||||
|
MilkUrl string
|
||||||
}
|
}
|
||||||
|
|
||||||
type AliOss struct {
|
type AliOss struct {
|
||||||
|
|
1
go.mod
1
go.mod
|
@ -35,6 +35,7 @@ require (
|
||||||
github.com/KyleBanks/depth v1.2.1 // indirect
|
github.com/KyleBanks/depth v1.2.1 // indirect
|
||||||
github.com/PuerkitoBio/purell v1.1.1 // indirect
|
github.com/PuerkitoBio/purell v1.1.1 // indirect
|
||||||
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
|
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
|
||||||
|
github.com/ahmetb/go-linq/v3 v3.2.0 // indirect
|
||||||
github.com/alibabacloud-go/debug v0.0.0-20190504072949-9472017b5c68 // indirect
|
github.com/alibabacloud-go/debug v0.0.0-20190504072949-9472017b5c68 // indirect
|
||||||
github.com/alibabacloud-go/tea v1.1.17 // indirect
|
github.com/alibabacloud-go/tea v1.1.17 // indirect
|
||||||
github.com/alibabacloud-go/tea-utils v1.4.4 // indirect
|
github.com/alibabacloud-go/tea-utils v1.4.4 // indirect
|
||||||
|
|
2
go.sum
2
go.sum
|
@ -61,6 +61,8 @@ github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/
|
||||||
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c=
|
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c=
|
||||||
github.com/agiledragon/gomonkey/v2 v2.3.1 h1:k+UnUY0EMNYUFUAQVETGY9uUTxjMdnUkP0ARyJS1zzs=
|
github.com/agiledragon/gomonkey/v2 v2.3.1 h1:k+UnUY0EMNYUFUAQVETGY9uUTxjMdnUkP0ARyJS1zzs=
|
||||||
github.com/agiledragon/gomonkey/v2 v2.3.1/go.mod h1:ap1AmDzcVOAz1YpeJ3TCzIgstoaWLA6jbbgxfB4w2iY=
|
github.com/agiledragon/gomonkey/v2 v2.3.1/go.mod h1:ap1AmDzcVOAz1YpeJ3TCzIgstoaWLA6jbbgxfB4w2iY=
|
||||||
|
github.com/ahmetb/go-linq/v3 v3.2.0 h1:BEuMfp+b59io8g5wYzNoFe9pWPalRklhlhbiU3hYZDE=
|
||||||
|
github.com/ahmetb/go-linq/v3 v3.2.0/go.mod h1:haQ3JfOeWK8HpVxMtHHEMPVgBKiYyQ+f1/kLZh/cj9U=
|
||||||
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
||||||
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
||||||
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
|
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
|
||||||
|
|
Loading…
Reference in New Issue