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

108 lines
2.4 KiB
Go
Raw Normal View History

2024-07-12 18:11:21 +08:00
package orders
import (
2024-09-10 14:26:07 +08:00
"errors"
2024-07-12 18:11:21 +08:00
models "com.snow.auto_monitor/app/models/orders"
2024-09-10 14:26:07 +08:00
promod "com.snow.auto_monitor/app/models/product"
2024-07-12 18:11:21 +08:00
)
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,
2024-08-07 13:46:10 +08:00
device_no string,
2024-07-12 18:11:21 +08:00
out_trade_no string,
recharge_account string,
account_type int64,
status int64,
transfer_status int64,
2024-09-10 14:26:07 +08:00
queue_no int64,
2024-07-12 18:11:21 +08:00
startTime string,
endTime string,
limit int,
page int) (res []*models.Orders, err error) {
limit, page = GetLimitStart(limit, page)
2024-08-07 13:46:10 +08:00
res, err = models.GetInstance().Search(id, order_no, merchant_id, product_id, device_no, out_trade_no,
2024-09-10 14:26:07 +08:00
recharge_account, account_type, status, transfer_status, queue_no,
2024-07-12 18:11:21 +08:00
startTime, endTime, limit, page)
return
}
func CountAll(id int64,
order_no string,
merchant_id int64,
product_id int64,
2024-08-07 13:46:10 +08:00
device_no string,
2024-07-12 18:11:21 +08:00
out_trade_no string,
recharge_account string,
account_type int64,
status int64,
transfer_status int64,
2024-09-10 14:26:07 +08:00
queue_no int64,
2024-07-12 18:11:21 +08:00
startTime string,
endTime string) (res int64, err error) {
2024-08-21 10:18:34 +08:00
res, err = models.GetInstance().CountAll(id, order_no, merchant_id, product_id, device_no, out_trade_no,
2024-09-10 14:26:07 +08:00
recharge_account, account_type, status, transfer_status, queue_no,
2024-07-12 18:11:21 +08:00
startTime, endTime)
return
}
func Create(orders *models.Orders) (affected int64, err error) {
2024-09-10 14:26:07 +08:00
//验证产品是否存在
product, has, err := promod.GetInstance().GetById(orders.ProductId)
if err != nil {
return
}
if !has {
return 0, errors.New("产品不存在")
}
orders.QueueNo = product.QueueNo
2024-07-12 18:11:21 +08:00
affected, err = models.GetInstance().Create(orders)
return
}
func Update(orders *models.Orders) (affected int64, err error) {
affected, err = models.GetInstance().Update(orders)
return
}
2024-07-26 15:09:57 +08:00
func Cancel(id int64) (affected int64, err error) {
affected, err = models.GetInstance().CancelOrder(id)
return
}
2024-08-30 15:16:16 +08:00
func DangerousConfirm(id int64) (affected int64, err error) {
affected, err = models.GetInstance().DangerousConfirm(id)
return
}
2024-08-21 19:50:25 +08:00
func DangerousCancel(id int64) (affected int64, err error) {
affected, err = models.GetInstance().DangerousCancel(id)
return
}
2024-07-12 18:11:21 +08:00
func Delete(id int64) (affected int64, err error) {
affected, err = models.GetInstance().Delete(id)
return
}