|
@@ -346,6 +346,58 @@ func (d *DataExport) CancelOrder() error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
+// 查询订单最后开票状态
|
|
|
+func QmxInvoice(res map[string]interface{}) bool {
|
|
|
+ if res["is_backstage_order"] == 1 && res["order_channel"] != "xdqd04" {
|
|
|
+ if res["return_status"] == 1 && public.Mysql.Count("invoice", map[string]interface{}{
|
|
|
+ "order_code": res["order_code"],
|
|
|
+ }) == 0 && res["signing_subject"] == "北京剑鱼信息技术有限公司" {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false
|
|
|
+}
|
|
|
+
|
|
|
+// 剩余金额
|
|
|
+func InvoicePrice(orderData map[string]interface{}) int64 {
|
|
|
+ residueMoney := int64(0)
|
|
|
+ if util.Int64All(orderData["applybill_status"]) == 2 {
|
|
|
+ return residueMoney
|
|
|
+ }
|
|
|
+
|
|
|
+ return util.Int64All(orderData["pay_money"]) - InvoiceAmount(util.InterfaceToStr(orderData["order_code"]))
|
|
|
+}
|
|
|
+
|
|
|
+func InvoiceAmount(orderCode string) (invoicedMoney int64) {
|
|
|
+ invoicedInfo := public.Mysql.SelectBySql(fmt.Sprintf("SELECT invoice_order_money,only_Identifying FROM invoice WHERE order_code = '%s' and invoice_status>=0", orderCode))
|
|
|
+ if invoicedInfo != nil && len(*invoicedInfo) > 0 {
|
|
|
+ onlyMap := make(map[string]int64)
|
|
|
+ for _, m := range *invoicedInfo {
|
|
|
+ if m["only_Identifying"] != nil { //过滤换票过程中的数据
|
|
|
+ onlyMap[util.InterfaceToStr(m["only_Identifying"])] = util.Int64All(m["invoice_order_money"])
|
|
|
+ } else {
|
|
|
+ invoicedMoney += util.Int64All(m["invoice_order_money"])
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if len(onlyMap) > 0 {
|
|
|
+ for _, i := range onlyMap {
|
|
|
+ invoicedMoney += i
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func ShowList(order_code string) []map[string]interface{} {
|
|
|
+ data := public.Mysql.SelectBySql(fmt.Sprintf(`SELECT *,(
|
|
|
+ SELECT count(1) as count FROM invoice b WHERE b.order_code = a.order_code and b.only_Identifying is not null and b.only_Identifying = a.only_Identifying
|
|
|
+) as isChanged FROM invoice a WHERE order_code = '%s' and invoice_status != -2 and invoice_variety is not null and invoice_variety not LIKE '%s' ORDER BY create_time DESC`, order_code, "%纸质%"))
|
|
|
+ if data == nil {
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ return *data
|
|
|
+}
|
|
|
+
|
|
|
/*
|
|
|
*
|
|
|
根据 订单编号+userId 查询
|
|
@@ -367,7 +419,17 @@ func (d *DataExport) ToOrderDetail(orderCode string) error {
|
|
|
if orderCode != "" {
|
|
|
orderDetail = *public.Mysql.FindOne(tableName_order, queryMap, "", "")
|
|
|
//最后一次开票查询
|
|
|
- orderDetail["source"] = LastInvoiceSource(orderCode)
|
|
|
+ //orderDetail["source"] = LastInvoiceSource(orderCode)
|
|
|
+ //如果是管理后台的单子 是否满足可开票
|
|
|
+ orderDetail["qmx_invoice"] = QmxInvoice(orderDetail)
|
|
|
+ //剩余可开票金额
|
|
|
+ var invoicePrice bool
|
|
|
+ if util.Int64All(orderDetail["create_time"]) > 1704038400 {
|
|
|
+ invoicePrice = InvoicePrice(orderDetail) > 0
|
|
|
+ }
|
|
|
+ orderDetail["invoice_price"] = invoicePrice
|
|
|
+ //是否存在可查看发票
|
|
|
+ orderDetail["invoice_show"] = len(ShowList(util.InterfaceToStr(orderDetail["order_code"]))) > 0
|
|
|
}
|
|
|
// log.Println("ToOrderDetail", orderCode, orderDetail)
|
|
|
if orderDetail["pay_money"] != nil {
|