|
@@ -242,6 +242,7 @@ func (this *Invoice) Addinvoice() error {
|
|
|
data["create_time"] = time.Now().Unix()
|
|
|
data["user_id"] = userId
|
|
|
data["invoice_status"] = 0
|
|
|
+ data["invoice_money"] = price
|
|
|
var orders = []map[string]interface{}{}
|
|
|
var items = []map[string]interface{}{}
|
|
|
item := map[string]interface{}{
|
|
@@ -281,52 +282,58 @@ func (this *Invoice) Addinvoice() error {
|
|
|
if len(*status) > 0 {
|
|
|
return nil
|
|
|
}
|
|
|
- util.Mysql.Insert(dbname, data)
|
|
|
+ if i := util.Mysql.Insert(dbname, data); i > 0 {
|
|
|
+ invoice_status = 0
|
|
|
+ }
|
|
|
if !util.Mysql.Update("dataexport_order", map[string]interface{}{"order_code": order_code, "user_id": userId}, dataexport_data) {
|
|
|
invoice_status = -1
|
|
|
}
|
|
|
} else {
|
|
|
- util.Mysql.Update(dbname, map[string]interface{}{
|
|
|
+ if ok := util.Mysql.Update(dbname, map[string]interface{}{
|
|
|
"order_code": order_code,
|
|
|
"user_id": userId,
|
|
|
"invoice_changed": 0,
|
|
|
- }, data)
|
|
|
+ }, data); ok {
|
|
|
+ invoice_status = 0
|
|
|
+ }
|
|
|
}
|
|
|
- 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
|
|
|
- jsonData["invoice_status"] = invoice_status
|
|
|
- } else if qutil.IntAll((*resMap)["code"]) == 2 { //开票中
|
|
|
- // log.Println("开票中")
|
|
|
- invoice_status = 0
|
|
|
- jsonData["invoice_status"] = invoice_status
|
|
|
- } else { //开票失败
|
|
|
- // log.Println("开票失败")
|
|
|
- invoice_status = -1
|
|
|
- jsonData["invoice_status"] = invoice_status
|
|
|
+ if config.InvoiceConfig.Third_party_switch {
|
|
|
+ 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
|
|
|
+ jsonData["invoice_status"] = invoice_status
|
|
|
+ } else if qutil.IntAll((*resMap)["code"]) == 2 { //开票中
|
|
|
+ // log.Println("开票中")
|
|
|
+ invoice_status = 0
|
|
|
+ jsonData["invoice_status"] = invoice_status
|
|
|
+ } else { //开票失败
|
|
|
+ // log.Println("开票失败")
|
|
|
+ invoice_status = -1
|
|
|
+ jsonData["invoice_status"] = invoice_status
|
|
|
+ }
|
|
|
+ }
|
|
|
+ defer response.Body.Close()
|
|
|
+ resData := (*resMap)["data"].(map[string]interface{})
|
|
|
+ update_status := util.Mysql.Update(dbname, map[string]interface{}{"order_code": order_code}, map[string]interface{}{
|
|
|
+ "invoice_serialnum": resData["swno"],
|
|
|
+ "invoice_code": resData["fpdm"],
|
|
|
+ "invoice_number": resData["fphm"],
|
|
|
+ "url": resData["path"],
|
|
|
+ "invoice_status": invoice_status,
|
|
|
+ })
|
|
|
+ if !update_status {
|
|
|
+ log.Println("order_ocde:", order_code+"update fail")
|
|
|
}
|
|
|
- }
|
|
|
- defer response.Body.Close()
|
|
|
- resData := (*resMap)["data"].(map[string]interface{})
|
|
|
- update_status := util.Mysql.Update(dbname, map[string]interface{}{"order_code": order_code}, map[string]interface{}{
|
|
|
- "invoice_serialnum": resData["swno"],
|
|
|
- "invoice_code": resData["fpdm"],
|
|
|
- "invoice_number": resData["fphm"],
|
|
|
- "url": resData["path"],
|
|
|
- "invoice_status": invoice_status,
|
|
|
- })
|
|
|
- if !update_status {
|
|
|
- log.Println("order_ocde:", order_code+"update fail")
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -348,42 +355,86 @@ func (this *Invoice) Showinvoice() {
|
|
|
data := make(map[string]interface{})
|
|
|
data["order_code"] = order_code
|
|
|
status := util.Mysql.Find(dbname, data, "", "create_time", 0, 0)
|
|
|
- if len(*status) != 0 {
|
|
|
- if len(*status) > 1 {
|
|
|
- if (*status)[1]["url"] != nil && (*status)[1]["url"] != "" {
|
|
|
+ //红冲发票开关
|
|
|
+ redSwitchInfo := map[string]interface{}{
|
|
|
+ "ris": config.InvoiceConfig.Red_invoice_switch,
|
|
|
+ "rim": config.InvoiceConfig.Red_invoice_msg,
|
|
|
+ }
|
|
|
+ if status != nil && len(*status) != 0 {
|
|
|
+ count := len(*status)
|
|
|
+ data := (*status)[count-1]
|
|
|
+ if data != nil {
|
|
|
+ delete(data, "user_id")
|
|
|
+ if url := qutil.InterfaceToStr(data["url"]); url != "" {
|
|
|
+ //ios 移动端
|
|
|
+ if util.IsMobileIOS(this.Request.UserAgent()) {
|
|
|
+ //国家税务局-增值税电子发票公共服务平台
|
|
|
+ if strings.Contains(url, "tysl.beijing.chinatax") {
|
|
|
+ data["url"] = strings.ReplaceAll(url, "/preview.html?code=", "/web-reader/reader?file=")
|
|
|
+ }
|
|
|
+ }
|
|
|
this.ServeJson(map[string]interface{}{
|
|
|
- "status": "success",
|
|
|
- "changed": true,
|
|
|
- "data": (*status)[1],
|
|
|
+ "status": "success",
|
|
|
+ "changed": qutil.If(count > 1, true, false).(bool),
|
|
|
+ "data": data,
|
|
|
+ "redSwitchInfo": redSwitchInfo,
|
|
|
})
|
|
|
} else {
|
|
|
this.ServeJson(map[string]interface{}{
|
|
|
- "status": "processing",
|
|
|
- "changed": true,
|
|
|
- "data": (*status)[1],
|
|
|
+ "status": "processing",
|
|
|
+ "changed": qutil.If(count > 1, true, false).(bool),
|
|
|
+ "data": data,
|
|
|
+ "redSwitchInfo": redSwitchInfo,
|
|
|
})
|
|
|
}
|
|
|
} else {
|
|
|
- if (*status)[0]["url"] != nil && (*status)[0]["url"] != "" {
|
|
|
- this.ServeJson(map[string]interface{}{
|
|
|
- "status": "success",
|
|
|
- "changed": false,
|
|
|
- "data": (*status)[0],
|
|
|
- })
|
|
|
- } else {
|
|
|
- this.ServeJson(map[string]interface{}{
|
|
|
- "status": "processing",
|
|
|
- "changed": false,
|
|
|
- "data": (*status)[0],
|
|
|
- })
|
|
|
- }
|
|
|
+ this.ServeJson(map[string]interface{}{
|
|
|
+ "status": "fail",
|
|
|
+ "changed": false,
|
|
|
+ "data": "",
|
|
|
+ "redSwitchInfo": redSwitchInfo,
|
|
|
+ })
|
|
|
}
|
|
|
+ //if len(*status) > 1 {
|
|
|
+ // if (*status)[1]["url"] != nil && (*status)[1]["url"] != "" {
|
|
|
+ // this.ServeJson(map[string]interface{}{
|
|
|
+ // "status": "success",
|
|
|
+ // "changed": true,
|
|
|
+ // "data": (*status)[1],
|
|
|
+ // "redSwitchInfo": redSwitchInfo,
|
|
|
+ // })
|
|
|
+ // } else {
|
|
|
+ // this.ServeJson(map[string]interface{}{
|
|
|
+ // "status": "processing",
|
|
|
+ // "changed": true,
|
|
|
+ // "data": (*status)[1],
|
|
|
+ // "redSwitchInfo": redSwitchInfo,
|
|
|
+ // })
|
|
|
+ // }
|
|
|
+ //} else {
|
|
|
+ // if (*status)[0]["url"] != nil && (*status)[0]["url"] != "" {
|
|
|
+ // this.ServeJson(map[string]interface{}{
|
|
|
+ // "status": "success",
|
|
|
+ // "changed": false,
|
|
|
+ // "data": (*status)[0],
|
|
|
+ // "redSwitchInfo": redSwitchInfo,
|
|
|
+ // })
|
|
|
+ // } else {
|
|
|
+ // this.ServeJson(map[string]interface{}{
|
|
|
+ // "status": "processing",
|
|
|
+ // "changed": false,
|
|
|
+ // "data": (*status)[0],
|
|
|
+ // "redSwitchInfo": redSwitchInfo,
|
|
|
+ // })
|
|
|
+ // }
|
|
|
+ //}
|
|
|
} else {
|
|
|
datas := util.Mysql.FindOne("dataexport_order", data, "order_status,applybill_status,order_code,user_mail,applybill_type,applybill_company,user_phone,applybill_taxnum", "")
|
|
|
this.ServeJson(map[string]interface{}{
|
|
|
- "status": "fail",
|
|
|
- "data": "",
|
|
|
- "datas": datas,
|
|
|
+ "status": "fail",
|
|
|
+ "data": "",
|
|
|
+ "datas": datas,
|
|
|
+ "redSwitchInfo": redSwitchInfo,
|
|
|
})
|
|
|
}
|
|
|
|
|
@@ -672,6 +723,14 @@ func (this *Invoice) Callbackinvoice() {
|
|
|
|
|
|
// 换票
|
|
|
func (this *Invoice) Replaceinvoice() {
|
|
|
+ //红冲开关
|
|
|
+ if !config.InvoiceConfig.Red_invoice_switch {
|
|
|
+ this.ServeJson(map[string]interface{}{
|
|
|
+ "invoice_status": -1,
|
|
|
+ "invoice_msg": config.InvoiceConfig.Red_invoice_msg,
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
userId := qutil.ObjToString(this.GetSession("userId"))
|
|
|
order_code := this.GetString("order_code")
|
|
|
isSys, _ := this.GetBool("isSys")
|
|
@@ -780,6 +839,7 @@ func (this *Invoice) Replaceinvoice() {
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
+ invoice_status := 0
|
|
|
dataexport_data := make(map[string]interface{})
|
|
|
if invoice_type == "个人" {
|
|
|
dataexport_data["applyBill_type"] = 0
|
|
@@ -802,20 +862,31 @@ func (this *Invoice) Replaceinvoice() {
|
|
|
data["invoice_changed"] = 1
|
|
|
data["create_time"] = time.Now().Unix()
|
|
|
data["user_id"] = userId
|
|
|
- data["invoice_status"] = 0
|
|
|
+ data["invoice_status"] = invoice_status
|
|
|
data["product_type"] = (*res)["product_type"]
|
|
|
if !isSys {
|
|
|
status := util.Mysql.Find(dbname, map[string]interface{}{"order_code": order_code, "user_id": userId}, "", "create_time", 0, 0)
|
|
|
- if len(*status) > 1 {
|
|
|
- return
|
|
|
+ if len(*status) == 0 {
|
|
|
+ if id := util.Mysql.Insert(dbname, data); id > 0 {
|
|
|
+ invoice_status = 1
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ invoice_status = 1
|
|
|
}
|
|
|
- util.Mysql.Insert(dbname, data)
|
|
|
} else {
|
|
|
- util.Mysql.Update(dbname, map[string]interface{}{
|
|
|
+ if ok := util.Mysql.Update(dbname, map[string]interface{}{
|
|
|
"order_code": order_code,
|
|
|
"user_id": userId,
|
|
|
"invoice_changed": 1,
|
|
|
- }, data)
|
|
|
+ }, data); ok {
|
|
|
+ invoice_status = 1
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if !config.InvoiceConfig.Third_party_switch {
|
|
|
+ this.ServeJson(map[string]interface{}{
|
|
|
+ "invoice_status": invoice_status,
|
|
|
+ })
|
|
|
+ return
|
|
|
}
|
|
|
var orders = []map[string]interface{}{}
|
|
|
var items = []map[string]interface{}{}
|
|
@@ -934,6 +1005,13 @@ func (this *Invoice) Replaceinvoice() {
|
|
|
|
|
|
// 退票
|
|
|
func (this *Invoice) Refundinvoice() {
|
|
|
+ if !config.InvoiceConfig.Third_party_switch {
|
|
|
+ this.ServeJson(map[string]interface{}{
|
|
|
+ "invoice_status": -1,
|
|
|
+ "invoice_msg": config.InvoiceConfig.Red_invoice_msg,
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
var refund_flag = -1
|
|
|
userid := this.GetSession("userId")
|
|
|
invoice_serialnum := this.GetString("invoice_serialnum") //发票流水号
|
|
@@ -1113,6 +1191,11 @@ func (this *Invoice) InvoiceSubmit() {
|
|
|
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", "")
|
|
|
+ productType := ""
|
|
|
+ if orderInfo != nil {
|
|
|
+ productType = qutil.InterfaceToStr((*orderInfo)["product_type"])
|
|
|
+ }
|
|
|
data := map[string]interface{}{
|
|
|
"order_code": orderCode,
|
|
|
"company_name": this.GetString("company_name"),
|
|
@@ -1141,6 +1224,7 @@ func (this *Invoice) InvoiceSubmit() {
|
|
|
"bank_name": this.GetString("bank_name"),
|
|
|
"recipient": this.GetString("recipient"),
|
|
|
"delivery_address": this.GetString("delivery_address"),
|
|
|
+ "product_type": productType,
|
|
|
}
|
|
|
if util.Mysql.Insert("invoice", data) <= 0 {
|
|
|
return false
|
|
@@ -1189,7 +1273,9 @@ func (this *Invoice) InvoiceSubmit() {
|
|
|
} 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"))
|
|
|
+ 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 := ""
|