You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

249 lines
5.9 KiB
Go

package suixing
import (
"encoding/json"
"fmt"
"github.com/gin-gonic/gin"
"github.com/tidwall/gjson"
"insure/global"
"insure/model"
"insure/service"
"insure/third_party/signer"
"insure/third_party/suixing"
"io"
)
func Create(c *gin.Context) {
data := map[string]interface{}{}
result := map[string]interface{}{
"code": 200,
"msg": "成功",
"data": data,
}
body, _ := io.ReadAll(c.Request.Body)
if body != nil {
fmt.Printf("body:%s\n", body)
}
var param suixing.CreateParam
err := json.Unmarshal(body, &param)
if err != nil {
result["code"] = 201
result["msg"] = "参数异常:" + err.Error()
c.JSON(200, result)
return
}
fmt.Println(param)
dataStr := gjson.Get(string(body), "data")
if !suixing.SuixingApi.Verify(param.CommonParam, dataStr.String()) {
result["code"] = 301
result["msg"] = "验签失败"
c.JSON(200, result)
return
}
order, err := service.OrderService.CreateOrder(param)
if err != nil {
result["code"] = 202
result["msg"] = err.Error()
c.JSON(200, result)
return
}
data["order_sn"] = order.OrderNo
data["url"] = global.Config.Server.Domain + "/tender?token=" + order.Token
result["data"] = data
c.JSON(200, result)
return
}
func Surrend(c *gin.Context) {
data := map[string]interface{}{}
result := map[string]interface{}{
"code": 200,
"msg": "成功",
"data": data,
}
isTest := c.DefaultQuery("isTest", "0")
body, _ := io.ReadAll(c.Request.Body)
if body != nil {
fmt.Printf("surrend body:%s\n", body)
}
if isTest == "1" {
body = []byte("{\"requestid\":\"c11cfbe1944a40ad847b396ff5261291\",\"appid\":\"zijin\",\"timestamp\":\"1721113249\",\"version\":\"1.0.0\",\"sign\":\"744dfc008c1955f94188450ac24c71aaf3f74bf2\",\"data\":{\"policyNo\":\"21122235000024000020\",\"bankName\":\"中国建设银行\",\"accountName\":\"湖南弘湘建设工程管理有限公司\",\"bankCardNum\":\"6217001820001592123\",\"backPremium\":\"5000.00\",\"contactName\":\"李一一\",\"contactPhone\":\"18120815541\",\"fileList\":[],\"reason\":\"\"}}")
}
var param suixing.RevokeParam
err := json.Unmarshal(body, &param)
if err != nil {
result["code"] = 201
result["msg"] = "参数异常:" + err.Error()
c.JSON(200, result)
return
}
fmt.Println(param)
dataStr := gjson.Get(string(body), "data")
if !suixing.SuixingApi.Verify(param.CommonParam, dataStr.String()) {
result["code"] = 301
result["msg"] = "验签失败"
c.JSON(200, result)
return
}
/*orderResult, err := service.OrderService.GetOrderResultByPolicyNo(param.Data.PolicyNo)
if err != nil {
result["code"] = 501
result["msg"] = err.Error()
c.JSON(200, result)
return
}*/
revoke, err := service.OrderService.SaveRevoke(param)
if err != nil {
result["code"] = 501
result["msg"] = err.Error()
c.JSON(200, result)
return
}
ret, err := service.OrderService.ZkingRevoke(revoke)
fmt.Println("revoke ret:", ret)
if err != nil {
result["code"] = 501
result["msg"] = err.Error()
c.JSON(200, result)
return
}
//service.OrderService.UpdateOrderAfterRevoke(orderResult.OrderNo)
c.JSON(200, result)
return
}
func Claim(c *gin.Context) {
data := map[string]interface{}{}
result := map[string]interface{}{
"code": 200,
"msg": "成功",
"data": data,
}
body, _ := io.ReadAll(c.Request.Body)
if body != nil {
fmt.Printf("body:%s\n", body)
}
var param suixing.ClaimParam
err := json.Unmarshal(body, &param)
if err != nil {
result["code"] = 201
result["msg"] = "参数异常:" + err.Error()
c.JSON(200, result)
return
}
fmt.Println(param)
dataStr := gjson.Get(string(body), "data")
if !suixing.SuixingApi.Verify(param.CommonParam, dataStr.String()) {
result["code"] = 301
result["msg"] = "验签失败"
c.JSON(200, result)
return
}
/*orderResult, err := service.OrderService.GetOrderResultByPolicyNo(param.Data.PolicyNo)
if err != nil {
result["code"] = 501
result["msg"] = err.Error()
c.JSON(200, result)
return
}*/
claim, err := service.OrderService.SaveClaim(param)
if err != nil {
result["code"] = 501
result["msg"] = err.Error()
c.JSON(200, result)
return
}
ret, err := service.OrderService.ZkingClaim(claim)
fmt.Println("claim ret:", ret)
if err != nil {
result["code"] = 501
result["msg"] = err.Error()
c.JSON(200, result)
return
}
//service.OrderService.UpdateOrderAfterClaim(orderResult.OrderNo)
c.JSON(200, result)
return
}
func UploadSignedFile(c *gin.Context) {
result := map[string]interface{}{
"status": "1",
"msg": "成功",
}
param := signer.UploadParam{}
err := c.ShouldBind(&param)
if err != nil {
result["status"] = "0"
result["msg"] = "参数异常"
c.JSON(200, result)
return
}
fmt.Println(param)
params := map[string]interface{}{}
err = json.Unmarshal([]byte(param.Params), &params)
if err != nil {
result["status"] = "0"
result["msg"] = "params解析异常"
c.JSON(200, result)
return
}
token := params["token"].(string)
order, err := service.OrderService.GetOrderByToken(token)
if err != nil {
result["status"] = "0"
result["msg"] = err.Error()
c.JSON(200, result)
return
}
signFileUrl, err := service.OrderService.UploadPdf("pdf", c)
if err != nil {
result["status"] = "0"
result["msg"] = err.Error()
c.JSON(200, result)
return
}
global.DB.Model(&model.Applicant{}).Where("order_no", order.OrderNo).UpdateColumn("signed_url", signFileUrl)
global.DB.Model(&model.Order{}).Where("order_no", order.OrderNo).UpdateColumn("status", "signed")
service.OrderService.AddSignLog(order.OrderNo, param)
res, err := service.OrderService.PostToZking(order.OrderNo)
if err != nil {
result["status"] = "0"
result["msg"] = "文件保存失败:" + err.Error()
c.JSON(200, result)
return
}
if res.Code != "200" {
result["status"] = "0"
result["msg"] = res.Code
c.JSON(200, result)
return
}
payUrl := res.Data["url"].(string)
orderSn := res.Data["order_sn"].(string)
service.OrderService.UpdateOrderAfterPostToInsure(order.OrderNo, payUrl, orderSn)
c.JSON(200, result)
return
}