瀏覽代碼

发票页面提交

WH01243 1 年之前
父節點
當前提交
1d81017136
共有 2 個文件被更改,包括 109 次插入69 次删除
  1. 2 2
      src/jfw/modules/subscribepay/src/invoice.json
  2. 107 67
      src/jfw/modules/subscribepay/src/service/invoice.go

+ 2 - 2
src/jfw/modules/subscribepay/src/invoice.json

@@ -3,11 +3,11 @@
   "tax_rate": "0.06",
   "tax_policy": "0",
   "invoice_nature": "0",
-  "invoice_interface_address": "http://192.168.3.14:7081",
+  "invoice_interface_address": "https://jybx3-webtest.jydev.jianyu360.com",
   "code": "3040205000000000000",
   "switch_paymch":{
 	"model":1,
 	"time":"2022-01-17 10:00:00"
   },
   "invoice_switch": true
-}
+}

+ 107 - 67
src/jfw/modules/subscribepay/src/service/invoice.go

@@ -1040,7 +1040,7 @@ func (this *Invoice) InvoiceSubmit() {
 	now := time.Now()
 	onlyIdentifying := encrypt.SE.DecodeString(this.GetString("onlyIdentifying"))
 	invoiceMoney := encrypt.SE.DecodeString(this.GetString("invoiceMoney"))
-	operator := encrypt.SE.DecodeString(this.GetString("operator"))
+	operator := ""
 	if onlyIdentifying == "" || invoiceMoney == "" {
 		this.ServeJson(NewResult("", errors.New("传入参数不正确")))
 		return
@@ -1061,6 +1061,13 @@ func (this *Invoice) InvoiceSubmit() {
 		Allmoney += qutil.Int64All(invoiceMoneyArr[1])
 		orderMap[invoiceMoneyArr[0]] = invoiceMoneyArr[1]
 	}
+	//提交时订单金额再做一次校验
+	for orderCode, money := range orderMap {
+		if ResidueMoney(orderCode) < qutil.Int64All(money) {
+			this.ServeJson(NewResult("", errors.New("该订单发票信息已经提交过申请")))
+			return
+		}
+	}
 	if !util.Mysql.ExecTx("发票信息保存", func(tx *sql.Tx) bool {
 		for orderCode, money := range orderMap {
 			userId := GetUserId(orderCode)
@@ -1105,73 +1112,73 @@ func (this *Invoice) InvoiceSubmit() {
 				return false
 			}
 		}
-        if this.GetString("invoice_variety") == "电子普通发票" && Allmoney < 1000000 {
-            //走航天金税开票
-            var orders = []map[string]interface{}{}
-            var items = []map[string]interface{}{}
-            item := map[string]interface{}{
-                "name":        "技术服务费",
-                "code":        config.InvoiceConfig.Code,
-                "yhzcbs":      config.InvoiceConfig.Tax_policy,
-                "lineType":    config.InvoiceConfig.Invoice_nature,
-                "taxRate":     config.InvoiceConfig.Tax_rate,
-                "taxPrice":    Allmoney,
-                "totalAmount": Allmoney,
-                "quantity":    "1",
-            }
-            items = append(items, item)
-            order := map[string]interface{}{
-                "billNo": onlyIdentifying,
-                "items":  items,
-            }
-            orders = append(orders, order)
-            body := map[string]interface{}{
-                "Swno":      onlyIdentifying,
-                "custType":  "03",
-                "orders":    orders,
-                "custTaxNo": this.GetString("taxpayer_identnum"),
-                "changed":   "0",
-                "phone":     this.GetString("phone"),
-            }
-            if this.GetString("invoice_type") == "单位" {
-                body["custName"] = this.GetString("company_name")
-            } else {
-                body["custName"] = "个人"
-            }
-            htjs(body, orderArr, this.GetString("invoice_type"), this.GetString("company_name"), this.GetString("taxpayer_identnum"), this.GetString("mail"), this.GetString("phone"))
-        } else {
-            //给王航发信息
-            recipientStr := ""
-            deliveryAddressStr := ""
-            if this.GetString("invoice_variety") == "纸质普通发票" || this.GetString("invoice_variety") == "纸质专用发票" {
-                recipientStr = fmt.Sprintf("<p class=\"item\">\n      <span class=\"label\">收件人:</span>\n      <span class=\"value\">%s</span>\n    </p>", this.GetString("recipient"))
-                deliveryAddressStr = fmt.Sprintf("<p class=\"item\">\n      <span class=\"label\">收件地址:</span>\n      <span class=\"value\">%s</span>\n    </p>", this.GetString("delivery_address"))
-            }
-            html := fmt.Sprintf(email_format_new,
-                FormatDate(&now, Date_Full_Layout),
-                strings.Join(orderArr, ","),
-                Allmoney/100,
-                this.GetString("invoice_variety"),
-                qutil.InterfaceToStr(qutil.If(this.GetString("invoice_type") == "", "--", this.GetString("invoice_type"))),
-                qutil.InterfaceToStr(qutil.If(this.GetString("company_name") == "", "--", this.GetString("company_name"))),
-                qutil.InterfaceToStr(qutil.If(this.GetString("taxpayer_identnum") == "", "--", this.GetString("taxpayer_identnum"))),
-                qutil.InterfaceToStr(qutil.If(this.GetString("company_address") == "", "--", this.GetString("company_address"))),
-                qutil.InterfaceToStr(qutil.If(this.GetString("company_phone") == "", "--", this.GetString("company_phone"))),
-                qutil.InterfaceToStr(qutil.If(this.GetString("bank_name") == "", "--", this.GetString("bank_name"))),
-                qutil.InterfaceToStr(qutil.If(this.GetString("bank_account") == "", "--", this.GetString("bank_account"))),
-                qutil.InterfaceToStr(qutil.If(this.GetString("remark") == "", "--", this.GetString("remark"))),
-                recipientStr,
-                this.GetString("phone"),
-                deliveryAddressStr,
-            )
-            for _, v := range strings.Split(config.Config.FinanceMail, ",") {
-                InvoiceSendMail(v, html, fmt.Sprintf("客户申请开具%s", this.GetString("invoice_variety")))
-            }
-        }
+		if this.GetString("invoice_variety") == "电子普通发票" && Allmoney < 1000000 {
+			//走航天金税开票
+			var orders = []map[string]interface{}{}
+			var items = []map[string]interface{}{}
+			item := map[string]interface{}{
+				"name":        "技术服务费",
+				"code":        config.InvoiceConfig.Code,
+				"yhzcbs":      config.InvoiceConfig.Tax_policy,
+				"lineType":    config.InvoiceConfig.Invoice_nature,
+				"taxRate":     config.InvoiceConfig.Tax_rate,
+				"taxPrice":    Allmoney,
+				"totalAmount": Allmoney,
+				"quantity":    "1",
+			}
+			items = append(items, item)
+			order := map[string]interface{}{
+				"billNo": onlyIdentifying,
+				"items":  items,
+			}
+			orders = append(orders, order)
+			body := map[string]interface{}{
+				"Swno":      onlyIdentifying,
+				"custType":  "03",
+				"orders":    orders,
+				"custTaxNo": this.GetString("taxpayer_identnum"),
+				"changed":   "0",
+				"phone":     this.GetString("phone"),
+			}
+			if this.GetString("invoice_type") == "单位" {
+				body["custName"] = this.GetString("company_name")
+			} else {
+				body["custName"] = "个人"
+			}
+			htjs(body, orderArr, this.GetString("invoice_type"), this.GetString("company_name"), this.GetString("taxpayer_identnum"), this.GetString("mail"), this.GetString("phone"))
+		} else {
+			//给王航发信息
+			recipientStr := ""
+			deliveryAddressStr := ""
+			if this.GetString("invoice_variety") == "纸质普通发票" || this.GetString("invoice_variety") == "纸质专用发票" {
+				recipientStr = fmt.Sprintf("<p class=\"item\">\n      <span class=\"label\">收件人:</span>\n      <span class=\"value\">%s</span>\n    </p>", this.GetString("recipient"))
+				deliveryAddressStr = fmt.Sprintf("<p class=\"item\">\n      <span class=\"label\">收件地址:</span>\n      <span class=\"value\">%s</span>\n    </p>", this.GetString("delivery_address"))
+			}
+			html := fmt.Sprintf(email_format_new,
+				FormatDate(&now, Date_Full_Layout),
+				strings.Join(orderArr, ","),
+				Allmoney/100,
+				this.GetString("invoice_variety"),
+				qutil.InterfaceToStr(qutil.If(this.GetString("invoice_type") == "", "--", this.GetString("invoice_type"))),
+				qutil.InterfaceToStr(qutil.If(this.GetString("company_name") == "", "--", this.GetString("company_name"))),
+				qutil.InterfaceToStr(qutil.If(this.GetString("taxpayer_identnum") == "", "--", this.GetString("taxpayer_identnum"))),
+				qutil.InterfaceToStr(qutil.If(this.GetString("company_address") == "", "--", this.GetString("company_address"))),
+				qutil.InterfaceToStr(qutil.If(this.GetString("company_phone") == "", "--", this.GetString("company_phone"))),
+				qutil.InterfaceToStr(qutil.If(this.GetString("bank_name") == "", "--", this.GetString("bank_name"))),
+				qutil.InterfaceToStr(qutil.If(this.GetString("bank_account") == "", "--", this.GetString("bank_account"))),
+				qutil.InterfaceToStr(qutil.If(this.GetString("remark") == "", "--", this.GetString("remark"))),
+				recipientStr,
+				this.GetString("phone"),
+				deliveryAddressStr,
+			)
+			for _, v := range strings.Split(config.Config.FinanceMail, ",") {
+				InvoiceSendMail(v, html, fmt.Sprintf("客户申请开具%s", this.GetString("invoice_variety")))
+			}
+		}
 		return true
 	}) {
 		this.ServeJson(NewResult("", errors.New("发票信息保存失败")))
-        return
+		return
 	}
 	this.ServeJson(NewResult("保存信息成功", nil))
 }
@@ -1180,7 +1187,7 @@ func (this *Invoice) InvoiceSubmit() {
 func (this *Invoice) InvoiceQuery() {
 	onlyIdentifying := encrypt.SE.DecodeString(this.GetString("onlyIdentifying"))
 	invoiceMoney := encrypt.SE.DecodeString(this.GetString("invoiceMoney"))
-	operator := encrypt.SE.DecodeString(this.GetString("operator"))
+	operator := ""
 	if onlyIdentifying == "" || invoiceMoney == "" {
 		this.ServeJson(NewResult("", errors.New("传入参数不正确")))
 		return
@@ -1194,7 +1201,7 @@ func (this *Invoice) InvoiceQuery() {
 	}
 	invoiceOne := util.Mysql.FindOne("invoice", map[string]interface{}{
 		"only_Identifying": onlyIdentifying,
-	}, " bank_account, company_name, phone, mail,company_phone, invoice_type, invoice_content, url, invoice_status, invoice_serialnum, taxpayer_identnum,    operator, operable_time, invoicing_entity, remark, invoice_variety, logistics_code, company_address, bank_name, recipient, delivery_address", "")
+	}, " bank_account, company_phone,company_name, phone, mail,company_phone, invoice_type, invoice_content, url, invoice_status, invoice_serialnum, taxpayer_identnum,    operator, operable_time, invoicing_entity, remark, invoice_variety, logistics_code, company_address, bank_name, recipient, delivery_address", "")
 	this.ServeJson(NewResult(map[string]interface{}{
 		"orderCodes": strings.Join(orderArr, ","),
 		"money":      money,
@@ -1283,6 +1290,7 @@ func InvoiceStatusHandle(orderCode string) bool {
 
 // 电子普票发邮箱
 func sendMail(invoiceType, orderCode, companyName, taxpayerIdentnum, mail, phone, url string) {
+	url = "https://www.baidu.com/index.php?tn=monline_3_dg"
 	if invoiceType == "个人" {
 		emailHtml := emailHtml_gr
 		emailHtmls := fmt.Sprintf(emailHtml, phone, mail)
@@ -1295,3 +1303,35 @@ func sendMail(invoiceType, orderCode, companyName, taxpayerIdentnum, mail, phone
 		InvoiceSendMail(mail, html, "电子发票")
 	}
 }
+
+// 订单剩余金额查询
+func ResidueMoney(orderCode string) int64 {
+	residueMoney := int64(0)
+	//订单信息查询
+	orderData := util.Mysql.SelectBySql("select  pay_money,applybill_status from  dataexport_order  where  order_code =?", orderCode)
+	if len(*orderData) == 0 || orderData == nil {
+		return residueMoney
+	}
+	if qutil.Int64All((*orderData)[0]["applybill_status"]) == 2 {
+		return residueMoney
+	}
+	//发票信息查询
+	invoiceData := util.Mysql.SelectBySql("select invoice_status,sum(invoice_order_money) as  money  from  invoice where  order_code=?  and  invoice_status>=0  GROUP BY  invoice_status", orderCode)
+	if len(*orderData) == 0 || orderData == nil {
+	} else {
+		//开过几次票
+		payMoney := qutil.Int64All((*orderData)[0]["pay_money"])
+		allMoney := int64(0)
+		for _, invoice := range *invoiceData {
+			invoice_status := qutil.Int64All(invoice["invoice_status"])
+			money := qutil.Int64All(invoice["money"])
+			if invoice_status == 0 {
+				return residueMoney
+			} else {
+				allMoney += money
+			}
+		}
+		residueMoney = payMoney - allMoney
+	}
+	return residueMoney
+}