|
|
package goods
|
|
|
|
|
|
import (
|
|
|
"github.com/golangkit/formatime"
|
|
|
"github.com/shopspring/decimal"
|
|
|
"recook/internal/v2/lib/db"
|
|
|
)
|
|
|
|
|
|
type RecookBill struct {
|
|
|
ID uint `gorm:"column:id;primary_key" json:"id"`
|
|
|
UID uint `gorm:"column:uid;" json:"uid"`
|
|
|
Fpqqlsh string `gorm:"column:fpqqlsh;" json:"fpqqlsh"`
|
|
|
Status int `gorm:"column:status;" json:"status"`
|
|
|
Buyername string `gorm:"column:buyername;" json:"buyername"`
|
|
|
Taxnum string `gorm:"column:taxnum;" json:"taxnum"`
|
|
|
Address string `gorm:"column:address;" json:"address"`
|
|
|
Telephone string `gorm:"column:telephone;" json:"telephone"`
|
|
|
Phone string `gorm:"column:phone;" json:"phone"`
|
|
|
Email string `gorm:"column:email;" json:"email"`
|
|
|
Account string `gorm:"column:account;" json:"account"`
|
|
|
Content string `gorm:"column:content;" json:"content"`
|
|
|
Message string `gorm:"column:message;" json:"message"`
|
|
|
Ctime formatime.Second `gorm:"column:ctime;" json:"ctime"`
|
|
|
Price decimal.Decimal `gorm:"column:price;" json:"pice"`
|
|
|
Fail string `gorm:"column:fail;" json:"fail"`
|
|
|
}
|
|
|
|
|
|
// TableName sets the insert table name for this struct type
|
|
|
func (r *RecookBill) TableName() string {
|
|
|
return "recook_order_goods_bill"
|
|
|
}
|
|
|
|
|
|
//@title 用户申请开票的表
|
|
|
type RecookInvoiceApplyModel struct {
|
|
|
db.BaseModel
|
|
|
Id int `gorm:"column:id;primary_key" json:"id"` //表id关键
|
|
|
UserId int `gorm:"column:user_id" json:"user_id"` //购买者id
|
|
|
OrderId uint `gorm:"column:order_id" json:"order_id"` //订单id
|
|
|
BuyerName string `gorm:"column:buyer_name" json:"buyer_name"` //抬头名称
|
|
|
TaxNum string `gorm:"column:tax_num" json:"tax_num"` //购方税号
|
|
|
Address string `gorm:"column:address" json:"address"` //公司地址
|
|
|
Telephone string `gorm:"column:telephone" json:"telephone"` //公司电话
|
|
|
Phone string `gorm:"column:phone" json:"phone"` //购方手机
|
|
|
Email string `gorm:"column:email" json:"email"` //推送邮箱
|
|
|
Account string `gorm:"column:account" json:"account"` //银行账号
|
|
|
Message string `gorm:"column:message" json:"message"` //备注
|
|
|
TotalAmount decimal.Decimal `gorm:"column:total_amount" json:"total_amount"` //订单总金额
|
|
|
InvoiceStatus int `gorm:"column:invoice_status" json:"invoice_status"` //开票状态,1:待开票 2:开票异常 3:开票中 4:开票失败 5:开票成功
|
|
|
Fpqqlsh string `gorm:"column:fpqqlsh" json:"fpqqlsh"` //流水号
|
|
|
Ctime formatime.Second `gorm:"column:ctime" json:"ctime"` //申请时间
|
|
|
FailReasons string `gorm:"column:fail_reasons" json:"fail_reasons"` //失败原因
|
|
|
CtimeInvoice formatime.Second `gorm:"column:ctime_invoice" json:"ctime_invoice"` //开票时间
|
|
|
InvoiceUrl string `gorm:"column:invoice_url" json:"invoice_url"` //发票地址
|
|
|
|
|
|
}
|
|
|
|
|
|
//结构体对应表名
|
|
|
func (r *RecookInvoiceApplyModel) TableName() string {
|
|
|
return "recook_invoice_apply"
|
|
|
}
|
|
|
|
|
|
//通过userId来获取
|
|
|
func (r *RecookInvoiceApplyModel) FindByUid(uid uint) (rest []RecookInvoiceApplyModel) {
|
|
|
r.GetDb().Model(&RecookInvoiceApplyModel{}).Order("ctime desc").Find(&rest, "user_id=?", uid)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//查询状态为3,开票中的订单
|
|
|
func (r *RecookInvoiceApplyModel) NeedInvoice() (rest []RecookInvoiceApplyModel) {
|
|
|
r.GetDb().Model(&RecookInvoiceApplyModel{}).Where("invoice_status=3").Find(&rest)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//开票成功 ,invoice_status的状态变成5 传入order_id
|
|
|
func (r *RecookInvoiceApplyModel) Suc(oid uint64, url string) {
|
|
|
r.GetDb().Model(&RecookInvoiceApplyModel{}).Where("order_id=?", oid).Updates(&RecookInvoiceApplyModel{
|
|
|
InvoiceStatus: 5,
|
|
|
InvoiceUrl: url,
|
|
|
})
|
|
|
}
|
|
|
|
|
|
//开票失败,invoice_status==4,and set fail message
|
|
|
func (r *RecookInvoiceApplyModel) Fail(oid uint64, fail string) {
|
|
|
r.GetDb().Model(&RecookInvoiceApplyModel{}).Where("order_id=?", oid).Updates(&RecookInvoiceApplyModel{
|
|
|
InvoiceStatus: 4,
|
|
|
FailReasons: fail,
|
|
|
})
|
|
|
}
|
|
|
|
|
|
//新增
|
|
|
func (r *RecookInvoiceApplyModel) Create(p *RecookInvoiceApplyModel) {
|
|
|
r.GetDb().Model(&RecookInvoiceApplyModel{}).Create(&p)
|
|
|
}
|
|
|
|
|
|
//通过订单查询
|
|
|
func (r *RecookInvoiceApplyModel) FindByOrderId(by uint) (rest RecookInvoiceApplyModel) {
|
|
|
r.GetDb().Model(&RecookInvoiceApplyModel{}).First(&rest, "order_id=?", by)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//where,多条件查询 获取开票正确并且多条件
|
|
|
func (r *RecookInvoiceApplyModel) GetSuc(sql string, args []interface{}, size uint, num uint) (rest []RecookInvoiceApplyModel) {
|
|
|
r.GetDb().Model(&RecookInvoiceApplyModel{}).Where(sql, args...).Limit(size).Offset((num - 1) * size).Order("ctime desc").Find(&rest)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//where 条件查询
|
|
|
func (r *RecookInvoiceApplyModel) FindAllInvoice(query string, by []interface{}, size uint, num uint) (rest []RecookInvoiceApplyModel) {
|
|
|
r.GetDb().Model(&InvoiceTitleModel{}).Where(query, by...).Order("ctime_invoice DESC").Limit(size).Offset((num - 1) * size).Find(&rest)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//返回计数
|
|
|
func (r *RecookInvoiceApplyModel) Count(status int) (count uint) {
|
|
|
r.GetDb().Table("recook_invoice_apply").Where("invoice_status=?", status).Count(&count)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//返回总金额
|
|
|
func (r *RecookInvoiceApplyModel) PluckPrice(status int) (price []decimal.Decimal) {
|
|
|
r.GetDb().Table("recook_invoice_apply").Where("invoice_status=?", status).Pluck("total_amount", &price)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//用户增加常用抬头功能的表
|
|
|
type InvoiceTitleModel struct {
|
|
|
db.BaseModel
|
|
|
ID uint `gorm:"column:id" json:"id"`
|
|
|
// UID 用户id
|
|
|
UID uint `gorm:"column:uid" json:"uid"`
|
|
|
// Type 1公司 2个人
|
|
|
Type uint `gorm:"column:type" json:"type"`
|
|
|
// Name 名称
|
|
|
Name string `gorm:"column:name" json:"name"`
|
|
|
// TaxNum 税号
|
|
|
Taxnum string `gorm:"column:taxnum" json:"taxnum"`
|
|
|
// Address 地址
|
|
|
Address string `gorm:"column:address" json:"address"`
|
|
|
// Phone 电话
|
|
|
Phone string `gorm:"column:phone" json:"phone"`
|
|
|
// Bank 银行账号
|
|
|
Bank string `gorm:"column:bank" json:"bank"`
|
|
|
// Default 1默认
|
|
|
Default int `gorm:"column:default" json:"defaultValue"`
|
|
|
}
|
|
|
|
|
|
func (r *InvoiceTitleModel) TableName() string {
|
|
|
return "recook_user_letterhead"
|
|
|
}
|
|
|
|
|
|
//查询抬头表by name
|
|
|
func (r *InvoiceTitleModel) FindByName(name string, uid uint) (rest InvoiceTitleModel) {
|
|
|
r.GetDb().Model(&InvoiceTitleModel{}).Where("name=? and uid=?", name, uid).First(&rest)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//判断公司税号是否存在
|
|
|
func (r *InvoiceTitleModel) FindByTaxNum(name string, uid uint) (rest InvoiceTitleModel) {
|
|
|
r.GetDb().Model(&InvoiceTitleModel{}).Where("taxnum=? and uid=? ", name, uid).First(&rest)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//新增
|
|
|
func (r *InvoiceTitleModel) Add(p *InvoiceTitleModel) {
|
|
|
r.GetDb().Model(&InvoiceTitleModel{}).Create(&p)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//通过id来获取
|
|
|
func (r *InvoiceTitleModel) FindById(id uint, uid uint) (rest InvoiceTitleModel) {
|
|
|
r.GetDb().Model(&InvoiceTitleModel{}).Where("id=? and uid=? ", id, uid).First(&rest)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//通过UID来获取全部数据
|
|
|
func (r *InvoiceTitleModel) FindAll(uid uint) (rest []InvoiceTitleModel) {
|
|
|
r.GetDb().Model(&InvoiceTitleModel{}).Find(&rest, "uid=?", uid)
|
|
|
return
|
|
|
}
|