| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- package train
- import (
- "context"
- dao "dashoo.cn/micro/app/dao/train"
- model "dashoo.cn/micro/app/model/train"
- "dashoo.cn/micro/app/service"
- "dashoo.cn/opms_libary/myerrors"
- "github.com/gogf/gf/database/gdb"
- "github.com/gogf/gf/frame/g"
- "github.com/gogf/gf/util/gconv"
- )
- type SaleApplySummaryService struct {
- *service.ContextService
- Dao *dao.TrainSaleApplySummaryDao
- }
- func NewSaleApplySummaryService(ctx context.Context) (svc *SaleApplySummaryService, err error) {
- svc = new(SaleApplySummaryService)
- if svc.ContextService, err = svc.Init(ctx); err != nil {
- return nil, err
- }
- svc.Dao = dao.NewTrainSaleApplySummaryDao(svc.Tenant)
- return svc, nil
- }
- // GetList 销售申请总结信息列表
- func (s *SaleApplySummaryService) GetList(ctx context.Context, req *model.TraSaleApplySummarySearchReq) (total int, distributorList []*model.TraSaleApplySummaryRes, err error) {
- distributorModel := s.Dao.FieldsEx(s.Dao.C.DeletedTime)
- if req.ApplyId != 0 {
- distributorModel = distributorModel.Where(s.Dao.C.ApplyId, req.ApplyId)
- }
- total, _ = distributorModel.Count()
- err = distributorModel.Order("id desc").Scan(&distributorList)
- if err != nil {
- return 0, nil, err
- }
- return
- }
- // GetEntityById 详情
- func (s *SaleApplySummaryService) GetEntityById(ctx context.Context, id int64) (distributorInfo *model.TraSaleApplySummaryRes, err error) {
- err = s.Dao.Where(s.Dao.C.Id, id).Scan(&distributorInfo)
- if err != nil {
- return nil, err
- }
- return
- }
- // CreateSupport
- // Create 支持人员反馈创建
- func (s *SaleApplySummaryService) CreateSupport(ctx context.Context, req *model.TraSaleSupportReq) (lastId int64, err error) {
- DistributorData := new(model.TrainSaleApplySummary)
- if err = gconv.Struct(req, DistributorData); err != nil {
- return 0, err
- }
- service.SetCreatedInfo(DistributorData, s.GetCxtUserId(), s.GetCxtUserName())
- svc, _ := NewSaleApplyService(ctx)
- txerr := s.Dao.DB.Transaction(ctx, func(ctx context.Context, tx *gdb.TX) error {
- count, e := s.Dao.Ctx(ctx).TX(tx).Where(s.Dao.C.ApplyId, req.ApplyId).Count()
- if e != nil {
- return e
- }
- if count == 0 {
- lastId, e = tx.InsertAndGetId("train_sale_apply_summary", DistributorData)
- if e != nil {
- return e
- }
- _, e = svc.Dao.Ctx(ctx).TX(tx).WherePri(req.ApplyId).Data(g.Map{svc.Dao.C.ApplyType: "25"}).Update()
- if e != nil {
- return e
- }
- } else {
- _, e = s.Dao.Ctx(ctx).TX(tx).FieldsEx(s.Dao.C.Id, s.Dao.C.CreatedName, s.Dao.C.CreatedBy, s.Dao.C.CreatedTime).
- Where(s.Dao.C.ApplyId, req.ApplyId).
- Data(g.Map{s.Dao.C.ApplyId: req.ApplyId, s.Dao.C.WorkOrderId: req.WorkOrderId, s.Dao.C.FeedbackSupportTime: req.FeedbackSupportTime, s.Dao.C.FeedbackSupportContent: req.FeedbackSupportContent}).Update()
- if e != nil {
- return e
- }
- _, e = svc.Dao.Ctx(ctx).TX(tx).WherePri(req.ApplyId).Data(g.Map{svc.Dao.C.ApplyType: "40"}).Update()
- if e != nil {
- return e
- }
- }
- return e
- })
- if txerr != nil {
- return 0, txerr
- }
- return lastId, nil
- }
- // Create 销售申请总结创建
- func (s *SaleApplySummaryService) Create(ctx context.Context, req *model.TraSaleApplySummaryCreateReq) (lastId int64, err error) {
- DistributorData := new(model.TrainSaleApplySummary)
- if err = gconv.Struct(req, DistributorData); err != nil {
- return 0, err
- }
- service.SetCreatedInfo(DistributorData, s.GetCxtUserId(), s.GetCxtUserName())
- svc, _ := NewSaleApplyService(ctx)
- txerr := s.Dao.DB.Transaction(ctx, func(ctx context.Context, tx *gdb.TX) error {
- count, e := s.Dao.Ctx(ctx).TX(tx).Where(s.Dao.C.ApplyId, req.ApplyId).Count()
- if e != nil {
- return e
- }
- if count == 0 {
- lastId, e = tx.InsertAndGetId("train_sale_apply_summary", DistributorData)
- if e != nil {
- return e
- }
- _, e = svc.Dao.Ctx(ctx).TX(tx).WherePri(req.ApplyId).Data(g.Map{svc.Dao.C.ApplyType: "30"}).Update()
- if e != nil {
- return e
- }
- } else {
- _, e = s.Dao.Ctx(ctx).TX(tx).FieldsEx(s.Dao.C.Id, s.Dao.C.CreatedName, s.Dao.C.CreatedBy, s.Dao.C.CreatedTime).
- Where(s.Dao.C.ApplyId, req.ApplyId).
- Data(g.Map{s.Dao.C.ApplyId: req.ApplyId, s.Dao.C.ExplainDuration: req.ExplainDuration, s.Dao.C.QuestionRecord: req.QuestionRecord, s.Dao.C.TrainSummary: req.TrainSummary, s.Dao.C.NextStep: req.NextStep}).Update()
- if e != nil {
- return e
- }
- _, e = svc.Dao.Ctx(ctx).TX(tx).WherePri(req.ApplyId).Data(g.Map{svc.Dao.C.ApplyType: "40"}).Update()
- if e != nil {
- return e
- }
- }
- return err
- })
- if txerr != nil {
- return 0, txerr
- }
- return lastId, nil
- }
- // UpdateById 修改数据
- func (s *SaleApplySummaryService) UpdateById(ctx context.Context, req *model.TraSaleApplySummaryUpdateReq) (err error) {
- ent, err := s.Dao.Where("id = ", req.Id).One()
- if err != nil {
- g.Log().Error(err)
- return
- }
- if ent == nil {
- err = myerrors.TipsError("无修改数据")
- return
- }
- distData := new(model.TrainSaleApplySummary)
- if err = gconv.Struct(req, distData); err != nil {
- return
- }
- service.SetUpdatedInfo(distData, s.GetCxtUserId(), s.GetCxtUserName())
- _, err = s.Dao.FieldsEx(s.Dao.C.Id, s.Dao.C.CreatedName, s.Dao.C.CreatedBy, s.Dao.C.CreatedTime).
- WherePri(s.Dao.C.Id, req.Id).Update(distData)
- if err != nil {
- g.Log().Error(err)
- return
- }
- return
- }
- // DeleteByIds 删除
- func (s *SaleApplySummaryService) DeleteByIds(ctx context.Context, ids []int64) (err error) {
- _, err = s.Dao.WhereIn(s.Dao.C.Id, ids).Delete()
- if err != nil {
- return err
- }
- return
- }
|