|
|
|
package h5
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"insure/dto/request"
|
|
|
|
"insure/e"
|
|
|
|
"insure/global"
|
|
|
|
"insure/model"
|
|
|
|
"insure/service"
|
|
|
|
"insure/third_party/signer"
|
|
|
|
"insure/utils/result"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Index(c *gin.Context) (result.Data, error) {
|
|
|
|
return result.Data{"hello": "elf"}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func Error(c *gin.Context) (result.Data, error) {
|
|
|
|
return nil, e.NewError("测试", "1122")
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetOrder(c *gin.Context) (result.Data, error) {
|
|
|
|
token := c.DefaultQuery("token", "")
|
|
|
|
if token == "" {
|
|
|
|
return nil, e.NewError("缺少参数")
|
|
|
|
}
|
|
|
|
order, err := service.OrderService.GetOrderByToken(token)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return result.Data{"order": order}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetSignUrl(c *gin.Context) (result.Data, error) {
|
|
|
|
token := c.DefaultQuery("token", "")
|
|
|
|
if token == "" {
|
|
|
|
return nil, e.NewError("缺少参数")
|
|
|
|
}
|
|
|
|
order, err := service.OrderService.GetOrderByToken(token)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
params := map[string]interface{}{
|
|
|
|
"token": token,
|
|
|
|
}
|
|
|
|
paramsStr, err := json.Marshal(params)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
param := signer.SignParam{}
|
|
|
|
param.Url = order.Applicant.SignUrl
|
|
|
|
param.UploadUrl = global.Config.Server.Domain + "/api/suixing/upload-signed-file"
|
|
|
|
param.IsView = "0"
|
|
|
|
param.IsAutoClose = "0"
|
|
|
|
param.IsEdit = "1"
|
|
|
|
param.IsUploadPdf = "1"
|
|
|
|
param.Params = string(paramsStr)
|
|
|
|
signUrl, err := signer.SignerApi.GetSignUrl(param)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return result.Data{"signUrl": signUrl}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetOrderResult(c *gin.Context) (result.Data, error) {
|
|
|
|
token := c.DefaultQuery("token", "")
|
|
|
|
if token == "" {
|
|
|
|
return nil, e.NewError("缺少参数")
|
|
|
|
}
|
|
|
|
orderResult, err := service.OrderService.GetOrderResultByToken(token)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return result.Data{"orderResult": orderResult}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetOrderPayUrl(c *gin.Context) (result.Data, error) {
|
|
|
|
token := c.DefaultQuery("token", "")
|
|
|
|
if token == "" {
|
|
|
|
return nil, e.NewError("缺少参数")
|
|
|
|
}
|
|
|
|
order, err := service.OrderService.GetOrderByToken(token)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return result.Data{"payUrl": order.PayUrl, "status": order.Status}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetOrderStatus(c *gin.Context) (result.Data, error) {
|
|
|
|
token := c.DefaultQuery("token", "")
|
|
|
|
if token == "" {
|
|
|
|
return nil, e.NewError("缺少参数")
|
|
|
|
}
|
|
|
|
order, err := service.OrderService.GetOrderByToken(token)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return result.Data{"status": order.Status}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func PostToZking(c *gin.Context) (result.Data, error) {
|
|
|
|
orderNo := c.DefaultQuery("order_no", "")
|
|
|
|
if orderNo == "" {
|
|
|
|
return nil, e.NewError("缺少参数")
|
|
|
|
}
|
|
|
|
res, err := service.OrderService.PostToZking(orderNo)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
payUrl := res.Data["url"].(string)
|
|
|
|
orderSn := res.Data["order_sn"].(string)
|
|
|
|
service.OrderService.UpdateOrderAfterPostToInsure(orderNo, payUrl, orderSn)
|
|
|
|
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 UpdateInvoice(c *gin.Context) (result.Data, error) {
|
|
|
|
req := request.UpdateInvoiceRequest{}
|
|
|
|
err := c.ShouldBind(&req)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, e.NewError("参数错误")
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = service.OrderService.UpdateInvoice(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_no", order.OrderNo).UpdateColumn("sign_url", signUrl)
|
|
|
|
global.DB.Model(&model.Order{}).Where("order_no", order.OrderNo).UpdateColumns(model.Order{Status: "generated"})
|
|
|
|
|
|
|
|
return result.Data{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func GenerateSignFile(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.PdfService.Generate(order)
|
|
|
|
fmt.Println(signUrl)
|
|
|
|
fmt.Println(err)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
global.DB.Model(&model.Applicant{}).Where("order_no", order.OrderNo).UpdateColumn("sign_url", signUrl)
|
|
|
|
global.DB.Model(&model.Order{}).Where("order_no", order.OrderNo).UpdateColumns(model.Order{Status: "generated"})
|
|
|
|
|
|
|
|
return result.Data{}, nil
|
|
|
|
}
|