com.snow.auto_monitor/app/services/orders/orders.go

108 lines
2.4 KiB
Go

package orders
import (
"errors"
models "com.snow.auto_monitor/app/models/orders"
promod "com.snow.auto_monitor/app/models/product"
)
func GetLimitStart(limit int, page int) (int, int) {
if limit <= 0 {
limit = 20
}
if page > 0 {
page = (page - 1) * limit
} else {
page = 0
}
return limit, page
}
func GetById(id int64) (res *models.Orders, err error) {
res, _, err = models.GetInstance().GetById(id)
return
}
func Search(id int64,
order_no string,
merchant_id int64,
product_id int64,
device_no string,
out_trade_no string,
recharge_account string,
account_type int64,
status int64,
transfer_status int64,
queue_no int64,
startTime string,
endTime string,
limit int,
page int) (res []*models.Orders, err error) {
limit, page = GetLimitStart(limit, page)
res, err = models.GetInstance().Search(id, order_no, merchant_id, product_id, device_no, out_trade_no,
recharge_account, account_type, status, transfer_status, queue_no,
startTime, endTime, limit, page)
return
}
func CountAll(id int64,
order_no string,
merchant_id int64,
product_id int64,
device_no string,
out_trade_no string,
recharge_account string,
account_type int64,
status int64,
transfer_status int64,
queue_no int64,
startTime string,
endTime string) (res int64, err error) {
res, err = models.GetInstance().CountAll(id, order_no, merchant_id, product_id, device_no, out_trade_no,
recharge_account, account_type, status, transfer_status, queue_no,
startTime, endTime)
return
}
func Create(orders *models.Orders) (affected int64, err error) {
//验证产品是否存在
product, has, err := promod.GetInstance().GetById(orders.ProductId)
if err != nil {
return
}
if !has {
return 0, errors.New("产品不存在")
}
orders.QueueNo = product.QueueNo
affected, err = models.GetInstance().Create(orders)
return
}
func Update(orders *models.Orders) (affected int64, err error) {
affected, err = models.GetInstance().Update(orders)
return
}
func Cancel(id int64) (affected int64, err error) {
affected, err = models.GetInstance().CancelOrder(id)
return
}
func DangerousConfirm(id int64) (affected int64, err error) {
affected, err = models.GetInstance().DangerousConfirm(id)
return
}
func DangerousCancel(id int64) (affected int64, err error) {
affected, err = models.GetInstance().DangerousCancel(id)
return
}
func Delete(id int64) (affected int64, err error) {
affected, err = models.GetInstance().Delete(id)
return
}