|
@@ -1121,7 +1121,7 @@ func (this *Invoice) NewReplaceinvoice() {
|
|
//userId := qutil.ObjToString(this.GetSession("userId")) 支持扫描换票
|
|
//userId := qutil.ObjToString(this.GetSession("userId")) 支持扫描换票
|
|
//order_code := this.GetString("order_code")
|
|
//order_code := this.GetString("order_code")
|
|
sid := encrypt.SE.Decode4Hex(this.GetString("sid"))
|
|
sid := encrypt.SE.Decode4Hex(this.GetString("sid"))
|
|
- oRes := util.Mysql.FindOne(dbname, map[string]interface{}{"id": sid, "invoice_changed": 0}, "", "") //仅线上开发票可换票
|
|
|
|
|
|
+ oRes := util.Mysql.FindOne(dbname, map[string]interface{}{"id": sid, "invoice_changed": 0, "invoice_status": 1}, "", "") //仅线上开发票可换票
|
|
if oRes != nil && len(*oRes) > 0 &&
|
|
if oRes != nil && len(*oRes) > 0 &&
|
|
((*oRes)["invoicing_entity"] == nil || qutil.InterfaceToStr((*oRes)["invoicing_entity"]) == config.InvoiceConfig.SigningSubject) {
|
|
((*oRes)["invoicing_entity"] == nil || qutil.InterfaceToStr((*oRes)["invoicing_entity"]) == config.InvoiceConfig.SigningSubject) {
|
|
var (
|
|
var (
|
|
@@ -1130,19 +1130,16 @@ func (this *Invoice) NewReplaceinvoice() {
|
|
//saveData []map[string]interface{}
|
|
//saveData []map[string]interface{}
|
|
resArr []map[string]interface{}
|
|
resArr []map[string]interface{}
|
|
)
|
|
)
|
|
- if qutil.IntAll((*oRes)["invoice_status"]) == -2 {
|
|
|
|
- this.ServeJson(map[string]interface{}{
|
|
|
|
- "invoice_status": -2,
|
|
|
|
- })
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
|
|
+ pCode := qutil.InterfaceToStr((*oRes)["order_code"])
|
|
|
|
+ //多订单联合开票
|
|
if invoice_order_code := qutil.InterfaceToStr((*oRes)["invoice_order_code"]); len(strings.Split(invoice_order_code, ",")) > 1 {
|
|
if invoice_order_code := qutil.InterfaceToStr((*oRes)["invoice_order_code"]); len(strings.Split(invoice_order_code, ",")) > 1 {
|
|
- qSql = fmt.Sprintf(`SELECT * FROM invoice WHERE invoice_order_code = '%s' `, qutil.InterfaceToStr((*oRes)["invoice_order_code"]))
|
|
|
|
|
|
+ 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)
|
|
res1 := util.Mysql.SelectBySql(qSql)
|
|
if res1 != nil && len(*res1) > 0 {
|
|
if res1 != nil && len(*res1) > 0 {
|
|
resArr = *res1
|
|
resArr = *res1
|
|
}
|
|
}
|
|
- } else { //多订单联合开票
|
|
|
|
|
|
+ } else {
|
|
resArr = append(resArr, *oRes)
|
|
resArr = append(resArr, *oRes)
|
|
}
|
|
}
|
|
var isMail bool
|
|
var isMail bool
|
|
@@ -1159,55 +1156,65 @@ func (this *Invoice) NewReplaceinvoice() {
|
|
}) > 1 {
|
|
}) > 1 {
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
- res["phone"] = phone
|
|
|
|
- res["mail"] = e_mail
|
|
|
|
- res["invoice_content"] = invoiceContent
|
|
|
|
|
|
+
|
|
res["company_phone"] = this.GetString("company_phone")
|
|
res["company_phone"] = this.GetString("company_phone")
|
|
- res["taxpayer_identnum"] = id_num
|
|
|
|
res["operable_time"] = FormatDate(&tm, Date_Full_Layout)
|
|
res["operable_time"] = FormatDate(&tm, Date_Full_Layout)
|
|
- res["remark"] = remark
|
|
|
|
- res["invoice_variety"] = invoiceVariety
|
|
|
|
res["bank_account"] = this.GetString("bank_account")
|
|
res["bank_account"] = this.GetString("bank_account")
|
|
res["company_address"] = this.GetString("company_address")
|
|
res["company_address"] = this.GetString("company_address")
|
|
res["bank_name"] = this.GetString("bank_name")
|
|
res["bank_name"] = this.GetString("bank_name")
|
|
res["recipient"] = this.GetString("recipient")
|
|
res["recipient"] = this.GetString("recipient")
|
|
res["delivery_address"] = this.GetString("delivery_address")
|
|
res["delivery_address"] = this.GetString("delivery_address")
|
|
- res["company_name"] = company_name
|
|
|
|
- res["invoice_type"] = invoice_type
|
|
|
|
data := res
|
|
data := res
|
|
delete(data, "id")
|
|
delete(data, "id")
|
|
switch IsEdit(res, phone, e_mail, id_num, company_name, invoice_type, invoiceContent, remark, invoiceVariety) {
|
|
switch IsEdit(res, phone, e_mail, id_num, company_name, invoice_type, invoiceContent, remark, invoiceVariety) {
|
|
case true:
|
|
case true:
|
|
- var html string
|
|
|
|
- if invoice_type == "个人" {
|
|
|
|
- emailHtml := emailHtml_gr
|
|
|
|
- emailHtmls := fmt.Sprintf(emailHtml, phone, e_mail)
|
|
|
|
- html = fmt.Sprintf(email_format, res["order_code"], res["url"], emailHtmls)
|
|
|
|
- } else {
|
|
|
|
- emailHtml := emailHtml_gs
|
|
|
|
- emailHtmls := fmt.Sprintf(emailHtml, company_name, id_num, phone, e_mail)
|
|
|
|
- html = fmt.Sprintf(email_format, res["order_code"], res["url"], emailHtmls)
|
|
|
|
- }
|
|
|
|
|
|
+ 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_changed"] = 1
|
|
data["invoice_status"] = 1
|
|
data["invoice_status"] = 1
|
|
data["billing_time"] = tm.Unix()
|
|
data["billing_time"] = tm.Unix()
|
|
data["create_time"] = tm.Unix()
|
|
data["create_time"] = tm.Unix()
|
|
order_id := util.Mysql.Insert(dbname, data)
|
|
order_id := util.Mysql.Insert(dbname, data)
|
|
if order_id == -1 {
|
|
if order_id == -1 {
|
|
- errCode = append(errCode, fmt.Sprintf("%s_%s", res["order_code"], res["invoice_order_code"]))
|
|
|
|
|
|
+ errCode = append(errCode, fmt.Sprintf("%s_%s", data["order_code"], data["invoice_order_code"]))
|
|
}
|
|
}
|
|
if !isMail { //成功发邮件
|
|
if !isMail { //成功发邮件
|
|
isMail = true
|
|
isMail = true
|
|
- InvoiceSendMail(res["mail"].(string), html, "电子发票")
|
|
|
|
|
|
+ sendMail(invoice_type, pCode, company_name, id_num, e_mail, phone, qutil.InterfaceToStr(data["url"]), invoiceContent)
|
|
|
|
+ //InvoiceSendMail(data["mail"].(string), html, "电子发票")
|
|
}
|
|
}
|
|
case false:
|
|
case false:
|
|
- 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
|
|
|
|
|
|
+ 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{})
|
|
dataexport_data := make(map[string]interface{})
|
|
if invoice_type == "个人" {
|
|
if invoice_type == "个人" {
|
|
dataexport_data["applyBill_type"] = 0
|
|
dataexport_data["applyBill_type"] = 0
|
|
@@ -1230,20 +1237,20 @@ func (this *Invoice) NewReplaceinvoice() {
|
|
data["invoice_status"] = invoice_status
|
|
data["invoice_status"] = invoice_status
|
|
order_id := util.Mysql.Insert(dbname, data)
|
|
order_id := util.Mysql.Insert(dbname, data)
|
|
if order_id == -1 {
|
|
if order_id == -1 {
|
|
- errCode = append(errCode, fmt.Sprintf("%s_%s", res["order_code"], res["invoice_order_code"]))
|
|
|
|
|
|
+ errCode = append(errCode, fmt.Sprintf("%s_%s", data["order_code"], data["invoice_order_code"]))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
log.Println("换票错误信息:", errCode)
|
|
log.Println("换票错误信息:", errCode)
|
|
- if !config.InvoiceConfig.Third_party_switch {
|
|
|
|
- this.ServeJson(map[string]interface{}{
|
|
|
|
- "invoice_status": invoice_status,
|
|
|
|
- })
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
|
|
+ this.ServeJson(map[string]interface{}{
|
|
|
|
+ "error_code": 0,
|
|
|
|
+ "error_msg": "",
|
|
|
|
+ })
|
|
|
|
+
|
|
} else {
|
|
} else {
|
|
this.ServeJson(map[string]interface{}{
|
|
this.ServeJson(map[string]interface{}{
|
|
- "invoice_status": -1,
|
|
|
|
|
|
+ "error_code": -1,
|
|
|
|
+ "error_msg": "订单状态异常",
|
|
})
|
|
})
|
|
return
|
|
return
|
|
}
|
|
}
|
|
@@ -1252,7 +1259,8 @@ func (this *Invoice) NewReplaceinvoice() {
|
|
|
|
|
|
func IsEdit(res map[string]interface{}, phone, e_mail, id_num, company_name, invoice_type, invoiceContent, remark, invoiceVariety string) bool {
|
|
func IsEdit(res map[string]interface{}, phone, e_mail, id_num, company_name, invoice_type, invoiceContent, remark, invoiceVariety string) bool {
|
|
if invoice_type == "个人" {
|
|
if invoice_type == "个人" {
|
|
- if phone == res["phone"] && e_mail == res["mail"] && res["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
|
|
return true
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
@@ -1595,6 +1603,10 @@ func JyOpenInvoice(orderCode, userId string, data map[string]interface{}) error
|
|
}
|
|
}
|
|
|
|
|
|
func AdminOpenInvoice(onlyIdentifying, invoiceMoney, operator string, data map[string]interface{}) error {
|
|
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 := config.InvoiceConfig.Admin_webdomain + path + "?" + urlStr
|
|
oldData := util.Mysql.FindOne("invoice", map[string]interface{}{
|
|
oldData := util.Mysql.FindOne("invoice", map[string]interface{}{
|
|
"only_Identifying": onlyIdentifying,
|
|
"only_Identifying": onlyIdentifying,
|
|
}, "id", "")
|
|
}, "id", "")
|
|
@@ -1642,6 +1654,7 @@ func AdminOpenInvoice(onlyIdentifying, invoiceMoney, operator string, data map[s
|
|
data["user_id"] = qutil.ObjToString((*orderInfo)["user_id"])
|
|
data["user_id"] = qutil.ObjToString((*orderInfo)["user_id"])
|
|
data["operator"] = operator
|
|
data["operator"] = operator
|
|
data["source"] = 1
|
|
data["source"] = 1
|
|
|
|
+ data["code_url"] = fullUrl
|
|
if util.Mysql.Insert("invoice", data) <= 0 {
|
|
if util.Mysql.Insert("invoice", data) <= 0 {
|
|
log.Println("扫码开票插入invoice表出错", orderCode)
|
|
log.Println("扫码开票插入invoice表出错", orderCode)
|
|
return false
|
|
return false
|
|
@@ -1674,6 +1687,7 @@ func InvoiceFailRecord(oldOnlyIdentifying string) bool {
|
|
ok := util.Mysql.ExecTx("插入开票失败记录表", func(tx *sql.Tx) bool {
|
|
ok := util.Mysql.ExecTx("插入开票失败记录表", func(tx *sql.Tx) bool {
|
|
for _, val := range *invoiceData {
|
|
for _, val := range *invoiceData {
|
|
delete(val, "id")
|
|
delete(val, "id")
|
|
|
|
+ delete(val, "code_url")
|
|
if util.Mysql.InsertByTx(tx, "invoice_fail_record", val) <= 0 {
|
|
if util.Mysql.InsertByTx(tx, "invoice_fail_record", val) <= 0 {
|
|
return false
|
|
return false
|
|
}
|
|
}
|
|
@@ -1783,7 +1797,7 @@ func htjs(body map[string]interface{}, orderCode []string, invoiceType, companyN
|
|
defer response.Body.Close()
|
|
defer response.Body.Close()
|
|
resData := (*resMap)["data"].(map[string]interface{})
|
|
resData := (*resMap)["data"].(map[string]interface{})
|
|
if invoice_status == 1 {
|
|
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 {
|
|
for _, v := range orderCode {
|
|
util.Mysql.Update(dbname, map[string]interface{}{"order_code": v, "invoice_status": 0}, map[string]interface{}{
|
|
util.Mysql.Update(dbname, map[string]interface{}{"order_code": v, "invoice_status": 0}, map[string]interface{}{
|
|
@@ -1829,16 +1843,16 @@ 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 == "个人" {
|
|
if invoiceType == "个人" {
|
|
emailHtml := emailHtml_gr
|
|
emailHtml := emailHtml_gr
|
|
emailHtmls := fmt.Sprintf(emailHtml, phone, mail)
|
|
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, "电子发票")
|
|
InvoiceSendMail(mail, html, "电子发票")
|
|
} else {
|
|
} else {
|
|
emailHtml := emailHtml_gs
|
|
emailHtml := emailHtml_gs
|
|
emailHtmls := fmt.Sprintf(emailHtml, companyName, taxpayerIdentnum, phone, mail)
|
|
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, "电子发票")
|
|
InvoiceSendMail(mail, html, "电子发票")
|
|
}
|
|
}
|
|
}
|
|
}
|