Exemple #1
0
        /// <summary>
        /// 没有领取红包
        /// </summary>
        /// <param name="accountID"></param>
        /// <param name="pm"></param>
        /// <returns></returns>
        private bool NoOpenPackets(ObjectId accountID, VoicePacketsModel pm)
        {
            bool flag = true;

            if (pm.Participants == null)
            {
                return(flag);
            }
            if (pm.Participants.Count >= pm.PeopleNum)
            {
                flag = false;
                throw (new ExceptionModel()
                {
                    ExceptionParam = ActionParams.packets_opened
                });
            }
            if (pm.Participants.Exists(x => x.AccountID.Equals(accountID)))
            {
                flag = false;
                throw (new ExceptionModel()
                {
                    ExceptionParam = ActionParams.packets_people_opened
                });
            }
            return(flag);
        }
Exemple #2
0
        /// <summary>
        /// 创建微信支付参数
        /// </summary>
        /// <param name="money"></param>
        /// <param name="vpm"></param>
        /// <param name="uniacid"></param>
        /// <param name="account"></param>
        /// <param name="weChatOrder"></param>
        /// <returns></returns>
        private WXPayModel GetCreatePacketsPayParams(decimal money, VoicePacketsModel vpm, string uniacid, AccountModel account, out WeChatOrder weChatOrder)
        {
            weChatOrder = new WeChatOrder()
            {
                CreateTime    = DateTime.Now,
                Total         = money,
                VoicePackets  = vpm,
                WeChatOrderID = ObjectId.GenerateNewId()
            };
            if (account.WeChatOrders == null)
            {
                collection.UpdateOne(x => x.AccountID.Equals(account.AccountID),
                                     Builders <AccountModel> .Update.Set(x => x.WeChatOrders, new List <WeChatOrder>()));
            }
            collection.UpdateOne(x => x.AccountID.Equals(account.AccountID),
                                 Builders <AccountModel> .Update.Push(x => x.WeChatOrders, weChatOrder));
            ///微擎相关
            JsApiPay jsApiPay = new JsApiPay();

            jsApiPay.openid    = account.OpenID;
            jsApiPay.total_fee = money.ConvertToMoneyCent();
            var body      = "test";
            var attach    = account.AccountID + "," + weChatOrder.WeChatOrderID.ToString();
            var goods_tag = "创建红包";

            jsApiPay.CreateWeChatOrder(uniacid, body, attach, goods_tag);
            var param = jsApiPay.GetJsApiParameters(We7Tools.Models.We7ProcessMiniConfig.GetAllConfig(uniacid).KEY);
            var wxpm  = JsonConvert.DeserializeObject <WXPayModel>(param);

            return(wxpm);
        }
Exemple #3
0
        /// <summary>
        /// 将红包放入余额
        /// </summary>
        /// <param name="uniacid"></param>
        /// <param name="account"></param>
        /// <param name="money"></param>
        private void PushMoneyToBalance(string uniacid, AccountModel account, VoicePacketsModel vpm, decimal money)
        {
            var createPeople = GetModelByID(vpm.CreatePeople.AccountID);
            var filter       = Builders <AccountModel> .Filter;
            var filterSum    = filter.Eq(x => x.uniacid, uniacid) & filter.Eq(x => x.AccountID, account.AccountID);

            if (account.ReceivePackets == null)
            {
                collection.UpdateOne(filterSum, Builders <AccountModel> .Update.Set(x => x.ReceivePackets, new List <VoicePacketsModel>()));
            }
            if (account.Statements == null)
            {
                collection.UpdateOne(x => x.AccountID.Equals(account.AccountID), Builders <AccountModel> .Update.Set(x => x.Statements, new List <Statement>()));
            }
            var packetsStatement = new Statement()
            {
                StatementName = $@"领取{createPeople.AccountName}的红包",
                RMB           = +money,
                CreateTime    = DateTime.Now
            };
            var update = Builders <AccountModel> .Update
                         .Set(x => x.Balances, account.Balances + money)
                         .Set(x => x.ReceivePacketsMoneyCount, account.ReceivePacketsMoneyCount + money)
                         .Set(x => x.CountReceivePacket, account.CountReceivePacket + 1)
                         .Push(x => x.ReceivePackets, vpm)
                         .Push(x => x.Statements, packetsStatement);

            collection.UpdateOne(filterSum, update);
        }
Exemple #4
0
 /// <summary>
 /// 检测人数
 /// </summary>
 /// <param name="packetsModel"></param>
 /// <returns></returns>
 private bool CheckPeopleNum(VoicePacketsModel packetsModel)
 {
     if (packetsModel.PeopleNum == 0)
     {
         var e = new ExceptionModel()
         {
             MethodFullName = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName,
             ExceptionDate  = DateTime.Now,
             ExceptionParam = ActionParams.packets_people_none
         };
         e.Save();
         throw e;
     }
     if (packetsModel.Amount.ConvertToMoneyCent() / packetsModel.PeopleNum < 1)
     {
         var e = new ExceptionModel()
         {
             MethodFullName = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName,
             ExceptionDate  = DateTime.Now,
             ExceptionParam = ActionParams.packets_people_too_many
         };
         e.Save();
         throw e;
     }
     return(true);
 }
 /// <summary>
 /// 获取红包信息
 /// </summary>
 /// <param name="uniacid">商户识别ID</param>
 /// <param name="packetsID">订单ID或者红包ID</param>
 /// <returns></returns>
 public string GetPacketsInfo(string uniacid, string packetsID, string accountID)
 {
     try
     {
         VoicePacketsModel vpm = thisData.GetPacketsInfo(uniacid, new ObjectId(packetsID), new ObjectId(accountID));
         return(new BaseResponseModel <VoicePacketsModel>()
         {
             StatusCode = ActionParams.code_ok, JsonData = vpm
         }.ToJson());
     }
     catch (Exception e)
     {
         e.Save();
         return(JsonResponseModel.ErrorJson);
     }
 }
Exemple #6
0
        /// <summary>
        /// 执行创建语音口令红包
        /// </summary>
        /// <param name="account"></param>
        /// <param name="packetsModel"></param>
        /// <param name="serviceMoney"></param>
        /// <param name="balance"></param>
        internal void CreateVoicePackets(AccountModel account, VoicePacketsModel packetsModel, decimal serviceMoney, decimal balance)
        {
            if (account.Statements == null)
            {
                collection.UpdateOne(x => x.AccountID.Equals(account.AccountID), Builders <AccountModel> .Update.Set(x => x.Statements, new List <Statement>()));
            }

            var sp = new Statement[] {
                new Statement()
                {
                    StatementName = "创建红包-手续费",
                    RMB           = -serviceMoney,
                    CreateTime    = DateTime.Now
                },
                new Statement()
                {
                    StatementName = "创建红包",
                    RMB           = -packetsModel.Amount,
                    CreateTime    = DateTime.Now
                }
            };

            if (account.SendPackets == null)
            {
                collection.UpdateOne(x => x.AccountID.Equals(account.AccountID), Builders <AccountModel> .Update
                                     .Set(x => x.SendPackets, new List <VoicePacketsModel>()));
            }

            collection.UpdateOne(x => x.AccountID.Equals(account.AccountID),
                                 Builders <AccountModel> .Update
                                 .Set(x => x.CountSendPacket, account.CountSendPacket + 1)
                                 .Set(x => x.SendPacketsMoneyCount, account.SendPacketsMoneyCount + packetsModel.Amount)
                                 .Set(x => x.Balances, balance)
                                 .Push(x => x.SendPackets, packetsModel)
                                 .PushEach(x => x.Statements, sp));
            mongo.GetMongoCollection <VoicePacketsModel>().InsertOne(packetsModel);
        }
Exemple #7
0
        /// <summary>
        /// 计算红包金额
        /// </summary>
        /// <param name="pm"></param>
        /// <returns></returns>
        private decimal CalcMoney(VoicePacketsModel pm)
        {
            decimal sumPeopleMoney = 0;

            if (pm.Participants != null)
            {
                pm.Participants.ForEach(x => sumPeopleMoney += x.MoneyGet);
            }

            decimal amount = pm.Amount - sumPeopleMoney;

            if (pm.Participants != null && pm.Participants.Count + 1 == pm.PeopleNum)
            {
                return(amount);
            }
            if (pm.PeopleNum == 1)
            {
                return(pm.Amount);
            }
            int cent       = amount.ConvertToMoneyCent();
            int randomCent = new Random().Next(1, cent - (pm.PeopleNum - (pm.Participants == null ? 0 : pm.Participants.Count)));

            return((decimal)randomCent / (decimal)100);
        }
Exemple #8
0
        /// <summary>
        /// 创建语音口令红包
        /// </summary>
        /// <param name="uniacid"></param>
        /// <param name="accountID"></param>
        /// <param name="packetsModel"></param>
        /// <returns></returns>
        internal async Task <string> CreateVoicePackets(string uniacid, ObjectId accountID, VoicePacketsModel packetsModel)
        {
            CheckPeopleNum(packetsModel);
            CheckText(packetsModel.TextCmd);

            packetsModel.uniacid    = uniacid;
            packetsModel.CreateTime = DateTime.Now;
            return(await Task.Run(() =>
            {
                var account = GetModelByIDAndUniacID(accountID, uniacid);
                if (account == null)
                {
                    var e = new ExceptionModel()
                    {
                        MethodFullName = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName,
                        Content = $"用户为空:accountID={accountID.ToString()},uniacid={uniacid}",
                        ExceptionDate = DateTime.Now
                    };
                    e.Save();
                    throw e;
                }

                var serviceMoney = GetServiceMoney(uniacid, packetsModel.Amount);
                var balance = account.Balances - (packetsModel.Amount + serviceMoney);

                packetsModel.PacketsID = ObjectId.GenerateNewId();
                packetsModel.CreatePeople = new Participant
                {
                    AccountID = account.AccountID,
                    AccountAvatar = account.AccountAvatar,
                    AccountName = account.AccountName,
                    CreateTime = DateTime.Now
                };
                if (balance < 0)
                {
                    WeChatOrder weChatOrder;
                    WXPayModel wXPayModel = GetCreatePacketsPayParams(-balance, packetsModel, uniacid, account, out weChatOrder);
                    return new BaseResponseModel3 <bool, string, WXPayModel>()
                    {
                        StatusCode = ActionParams.code_ok, JsonData = false, JsonData1 = packetsModel.PacketsID.ToString(), JsonData2 = wXPayModel
                    }.ToJson();
                }
                CreateVoicePackets(account, packetsModel, serviceMoney, balance);
                return new BaseResponseModel2 <bool, string>()
                {
                    StatusCode = ActionParams.code_ok, JsonData = true, JsonData1 = packetsModel.PacketsID.ToString()
                }.ToJson();
            }));
        }