feat(1.0.4):增加订单日志接口
parent
a925ad776d
commit
b95732f07d
@ -0,0 +1,56 @@
|
||||
package order
|
||||
|
||||
import (
|
||||
"cls/internal/domain/coupon"
|
||||
price2 "cls/internal/domain/price"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCreateOrder(t *testing.T) {
|
||||
price := &price2.Price{
|
||||
ID: 0,
|
||||
TargetID: 2000798,
|
||||
Type: 1,
|
||||
Amount: 11,
|
||||
OneMonthPrice: 0,
|
||||
ThreeMonthsPrice: 0,
|
||||
SixMonthsPrice: 0,
|
||||
OneYearPrice: 0,
|
||||
FirstMontDiscount: 0,
|
||||
Discount: 0.1,
|
||||
}
|
||||
|
||||
c := coupon.Coupon{Status: coupon.CouponStatusNormal, MinAmount: 2, Value: 2}
|
||||
t.Log(c.CanUse(price.GetFinalAmount()))
|
||||
|
||||
//v := price.GetFinalAmount()
|
||||
//t.Log("0.1", price.GetFinalAmountWitCoupon(1))
|
||||
t.Log("0.1", price.GetFinalAmount())
|
||||
price.Discount = 0.2
|
||||
//t.Log("0.2", price.GetFinalAmountWitCoupon(1))
|
||||
t.Log("0.2", price.GetFinalAmount())
|
||||
price.Discount = 0.3
|
||||
//t.Log("0.3", price.GetFinalAmountWitCoupon(1))
|
||||
t.Log("0.3", price.GetFinalAmount())
|
||||
price.Discount = 0.4
|
||||
t.Log("0.4", price.GetFinalAmountWitCoupon(1))
|
||||
//t.Log("0.4", price.GetFinalAmount())
|
||||
price.Discount = 0.5
|
||||
t.Log("0.5", price.GetFinalAmountWitCoupon(1))
|
||||
//t.Log("0.5", price.GetFinalAmount())
|
||||
price.Discount = 0.6
|
||||
//t.Log("0.6", price.GetFinalAmountWitCoupon(1))
|
||||
t.Log("0.6", price.GetFinalAmount())
|
||||
price.Discount = 0.7
|
||||
//t.Log("0.7", price.GetFinalAmountWitCoupon(1))
|
||||
t.Log("0.7", price.GetFinalAmount())
|
||||
price.Discount = 0.8
|
||||
//t.Log("0.8", price.GetFinalAmountWitCoupon(1))
|
||||
t.Log("0.8", price.GetFinalAmount())
|
||||
price.Discount = 0.9
|
||||
//t.Log("0.9", price.GetFinalAmountWitCoupon(1))
|
||||
t.Log("0.9", price.GetFinalAmount())
|
||||
price.Discount = 1
|
||||
//t.Log("1", price.GetFinalAmountWitCoupon(1))
|
||||
t.Log("1", price.GetFinalAmount())
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package run_log
|
||||
|
||||
import "time"
|
||||
|
||||
type RunLogType uint8
|
||||
|
||||
const (
|
||||
LogTypeOrder = iota + 1
|
||||
LogTypePayment
|
||||
LogTypePurchase
|
||||
)
|
||||
|
||||
type RunLog struct {
|
||||
Id int64
|
||||
LogType RunLogType
|
||||
OrderNo string
|
||||
Remark string
|
||||
Info string `xorm:"varchar(5000)"`
|
||||
Created time.Time `xorm:"created"`
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package run_log
|
||||
|
||||
type RunLogRepository interface {
|
||||
Log(log *RunLog)
|
||||
LogOrderInfo(orderNo string, info string, remark ...string)
|
||||
LogPaymentInfo(orderNo string, info string, remark ...string)
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package run_log
|
||||
|
||||
import (
|
||||
"cls/internal/domain/run_log"
|
||||
"cls/pkg/logger"
|
||||
"cls/pkg/xorm_engine"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type RunLogRepositoryORM struct {
|
||||
engine *xorm_engine.Engine
|
||||
log logger.Logger
|
||||
}
|
||||
|
||||
func NewRunLogRepositoryORM(engine *xorm_engine.Engine, log logger.New) run_log.RunLogRepository {
|
||||
return &RunLogRepositoryORM{engine, log("cls:persistence:run_log")}
|
||||
}
|
||||
|
||||
var _ run_log.RunLogRepository = (*RunLogRepositoryORM)(nil)
|
||||
|
||||
func (r *RunLogRepositoryORM) Log(log *run_log.RunLog) {
|
||||
_, err := r.engine.Insert(log)
|
||||
if err != nil {
|
||||
r.log.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (r *RunLogRepositoryORM) LogOrderInfo(orderNo string, info string, remark ...string) {
|
||||
_, err := r.engine.Insert(&run_log.RunLog{
|
||||
LogType: run_log.LogTypeOrder,
|
||||
OrderNo: orderNo,
|
||||
Info: info,
|
||||
Remark: strings.Join(remark, "|"),
|
||||
})
|
||||
if err != nil {
|
||||
r.log.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (r *RunLogRepositoryORM) LogPaymentInfo(orderNo string, info string, remark ...string) {
|
||||
_, err := r.engine.Insert(&run_log.RunLog{
|
||||
LogType: run_log.LogTypePayment,
|
||||
OrderNo: orderNo,
|
||||
Info: info,
|
||||
Remark: strings.Join(remark, "|"),
|
||||
})
|
||||
if err != nil {
|
||||
r.log.Error(err)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue