package controller import ( "context" "errors" "video-factory/common" "video-factory/shortdrama/dao" "video-factory/shortdrama/model/dto" "video-factory/shortdrama/service" "github.com/gogf/gf/v2/frame/g" ) type customer struct{} var Customer = new(customer) type createCustomerRes struct { Id int64 `json:"id"` } func (c *customer) Create(ctx context.Context, req *dto.CreateCustomerReq) (res *createCustomerRes, err error) { agentId := req.AgentId if agentId == 0 { r := g.RequestFromCtx(ctx) agentId = common.GetUserId(r) } user, err := dao.User.GetOne(ctx, agentId) if err != nil || user == nil || user.Role != "agent" { return nil, errors.New("agent not found") } user, err = service.CustomerService.CreateCustomer(ctx, req.Phone, req.Name, req.Address, agentId) if err != nil { return nil, err } return &createCustomerRes{Id: user.Id}, nil } func (c *customer) List(ctx context.Context, req *dto.ListCustomerReq) (res *dto.ListCustomerRes, err error) { return service.CustomerService.ListCustomers(ctx, req) } func (c *customer) Detail(ctx context.Context, req *struct{ Id int64 }) (res *dto.CustomerDetail, err error) { return service.CustomerService.GetCustomerDetail(ctx, req.Id) } func (c *customer) Update(ctx context.Context, req *dto.UpdateCustomerReq) (res *struct{}, err error) { r := g.RequestFromCtx(ctx) agentId := common.GetUserId(r) return nil, service.CustomerService.UpdateCustomer(ctx, agentId, req) }