forked from free-lancers/electricity_bill_calc_service
		
	fix(charge):基本完成用户充值功能部分的测试。
This commit is contained in:
		| @@ -50,9 +50,9 @@ func createNewUserChargeRecord(c *fiber.Ctx) error { | |||||||
| 		chargeLog.Error("无法解析创建充值记录的请求数据。", zap.Error(err)) | 		chargeLog.Error("无法解析创建充值记录的请求数据。", zap.Error(err)) | ||||||
| 		return result.Error(http.StatusBadRequest, err.Error()) | 		return result.Error(http.StatusBadRequest, err.Error()) | ||||||
| 	} | 	} | ||||||
| 	fee, _ := createionForm.Fee.Float64() | 	fee, _ := createionForm.Fee.Decimal.Float64() | ||||||
| 	discount, _ := createionForm.Discount.Float64() | 	discount, _ := createionForm.Discount.Decimal.Float64() | ||||||
| 	amount, _ := createionForm.Amount.Float64() | 	amount, _ := createionForm.Amount.Decimal.Float64() | ||||||
| 	ok, err := service.ChargeService.RecordUserCharge( | 	ok, err := service.ChargeService.RecordUserCharge( | ||||||
| 		createionForm.UserId, | 		createionForm.UserId, | ||||||
| 		&fee, | 		&fee, | ||||||
|   | |||||||
| @@ -24,9 +24,9 @@ type UserChargeDetail struct { | |||||||
| } | } | ||||||
|  |  | ||||||
| type ChargeRecordCreationForm struct { | type ChargeRecordCreationForm struct { | ||||||
| 	UserId   string           `json:"userId"` | 	UserId   string              `json:"userId"` | ||||||
| 	Fee      *decimal.Decimal `json:"fee"` | 	Fee      decimal.NullDecimal `json:"fee"` | ||||||
| 	Discount *decimal.Decimal `json:"discount"` | 	Discount decimal.NullDecimal `json:"discount"` | ||||||
| 	Amount   *decimal.Decimal `json:"amount"` | 	Amount   decimal.NullDecimal `json:"amount"` | ||||||
| 	ChargeTo types.Date       `json:"chargeTo"` | 	ChargeTo types.Date          `json:"chargeTo"` | ||||||
| } | } | ||||||
|   | |||||||
| @@ -401,7 +401,7 @@ func (ur _UserRepository) ChangeState(uid string, state bool) (bool, error) { | |||||||
| } | } | ||||||
|  |  | ||||||
| // 检索条目数量有限的用户详细信息 | // 检索条目数量有限的用户详细信息 | ||||||
| func (ur _UserRepository) SearchUsersWithLimit(userType *int16, keyword *string, limit uint) ([]*model.UserDetail, error) { | func (ur _UserRepository) SearchUsersWithLimit(userType *int16, keyword *string, limit uint) ([]*model.UserWithDetail, error) { | ||||||
| 	ur.log.Info("检索条目数量有限的用户详细信息。", zap.Int16p("user type", userType), zap.Uint("limit", limit), zap.Stringp("keyword", keyword)) | 	ur.log.Info("检索条目数量有限的用户详细信息。", zap.Int16p("user type", userType), zap.Uint("limit", limit), zap.Stringp("keyword", keyword)) | ||||||
| 	actualUserType := tools.DefaultTo(userType, model.USER_TYPE_ENT) | 	actualUserType := tools.DefaultTo(userType, model.USER_TYPE_ENT) | ||||||
| 	cacheConditions := []string{ | 	cacheConditions := []string{ | ||||||
| @@ -409,13 +409,13 @@ func (ur _UserRepository) SearchUsersWithLimit(userType *int16, keyword *string, | |||||||
| 		tools.DefaultTo(keyword, ""), | 		tools.DefaultTo(keyword, ""), | ||||||
| 		fmt.Sprintf("%d", limit), | 		fmt.Sprintf("%d", limit), | ||||||
| 	} | 	} | ||||||
| 	if users, err := cache.RetrieveSearch[[]*model.UserDetail]("user_with_detail_limited", cacheConditions...); err == nil && users != nil { | 	if users, err := cache.RetrieveSearch[[]*model.UserWithDetail]("user_with_detail_limited", cacheConditions...); err == nil && users != nil { | ||||||
| 		return *users, nil | 		return *users, nil | ||||||
| 	} | 	} | ||||||
| 	ctx, cancel := global.TimeoutContext() | 	ctx, cancel := global.TimeoutContext() | ||||||
| 	defer cancel() | 	defer cancel() | ||||||
|  |  | ||||||
| 	var users []*model.UserDetail | 	var users = make([]*model.UserWithDetail, 0) | ||||||
| 	userQuery := ur.ds. | 	userQuery := ur.ds. | ||||||
| 		From(goqu.T("user").As("u")). | 		From(goqu.T("user").As("u")). | ||||||
| 		Join(goqu.T("user_detail").As("ud"), goqu.On(goqu.Ex{"ud.id": goqu.I("u.id")})). | 		Join(goqu.T("user_detail").As("ud"), goqu.On(goqu.Ex{"ud.id": goqu.I("u.id")})). | ||||||
| @@ -442,7 +442,7 @@ func (ur _UserRepository) SearchUsersWithLimit(userType *int16, keyword *string, | |||||||
| 	userQuery.Order(goqu.I("u.created_at").Desc()).Limit(limit) | 	userQuery.Order(goqu.I("u.created_at").Desc()).Limit(limit) | ||||||
|  |  | ||||||
| 	userSql, userParams, _ := userQuery.Prepared(true).ToSQL() | 	userSql, userParams, _ := userQuery.Prepared(true).ToSQL() | ||||||
| 	if err := pgxscan.Select(ctx, global.DB, users, userSql, userParams...); err != nil { | 	if err := pgxscan.Select(ctx, global.DB, &users, userSql, userParams...); err != nil { | ||||||
| 		ur.log.Error("从数据库查询用户列表失败。", zap.Error(err)) | 		ur.log.Error("从数据库查询用户列表失败。", zap.Error(err)) | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user