Example #1
0
        protected override DownloadQRCodeRD ProcessRequest(DTO.Base.APIRequest <DownloadQRCodeRP> pRequest)
        {
            string content    = string.Empty;
            string customerId = string.Empty;
            var    RD         = new DownloadQRCodeRD();

            try
            {
                #region 解析传入参数
                //解析请求字符串
                var RP = pRequest.Parameters;

                //判断客户ID是否传递

                customerId = CurrentUserInfo.CurrentUser.customer_id;


                #endregion
                var    imageUrl = string.Empty;
                Random ro       = new Random();
                var    iUp      = 100000000;
                var    iDown    = 50000000;

                if (string.IsNullOrEmpty(RP.VipDCode.ToString()) || RP.VipDCode == 0)
                {
                    throw new APIException("VipDCode参数不能为空");
                }
                var rpVipDCode = 0;                   //临时二维码
                var iResult    = ro.Next(iDown, iUp); //随机数

                if (RP.VipDCode == 9)                 //永久二维码
                {
                    var userQRCodeBll  = new WQRCodeManagerBLL(CurrentUserInfo);
                    var marketEventBll = new MarketEventBLL(CurrentUserInfo);

                    var marketEventEntity = marketEventBll.QueryByEntity(new MarketEventEntity()
                    {
                        EventCode = "CA00002433", CustomerId = CurrentUserInfo.ClientID
                    }, null).FirstOrDefault();
                    var userQRCode = userQRCodeBll.QueryByEntity(new WQRCodeManagerEntity()
                    {
                        ObjectId = marketEventEntity.MarketEventID, CustomerId = CurrentUserInfo.ClientID
                    }, null);                                                                                                                                                              //

                    if (userQRCode != null && userQRCode.Length > 0)
                    {
                        RD.imageUrl = userQRCode[0].ImageUrl;
                        return(RD);
                    }

                    //获取当前二维码 最大值
                    iResult    = new WQRCodeManagerBLL(CurrentUserInfo).GetMaxWQRCod() + 1;
                    rpVipDCode = 1;                 //永久

                    #region 获取微信帐号
                    //门店关联的公众号
                    var tueBll    = new TUnitExpandBLL(CurrentUserInfo);
                    var tueEntity = new TUnitExpandEntity();
                    if (!string.IsNullOrEmpty(CurrentUserInfo.CurrentUserRole.UnitId))
                    {
                        tueEntity = tueBll.QueryByEntity(new TUnitExpandEntity()
                        {
                            UnitId = CurrentUserInfo.CurrentUserRole.UnitId
                        }, null).FirstOrDefault();
                    }

                    var server = new WApplicationInterfaceBLL(CurrentUserInfo);
                    var wxObj  = new WApplicationInterfaceEntity();
                    if (tueEntity != null && !string.IsNullOrEmpty(tueEntity.Field1))
                    {
                        wxObj = server.QueryByEntity(new WApplicationInterfaceEntity {
                            AppID = tueEntity.Field1, CustomerId = customerId
                        }, null).FirstOrDefault();
                    }
                    else
                    {
                        wxObj = server.QueryByEntity(new WApplicationInterfaceEntity {
                            CustomerId = customerId
                        }, null).FirstOrDefault();
                    }

                    if (wxObj == null)
                    {
                        throw new APIException("没有对应公众号");
                    }
                    else
                    {
                        var commonServer = new CommonBLL();

                        imageUrl = commonServer.GetQrcodeUrl(wxObj.AppID
                                                             , wxObj.AppSecret
                                                             , rpVipDCode.ToString("")    //二维码类型  0: 临时二维码  1:永久二维码
                                                             , iResult, CurrentUserInfo); //iResult作为场景值ID,临时二维码时为32位整型,永久二维码时只支持1--100000
                        if (imageUrl != null && !imageUrl.Equals(""))
                        {
                            CPOS.Common.DownloadImage downloadServer = new DownloadImage();
                            string downloadImageUrl = ConfigurationManager.AppSettings["website_WWW"];
                            imageUrl = downloadServer.DownloadFile(imageUrl, downloadImageUrl);
                            //如果名称不为空,就把图片放在一定的背景下面
                            //if (!string.IsNullOrEmpty(RP.Parameters.RetailTraderName))
                            //{
                            //    string apiDomain = ConfigurationManager.AppSettings["website_url"];

                            //    imageUrl = CombinImage(apiDomain + @"/HeadImage/qrcodeBack.jpg", imageUrl, RP.Parameters.RetailTraderName + "合作二维码");
                            //}
                        }
                    }

                    #endregion

                    if (!string.IsNullOrEmpty(imageUrl))    //永久二维码
                    {
                        #region 创建店员永久二维码匹配表
                        var userQrTypeBll = new WQRCodeTypeBLL(CurrentUserInfo);
                        var userQrType    = userQrTypeBll.QueryByEntity(new WQRCodeTypeEntity()
                        {
                            TypeName = "签到"
                        }, null);                                                                                       //"UserQrCode"
                        if (userQrType != null && userQrType.Length > 0)
                        {
                            var userQrCodeBll = new WQRCodeManagerBLL(CurrentUserInfo);
                            var userQrCode    = new WQRCodeManagerEntity();
                            userQrCode.QRCode        = iResult.ToString();//记录传过去的二维码场景值
                            userQrCode.QRCodeTypeId  = userQrType[0].QRCodeTypeId;
                            userQrCode.IsUse         = 1;
                            userQrCode.CustomerId    = CurrentUserInfo.CurrentUser.customer_id;
                            userQrCode.ImageUrl      = imageUrl;
                            userQrCode.ApplicationId = wxObj.ApplicationId;
                            //objectId 为店员ID
                            userQrCode.ObjectId = marketEventEntity.MarketEventID;
                            userQrCodeBll.Create(userQrCode);
                        }
                        #endregion
                    }
                }

                RD.imageUrl = imageUrl;
            }
            catch
            {
                throw new APIException("生成二维码错误");
            }
            return(RD);
        }
Example #2
0
        protected override GetVipDealerSpreadCodeRD ProcessRequest(DTO.Base.APIRequest <GetVipDealerSpreadCodeRP> pRequest)
        {
            var rd                = new GetVipDealerSpreadCodeRD();
            var VipBLL            = new VipBLL(CurrentUserInfo);
            var WQRCodeManagerBLL = new WQRCodeManagerBLL(this.CurrentUserInfo);
            var WQRCodeTypeBLL    = new WQRCodeTypeBLL(this.CurrentUserInfo);

            try
            {
                var UserID = pRequest.UserID;
                //
                string imageUrl   = string.Empty;
                string QRCodeId   = string.Empty;
                string VipName    = string.Empty;
                string HeadImgUrl = string.Empty;
                //分享处理
                if (!string.IsNullOrWhiteSpace(pRequest.Parameters.ShareUserId))
                {
                    UserID = pRequest.Parameters.ShareUserId;
                }
                //微信 公共平台
                var wapentity = new WApplicationInterfaceBLL(this.CurrentUserInfo).QueryByEntity(new WApplicationInterfaceEntity
                {
                    CustomerId = this.CurrentUserInfo.ClientID,
                    IsDelete   = 0
                }, null).FirstOrDefault();

                var VipDealerType = WQRCodeTypeBLL.QueryByEntity(new WQRCodeTypeEntity()
                {
                    TypeCode = "VipDealerCode"
                }, null).FirstOrDefault();
                if (VipDealerType == null)
                {
                    throw new APIException("静态二位经销商类型无此类型!");
                }

                if (!string.IsNullOrWhiteSpace(pRequest.Parameters.QRCodeId))
                {
                    #region 分享出去的二维码
                    var WQRCodeManagerData = WQRCodeManagerBLL.GetByID(pRequest.Parameters.QRCodeId);
                    if (WQRCodeManagerData == null)
                    {
                        throw new APIException("此二维码不存在!");
                    }

                    var VipData = VipBLL.GetByID(WQRCodeManagerData.ObjectId);
                    if (VipData == null)
                    {
                        throw new APIException("此二维码会员不存在!");
                    }

                    //二维码图片地址,ID赋值,会员名称,头像地址赋值
                    imageUrl   = WQRCodeManagerData.ImageUrl;
                    QRCodeId   = WQRCodeManagerData.QRCodeId.ToString();
                    VipName    = VipData.VipName;
                    HeadImgUrl = VipData.HeadImgUrl;
                    #endregion
                }
                else
                {
                    #region 获取去自己静态推广二维码
                    var WQRCodeManagerData = WQRCodeManagerBLL.QueryByEntity(new WQRCodeManagerEntity()
                    {
                        ObjectId = UserID, QRCodeTypeId = VipDealerType.QRCodeTypeId
                    }, null).FirstOrDefault();
                    if (WQRCodeManagerData != null)
                    {
                        //二维码图片地址,ID赋值
                        imageUrl = WQRCodeManagerData.ImageUrl;
                        QRCodeId = WQRCodeManagerData.QRCodeId.ToString();
                    }
                    else
                    {
                        //获取当前二维码 最大值
                        var MaxWQRCod = new WQRCodeManagerBLL(this.CurrentUserInfo).GetMaxWQRCod() + 1;
                        if (wapentity == null)
                        {
                            throw new APIException("无设置微信公众平台!");
                        }

                        #region 生成二维码
                        JIT.CPOS.BS.BLL.WX.CommonBLL commonServer = new JIT.CPOS.BS.BLL.WX.CommonBLL();
                        imageUrl = commonServer.GetQrcodeUrl(wapentity.AppID.ToString().Trim()
                                                             , wapentity.AppSecret.Trim()
                                                             , "1", MaxWQRCod
                                                             , this.CurrentUserInfo);

                        if (string.IsNullOrEmpty(imageUrl))
                        {
                            throw new APIException("二维码生成失败!");
                        }
                        else
                        {
                            string host = ConfigurationManager.AppSettings["original_url"];
                            CPOS.Common.DownloadImage downloadServer = new DownloadImage();
                            //二维码赋值
                            imageUrl = downloadServer.DownloadFile(imageUrl, host);
                            if (!string.IsNullOrEmpty(UserID))
                            {
                                var WQRQrCode = new WQRCodeManagerEntity();
                                WQRQrCode.QRCodeId      = Guid.NewGuid();
                                WQRQrCode.QRCode        = MaxWQRCod.ToString();
                                WQRQrCode.QRCodeTypeId  = VipDealerType.QRCodeTypeId;
                                WQRQrCode.IsUse         = 1;
                                WQRQrCode.CustomerId    = this.CurrentUserInfo.ClientID;
                                WQRQrCode.ImageUrl      = imageUrl;
                                WQRQrCode.ApplicationId = wapentity.ApplicationId;//微信公众号的编号
                                //objectId 为会员ID
                                WQRQrCode.ObjectId = UserID;
                                WQRCodeManagerBLL.Create(WQRQrCode);

                                //二维码ID赋值
                                QRCodeId = WQRQrCode.QRCodeId.ToString();
                            }
                        }
                        #endregion
                    }
                    //会员名称,头像地址
                    var VipData = VipBLL.GetByID(UserID);
                    if (VipData == null)
                    {
                        throw new APIException("会员不存在!");
                    }

                    VipName    = VipData.VipName;
                    HeadImgUrl = VipData.HeadImgUrl;
                    #endregion
                }
                //响应参数赋值
                rd.imageUrl   = imageUrl;
                rd.VipName    = VipName;
                rd.HeadImgUrl = HeadImgUrl;
                rd.QRCodeId   = QRCodeId;
            }
            catch (Exception ex)
            {
                throw new APIException(ex.Message);
            }

            return(rd);
        }