/// <summary>
        /// 发送奖励金
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public IActionResult OnPostSendReward(long invitelogId, string invitedOpenId, string ownOpenId)
        {
            ResultNormal result = new ResultNormal();

            try
            {
                AmountTransType amountTransType = AmountTransType.Invited_TrialReward;
                EUserAccount    ownAccount;
                bool            needWx = _SalesSrv.CreateRewardTrans(invitelogId, ownOpenId, amountTransType, out ownAccount);

                if (ownAccount != null)
                {
                    var ui = _UserSrv.GetUserInfo(invitedOpenId);
                    NLogHelper.InfoTxt($"wxMessage:OpenId-{ownOpenId}");
                    //微信提醒
                    UserAccountChangeTemplate wxMessage = new UserAccountChangeTemplate();
                    wxMessage.data = wxMessage.GenerateData(ownOpenId,
                                                            ui.Name,
                                                            amountTransType,
                                                            DateTime.Now,
                                                            ownAccount.InviteRewards,
                                                            GlobalSrv.GetRewardAmount(amountTransType)
                                                            );
                    WXApi.SendTemplateMessage <UserAccountChangeTemplate>(wxMessage);
                }
            }
            catch (Exception ex)
            {
                result.ErrorMsg = ex.Message;
            }

            return(new JsonResult(result));
        }
示例#2
0
        public static double GetRewardAmount(AmountTransType TransType)
        {
            switch (TransType)
            {
            case AmountTransType.Invited_Paied:
                return(PaiedReardAmt);

            case AmountTransType.Invited_TrialReward:
                return(TrialRewardAmt);

            default:
                return(0);
            }
        }
        public UserAccountChangeTemplate GenerateData(string toUserOpenId, string InvitedName,
                                                      AmountTransType amountTransType,
                                                      DateTime transDate,
                                                      double UserBalance,
                                                      double Amount)
        {
            string desc = "";

            if (amountTransType == AmountTransType.Invited_TrialReward)
            {
                desc = $"您邀请的用户[{InvitedName}],试听课成功参加.您获得奖励金额[{Amount}]";
            }
            else if (amountTransType == AmountTransType.Invited_Paied)
            {
                desc = $"您邀请的用户[{InvitedName}],已正式加入学院.您获得奖励金额[{Amount}]";
            }

            string first = desc;

            string remark = $"请点击此条消息查看您的账户变动!也可通过[菜单]->[我的账户]查看";
            var    data   = new
            {
                first = new TemplateField()
                {
                    value = first, color = "#EB6B13"
                },
                keyword1 = new TemplateField()
                {
                    value = transDate.ToString("yyyy-MM-dd")
                },
                keyword2 = new TemplateField()
                {
                    value = $"+【{Amount}】", color = "#FFC753"
                },
                keyword3 = new TemplateField()
                {
                    value = $"{UserBalance.ToString("0.00")} 元"
                },

                remark = new TemplateField {
                    value = remark, color = "#007ACC"
                },
            };
            string url = WebUrl + $"&openid={toUserOpenId}&toPage=/User/MyCourseTime";

            UserAccountChangeTemplate obj = base.InitObject(toUserOpenId, url, "tSw-YvTMPjTYieuDGdjBlH-ZOyZa9FxTW4SWt63Kup8");

            obj.data = data;
            return(obj);
        }
示例#4
0
        public static string GetAmountTransTypeName(AmountTransType amountTransType)
        {
            switch (amountTransType)
            {
            case AmountTransType.Invited_Paied:
                return("支付邀请奖励");

            case AmountTransType.Invited_TrialReward:
                return("试听邀请奖励");

            case AmountTransType.TransferToUser:
                return("提现");
            }
            return("");
        }
示例#5
0
        public bool CreateRewardTrans(long inviteLogId, string ownOpenId, AmountTransType TransType, out EUserAccount UserAccount, bool needSave = true)
        {
            int c = _dbContext.DBInviteRewardTrans.Where(a => a.InviteLogId == inviteLogId && a.TransType == TransType).Count();

            UserAccount = null;
            if (c == 0)
            {
                var reward = new EInviteRewardTrans()
                {
                    Amount        = GlobalSrv.GetRewardAmount(TransType),
                    Direction     = AmountTransDirection.In,
                    InviteLogId   = inviteLogId,
                    TransDateTime = DateTime.Now,
                    TransType     = TransType,
                    UserOpenId    = ownOpenId,
                    TransStatus   = AmountTransStatus.Created
                };
                _dbContext.DBInviteRewardTrans.Add(reward);
                UserAccount = _dbContext.DBUserAccount.Where(a => a.UserOpenId == ownOpenId).FirstOrDefault();
                if (UserAccount != null)
                {
                    UserAccount.InviteRewards += reward.Amount;
                    UserAccount.RemainRewards += reward.Amount;
                }

                var inviteLog = _dbContext.DBInviteLog.Where(a => a.Id == inviteLogId).FirstOrDefault();
                if (inviteLog != null)
                {
                    if (TransType == AmountTransType.Invited_TrialReward)
                    {
                        inviteLog.InviteStatus = InviteStatus.ApplyTrial;
                    }
                    else if (TransType == AmountTransType.Invited_Paied)
                    {
                        inviteLog.InviteStatus = InviteStatus.Paied;
                    }
                }

                if (needSave)
                {
                    _dbContext.SaveChanges();
                }
                return(true);
            }
            return(false);
        }