package shop import ( "context" "dubbo.apache.org/dubbo-go/v3/common/constant" "errors" "fmt" "github.com/fonchain_enterprise/fonchain-main/api/account" "github.com/fonchain_enterprise/fonchain-main/api/collections" "github.com/fonchain_enterprise/fonchain-main/api/order" frontSeries "github.com/fonchain_enterprise/fonchain-main/api/series" "github.com/fonchain_enterprise/fonchain-main/api/shopbrand" "github.com/fonchain_enterprise/fonchain-main/pkg/common/dingding" "github.com/fonchain_enterprise/fonchain-main/pkg/config" "github.com/fonchain_enterprise/fonchain-main/pkg/e" "github.com/fonchain_enterprise/fonchain-main/pkg/service" "github.com/gin-gonic/gin" "net/url" "strconv" ) type CollectionsSt struct { ArtworkName string ArtworkNum string ArtworkLevel string ArtworkImg string ArtworkType uint64 ArtworkSize float64 ArtworkHash string ArtistName string ArtistTel string Price string SeriesUid string BrandUID string BrandName string BrandAddress string BrandMem string BrandNumber string CoverImg string SeriesName string SaleType string } //ExamAutoWipedOutPosition 持岗证图片 func ExamAutoWipedOutPosition(c *gin.Context, phone string) (string, error) { err := registerShop(c, phone) if err != nil { dingding.Send("年会-持岗证 用户注册失败 请关注年会产品领取失败(持岗证),提示:"+err.Error()+"\n "+ "重新提交请点击手机号是"+phone+"\n"+ "点击重新发放"+config.ApiHost+"/shop/test/push/wiped?telNum="+phone+ "", err) } _, image, err := autoWipedOutPosition(c, phone) if err != nil { dingding.Send("年会-持岗证 请关注年会产品领取失败(持岗证),提示:"+err.Error()+"\n "+ "重新提交请点击手机号是"+phone+"\n"+ "点击重新发放"+config.ApiHost+"/shop/test/push/wiped?telNum="+phone+ "", err) } return image, err } //ExamAutoWipedOut 年货 二维码 func ExamAutoWipedOut(c *gin.Context, phone string) (string, error) { err := registerShop(c, phone) if err != nil { dingding.Send("年会-持岗证 用户注册失败 请关注年会产品领取失败(持岗证),提示:"+err.Error()+"\n "+ "重新提交请点击手机号是"+phone+"\n"+ "点击重新发放"+config.ApiHost+"/shop/test/push/wiped?telNum="+phone+ "", err) } id, err := autoWipedOut(c, phone) if err != nil { dingding.Send("年会-年货 请关注年会产品领取失败(核销产品),提示:"+err.Error()+"\n "+ "重新提交请点击手机号是"+phone+"\n"+ "点击重新发放"+config.ApiHost+"/shop/test/push/position?telNum="+phone+ "", err) } return fmt.Sprintf("%s%s", e.CreateQrUrl, url.QueryEscape(fmt.Sprintf("%s%d", config.YearGiftCheckHost, id))), err } func AutoWipedOutPosition(c *gin.Context, phone string) (string, error) { _ = registerShop(c, phone) _, image, err := autoWipedOutPosition(c, phone) if err != nil { dingding.Send("年会-持岗证 请关注年会产品领取失败(持岗证),提示:"+err.Error()+"\n "+ "重新提交请点击手机号是"+phone+"\n"+ "点击重新发放"+config.ApiHost+"/shop/test/push/wiped?telNum="+phone+ "", err) } return image, err } func AutoWipedOut(c *gin.Context, phone string) (string, error) { e1 := registerShop(c, phone) fmt.Println(e1) id, err := autoWipedOut(c, phone) if err != nil { dingding.Send("年会-年货 请关注年会产品领取失败(核销产品),提示:"+err.Error()+"\n "+ "重新提交请点击手机号是"+phone+"\n"+ "点击重新发放"+config.ApiHost+"/shop/test/push/position?telNum="+phone+ "", err) } return fmt.Sprintf("%s%s", e.CreateQrUrl, url.QueryEscape(fmt.Sprintf("%s%d", config.YearGiftCheckHost, id))), err } //PushAutoPosition 自动领取持岗证 func PushAutoPosition(c *gin.Context) { telNum := c.Query("telNum") fmt.Println("temNum", telNum) nn := c.Query("nn") if nn != "qaz123" { service.Error(c, e.Error, errors.New("没有密钥")) return } id, _, err := autoWipedOutPosition(c, telNum) if err != nil { service.Error(c, e.Error, err) return } service.Success(c, id) return } func TTest(c *gin.Context) { service.Success(c, nil) return } //PushAutoWipedOut 收年货 func PushAutoWipedOut(c *gin.Context) { telNum := c.Query("telNum") nn := c.Query("nn") if nn != "qaz123" { service.Error(c, e.Error, errors.New("没有密钥")) return } fmt.Println("temNum", telNum) id, err := autoWipedOut(c, telNum) if err != nil { service.Error(c, e.Error, err) return } service.Success(c, id) return } //MethodAutoPosition 自动领取持岗证 func MethodAutoPosition(c *gin.Context) { var req account.AccountInfo if err := c.ShouldBind(&req); err != nil { service.Error(c, e.Error, err) return } id, err := AutoWipedOutPosition(c, req.TelNum) if err != nil { service.Error(c, e.Error, err) return } service.Success(c, id) return } //MethodAutoWipedOut 收年货 func MethodAutoWipedOut(c *gin.Context) { var req account.AccountInfo if err := c.ShouldBind(&req); err != nil { service.Error(c, e.Error, err) return } id, err := AutoWipedOut(c, req.TelNum) if err != nil { service.Error(c, e.Error, err) return } service.Success(c, id) return } //AutoWipedOutPosition 自动领取持岗证 func autoWipedOutPosition(c *gin.Context, phone string) (uint64, string, error) { userRes, err := service.AccountProvider.UserByTel(c, &account.UserByTelRequest{Tel: phone, Domain: e.Domain_Mall}) if err != nil { return 0, "", err } config, err := service.GrpcCollectionImpl.GetCollectionConfig(c, &collections.CommonReq{}) if err != nil { return 0, "", err } res, st, err := BuyShopTemp(c, userRes.Info, config.PositionCollectionUID) //持岗证写死 if err != nil { return 0, "", err } return res.ID, st.ArtworkImg, nil } //AutoWipedOut 收年货 func autoWipedOut(c *gin.Context, phone string) (uint64, error) { userRes, err := service.AccountProvider.UserByTel(c, &account.UserByTelRequest{Domain: e.Domain_Mall, Tel: phone}) if err != nil { return 0, err } config, err := service.GrpcCollectionImpl.GetCollectionConfig(c, &collections.CommonReq{}) if err != nil { return 0, err } res, _, err := BuyShopTemp(c, userRes.Info, config.WipedOutCollectionUID) if err != nil { return 0, err } //推送任务 //cache.RedisClient.LPush(cache.GetListPushKey(), res.ID) //f, _ := strconv.ParseFloat(st.Price, 32) /* _, err = service.OrderProvider.SetPayCheck(c, &order.SetPayCheckRequest{ID: res.ID}) if err != nil { return 0, err } */ return res.ID, nil } // BuyShopTemp 压测temp func BuyShopTemp(c *gin.Context, userInfo *account.AccountInfo, collectionsUID string) (*order.CommonCreateResponse, *CollectionsSt, error) { fmt.Println("获取缓存之前") //如果没有缓存 st, err := getRedirectDrawFromDetail(c, userInfo.Domain, collectionsUID) //通过详情页领取,不扣库存 if err != nil { return nil, st, err } payCreateReq := order.PayCreateRequest{ Domain: e.Domain_Mall, BuyerName: userInfo.NickName, BuyerId: userInfo.ID, BuyerTel: userInfo.TelNum, BuyerIdNum: userInfo.IDNum, BuyerAddress: userInfo.Account, ArtworkName: st.ArtworkName, ArtworkUid: collectionsUID, ArtworkLevel: st.ArtworkLevel, ArtworkNum: st.ArtworkNum, ArtworkImg: st.ArtworkImg, CoverImg: st.CoverImg, ArtworkType: st.ArtworkType, ArtworkSize: fmt.Sprintf("%.2f", st.ArtworkSize), ArtworkHash: st.ArtworkHash, ArtistName: st.ArtistName, ArtistTel: st.ArtistTel, SeriesUid: st.SeriesUid, ArtworkId: collectionsUID, BrandUid: st.BrandUID, BrandName: st.BrandName, BrandAddress: st.BrandAddress, BrandMem: st.BrandMem, BrandNumber: st.BrandNumber, Price: st.Price, SellPrice: st.Price, SaleType: st.SaleType, IsCheck: 0, PayInfo: "", } payCreateReq.PayType = 9 payCreateReq.PayMethodType = "recshop" payCreateReq.PayTypeName = "领取" payCreateReq.UserAirdropUuid = collectionsUID //创建订 res, err := service.OrderProvider.PayCreate(c, &payCreateReq) if err != nil { return nil, st, err } return res, st, nil } // redirectDrawFromDetail 从详情里面直接领取 func getRedirectDrawFromDetail(c *gin.Context, domain, CollectionsUID string) (*CollectionsSt, error) { seriesName := "" req := collections.CollectionsInfoReq{ CollectionsUID: CollectionsUID, Language: c.GetString("lang"), } atta := make(map[string]interface{}) atta["lang"], _ = c.Get("lang") reqContext := context.WithValue(c, constant.DubboCtxKey("attachment"), atta) resp, err := service.GrpcCollectionImpl.CollectionsDetail(reqContext, &req) if err != nil { dingding.Send("购买查找藏品错误:,info:"+CollectionsUID, err) return nil, err } //获取brand的信息 if resp.Data != nil { data := resp.Data //1- 获取品牌方信息 brandReq := &shopbrand.BrandInforeq{ BrandUid: data.BrandUID, } brandInfo, err := service.GrpcShopBrandImpl.BrandInfo(c, brandReq) if err != nil { dingding.Send("购买查找品牌方区块地址和助记词错误:,BrandUID:"+data.BrandUID+",info:"+data.String(), err) return nil, err } if brandInfo == nil { dingding.Send("购买查找品牌方=nil:BrandUID:"+data.BrandUID+",info:"+data.String(), err) return nil, errors.New("not found") } if brandInfo.Address == "" || brandInfo.Mnemonic == "" { dingding.Send("购买查找品牌方区块地址和助记词为空:BrandUID:"+data.BrandUID+",info:"+data.String(), err) return nil, errors.New("brandInfo wrong,mnmonic wrong") } seriesInfo, err := GetSeriesDetail(c, resp.Data.SeriesUID) //系列 fmt.Println("获取藏品"+ "-----", seriesInfo, err) if seriesInfo != nil { langCode := c.GetString("lang") if langCode == "" { langCode = "zh-CN" } if len(seriesInfo.SeriesLang) > 0 { for _, tt := range seriesInfo.SeriesLang { if tt.Language == langCode { seriesName = tt.SeriesName } } } } size, _ := strconv.ParseFloat(data.Size, 64) typeInt, _ := strconv.ParseInt(data.CollectionType, 10, 64) //获取艺术品的hash nftQuery := &collections.CommonReq{ CollectionsUID: CollectionsUID, } fmt.Println("5-获取hash", nftQuery) //1-获取百度链hash r, err := service.GrpcCollectionImpl.QueryCollectionsChain(c, nftQuery) fmt.Println("6-获取hash", r.Data, err) if err != nil { dingding.Send("创建订单获取NFT hash错误:,info:"+data.String(), err) return nil, err } if r == nil || r.Data == nil || r.Data.TransactionHash == "" { //获取商品hash dingding.Send("创建订单获取NFT hash=nil:,info:"+data.String(), err) return nil, errors.New("hash not found") } artworkHash := r.Data.TransactionHash st := &CollectionsSt{ ArtworkName: data.Name, ArtworkImg: data.CollectionImg, ArtworkType: uint64(typeInt), ArtworkSize: size, ArtworkHash: artworkHash, Price: fmt.Sprintf("%.2f", data.Price), SeriesUid: data.SeriesUID, BrandUID: data.BrandUID, BrandName: brandInfo.BrandName, BrandAddress: brandInfo.Address, BrandMem: brandInfo.Mnemonic, BrandNumber: brandInfo.BrandNumber, ArtworkLevel: data.Level, CoverImg: data.CoverImg, SeriesName: seriesName, SaleType: data.SaleType, } fmt.Println("生成订单转化价格:", data.Price, "---", fmt.Sprintf("%.2f", data.Price)) return st, nil } return nil, errors.New("no found") } func GetSeriesDetail(c context.Context, seriesUid string) (*frontSeries.SeriesDetailResp, error) { req := frontSeries.SeriesDetailReq{ SeriesUuid: seriesUid, } resp, err := service.GrpcBackendSeriesImpl.SeriesDetail(c, &req) if err != nil { return nil, err } return resp, nil } func registerShop(c *gin.Context, telNum string) error { userByTelReq := account.UserByTelRequest{ Tel: telNum, Domain: e.Domain_Mall, } //查询是否有该账号 userByTelRes, err := service.AccountProvider.UserByTel(c, &userByTelReq) if err != nil { return err } if userByTelRes.IsExist == true { return nil } tempNick := "staff" if len(telNum) > 4 { tempNick = telNum[(len(telNum) - 4):] } //账号服务 registerRequest := account.RegistRequest{ NickName: tempNick, TelNum: telNum, Password: tempNick + "fontree", Extend: &account.Extend{}, Domain: e.Domain_Mall, } _, err = service.AccountProvider.Register(c, ®isterRequest) if err != nil { return err } return nil }