陈少旭 vor 6 Monaten
Ursprung
Commit
443a006073

+ 218 - 0
controllers/fapiao_controller.go Datei anzeigen

@@ -0,0 +1,218 @@
1
+package controllers
2
+
3
+import (
4
+	"XT_New/enums"
5
+	"XT_New/models"
6
+	"XT_New/service"
7
+	"XT_New/service/fapiao"
8
+	"XT_New/utils"
9
+	"fmt"
10
+	"github.com/astaxie/beego"
11
+	"github.com/gaodengyun/goldencloud-sdk-go/goldencloud/common"
12
+	"github.com/gaodengyun/goldencloud-sdk-go/goldencloud/invoice"
13
+	"time"
14
+)
15
+
16
+type FapiaoApiController struct {
17
+	BaseAuthAPIController
18
+}
19
+
20
+func FaPiaoApiRegistRouters() {
21
+	beego.Router("/api/fapiao/sms/code", &FapiaoApiController{}, "get:GetLoginUploadCode")
22
+	beego.Router("/api/fapiao/sms/login", &FapiaoApiController{}, "get:Login")
23
+	beego.Router("/api/fapiao/qrcode/get", &FapiaoApiController{}, "get:GetQRCode")
24
+	beego.Router("/api/fapiao/stock/get", &FapiaoApiController{}, "get:GetFaPiaoStock")
25
+	beego.Router("/api/fapiao/blue", &FapiaoApiController{}, "get:OpenFaPiao")
26
+	beego.Router("/api/fapiao/red", &FapiaoApiController{}, "get:RedFaPiao")
27
+
28
+	beego.Router("/api/order/fapiao/list", &FapiaoApiController{}, "get:GetOrderFaPiaoList")
29
+	beego.Router("/api/fapiao/list", &FapiaoApiController{}, "get:GetFaPiaoList")
30
+
31
+}
32
+func (c *FapiaoApiController) GetFaPiaoList() {
33
+	page, _ := c.GetInt64("page", -1)
34
+	limit, _ := c.GetInt64("limit", -1)
35
+	start_time := c.GetString("start_time")
36
+	end_time := c.GetString("end_time")
37
+	timeLayout := "2006-01-02"
38
+	loc, _ := time.LoadLocation("Local")
39
+	var startTime int64
40
+	if len(start_time) > 0 {
41
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
42
+		if err != nil {
43
+			//fmt.Println(err)
44
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
45
+			return
46
+		}
47
+		startTime = theTime.Unix()
48
+	}
49
+	var endTime int64
50
+	if len(end_time) > 0 {
51
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
52
+		if err != nil {
53
+			utils.ErrorLog(err.Error())
54
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
55
+			return
56
+		}
57
+		endTime = theTime.Unix()
58
+	}
59
+
60
+	adminUser := c.GetAdminUserInfo()
61
+	org_id := adminUser.CurrentOrgId
62
+	order, err, total := service.GetFaPiaoList(org_id, page, limit, startTime, endTime)
63
+	if err == nil {
64
+		c.ServeSuccessJSON(map[string]interface{}{
65
+			"order": order,
66
+			"total": total,
67
+		})
68
+
69
+	} else {
70
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
71
+		return
72
+	}
73
+
74
+}
75
+func (c *FapiaoApiController) GetOrderFaPiaoList() {
76
+	page, _ := c.GetInt64("page", -1)
77
+	limit, _ := c.GetInt64("limit", -1)
78
+	start_time := c.GetString("start_time")
79
+	end_time := c.GetString("end_time")
80
+	is_open_fapiao, _ := c.GetInt64("is_open_fapiao", 0)
81
+	sort_type, _ := c.GetInt64("sort_type", 0)
82
+
83
+	patient_id, _ := c.GetInt64("patient_id", 0)
84
+
85
+	timeLayout := "2006-01-02"
86
+	loc, _ := time.LoadLocation("Local")
87
+	var startTime int64
88
+	if len(start_time) > 0 {
89
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
90
+		if err != nil {
91
+			//fmt.Println(err)
92
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
93
+			return
94
+		}
95
+		startTime = theTime.Unix()
96
+	}
97
+	var endTime int64
98
+	if len(end_time) > 0 {
99
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
100
+		if err != nil {
101
+			utils.ErrorLog(err.Error())
102
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
103
+			return
104
+		}
105
+		endTime = theTime.Unix()
106
+	}
107
+	adminUser := c.GetAdminUserInfo()
108
+	org_id := adminUser.CurrentOrgId
109
+	order, err, total := service.GetFaPiaoSettleList(org_id, page, limit, startTime, endTime, sort_type, start_time, end_time, is_open_fapiao, patient_id)
110
+	if err == nil {
111
+		c.ServeSuccessJSON(map[string]interface{}{
112
+			"order": order,
113
+			"total": total,
114
+		})
115
+
116
+	} else {
117
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
118
+		return
119
+	}
120
+}
121
+
122
+func (c *FapiaoApiController) GetLoginUploadCode() {
123
+	sdk := invoice.NewSdk(common.HMAC_SHA256, "8ca4ee7b152c0abceff9", "17402aff152dbeedf7a7b30be553f4c4", "", "test")
124
+	var config models.FapiaoConfig
125
+	config, _ = service.FindFaPiaoConfigInfo(c.GetAdminUserInfo().CurrentOrgId)
126
+	routerAddress, postData := fapiao.GetSMSCode(config) //发票开具
127
+	r, err := sdk.HttpPost("https://apigw-test.goldentec.com", routerAddress, postData)
128
+	if err != nil {
129
+		fmt.Println(err)
130
+	} else {
131
+		fmt.Println(string(r))
132
+	}
133
+}
134
+
135
+func (c *FapiaoApiController) Login() {
136
+	GetQRStatus(c.GetAdminUserInfo().CurrentOrgId)
137
+	code := c.GetString("code")
138
+	var config models.FapiaoConfig
139
+	config, _ = service.FindFaPiaoConfigInfo(c.GetAdminUserInfo().CurrentOrgId)
140
+	sdk := invoice.NewSdk(common.HMAC_SHA256, "8ca4ee7b152c0abceff9", "17402aff152dbeedf7a7b30be553f4c4", "", "test")
141
+	routerAddress, postData := fapiao.Login(code, config) //发票开具
142
+	r, err := sdk.HttpPost("https://apigw-test.goldentec.com", routerAddress, postData)
143
+	if err != nil {
144
+		fmt.Println(err)
145
+	} else {
146
+		fmt.Println(string(r))
147
+	}
148
+}
149
+
150
+func (c *FapiaoApiController) GetQRCode() {
151
+	sdk := invoice.NewSdk(common.HMAC_SHA256, "8ca4ee7b152c0abceff9", "17402aff152dbeedf7a7b30be553f4c4", "", "test")
152
+	var config models.FapiaoConfig
153
+	config, _ = service.FindFaPiaoConfigInfo(c.GetAdminUserInfo().CurrentOrgId)
154
+	routerAddress, postData := fapiao.GetQRCode(config) //发票开具
155
+	r, err := sdk.HttpPost("https://apigw-test.goldentec.com", routerAddress, postData)
156
+	if err != nil {
157
+		fmt.Println(err)
158
+	} else {
159
+		fmt.Println(string(r))
160
+	}
161
+}
162
+
163
+func (c *FapiaoApiController) GetFaPiaoStock() {
164
+	sdk := invoice.NewSdk(common.HMAC_SHA256, "8ca4ee7b152c0abceff9", "17402aff152dbeedf7a7b30be553f4c4", "", "test")
165
+	var config models.FapiaoConfig
166
+	config, _ = service.FindFaPiaoConfigInfo(c.GetAdminUserInfo().CurrentOrgId)
167
+	routerAddress, postData := fapiao.QueryStock(config) //发票开具
168
+	r, err := sdk.HttpPost("https://apigw-test.goldentec.com", routerAddress, postData)
169
+	if err != nil {
170
+		fmt.Println(err)
171
+	} else {
172
+		fmt.Println(string(r))
173
+	}
174
+
175
+}
176
+
177
+func (c *FapiaoApiController) OpenFaPiao() {
178
+	GetQRStatus(c.GetAdminUserInfo().CurrentOrgId)
179
+	sdk := invoice.NewSdk(common.HMAC_SHA256, "8ca4ee7b152c0abceff9", "17402aff152dbeedf7a7b30be553f4c4", "", "test")
180
+	var config models.FapiaoConfig
181
+	config, _ = service.FindFaPiaoConfigInfo(c.GetAdminUserInfo().CurrentOrgId)
182
+	routerAddress, postData := fapiao.Blue(config) //发票开具
183
+	r, err := sdk.HttpPost("https://apigw-test.goldentec.com", routerAddress, postData)
184
+	if err != nil {
185
+		fmt.Println(err)
186
+	} else {
187
+		fmt.Println(string(r))
188
+	}
189
+}
190
+
191
+func (c *FapiaoApiController) RedFaPiao() {
192
+	GetQRStatus(c.GetAdminUserInfo().CurrentOrgId)
193
+	sdk := invoice.NewSdk(common.HMAC_SHA256, "8ca4ee7b152c0abceff9", "17402aff152dbeedf7a7b30be553f4c4", "", "test")
194
+	//var config models.FapiaoConfig
195
+	//config, _ = service.FindFaPiaoConfigInfo(c.GetAdminUserInfo().CurrentOrgId)
196
+	routerAddress, postData := fapiao.Red() //发票开具
197
+	r, err := sdk.HttpPost("https://apigw-test.goldentec.com", routerAddress, postData)
198
+	if err != nil {
199
+		fmt.Println(err)
200
+	} else {
201
+		fmt.Println(string(r))
202
+	}
203
+}
204
+
205
+func GetQRStatus(org_id int64) {
206
+	redis := service.RedisClient()
207
+	defer redis.Close()
208
+	sdk := invoice.NewSdk(common.HMAC_SHA256, "8ca4ee7b152c0abceff9", "17402aff152dbeedf7a7b30be553f4c4", "", "test")
209
+	var config models.FapiaoConfig
210
+	config, _ = service.FindFaPiaoConfigInfo(org_id)
211
+	routerAddress, postData := fapiao.GetQRStatus("", config) //发票开具
212
+	r, err := sdk.HttpPost("https://apigw-test.goldentec.com", routerAddress, postData)
213
+	if err != nil {
214
+		fmt.Println(err)
215
+	} else {
216
+		fmt.Println(string(r))
217
+	}
218
+}

+ 91 - 0
models/fapiao.go Datei anzeigen

@@ -0,0 +1,91 @@
1
+package models
2
+
3
+type FapiaoConfig struct {
4
+	ID                int64  `gorm:"column:id" json:"id" form:"id"`
5
+	UserOrgId         int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
6
+	IsUse             int64  `gorm:"column:is_use" json:"is_use" form:"is_use"`
7
+	TaxpayerId        string `gorm:"column:taxpayer_id" json:"taxpayer_id" form:"taxpayer_id"`
8
+	TerminalCode      string `gorm:"column:terminal_code" json:"terminal_code" form:"terminal_code"`
9
+	SellerTaxpayerNum string `gorm:"column:seller_taxpayer_num" json:"seller_taxpayer_num" form:"seller_taxpayer_num"`
10
+	SellerAddress     string `gorm:"column:seller_address" json:"seller_address" form:"seller_address"`
11
+	SellerTel         string `gorm:"column:seller_tel" json:"seller_tel" form:"seller_tel"`
12
+	SellerBankName    string `gorm:"column:seller_bank_name" json:"seller_bank_name" form:"seller_bank_name"`
13
+	SellerBankAccount string `gorm:"column:seller_bank_account" json:"seller_bank_account" form:"seller_bank_account"`
14
+	TitleType         string `gorm:"column:title_type" json:"title_type" form:"title_type"`
15
+	BuyerTitle        string `gorm:"column:buyer_title" json:"buyer_title" form:"buyer_title"`
16
+	CallbackUrl       string `gorm:"column:callback_url" json:"callback_url" form:"callback_url"`
17
+	UserOpenid        string `gorm:"column:user_openid" json:"user_openid" form:"user_openid"`
18
+}
19
+
20
+func (FapiaoConfig) TableName() string {
21
+	return "fapiao_config"
22
+}
23
+
24
+type HisOrderByFaPiao struct {
25
+	ID                 int64          `gorm:"column:id" json:"id" form:"id"`
26
+	UserOrgId          int64          `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
27
+	HisPatientId       int64          `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
28
+	SettleAccountsDate int64          `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
29
+	Ctime              int64          `gorm:"column:ctime" json:"ctime" form:"ctime"`
30
+	Mtime              int64          `gorm:"column:mtime" json:"mtime" form:"mtime"`
31
+	Status             int64          `gorm:"column:status" json:"status" form:"status"`
32
+	Number             string         `gorm:"column:number" json:"number" form:"number"`
33
+	PatientId          int64          `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
34
+	Infcode            int64          `gorm:"column:infcode" json:"infcode" form:"infcode"`
35
+	WarnMsg            string         `gorm:"column:warn_msg" json:"warn_msg" form:"warn_msg"`
36
+	Cainfo             string         `gorm:"column:cainfo" json:"cainfo" form:"cainfo"`
37
+	ErrMsg             string         `gorm:"column:err_msg" json:"err_msg" form:"err_msg"`
38
+	RespondTime        string         `gorm:"column:respond_time" json:"respond_time" form:"respond_time"`
39
+	InfRefmsgid        string         `gorm:"column:inf_refmsgid" json:"inf_refmsgid" form:"inf_refmsgid"`
40
+	OrderStatus        int64          `gorm:"column:order_status" json:"order_status" form:"order_status"`
41
+	MdtrtId            string         `gorm:"column:mdtrt_id" json:"mdtrt_id" form:"mdtrt_id"`
42
+	SetlId             string         `gorm:"column:setl_id" json:"setl_id" form:"setl_id"`
43
+	PsnNo              string         `gorm:"column:psn_no" json:"psn_no" form:"psn_no"`
44
+	PsnName            string         `gorm:"column:psn_name" json:"psn_name" form:"psn_name"`
45
+	PsnCertType        string         `gorm:"column:psn_cert_type" json:"psn_cert_type" form:"psn_cert_type"`
46
+	Certno             string         `gorm:"column:certno" json:"certno" form:"certno"`
47
+	Gend               string         `gorm:"column:gend" json:"gend" form:"gend"`
48
+	Insutype           string         `gorm:"column:insutype" json:"insutype" form:"insutype"`
49
+	SetlTime           string         `gorm:"column:setl_time" json:"setl_time" form:"setl_time"`
50
+	MedType            string         `gorm:"column:med_type" json:"med_type" form:"med_type"`
51
+	MedfeeSumamt       float64        `gorm:"column:medfee_sumamt" json:"medfee_sumamt" form:"medfee_sumamt"`
52
+	FaPiaoCode         string         `gorm:"column:fa_piao_code" json:"fa_piao_code" form:"fa_piao_code"`
53
+	FaPiaoNumber       string         `gorm:"column:fa_piao_number" json:"fa_piao_number" form:"fa_piao_number"`
54
+	Patients           Patients       `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
55
+	HisPatient         HisPatient     `gorm:"ForeignKey:MdtrtId;AssociationForeignKey:Number" json:"his_patient"`
56
+	HisFaPiaoOrder     HisFaPiaoOrder `gorm:"ForeignKey:FaPiaoNumber;AssociationForeignKey:TicketSn" json:"result"`
57
+}
58
+
59
+func (HisOrderByFaPiao) TableName() string {
60
+	return "his_order"
61
+}
62
+
63
+type HisFaPiaoOrder struct {
64
+	ID               int64   `gorm:"column:id" json:"id" form:"id"`
65
+	InvoiceId        string  `gorm:"column:invoice_id" json:"invoice_id" form:"invoice_id"`
66
+	OrderSn          string  `gorm:"column:order_sn" json:"order_sn" form:"order_sn"`
67
+	TicketSn         string  `gorm:"column:ticket_sn" json:"ticket_sn" form:"ticket_sn"`
68
+	TicketDate       string  `gorm:"column:ticket_date" json:"ticket_date" form:"ticket_date"`
69
+	AmountWithTax    string  `gorm:"column:amount_with_tax" json:"amount_with_tax" form:"amount_with_tax"`
70
+	AmountWithoutTax string  `gorm:"column:amount_without_tax" json:"amount_without_tax" form:"amount_without_tax"`
71
+	TaxAmount        string  `gorm:"column:tax_amount" json:"tax_amount" form:"tax_amount"`
72
+	IsRedWashed      string  `gorm:"column:is_red_washed" json:"is_red_washed" form:"is_red_washed"`
73
+	PdfUrl           string  `gorm:"column:pdf_url" json:"pdf_url" form:"pdf_url"`
74
+	OfdUrl           string  `gorm:"column:ofd_url" json:"ofd_url" form:"ofd_url"`
75
+	XmlUrl           string  `gorm:"column:xml_url" json:"xml_url" form:"xml_url"`
76
+	FapiaoStatus     string  `gorm:"column:fapiao_status" json:"fapiao_status" form:"fapiao_status"`
77
+	OrderIds         string  `gorm:"column:order_ids" json:"order_ids" form:"order_ids"`
78
+	UserOrgId        int64   `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
79
+	Status           int64   `gorm:"column:status" json:"status" form:"status"`
80
+	PatientId        int64   `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
81
+	Ctime            int64   `gorm:"column:ctime" json:"ctime" form:"ctime"`
82
+	Mtime            int64   `gorm:"column:mtime" json:"mtime" form:"mtime"`
83
+	Creator          string  `gorm:"column:creator" json:"creator" form:"creator"`
84
+	MedfeeSumamt     float64 `gorm:"column:medfee_sumamt" json:"medfee_sumamt" form:"medfee_sumamt"`
85
+	PsnCashPay       float64 `gorm:"column:psn_cash_pay" json:"psn_cash_pay" form:"psn_cash_pay"`
86
+	FundPaySumamt    float64 `gorm:"column:fund_pay_sumamt" json:"fund_pay_sumamt" form:"fund_pay_sumamt"`
87
+}
88
+
89
+func (HisFaPiaoOrder) TableName() string {
90
+	return "his_fapiao_order"
91
+}

+ 1 - 0
routers/router.go Datei anzeigen

@@ -88,4 +88,5 @@ func init() {
88 88
 	controllers.ZuobiaoApiRegistRouters()
89 89
 	controllers.HisExportDataApiRegistRouters()
90 90
 	controllers.NewStockApiRegistRouters()
91
+	controllers.FaPiaoApiRegistRouters()
91 92
 }

+ 63 - 0
service/fapiao/bule.go Datei anzeigen

@@ -0,0 +1,63 @@
1
+package fapiao
2
+
3
+import "XT_New/models"
4
+
5
+func Blue(config models.FapiaoConfig) (routerAddress string, postData map[string]interface{}) {
6
+
7
+	routerAddress = "/tax-api/invoice/blue/v1"
8
+
9
+	postData = map[string]interface{}{
10
+		"seller_name":          "wkbb invoice blue test",
11
+		"seller_taxpayer_num":  "your seller_taxpayer_num",
12
+		"seller_address":       "",
13
+		"seller_tel":           "",
14
+		"seller_bank_name":     "",
15
+		"seller_bank_account":  "",
16
+		"title_type":           1,
17
+		"buyer_title":          "海南高灯科技",
18
+		"buyer_taxpayer_num":   "",
19
+		"buyer_address":        "",
20
+		"buyer_bank_name":      "",
21
+		"buyer_bank_account":   "",
22
+		"buyer_phone":          "",
23
+		"buyer_email":          "",
24
+		"taker_phone":          "",
25
+		"order_id":             "fc5fec2d1b6942658c009a151d4cffa5",
26
+		"invoice_type_code":    "032",
27
+		"callback_url":         "http://www.test.com",
28
+		"drawer":               "TEST",
29
+		"payee":                "TEST",
30
+		"checker":              "TEST",
31
+		"terminal_code":        "661234567789",
32
+		"user_openid":          "ba9ea0bdfa1f460993c990564caab18f",
33
+		"special_invoice_kind": "",
34
+		"zsfs":                 "",
35
+		"deduction":            "",
36
+		"amount_has_tax":       "66.66",
37
+		"tax_amount":           "66.66",
38
+		"amount_without_tax":   "66.66",
39
+		"remark":               "readme",
40
+	}
41
+
42
+	//项目商品明细
43
+	items := make([]map[string]interface{}, 1)
44
+	item := make(map[string]interface{})
45
+	item["name"] = "海鲜真划算"
46
+	item["tax_code"] = "your tax_code"
47
+	item["models"] = "zyx"
48
+	item["unit"] = "个"
49
+	item["total_price"] = "66.66"
50
+	item["total"] = "5"
51
+	item["price"] = "17.22"
52
+	item["tax_rate"] = "66.66"
53
+	item["tax_amount"] = "66.66"
54
+	item["discount"] = "66.66"
55
+	item["preferential_policy_flag"] = "0"
56
+	item["zero_tax_flag"] = "0"
57
+	item["vat_special_management"] = ""
58
+	items[0] = item
59
+
60
+	postData["items"] = items
61
+
62
+	return routerAddress, postData
63
+}

+ 16 - 0
service/fapiao/invalid.go Datei anzeigen

@@ -0,0 +1,16 @@
1
+package fapiao
2
+
3
+func Invalid() (routerAddress string, postData map[string]interface{}) {
4
+
5
+	routerAddress = "/tax-api/invoice/invalid/v1"
6
+
7
+	postData = map[string]interface{}{
8
+		"seller_taxpayer_num": "500102010004038",
9
+		"order_sn":            "",
10
+		"order_id":            "gp_20190828115454_742_11296_31131",
11
+		"name":                "fff",
12
+		"is_red":              0,
13
+	}
14
+
15
+	return routerAddress, postData
16
+}

+ 13 - 0
service/fapiao/login.go Datei anzeigen

@@ -0,0 +1,13 @@
1
+package fapiao
2
+
3
+import "XT_New/models"
4
+
5
+func Login(code string, config models.FapiaoConfig) (routerAddress string, postData map[string]interface{}) {
6
+	routerAddress = "/tax-api/invoice/sms/upload/v1"
7
+	postData = map[string]interface{}{
8
+		"taxpayer_id":   config.TaxpayerId,
9
+		"terminal_code": config.TerminalCode,
10
+		"sms_code":      code,
11
+	}
12
+	return routerAddress, postData
13
+}

+ 18 - 0
service/fapiao/print.go Datei anzeigen

@@ -0,0 +1,18 @@
1
+package fapiao
2
+
3
+func Print() (routerAddress string, postData map[string]interface{}) {
4
+
5
+	routerAddress = "/tax-api/invoice/print/v1"
6
+
7
+	postData = map[string]interface{}{
8
+		"seller_taxpayer_num": "500102010004038",
9
+		"order_sn":            "",
10
+		"order_id":            "gp_20190828115454_742_11296_31131",
11
+		"print_type":          "",
12
+		"print_flag":          "",
13
+		"print_mode":          "",
14
+		"is_red":              0,
15
+	}
16
+
17
+	return routerAddress, postData
18
+}

+ 26 - 0
service/fapiao/qrcode.go Datei anzeigen

@@ -0,0 +1,26 @@
1
+package fapiao
2
+
3
+import "XT_New/models"
4
+
5
+func GetQRCode(config models.FapiaoConfig) (routerAddress string, postData map[string]interface{}) {
6
+
7
+	routerAddress = "/tax-api/invoice/auth/get-qrcode/v1"
8
+	postData = map[string]interface{}{
9
+		"taxpayer_id":   config.TaxpayerId,
10
+		"terminal_code": config.TerminalCode,
11
+	}
12
+
13
+	return routerAddress, postData
14
+}
15
+
16
+func GetQRStatus(auth_id string, config models.FapiaoConfig) (routerAddress string, postData map[string]interface{}) {
17
+
18
+	routerAddress = "tax-api/invoice/auth/query-qrcode-status/v1"
19
+	postData = map[string]interface{}{
20
+		"taxpayer_id":   config.TaxpayerId,
21
+		"terminal_code": config.TerminalCode,
22
+		"auth_id":       auth_id,
23
+	}
24
+
25
+	return routerAddress, postData
26
+}

+ 27 - 0
service/fapiao/query.go Datei anzeigen

@@ -0,0 +1,27 @@
1
+package fapiao
2
+
3
+import "XT_New/models"
4
+
5
+func Query() (routerAddress string, postData map[string]interface{}) {
6
+
7
+	routerAddress = "/tax-api/invoice/query/v1"
8
+
9
+	postData = map[string]interface{}{
10
+		"seller_taxpayer_num": "500102010004038",
11
+		"order_sn":            "",
12
+		"order_id":            "gp_20190828115454_742_11296_31131",
13
+		"is_red":              0,
14
+	}
15
+
16
+	return routerAddress, postData
17
+}
18
+
19
+func QueryStock(config models.FapiaoConfig) (routerAddress string, postData map[string]interface{}) {
20
+	routerAddress = "/tax-api/invoice/query-stock/v1"
21
+	postData = map[string]interface{}{
22
+		"taxpayer_id":       config.TaxpayerId,
23
+		"terminal_code":     config.TerminalCode,
24
+		"invoice_type_code": "007",
25
+	}
26
+	return routerAddress, postData
27
+}

+ 21 - 0
service/fapiao/red.go Datei anzeigen

@@ -0,0 +1,21 @@
1
+package fapiao
2
+
3
+func Red() (routerAddress string, postData map[string]interface{}) {
4
+
5
+	routerAddress = "/tax-api/invoice/red/v1"
6
+
7
+	invoices := make([]map[string]interface{}, 1)
8
+
9
+	invoice := make(map[string]interface{})
10
+	invoice["seller_taxpayer_num"] = "111112222233333"
11
+	invoice["callback_url"] = "http://test.feehi.com/sign/mock/invoice-callback.php"
12
+	invoice["order_sn"] = "6555407740980870214"
13
+
14
+	invoices[0] = invoice
15
+
16
+	postData = map[string]interface{}{
17
+		"invoices": invoices,
18
+	}
19
+
20
+	return routerAddress, postData
21
+}

+ 14 - 0
service/fapiao/sms.go Datei anzeigen

@@ -0,0 +1,14 @@
1
+package fapiao
2
+
3
+import "XT_New/models"
4
+
5
+func GetSMSCode(config models.FapiaoConfig) (routerAddress string, postData map[string]interface{}) {
6
+
7
+	routerAddress = "/tax-api/invoice/login/check/v1"
8
+	postData = map[string]interface{}{
9
+		"taxpayer_id":   config.TaxpayerId,
10
+		"terminal_code": config.TerminalCode,
11
+	}
12
+
13
+	return routerAddress, postData
14
+}

+ 14 - 0
service/fapiao/waitopen.go Datei anzeigen

@@ -0,0 +1,14 @@
1
+package fapiao
2
+
3
+func WaitOpen() (routerAddress string, postData map[string]interface{}) {
4
+
5
+	routerAddress = "/tax-api/invoice/wait-open/v1"
6
+
7
+	postData = map[string]interface{}{
8
+		"taxpayer_num":      "20181010000000865115391398242493",
9
+		"machine_no":        "125523523523",
10
+		"invoice_type_code": "026",
11
+	}
12
+
13
+	return routerAddress, postData
14
+}

+ 85 - 0
service/fapiao_service.go Datei anzeigen

@@ -0,0 +1,85 @@
1
+package service
2
+
3
+import "XT_New/models"
4
+
5
+func FindFaPiaoConfigInfo(org_id int64) (config models.FapiaoConfig, err error) {
6
+	err = readDb.Model(&models.FapiaoConfig{}).Where("status = 1 AND user_org_id = ?", org_id).First(&config).Error
7
+	return
8
+}
9
+
10
+func GetFaPiaoSettleList(user_org_id int64, page int64, limit int64, start_time_timestamp int64, end_time_timestamp int64, sort_type int64, start_time string, end_time string, is_open_fapiao int64, patient_id int64) (order []*models.HisOrderByFaPiao, err error, total int64) {
11
+	offset := (page - 1) * limit
12
+	db := readDb.Model(&models.HisOrderByFaPiao{})
13
+
14
+	// Join the patients table based on user_org_id
15
+	db = db.Joins("join xt_patients as patient on patient.id = his_order.patient_id and patient.user_org_id = ?", user_org_id)
16
+
17
+	// Handle the is_open_fapiao logic
18
+	if is_open_fapiao == 1 {
19
+		// is_open_fapiao == 1: Look for orders with a corresponding fa_piao_number
20
+		db = db.Joins("left join his_fapiao_order as fo on fo.ticket_sn = his_order.fa_piao_number and fo.user_org_id = ?", user_org_id).
21
+			Where("fo.id IS NOT NULL") // Ensure fa_piao_number exists
22
+	} else if is_open_fapiao == 2 {
23
+		// is_open_fapiao == 2: Look for orders without a corresponding fa_piao_number
24
+		db = db.Joins("left join his_fapiao_order as fo on fo.ticket_sn = his_order.fa_piao_number and fo.user_org_id = ?", user_org_id).
25
+			Where("fo.id IS NULL") // Ensure fa_piao_number does not exist
26
+	}
27
+
28
+	// Handle sorting logic
29
+	if sort_type == 1 {
30
+		if start_time_timestamp != 0 {
31
+			db = db.Where("his_order.settle_accounts_date >= ?", start_time_timestamp)
32
+		}
33
+		if end_time_timestamp != 0 {
34
+			db = db.Where("his_order.settle_accounts_date <= ?", end_time_timestamp)
35
+		}
36
+	} else {
37
+		if len(start_time) != 0 {
38
+			db = db.Where("his_order.setl_time >= ?", start_time+" 00:00:00")
39
+		}
40
+		if len(end_time) != 0 {
41
+			db = db.Where("his_order.setl_time <= ?", end_time+" 23:59:59")
42
+		}
43
+	}
44
+	if patient_id > 0 {
45
+		db = db.Where("his_order.patient_id = ?", patient_id)
46
+
47
+	}
48
+
49
+	// Preload related data
50
+	db = db.Preload("Patients", "status = 1 AND user_org_id = ?", user_org_id).
51
+		Preload("HisPatient", "status = 1 AND user_org_id = ?", user_org_id).
52
+		Preload("HisFaPiaoOrder", "status = 1")
53
+
54
+	// Count the total number of records
55
+	db = db.Count(&total)
56
+
57
+	// Apply pagination
58
+	db = db.Limit(limit).Offset(offset)
59
+
60
+	// Execute query and return results
61
+	err = db.Find(&order).Error
62
+	//
63
+	//for _, item := range order {
64
+	//	var hfpo models.HisFaPiaoOrder
65
+	//	readDb.Model(&models.HisFaPiaoOrder{}).Where("ticket_sn = ?", item.FaPiaoNumber).First(&hfpo)
66
+	//	item.HisFaPiaoOrder =
67
+	//}
68
+
69
+	return
70
+}
71
+
72
+func GetFaPiaoList(user_org_id int64, page int64, limit int64, start_time_timestamp int64, end_time_timestamp int64) (order []*models.HisOrder, err error, total int64) {
73
+	offset := (page - 1) * limit
74
+	db := readDb.Model(&models.HisFaPiaoOrder{})
75
+	db = db.Preload("Patients", "status = 1 AND user_org_id = ?", user_org_id).
76
+		Preload("HisFaPiaoOrder", "status = 1")
77
+	db = db.Where("ctime >= ? and ctime <= ? and user_org_id = ?", start_time_timestamp, end_time_timestamp, user_org_id)
78
+	// Count the total number of records
79
+	db = db.Count(&total)
80
+	// Apply pagination
81
+	db = db.Limit(limit).Offset(offset)
82
+	// Execute query and return results
83
+	err = db.Find(&order).Error
84
+	return
85
+}