package service import ( "context" "dubbo.apache.org/dubbo-go/v3/common/logger" "github.com/fonchain_enterprise/fonchain-main/api/order" "github.com/fonchain_enterprise/fonchain-main/api/orderproduct" "github.com/fonchain_enterprise/fonchain-main/pkg/e" "github.com/gin-gonic/gin" "github.com/gin-gonic/gin/binding" ) //商品列表 func ProductList(c *gin.Context) { var req orderproduct.ProductListreq if err := c.ShouldBind(&req); err != nil { logger.Errorf("ProductList ShouldBind err", err) ResponseQuickMsg(c, e.Failed, err.Error(), nil) return } resp, err := GrpcProductImpl.ProductList(context.Background(), &req) if err != nil { ResponseQuickMsg(c, e.Failed, err.Error(), nil) return } ResponseQuickMsg(c, e.Ok, resp.Msg, resp) return } //商品详情 func ProductInfo(c *gin.Context) { var req orderproduct.ProductInforeq if err := c.ShouldBind(&req); err != nil { logger.Errorf("ProductInfo ShouldBind err", err) ResponseQuickMsg(c, e.Failed, err.Error(), nil) return } resp, err := GrpcProductImpl.ProductInfo(context.Background(), &req) if err != nil { ResponseQuickMsg(c, e.Failed, err.Error(), nil) return } ResponseQuickMsg(c, e.Ok, resp.Msg, resp) return } //售卖列表 func SellList(c *gin.Context) { var req orderproduct.SellListreq if err := c.ShouldBind(&req); err != nil { logger.Errorf("SellList ShouldBind err", err) ResponseQuickMsg(c, e.Failed, err.Error(), nil) return } resp, err := GrpcProductImpl.SellList(context.Background(), &req) if err != nil { ResponseQuickMsg(c, e.Failed, err.Error(), nil) return } ResponseQuickMsg(c, e.Ok, resp.Msg, resp) return } //新建商品 func AddProduct(c *gin.Context) { var req orderproduct.AddProductreq if err := c.ShouldBind(&req); err != nil { logger.Errorf("AddProduct ShouldBind err", err) ResponseQuickMsg(c, e.Failed, err.Error(), nil) return } resp, err := GrpcProductImpl.AddProduct(context.Background(), &req) if err != nil { ResponseQuickMsg(c, e.Failed, err.Error(), nil) return } ResponseQuickMsg(c, e.Ok, resp.Msg, map[string]interface{}{ "Uuid": resp.Data.Uuid, }) return } //更新商品状态 func UpdateProductState(c *gin.Context) { var req orderproduct.UpdateStatereq if err := c.ShouldBind(&req); err != nil { logger.Errorf("UpdateState ShouldBind err", err) ResponseQuickMsg(c, e.Failed, err.Error(), nil) return } resp, err := GrpcProductImpl.UpdateProductState(context.Background(), &req) if err != nil { ResponseQuickMsg(c, e.Failed, err.Error(), nil) return } ResponseQuickMsg(c, e.Ok, resp.Msg, nil) return } //删除未上架的商品 func DelProduct(c *gin.Context) { var req orderproduct.DeleteProductreq if err := c.ShouldBind(&req); err != nil { logger.Errorf("DelProduct ShouldBind err", err) ResponseQuickMsg(c, e.Failed, err.Error(), nil) return } resp, err := GrpcProductImpl.DelProduct(context.Background(), &req) if err != nil { ResponseQuickMsg(c, e.Failed, err.Error(), nil) return } ResponseQuickMsg(c, e.Ok, resp.Msg, nil) return } //修改未上架的商品 func UpdateProduct(c *gin.Context) { var req orderproduct.UpdateProductreq if err := c.ShouldBind(&req); err != nil { logger.Errorf("Update ShouldBind err", err) ResponseQuickMsg(c, e.Failed, err.Error(), nil) return } resp, err := GrpcProductImpl.UpdateProduct(context.Background(), &req) if err != nil { ResponseQuickMsg(c, e.Failed, err.Error(), nil) return } ResponseQuickMsg(c, e.Ok, resp.Msg, nil) return } //没有商品版的售卖记录 func SaleLog(c *gin.Context) { var req orderproduct.SaleLogreq if err := c.ShouldBind(&req); err != nil { logger.Errorf("Select ShouldBind err", err) ResponseQuickMsg(c, e.Failed, err.Error(), nil) return } resp, err := GrpcProductImpl.SaleLog(context.Background(), &req) if err != nil { ResponseQuickMsg(c, e.Failed, err.Error(), nil) return } ResponseQuickMsg(c, e.Ok, resp.Msg, resp) return } //以下是微信jsapi退款 func WechatRefunds(ctx *gin.Context) { var req order.WechatJsApiRefundsRequest if err := ctx.ShouldBindBodyWith(&req, binding.JSON); err != nil { Error(ctx, e.InvalidParams, err) return } req.Reason = "退款" req.NotifyUrl = "https://appointtest.szjixun.cn/api/appointment/pay/SNsadfSkaAPyadfk" //调用其他微服务,还差两个字段,需要从订单表里面拿出来 req.OutRefundNo = req.OutTradeNo res, err := OrderProvider.WechatJsApiRefunds(ctx, &req) if err != nil { Error(ctx, e.Error, err) return } Success(ctx, res) return }