| | |
| | | "fmt" |
| | | "github.com/shopspring/decimal" |
| | | "gorm.io/gorm" |
| | | "strconv" |
| | | ) |
| | | |
| | | type Server struct { |
| | |
| | | resp.List = append(resp.List, &Client{ |
| | | Number: client.Number, |
| | | Name: client.Name, |
| | | Id: int64(client.Id), |
| | | }) |
| | | } |
| | | return resp, nil |
| | | } |
| | | |
| | | func (s *Server) GetClientMaxId(ctx context.Context, req *ClientMaxIdRequest) (*ClientMaxIdResponse, error) { |
| | | clientService := new(service.ClientService) |
| | | id, err := clientService.GetClientMaxId() |
| | | return &ClientMaxIdResponse{Id: int64(id)}, err |
| | | } |
| | | func (s *Server) AddClient(ctx context.Context, req *AddClientRequest) (*ClientMsgResponse, error) { |
| | | clientService := new(service.ClientService) |
| | | client := &model.Client{Id: int(req.Id), Number: req.Number, Name: req.Name, DetailAddress: req.DetailAddress, Remark: req.Remark, CreatorId: int(req.CreatorId)} |
| | | code := clientService.AddClient(client, 0) |
| | | if code != ecode.OK { |
| | | return &ClientMsgResponse{Code: int64(code), Msg: "添加失败", Id: strconv.Itoa(client.Id)}, nil |
| | | } |
| | | return &ClientMsgResponse{Code: int64(code), Msg: "添加成功", Id: strconv.Itoa(client.Id)}, nil |
| | | } |
| | | func (s *Server) EditClient(ctx context.Context, req *EditClientRequest) (*ClientMsgResponse, error) { |
| | | clientService := new(service.ClientService) |
| | | client := &model.Client{Id: int(req.Id), Number: req.Number, Name: req.Name, DetailAddress: req.DetailAddress, Remark: req.Remark, CreatorId: int(req.CreatorId)} |
| | | code := clientService.UpdateClient(client, 0) |
| | | if code != ecode.OK { |
| | | return &ClientMsgResponse{Code: int64(code), Msg: "添加失败", Id: strconv.Itoa(client.Id)}, nil |
| | | } |
| | | return &ClientMsgResponse{Code: int64(code), Msg: "添加成功", Id: strconv.Itoa(client.Id)}, nil |
| | | } |
| | | func (s *Server) DelClient(ctx context.Context, req *DelClientRequest) (*ClientMsgResponse, error) { |
| | | clientService := new(service.ClientService) |
| | | |
| | | code := clientService.DeleteClient([]int{int(req.Id)}) |
| | | if code != ecode.OK { |
| | | return &ClientMsgResponse{Code: int64(code), Msg: "删除失败", Id: strconv.FormatInt(req.Id, 10)}, nil |
| | | } |
| | | return &ClientMsgResponse{Code: int64(code), Msg: "删除成功", Id: strconv.FormatInt(req.Id, 10)}, nil |
| | | } |
| | | |
| | | func (s *Server) UpdateSalesDetail(ctx context.Context, req *UpdateSalesDetailRequest) (*UpdateSalesDetailResponse, error) { |
| | | if req.Number == "" { |
| | | return nil, errors.New("销售明细编号为空") |