| | |
| | | "fmt" |
| | | "github.com/shopspring/decimal" |
| | | "gorm.io/gorm" |
| | | "strconv" |
| | | ) |
| | | |
| | | type Server struct { |
| | |
| | | ProductTotal: total.IntPart(), |
| | | ProjectId: req.ProjectId, |
| | | Products: products, |
| | | DeliverType: int64(detail.DeliverType), |
| | | }) |
| | | if err != nil { |
| | | //状态还原 |
| | |
| | | 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("销售明细编号为空") |
| | |
| | | |
| | | return &RemoveSalesDetailResponse{}, nil |
| | | } |
| | | |
| | | func (s *Server) GetCrmSalesDetailsProductInfo(ctx context.Context, req *GetCrmSalesDetailsProductInfoRequest) (*GetCrmSalesDetailsProductInfoResponse, error) { |
| | | if req.SalesDetailsNumber == "" { |
| | | return nil, errors.New("销售明细编号为空") |
| | | } |
| | | first, err := model.NewSalesDetailsSearch().SetPreload(true).SetNumber(req.SalesDetailsNumber).First() |
| | | if err != nil { |
| | | return nil, err |
| | | } |
| | | list := make([]*CrmSalesDetailsProductInfo, 0) |
| | | for _, product := range first.Products { |
| | | var csp CrmSalesDetailsProductInfo |
| | | csp.ProductId = product.Number |
| | | csp.ProductName = product.Name |
| | | csp.Specs = product.Specs |
| | | csp.Unit = product.Unit |
| | | csp.Amount = product.Amount.IntPart() |
| | | csp.Cost = product.Cost |
| | | csp.Price = product.Price.IntPart() |
| | | csp.Total = product.Total.IntPart() |
| | | csp.Profit = product.Profit |
| | | csp.Margin = product.Margin |
| | | list = append(list, &csp) |
| | | } |
| | | resp := new(GetCrmSalesDetailsProductInfoResponse) |
| | | resp.List = list |
| | | return resp, nil |
| | | } |