Pārlūkot izejas kodu

fix:发票列表与展示&换票功能修改

duxin 1 gadu atpakaļ
vecāks
revīzija
d9cad285b9

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

@@ -164,7 +164,8 @@ type config struct {
 	} `json:"payRaffle"`
 	NewOrderTime   int64  `json:"newOrderTime"`
 	SigningSubject string `json:"signing_subject"` //管理后台订单发票签约主体配置
-	SubmitNum      int    `json:"submit_num"`
+	SubmitNum      int64  `json:"submit_num"`
+	OrderTime      int64  `json:"orderTime"`
 }
 type mgoConf struct {
 	Address           string

+ 42 - 22
src/jfw/modules/subscribepay/src/service/invoice.go

@@ -450,24 +450,21 @@ func (this *Invoice) ShowinvoiceList() {
 		"ris": config.InvoiceConfig.Red_invoice_switch,
 		"rim": config.InvoiceConfig.Red_invoice_msg,
 	}
-	invoices := 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 submit_num>= 0 ORDER BY create_time DESC`, order_code))
-	if invoices != nil && len(*invoices) > 0 {
+	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 {
-			delete(data, "user_id")
-			isJyInvoice := !strings.Contains(qutil.InterfaceToStr(data["url"]), "/jyInvoice/") //非数电票
+		for _, data := range invoices {
 			//是否换过票
 			isChanged := qutil.IntAll(data["isChanged"]) > 1
 			if isChanged && data["invoice_changed"] == 0 { //换过票的 只展示换票后的数据
 				continue
 			}
-			data["changed"] = qutil.If(isJyInvoice || isChanged, true, false)
-			//data["status"] = "processing"
+			delete(data, "user_id")
+			isJyInvoice := !strings.Contains(qutil.InterfaceToStr(data["url"]), "/jyInvoice/") //非数电票
+			isJyEntity := data["invoicing_entity"] != nil && qutil.InterfaceToStr(data["invoicing_entity"]) != config.Config.SigningSubject
+			data["changed"] = qutil.If(isJyInvoice || isChanged || isJyEntity, true, false)
 			if url := qutil.InterfaceToStr(data["url"]); url != "" {
-				//data["status"] = "success"
 				//ios 移动端
 				if isIos {
 					//国家税务局-增值税电子发票公共服务平台
@@ -478,7 +475,10 @@ func (this *Invoice) ShowinvoiceList() {
 			}
 			var isReopen bool
 			if data["invoice_status"] == -1 {
-				isReopen = qutil.IntAll(data["submit_num"])+1 >= config.Config.SubmitNum
+				isReopen = util.Mysql.Count("invoice_fail_record", map[string]interface{}{
+					"only_Identifying": data["only_Identifying"],
+					"order_code":       order_code,
+				})+1 >= config.Config.SubmitNum
 			}
 			data["isReopen"] = isReopen
 			invoiceData = append(invoiceData, data)
@@ -504,20 +504,23 @@ func (this *Invoice) ShowinvoiceList() {
 	}
 }
 
+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 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": //订单回显金额
-		res := util.Mysql.FindOne("dataexport_order", map[string]interface{}{
-			"order_code": code,
-		}, "order_status,applybill_status,order_code,user_mail,applybill_type,applybill_company,user_phone,applybill_taxnum", "")
-		if res != nil {
-			if pay_money := qutil.Int64All((*res)["pay_money"]) - InvoiceAmount(qutil.InterfaceToStr((*res)["order_code"])); pay_money > 0 {
-				data["pay_money"] = pay_money
-			}
-		}
+		data["pay_money"] = ResidueMoney(code)
 	case "2": //发票信息回显
 		invoice := util.Mysql.FindOne("invoice", map[string]interface{}{"id": code}, "id,order_code,invoice_money,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", "")
 		data["invoice"] = invoice
@@ -1110,7 +1113,8 @@ func (this *Invoice) NewReplaceinvoice() {
 	//order_code := this.GetString("order_code")
 	sid := this.GetString("sid")
 	oRes := util.Mysql.FindOne(dbname, map[string]interface{}{"id": sid, "invoie_changed": 0}, "", "") //仅线上开发票可换票
-	if oRes != nil && len(*oRes) > 0 {
+	if oRes != nil && len(*oRes) > 0 &&
+		((*oRes)["invoicing_entity"] == nil || qutil.InterfaceToStr((*oRes)["invoicing_entity"]) == config.Config.SigningSubject) {
 		var (
 			qSql    string
 			errCode []string
@@ -1124,7 +1128,7 @@ func (this *Invoice) NewReplaceinvoice() {
 			return
 		}
 		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' and submit_num >= 0`, qutil.InterfaceToStr((*oRes)["invoice_order_code"]))
+			qSql = fmt.Sprintf(`SELECT * FROM invoice WHERE invoice_order_code = '%s' `, qutil.InterfaceToStr((*oRes)["invoice_order_code"]))
 			res1 := util.Mysql.SelectBySql(qSql)
 			if res1 != nil && len(*res1) > 0 {
 				resArr = *res1
@@ -1642,7 +1646,7 @@ func (this *Invoice) InvoiceQuery() {
 	}
 	invoiceOne := util.Mysql.FindOne("invoice", map[string]interface{}{
 		"only_Identifying": onlyIdentifying,
-	}, "id,invoice_changed, 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", " create_time   DESC")
+	}, "id,invoice_changed,order_code, 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", " create_time   DESC")
 	companyName := ""
 	if invoiceOne == nil {
 		//查询公司名称
@@ -1651,6 +1655,22 @@ func (this *Invoice) InvoiceQuery() {
 		if orderArr != nil && len(*orderArr) > 0 {
 			companyName = qutil.ObjToString((*orderArr)[0]["company_name"])
 		}
+	} else {
+		switch qutil.IntAll((*invoiceOne)["invoice_status"]) {
+		case 1:
+			//是否换票
+			isJyInvoice := !strings.Contains(qutil.InterfaceToStr((*invoiceOne)["url"]), "/jyInvoice/") //非数电票
+			isChanged := util.Mysql.Count("invoice", map[string]interface{}{
+				"only_Identifying": onlyIdentifying,
+				"order_code":       (*invoiceOne)["order_code"],
+			}) > 1
+			(*invoiceOne)["changed"] = qutil.If(isJyInvoice || isChanged, true, false)
+		case -1: //失败支持重新提交否
+			(*invoiceOne)["isReopen"] = util.Mysql.Count("invoice_fail_record", map[string]interface{}{
+				"only_Identifying": (*invoiceOne)["only_Identifying"],
+				"order_code":       (*invoiceOne)["order_code"],
+			})+1 >= config.Config.SubmitNum
+		}
 	}
 	this.ServeJson(NewResult(map[string]interface{}{
 		"orderCodes":   strings.Join(orderArr, ","),

+ 2 - 0
src/jfw/modules/subscribepay/src/service/orderListDetails.go

@@ -667,6 +667,8 @@ func (o *OrderListDetails) Datas(sql string, pageNum, pagesize_max int) (haveNex
 			result[i]["qmx_invoice"] = QmxInvoice(result[i])
 			//剩余可开票金额
 			result[i]["invoice_price"] = InvoicePrice(result[i]) > 0
+			//是否存在可查看发票
+			result[i]["invoice_show"] = len(ShowList(qutil.InterfaceToStr(result[i]["order_code"]))) > 0
 		}
 	}
 	haveNextPage = len(result) >= pagesize_max