distributor.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. package base
  2. import (
  3. "context"
  4. "dashoo.cn/common_definition/comm_def"
  5. "dashoo.cn/opms_libary/myerrors"
  6. "github.com/gogf/gf/frame/g"
  7. "github.com/gogf/gf/util/gvalid"
  8. model "dashoo.cn/micro/app/model/base"
  9. contractmodel "dashoo.cn/micro/app/model/contract"
  10. projmodel "dashoo.cn/micro/app/model/proj"
  11. server "dashoo.cn/micro/app/service/base"
  12. )
  13. type DistributorHandler struct{}
  14. // GetList 获取列表
  15. // Swagger:Distributor 经销商代理商 查询
  16. func (p *DistributorHandler) GetList(ctx context.Context, req *model.BaseDistributorSearchReq, rsp *comm_def.CommonMsg) error {
  17. distributorServer, err := server.NewDistributorService(ctx)
  18. if err != nil {
  19. return err
  20. }
  21. total, list, err := distributorServer.GetList(ctx, req)
  22. if err != nil {
  23. return err
  24. }
  25. rsp.Data = g.Map{"list": list, "total": total}
  26. return nil
  27. }
  28. // Swagger:Distributor 经销商代理商 新增
  29. func (p *DistributorHandler) Create(ctx context.Context, req *model.AddDistributor, rsp *comm_def.CommonMsg) error {
  30. distributorServer, err := server.NewDistributorService(ctx)
  31. if err != nil {
  32. return err
  33. }
  34. _, err = distributorServer.Create(ctx, req)
  35. if err != nil {
  36. return myerrors.CreateError(err, "经销商")
  37. }
  38. return nil
  39. }
  40. // GetEntityById 详情
  41. func (p *DistributorHandler) GetEntityById(ctx context.Context, req *comm_def.IdReq, rsp *comm_def.CommonMsg) error {
  42. if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
  43. return err
  44. }
  45. distributorServer, err := server.NewDistributorService(ctx)
  46. if err != nil {
  47. return err
  48. }
  49. list, err := distributorServer.GetEntityById(req.Id)
  50. if err != nil {
  51. return err
  52. }
  53. rsp.Data = g.Map{"list": list}
  54. return nil
  55. }
  56. // Swagger:Distributor 经销商代理商 修改
  57. func (p *DistributorHandler) UpdateById(ctx context.Context, req *model.UpdateDistributorReq, rsp *comm_def.CommonMsg) error {
  58. if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
  59. return err
  60. }
  61. distributorServer, err := server.NewDistributorService(ctx)
  62. if err != nil {
  63. return err
  64. }
  65. err = distributorServer.UpdateById(req)
  66. if err != nil {
  67. return err
  68. }
  69. return nil
  70. }
  71. // Swagger:Distributor 经销商代理商 转为代理商
  72. func (p *DistributorHandler) ToProxy(ctx context.Context, req *model.DistributorToProxyReq, rsp *comm_def.CommonMsg) error {
  73. g.Log().Infof("DistributorHandler.ToProxy request %#v ", *req)
  74. if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
  75. return err
  76. }
  77. distributorServer, err := server.NewDistributorService(ctx)
  78. if err != nil {
  79. return err
  80. }
  81. err = distributorServer.ToProxy(ctx, req)
  82. if err != nil {
  83. return err
  84. }
  85. return nil
  86. }
  87. // Swagger:Distributor 经销商代理商 续签
  88. func (p *DistributorHandler) Renew(ctx context.Context, req *model.DistributorRenewReq, rsp *comm_def.CommonMsg) error {
  89. g.Log().Infof("DistributorHandler.Renew request %#v ", *req)
  90. if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
  91. return err
  92. }
  93. distributorServer, err := server.NewDistributorService(ctx)
  94. if err != nil {
  95. return err
  96. }
  97. err = distributorServer.Renew(ctx, req)
  98. if err != nil {
  99. return err
  100. }
  101. return nil
  102. }
  103. // Swagger:Distributor 经销商代理商 转为经销商
  104. func (p *DistributorHandler) ToDist(ctx context.Context, req *model.DistributorToDistReq, rsp *comm_def.CommonMsg) error {
  105. g.Log().Infof("DistributorHandler.ToDist request %#v ", *req)
  106. if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
  107. return err
  108. }
  109. distributorServer, err := server.NewDistributorService(ctx)
  110. if err != nil {
  111. return err
  112. }
  113. err = distributorServer.ToDist(ctx, req)
  114. if err != nil {
  115. return err
  116. }
  117. return nil
  118. }
  119. // Swagger:Distributor 经销商代理商 历史代理
  120. func (c *DistributorHandler) TransRecord(ctx context.Context, req *model.DistributorTransRecordReq, rsp *comm_def.CommonMsg) error {
  121. g.Log().Infof("DistributorHandler.TransRecord request %#v ", *req)
  122. s, err := server.NewDistributorService(ctx)
  123. if err != nil {
  124. return err
  125. }
  126. total, ent, err := s.TransRecord(ctx, req)
  127. if err != nil {
  128. return err
  129. }
  130. if ent == nil {
  131. ent = []*model.BaseDistributorRecord{}
  132. }
  133. rsp.Data = g.Map{"list": ent, "total": total}
  134. return nil
  135. }
  136. // DeleteByIds 删掉
  137. func (p *DistributorHandler) DeleteByIds(ctx context.Context, req *model.DeleteDistributorReq, rsp *comm_def.CommonMsg) error {
  138. distributorServer, err := server.NewDistributorService(ctx)
  139. if err != nil {
  140. return err
  141. }
  142. err = distributorServer.DeleteByIds(req.Ids)
  143. if err != nil {
  144. return err
  145. }
  146. return nil
  147. }
  148. // Swagger:Distributor 经销商代理商 项目列表
  149. func (c *DistributorHandler) ProjectList(ctx context.Context, req *model.DistributorProjectListReq, rsp *comm_def.CommonMsg) error {
  150. g.Log().Infof("DistributorHandler.ProjectList request %#v ", *req)
  151. s, err := server.NewDistributorService(ctx)
  152. if err != nil {
  153. return err
  154. }
  155. total, ent, err := s.ProjectList(ctx, req)
  156. if err != nil {
  157. return err
  158. }
  159. if ent == nil {
  160. ent = []*projmodel.ProjBusiness{}
  161. }
  162. rsp.Data = g.Map{"list": ent, "total": total}
  163. return nil
  164. }
  165. // Swagger:Distributor 经销商代理商 合同列表
  166. func (c *DistributorHandler) ContractList(ctx context.Context, req *model.DistributorContractListReq, rsp *comm_def.CommonMsg) error {
  167. g.Log().Infof("DistributorHandler.ContractList request %#v ", *req)
  168. s, err := server.NewDistributorService(ctx)
  169. if err != nil {
  170. return err
  171. }
  172. total, ent, err := s.ContractList(ctx, req)
  173. if err != nil {
  174. return err
  175. }
  176. if ent == nil {
  177. ent = []*contractmodel.CtrContractListRsp{}
  178. }
  179. rsp.Data = g.Map{"list": ent, "total": total}
  180. return nil
  181. }
  182. func (c *DistributorHandler) DynamicsList(ctx context.Context, req *model.DistributorDynamicsListReq, rsp *comm_def.CommonMsg) error {
  183. g.Log().Infof("DistributorHandler.GetDynamicsList request %#v ", *req)
  184. s, err := server.NewDistributorService(ctx)
  185. if err != nil {
  186. return err
  187. }
  188. total, ent, err := s.DynamicsList(ctx, req)
  189. if err != nil {
  190. return err
  191. }
  192. if ent == nil {
  193. ent = []*model.BaseDistributorDynamics{}
  194. }
  195. rsp.Data = g.Map{"list": ent, "total": total}
  196. return nil
  197. }