PaymentCenter/app/services/merchant.go

68 lines
1.8 KiB
Go

package services
import (
"PaymentCenter/app/data"
"PaymentCenter/app/http/entities"
"PaymentCenter/app/http/entities/backend"
"PaymentCenter/app/models/merchantmodel"
"strings"
"xorm.io/builder"
)
// MerchantList 商户列表
func MerchantList(req backend.MerchantListRequest) (result []merchantmodel.Merchant, total int64, code int) {
repo := data.NewMerchantRepo(merchantmodel.GetInstance().GetDb())
// 拼接查询条件
conn := builder.NewCond()
if req.Name != "" {
conn = conn.And(builder.Like{"name", req.Name})
}
if req.Contact != "" {
conn = conn.And(builder.Like{"contact", req.Contact})
}
if req.Phone != "" {
conn = conn.And(builder.Like{"phone", req.Phone})
}
if req.GroupInfo != "" {
conn = conn.And(builder.In("creator", strings.Split(req.GroupInfo, ",")))
}
// 调用repo
merchantList := make([]merchantmodel.Merchant, 0)
count, err := repo.MerchantList(conn, req.PageRequest, &merchantList)
code = handErr(err)
return merchantList, count, code
}
func MerchantCreate(merchant *merchantmodel.Merchant) (code int) {
repo := data.NewMerchantRepo(merchantmodel.GetInstance().GetDb())
_, err := repo.MerchantInsertOne(merchant)
code = handErr(err)
return
}
func MerchantUpdate(merchant *merchantmodel.Merchant) (code int) {
repo := data.NewMerchantRepo(merchantmodel.GetInstance().GetDb())
// 拼接查询条件
conn := builder.NewCond()
conn = conn.And(builder.Eq{"Id": merchant.Id})
_, err := repo.MerchantUpdate(merchant, conn, "remark")
code = handErr(err)
return
}
func MerchantDelete(req entities.IdRequest) (code int) {
repo := data.NewMerchantRepo(merchantmodel.GetInstance().GetDb())
// 拼接查询条件
conn := builder.NewCond()
conn = conn.And(builder.Eq{"Id": req.Id})
m := merchantmodel.Merchant{Id: req.Id}
_, err := repo.MerchantDelete(&m, conn)
code = handErr(err)
return
}