1
This commit is contained in:
@@ -2,8 +2,10 @@ package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"video-factory/common"
|
||||
|
||||
"video-factory/shortdrama/middleware"
|
||||
"video-factory/shortdrama/dao"
|
||||
"video-factory/shortdrama/model/dto"
|
||||
"video-factory/shortdrama/service"
|
||||
|
||||
@@ -22,9 +24,13 @@ func (c *customer) Create(ctx context.Context, req *dto.CreateCustomerReq) (res
|
||||
agentId := req.AgentId
|
||||
if agentId == 0 {
|
||||
r := g.RequestFromCtx(ctx)
|
||||
agentId = middleware.GetUserId(r)
|
||||
agentId = common.GetUserId(r)
|
||||
}
|
||||
user, err := service.CustomerService.CreateCustomer(ctx, req.Phone, req.Name, req.Address, agentId)
|
||||
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
|
||||
}
|
||||
@@ -41,6 +47,6 @@ func (c *customer) Detail(ctx context.Context, req *struct{ Id int64 }) (res *dt
|
||||
|
||||
func (c *customer) Update(ctx context.Context, req *dto.UpdateCustomerReq) (res *struct{}, err error) {
|
||||
r := g.RequestFromCtx(ctx)
|
||||
agentId := middleware.GetUserId(r)
|
||||
agentId := common.GetUserId(r)
|
||||
return nil, service.CustomerService.UpdateCustomer(ctx, agentId, req)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user