refactor(service): 简化 CompleteRedeemExValue 函数参数及调用
- 移除 CompleteRedeemExValue 中的 orderAmount 参数 - 删除对订单金额和提交金额一致性的校验 - 调整 scan_controller 中对 CompleteRedeemExValue 的调用逻辑 - 删除不必要的空行和变量赋值 - 优化错误处理及日志输出信息
This commit is contained in:
@@ -155,7 +155,6 @@ func (c *ScanController) Scan() {
|
||||
c.SolveFailJSON(p)
|
||||
return
|
||||
}
|
||||
|
||||
mt := merchant_deploy.GetMerchantDeployByUidAndRoadUid(ctx, p.MerchantInfo.MerchantUid, p.RoadInfo.RoadUid)
|
||||
if mt.Id == 0 {
|
||||
p.Msg = "当前用户没有开通该通道"
|
||||
@@ -163,7 +162,7 @@ func (c *ScanController) Scan() {
|
||||
return
|
||||
}
|
||||
|
||||
orderPrice, err := strconv.ParseFloat(convertor.ToString(p.Params["orderPrice"]), 64)
|
||||
_, err = strconv.ParseFloat(convertor.ToString(p.Params["orderPrice"]), 64)
|
||||
if err != nil {
|
||||
p.Code = -1
|
||||
p.Msg = fmt.Sprintf("订单金额转换失败:%v", err.Error())
|
||||
@@ -171,15 +170,7 @@ func (c *ScanController) Scan() {
|
||||
return
|
||||
}
|
||||
|
||||
pm, err := mt.GetProfitMarginByFactLabel(ctx, orderPrice)
|
||||
if err != nil {
|
||||
p.Code = -1
|
||||
p.Msg = fmt.Sprintf("获取展示比例失败:%v", err.Error())
|
||||
c.SolveFailJSON(p)
|
||||
return
|
||||
}
|
||||
|
||||
p.Params["exValue"], err = service.CompleteRedeemExValue(ctx, orderPrice, convertor.ToString(p.Params["exValue"]), strconv.FormatFloat(pm.ShowLabel, 'f', 0, 64))
|
||||
p.Params["exValue"], err = service.CompleteRedeemExValue(ctx, convertor.ToString(p.Params["exValue"]), p.Params["orderPrice"].(string))
|
||||
if err != nil {
|
||||
p.Code = -1
|
||||
p.Msg = fmt.Sprintf("订单金额转换失败:%v", err.Error())
|
||||
|
||||
@@ -77,16 +77,13 @@ func ExValueIsValid(ctx context.Context, c *response.PayBaseResp) *response.PayB
|
||||
return c
|
||||
}
|
||||
|
||||
func CompleteRedeemExValue(ctx context.Context, orderAmount float64, exValueStr string, faceValue string) (string, error) {
|
||||
func CompleteRedeemExValue(ctx context.Context, exValueStr string, faceValue string) (string, error) {
|
||||
exValue := supplier.RedeemCardInfo{}
|
||||
if err := json.Unmarshal([]byte(exValueStr), &exValue); err != nil {
|
||||
return "", err
|
||||
}
|
||||
exValue.FaceType = faceValue
|
||||
res, err := json.Marshal(&exValue)
|
||||
if orderAmount != exValue.GetFaceTypeFloat(ctx) {
|
||||
return "", errors.New("订单金额与提交的金额不一致")
|
||||
}
|
||||
return string(res), err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user