Selaa lähdekoodia

wip:发票信息

wangshan 1 vuosi sitten
vanhempi
commit
595422626d

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

@@ -76,9 +76,9 @@
   },
   "activityMysql": {
     "dbName": "jyactivities",
-    "address": "192.168.3.149:3306",
+    "address": "192.168.3.217:4000",
     "userName": "root",
-    "passWord": "Topnet123",
+    "passWord": "=PDT49#80Z!RVv52_z",
     "maxOpenConns": 5,
     "maxIdleConns": 5
   },

+ 1 - 0
src/jfw/modules/subscribepay/src/config/config.go

@@ -222,6 +222,7 @@ type Invoice struct {
 	Invoice_switch     bool
 	Red_invoice_switch bool   //红冲发票是否可用开关
 	Red_invoice_msg    string //提示信息
+	Third_party_switch bool   //第三方开票开关
 }
 
 type entnicheConfig struct {

+ 5 - 4
src/jfw/modules/subscribepay/src/invoice.json

@@ -6,10 +6,11 @@
   "invoice_interface_address": "http://127.0.0.1:7070",
   "code": "3040205000000000000",
   "switch_paymch":{
-	"model":1,
-	"time":"2022-01-17 10:00:00"
+    "model":2,
+    "time":"2022-01-17 10:00:00"
   },
   "invoice_switch": true,
-  "red_invoice_switch": false,
-  "red_invoice_msg": "由于系统升级,线上换开发票功能暂时维护阶段,如需换开请直接联系在线客服!"
+  "red_invoice_switch": true,
+  "red_invoice_msg": "由于系统升级,线上换开发票功能暂时维护阶段,如需换开请直接联系在线客服!",
+  "third_party_switch": false
 }

+ 134 - 66
src/jfw/modules/subscribepay/src/service/invoice.go

@@ -281,52 +281,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")
 						}
 					}
 				}
@@ -353,40 +359,73 @@ func (this *Invoice) Showinvoice() {
 		"ris": config.InvoiceConfig.Red_invoice_switch,
 		"rim": config.InvoiceConfig.Red_invoice_msg,
 	}
-	if len(*status) != 0 {
-		if len(*status) > 1 {
-			if (*status)[1]["url"] != nil && (*status)[1]["url"] != "" {
+	if status != nil && len(*status) != 0 {
+		count := len(*status)
+		data := (*status)[count-1]
+		if data != nil {
+			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],
+					"changed":       qutil.If(count > 0, true, false).(bool),
+					"data":          data,
 					"redSwitchInfo": redSwitchInfo,
 				})
 			} else {
 				this.ServeJson(map[string]interface{}{
 					"status":        "processing",
-					"changed":       true,
-					"data":          (*status)[1],
+					"changed":       qutil.If(count > 0, 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],
-					"redSwitchInfo": redSwitchInfo,
-				})
-			} else {
-				this.ServeJson(map[string]interface{}{
-					"status":        "processing",
-					"changed":       false,
-					"data":          (*status)[0],
-					"redSwitchInfo": redSwitchInfo,
-				})
-			}
+			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{}{
@@ -682,6 +721,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")
@@ -790,6 +837,7 @@ func (this *Invoice) Replaceinvoice() {
 				return
 			}
 		}
+		invoice_status := 0
 		dataexport_data := make(map[string]interface{})
 		if invoice_type == "个人" {
 			dataexport_data["applyBill_type"] = 0
@@ -812,20 +860,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{}{}
@@ -944,6 +1003,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") //发票流水号
@@ -1199,7 +1265,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 := ""

+ 25 - 18
src/jfw/modules/subscribepay/src/util/util.go

@@ -1,18 +1,25 @@
-package util
-
-import (
-	qutil "app.yhyue.com/moapp/jybase/common"
-	"app.yhyue.com/moapp/jypkg/compatible"
-)
-
-var (
-	Compatible *compatible.Compatible
-)
-
-func ConfirmIntArr(arr []interface{}) []int {
-	tmp := make([]int, 0)
-	for _, v := range arr {
-		tmp = append(tmp, qutil.IntAll(v))
-	}
-	return tmp
-}
+package util
+
+import (
+    qutil "app.yhyue.com/moapp/jybase/common"
+    "app.yhyue.com/moapp/jypkg/compatible"
+    "strings"
+)
+
+var (
+    Compatible *compatible.Compatible
+)
+
+func ConfirmIntArr(arr []interface{}) []int {
+    tmp := make([]int, 0)
+    for _, v := range arr {
+        tmp = append(tmp, qutil.IntAll(v))
+    }
+    return tmp
+}
+
+//移动端ios
+func IsMobileIOS(userAgent string) bool {
+    userAgent = strings.ToLower(userAgent)
+    return strings.Contains(userAgent, "iphone") || strings.Contains(userAgent, "ipad") || strings.Contains(userAgent, "ipod")
+}