|
@@ -1,8 +1,17 @@
|
|
|
package service
|
|
|
|
|
|
import (
|
|
|
+ . "app.yhyue.com/moapp/jybase/api"
|
|
|
+ qutil "app.yhyue.com/moapp/jybase/common"
|
|
|
+ . "app.yhyue.com/moapp/jybase/date"
|
|
|
+ "app.yhyue.com/moapp/jybase/encrypt"
|
|
|
+ "app.yhyue.com/moapp/jybase/go-xweb/log"
|
|
|
+ "app.yhyue.com/moapp/jybase/go-xweb/xweb"
|
|
|
+ "app.yhyue.com/moapp/jybase/mail"
|
|
|
"bytes"
|
|
|
+ "database/sql"
|
|
|
"encoding/json"
|
|
|
+ "errors"
|
|
|
"fmt"
|
|
|
"io/ioutil"
|
|
|
"jy/src/jfw/modules/subscribepay/src/config"
|
|
@@ -13,13 +22,6 @@ import (
|
|
|
"strings"
|
|
|
"sync"
|
|
|
"time"
|
|
|
-
|
|
|
- qutil "app.yhyue.com/moapp/jybase/common"
|
|
|
- . "app.yhyue.com/moapp/jybase/date"
|
|
|
- "app.yhyue.com/moapp/jybase/encrypt"
|
|
|
- "app.yhyue.com/moapp/jybase/go-xweb/log"
|
|
|
- "app.yhyue.com/moapp/jybase/go-xweb/xweb"
|
|
|
- "app.yhyue.com/moapp/jybase/mail"
|
|
|
)
|
|
|
|
|
|
type Invoice struct {
|
|
@@ -32,6 +34,8 @@ type Invoice struct {
|
|
|
invoiceinfo xweb.Mapper `xweb:"/invoice/info"` //订单详情数据
|
|
|
available xweb.Mapper `xweb:"/invoice/available"` //是否可用开发票
|
|
|
invoiceswitch xweb.Mapper `xweb:"/invoice/switch"` //发票开关
|
|
|
+ invoiceQuery xweb.Mapper `xweb:"/invoice/query"` //发票信息查询
|
|
|
+ invoiceSubmit xweb.Mapper `xweb:"/invoice/submit"` //发票信息提交
|
|
|
}
|
|
|
|
|
|
var dbname = "invoice"
|
|
@@ -62,7 +66,7 @@ var emailHtml_gs = `<p class="item">
|
|
|
<span class="value">%s</span>
|
|
|
</p>
|
|
|
<p class="item">
|
|
|
- <span class="label">手机号:</span>
|
|
|
+ <span class="label">联系电话:</span>
|
|
|
<span class="value">%s</span>
|
|
|
</p>
|
|
|
<p class="item">
|
|
@@ -76,7 +80,7 @@ var emailHtml_gs = `<p class="item">
|
|
|
</html>`
|
|
|
|
|
|
var emailHtml_gr = `<p class="item">
|
|
|
- <span class="label">手机号:</span>
|
|
|
+ <span class="label">联系电话:</span>
|
|
|
<span class="value">%s</span>
|
|
|
</p>
|
|
|
<p class="item">
|
|
@@ -90,6 +94,7 @@ var emailHtml_gr = `<p class="item">
|
|
|
</html>`
|
|
|
var locks = [11]sync.Mutex{}
|
|
|
var email_format = ""
|
|
|
+var email_format_new = ""
|
|
|
|
|
|
func init() {
|
|
|
for i := 0; i < 10; i++ {
|
|
@@ -102,6 +107,13 @@ func init() {
|
|
|
defer r.Close()
|
|
|
bs, _ := ioutil.ReadAll(r)
|
|
|
email_format = string(bs)
|
|
|
+ r, err = os.Open("./mailtemplateNew.html")
|
|
|
+ if err != nil {
|
|
|
+ log.Println("err", err)
|
|
|
+ }
|
|
|
+ defer r.Close()
|
|
|
+ bs, _ = ioutil.ReadAll(r)
|
|
|
+ email_format_new = string(bs)
|
|
|
}
|
|
|
|
|
|
func (this *Invoice) Invoiceswitch() {
|
|
@@ -408,7 +420,13 @@ func (this *Invoice) Callbackinvoice() {
|
|
|
if changed == "1" {
|
|
|
m := make(map[string]interface{})
|
|
|
query := make(map[string]interface{})
|
|
|
- query["order_code"] = order_code
|
|
|
+ if strings.Contains(order_code, "xx") {
|
|
|
+ //自助开票
|
|
|
+ query["only_Identifying"] = order_code
|
|
|
+ } else {
|
|
|
+ //系统开票
|
|
|
+ query["order_code"] = order_code
|
|
|
+ }
|
|
|
query["invoice_changed"] = 1
|
|
|
m["invoice_code"] = fpdm
|
|
|
m["invoice_number"] = fphm
|
|
@@ -436,13 +454,30 @@ func (this *Invoice) Callbackinvoice() {
|
|
|
}
|
|
|
emailHtml := emailHtml_gr
|
|
|
emailHtmls := fmt.Sprintf(emailHtml, (*res)["phone"], user_mail)
|
|
|
- html := fmt.Sprintf(email_format, order_code, url, emailHtmls)
|
|
|
- InvoiceSendMail(user_mail, html)
|
|
|
+ if strings.Contains(order_code, "xx") {
|
|
|
+ //自助开票
|
|
|
+ orderCodeArr := util.Mysql.SelectBySql("select GROUP_CONCAT(order_code) as order_code from invoice where only_Identifying=?", order_code)
|
|
|
+ if len(*orderCodeArr) > 0 {
|
|
|
+ order_code = qutil.ObjToString((*orderCodeArr)[0]["order_code"])
|
|
|
+ for _, v := range strings.Split(order_code, ",") {
|
|
|
+ //订单信息保存
|
|
|
+ updateData := map[string]interface{}{}
|
|
|
+ if InvoiceStatusHandle(v) {
|
|
|
+ updateData["applybill_status"] = 2
|
|
|
+ } else {
|
|
|
+ updateData["applybill_status"] = 3
|
|
|
+ }
|
|
|
+ util.Mysql.Update("dataexport_order", map[string]interface{}{
|
|
|
+ "order_code": v,
|
|
|
+ }, updateData)
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ }
|
|
|
+ html := fmt.Sprintf(email_format, order_code, "电子普通发票", fmt.Sprintf("<a href=\"%s\" download class=\"download\">下载发票</a>", url), "电子普通发票", emailHtmls)
|
|
|
+ InvoiceSendMail(user_mail, html, "电子发票")
|
|
|
}()
|
|
|
-
|
|
|
} else {
|
|
|
-
|
|
|
var company_mail string
|
|
|
if (*res)["mail"] == nil {
|
|
|
company_mail = (*user_info)["user_mail"].(string)
|
|
@@ -457,8 +492,27 @@ func (this *Invoice) Callbackinvoice() {
|
|
|
}
|
|
|
emailHtml := emailHtml_gs
|
|
|
emailHtmls := fmt.Sprintf(emailHtml, (*res)["company_name"], (*res)["taxpayer_identnum"], (*res)["phone"], company_mail)
|
|
|
- html := fmt.Sprintf(email_format, order_code, url, emailHtmls)
|
|
|
- InvoiceSendMail((*res)["mail"].(string), html)
|
|
|
+ if strings.Contains(order_code, "xx") {
|
|
|
+ //自助开票
|
|
|
+ orderCodeArr := util.Mysql.SelectBySql("select GROUP_CONCAT(order_code) as order_code from invoice where only_Identifying=?", order_code)
|
|
|
+ if len(*orderCodeArr) > 0 {
|
|
|
+ order_code = qutil.ObjToString((*orderCodeArr)[0]["order_code"])
|
|
|
+ for _, v := range strings.Split(order_code, ",") {
|
|
|
+ //订单信息保存
|
|
|
+ updateData := map[string]interface{}{}
|
|
|
+ if InvoiceStatusHandle(v) {
|
|
|
+ updateData["applybill_status"] = 2
|
|
|
+ } else {
|
|
|
+ updateData["applybill_status"] = 3
|
|
|
+ }
|
|
|
+ util.Mysql.Update("dataexport_order", map[string]interface{}{
|
|
|
+ "order_code": v,
|
|
|
+ }, updateData)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ html := fmt.Sprintf(email_format, order_code, "电子普通发票", fmt.Sprintf("<a href=\"%s\" download class=\"download\">下载发票</a>", url), "电子普通发票", emailHtmls)
|
|
|
+ InvoiceSendMail((*res)["mail"].(string), html, "电子发票")
|
|
|
|
|
|
}
|
|
|
this.ServeJson(map[string]interface{}{
|
|
@@ -500,8 +554,8 @@ func (this *Invoice) Callbackinvoice() {
|
|
|
}
|
|
|
emailHtml := emailHtml_gr
|
|
|
emailHtmls := fmt.Sprintf(emailHtml, (*res)["phone"], user_mail)
|
|
|
- html := fmt.Sprintf(email_format, order_code, url, emailHtmls)
|
|
|
- InvoiceSendMail(user_mail, html)
|
|
|
+ html := fmt.Sprintf(email_format, order_code, "电子普通发票", fmt.Sprintf("<a href=\"%s\" download class=\"download\">下载发票</a>", url), "电子普通发票", emailHtmls)
|
|
|
+ InvoiceSendMail(user_mail, html, "电子发票")
|
|
|
|
|
|
}()
|
|
|
|
|
@@ -520,8 +574,8 @@ func (this *Invoice) Callbackinvoice() {
|
|
|
}
|
|
|
emailHtml := emailHtml_gs
|
|
|
emailHtmls := fmt.Sprintf(emailHtml, (*res)["company_name"], (*res)["taxpayer_identnum"], (*res)["phone"], company_mail)
|
|
|
- html := fmt.Sprintf(email_format, order_code, url, emailHtmls)
|
|
|
- InvoiceSendMail((*res)["mail"].(string), html)
|
|
|
+ html := fmt.Sprintf(email_format, order_code, "电子普通发票", fmt.Sprintf("<a href=\"%s\" download class=\"download\">下载发票</a>", url), "电子普通发票", emailHtmls)
|
|
|
+ InvoiceSendMail((*res)["mail"].(string), html, "电子发票")
|
|
|
|
|
|
}
|
|
|
this.ServeJson(map[string]interface{}{
|
|
@@ -646,7 +700,7 @@ func (this *Invoice) Replaceinvoice() {
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
- InvoiceSendMail((*res)["mail"].(string), html)
|
|
|
+ InvoiceSendMail((*res)["mail"].(string), html, "电子发票")
|
|
|
return
|
|
|
}
|
|
|
} else {
|
|
@@ -694,7 +748,7 @@ func (this *Invoice) Replaceinvoice() {
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
- InvoiceSendMail((*res)["mail"].(string), html)
|
|
|
+ InvoiceSendMail((*res)["mail"].(string), html, "电子发票")
|
|
|
return
|
|
|
}
|
|
|
}
|
|
@@ -903,6 +957,7 @@ func (this *Invoice) Invoiceinfo() {
|
|
|
countdowntime := config.Config.OrderCountdown.(string)
|
|
|
status := util.Mysql.FindOne("dataexport_order", data, "", "")
|
|
|
if *status != nil {
|
|
|
+ (*status)["source"] = LastInvoiceSource(qutil.InterfaceToStr((*status)["order_code"]))
|
|
|
//卡卷id加密
|
|
|
if (*status)["d_relation_id"] != "" {
|
|
|
(*status)["userLotteryId"] = encrypt.SE.Encode2Hex(qutil.ObjToString((*status)["d_relation_id"]))
|
|
@@ -930,9 +985,9 @@ func (this *Invoice) Invoiceinfo() {
|
|
|
|
|
|
}
|
|
|
|
|
|
-func InvoiceSendMail(target_mail, html string) {
|
|
|
+func InvoiceSendMail(target_mail, html, title string) {
|
|
|
for k, v := range config.GmailAuth {
|
|
|
- if mail.GSendMail("剑鱼标讯", target_mail, "", "", "电子发票", html, "", "", v) {
|
|
|
+ if mail.GSendMail("剑鱼标讯", target_mail, "", "", title, html, "", "", v) {
|
|
|
log.Println(target_mail, fmt.Sprintf("使用%s发送邮件成功", v.User))
|
|
|
break
|
|
|
}
|
|
@@ -945,6 +1000,14 @@ func InvoiceSendMail(target_mail, html string) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// 查询订单最后开票状态
|
|
|
+func LastInvoiceSource(orderCode string) int64 {
|
|
|
+ orderData := util.Mysql.SelectBySql("select source from invoice where order_code =? ORDER BY create_time desc ", orderCode)
|
|
|
+ if orderData != nil && len(*orderData) > 0 {
|
|
|
+ return qutil.Int64All((*orderData)[0]["source"])
|
|
|
+ }
|
|
|
+ return 0
|
|
|
+}
|
|
|
func (this *Invoice) Available() {
|
|
|
u := util.Mysql.FindOne("dataexport_order", map[string]interface{}{"order_code": this.GetString("order_code")}, "pay_time", "")
|
|
|
status := 0
|
|
@@ -980,3 +1043,323 @@ func delReplaceInvoice(query map[string]interface{}) bool {
|
|
|
}
|
|
|
return util.Mysql.Delete(dbname, query)
|
|
|
}
|
|
|
+
|
|
|
+// 发票信息提交
|
|
|
+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"))
|
|
|
+ if onlyIdentifying == "" || invoiceMoney == "" {
|
|
|
+ this.ServeJson(NewResult("", errors.New("传入参数不正确")))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ data := util.Mysql.FindOne("invoice", map[string]interface{}{
|
|
|
+ "only_Identifying": onlyIdentifying,
|
|
|
+ }, "id", "")
|
|
|
+ if data != nil {
|
|
|
+ this.ServeJson(NewResult("", errors.New("该订单发票信息已经提交过申请")))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ orderArr := []string{}
|
|
|
+ mailOrderArr := []string{}
|
|
|
+ orderMap := map[string]interface{}{}
|
|
|
+ Allmoney := int64(0)
|
|
|
+ for _, v := range strings.Split(invoiceMoney, ",") {
|
|
|
+ invoiceMoneyArr := strings.Split(v, ":")
|
|
|
+ orderArr = append(orderArr, invoiceMoneyArr[0])
|
|
|
+ Allmoney += qutil.Int64All(invoiceMoneyArr[1])
|
|
|
+ orderMap[invoiceMoneyArr[0]] = invoiceMoneyArr[1]
|
|
|
+ prices := qutil.Float64All(invoiceMoneyArr[1]) / float64(100)
|
|
|
+ price := strconv.FormatFloat(prices, 'f', -1, 64)
|
|
|
+ mailOrderArr = append(mailOrderArr, fmt.Sprintf("%s(%s元)", invoiceMoneyArr[0], price))
|
|
|
+
|
|
|
+ }
|
|
|
+ //提交时订单金额再做一次校验
|
|
|
+ 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)
|
|
|
+ data := map[string]interface{}{
|
|
|
+ "order_code": orderCode,
|
|
|
+ "company_name": this.GetString("company_name"),
|
|
|
+ "phone": this.GetString("phone"),
|
|
|
+ "mail": this.GetString("mail"),
|
|
|
+ "invoice_type": this.GetString("invoice_type"),
|
|
|
+ "invoice_content": "信息技术服务-技术服务费",
|
|
|
+ "invoice_status": 0,
|
|
|
+ "invoice_changed": 0,
|
|
|
+ "invoice_order_code": strings.Join(orderArr, ","),
|
|
|
+ "company_phone": this.GetString("company_phone"),
|
|
|
+ "taxpayer_identnum": this.GetString("taxpayer_identnum"),
|
|
|
+ "create_time": time.Now().Unix(),
|
|
|
+ "user_id": userId,
|
|
|
+ "operator": operator,
|
|
|
+ "operable_time": FormatDate(&now, Date_Full_Layout),
|
|
|
+ "invoice_money": Allmoney,
|
|
|
+ "invoice_order_money": money,
|
|
|
+ "invoicing_entity": "北京剑鱼信息技术有限公司",
|
|
|
+ "remark": this.GetString("remark"),
|
|
|
+ "source": 1,
|
|
|
+ "invoice_variety": this.GetString("invoice_variety"),
|
|
|
+ "bank_account": this.GetString("bank_account"),
|
|
|
+ "only_Identifying": onlyIdentifying,
|
|
|
+ "company_address": this.GetString("company_address"),
|
|
|
+ "bank_name": this.GetString("bank_name"),
|
|
|
+ "recipient": this.GetString("recipient"),
|
|
|
+ "delivery_address": this.GetString("delivery_address"),
|
|
|
+ }
|
|
|
+ if util.Mysql.Insert("invoice", data) <= 0 {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ //订单发票状态改成已申请
|
|
|
+ if !util.Mysql.Update("dataexport_order", map[string]interface{}{
|
|
|
+ "order_code": orderCode,
|
|
|
+ }, map[string]interface{}{
|
|
|
+ "applybill_status": 1,
|
|
|
+ }) {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if this.GetString("invoice_variety") == "电子普通发票" && Allmoney < 1000000 {
|
|
|
+ //走航天金税开票
|
|
|
+ var orders = []map[string]interface{}{}
|
|
|
+ var items = []map[string]interface{}{}
|
|
|
+ prices := qutil.Float64All(Allmoney) / float64(100)
|
|
|
+ price := strconv.FormatFloat(prices, 'f', -1, 64)
|
|
|
+ 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": price,
|
|
|
+ "totalAmount": price,
|
|
|
+ "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"] = "个人"
|
|
|
+ }
|
|
|
+ go 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"))
|
|
|
+ }
|
|
|
+ prices := qutil.Float64All(Allmoney) / float64(100)
|
|
|
+ price := strconv.FormatFloat(prices, 'f', -1, 64)
|
|
|
+ html := fmt.Sprintf(email_format_new,
|
|
|
+ FormatDate(&now, Date_Full_Layout),
|
|
|
+ strings.Join(orderArr, ","),
|
|
|
+ strings.Join(mailOrderArr, ","),
|
|
|
+ price,
|
|
|
+ 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, ",") {
|
|
|
+ go InvoiceSendMail(v, html, fmt.Sprintf("客户申请开具%s", this.GetString("invoice_variety")))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true
|
|
|
+ }) {
|
|
|
+ this.ServeJson(NewResult("", errors.New("发票信息保存失败")))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ this.ServeJson(NewResult("保存信息成功", nil))
|
|
|
+}
|
|
|
+
|
|
|
+// 发票信息查询
|
|
|
+func (this *Invoice) InvoiceQuery() {
|
|
|
+ onlyIdentifying := encrypt.SE.DecodeString(this.GetString("onlyIdentifying"))
|
|
|
+ invoiceMoney := encrypt.SE.DecodeString(this.GetString("invoiceMoney"))
|
|
|
+ operator := ""
|
|
|
+ if onlyIdentifying == "" || invoiceMoney == "" {
|
|
|
+ this.ServeJson(NewResult("", errors.New("传入参数不正确")))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ orderArr := []string{}
|
|
|
+ money := int64(0)
|
|
|
+ for _, v := range strings.Split(invoiceMoney, ",") {
|
|
|
+ invoiceMoneyArr := strings.Split(v, ":")
|
|
|
+ orderArr = append(orderArr, invoiceMoneyArr[0])
|
|
|
+ money += qutil.Int64All(invoiceMoneyArr[1])
|
|
|
+ }
|
|
|
+ invoiceOne := util.Mysql.FindOne("invoice", map[string]interface{}{
|
|
|
+ "only_Identifying": onlyIdentifying,
|
|
|
+ }, " 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", "")
|
|
|
+ companyName := ""
|
|
|
+ if invoiceOne == nil {
|
|
|
+ //查询公司名称
|
|
|
+ querySQL := fmt.Sprintf("select company_name from dataexport_order where order_code in (%s) and company_name!='' ORDER BY create_time DESC LIMIT 1", fmt.Sprintf("\"%s\"", strings.Join(orderArr, "\",\"")))
|
|
|
+ orderArr := util.Mysql.SelectBySql(querySQL)
|
|
|
+ if orderArr != nil && len(*orderArr) > 0 {
|
|
|
+ companyName = qutil.ObjToString((*orderArr)[0]["company_name"])
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.ServeJson(NewResult(map[string]interface{}{
|
|
|
+ "orderCodes": strings.Join(orderArr, ","),
|
|
|
+ "money": money,
|
|
|
+ "invoice": &invoiceOne,
|
|
|
+ "operator": operator,
|
|
|
+ "company_name": companyName,
|
|
|
+ }, nil))
|
|
|
+}
|
|
|
+
|
|
|
+// GetUserId 获取用户id从订单中
|
|
|
+func GetUserId(orderCode string) (userId string) {
|
|
|
+ rs := util.Mysql.SelectBySql(fmt.Sprintf("select user_id from %s where order_code=?", "dataexport_order"), orderCode)
|
|
|
+ if rs != nil && len(*rs) > 0 {
|
|
|
+ userId = qutil.ObjToString((*rs)[0]["userId"])
|
|
|
+ }
|
|
|
+ return userId
|
|
|
+}
|
|
|
+
|
|
|
+// 调航天金税接口
|
|
|
+func htjs(body map[string]interface{}, orderCode []string, invoiceType, companyName, taxpayerIdentnum, mail, phone string) {
|
|
|
+ invoice_status := 0
|
|
|
+ client := &http.Client{}
|
|
|
+ b, _ := json.Marshal(body)
|
|
|
+ buffer := bytes.NewBuffer(b)
|
|
|
+ request, _ := http.NewRequest("POST", config.InvoiceConfig.Invoice_interface_address+"/Invoice/Add", buffer)
|
|
|
+ response, err := client.Do(request)
|
|
|
+ if err == nil {
|
|
|
+ res, err := ioutil.ReadAll(response.Body)
|
|
|
+ if err != nil {
|
|
|
+ invoice_status = -1
|
|
|
+ } else {
|
|
|
+ resMap := qutil.ObjToMap(string(res))
|
|
|
+ if *resMap != nil {
|
|
|
+ if qutil.IntAll((*resMap)["code"]) == 0 { //开票成功
|
|
|
+ invoice_status = 1
|
|
|
+ } else if qutil.IntAll((*resMap)["code"]) == 2 { //开票中
|
|
|
+ invoice_status = 0
|
|
|
+ } else { //开票失败
|
|
|
+ invoice_status = -1
|
|
|
+ }
|
|
|
+ }
|
|
|
+ defer response.Body.Close()
|
|
|
+ resData := (*resMap)["data"].(map[string]interface{})
|
|
|
+ for _, v := range orderCode {
|
|
|
+ util.Mysql.Update(dbname, map[string]interface{}{"order_code": v, "invoice_status": 0}, map[string]interface{}{
|
|
|
+ "invoice_serialnum": resData["swno"],
|
|
|
+ "invoice_code": resData["fpdm"],
|
|
|
+ "invoice_number": resData["fphm"],
|
|
|
+ "url": resData["path"],
|
|
|
+ "invoice_status": invoice_status,
|
|
|
+ })
|
|
|
+ //订单信息保存
|
|
|
+ updateData := map[string]interface{}{}
|
|
|
+ if InvoiceStatusHandle(v) {
|
|
|
+ updateData["applybill_status"] = 2
|
|
|
+ } else {
|
|
|
+ updateData["applybill_status"] = 3
|
|
|
+ }
|
|
|
+ util.Mysql.Update("dataexport_order", map[string]interface{}{
|
|
|
+ "order_code": v,
|
|
|
+ }, updateData)
|
|
|
+ }
|
|
|
+ sendMail(invoiceType, strings.Join(orderCode, ","), companyName, taxpayerIdentnum, mail, phone, qutil.InterfaceToStr(resData["path"]))
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// 判断是全额还是部分回款
|
|
|
+func InvoiceStatusHandle(orderCode string) bool {
|
|
|
+ orderData := util.Mysql.FindOne("dataexport_order", map[string]interface{}{
|
|
|
+ "order_code": orderCode,
|
|
|
+ }, "pay_money", "")
|
|
|
+ if orderData == nil {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ invoiceData := util.Mysql.SelectBySql("select sum(invoice_order_money) as money from invoice where order_code=? and invoice_status>=0 ", orderCode)
|
|
|
+ if invoiceData == nil || len(*invoiceData) == 0 {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ allMoney := qutil.Int64All((*invoiceData)[0]["money"])
|
|
|
+ pay_money := qutil.Int64All((*orderData)["pay_money"])
|
|
|
+ if pay_money == allMoney {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ return false
|
|
|
+}
|
|
|
+
|
|
|
+// 电子普票发邮箱
|
|
|
+func sendMail(invoiceType, orderCode, companyName, taxpayerIdentnum, mail, phone, url string) {
|
|
|
+ if invoiceType == "个人" {
|
|
|
+ emailHtml := emailHtml_gr
|
|
|
+ emailHtmls := fmt.Sprintf(emailHtml, phone, mail)
|
|
|
+ html := fmt.Sprintf(email_format, orderCode, "电子普通发票", fmt.Sprintf("<a href=\"%s\" download class=\"download\">下载发票</a>", url), "电子普通发票", emailHtmls)
|
|
|
+ InvoiceSendMail(mail, html, "电子发票")
|
|
|
+ } else {
|
|
|
+ emailHtml := emailHtml_gs
|
|
|
+ emailHtmls := fmt.Sprintf(emailHtml, companyName, taxpayerIdentnum, phone, mail)
|
|
|
+ html := fmt.Sprintf(email_format, orderCode, "电子普通发票", fmt.Sprintf("<a href=\"%s\" download class=\"download\">下载发票</a>", url), "电子普通发票", emailHtmls)
|
|
|
+ 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
|
|
|
+}
|