|
@@ -13,6 +13,7 @@ import (
|
|
|
"encoding/json"
|
|
|
"errors"
|
|
|
"fmt"
|
|
|
+ "github.com/google/uuid"
|
|
|
"io/ioutil"
|
|
|
"jy/src/jfw/modules/subscribepay/src/config"
|
|
|
"jy/src/jfw/modules/subscribepay/src/util"
|
|
@@ -26,16 +27,20 @@ import (
|
|
|
|
|
|
type Invoice struct {
|
|
|
*xweb.Action
|
|
|
- addinvoice xweb.Mapper `xweb:"/invoice/add"` //开发票
|
|
|
- showinvoice xweb.Mapper `xweb:"/invoice/show"` //查看发票
|
|
|
- callbackinvoice xweb.Mapper `xweb:"/invoice/callback"` //开发票回调
|
|
|
- replaceinvoice xweb.Mapper `xweb:"/invoice/replace"` //换发票
|
|
|
- refundinvoice xweb.Mapper `xweb:"/invoice/refund"` //退票
|
|
|
- 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"` //发票信息提交
|
|
|
+ addinvoice xweb.Mapper `xweb:"/invoice/add"` //开发票
|
|
|
+ showinvoice xweb.Mapper `xweb:"/invoice/show"` //查看发票
|
|
|
+ newInvoiceShow xweb.Mapper `xweb:"/invoice/newShow"` //查看发票
|
|
|
+ showinvoiceList xweb.Mapper `xweb:"/invoice/showList"` //新查看发票 p537
|
|
|
+ callbackinvoice xweb.Mapper `xweb:"/invoice/callback"` //开发票回调
|
|
|
+ replaceinvoice xweb.Mapper `xweb:"/invoice/replace"` //换发票
|
|
|
+ newReplaceinvoice xweb.Mapper `xweb:"/invoice/newReplace"` //新换发票
|
|
|
+ refundinvoice xweb.Mapper `xweb:"/invoice/refund"` //退票
|
|
|
+ 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"` //发票信息提交
|
|
|
+ getCompanyCode xweb.Mapper `xweb:"/invoice/getCompanyCode"` //开票联想税号
|
|
|
}
|
|
|
|
|
|
var dbname = "invoice"
|
|
@@ -180,6 +185,7 @@ func (this *Invoice) Invoiceswitch() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// Addinvoice 用户端-线上开票只能选电子普票
|
|
|
func (this *Invoice) Addinvoice() error {
|
|
|
defer qutil.Catch()
|
|
|
userId := qutil.ObjToString(this.GetSession("userId"))
|
|
@@ -201,19 +207,15 @@ func (this *Invoice) Addinvoice() error {
|
|
|
pos := qutil.IntAllDef(last, 0)
|
|
|
locks[pos].Lock()
|
|
|
defer locks[pos].Unlock()
|
|
|
- u := util.Mysql.FindOne("dataexport_order", map[string]interface{}{"order_code": order_code, "user_id": userId, "applyBill_status": map[string]interface{}{"ne": 2}}, "order_money,product_type,order_channel,pay_way,pay_money,is_backstage_order,billingMode", "")
|
|
|
+ u := util.Mysql.FindOne("dataexport_order", map[string]interface{}{"order_code": order_code, "user_id": userId, "applyBill_status": map[string]interface{}{"ne": 2}}, "order_money,product_type,pay_way,pay_money,is_backstage_order,billingMode,signing_subject,return_status,applybill_status", "")
|
|
|
if u != nil {
|
|
|
//后端代用户下单支持开票 order_channel = xdqd04
|
|
|
- if qutil.IntAll((*u)["billingMode"]) == 1 && (qutil.IntAll((*u)["is_backstage_order"]) != 1 || qutil.InterfaceToStr((*u)["order_channel"]) == "xdqd04") {
|
|
|
+ if qutil.IntAll((*u)["billingMode"]) == 1 && (qutil.IntAll((*u)["is_backstage_order"]) != 1 || (qutil.IntAll((*u)["is_backstage_order"]) == 1 && qutil.ObjToString((*u)["signing_subject"]) == "h01" && qutil.IntAll((*u)["return_status"]) == 1 && qutil.IntAll((*u)["applybill_status"]) == 0)) {
|
|
|
var prices float64
|
|
|
//公对公转账 账单金额可以修改 开发票应取实付金额 pay_money
|
|
|
//微信支付宝支付 pay_money为订单金额减去微信or支付包红包
|
|
|
- if qutil.ObjToString((*u)["pay_way"]) == "transferAccounts" {
|
|
|
- prices = qutil.Float64All((*u)["pay_money"]) // float64(100)
|
|
|
- } else {
|
|
|
- prices = qutil.Float64All((*u)["order_money"]) // float64(100)
|
|
|
- }
|
|
|
- //price = strconv.FormatFloat(prices, 'f', -1, 64)
|
|
|
+ prices = qutil.Float64All((*u)["pay_money"]) / float64(100)
|
|
|
+ price = strconv.FormatFloat(prices, 'f', -1, 64)
|
|
|
product_name = (*u)["product_type"].(string)
|
|
|
applyBill_status = 1
|
|
|
data := make(map[string]interface{})
|
|
@@ -242,7 +244,7 @@ func (this *Invoice) Addinvoice() error {
|
|
|
data["create_time"] = time.Now().Unix()
|
|
|
data["user_id"] = userId
|
|
|
data["invoice_status"] = 0
|
|
|
- data["invoice_money"] = prices
|
|
|
+ data["invoice_money"] = price
|
|
|
var orders = []map[string]interface{}{}
|
|
|
var items = []map[string]interface{}{}
|
|
|
item := map[string]interface{}{
|
|
@@ -251,7 +253,7 @@ func (this *Invoice) Addinvoice() error {
|
|
|
"yhzcbs": config.InvoiceConfig.Tax_policy,
|
|
|
"lineType": config.InvoiceConfig.Invoice_nature,
|
|
|
"taxRate": config.InvoiceConfig.Tax_rate,
|
|
|
- "taxPrice": price, // 不再使用
|
|
|
+ "taxPrice": price,
|
|
|
"totalAmount": price,
|
|
|
"quantity": "1",
|
|
|
}
|
|
@@ -440,6 +442,106 @@ func (this *Invoice) Showinvoice() {
|
|
|
|
|
|
}
|
|
|
|
|
|
+// 查看发票
|
|
|
+func (this *Invoice) ShowinvoiceList() {
|
|
|
+ order_code := this.GetString("order_code")
|
|
|
+ //红冲发票开关
|
|
|
+ redSwitchInfo := map[string]interface{}{
|
|
|
+ "ris": config.InvoiceConfig.Red_invoice_switch,
|
|
|
+ "rim": config.InvoiceConfig.Red_invoice_msg,
|
|
|
+ }
|
|
|
+ invoices := ShowList(order_code)
|
|
|
+ if invoices != nil && len(invoices) > 0 {
|
|
|
+ isIos := util.IsMobileIOS(this.Request.UserAgent())
|
|
|
+ var invoiceData []map[string]interface{}
|
|
|
+ for _, data := range invoices {
|
|
|
+ //是否换过票
|
|
|
+ isChanged := qutil.IntAll(data["isChanged"]) > 1
|
|
|
+ if isChanged && qutil.IntAll(data["invoice_changed"]) == 0 { //换过票的 只展示换票后的数据
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ delete(data, "user_id")
|
|
|
+ data["id"] = encrypt.SE.Encode2Hex(qutil.InterfaceToStr(data["id"]))
|
|
|
+ timeLimit := qutil.Int64All(data["create_time"]) <= config.InvoiceConfig.Order_createtime //24年之前的发票不让换票
|
|
|
+ isJyInvoice := !(qutil.InterfaceToStr(data["invoice_number"]) != "" && qutil.InterfaceToStr(data["invoice_code"]) == "") //非数电票
|
|
|
+ isJyEntity := data["invoicing_entity"] != nil && qutil.InterfaceToStr(data["invoicing_entity"]) != config.InvoiceConfig.SigningSubject
|
|
|
+ data["changed"] = qutil.If(isJyInvoice || isChanged || isJyEntity || timeLimit, true, false)
|
|
|
+ //if url := qutil.InterfaceToStr(data["url"]); url != "" {
|
|
|
+ //ios 移动端
|
|
|
+ if !isIos {
|
|
|
+ data["url"] = qutil.If(data["source_url"] != nil && qutil.ObjToString(data["source_url"]) != "", data["source_url"], data["url"])
|
|
|
+ //国家税务局-增值税电子发票公共服务平台
|
|
|
+ //if strings.Contains(url, "tysl.beijing.chinatax") {
|
|
|
+ // data["url"] = strings.ReplaceAll(url, "/preview.html?code=", "/web-reader/reader?file=")
|
|
|
+ //}
|
|
|
+ }
|
|
|
+ //}
|
|
|
+ isReopen := timeLimit
|
|
|
+ //var isReopen bool
|
|
|
+ if qutil.IntAll(data["invoice_status"]) == -1 && !isReopen {
|
|
|
+ isReopen = util.Mysql.Count("invoice_fail_record", map[string]interface{}{
|
|
|
+ "only_Identifying": data["only_Identifying"],
|
|
|
+ "order_code": order_code,
|
|
|
+ })+1 >= config.InvoiceConfig.SubmitNum
|
|
|
+ }
|
|
|
+ data["only_Identifying"] = encrypt.SE.EncodeString(qutil.InterfaceToStr(data["only_Identifying"]))
|
|
|
+ data["isReopen"] = isReopen
|
|
|
+ invoiceData = append(invoiceData, data)
|
|
|
+ }
|
|
|
+ this.ServeJson(map[string]interface{}{
|
|
|
+ "status": "success",
|
|
|
+ "invoiceData": invoiceData,
|
|
|
+ "redSwitchInfo": redSwitchInfo,
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ data := util.Mysql.FindOne("dataexport_order", map[string]interface{}{
|
|
|
+ "order_code": order_code,
|
|
|
+ }, "order_status,applybill_status,order_code,user_mail,applybill_type,applybill_company,user_phone,applybill_taxnum", "")
|
|
|
+ if data != nil {
|
|
|
+ (*data)["status"] = "fail"
|
|
|
+ }
|
|
|
+
|
|
|
+ this.ServeJson(map[string]interface{}{
|
|
|
+ "status": "fail",
|
|
|
+ "orderData": data,
|
|
|
+ "redSwitchInfo": redSwitchInfo,
|
|
|
+ })
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func ShowList(order_code string) []map[string]interface{} {
|
|
|
+ data := util.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 is not null and invoice_variety not LIKE '%s' ORDER BY create_time DESC`, order_code, "%纸质%"))
|
|
|
+ if data == nil {
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ return *data
|
|
|
+}
|
|
|
+
|
|
|
+func (this *Invoice) NewInvoiceShow() {
|
|
|
+ stype := this.GetString("stype")
|
|
|
+ code := this.GetString("code")
|
|
|
+ data := make(map[string]interface{})
|
|
|
+ switch stype {
|
|
|
+ case "1": //订单回显金额
|
|
|
+ data["pay_money"] = ResidueMoney(code)
|
|
|
+ case "2": //发票信息回显
|
|
|
+ invoice := util.Mysql.FindOne("invoice", map[string]interface{}{"id": encrypt.SE.Decode4Hex(code)}, "id,only_Identifying,order_code,invoice_order_code,invoice_money,remark,invoice_type,invoice_content,invoice_variety,company_name,phone,mail,taxpayer_identnum,invoice_money,invoice_order_money,company_address,bank_name,recipient,delivery_address,bank_account,company_phone", "")
|
|
|
+ if invoice != nil {
|
|
|
+ (*invoice)["id"] = code
|
|
|
+ if (*invoice)["invoice_order_code"] != nil {
|
|
|
+ (*invoice)["order_code"] = (*invoice)["invoice_order_code"]
|
|
|
+ }
|
|
|
+ (*invoice)["only_Identifying"] = encrypt.SE.EncodeString(qutil.InterfaceToStr((*invoice)["only_Identifying"]))
|
|
|
+ }
|
|
|
+ data["invoice"] = invoice
|
|
|
+ }
|
|
|
+ this.ServeJson(map[string]interface{}{
|
|
|
+ "data": data,
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
// 开发票回调
|
|
|
func (this *Invoice) Callbackinvoice() {
|
|
|
isRed, _ := this.GetBool("isRed")
|
|
@@ -1003,6 +1105,180 @@ func (this *Invoice) Replaceinvoice() {
|
|
|
|
|
|
}
|
|
|
|
|
|
+// 新换票
|
|
|
+func (this *Invoice) NewReplaceinvoice() {
|
|
|
+ //红冲开关
|
|
|
+ if !config.InvoiceConfig.Red_invoice_switch {
|
|
|
+ this.ServeJson(map[string]interface{}{
|
|
|
+ "invoice_status": -1,
|
|
|
+ "invoice_msg": config.InvoiceConfig.Red_invoice_msg,
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ invoice_type := this.GetString("invoice_type")
|
|
|
+ phone := this.GetString("phone")
|
|
|
+ e_mail := this.GetString("mail")
|
|
|
+ company_name := this.GetString("company_name")
|
|
|
+ id_num := strings.ToUpper(this.GetString("taxpayer_identnum")) //纳税人识别号
|
|
|
+ invoiceContent := this.GetString("invoiceContent")
|
|
|
+ remark := this.GetString("remark")
|
|
|
+ invoiceVariety := this.GetString("invoice_variety")
|
|
|
+ invoice_status := 0
|
|
|
+ //userId := qutil.ObjToString(this.GetSession("userId")) 支持扫描换票
|
|
|
+ //order_code := this.GetString("order_code")
|
|
|
+ sid := encrypt.SE.Decode4Hex(this.GetString("sid"))
|
|
|
+ oRes := util.Mysql.FindOne(dbname, map[string]interface{}{"id": sid, "invoice_changed": 0, "invoice_status": 1}, "", "") //仅线上开发票可换票
|
|
|
+ if oRes != nil && len(*oRes) > 0 &&
|
|
|
+ ((*oRes)["invoicing_entity"] == nil || qutil.InterfaceToStr((*oRes)["invoicing_entity"]) == config.InvoiceConfig.SigningSubject) {
|
|
|
+ var (
|
|
|
+ qSql string
|
|
|
+ errCode []string
|
|
|
+ //saveData []map[string]interface{}
|
|
|
+ resArr []map[string]interface{}
|
|
|
+ )
|
|
|
+ pCode := qutil.InterfaceToStr((*oRes)["order_code"])
|
|
|
+ //多订单联合开票
|
|
|
+ if invoice_order_code := qutil.InterfaceToStr((*oRes)["invoice_order_code"]); len(strings.Split(invoice_order_code, ",")) > 1 {
|
|
|
+ pCode = invoice_order_code
|
|
|
+ qSql = fmt.Sprintf(`SELECT * FROM invoice WHERE invoice_order_code = '%s' and invoice_changed = 0 and invoice_status = 1`, qutil.InterfaceToStr((*oRes)["invoice_order_code"]))
|
|
|
+ res1 := util.Mysql.SelectBySql(qSql)
|
|
|
+ if res1 != nil && len(*res1) > 0 {
|
|
|
+ resArr = *res1
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ resArr = append(resArr, *oRes)
|
|
|
+ }
|
|
|
+ var isMail bool
|
|
|
+ tm := time.Now()
|
|
|
+ for _, res := range resArr {
|
|
|
+ if res["only_Identifying"] == nil { //无唯一id 允许换票一次 生成唯一id
|
|
|
+ newUuid := uuid.New()
|
|
|
+ res["only_Identifying"] = newUuid
|
|
|
+ util.Mysql.Update(dbname, map[string]interface{}{"id": res["id"]}, map[string]interface{}{"only_Identifying": newUuid})
|
|
|
+ } else if util.Mysql.Count(dbname, map[string]interface{}{
|
|
|
+ "order_code": res["order_code"],
|
|
|
+ "user_id": res["user_id"],
|
|
|
+ "only_Identifying": res["only_Identifying"],
|
|
|
+ }) > 1 {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+ res["company_phone"] = this.GetString("company_phone")
|
|
|
+ res["operable_time"] = FormatDate(&tm, Date_Full_Layout)
|
|
|
+ res["bank_account"] = this.GetString("bank_account")
|
|
|
+ res["company_address"] = this.GetString("company_address")
|
|
|
+ res["bank_name"] = this.GetString("bank_name")
|
|
|
+ res["recipient"] = this.GetString("recipient")
|
|
|
+ res["delivery_address"] = this.GetString("delivery_address")
|
|
|
+ data := res
|
|
|
+ delete(data, "id")
|
|
|
+ switch IsEdit(res, phone, e_mail, id_num, company_name, invoice_type, invoiceContent, remark, invoiceVariety) {
|
|
|
+ case true:
|
|
|
+ data["phone"] = phone
|
|
|
+ data["mail"] = e_mail
|
|
|
+ data["invoice_content"] = invoiceContent
|
|
|
+ data["company_name"] = company_name
|
|
|
+ data["invoice_type"] = invoice_type
|
|
|
+ data["taxpayer_identnum"] = id_num
|
|
|
+ data["remark"] = remark
|
|
|
+ data["invoice_variety"] = invoiceVariety
|
|
|
+ //var html string
|
|
|
+ //if invoice_type == "个人" {
|
|
|
+ // emailHtml := emailHtml_gr
|
|
|
+ // emailHtmls := fmt.Sprintf(emailHtml, phone, e_mail)
|
|
|
+ // html = fmt.Sprintf(email_format, data["order_code"], data["url"], emailHtmls)
|
|
|
+ //} else {
|
|
|
+ // emailHtml := emailHtml_gs
|
|
|
+ // emailHtmls := fmt.Sprintf(emailHtml, company_name, id_num, phone, e_mail)
|
|
|
+ // html = fmt.Sprintf(email_format, data["order_code"], data["url"], emailHtmls)
|
|
|
+ //}
|
|
|
+ data["invoice_changed"] = 1
|
|
|
+ data["invoice_status"] = 1
|
|
|
+ data["billing_time"] = tm.Unix()
|
|
|
+ data["create_time"] = tm.Unix()
|
|
|
+ order_id := util.Mysql.Insert(dbname, data)
|
|
|
+ if order_id == -1 {
|
|
|
+ errCode = append(errCode, fmt.Sprintf("%s_%s", data["order_code"], data["invoice_order_code"]))
|
|
|
+ }
|
|
|
+ if !isMail { //成功发邮件
|
|
|
+ isMail = true
|
|
|
+ sendMail(invoice_type, pCode, company_name, id_num, e_mail, phone, qutil.InterfaceToStr(data["source_url"]), invoiceContent)
|
|
|
+ //InvoiceSendMail(data["mail"].(string), html, "电子发票")
|
|
|
+ }
|
|
|
+ case false:
|
|
|
+ if !config.InvoiceConfig.Third_party_switch {
|
|
|
+ this.ServeJson(map[string]interface{}{
|
|
|
+ "error_code": -2,
|
|
|
+ "error_msg": "暂不支持换票",
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ data["phone"] = phone
|
|
|
+ data["mail"] = e_mail
|
|
|
+ data["invoice_content"] = invoiceContent
|
|
|
+ data["company_name"] = company_name
|
|
|
+ data["invoice_type"] = invoice_type
|
|
|
+ data["taxpayer_identnum"] = id_num
|
|
|
+ data["remark"] = remark
|
|
|
+ data["invoice_variety"] = invoiceVariety
|
|
|
+ dataexport_data := make(map[string]interface{})
|
|
|
+ if invoice_type == "个人" {
|
|
|
+ dataexport_data["applyBill_type"] = 0
|
|
|
+ dataexport_data["applyBill_taxnum"] = ""
|
|
|
+ dataexport_data["applybill_company"] = ""
|
|
|
+ } else {
|
|
|
+ dataexport_data["applyBill_type"] = 1
|
|
|
+ dataexport_data["applyBill_taxnum"] = id_num
|
|
|
+ dataexport_data["applybill_company"] = company_name
|
|
|
+ }
|
|
|
+ dataexport_data["user_mail"] = e_mail
|
|
|
+ util.Mysql.Update("dataexport_order", map[string]interface{}{"order_code": res["order_code"]}, dataexport_data)
|
|
|
+ data["mail"] = e_mail
|
|
|
+ data["phone"] = phone
|
|
|
+ data["invoice_type"] = invoice_type
|
|
|
+ data["company_name"] = company_name
|
|
|
+ data["taxpayer_identnum"] = id_num
|
|
|
+ data["invoice_changed"] = 1
|
|
|
+ data["create_time"] = time.Now().Unix()
|
|
|
+ data["invoice_status"] = invoice_status
|
|
|
+ order_id := util.Mysql.Insert(dbname, data)
|
|
|
+ if order_id == -1 {
|
|
|
+ errCode = append(errCode, fmt.Sprintf("%s_%s", data["order_code"], data["invoice_order_code"]))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.Println("换票错误信息:", errCode)
|
|
|
+ this.ServeJson(map[string]interface{}{
|
|
|
+ "error_code": 0,
|
|
|
+ "error_msg": "",
|
|
|
+ })
|
|
|
+
|
|
|
+ } else {
|
|
|
+ this.ServeJson(map[string]interface{}{
|
|
|
+ "error_code": -1,
|
|
|
+ "error_msg": "订单状态异常",
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+func IsEdit(res map[string]interface{}, phone, e_mail, id_num, company_name, invoice_type, invoiceContent, remark, invoiceVariety string) bool {
|
|
|
+ if invoice_type == "个人" {
|
|
|
+ if phone == res["phone"] && e_mail == res["mail"] && res["invoice_type"] == "个人" &&
|
|
|
+ res["invoice_content"] == invoiceContent && res["remark"] == remark && res["invoice_variety"] == invoiceVariety {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if phone == res["phone"] && e_mail == res["mail"] && id_num == res["taxpayer_identnum"] &&
|
|
|
+ company_name == res["company_name"] && res["invoice_type"] == "单位" &&
|
|
|
+ res["invoice_content"] == invoiceContent && res["remark"] == remark && res["invoice_variety"] == invoiceVariety {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false
|
|
|
+}
|
|
|
+
|
|
|
// 退票
|
|
|
func (this *Invoice) Refundinvoice() {
|
|
|
if !config.InvoiceConfig.Third_party_switch {
|
|
@@ -1077,6 +1353,15 @@ func (this *Invoice) Invoiceinfo() {
|
|
|
}
|
|
|
delete((*status), "d_relation_id")
|
|
|
(*status)["countdown"] = countdowntime
|
|
|
+ var isCanInvoic bool
|
|
|
+ create_time, _ := time.ParseInLocation(Date_Full_Layout, qutil.ObjToString((*status)["create_time"]), time.Local)
|
|
|
+ if create_time.Unix() > config.InvoiceConfig.Order_createtime {
|
|
|
+ //剩余可开票金额
|
|
|
+ isCanInvoic = IsAllowInvoice(*status)
|
|
|
+ }
|
|
|
+ (*status)["is_can_invoice"] = isCanInvoic
|
|
|
+ //是否存在可查看发票
|
|
|
+ (*status)["invoice_show"] = len(ShowList(order_code)) > 0
|
|
|
this.ServeJson(map[string]interface{}{
|
|
|
"status": "success",
|
|
|
"data": status,
|
|
@@ -1114,6 +1399,30 @@ func LastInvoiceSource(orderCode string) int64 {
|
|
|
}
|
|
|
return 0
|
|
|
}
|
|
|
+
|
|
|
+// 是否可开票
|
|
|
+func IsAllowInvoice(res map[string]interface{}) bool {
|
|
|
+ if qutil.IntAll(res["applybill_status"]) > 0 {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ if qutil.Float64All(res["pay_money"]) == 0 {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ filter := qutil.ObjToString(res["filter"].(string))
|
|
|
+ filter_map := map[string]interface{}{}
|
|
|
+ _ = json.Unmarshal([]byte(filter), &filter_map)
|
|
|
+ if qutil.IntAll(res["order_status"]) == 1 && qutil.InterfaceToStr(filter_map["badge"]) != "exchange" {
|
|
|
+ //用户下单|| 代用户下单
|
|
|
+ if qutil.IntAll(res["is_backstage_order"]) == 0 || qutil.InterfaceToStr(res["order_channel"]) == "xdqd04" {
|
|
|
+ return len(ShowList(qutil.InterfaceToStr(res["order_code"]))) == 0
|
|
|
+ } else { //qmx下单 已全额回款 发票企业为剑鱼
|
|
|
+ return qutil.IntAll(res["return_status"]) == 1 && qutil.InterfaceToStr(res["signing_subject"]) == "h01" &&
|
|
|
+ len(ShowList(qutil.InterfaceToStr(res["order_code"]))) == 0
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false
|
|
|
+}
|
|
|
+
|
|
|
func (this *Invoice) Available() {
|
|
|
u := util.Mysql.FindOne("dataexport_order", map[string]interface{}{"order_code": this.GetString("order_code")}, "pay_time", "")
|
|
|
status := 0
|
|
@@ -1134,6 +1443,8 @@ func (this *Invoice) Available() {
|
|
|
status = 1
|
|
|
}
|
|
|
}
|
|
|
+ } else {
|
|
|
+ status = 1
|
|
|
}
|
|
|
}
|
|
|
this.ServeJson(map[string]interface{}{
|
|
@@ -1150,22 +1461,182 @@ func delReplaceInvoice(query map[string]interface{}) bool {
|
|
|
return util.Mysql.Delete(dbname, query)
|
|
|
}
|
|
|
|
|
|
-// 发票信息提交
|
|
|
+func InvoiceAmount(orderCode string) (invoicedMoney int64) {
|
|
|
+ invoicedInfo := util.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[qutil.InterfaceToStr(m["only_Identifying"])] = qutil.Int64All(m["invoice_order_money"])
|
|
|
+ } else {
|
|
|
+ invoicedMoney += qutil.Int64All(m["invoice_order_money"])
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if len(onlyMap) > 0 {
|
|
|
+ for _, i := range onlyMap {
|
|
|
+ invoicedMoney += i
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// InvoiceSubmit 发票信息提交
|
|
|
func (this *Invoice) InvoiceSubmit() {
|
|
|
+ if !R.CheckReqParam(this.ResponseWriter, this.Request, "invoice_variety", "invoiceContent", "invoice_type", "phone", "mail") {
|
|
|
+ this.ServeJson(NewResult("", errors.New("缺少参数")))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if this.GetString("invoice_type") == "单位" && !R.CheckReqParam(this.ResponseWriter, this.Request, "company_name", "taxpayer_identnum") {
|
|
|
+ this.ServeJson(NewResult("", errors.New("缺少参数")))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if !config.InvoiceConfig.Invoice_type[this.GetString("invoice_variety")] {
|
|
|
+ this.ServeJson(NewResult("", errors.New("发票类型有误")))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if this.GetString("invoice_type") != "个人" && this.GetString("invoice_type") != "单位" {
|
|
|
+ this.ServeJson(NewResult("", errors.New("发票抬头有误")))
|
|
|
+ return
|
|
|
+ }
|
|
|
now := time.Now()
|
|
|
- onlyIdentifying := encrypt.SE.DecodeString(this.GetString("onlyIdentifying"))
|
|
|
- invoiceMoney := encrypt.SE.DecodeString(this.GetString("invoiceMoney"))
|
|
|
- operator := encrypt.SE.Decode4HexByCheck(this.GetString("operator"))
|
|
|
- if onlyIdentifying == "" || invoiceMoney == "" {
|
|
|
- this.ServeJson(NewResult("", errors.New("传入参数不正确")))
|
|
|
+ again, _ := this.GetInteger("again") //是否是失败重新开票 0 首次提交 1 再此提交
|
|
|
+ oldOnlyIdentifying := encrypt.SE.DecodeString(this.GetString("oldOnlyIdentifying")) //最后一次失败的发票信息唯一标识
|
|
|
+ data := map[string]interface{}{
|
|
|
+ "company_name": this.GetString("company_name"),
|
|
|
+ "phone": this.GetString("phone"),
|
|
|
+ "mail": this.GetString("mail"),
|
|
|
+ "invoice_type": this.GetString("invoice_type"),
|
|
|
+ "invoice_content": this.GetString("invoiceContent"),
|
|
|
+ "invoice_status": 0,
|
|
|
+ "invoice_changed": 0,
|
|
|
+ "company_phone": this.GetString("company_phone"),
|
|
|
+ "taxpayer_identnum": this.GetString("taxpayer_identnum"),
|
|
|
+ "create_time": time.Now().Unix(),
|
|
|
+ "operable_time": FormatDate(&now, Date_Full_Layout),
|
|
|
+ "invoicing_entity": "北京剑鱼信息技术有限公司",
|
|
|
+ "remark": this.GetString("remark"),
|
|
|
+ "invoice_variety": this.GetString("invoice_variety"),
|
|
|
+ "bank_account": this.GetString("bank_account"),
|
|
|
+ "company_address": this.GetString("company_address"),
|
|
|
+ "bank_name": this.GetString("bank_name"),
|
|
|
+ "recipient": this.GetString("recipient"),
|
|
|
+ "delivery_address": this.GetString("delivery_address"),
|
|
|
+ }
|
|
|
+ if again == 1 {
|
|
|
+ err := OpenInvoiceAgain(oldOnlyIdentifying, data)
|
|
|
+ if err != nil {
|
|
|
+ this.ServeJson(NewResult("", err))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ this.ServeJson(NewResult("保存信息成功", nil))
|
|
|
return
|
|
|
}
|
|
|
- data := util.Mysql.FindOne("invoice", map[string]interface{}{
|
|
|
+ source, _ := this.GetInteger("source")
|
|
|
+ switch source {
|
|
|
+ case 0: //用户端开票
|
|
|
+ userId := qutil.ObjToString(this.GetSession("userId"))
|
|
|
+ if userId == "" {
|
|
|
+ this.ServeJson(NewResult("", errors.New("userId为空")))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ orderCode := this.GetString("order_code")
|
|
|
+ err := JyOpenInvoice(orderCode, userId, data)
|
|
|
+ if err != nil {
|
|
|
+ this.ServeJson(NewResult("", err))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ case 1: //管理后台扫码开票
|
|
|
+ onlyIdentifying := encrypt.SE.DecodeString(this.GetString("onlyIdentifying"))
|
|
|
+ invoiceMoney := encrypt.SE.DecodeString(this.GetString("invoiceMoney"))
|
|
|
+ operator := encrypt.SE.Decode4HexByCheck(this.GetString("operator"))
|
|
|
+ if onlyIdentifying == "" || invoiceMoney == "" {
|
|
|
+ this.ServeJson(NewResult("", errors.New("传入参数不正确")))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ err := AdminOpenInvoice(onlyIdentifying, invoiceMoney, operator, data)
|
|
|
+ if err != nil {
|
|
|
+ this.ServeJson(NewResult("", err))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.ServeJson(NewResult("保存信息成功", nil))
|
|
|
+}
|
|
|
+
|
|
|
+func OpenInvoiceAgain(oldOnlyIdentifying string, data map[string]interface{}) error {
|
|
|
+ if oldOnlyIdentifying == "" {
|
|
|
+ return errors.New("缺少关键参数")
|
|
|
+ }
|
|
|
+ if util.Mysql.Count("invoice_fail_record", map[string]interface{}{"only_Identifying": oldOnlyIdentifying}) >= config.InvoiceConfig.SubmitNum {
|
|
|
+ return errors.New("提交次数已达上限")
|
|
|
+ }
|
|
|
+ ok := InvoiceFailRecord(oldOnlyIdentifying)
|
|
|
+ if !ok {
|
|
|
+ return errors.New("插入失败记录出错")
|
|
|
+ }
|
|
|
+ delete(data, "invoice_changed")
|
|
|
+ if !util.Mysql.Update("invoice", map[string]interface{}{"only_Identifying": oldOnlyIdentifying, "invoice_status": -1}, data) {
|
|
|
+ return errors.New("再次开票更新发票信息出错")
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
+func JyOpenInvoice(orderCode, userId string, data map[string]interface{}) error {
|
|
|
+ onlyIdentifying := fmt.Sprintf("%s%s%s", "aa", time.Now().Format("150405"), qutil.GetRandom(4))
|
|
|
+ orderInfo := util.Mysql.FindOne("dataexport_order", map[string]interface{}{"order_code": orderCode}, "product_type,user_mail,pay_money,create_time,signing_subject,applybill_status", "")
|
|
|
+ if orderInfo == nil {
|
|
|
+ return errors.New("订单不存在")
|
|
|
+ }
|
|
|
+ createTime, _ := time.ParseInLocation("2006-01-02 15:04:05", qutil.ObjToString((*orderInfo)["create_time"]), time.Local)
|
|
|
+ if createTime.Unix() < config.InvoiceConfig.Order_createtime {
|
|
|
+ return errors.New("2024年之前的订单不在开票")
|
|
|
+ }
|
|
|
+ if qutil.ObjToString((*orderInfo)["signing_subject"]) == "h02" {
|
|
|
+ return errors.New("签约主体为拓普")
|
|
|
+ }
|
|
|
+ /*if qutil.IntAll((*orderInfo)["applybill_status"]) != 0 {
|
|
|
+ return errors.New("已提交发票信息")
|
|
|
+ }*/
|
|
|
+ invoicedMoney := InvoiceAmount(orderCode) //已开票金额
|
|
|
+ invoiceMoney := qutil.Int64All((*orderInfo)["pay_money"]) - invoicedMoney
|
|
|
+ data["order_code"] = orderCode
|
|
|
+ data["invoice_order_code"] = orderCode
|
|
|
+ data["only_Identifying"] = onlyIdentifying
|
|
|
+ data["invoice_money"] = invoiceMoney
|
|
|
+ data["invoice_order_money"] = invoiceMoney
|
|
|
+ data["product_type"] = qutil.ObjToString((*orderInfo)["product_type"])
|
|
|
+ data["user_id"] = userId
|
|
|
+ data["source"] = 0
|
|
|
+ if !util.Mysql.ExecTx("用户端开发票", func(tx *sql.Tx) bool {
|
|
|
+ if util.Mysql.InsertByTx(tx, "invoice", data) <= 0 {
|
|
|
+ log.Println("插入invoice出错", orderCode)
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ if !util.Mysql.UpdateByTx(tx, "dataexport_order", map[string]interface{}{
|
|
|
+ "order_code": orderCode,
|
|
|
+ }, map[string]interface{}{
|
|
|
+ "applybill_status": 1,
|
|
|
+ }) {
|
|
|
+ log.Println("更新dataexport_order出错", orderCode)
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ return true
|
|
|
+ }) {
|
|
|
+ return errors.New("用户端开票插入数据出错")
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
+func AdminOpenInvoice(onlyIdentifying, invoiceMoney, operator string, data map[string]interface{}) error {
|
|
|
+ //二维码
|
|
|
+ path := "/front/invoiceScan/qr"
|
|
|
+ urlStr := fmt.Sprintf("onlyIdentifying=%s&invoiceMoney=%s&operator=%s", encrypt.SE.EncodeString(onlyIdentifying), encrypt.SE.EncodeString(invoiceMoney), encrypt.SE.Encode2HexByCheck(operator))
|
|
|
+ fullUrl := path + "?" + urlStr
|
|
|
+ oldData := util.Mysql.FindOne("invoice", map[string]interface{}{
|
|
|
"only_Identifying": onlyIdentifying,
|
|
|
}, "id", "")
|
|
|
- if data != nil {
|
|
|
- this.ServeJson(NewResult("", errors.New("该订单发票信息已经提交过申请")))
|
|
|
- return
|
|
|
+ if oldData != nil {
|
|
|
+ return errors.New("该订单发票信息已经提交过申请")
|
|
|
}
|
|
|
orderArr := []string{}
|
|
|
mailOrderArr := []string{}
|
|
@@ -1184,49 +1655,33 @@ func (this *Invoice) InvoiceSubmit() {
|
|
|
//提交时订单金额再做一次校验
|
|
|
for orderCode, money := range orderMap {
|
|
|
if ResidueMoney(orderCode) < qutil.Int64All(money) {
|
|
|
- this.ServeJson(NewResult("", errors.New("该订单发票信息已经提交过申请")))
|
|
|
- return
|
|
|
+ return errors.New("该订单发票信息已经提交过申请")
|
|
|
}
|
|
|
}
|
|
|
if !util.Mysql.ExecTx("发票信息保存", func(tx *sql.Tx) bool {
|
|
|
for orderCode, money := range orderMap {
|
|
|
- userId := GetUserId(orderCode)
|
|
|
- orderInfo := util.Mysql.FindOne("dataexport_order", map[string]interface{}{"order_code": orderCode}, "product_type,user_mail", "")
|
|
|
+ orderInfo := util.Mysql.FindOne("dataexport_order", map[string]interface{}{"order_code": orderCode}, "product_type,user_mail,user_id,create_time", "")
|
|
|
productType := ""
|
|
|
if orderInfo != nil {
|
|
|
productType = qutil.InterfaceToStr((*orderInfo)["product_type"])
|
|
|
}
|
|
|
- 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"),
|
|
|
- "product_type": productType,
|
|
|
+ createTime, _ := time.ParseInLocation("2006-01-02 15:04:05", qutil.ObjToString((*orderInfo)["create_time"]), time.Local)
|
|
|
+ if createTime.Unix() < config.InvoiceConfig.Order_createtime {
|
|
|
+ log.Println("2024年之前的订单不在开票", orderCode)
|
|
|
+ return false
|
|
|
}
|
|
|
+ data["order_code"] = orderCode
|
|
|
+ data["invoice_order_code"] = strings.Join(orderArr, ",")
|
|
|
+ data["only_Identifying"] = onlyIdentifying
|
|
|
+ data["invoice_money"] = Allmoney
|
|
|
+ data["invoice_order_money"] = money
|
|
|
+ data["product_type"] = productType
|
|
|
+ data["user_id"] = qutil.ObjToString((*orderInfo)["user_id"])
|
|
|
+ data["operator"] = operator
|
|
|
+ data["source"] = 1
|
|
|
+ data["code_url"] = fullUrl
|
|
|
if util.Mysql.Insert("invoice", data) <= 0 {
|
|
|
+ log.Println("扫码开票插入invoice表出错", orderCode)
|
|
|
return false
|
|
|
}
|
|
|
//订单发票状态改成已申请
|
|
@@ -1235,85 +1690,48 @@ func (this *Invoice) InvoiceSubmit() {
|
|
|
}, map[string]interface{}{
|
|
|
"applybill_status": 1,
|
|
|
}) {
|
|
|
+ log.Println("扫码开票更新dataexport_order表出错", orderCode)
|
|
|
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"] = "个人"
|
|
|
- }
|
|
|
- if config.InvoiceConfig.Third_party_switch {
|
|
|
- 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
|
|
|
+ }) {
|
|
|
+ return errors.New("发票信息保存失败")
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
+func InvoiceFailRecord(oldOnlyIdentifying string) bool {
|
|
|
+ //开票失败再次提交
|
|
|
+ invoiceData := util.Mysql.Find("invoice", map[string]interface{}{"only_Identifying": oldOnlyIdentifying, "invoice_status": -1}, "", "", -1, -1)
|
|
|
+ if invoiceData == nil && len(*invoiceData) <= 0 {
|
|
|
+ log.Println("未找到开票记录", oldOnlyIdentifying)
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ //插入开票失败记录表
|
|
|
+ ok := util.Mysql.ExecTx("插入开票失败记录表", func(tx *sql.Tx) bool {
|
|
|
+ for _, val := range *invoiceData {
|
|
|
+ delete(val, "id")
|
|
|
+ delete(val, "code_url")
|
|
|
+ if util.Mysql.InsertByTx(tx, "invoice_fail_record", val) <= 0 {
|
|
|
+ return false
|
|
|
}
|
|
|
}
|
|
|
return true
|
|
|
- }) {
|
|
|
- this.ServeJson(NewResult("", errors.New("发票信息保存失败")))
|
|
|
- return
|
|
|
+ })
|
|
|
+ return ok
|
|
|
+}
|
|
|
+
|
|
|
+func (this *Invoice) GetCompanyCode() {
|
|
|
+ code := ""
|
|
|
+ companyInfo := util.Mysql.FindOne("entniche_info", map[string]interface{}{"name": this.GetString("companyName")}, "code", "")
|
|
|
+ if companyInfo != nil && len(*companyInfo) > 0 {
|
|
|
+ code = qutil.ObjToString((*companyInfo)["code"])
|
|
|
}
|
|
|
- this.ServeJson(NewResult("保存信息成功", nil))
|
|
|
+ this.ServeJson(NewResult(map[string]interface{}{
|
|
|
+ "code": code,
|
|
|
+ }, nil))
|
|
|
+ return
|
|
|
}
|
|
|
|
|
|
// 发票信息查询
|
|
@@ -1334,7 +1752,7 @@ func (this *Invoice) InvoiceQuery() {
|
|
|
}
|
|
|
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", "")
|
|
|
+ }, "id,invoice_changed,order_code, invoice_order_code,bank_account,invoice_code, create_time,invoice_number,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,only_Identifying", " create_time DESC")
|
|
|
companyName := ""
|
|
|
if invoiceOne == nil {
|
|
|
//查询公司名称
|
|
@@ -1343,13 +1761,38 @@ func (this *Invoice) InvoiceQuery() {
|
|
|
if orderArr != nil && len(*orderArr) > 0 {
|
|
|
companyName = qutil.ObjToString((*orderArr)[0]["company_name"])
|
|
|
}
|
|
|
+ } else {
|
|
|
+ (*invoiceOne)["order_code"] = qutil.If((*invoiceOne)["invoice_order_code"] != nil, (*invoiceOne)["invoice_order_code"], (*invoiceOne)["order_code"])
|
|
|
+ (*invoiceOne)["id"] = encrypt.SE.Encode2Hex(qutil.InterfaceToStr((*invoiceOne)["id"]))
|
|
|
+ timeLimit := qutil.Int64All((*invoiceOne)["create_time"]) <= config.InvoiceConfig.Order_createtime //24年之前的发票不让换票
|
|
|
+ switch qutil.IntAll((*invoiceOne)["invoice_status"]) {
|
|
|
+ case 1:
|
|
|
+ isJyInvoice := !(qutil.InterfaceToStr((*invoiceOne)["invoice_number"]) != "" && qutil.InterfaceToStr((*invoiceOne)["invoice_code"]) == "") //非数电票
|
|
|
+ isJyEntity := (*invoiceOne)["invoicing_entity"] != nil && qutil.InterfaceToStr((*invoiceOne)["invoicing_entity"]) != config.InvoiceConfig.SigningSubject
|
|
|
+ isChanged := util.Mysql.Count("invoice", map[string]interface{}{
|
|
|
+ "only_Identifying": onlyIdentifying,
|
|
|
+ "order_code": (*invoiceOne)["order_code"],
|
|
|
+ }) > 1
|
|
|
+ (*invoiceOne)["changed"] = qutil.If(isJyInvoice || isChanged || isJyEntity || timeLimit, true, false)
|
|
|
+ case -1: //失败支持重新提交否
|
|
|
+ if !timeLimit {
|
|
|
+ (*invoiceOne)["isReopen"] = util.Mysql.Count("invoice_fail_record", map[string]interface{}{
|
|
|
+ "only_Identifying": onlyIdentifying,
|
|
|
+ "order_code": (*invoiceOne)["order_code"],
|
|
|
+ })+1 >= config.InvoiceConfig.SubmitNum
|
|
|
+ } else {
|
|
|
+ (*invoiceOne)["isReopen"] = false
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
this.ServeJson(NewResult(map[string]interface{}{
|
|
|
"orderCodes": strings.Join(orderArr, ","),
|
|
|
"money": money,
|
|
|
"invoice": &invoiceOne,
|
|
|
"operator": operator,
|
|
|
"company_name": companyName,
|
|
|
+ "isFollowWx": 1,
|
|
|
}, nil))
|
|
|
}
|
|
|
|
|
@@ -1388,7 +1831,7 @@ func htjs(body map[string]interface{}, orderCode []string, invoiceType, companyN
|
|
|
defer response.Body.Close()
|
|
|
resData := (*resMap)["data"].(map[string]interface{})
|
|
|
if invoice_status == 1 {
|
|
|
- sendMail(invoiceType, strings.Join(orderCode, ","), companyName, taxpayerIdentnum, mail, phone, qutil.InterfaceToStr(resData["path"]))
|
|
|
+ sendMail(invoiceType, strings.Join(orderCode, ","), companyName, taxpayerIdentnum, mail, phone, qutil.InterfaceToStr(resData["path"]), "")
|
|
|
}
|
|
|
for _, v := range orderCode {
|
|
|
util.Mysql.Update(dbname, map[string]interface{}{"order_code": v, "invoice_status": 0}, map[string]interface{}{
|
|
@@ -1434,20 +1877,30 @@ func InvoiceStatusHandle(orderCode string) bool {
|
|
|
}
|
|
|
|
|
|
// 电子普票发邮箱
|
|
|
-func sendMail(invoiceType, orderCode, companyName, taxpayerIdentnum, mail, phone, url string) {
|
|
|
+func sendMail(invoiceType, orderCode, companyName, taxpayerIdentnum, mail, phone, url, invoiceContent 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)
|
|
|
+ html := fmt.Sprintf(email_format, orderCode, "电子普通发票", fmt.Sprintf("<a href=\"%s\" download class=\"download\">查看发票</a>", url), "电子普通发票", invoiceContent, 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)
|
|
|
+ html := fmt.Sprintf(email_format, orderCode, "电子普通发票", fmt.Sprintf("<a href=\"%s\" download class=\"download\">查看发票</a>", url), "电子普通发票", invoiceContent, emailHtmls)
|
|
|
InvoiceSendMail(mail, html, "电子发票")
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// 剩余金额
|
|
|
+func InvoicePrice(orderData map[string]interface{}) int64 {
|
|
|
+ residueMoney := int64(0)
|
|
|
+ if qutil.Int64All(orderData["applybill_status"]) == 2 {
|
|
|
+ return residueMoney
|
|
|
+ }
|
|
|
+
|
|
|
+ return qutil.Int64All(orderData["pay_money"]) - InvoiceAmount(qutil.InterfaceToStr(orderData["order_code"]))
|
|
|
+}
|
|
|
+
|
|
|
// 订单剩余金额查询
|
|
|
func ResidueMoney(orderCode string) int64 {
|
|
|
residueMoney := int64(0)
|
|
@@ -1456,26 +1909,25 @@ func ResidueMoney(orderCode string) int64 {
|
|
|
if len(*orderData) == 0 || orderData == nil {
|
|
|
return residueMoney
|
|
|
}
|
|
|
- if qutil.Int64All((*orderData)[0]["applybill_status"]) == 2 {
|
|
|
- return residueMoney
|
|
|
- }
|
|
|
+ return InvoicePrice((*orderData)[0])
|
|
|
+
|
|
|
//发票信息查询
|
|
|
- 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
|
|
|
+ //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
|
|
|
}
|