This commit is contained in:
parent
bf4e24619d
commit
88b95cb67a
|
@ -1,9 +1,86 @@
|
|||
package console
|
||||
|
||||
import (
|
||||
"PaymentCenter/app/constants/common"
|
||||
"PaymentCenter/app/data"
|
||||
"PaymentCenter/app/http/entities"
|
||||
"PaymentCenter/app/models/ordersmodel"
|
||||
"PaymentCenter/app/utils"
|
||||
"github.com/qit-team/snow-core/command"
|
||||
"strconv"
|
||||
"time"
|
||||
"xorm.io/builder"
|
||||
)
|
||||
|
||||
func RegisterCommand(c *command.Command) {
|
||||
c.AddFunc("test", test)
|
||||
c.AddFunc("closeOrder", closeOrder)
|
||||
}
|
||||
|
||||
// 关闭长时间支付中的订单
|
||||
func closeOrder() {
|
||||
var now = time.Now().Format(time.DateTime)
|
||||
utils.Log(nil, "关闭订单", now)
|
||||
// 查询未支付的订单
|
||||
repo := data.NewOrderRepo(ordersmodel.GetInstance().GetDb())
|
||||
// 拼接条件
|
||||
cond := builder.NewCond()
|
||||
cond = cond.And(builder.Eq{"status": common.ORDER_STATUS_PAYING}, builder.Lt{"create_time": time.Now().Add(-time.Hour)})
|
||||
|
||||
order := make([]ordersmodel.Orders, 0)
|
||||
total, err := repo.OrderList(cond, entities.PageRequest{}, &order)
|
||||
if err != nil {
|
||||
utils.Log(nil, "关闭订单,查询未支付订单失败", err)
|
||||
} else if total > 0 {
|
||||
orderIds := make([]int64, 0)
|
||||
for _, v := range order {
|
||||
orderIds = append(orderIds, v.Id)
|
||||
}
|
||||
// 修改订单状态为关闭
|
||||
cond = builder.NewCond()
|
||||
cond = cond.And(builder.In("id", orderIds))
|
||||
_, err = repo.OrderUpdate(&ordersmodel.Orders{Status: common.ORDER_STATUS_CLOSE}, cond, "status")
|
||||
if err != nil {
|
||||
utils.Log(nil, "关闭订单,修改订单状态失败", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
utils.Log(nil, "关闭订单,修改订单状态成功", "count="+strconv.Itoa(len(order)))
|
||||
}
|
||||
|
||||
// 定时查询支付中的订单, 主动查询订单支付状态
|
||||
func queryOrder() {
|
||||
var now = time.Now().Format(time.DateTime)
|
||||
utils.Log(nil, "主动查询订单支付状态", now)
|
||||
// 查询未支付的订单
|
||||
repo := data.NewOrderRepo(ordersmodel.GetInstance().GetDb())
|
||||
// 拼接条件
|
||||
cond := builder.NewCond()
|
||||
cond = cond.And(builder.Eq{"status": common.ORDER_STATUS_PAYING}, builder.Gt{"create_time": time.Now().Add(-time.Second)})
|
||||
order := make([]ordersmodel.Orders, 0)
|
||||
total, err := repo.OrderList(cond, entities.PageRequest{}, &order)
|
||||
if err != nil {
|
||||
utils.Log(nil, "主动查询订单支付状态,查询未付中订单失败", err)
|
||||
return
|
||||
} else if total > 0 {
|
||||
// 发起查询上游支付
|
||||
for _, v := range order {
|
||||
go func(order ordersmodel.Orders) {
|
||||
// 发起查询
|
||||
utils.Log(nil, "主动查询订单支付状态,发起查询", order.Id)
|
||||
// 解析上游结果
|
||||
|
||||
// 修改订单状态
|
||||
}(v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 回调下游
|
||||
func callbackOrder() {
|
||||
var now = time.Now().Format(time.DateTime)
|
||||
utils.Log(nil, "回调下游", now)
|
||||
// 查询回调失败的订单
|
||||
|
||||
// 发起回调
|
||||
}
|
||||
|
|
|
@ -11,5 +11,7 @@ import (
|
|||
func RegisterSchedule(c *cron.Cron) {
|
||||
//c.AddFunc("0 30 * * * *", test)
|
||||
//c.AddFunc("@hourly", test)
|
||||
c.AddFunc("@every 10s", test)
|
||||
//c.AddFunc("@every 10s", test)
|
||||
c.AddFunc("@every 60s", closeOrder)
|
||||
c.AddFunc("@every 10s", queryOrder)
|
||||
}
|
||||
|
|
|
@ -20,4 +20,11 @@ const (
|
|||
ADMIN_USER_ID = "User-Id"
|
||||
ADMIN_USER_NAME = "User-Name"
|
||||
ADMIN_USER_INCLUDEUSERS = "Include-Users"
|
||||
|
||||
// '订单状态,待支付、支付中、支付成功、支付失败、订单关闭',
|
||||
ORDER_STATUS_WAITPAY = 1
|
||||
ORDER_STATUS_PAYING = 2
|
||||
ORDER_STATUS_PAYED = 3
|
||||
ORDER_STATUS_FAILED = 4
|
||||
ORDER_STATUS_CLOSE = 5
|
||||
)
|
||||
|
|
|
@ -37,3 +37,7 @@ func (m *AppRepo) AppDelete(app *appmodel.App, conn builder.Cond) (int64, error)
|
|||
func (m *AppRepo) AppUpdate(app *appmodel.App, conn builder.Cond, columns ...string) (int64, error) {
|
||||
return m.repo.Where(conn).MustCols(columns...).Update(app)
|
||||
}
|
||||
|
||||
func (m *AppRepo) AppGet(app *appmodel.App, conn builder.Cond) (bool, error) {
|
||||
return m.repo.Where(conn).Get(app)
|
||||
}
|
||||
|
|
|
@ -25,15 +25,19 @@ func (m *PayChannelRepo) PayChannelList(conn builder.Cond, pageFilter entities.P
|
|||
return repo.Desc("create_time").FindAndCount(payChannelList)
|
||||
}
|
||||
|
||||
func (m *PayChannelRepo) PayChannelInsertOne(merchant *paychannelmodel.PayChannel) (int64, error) {
|
||||
return m.repo.InsertOne(merchant)
|
||||
func (m *PayChannelRepo) PayChannelInsertOne(payChannel *paychannelmodel.PayChannel) (int64, error) {
|
||||
return m.repo.InsertOne(payChannel)
|
||||
}
|
||||
|
||||
func (m *PayChannelRepo) PayChannelDelete(merchant *paychannelmodel.PayChannel, conn builder.Cond) (int64, error) {
|
||||
return m.repo.Where(conn).Delete(merchant)
|
||||
func (m *PayChannelRepo) PayChannelDelete(payChannel *paychannelmodel.PayChannel, conn builder.Cond) (int64, error) {
|
||||
return m.repo.Where(conn).Delete(payChannel)
|
||||
}
|
||||
|
||||
// columns 参数为要更新的字段,即使为空
|
||||
func (m *PayChannelRepo) PayChannelUpdate(merchant *paychannelmodel.PayChannel, conn builder.Cond, columns ...string) (int64, error) {
|
||||
return m.repo.Where(conn).MustCols(columns...).Update(merchant)
|
||||
func (m *PayChannelRepo) PayChannelUpdate(payChannel *paychannelmodel.PayChannel, conn builder.Cond, columns ...string) (int64, error) {
|
||||
return m.repo.Where(conn).MustCols(columns...).Update(payChannel)
|
||||
}
|
||||
|
||||
func (m *PayChannelRepo) PayChannelGet(payChannel *paychannelmodel.PayChannel, conn builder.Cond) (bool, error) {
|
||||
return m.repo.Where(conn).Get(payChannel)
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
func MerchantList(c *gin.Context) {
|
||||
req, _ := controllers.GetRequest(c).(*backend.MerchantListRequest)
|
||||
req.SetDefault()
|
||||
req.GroupInfo = controllers.GetAdminUserIncludeUsers(c)
|
||||
merchantList, total, code := services.MerchantList(*req)
|
||||
|
||||
result := make([]backend.MerchantResponse, 0, len(merchantList))
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package controllers
|
||||
|
||||
import (
|
||||
"PaymentCenter/app/constants/common"
|
||||
"PaymentCenter/app/utils"
|
||||
"PaymentCenter/config"
|
||||
"bytes"
|
||||
|
@ -17,6 +18,7 @@ import (
|
|||
"net/http"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"strconv"
|
||||
|
||||
"PaymentCenter/app/constants/errorcode"
|
||||
|
||||
|
@ -207,3 +209,24 @@ func phoneValidation(fl validator.FieldLevel) bool {
|
|||
reg := regexp.MustCompile(phoneRegex)
|
||||
return reg.MatchString(phone)
|
||||
}
|
||||
|
||||
// 管理后台,获取用户id
|
||||
func GetAdminId(c *gin.Context) int {
|
||||
userIdStr, _ := c.Get(common.ADMIN_USER_ID)
|
||||
if userIdStr != nil {
|
||||
var userId, _ = strconv.Atoi(userIdStr.(string))
|
||||
return userId
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
// 获取对应数据权限中拥有用户数据ID
|
||||
func GetAdminUserIncludeUsers(c *gin.Context) string {
|
||||
name, _ := c.Get(common.ADMIN_USER_INCLUDEUSERS)
|
||||
if name != nil {
|
||||
var temp, _ = name.(string)
|
||||
return temp
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
|
|
@ -6,7 +6,8 @@ import (
|
|||
)
|
||||
|
||||
type AppListRequest struct {
|
||||
MerchantId int64 `json:"merchant_id"`
|
||||
Id int64 `json:"id" form:"id"`
|
||||
MerchantId int64 `json:"merchant_id" form:"merchant_id" validate:"required" label:"商户ID"`
|
||||
entities.PageRequest
|
||||
}
|
||||
|
||||
|
|
|
@ -7,9 +7,10 @@ import (
|
|||
|
||||
type MerchantListRequest struct {
|
||||
entities.PageRequest
|
||||
Name string `form:"name"`
|
||||
Contact string `form:"contact"`
|
||||
Phone string `form:"phone"`
|
||||
Name string `form:"name"`
|
||||
Contact string `form:"contact"`
|
||||
Phone string `form:"phone"`
|
||||
GroupInfo string
|
||||
}
|
||||
|
||||
type MerchantResponse struct {
|
||||
|
@ -35,6 +36,7 @@ type MerchantCreateRequest struct {
|
|||
Contact string `json:"contact" validate:"required" label:"联系人"`
|
||||
Phone string `json:"phone" validate:"required,phoneValidation" label:"联系电话"`
|
||||
Remark string `json:"remark" label:"备注"`
|
||||
Creator int
|
||||
}
|
||||
|
||||
func (m *MerchantCreateRequest) RequestToDb() (db merchantmodel.Merchant) {
|
||||
|
@ -42,6 +44,7 @@ func (m *MerchantCreateRequest) RequestToDb() (db merchantmodel.Merchant) {
|
|||
db.Contact = m.Contact
|
||||
db.Phone = m.Phone
|
||||
db.Remark = m.Remark
|
||||
db.Creator = m.Creator
|
||||
return db
|
||||
}
|
||||
|
||||
|
|
|
@ -86,7 +86,8 @@ func (p *PayChannelCreateRequest) RequestToDb() (db paychannelmodel.PayChannel,
|
|||
}
|
||||
|
||||
type PayChannelListRequest struct {
|
||||
MerchantId int64 `json:"merchant_id"`
|
||||
Id int64 `json:"id" form:"id" `
|
||||
MerchantId int64 `json:"merchant_id" form:"merchant_id" validate:"required" label:"商户ID"`
|
||||
entities.PageRequest
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ type Merchant struct {
|
|||
Contact string `xorm:"'contact' varchar(128)"`
|
||||
Phone string `xorm:"'phone' varchar(11)"`
|
||||
Remark string `xorm:"'remark' varchar(1024)"`
|
||||
Creator int `xorm:"'creator' int(10)"`
|
||||
CreateTime time.Time `xorm:"'create_time' datetime created"`
|
||||
UpdateTime time.Time `xorm:"'update_time' timestamp updated"`
|
||||
DeleteTime time.Time `xorm:"'delete_time' timestamp deleted"`
|
||||
|
|
|
@ -18,6 +18,9 @@ func AppList(req backend.AppListRequest) (result []appmodel.App, total int64, co
|
|||
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)
|
||||
|
@ -78,3 +81,19 @@ func AppDelete(req entities.IdRequest) (code int) {
|
|||
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
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"PaymentCenter/app/http/entities"
|
||||
"PaymentCenter/app/http/entities/backend"
|
||||
"PaymentCenter/app/models/merchantmodel"
|
||||
"strings"
|
||||
"xorm.io/builder"
|
||||
)
|
||||
|
||||
|
@ -22,6 +23,9 @@ func MerchantList(req backend.MerchantListRequest) (result []merchantmodel.Merch
|
|||
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)
|
||||
|
|
|
@ -17,6 +17,9 @@ func PayChannelList(req backend.PayChannelListRequest) (result []paychannelmodel
|
|||
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
|
||||
paychannelList := make([]paychannelmodel.PayChannel, 0)
|
||||
|
@ -71,3 +74,21 @@ func PayChannelDelete(req entities.IdRequest) (code int) {
|
|||
code = handErr(err)
|
||||
return
|
||||
}
|
||||
|
||||
func PayChannelGet(payChannel *paychannelmodel.PayChannel) (code int) {
|
||||
repo := data.NewPayChannelRepo(paychannelmodel.GetInstance().GetDb())
|
||||
|
||||
// 拼接查询条件
|
||||
conn := builder.NewCond()
|
||||
conn = conn.And(builder.Eq{"Id": payChannel.Id})
|
||||
has, err := repo.PayChannelGet(payChannel, conn)
|
||||
if err != nil {
|
||||
return handErr(err)
|
||||
}
|
||||
if !has {
|
||||
return errorcode.PayChannelNotFound
|
||||
}
|
||||
|
||||
code = errorcode.Success
|
||||
return
|
||||
}
|
||||
|
|
|
@ -4,11 +4,10 @@ import (
|
|||
"PaymentCenter/app/jobs"
|
||||
"PaymentCenter/app/jobs/basejob"
|
||||
"PaymentCenter/config"
|
||||
"github.com/qit-team/snow-core/log/accesslogger"
|
||||
|
||||
"github.com/qit-team/snow-core/db"
|
||||
"github.com/qit-team/snow-core/kernel/close"
|
||||
"github.com/qit-team/snow-core/kernel/container"
|
||||
"github.com/qit-team/snow-core/log/accesslogger"
|
||||
"github.com/qit-team/snow-core/log/logger"
|
||||
"github.com/qit-team/snow-core/redis"
|
||||
)
|
||||
|
@ -26,6 +25,8 @@ func Bootstrap(conf *config.Config) (err error) {
|
|||
//注册db服务
|
||||
//第一个参数为注入别名,第二个参数为配置,第三个参数可选为是否懒加载
|
||||
err = db.Pr.Register(db.SingletonMain, conf.Db)
|
||||
//cacher := caches.NewLRUCacher2(caches.NewMemoryStore(), time.Hour, 1000)
|
||||
//db.GetDb().SetDefaultCacher(cacher)
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue