You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
1.3 KiB
68 lines
1.3 KiB
package order
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/jinzhu/gorm"
|
|
"recook/internal/back"
|
|
"recook/internal/dbc"
|
|
"recook/internal/model/order"
|
|
"recook/internal/model/user"
|
|
"recook/tools"
|
|
)
|
|
|
|
type createInvoiceParam struct {
|
|
UserID uint `json:"userId"`
|
|
OrderID uint `json:"orderId"`
|
|
InvoiceID uint `json:"invoiceId"`
|
|
}
|
|
|
|
/*申请开票*/
|
|
func CreateInvoice(c *gin.Context) {
|
|
var p createInvoiceParam
|
|
if err := tools.ParseParams(&p, c); err != nil {
|
|
back.Fail(c, err.Error())
|
|
return
|
|
}
|
|
|
|
var one order.Invoice
|
|
if err := dbc.DB.First(&one, "order_id = ?", p.OrderID).Error; err != nil && !gorm.IsRecordNotFoundError(err) {
|
|
back.Err(c, err.Error())
|
|
return
|
|
}
|
|
|
|
if one.ID > 0 {
|
|
back.Fail(c, "请勿重复申请")
|
|
return
|
|
}
|
|
|
|
var myInvoice user.Invoice
|
|
dbc.DB.First(&myInvoice, p.InvoiceID)
|
|
|
|
orderInvoice := order.Invoice{
|
|
OrderID: p.OrderID,
|
|
Type: myInvoice.Type,
|
|
Title: myInvoice.Title,
|
|
TaxNo: myInvoice.TaxNo,
|
|
}
|
|
|
|
tx := dbc.DB.Begin()
|
|
{
|
|
if err := dbc.DB.Create(&orderInvoice).Error; err != nil {
|
|
back.Err(c, err.Error())
|
|
tx.Rollback()
|
|
return
|
|
}
|
|
|
|
if err := tx.Model(&order.Information{ID: p.OrderID}).Updates(order.Information{
|
|
InvoiceStatus: 1,
|
|
}).Error; err != nil {
|
|
back.Err(c, err.Error())
|
|
tx.Rollback()
|
|
return
|
|
}
|
|
}
|
|
tx.Commit()
|
|
|
|
back.Suc(c, "", &orderInvoice)
|
|
}
|