feat: 客户端接口数据模型基础准备
- 新增资产状态、订单来源、操作人类型、实名链接类型常量 - 8个模型新增字段(asset_status/generation/source/retail_price等) - 数据库迁移000082:7张表15+字段,含存量retail_price回填 - BUG-1修复:代理零售价渠道隔离,cost_price分配锁定 - BUG-2修复:一次性佣金仅客户端订单触发 - BUG-4修复:充值回调Store操作纳入事务 - 新增资产手动停用接口(PATCH /iot-cards/:id/deactivate、/devices/:id/deactivate) - Carrier管理新增实名链接配置 - 后台订单generation写时快照 - BatchUpdatePricing支持retail_price调价目标 - 清理全部H5旧接口和个人客户旧登录方法
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"github.com/break/junhong_cmp_fiber/internal/model/dto"
|
||||
"github.com/break/junhong_cmp_fiber/internal/service/personal_customer"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/errors"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/response"
|
||||
@@ -25,45 +24,6 @@ func NewPersonalCustomerHandler(service *personal_customer.Service, logger *zap.
|
||||
}
|
||||
}
|
||||
|
||||
// SendCodeRequest 发送验证码请求
|
||||
type SendCodeRequest struct {
|
||||
Phone string `json:"phone" validate:"required,len=11"` // 手机号(11位)
|
||||
}
|
||||
|
||||
// SendCode 发送验证码
|
||||
// POST /api/c/v1/login/send-code
|
||||
func (h *PersonalCustomerHandler) SendCode(c *fiber.Ctx) error {
|
||||
var req SendCodeRequest
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "请求参数解析失败")
|
||||
}
|
||||
|
||||
// 发送验证码
|
||||
if err := h.service.SendVerificationCode(c.Context(), req.Phone); err != nil {
|
||||
h.logger.Error("发送验证码失败",
|
||||
zap.String("phone", req.Phone),
|
||||
zap.Error(err),
|
||||
)
|
||||
return errors.Wrap(errors.CodeInternalError, err, "发送验证码失败")
|
||||
}
|
||||
|
||||
return response.Success(c, fiber.Map{
|
||||
"message": "验证码已发送",
|
||||
})
|
||||
}
|
||||
|
||||
// LoginRequest 登录请求
|
||||
type LoginRequest struct {
|
||||
Phone string `json:"phone" validate:"required,len=11"` // 手机号(11位)
|
||||
Code string `json:"code" validate:"required,len=6"` // 验证码(6位)
|
||||
}
|
||||
|
||||
// LoginResponse 登录响应
|
||||
type LoginResponse struct {
|
||||
Token string `json:"token"` // 访问令牌
|
||||
Customer *PersonalCustomerDTO `json:"customer"` // 客户信息
|
||||
}
|
||||
|
||||
// PersonalCustomerDTO 个人客户 DTO
|
||||
type PersonalCustomerDTO struct {
|
||||
ID uint `json:"id"`
|
||||
@@ -74,87 +34,6 @@ type PersonalCustomerDTO struct {
|
||||
Status int `json:"status"`
|
||||
}
|
||||
|
||||
// Login 登录(手机号 + 验证码)
|
||||
// POST /api/c/v1/login
|
||||
func (h *PersonalCustomerHandler) Login(c *fiber.Ctx) error {
|
||||
var req LoginRequest
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "请求参数解析失败")
|
||||
}
|
||||
|
||||
// 登录
|
||||
token, customer, err := h.service.LoginByPhone(c.Context(), req.Phone, req.Code)
|
||||
if err != nil {
|
||||
h.logger.Error("登录失败",
|
||||
zap.String("phone", req.Phone),
|
||||
zap.Error(err),
|
||||
)
|
||||
return errors.Wrap(errors.CodeInternalError, err, "登录失败")
|
||||
}
|
||||
|
||||
// 构造响应
|
||||
// 注意:Phone 字段已从 PersonalCustomer 模型移除,需要从 PersonalCustomerPhone 表查询
|
||||
resp := &LoginResponse{
|
||||
Token: token,
|
||||
Customer: &PersonalCustomerDTO{
|
||||
ID: customer.ID,
|
||||
Phone: req.Phone, // 使用请求中的手机号(临时方案)
|
||||
Nickname: customer.Nickname,
|
||||
AvatarURL: customer.AvatarURL,
|
||||
WxOpenID: customer.WxOpenID,
|
||||
Status: customer.Status,
|
||||
},
|
||||
}
|
||||
|
||||
return response.Success(c, resp)
|
||||
}
|
||||
|
||||
// WechatOAuthLogin 微信 OAuth 登录
|
||||
// POST /api/c/v1/wechat/auth
|
||||
func (h *PersonalCustomerHandler) WechatOAuthLogin(c *fiber.Ctx) error {
|
||||
var req dto.WechatOAuthRequest
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "请求参数解析失败")
|
||||
}
|
||||
|
||||
result, err := h.service.WechatOAuthLogin(c.Context(), req.Code)
|
||||
if err != nil {
|
||||
h.logger.Error("微信 OAuth 登录失败",
|
||||
zap.String("code", req.Code),
|
||||
zap.Error(err),
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
return response.Success(c, result)
|
||||
}
|
||||
|
||||
// BindWechat 绑定微信
|
||||
// POST /api/c/v1/bind-wechat
|
||||
func (h *PersonalCustomerHandler) BindWechat(c *fiber.Ctx) error {
|
||||
var req dto.WechatOAuthRequest
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "请求参数解析失败")
|
||||
}
|
||||
|
||||
customerID, ok := c.Locals("customer_id").(uint)
|
||||
if !ok {
|
||||
return errors.New(errors.CodeUnauthorized, "未找到客户信息")
|
||||
}
|
||||
|
||||
if err := h.service.BindWechatWithCode(c.Context(), customerID, req.Code); err != nil {
|
||||
h.logger.Error("绑定微信失败",
|
||||
zap.Uint("customer_id", customerID),
|
||||
zap.Error(err),
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
return response.Success(c, fiber.Map{
|
||||
"message": "绑定成功",
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateProfileRequest 更新个人资料请求
|
||||
type UpdateProfileRequest struct {
|
||||
Nickname string `json:"nickname"` // 昵称
|
||||
|
||||
Reference in New Issue
Block a user