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.

154 lines
4.1 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package bill
import (
"github.com/gin-gonic/gin"
"recook/internal/back"
"recook/internal/dbc"
"recook/internal/model/order"
"recook/tools"
"strconv"
)
type canGetBillPem struct {
UserID uint `json:"userId"`
Page uint `json:"page"`
startTime string `json:"startTime"` //格式2020-08-03
endTime string `json:"endTime"` //格式2020-08-03
}
//获取可以开票的订单列表从这里去开发票的金额为actual_amount+coin_amount
func CangetBill(c *gin.Context) {
var p canGetBillPem
err := tools.ParseParams(&p, c)
if err != nil {
back.Fail(c, err.Error())
return
}
//p.UserID = 4736
if p.UserID <= 0 {
back.Fail(c, "用户ID必须大于0")
return
}
where := "refund_status=0 AND status=1 AND (bill=0 OR bill=3) AND user_id=" + strconv.Itoa(int(p.UserID))
if len(p.startTime) > 0 && len(p.endTime) > 0 {
where = "AND order_time>=" + p.startTime + " 00:00:00 AND order_time<=" + p.endTime + " 23:59:59"
}
var orderGoodsDetailData []order.GoodsDetail
dbc.DB.Order("id desc").Limit(10).Offset(10*p.Page).Find(&orderGoodsDetailData, where)
if len(orderGoodsDetailData) == 0 {
back.Suc(c, "", nil)
} else {
back.Suc(c, "", &orderGoodsDetailData)
}
return
}
//获取发票列表
//2 :开票完成( 最终状 态),其他状态分别为: 20:开票中; 21:开票成功签章中;22:开票失败;24: 开票成功签章失败 ;3: 发票已作废 31:\n\n发票作废中 备注22、24 状态时,无需再查询, 请确认开票失败原因以及签章失败 原因3、31 只针对纸票
//2,24已开票
//20,21,开票中
//22,开票失败
type getBillListPem struct {
UserID uint `json:"userId"`
Page int `json:"page"`
}
type getBillListResult struct {
Result order.Bill `json:"result"`
StatusDec string `json:"statusDec"`
Color int `json:"color"`
}
func GetBillList(c *gin.Context) {
limit := 10
var p getBillListPem
err := tools.ParseParams(&p, c)
if err != nil {
back.Fail(c, err.Error())
return
}
if p.Page < 1 {
p.Page = 1
}
//p.UserID = 4736
var billList []order.Bill
dbc.DB.Order("id desc").Limit(limit).Offset((p.Page-1)*limit).Find(&billList, "uid=?", p.UserID)
var mygetBillListResult []getBillListResult
myStatus := ""
myColor := 1
for _, item := range billList {
if item.Status == 2 || item.Status == 24 {
myStatus = "已开票"
myColor = 1
}
if item.Status == 20 || item.Status == 21 {
myStatus = "开票中"
myColor = 2
}
if item.Status == 22 {
myStatus = "开票失败"
myColor = 3
}
mygetBillListResult = append(mygetBillListResult, getBillListResult{
Result: item,
StatusDec: myStatus,
Color: myColor,
})
}
back.Suc(c, "", &mygetBillListResult)
return
}
type GetBillDetailPem struct {
BillId int `json:"billId"`
}
type GetBillDetailResult struct {
order.Bill
Type int `json:"type"`
}
//获取单个发票详情,有税号的就是公司
func GetBillDetail(c *gin.Context) {
var p GetBillDetailPem
err := tools.ParseParams(&p, c)
if err != nil {
back.Fail(c, err.Error())
return
}
//p.BillId = 1
var billList order.Bill
dbc.DB.Order("id desc").First(&billList, "id=?", p.BillId)
getBillDetailResultData := GetBillDetailResult{}
getBillDetailResultData.ID = billList.ID
getBillDetailResultData.UID = billList.UID
getBillDetailResultData.Fpqqlsh = billList.Fpqqlsh
getBillDetailResultData.Status = billList.Status
getBillDetailResultData.Buyername = billList.Buyername
getBillDetailResultData.Taxnum = billList.Taxnum
getBillDetailResultData.Address = billList.Address
getBillDetailResultData.Telephone = billList.Telephone
getBillDetailResultData.Account = billList.Account
getBillDetailResultData.Address = billList.Address
getBillDetailResultData.Content = billList.Content
getBillDetailResultData.Message = billList.Message
getBillDetailResultData.Ctime = billList.Ctime
getBillDetailResultData.Price = billList.Price
getBillDetailResultData.Fail = billList.Fail
if len(billList.Taxnum) > 0 {
getBillDetailResultData.Type = 1
} else {
getBillDetailResultData.Type = 0
}
back.Suc(c, "", &getBillDetailResultData)
return
}