已完成用户APP首期功能开发
交付用户端首期页面、配套接口、后台资源及测试文档。用户APP构建、静态分析和三个管理后台构建通过;完整测试仍有2项失败,后端模型注释检查未通过,详见交付记录。
This commit is contained in:
100
backend/api/internal/logic/client/user/deposit.go
Normal file
100
backend/api/internal/logic/client/user/deposit.go
Normal file
@@ -0,0 +1,100 @@
|
||||
// 功能描述:用户本人押金汇总、状态筛选和规则读取;版本:1.0.0。
|
||||
package user
|
||||
|
||||
import (
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/infra"
|
||||
"git.apinb.com/heqiapp/platforms/backend/api/internal/impl"
|
||||
"git.apinb.com/heqiapp/platforms/backend/api/internal/logic/common"
|
||||
"git.apinb.com/heqiapp/platforms/backend/api/internal/models"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// ListDeposits 只按JWT账户返回押金事实,不接受调用方指定用户。
|
||||
func ListDeposits(ctx *gin.Context) {
|
||||
account, ok := common.UserAccount(ctx)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
status := ctx.Query("status")
|
||||
var summary struct {
|
||||
RefundableAmount int64 `gorm:"column:refundable_amount"`
|
||||
UsingCount int `gorm:"column:using_count"`
|
||||
}
|
||||
if err := impl.DBService.Model(&models.DepositRecord{}).
|
||||
Where("user_account_id = ? AND status <> ? AND deposit_status = ?", account.ID, common.StatusArchived, 10).
|
||||
Select("COALESCE(SUM(amount), 0) AS refundable_amount, COUNT(*) AS using_count").Scan(&summary).Error; err != nil {
|
||||
infra.Response.Error(ctx, err)
|
||||
return
|
||||
}
|
||||
query := impl.DBService.Where("user_account_id = ? AND status <> ?", account.ID, common.StatusArchived)
|
||||
switch status {
|
||||
case "", "all":
|
||||
case "using":
|
||||
query = query.Where("deposit_status = ?", 10)
|
||||
case "refunding":
|
||||
query = query.Where("deposit_status = ?", 20)
|
||||
case "returned":
|
||||
query = query.Where("deposit_status = ?", 23)
|
||||
default:
|
||||
infra.Response.Error(ctx, errcode.ErrInvalidArgument)
|
||||
return
|
||||
}
|
||||
var records []models.DepositRecord
|
||||
if err := query.Order("paid_at desc, identity desc").Find(&records).Error; err != nil {
|
||||
infra.Response.Error(ctx, err)
|
||||
return
|
||||
}
|
||||
items := make([]gin.H, 0, len(records))
|
||||
returnByDeposit := make(map[uint64]models.DepositReturnRequest, len(records))
|
||||
if len(records) > 0 {
|
||||
ids := make([]uint64, 0, len(records))
|
||||
for _, record := range records {
|
||||
ids = append(ids, record.ID)
|
||||
}
|
||||
var returns []models.DepositReturnRequest
|
||||
if err := impl.DBService.Where("deposit_record_id IN ? AND return_status <> ?", ids, 50).Find(&returns).Error; err != nil {
|
||||
infra.Response.Error(ctx, err)
|
||||
return
|
||||
}
|
||||
for _, request := range returns {
|
||||
returnByDeposit[request.DepositRecordID] = request
|
||||
}
|
||||
}
|
||||
for _, record := range records {
|
||||
var product models.ProductInfo
|
||||
if err := impl.DBService.Where("id = ?", record.ProductInfoID).Take(&product).Error; err != nil {
|
||||
infra.Response.Error(ctx, err)
|
||||
return
|
||||
}
|
||||
var productType models.ProductType
|
||||
if err := impl.DBService.Where("id = ?", product.ProductTypeID).Take(&productType).Error; err != nil {
|
||||
infra.Response.Error(ctx, err)
|
||||
return
|
||||
}
|
||||
statusName := map[int]string{10: "使用中", 20: "退款中", 23: "已退回"}[record.DepositStatus]
|
||||
if statusName == "" {
|
||||
statusName = "处理中"
|
||||
}
|
||||
item := gin.H{
|
||||
"identity": record.Identity, "deposit_no": record.DepositNo, "deposit_status": record.DepositStatus,
|
||||
"status_name": statusName, "amount": record.Amount, "product_name": productType.Name,
|
||||
"product_code": product.Code, "paid_at": record.PaidAt, "refunded_at": record.RefundedAt,
|
||||
"allowed_actions": func() []string {
|
||||
if record.DepositStatus == 10 {
|
||||
return []string{"return_bottle"}
|
||||
}
|
||||
return []string{}
|
||||
}(),
|
||||
}
|
||||
if request, exists := returnByDeposit[record.ID]; exists {
|
||||
item["return_request_identity"] = request.Identity
|
||||
item["return_status"] = request.ReturnStatus
|
||||
item["return_status_name"] = map[int]string{10: "待上门", 20: "已回收待验收", 30: "已验收待退款", 40: "已完成"}[request.ReturnStatus]
|
||||
}
|
||||
items = append(items, item)
|
||||
}
|
||||
var policy models.DepositPolicy
|
||||
_ = impl.DBService.Where("status = ?", common.StatusEnable).Order("updated_at desc").Find(&policy).Error
|
||||
infra.Response.Success(ctx, gin.H{"refundable_amount": summary.RefundableAmount, "using_count": summary.UsingCount, "items": items, "rule_text": policy.RuleText})
|
||||
}
|
||||
Reference in New Issue
Block a user