WH01243 5 years ago
commit
624c045933

+ 106 - 0
invoice/src/api/InvoiceController.go

@@ -0,0 +1,106 @@
+package api
+
+import (
+	"encoding/json"
+	"entity"
+	"fmt"
+	"github.com/gin-gonic/gin"
+	"io/ioutil"
+	"net/http"
+	"service"
+	"spirit/model"
+	"strconv"
+	"strings"
+)
+
+type InvoiceController struct {
+	Data interface{}
+}
+
+var (
+	InvoiceService = &service.InvoiceService{}
+
+)
+
+func (u *InvoiceController) Router(router *gin.Engine) {
+	eleGroup := router.Group("/Invoice")
+	{
+		eleGroup.POST("/Add", InvoiceAdd)   // 发票开具
+		eleGroup.POST("/Download", InvoiceDownload)   // 发票下载
+		eleGroup.GET("/See", InvoiceSee)   // 查看发票
+		eleGroup.POST("/RedSubmit", InvoiceRedSubmit)   // 退票
+		eleGroup.POST("/Replace", InvoiceReplace)   // 换票
+
+
+	}
+}
+func InvoiceAdd(context *gin.Context) {
+	result := &model.BaseResult{}
+	data, _ := ioutil.ReadAll(context.Request.Body)
+	var dat *entity.Invoice
+	if err := json.Unmarshal([]byte(data), &dat); err == nil {
+		fmt.Println("==============json str 转map=======================")
+	}
+	msg,code,dataMap:= InvoiceService.InvoiceAdd(dat)
+	result.Msg=msg
+	result.Code=code
+	result.Data=dataMap
+	context.JSON(http.StatusOK, result)
+}
+func InvoiceDownload(context *gin.Context) {
+	result := &model.BaseResult{}
+	data, _ := ioutil.ReadAll(context.Request.Body)
+	dat := make(map[string]interface{})
+	if err := json.Unmarshal([]byte(data), &dat); err == nil {
+		fmt.Println("==============json str 转map=======================")
+	}
+	fmt.Println(dat["model"])
+	fmt.Println(dat["model"].(string))
+	Modelint, _ := strconv.Atoi(dat["model"].(string))
+	dataMap,code,msg:=InvoiceService.InvoiceDownload(strings.Replace(fmt.Sprintln(dat["swno"]), "\n", "", -1),strings.Replace(fmt.Sprintln(dat["saleTax"]), "\n", "", -1),Modelint)
+	result.Data=dataMap
+	result.Code=code
+	result.Msg=msg
+	context.JSON(http.StatusOK, result)
+}
+func InvoiceSee(context *gin.Context) {
+	result := &model.BaseResult{}
+	swno := context.Request.FormValue("swno")
+	saleTax := context.Request.FormValue("saleTax")
+	code,path,msg:=InvoiceService.InvoiceSee(swno,saleTax)
+	result.Data=path
+	result.Msg=msg
+	result.Code=code
+	context.JSON(http.StatusOK, result)
+}
+//退票
+func InvoiceRedSubmit(context *gin.Context) {
+	result := &model.BaseResult{}
+	data, _ := ioutil.ReadAll(context.Request.Body)
+	var dat *entity.RedSubmitJson
+	if err := json.Unmarshal([]byte(data), &dat); err == nil {
+		fmt.Println("==============json str 转map=======================")
+	}
+	msg,code,dataMap:=InvoiceService.InvoiceRedSubmit(dat.Fpdm,dat.Fphm)
+	result.Data=dataMap
+	result.Msg=msg
+	result.Code=code
+	context.JSON(http.StatusOK, result)
+}
+//换票
+func InvoiceReplace(context *gin.Context) {
+	result := &model.BaseResult{}
+	data, _ := ioutil.ReadAll(context.Request.Body)
+	var dat *entity.Invoice
+	if err := json.Unmarshal([]byte(data), &dat); err == nil {
+		fmt.Println("==============json str 转map=======================")
+	}
+	msg,code,dataMap:=InvoiceService.InvoiceReplace(dat)
+	result.Data=dataMap
+	result.Msg=msg
+	result.Code=code
+	context.JSON(http.StatusOK, result)
+}
+
+
+

+ 21 - 0
invoice/src/application.properties

@@ -0,0 +1,21 @@
+#app服务监听端口
+app.serverPort=:7070
+
+app.contextPath=/smallow
+app.noAuthorizationUris=/manager/sys/login
+app.signedKey=TopSmartRobot20190601
+
+#静态资源目录
+app.staticRoot=static/res
+#静态资源前缀
+app.staticPrefix=/static/res
+
+#模板目录
+app.templateDir=views
+
+#redis相关配置
+redis.addr=127.0.0.1:6379
+redis.modules=iesApp
+redis.maxPoolSize=10
+redis.maxIdle=20
+redis.idleTimeOut=240

+ 15 - 0
invoice/src/config.json

@@ -0,0 +1,15 @@
+{
+    "Title" : "您的剑鱼标讯订单【v%】电子发票已开具",
+    "Body" :"<html><head><meta charset=\"UTF-8\"><title></title></head><style>label{display: block;border: 1px solid red;width: 90px;}span{display: block;margin-top: 5px;border: 1px solid red;width: 90px;}td{border: 1px solid red;width: 480px;padding:10px 10px ;}div{width: 100px;margin-left:20px ;display: inline;float: left;}</style><body><table><tr><td><div><label>我的:</label><span>名字</span></div><div><label>我的:</label><span>名字</span></div><div><label>我的:</label><span>名字</span></div><div><label>我的:</label><span>名字</span></div><div><label>我的:</label><span>名字</span></div></td></tr></table></body></html>",
+    "Sender" : "2399761917@qq.com",
+    "SPassword" : "cntzknpoplpeecig",
+    "SMTPAddr" : "smtp.qq.com",
+    "SMTPPort" : 25,
+    "SuccessCode": "0000",
+    "LineUpCode": "1089",
+    "SealCode":"4002",
+    "TimingCron1": "* */1 * * * ?",
+    "TimingCron":"0 0/1 * * * ?",
+    "Url": "http://218.249.166.20:8113/eisp-zk/jsonToBillEntityController.do",
+    "PdfUrl": "127.0.0.1:7070"
+}

+ 15 - 0
invoice/src/email-template.html

@@ -0,0 +1,15 @@
+
+<html>
+<head>
+    <meta charset="utf-8">
+</head>
+<body>
+<h4>亲爱的{{.ToUserName}},您好!</h4>
+<div>{{.Message}}</div>
+</br>
+<div>
+    {{.FromUserName}} </br>
+    {{.TimeDate}}
+</div>
+</body>
+</html>

+ 121 - 0
invoice/src/entity/Invoice.go

@@ -0,0 +1,121 @@
+package entity
+
+type Invoice struct {
+	Swno              string    `json:"swno"`              //流水号
+	SaleTax           string    `json:"saleTax"`           //销方税号
+	Store             string    `json:"store"`             //门店
+	CustName          string    `json:"custName"`          //购方名称
+	CustTaxNo         string    `json:"custTaxNo"`         //购方税号
+	CustAddr          string    `json:"custAddr"`          //购方地址
+	CustTelephone     string    `json:"custTelephone"`     //购货方手机号
+	CustPhone         string    `json:"custPhone"`         //购方固定电话
+	CustEmail         string    `json:"custEmail"`         //购方邮箱
+	CustBankAccount   string    `json:"custBankAccount"`   //开户行+账号
+	CustType          string    `json:"custType"`          //购货方企业类型01:企业02:机关执业单位03:个人04:其他
+	InvoMemo          string    `json:"invoMemo"`          //备注
+	InvType           string    `json:"invType"`           //发票类型 专用票(0)、普通票(2)、电子票(3)目前字段只能为3
+	BillDate          string    `json:"billDate"`          //单据日期
+	Thdh              string    `json:"thdh"`              //退货单号
+	BillType          string    `json:"billType"`          //开票类型1:正票2:红票
+	OilIdentification string    `json:"oilIdentification"` //成品油标识0:代表普通电子发票,1:代表成品油电子发票
+	SpecialRedFlag    string    `json:"specialRedFlag"`    //特殊冲红标志0:正常冲红(电子发票)1:特殊冲红(冲红纸质等)
+	OperationCode     string    `json:"operationCode"`     //操作代码10:正票正常开具11:正票错票重开20:退货折让红票21:错票重开红票22:换票冲红(全冲红电子发票,开具纸质发票)
+	Verified          string    `json:"verified"`          //是否加密校验0-不进行加密校验1-进行加密校验
+	SecretKey         string    `json:"secretKey"`         //校验码Verified为1时,必选填此项生成规则:base64[md5(销方税号|流水号|私钥|总金额)
+	Kpy               string    `json:"kpy"`               //开票员
+	Fhr               string    `json:"submissionTime"`    //复核人
+	Yfpdm             string    `json:"yfpdm"`             //复核人
+	Yfphm             string    `json:"yfphm"`             //原发票号码
+	Chyy              string    `json:"chyy"`              //冲红原因
+	Spare1            string    `json:"spare1"`            //备用1
+	Spare2            string    `json:"spare2"`            //备用2
+	Spare3            string    `json:"spare3"`            //备用3
+	Spare4            string    `json:"spare4"`            //备用4
+	Spare5            string    `json:"spare5"`            //备用5
+	Orders            []*Orders `json:"orders"`
+}
+type Orders struct {
+	BillNo string   `json:"billNo"` //订单号
+	Items  []*Items `json:"items"`
+}
+type Items struct {
+	Name        string `json:"name"`        //商品名称
+	Code        string `json:"code"`        //商品编号(税收分类编码)
+	LineType    string `json:"lineType"`    //发票行性质 0:正常行1:折扣行2:被折扣行
+	Spec        string `json:"spec"`        //规格型号
+	Unit        string `json:"unit"`        //计量单位
+	TaxRate     string `json:"taxRate"`     //税率
+	Quantity    string `json:"quantity"`    //数量
+	TaxPrice    string `json:"taxPrice"`    //单价
+	TotalAmount string `json:"totalAmount"` //含税金额
+	Yhzcnr      string `json:"yhzcnr"`      //税收优惠政策标志
+	Yhzcbs      string `json:"yhzcbs"`      //享受税收优惠政策内容
+	Lslbs       string `json:"lslbs"`       //零税率标识
+	Zxbm        string `json:"zxbm"`        //自行编码
+	Kce         string `json:"kce"`         //扣除额
+	ItemSpare1  string `json:"itemSpare1"`  //明细备用1
+	ItemSpare2  string `json:"itemSpare2"`  //明细备用2
+	ItemSpare3  string `json:"itemSpare3"`  //明细备用3
+	ItemSpare4  string `json:"itemSpare4"`  //明细备用4
+	ItemSpare5  string `json:"itemSpare5"`  //明细备用5
+}
+
+type GetInvoice struct {
+	FpMsgs    []*FpMsgs `json:"fpMsgs"`    //明细备用5
+	ReturnMsg ReturnMsg `json:"returnMsg"` //明细备用5
+	Swno      string    `json:"Swno"`      //流水号
+}
+type FpMsgs struct {
+	Fpdm       string `json:"fpdm"`       //发票代码
+	Fphm       string `json:"fphm"`       //发票号码
+	Hjbhsje    string `json:"hjbhsje"`    //合计不含税金额
+	Kphjse     string `json:"kphjse"`     //开票合计税额
+	Kprq       string `json:"kprq"`       //开票日期
+	PdfContent string `json:"pdfContent"` //pdf文件
+	Pdf_url    string `json:"pdf_url"`    //pdf下载地址
+	PdfMd5     string `json:"pdfMd5"`     //Md5码
+}
+type ReturnMsg struct {
+	Msg     string `json:"msg"`     //明细备用5
+	MsgCode string `json:"msgCode"` //明细备用5
+}
+type RedSubmitJson struct {
+	Fpdm string `json:"fpdm"` //发票代码
+	Fphm string `json:"fphm"` //发票号码
+}
+
+// MailboxConf 邮箱配置
+type MailboxConf struct {
+	// 邮件标题
+	Title string
+	// 邮件内容
+	Body string
+	// 收件人列表
+	RecipientList []string
+	// 发件人账号
+	Sender string
+	// 发件人密码,QQ邮箱这里配置授权码
+	SPassword string
+	// SMTP 服务器地址, QQ邮箱是smtp.qq.com
+	SMTPAddr string
+	// SMTP端口 QQ邮箱是25
+	SMTPPort int
+}
+
+var Title string
+var Body string
+var Sender string
+var SPassword string
+var SMTPAddr string
+var SMTPPort int
+var SuccessCode string
+var LineUpCode string
+var TimingCron string
+var Url string
+var SealCode string
+var PdfUrl string
+
+
+
+
+

+ 60 - 0
invoice/src/main.go

@@ -0,0 +1,60 @@
+package main
+
+import (
+	"api"
+	"entity"
+	"fmt"
+	"github.com/gin-gonic/gin"
+	"github.com/robfig/cron"
+	"log"
+	"service"
+	"spirit/redis"
+	"spirit/web/core"
+	"util"
+)
+
+var Loger *log.Logger
+
+func main() {
+	router := core.InitFramework(registerRouter)
+	c := cron.New()
+	c.AddFunc("0 0 0 * * ? ", logInit)
+	c.Start()
+	Init()
+	util.Loger.Println("服务重启")
+	router.Run(core.GetConfiguration().App.ServerPort)
+}
+func registerRouter(r *gin.Engine) {
+	new(api.InvoiceController).Router(r)
+}
+
+func logInit() {
+	util.Log()
+}
+func Init() {
+	util.Log()
+	var Config map[string]interface{}
+	core.ReadConfig("./config.json", &Config)
+	entity.Title = fmt.Sprint(Config["Title"])
+	entity.Body = fmt.Sprint(Config["Body"])
+	entity.Sender = fmt.Sprint(Config["Sender"])
+	entity.SPassword = fmt.Sprint(Config["SPassword"])
+	entity.SMTPAddr = fmt.Sprint(Config["SMTPAddr"])
+
+	SMTPPortint := util.SafeConvert2Int(Config["SMTPPort"])
+	entity.SMTPPort = SMTPPortint
+	entity.SuccessCode = fmt.Sprint(Config["SuccessCode"])
+	entity.LineUpCode = fmt.Sprint(Config["LineUpCode"])
+	entity.TimingCron = fmt.Sprint(Config["TimingCron"])
+	entity.Url = fmt.Sprint(Config["Url"])
+	entity.SealCode = fmt.Sprint(Config["SealCode"])
+	entity.PdfUrl = fmt.Sprint(Config["PdfUrl"])
+	keys := redis.GetKeys(core.GetConfiguration().Redis.Modules, "fp_*")
+	invoiceService := service.InvoiceService{}
+	for numb, _ := range keys {
+		valueInface := redis.Get(core.GetConfiguration().Redis.Modules, string(keys[numb].([]byte)))
+		class_detail_map := make(map[string]interface{})
+		class_detail_map = valueInface.(map[string]interface{})
+		invoiceService.Timer(class_detail_map["swno"].(string), class_detail_map["saleTax"].(string),class_detail_map["model"].(int))
+	}
+}

+ 176 - 0
invoice/src/service/InvoiceService.go

@@ -0,0 +1,176 @@
+package service
+
+import (
+	"bytes"
+	"encoding/json"
+	"entity"
+	"fmt"
+	"github.com/robfig/cron"
+	"io/ioutil"
+	"net/http"
+	"spirit/redis"
+	"spirit/web/core"
+	"util"
+)
+
+type InvoiceService struct{}
+
+var (
+	invoiceService = InvoiceService{}
+)
+
+// 发票开具
+func (u *InvoiceService) InvoiceAdd(solgan *entity.Invoice) (string, int, interface{}) {
+	url := entity.Url + "?build_invoice"
+	bytesData, _ := json.Marshal(solgan)
+	fmt.Println("json", string(bytesData))
+	reader := bytes.NewReader(bytesData)
+	request, err := http.NewRequest("POST", url, reader)
+	fmt.Println(err)
+	request.Header.Set("Content-Type", "application/json;charset=UTF-8")
+	client := http.Client{}
+	resp, err := client.Do(request)
+	respBytes, err := ioutil.ReadAll(resp.Body)
+	data := make(map[string]interface{})
+	if err := json.Unmarshal([]byte(respBytes), &data); err == nil {
+		fmt.Println("==============json str 转map=======================", data)
+	}
+	util.Loger.Println("开具发票:数据", solgan)
+	util.Loger.Println("开具发票:结果", data)
+	if (data["returnCode"] == entity.SuccessCode) {
+		pdfData,_,_:=u.InvoiceDownload(solgan.Swno, solgan.SaleTax,0)
+		data["fpdm"]=pdfData["fpdm"]
+		data["fphm"]=pdfData["fphm"]
+		return fmt.Sprintln(data["returnMsg"]), 0, data
+	} else if (data["returnCode"] == entity.LineUpCode || data["returnCode"] == entity.SealCode) {
+		u.InvoiceDownload(solgan.Swno, solgan.SaleTax,0)
+		fmt.Println("完成")
+		return fmt.Sprintln(data["returnMsg"]), 2, data
+	} else {
+		return fmt.Sprintln(data["returnMsg"]), 1, data
+	}
+
+}
+
+// 发票下载
+func (u *InvoiceService) InvoiceDownload(swno string, saleTax string,model int) (map[string]interface{}, int, string) {
+	url := entity.Url + "?get_invoice"
+	song := make(map[string]interface{})
+	song["swno"] = swno
+	song["saleTax"] = saleTax
+	bytesData, _ := json.Marshal(song)
+	fmt.Println("json", string(bytesData))
+	reader := bytes.NewReader(bytesData)
+	request, err := http.NewRequest("POST", url, reader)
+	fmt.Println(err)
+	request.Header.Set("Content-Type", "application/json;charset=UTF-8")
+	client := http.Client{}
+	resp, err := client.Do(request)
+	respBytes, err := ioutil.ReadAll(resp.Body)
+	var dat *entity.GetInvoice
+	if err := json.Unmarshal([]byte(respBytes), &dat); err == nil {
+		fmt.Println("==============json str 转map=======================")
+	}
+	util.Loger.Println("发票下载:", "流水号:",swno, "发票开具方税号:",saleTax,"结果:", dat)
+	if (dat.ReturnMsg.MsgCode == entity.SuccessCode) {
+		if(model==1){
+			swno=swno[4 : len(swno)]
+		}
+		pdfData := make(map[string]interface{})
+		path := util.ImgHandle(dat.FpMsgs[0].PdfContent, swno)
+		pdfData["path"] = path
+		pdfData["fpdm"] = dat.FpMsgs[0].Fpdm
+		pdfData["fphm"] = dat.FpMsgs[0].Fphm
+		/*if(email!=""){
+			//util.SendPdf(email,pathArr,swno)
+		}*/
+		return pdfData, 0, dat.ReturnMsg.Msg
+	} else if (dat.ReturnMsg.MsgCode == entity.LineUpCode || dat.ReturnMsg.MsgCode == entity.SealCode) {
+		swnoMap := make(map[string]interface{})
+		swnoMap["swno"] = swno
+		swnoMap["saleTax"] = saleTax
+		swnoMap["model"] = model
+		redis.Pop("fp_"+swno, fmt.Sprint(swnoMap))
+		u.Timer(swno, saleTax,model)
+		return nil, 2, dat.ReturnMsg.Msg
+	} else {
+		return nil, 1, dat.ReturnMsg.Msg
+	}
+}
+
+// 发票是否存在
+//noinspection ALL
+func (u *InvoiceService) InvoiceSee(swno string, saleTax string) (int, interface{}, string) {
+	fool := util.Exists("./static/res/" + swno + "/")
+	msg := "发票地址"
+	if fool {
+		pdfData:=make(map[string]interface{})
+		pdfData["path"] = entity.PdfUrl+"/static/res/" + swno + "/" + swno + ".pdf"
+		return 0, pdfData, msg
+	} else {
+		path, numb, _ := u.InvoiceDownload(swno, saleTax,0)
+		return numb, path, msg
+	}
+}
+
+// 退票
+//noinspection ALL
+func (u *InvoiceService) InvoiceRedSubmit(fpdm string, fphm string) (string, int, interface{}) {
+	url := entity.Url + "?redSubmitEInvoiceInfo"
+	song := make(map[string]interface{})
+	song["fpdm"] = fpdm
+	song["fphm"] = fphm
+	bytesData, _ := json.Marshal(song)
+	fmt.Println("json", string(bytesData))
+	reader := bytes.NewReader(bytesData)
+	request, err := http.NewRequest("POST", url, reader)
+	fmt.Println(err)
+	request.Header.Set("Content-Type", "application/json;charset=UTF-8")
+	client := http.Client{}
+	resp, err := client.Do(request)
+	respBytes, err := ioutil.ReadAll(resp.Body)
+	data := make(map[string]interface{})
+	if err := json.Unmarshal([]byte(respBytes), &data); err == nil {
+		fmt.Println("==============json str 转map=======================")
+	}
+	util.Loger.Println("冲红:", "发票单号:",fpdm,"发票号码:", fphm,"结果:", data)
+	if (data["returnCode"] == entity.SuccessCode) {
+		u.InvoiceDownload(data["redSwno"].(string),data["saleTax"].(string),1)
+		return fmt.Sprintln(data["returnMsg"]), 0, data
+	}  else if (data["returnCode"] == entity.LineUpCode){
+		u.InvoiceDownload(data["redSwno"].(string),data["saleTax"].(string),1)
+		return fmt.Sprintln(data["returnMsg"]), 2, data
+	}else{
+		return fmt.Sprintln(data["returnMsg"]), 1, data
+	}
+}
+
+// 换票
+//noinspection ALL
+func (u *InvoiceService) InvoiceReplace(solgan *entity.Invoice) (string, int, interface{}) {
+	msg, code, dataMap := invoiceService.InvoiceRedSubmit(solgan.Yfpdm, solgan.Yfphm)
+	util.Loger.Println("换票:",  "发票单号:",solgan.Yfpdm,"发票号码:", solgan.Yfphm)
+	if (code == 1) {
+		return msg, code, dataMap
+	}
+	msg, code, datamap := u.InvoiceAdd(solgan)
+	return msg, code, datamap
+}
+
+func (u *InvoiceService) Timer(swno string, saleTax string,model int ) {
+	c := cron.New()
+	spec := entity.TimingCron
+	c.AddFunc(spec, func() { // AddFunc 是添加任务的地方,此函数接收两个参数,第一个为表示定时任务的字符串,第二个为真正的真正的任务。
+		util.Loger.Println("定时任务开始:", "流水号:",swno, "发票开具方税号:",saleTax,)
+		_, numb, _ := u.InvoiceDownload(swno, saleTax,model)
+		if (numb == 0) {
+			util.Loger.Println("定时开票成功:", "流水号:",swno, "发票开具方税号:",saleTax,)
+			redis.Del(core.GetConfiguration().Redis.Modules, "fp_"+swno)
+			util.Loger.Println("定时任务结束:", "流水号:",swno, "发票开具方税号:",saleTax,)
+			c.Stop()
+		}else if (numb == 1){
+			c.Stop()
+		}
+	})
+	c.Start()
+}

+ 88 - 0
invoice/src/test/email_test.go

@@ -0,0 +1,88 @@
+package test
+
+import (
+	"fmt"
+	"testing"
+)
+
+/*func Test_Upload(t *testing.T) {
+	fromUser := "golang<2399761917@qq.com>"
+	toUser := "2399761917@qq.com"
+	subject := "hello,world"
+	err := SendMail(fromUser,toUser,subject)
+	if err != nil {
+		log.Println("发送邮件失败")
+		return
+	}
+	log.Println("发送邮件成功")
+}*/
+/*func SendMail(fromUser, toUser, subject string) error {
+	// NewEmail返回一个email结构体的指针
+	e := email.NewEmail()
+	// 发件人
+	e.From = fromUser
+	// 收件人(可以有多个)
+	e.To = []string{toUser}
+	// 邮件主题
+	e.Subject = subject
+	// 解析html模板
+	t,err := template.ParseFiles("email-template.html")
+	if err != nil {
+		return err
+	}
+	// Buffer是一个实现了读写方法的可变大小的字节缓冲
+	body := new(bytes.Buffer)
+	// Execute方法将解析好的模板应用到匿名结构体上,并将输出写入body中
+	t.Execute(body,struct {
+		FromUserName string
+		ToUserName   string
+		TimeDate     string
+		Message      string
+	}{
+		FromUserName: "go语言",
+		ToUserName:   "Sixah",
+		TimeDate:     time.Now().Format("2006/01/02"),
+		Message:      "golang是世界上最好的语言!",
+	})
+	// html形式的消息
+	e.HTML = body.Bytes()
+	// 从缓冲中将内容作为附件到邮件中
+	e.Attach(body, "email-template.html", "text/html")
+	// 以路径将文件作为附件添加到邮件中
+	e.AttachFile("/home/shuai/go/src/email/main.go")
+	// 发送邮件(如果使用QQ邮箱发送邮件的话,passwd不是邮箱密码而是授权码)
+	return e.Send("smtp.qq.com:587", smtp.PlainAuth("", "xxx@qq.com", "passwd", "smtp.qq.com"))
+return err
+}*/
+func Test_wenjian(t *testing.T) {
+	//os.MkdirAll("../static/res",os.ModePerm)
+	swno:="RED_11-2020041502"
+
+	swno=swno[4 : len(swno)]
+	fmt.Println(swno)
+}
+/*func Test_email(t *testing.T) {
+	var  Config  map[string]interface{}
+	core.ReadConfig("../config.json", &Config)
+	entity.Title=fmt.Sprint(Config["Title"])
+	entity.Body=fmt.Sprint(Config["Body"])
+	entity.Sender=fmt.Sprint(Config["Sender"])
+	entity.SPassword=fmt.Sprint(Config["SPassword"])
+	entity.SMTPAddr=fmt.Sprint(Config["SMTPAddr"])
+	fmt.Println(Config["SMTPPort"])
+	fmt.Println(Config["SMTPPort"])
+	SMTPPortint:=util.SafeConvert2Int(Config["SMTPPort"])
+	entity.SMTPPort=SMTPPortint
+	entity.SuccessCode=fmt.Sprint(Config["SuccessCode"])
+	entity.LineUpCode=fmt.Sprint(Config["LineUpCode"])
+	entity.TimingCron=fmt.Sprint(Config["TimingCron"])
+	entity.Url=fmt.Sprint(Config["Url"])
+	entity.SealCode=fmt.Sprint(Config["SealCode"])
+	var  pathArr  []string
+	util.SendPdf("2399761917@qq.com",pathArr,"")
+	log.Println("发送邮件成功")
+}
+*/
+
+
+

+ 94 - 0
invoice/src/util/push.go

@@ -0,0 +1,94 @@
+package util
+
+import (
+	"bufio"
+	"encoding/base64"
+	"entity"
+	"fmt"
+	"io/ioutil"
+	loger "log"
+	"os"
+	"time"
+)
+
+var Loger *loger.Logger
+
+//文件是否存在
+func Exists(path string) (bool) {
+	fmt.Println(path)
+	dir, _ := ioutil.ReadDir(path)
+	if len(dir) == 0 {
+		return false
+	} else {
+		return true
+	}
+}
+
+//base64转pdf存本地
+func ImgHandle(imgBase64 string, swno string) string {
+	imgs, err := base64.StdEncoding.DecodeString(imgBase64)
+	if err != nil {
+		fmt.Println(err)
+	}
+	imgname := swno  + ".pdf"
+	exPath := "./static/res/" + swno + "/"
+	exPath1 := "/static/res/" + swno + "/"
+	os.MkdirAll("./static/res/"+swno, os.ModePerm)
+	file, err := os.OpenFile(exPath+imgname, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
+	if err != nil {
+		fmt.Println(err)
+	}
+	w := bufio.NewWriter(file) //创建新的 Writer 对象
+	_, err3 := w.WriteString(string(imgs))
+	if err3 != nil {
+		fmt.Println(err)
+	}
+
+	w.Flush()
+	file.Close()
+	return entity.PdfUrl+exPath1 + imgname
+
+}
+
+//pdf邮箱发送
+/*func SendPdf(name string,path []string,swno string) (bool) {
+	var mailConf entity.MailboxConf
+	mailConf.Title = entity.Title
+	mailConf.Body = entity.Body
+	mailConf.RecipientList = []string{name}
+	mailConf.Sender = entity.Sender
+	mailConf.SPassword = entity.SPassword
+	mailConf.SMTPAddr = entity.SMTPAddr
+	mailConf.SMTPPort = entity.SMTPPort
+	m := gomail.NewMessage()
+	m.SetHeader(`From`, mailConf.Sender)
+	m.SetHeader(`To`, mailConf.RecipientList...)
+	arr:=strings.Split(mailConf.Title,"v%")
+	fmt.Println(arr[0]+swno+arr[1])
+	m.SetHeader(`Subject`, arr[0]+swno+arr[1])
+	m.SetBody(`text/html`, mailConf.Body)
+	for _, value := range path {
+		m.Attach(value)//添加附件
+	}
+	err := gomail.NewDialer(mailConf.SMTPAddr, mailConf.SMTPPort, mailConf.Sender, mailConf.SPassword).DialAndSend(m)
+	if err != nil {
+		log.Fatalf("Send Email Fail, %s", err.Error())
+	}
+	log.Printf("Send Email Success")
+	return  false
+}*/
+func SafeConvert2Int(obj interface{}) int {
+	if obj != nil {
+		return int(obj.(float64))
+	}
+	return 0
+}
+func Log() {
+	file := "./static/logs/" + time.Now().Format("200612") + ".txt"
+	logFile, err := os.OpenFile(file, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0766)
+	if err != nil {
+		panic(err)
+	}
+	Loger = loger.New(logFile, "[logger]",loger.LstdFlags | loger.Lshortfile | loger.LUTC) // 将文件设置为loger作为输出
+
+}

+ 35 - 0
invoice/src/views/login.html

@@ -0,0 +1,35 @@
+{{define "login.html"}}
+<!DOCTYPE html>
+<html>
+<head>
+    <meta charset="UTF-8">
+    <title>测试页面</title>
+    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
+</head>
+<body>
+<div id="app">
+    <div>
+        测试登录页面
+    </div>
+</div>
+</body>
+<!-- import Vue before Element -->
+<script src="https://unpkg.com/vue/dist/vue.js"></script>
+<!-- import JavaScript -->
+<script src="https://unpkg.com/element-ui/lib/index.js"></script>
+<script>
+    new Vue({
+        el: '#app',
+        data() {
+            return {
+                username: "",
+                pwd: "",
+                edit: true
+            };
+        },
+        methods: {
+        }
+    })
+</script>
+</html>
+{{end}}