Ejemplo n.º 1
0
        /// <summary>
        /// 使用卡券
        /// </summary>
        /// <param name="code"></param>
        /// <param name="cardid"></param>
        /// <returns></returns>
        public void Consume(string cardid, string code)
        {
            Entities.WXCardCodeLogInfo wxcdata = DbFactory.Default.Get <Entities.WXCardCodeLogInfo>().Where(d => d.CardId == cardid && d.Code == code).FirstOrDefault();
            //WXCardCodeLogInfo wxcdata = Context.WXCardCodeLogInfo.FirstOrDefault(d => d.CardId == cardid && d.Code == code);
            if (wxcdata != null)
            {
                var carddata = DbFactory.Default.Get <Entities.WXCardLogInfo>().Where(d => d.Id == wxcdata.CardLogId).FirstOrDefault();
                if (carddata != null)
                {
#if DEBUG
                    Core.Log.Info("开始核销卡券:" + wxcdata.Code);
#endif
                    var acctoken = GetAccessToken(carddata.AppId, carddata.AppSecret);
                    if (!string.IsNullOrWhiteSpace(acctoken) && !string.IsNullOrWhiteSpace(wxcdata.Code))
                    {
                        var wxResultJson = CardApi.CardUnavailable(acctoken, wxcdata.Code, wxcdata.CardId);
                        if (wxResultJson.errcode != Senparc.Weixin.ReturnCode.请求成功)
                        {
                            Core.Log.Error("微信同步使用卡券失败", new Exception(((int)wxResultJson.errcode).ToString() + ":" + wxResultJson.errmsg));
                        }
                    }
                }
                wxcdata.CodeStatus = (int)Entities.WXCardCodeLogInfo.CodeStatusEnum.HasConsume;
                wxcdata.UsedTime   = DateTime.Now;
                DbFactory.Default.Update(wxcdata);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 是否可以同步微信
        /// </summary>
        /// <param name="couponid"></param>
        /// <param name="couponcodeid"></param>
        /// <param name="couponType"></param>
        /// <param name="url"></param>
        /// <returns></returns>
        public Entities.WXSyncJSInfoByCard GetSyncWeiXin(long couponid, long couponcodeid, Entities.WXCardLogInfo.CouponTypeEnum couponType, string url)
        {
            Entities.WXSyncJSInfoByCard result = null;
            bool isNeedSyncWX = false;

            Entities.WXCardLogInfo     wxcardinfo = null;
            Entities.WXCardCodeLogInfo wxcodeinfo = null;
            wxcardinfo = Get(couponid, couponType);
            if (wxcardinfo != null)
            {
                if (wxcardinfo.AuditStatus == (int)Entities.WXCardLogInfo.AuditStatusEnum.Audited)
                {
                    isNeedSyncWX = true;
                }
            }
            if (isNeedSyncWX)
            {
                wxcodeinfo = GetCodeInfo(couponcodeid, couponType);
                if (wxcodeinfo != null)
                {
                    if (wxcodeinfo.CodeStatus != (int)Entities.WXCardCodeLogInfo.CodeStatusEnum.WaitReceive)
                    {
                        isNeedSyncWX = false;
                    }
                }
            }
            if (isNeedSyncWX)
            {
                result = GetWXSyncJSInfo(wxcardinfo.CardId, url);
            }

            return(result);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 卡券Code失效
 /// </summary>
 /// <param name="id">投放记录编号</param>
 public void Unavailable(long id)
 {
     Entities.WXCardCodeLogInfo wxcdata = DbFactory.Default.Get <Entities.WXCardCodeLogInfo>(d => d.Id == id).FirstOrDefault();
     if (wxcdata != null)
     {
         Unavailable(wxcdata.CardId, wxcdata.Code);
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// 使用卡券
 /// <para>核销卡券</para>
 /// </summary>
 /// <param name="couponcodeid">红包记录号</param>
 /// <param name="coupontype">红包类型</param>
 public void Consume(long couponcodeid, Entities.WXCardLogInfo.CouponTypeEnum coupontype)
 {
     Entities.WXCardCodeLogInfo wxcdata = DbFactory.Default.Get <Entities.WXCardCodeLogInfo>().Where(d => d.CouponCodeId == couponcodeid && d.CouponType == coupontype).FirstOrDefault();
     if (wxcdata != null)
     {
         Consume(wxcdata.CardId, wxcdata.Code);
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// 使用卡券
 /// <para>核销卡券</para>
 /// </summary>
 /// <param name="id">投放记录编号</param>
 public void Consume(long id)
 {
     Entities.WXCardCodeLogInfo wxcdata = DbFactory.Default.Get <Entities.WXCardCodeLogInfo>().Where(d => d.Id == id).FirstOrDefault();
     if (wxcdata != null)
     {
         Consume(wxcdata.CardId, wxcdata.Code);
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// 卡券与红包领取信息同步前持久化
        /// </summary>
        /// <param name="cardid"></param>
        /// <param name="openid"></param>
        /// <param name="couponRecordId"></param>
        /// <param name="couponType"></param>
        private long SyncCouponRecordInfo(string cardid, long couponRecordId, Entities.WXCardLogInfo.CouponTypeEnum couponType)
        {
            long result = 0;

            DbFactory.Default.InTransaction(() =>
            {
                if (!string.IsNullOrWhiteSpace(cardid))
                {
                    var card = DbFactory.Default.Get <Entities.WXCardLogInfo>().Where(d => d.CardId == cardid).FirstOrDefault();
                    //var card = Context.WXCardLogInfo.FirstOrDefault(d => d.CardId == cardid);
                    if (card != null)
                    {
                        var wxcdata = DbFactory.Default.Get <Entities.WXCardCodeLogInfo>().Where(d => d.CouponCodeId == couponRecordId && d.CouponType == couponType).FirstOrDefault();
                        //var wxcdata = Context.WXCardCodeLogInfo.FirstOrDefault(d => d.CouponCodeId == couponRecordId && d.CouponType == couponType);
                        if (wxcdata == null)
                        {
                            //记录数据
                            wxcdata              = new Entities.WXCardCodeLogInfo();
                            wxcdata.CardId       = cardid;
                            wxcdata.CodeStatus   = (int)Entities.WXCardCodeLogInfo.CodeStatusEnum.WaitReceive;
                            wxcdata.CouponType   = couponType;
                            wxcdata.CouponCodeId = couponRecordId;
                            wxcdata.SendTime     = DateTime.Now;
                            wxcdata.CardLogId    = card.Id;
                            DbFactory.Default.Add(wxcdata);
                            //Context.WXCardCodeLogInfo.Add(wxcdata);
                            //Context.SaveChanges();
                            switch (wxcdata.CouponType)
                            {
                            case Entities.WXCardLogInfo.CouponTypeEnum.Coupon:
                                var coupondata = DbFactory.Default.Get <Entities.CouponRecordInfo>().Where(d => d.Id == couponRecordId).FirstOrDefault();
                                //var coupondata = Context.CouponRecordInfo.FirstOrDefault(d => d.Id == couponRecordId);
                                if (coupondata != null)
                                {
                                    coupondata.WXCodeId = wxcdata.Id;
                                    DbFactory.Default.Update(coupondata);
                                }
                                break;
                            }
                            //Context.SaveChanges();
                        }
                        result = wxcdata.Id;
                    }
                }
            });
            return(result);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 获取同步微信JS
        /// </summary>
        /// <param name="couponcodeid"></param>
        /// <param name="couponType"></param>
        /// <returns></returns>
        public Entities.WXJSCardModel GetJSWeiXinCard(long couponid, long couponcodeid, Entities.WXCardLogInfo.CouponTypeEnum couponType)
        {
            Entities.WXJSCardModel result = new Entities.WXJSCardModel();
            result.cardId = "0"; //默认不可同步
            bool isNeedSyncWX = false;

            Entities.WXCardLogInfo     wxcardinfo = null;
            Entities.WXCardCodeLogInfo wxcodeinfo = null;
            wxcardinfo = Get(couponid, couponType);
            if (wxcardinfo != null)
            {
                if (wxcardinfo.AuditStatus == (int)Entities.WXCardLogInfo.AuditStatusEnum.Audited)
                {
                    isNeedSyncWX = true;
                }
            }
            if (isNeedSyncWX)
            {
                wxcodeinfo = GetCodeInfo(couponcodeid, couponType);
                if (wxcodeinfo != null)
                {
                    if (wxcodeinfo.CodeStatus != (int)Entities.WXCardCodeLogInfo.CodeStatusEnum.WaitReceive)
                    {
                        isNeedSyncWX = false;
                    }
                }
            }
            if (isNeedSyncWX)
            {
                var data = MakeSyncWXJSInfo(wxcardinfo.CardId, couponcodeid, couponType);
                if (data != null)
                {
                    result.cardId            = data.card_id;
                    result.cardExt           = new Entities.WXJSCardExtModel();
                    result.cardExt.signature = data.signature;
                    result.cardExt.timestamp = data.timestamp;
                    result.cardExt.nonce_str = data.nonce_str;
                    result.cardExt.outer_id  = data.outerid;
                }
            }
            return(result);
        }