100 lines
2.4 KiB
Go
100 lines
2.4 KiB
Go
package services
|
||
|
||
import (
|
||
"PaymentCenter/app/constants/errorcode"
|
||
"PaymentCenter/app/data"
|
||
"PaymentCenter/app/http/entities"
|
||
"PaymentCenter/app/http/entities/backend"
|
||
"PaymentCenter/app/models/appmodel"
|
||
"PaymentCenter/app/models/merchantmodel"
|
||
"PaymentCenter/app/models/paychannelmodel"
|
||
"xorm.io/builder"
|
||
)
|
||
|
||
func AppList(req backend.AppListRequest) (result []appmodel.App, total int64, code int) {
|
||
repo := data.NewAppRepo(paychannelmodel.GetInstance().GetDb())
|
||
// 拼接查询条件
|
||
conn := builder.NewCond()
|
||
if req.MerchantId > 0 {
|
||
conn = conn.And(builder.Eq{"merchant_id": req.MerchantId})
|
||
}
|
||
if req.Id > 0 {
|
||
conn = conn.And(builder.Eq{"id": req.Id})
|
||
}
|
||
|
||
// 调用repo
|
||
appList := make([]appmodel.App, 0)
|
||
count, err := repo.AppList(conn, req.PageRequest, &appList)
|
||
code = handErr(err)
|
||
return appList, count, code
|
||
}
|
||
|
||
func AppCreate(app *appmodel.App) (code int) {
|
||
db := paychannelmodel.GetInstance().GetDb()
|
||
repo := data.NewAppRepo(db)
|
||
merchantRepo := data.NewMerchantRepo(db)
|
||
// 拼接查询条件
|
||
conn := builder.NewCond()
|
||
conn = conn.And(builder.Eq{"id": app.MerchantId})
|
||
merchant := merchantmodel.Merchant{}
|
||
has, err := merchantRepo.MerchantDetail(&merchant, conn)
|
||
if err != nil {
|
||
return handErr(err)
|
||
}
|
||
if !has {
|
||
return errorcode.MerchantNotFound
|
||
}
|
||
|
||
_, err = repo.AppInsertOne(app)
|
||
code = handErr(err)
|
||
return
|
||
}
|
||
|
||
func AppUpdate(app *appmodel.App) (code int) {
|
||
var err error
|
||
db := paychannelmodel.GetInstance().GetDb()
|
||
repo := data.NewAppRepo(db)
|
||
|
||
// 拼接查询条件
|
||
conn := builder.NewCond()
|
||
conn = conn.And(builder.Eq{"Id": app.Id})
|
||
if app.AppName != "" {
|
||
// 编辑页面更新,备注和白名单IP可更新为空
|
||
_, err = repo.AppUpdate(app, conn, "app_remark", "white_ip")
|
||
} else {
|
||
_, err = repo.AppUpdate(app, conn)
|
||
}
|
||
|
||
code = handErr(err)
|
||
return
|
||
}
|
||
|
||
func AppDelete(req entities.IdRequest) (code int) {
|
||
repo := data.NewAppRepo(paychannelmodel.GetInstance().GetDb())
|
||
|
||
// 拼接查询条件
|
||
conn := builder.NewCond()
|
||
conn = conn.And(builder.Eq{"Id": req.Id})
|
||
m := appmodel.App{Id: req.Id}
|
||
_, err := repo.AppDelete(&m, conn)
|
||
|
||
code = handErr(err)
|
||
return
|
||
}
|
||
|
||
func AppGet(app *appmodel.App) (code int) {
|
||
repo := data.NewAppRepo(appmodel.GetInstance().GetDb())
|
||
// 拼接查询条件
|
||
conn := builder.NewCond()
|
||
conn = conn.And(builder.Eq{"id": app.Id})
|
||
has, err := repo.AppGet(app, conn)
|
||
if err != nil {
|
||
return handErr(err)
|
||
}
|
||
if !has {
|
||
return errorcode.AppNotFound
|
||
}
|
||
code = errorcode.Success
|
||
return
|
||
}
|