(c *gin.Context)
| 176 | } |
| 177 | |
| 178 | func EpayNotify(c *gin.Context) { |
| 179 | params := lo.Reduce(lo.Keys(c.Request.URL.Query()), func(r map[string]string, t string, i int) map[string]string { |
| 180 | r[t] = c.Request.URL.Query().Get(t) |
| 181 | return r |
| 182 | }, map[string]string{}) |
| 183 | client := GetEpayClient() |
| 184 | if client == nil { |
| 185 | log.Println("易支付回调失败 未找到配置信息") |
| 186 | _, err := c.Writer.Write([]byte("fail")) |
| 187 | if err != nil { |
| 188 | log.Println("易支付回调写入失败") |
| 189 | return |
| 190 | } |
| 191 | } |
| 192 | verifyInfo, err := client.Verify(params) |
| 193 | if err == nil && verifyInfo.VerifyStatus { |
| 194 | _, err := c.Writer.Write([]byte("success")) |
| 195 | if err != nil { |
| 196 | log.Println("易支付回调写入失败") |
| 197 | } |
| 198 | } else { |
| 199 | _, err := c.Writer.Write([]byte("fail")) |
| 200 | if err != nil { |
| 201 | log.Println("易支付回调写入失败") |
| 202 | } |
| 203 | log.Println("易支付回调签名验证失败") |
| 204 | return |
| 205 | } |
| 206 | |
| 207 | if verifyInfo.TradeStatus == epay.StatusTradeSuccess { |
| 208 | log.Println(verifyInfo) |
| 209 | LockOrder(verifyInfo.ServiceTradeNo) |
| 210 | defer UnlockOrder(verifyInfo.ServiceTradeNo) |
| 211 | topUp := model.GetTopUpByTradeNo(verifyInfo.ServiceTradeNo) |
| 212 | if topUp == nil { |
| 213 | log.Printf("易支付回调未找到订单: %v", verifyInfo) |
| 214 | return |
| 215 | } |
| 216 | if topUp.Status == "pending" { |
| 217 | topUp.Status = "success" |
| 218 | err := topUp.Update() |
| 219 | if err != nil { |
| 220 | log.Printf("易支付回调更新订单失败: %v", topUp) |
| 221 | return |
| 222 | } |
| 223 | //user, _ := model.GetUserById(topUp.UserId, false) |
| 224 | //user.Quota += topUp.Amount * 500000 |
| 225 | dAmount := decimal.NewFromInt(int64(topUp.Amount)) |
| 226 | dQuotaPerUnit := decimal.NewFromFloat(common.QuotaPerUnit) |
| 227 | quotaToAdd := int(dAmount.Mul(dQuotaPerUnit).IntPart()) |
| 228 | err = model.IncreaseUserQuota(topUp.UserId, quotaToAdd, true) |
| 229 | if err != nil { |
| 230 | log.Printf("易支付回调更新用户失败: %v", topUp) |
| 231 | return |
| 232 | } |
| 233 | log.Printf("易支付回调更新用户成功 %v", topUp) |
| 234 | model.RecordLog(topUp.UserId, model.LogTypeTopup, fmt.Sprintf("使用在线充值成功,充值金额: %v,支付金额:%f", common.LogQuota(quotaToAdd), topUp.Money)) |
| 235 | } |
nothing calls this directly
no test coverage detected