elf 5 months ago
parent 922304c9d2
commit 0acb1d6b52

@ -3,8 +3,10 @@ package h5
import (
"encoding/json"
"github.com/gin-gonic/gin"
"insure/dto/request"
"insure/e"
"insure/global"
"insure/model"
"insure/service"
"insure/third_party/signer"
"insure/utils/result"
@ -86,3 +88,39 @@ func PostToZking(c *gin.Context) (result.Data, error) {
}
return result.Data{"result": res}, nil
}
func UpdateApplicant(c *gin.Context) (result.Data, error) {
req := request.UpdateApplicantRequest{}
err := c.ShouldBind(&req)
if err != nil {
return nil, e.NewError("参数错误")
}
_, err = service.OrderService.UpdateApplicant(req)
if err != nil {
return nil, e.NewError("保存错误")
}
return result.Data{}, nil
}
func UploadSignFile(c *gin.Context) (result.Data, error) {
token := c.DefaultPostForm("token", "")
if token == "" {
return nil, e.NewError("缺少参数")
}
order, err := service.OrderService.GetOrderByToken(token)
if err != nil {
return nil, err
}
signUrl, err := service.OrderService.UploadPdf("pdf", c)
if err != nil {
return nil, err
}
global.DB.Model(&model.Applicant{}).Where("order_sn", order.OrderSn).UpdateColumn("sign_url", signUrl)
return result.Data{}, nil
}

@ -10,12 +10,7 @@ import (
"insure/service"
"insure/third_party/signer"
"insure/third_party/suixing"
"insure/utils"
"io"
"net/http"
"strconv"
"strings"
"time"
)
func Create(c *gin.Context) {
@ -96,44 +91,32 @@ func UploadSignedFile(c *gin.Context) {
return
}
file, err := c.FormFile("pdf")
signFileUrl, err := service.OrderService.UploadPdf("pdf", c)
if err != nil {
result["code"] = 201
result["msg"] = "文件上传失败"
result["msg"] = err.Error()
c.JSON(200, result)
return
}
reader, err := file.Open()
global.DB.Model(&model.Applicant{}).Where("order_sn", order.OrderSn).UpdateColumn("sign_url", signFileUrl)
service.OrderService.AddSignLog(order.OrderSn, param)
res, err := service.OrderService.PostToZking(order.OrderSn)
if err != nil {
result["code"] = 201
result["msg"] = "文件打开失败:" + err.Error()
c.JSON(200, result)
return
}
b := make([]byte, 512)
reader.Read(b)
contentType := http.DetectContentType(b)
if contentType != "application/pdf" && contentType != "application/zip" {
result["code"] = 201
result["msg"] = "文件格式错误:" + contentType
result["msg"] = "文件保存失败:" + err.Error()
c.JSON(200, result)
return
}
fileNameItems := strings.Split(file.Filename, ".")
filePath := time.Now().Format("20060102") + "/" + utils.Md5(file.Filename+strconv.Itoa(int(time.Now().UnixMicro()))+utils.GenerateRandomString(10)) + "." + fileNameItems[len(fileNameItems)-1]
dest := "./static/uploads/" + filePath
err = c.SaveUploadedFile(file, dest)
if err != nil {
result["code"] = 201
result["msg"] = "文件保存失败:" + err.Error()
if res.Code != "200" {
result["code"] = 202
result["msg"] = res.Code
c.JSON(200, result)
return
}
signFileUrl := global.Config.Server.Domain + "/uploads/" + filePath
global.DB.Model(&model.Applicant{}).Where("order_sn", order.OrderSn).UpdateColumn("sign_url", signFileUrl)
service.OrderService.AddSignLog(order.OrderSn, param)
c.JSON(200, result)
return
}

@ -0,0 +1,105 @@
package zking
import (
"encoding/json"
"fmt"
"github.com/gin-gonic/gin"
"insure/e"
"insure/service"
"insure/third_party/zking"
"io"
)
func checkParam(c *gin.Context) (*zking.CommonParam, error) {
body, _ := io.ReadAll(c.Request.Body)
if body != nil {
fmt.Printf("push body:%s\n", body)
}
param := zking.CommonParam{}
err := json.Unmarshal(body, &param)
if err != nil {
return nil, e.NewError("参数异常:" + err.Error())
}
if !zking.InsureApi.Verify(param) {
return nil, e.NewError("验签错误")
}
return &param, nil
}
func Push(c *gin.Context) {
data := map[string]interface{}{}
result := map[string]interface{}{
"code": 200,
"msg": "成功",
"data": data,
}
param, err := checkParam(c)
if err != nil {
fmt.Println(err.Error())
result["code"] = 201
result["msg"] = err.Error()
c.JSON(200, result)
return
}
pushData := zking.PushCallbackData{}
err = json.Unmarshal([]byte(param.Data), &pushData)
if err != nil {
fmt.Println(err.Error())
result["code"] = 201
result["msg"] = "data异常"
c.JSON(200, result)
return
}
orderResult, err := service.OrderService.SaveOrderResult(pushData)
if err != nil {
fmt.Println(err.Error())
result["code"] = 201
result["msg"] = "内部错误"
c.JSON(200, result)
return
}
fmt.Println("orderResult:", orderResult)
}
func Revoke(c *gin.Context) {
data := map[string]interface{}{}
result := map[string]interface{}{
"code": 200,
"msg": "成功",
"data": data,
}
param, err := checkParam(c)
if err != nil {
fmt.Println(err.Error())
result["code"] = 201
result["msg"] = err.Error()
c.JSON(200, result)
return
}
fmt.Println(param)
}
func Claim(c *gin.Context) {
data := map[string]interface{}{}
result := map[string]interface{}{
"code": 200,
"msg": "成功",
"data": data,
}
param, err := checkParam(c)
if err != nil {
fmt.Println(err.Error())
result["code"] = 201
result["msg"] = err.Error()
c.JSON(200, result)
return
}
fmt.Println(param)
}

@ -1,5 +1,6 @@
server:
port: 9096
root-path: ""
domain: "http://fjtb.bj-eib.com"
alipay:
app-id: ""

@ -1,6 +1,7 @@
package config
type Server struct {
Port string
Domain string
Port string
Domain string
RootPath string `yaml:"root-path"`
}

@ -0,0 +1,11 @@
package request
type UpdateApplicantRequest struct {
Token string `form:"token"`
ApplicantName string `form:"applicantName"`
CreditCode string `form:"creditCode"`
ContactName string `form:"contactName"`
ContactMobile string `form:"contactMobile"`
BankName string `form:"bankName"`
BankCardNum string `form:"bankCardNum"`
}

BIN
insure

Binary file not shown.

@ -9,4 +9,5 @@ func Initial(r *gin.Engine) {
webRouteInit(r)
adminRouteInit(r)
suixingRouteInit(r)
zkingRouteInit(r)
}

@ -12,4 +12,6 @@ func webRouteInit(r *gin.Engine) {
webGroup.Match([]string{"GET", "OPTIONS"}, "/get-sign-url", result.Json(h5.GetSignUrl))
webGroup.Match([]string{"GET", "OPTIONS"}, "/get-order-result", result.Json(h5.GetOrderResult))
webGroup.Match([]string{"GET", "OPTIONS"}, "/post-to-zking", result.Json(h5.PostToZking))
webGroup.Match([]string{"POST", "OPTIONS"}, "/update-applicant", result.Json(h5.UpdateApplicant))
webGroup.Match([]string{"POST", "OPTIONS"}, "/upload-sign-file", result.Json(h5.UploadSignFile))
}

@ -0,0 +1,13 @@
package router
import (
"github.com/gin-gonic/gin"
"insure/api/zking"
)
func zkingRouteInit(r *gin.Engine) {
zkGroup := r.Group("/zking")
zkGroup.Match([]string{"POST", "GET", "OPTIONS"}, "/push", zking.Push)
zkGroup.Match([]string{"POST", "GET", "OPTIONS"}, "/revoke", zking.Revoke)
zkGroup.Match([]string{"POST", "GET", "OPTIONS"}, "/claim", zking.Claim)
}

@ -3,8 +3,10 @@ package service
import (
"encoding/json"
"errors"
"github.com/gin-gonic/gin"
"github.com/xuri/excelize/v2"
"gorm.io/gorm"
"insure/dto/request"
"insure/dto/request/manage"
"insure/e"
"insure/global"
@ -14,7 +16,9 @@ import (
"insure/third_party/zking"
"insure/utils"
"insure/utils/excel"
"net/http"
"strconv"
"strings"
"time"
)
@ -498,3 +502,86 @@ func (orderService) buildOrdersExcel(orders []model.Order, sheet string, f *exce
row++
}
}
func (orderService) SaveOrderResult(data zking.PushCallbackData) (*model.OrderResult, error) {
orderResult := model.OrderResult{}
orderResult.OrderSn = data.OrderSn
orderResult.PolicyNo = data.PolicyNo
orderResult.Status = data.Status
orderResult.Remark = data.Remark
orderResult.ConfirmReceiptLink = data.ConfirmReceiptLink
orderResult.ConfirmReceiptLinkMd5 = data.ConfirmReceiptLinkMd5
orderResult.GuranteeLink = data.GuranteeLink
orderResult.GuranteeLinkMd5 = data.GuranteeLinkMd5
orderResult.GuranteeOfdLink = data.GuranteeOfdLink
orderResult.GuranteeOfdLinkMd5 = data.GuranteeOfdLinkMd5
orderResult.InvoiceLink = data.InvoiceLink
orderResult.InvoiceLinkMd5 = data.InvoiceLinkMd5
orderResult.MinPremium = data.MinPremium
orderResult.Rate = data.Rate
orderResult.ServiceAmount = data.ServiceAmount
err := global.DB.Save(&orderResult).Error
if err != nil {
return nil, err
}
return &orderResult, nil
}
func (orderService) UploadPdf(fileParam string, c *gin.Context) (string, error) {
file, err := c.FormFile(fileParam)
if err != nil {
return "", e.NewError("文件上传失败")
}
reader, err := file.Open()
if err != nil {
return "", e.NewError("文件打开失败:" + err.Error())
}
b := make([]byte, 512)
reader.Read(b)
contentType := http.DetectContentType(b)
if contentType != "application/pdf" && contentType != "application/zip" {
return "", e.NewError("文件格式错误:" + contentType)
}
fileNameItems := strings.Split(file.Filename, ".")
filePath := time.Now().Format("20060102") + "/" + utils.Md5(file.Filename+strconv.Itoa(int(time.Now().UnixMicro()))+utils.GenerateRandomString(10)) + "." + fileNameItems[len(fileNameItems)-1]
uploadPath := "."
if global.Config.Server.RootPath != "" {
uploadPath = global.Config.Server.RootPath
}
dest := uploadPath + "/static/uploads/" + filePath
err = c.SaveUploadedFile(file, dest)
if err != nil {
return "", e.NewError("文件保存失败:" + err.Error())
}
return global.Config.Server.Domain + "/uploads/" + filePath, err
}
func (s *orderService) UpdateApplicant(req request.UpdateApplicantRequest) (*model.Order, error) {
order, err := s.GetOrderByToken(req.Token)
if err != nil {
return nil, err
}
user := order.User
user.BankName = req.BankName
user.BankCardNum = req.BankCardNum
err = global.DB.Save(&user).Error
if err != nil {
return nil, err
}
applicant := order.Applicant
applicant.ContactName = req.ContactName
applicant.ContactMobile = req.ContactMobile
applicant.CreditCode = req.CreditCode
applicant.ApplicantName = req.ApplicantName
err = global.DB.Save(&applicant).Error
if err != nil {
return nil, err
}
order.User = user
order.Applicant = applicant
return order, nil
}

@ -0,0 +1,7 @@
package zking
type ClaimCallbackData struct {
PolicyNo string `json:"policyNo" form:"policyNo"`
Msg string `json:"msg" form:"msg"`
Status string `json:"status" form:"status"` //2 已理赔0 理赔失败
}

@ -5,7 +5,6 @@ type CommonParam struct {
RequestID string `json:"requestid" form:"requestid"`
Timestamp string `json:"timestamp" form:"timestamp"`
Version string `json:"version" form:"version"`
//Data suixing.CreateData `json:"data" form:"data"`
Data string `json:"data" form:"data"`
Sign string `json:"sign" form:"sign"`
Data string `json:"data" form:"data"`
Sign string `json:"sign" form:"sign"`
}

@ -0,0 +1,20 @@
package zking
type PushCallbackData struct {
DataType string `json:"data_type" form:"data_type"`
OrderSn string `json:"ordersn" form:"ordersn"`
PolicyNo string `json:"policyNo" form:"policyNo"`
MinPremium string `json:"min_premium" form:"min_premium"`
Rate string `json:"rate" form:"rate"`
Status string `json:"status" form:"status"` // 3 已出单,其他状态待定
ServiceAmount string `json:"service_amount" form:"service_amount"`
GuranteeLink string `json:"gurantee_link" form:"gurantee_link"`
GuranteeLinkMd5 string `json:"gurantee_link_md5" form:"gurantee_link_md5"`
GuranteeOfdLink string `json:"gurantee_ofd_link" form:"gurantee_ofd_link"`
GuranteeOfdLinkMd5 string `json:"gurantee_ofd_link_md5" form:"gurantee_ofd_link_md5"`
InvoiceLink string `json:"invoice_link" form:"invoice_link"`
InvoiceLinkMd5 string `json:"invoice_link_md5" form:"invoice_link_md5"`
ConfirmReceiptLink string `json:"confirm_receipt_link" form:"confirm_receipt_link"`
ConfirmReceiptLinkMd5 string `json:"confirm_receipt_link_md5" form:"confirm_receipt_link_md5"`
Remark string `json:"remark" form:"remark"`
}

@ -0,0 +1,7 @@
package zking
type RevokeCallbackData struct {
PolicyNo string `json:"policyNo" form:"policyNo"`
Msg string `json:"msg" form:"msg"`
Status string `json:"status" form:"status"` // 7 已撤销3 已出单(客户申请退保之后又后悔了,可以传这个状态还原)
}
Loading…
Cancel
Save