|
|
|
@ -28,25 +28,25 @@ type orderService struct {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *orderService) CreateOrder(param suixing.CreateParam) (*model.Order, error) {
|
|
|
|
|
orderSn := utils.GenerateNo("order")
|
|
|
|
|
orderNo := utils.GenerateNo("order")
|
|
|
|
|
|
|
|
|
|
order, err := s.saveOrder(orderSn, param.RequestID)
|
|
|
|
|
order, err := s.saveOrder(orderNo, param.RequestID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
user, err := s.saveUser(orderSn, param.Data.User)
|
|
|
|
|
user, err := s.saveUser(orderNo, param.Data.User)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
project, err := s.saveProject(orderSn, param.Data.Project)
|
|
|
|
|
project, err := s.saveProject(orderNo, param.Data.Project)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
applicant, err := s.saveApplicant(orderSn, param.Data.Applicant)
|
|
|
|
|
applicant, err := s.saveApplicant(orderNo, param.Data.Applicant)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
assured, err := s.saveAssured(orderSn, param.Data.Assured)
|
|
|
|
|
assured, err := s.saveAssured(orderNo, param.Data.Assured)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
@ -57,10 +57,10 @@ func (s *orderService) CreateOrder(param suixing.CreateParam) (*model.Order, err
|
|
|
|
|
return order, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *orderService) saveOrder(orderSn string, requestID string) (*model.Order, error) {
|
|
|
|
|
func (s *orderService) saveOrder(orderNo string, requestID string) (*model.Order, error) {
|
|
|
|
|
o := model.Order{}
|
|
|
|
|
o.Token = utils.Md5(orderSn + utils.GenerateRandomString(10) + strconv.Itoa(int(time.Now().UnixMicro())))
|
|
|
|
|
o.OrderSn = orderSn
|
|
|
|
|
o.Token = utils.Md5(orderNo + utils.GenerateRandomString(10) + strconv.Itoa(int(time.Now().UnixMicro())))
|
|
|
|
|
o.OrderNo = orderNo
|
|
|
|
|
o.RequestID = requestID
|
|
|
|
|
o.Status = "initial"
|
|
|
|
|
err := global.DB.Save(&o).Error
|
|
|
|
@ -70,9 +70,9 @@ func (s *orderService) saveOrder(orderSn string, requestID string) (*model.Order
|
|
|
|
|
return &o, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *orderService) saveUser(orderSn string, user suixing.User) (*model.User, error) {
|
|
|
|
|
func (s *orderService) saveUser(orderNo string, user suixing.User) (*model.User, error) {
|
|
|
|
|
u := model.User{}
|
|
|
|
|
u.OrderSn = orderSn
|
|
|
|
|
u.OrderNo = orderNo
|
|
|
|
|
u.UserID = user.UserID
|
|
|
|
|
u.Username = user.Username
|
|
|
|
|
u.Mobile = user.Mobile
|
|
|
|
@ -89,9 +89,9 @@ func (s *orderService) saveUser(orderSn string, user suixing.User) (*model.User,
|
|
|
|
|
return &u, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *orderService) saveProject(orderSn string, project suixing.Project) (*model.Project, error) {
|
|
|
|
|
func (s *orderService) saveProject(orderNo string, project suixing.Project) (*model.Project, error) {
|
|
|
|
|
p := model.Project{}
|
|
|
|
|
p.OrderSn = orderSn
|
|
|
|
|
p.OrderNo = orderNo
|
|
|
|
|
p.Name = project.Name
|
|
|
|
|
p.TpID = project.TpID
|
|
|
|
|
p.BdID = project.BdID
|
|
|
|
@ -119,13 +119,13 @@ func (s *orderService) saveProject(orderSn string, project suixing.Project) (*mo
|
|
|
|
|
return &p, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *orderService) saveApplicant(orderSn string, applicant suixing.Applicant) (*model.Applicant, error) {
|
|
|
|
|
func (s *orderService) saveApplicant(orderNo string, applicant suixing.Applicant) (*model.Applicant, error) {
|
|
|
|
|
licenseFiles, err := json.Marshal(applicant.LicenseFiles)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
a := model.Applicant{}
|
|
|
|
|
a.OrderSn = orderSn
|
|
|
|
|
a.OrderNo = orderNo
|
|
|
|
|
a.ApplicantName = applicant.ApplicantName
|
|
|
|
|
a.CreditVld = applicant.CreditVld
|
|
|
|
|
a.CreditCode = applicant.CreditCode
|
|
|
|
@ -149,9 +149,9 @@ func (s *orderService) saveApplicant(orderSn string, applicant suixing.Applicant
|
|
|
|
|
return &a, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *orderService) saveAssured(orderSn string, assured suixing.Assured) (*model.Assured, error) {
|
|
|
|
|
func (s *orderService) saveAssured(orderNo string, assured suixing.Assured) (*model.Assured, error) {
|
|
|
|
|
a := model.Assured{}
|
|
|
|
|
a.OrderSn = orderSn
|
|
|
|
|
a.OrderNo = orderNo
|
|
|
|
|
a.AssuredName = assured.AssuredName
|
|
|
|
|
a.CreditVld = assured.CreditVld
|
|
|
|
|
a.CreditCode = assured.CreditCode
|
|
|
|
@ -194,6 +194,26 @@ func (s *orderService) GetOrderByToken(token string) (*model.Order, error) {
|
|
|
|
|
return &order, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *orderService) GetOrderByOrderNo(orderNo string) (*model.Order, error) {
|
|
|
|
|
order := model.Order{}
|
|
|
|
|
err := global.DB.
|
|
|
|
|
Preload("User").
|
|
|
|
|
Preload("Project").
|
|
|
|
|
Preload("Applicant").
|
|
|
|
|
Preload("Assured").
|
|
|
|
|
Where("order_no", orderNo).
|
|
|
|
|
First(&order).
|
|
|
|
|
Error
|
|
|
|
|
if err != nil {
|
|
|
|
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
|
|
|
return nil, e.NewError("记录不存在")
|
|
|
|
|
} else {
|
|
|
|
|
return nil, e.NewError("数据异常")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return &order, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *orderService) GetOrderByOrderSn(orderSn string) (*model.Order, error) {
|
|
|
|
|
order := model.Order{}
|
|
|
|
|
err := global.DB.
|
|
|
|
@ -214,7 +234,7 @@ func (s *orderService) GetOrderByOrderSn(orderSn string) (*model.Order, error) {
|
|
|
|
|
return &order, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *orderService) AddSignLog(orderSn string, param signer.UploadParam) (*model.SignLog, error) {
|
|
|
|
|
func (s *orderService) AddSignLog(orderNo string, param signer.UploadParam) (*model.SignLog, error) {
|
|
|
|
|
var err error
|
|
|
|
|
isUploadPdf := 1
|
|
|
|
|
if param.IsUploadPdf != "" {
|
|
|
|
@ -225,7 +245,7 @@ func (s *orderService) AddSignLog(orderSn string, param signer.UploadParam) (*mo
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
l := model.SignLog{}
|
|
|
|
|
l.OrderSn = orderSn
|
|
|
|
|
l.OrderNo = orderNo
|
|
|
|
|
l.Params = param.Params
|
|
|
|
|
l.CaInfo = param.CaInfo
|
|
|
|
|
l.IsUploadPdf = isUploadPdf
|
|
|
|
@ -238,7 +258,7 @@ func (s *orderService) AddSignLog(orderSn string, param signer.UploadParam) (*mo
|
|
|
|
|
return &l, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *orderService) PostToZking(orderSn string) (*zking.Result, error) {
|
|
|
|
|
func (s *orderService) PostToZking(orderNo string) (*zking.Result, error) {
|
|
|
|
|
order := model.Order{}
|
|
|
|
|
|
|
|
|
|
err := global.DB.
|
|
|
|
@ -246,7 +266,7 @@ func (s *orderService) PostToZking(orderSn string) (*zking.Result, error) {
|
|
|
|
|
Preload("Project").
|
|
|
|
|
Preload("Applicant").
|
|
|
|
|
Preload("Assured").
|
|
|
|
|
Where("order_sn", orderSn).
|
|
|
|
|
Where("order_no", orderNo).
|
|
|
|
|
First(&order).Error
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
@ -649,7 +669,7 @@ func (s *orderService) SaveOrderResult(data zking.PushCallbackData) (*model.Orde
|
|
|
|
|
return nil, e.NewError("参数错误")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_, err := s.GetOrderByOrderSn(data.OrderSn)
|
|
|
|
|
order, err := s.GetOrderByOrderSn(data.OrderSn)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
@ -660,6 +680,7 @@ func (s *orderService) SaveOrderResult(data zking.PushCallbackData) (*model.Orde
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
orderResult.OrderNo = order.OrderNo
|
|
|
|
|
orderResult.OrderSn = data.OrderSn
|
|
|
|
|
orderResult.PolicyNo = data.PolicyNo
|
|
|
|
|
orderResult.Status = data.Status
|
|
|
|
@ -740,3 +761,7 @@ func (s *orderService) UpdateApplicant(req request.UpdateApplicantRequest) (*mod
|
|
|
|
|
|
|
|
|
|
return order, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *orderService) UpdateOrderAfterPostToInsure(orderNo, payUrl string, orderSn string) {
|
|
|
|
|
global.DB.Model(&model.Order{}).Where("order_no", orderNo).UpdateColumns(model.Order{Status: "submitted", PayUrl: payUrl, OrderSn: orderSn})
|
|
|
|
|
}
|
|
|
|
|