distributor.go 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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(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. if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
  31. return err
  32. }
  33. distributorServer, err := server.NewDistributorService(ctx)
  34. if err != nil {
  35. return err
  36. }
  37. _, err = distributorServer.Create(req)
  38. if err != nil {
  39. return myerrors.CreateError(err, "经销商")
  40. }
  41. return nil
  42. }
  43. // GetEntityById 详情
  44. func (p *DistributorHandler) GetEntityById(ctx context.Context, req *comm_def.IdReq, rsp *comm_def.CommonMsg) error {
  45. if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
  46. return err
  47. }
  48. distributorServer, err := server.NewDistributorService(ctx)
  49. if err != nil {
  50. return err
  51. }
  52. list, err := distributorServer.GetEntityById(req.Id)
  53. if err != nil {
  54. return err
  55. }
  56. rsp.Data = g.Map{"list": list}
  57. return nil
  58. }
  59. // Swagger:Distributor 经销商代理商 修改
  60. func (p *DistributorHandler) UpdateById(ctx context.Context, req *model.UpdateDistributorReq, rsp *comm_def.CommonMsg) error {
  61. if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
  62. return err
  63. }
  64. distributorServer, err := server.NewDistributorService(ctx)
  65. if err != nil {
  66. return err
  67. }
  68. err = distributorServer.UpdateById(req)
  69. if err != nil {
  70. return err
  71. }
  72. return nil
  73. }
  74. // Swagger:Distributor 经销商代理商 转为代理商
  75. func (p *DistributorHandler) ToProxy(ctx context.Context, req *model.DistributorToProxyReq, rsp *comm_def.CommonMsg) error {
  76. g.Log().Infof("DistributorHandler.ToProxy request %#v ", *req)
  77. if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
  78. return err
  79. }
  80. distributorServer, err := server.NewDistributorService(ctx)
  81. if err != nil {
  82. return err
  83. }
  84. err = distributorServer.ToProxy(ctx, req)
  85. if err != nil {
  86. return err
  87. }
  88. return nil
  89. }
  90. // Swagger:Distributor 经销商代理商 续签
  91. func (p *DistributorHandler) Renew(ctx context.Context, req *model.DistributorRenewReq, rsp *comm_def.CommonMsg) error {
  92. g.Log().Infof("DistributorHandler.Renew request %#v ", *req)
  93. if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
  94. return err
  95. }
  96. distributorServer, err := server.NewDistributorService(ctx)
  97. if err != nil {
  98. return err
  99. }
  100. err = distributorServer.Renew(ctx, req)
  101. if err != nil {
  102. return err
  103. }
  104. return nil
  105. }
  106. // Swagger:Distributor 经销商代理商 转为经销商
  107. func (p *DistributorHandler) ToDist(ctx context.Context, req *model.DistributorToDistReq, rsp *comm_def.CommonMsg) error {
  108. g.Log().Infof("DistributorHandler.ToDist request %#v ", *req)
  109. if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
  110. return err
  111. }
  112. distributorServer, err := server.NewDistributorService(ctx)
  113. if err != nil {
  114. return err
  115. }
  116. err = distributorServer.ToDist(ctx, req)
  117. if err != nil {
  118. return err
  119. }
  120. return nil
  121. }
  122. // Swagger:Distributor 经销商代理商 历史代理
  123. func (c *DistributorHandler) TransRecord(ctx context.Context, req *model.DistributorTransRecordReq, rsp *comm_def.CommonMsg) error {
  124. g.Log().Infof("DistributorHandler.TransRecord request %#v ", *req)
  125. s, err := server.NewDistributorService(ctx)
  126. if err != nil {
  127. return err
  128. }
  129. total, ent, err := s.TransRecord(ctx, req)
  130. if err != nil {
  131. return err
  132. }
  133. if ent == nil {
  134. ent = []*model.BaseDistributorRecord{}
  135. }
  136. rsp.Data = g.Map{"list": ent, "total": total}
  137. return nil
  138. }
  139. // DeleteByIds 删掉
  140. func (p *DistributorHandler) DeleteByIds(ctx context.Context, req *model.DeleteDistributorReq, rsp *comm_def.CommonMsg) error {
  141. distributorServer, err := server.NewDistributorService(ctx)
  142. if err != nil {
  143. return err
  144. }
  145. err = distributorServer.DeleteByIds(req.Ids)
  146. if err != nil {
  147. return err
  148. }
  149. return nil
  150. }
  151. // Swagger:Distributor 经销商代理商 项目列表
  152. func (c *DistributorHandler) ProjectList(ctx context.Context, req *model.DistributorProjectListReq, rsp *comm_def.CommonMsg) error {
  153. g.Log().Infof("DistributorHandler.ProjectList request %#v ", *req)
  154. s, err := server.NewDistributorService(ctx)
  155. if err != nil {
  156. return err
  157. }
  158. total, ent, err := s.ProjectList(ctx, req)
  159. if err != nil {
  160. return err
  161. }
  162. if ent == nil {
  163. ent = []*projmodel.ProjBusiness{}
  164. }
  165. rsp.Data = g.Map{"list": ent, "total": total}
  166. return nil
  167. }
  168. // Swagger:Distributor 经销商代理商 合同列表
  169. func (c *DistributorHandler) ContractList(ctx context.Context, req *model.DistributorContractListReq, rsp *comm_def.CommonMsg) error {
  170. g.Log().Infof("DistributorHandler.ContractList request %#v ", *req)
  171. s, err := server.NewDistributorService(ctx)
  172. if err != nil {
  173. return err
  174. }
  175. total, ent, err := s.ContractList(ctx, req)
  176. if err != nil {
  177. return err
  178. }
  179. if ent == nil {
  180. ent = []*contractmodel.CtrContractListRsp{}
  181. }
  182. rsp.Data = g.Map{"list": ent, "total": total}
  183. return nil
  184. }
  185. func (c *DistributorHandler) DynamicsList(ctx context.Context, req *model.DistributorDynamicsListReq, rsp *comm_def.CommonMsg) error {
  186. g.Log().Infof("DistributorHandler.GetDynamicsList request %#v ", *req)
  187. s, err := server.NewDistributorService(ctx)
  188. if err != nil {
  189. return err
  190. }
  191. total, ent, err := s.DynamicsList(ctx, req)
  192. if err != nil {
  193. return err
  194. }
  195. if ent == nil {
  196. ent = []*model.BaseDistributorDynamics{}
  197. }
  198. rsp.Data = g.Map{"list": ent, "total": total}
  199. return nil
  200. }