/// <summary>
        /// 根据代理人Id来创建短信账号
        /// </summary>
        /// <param name="curAgent"></param>
        /// <param name="method">来源方式 1微信申请;2PC申请</param>
        /// <param name="topAgent"></param>
        /// <returns>创建的账号Id</returns>
        public int CreateAccount(int curAgent, int method, int topAgent)
        {
            //bool isCreat = false;//true为创建账号
            //bool isByTopAgent = IsPayByTopAgent(curAgent);//true为走顶级代理人账户
            int creatAgent = 0;

            creatAgent = curAgent;
            //if (method == 1)
            //{
            //    //微信端
            //    //如果走顶级代理人账户:走顶级,不允许创建账号;不走顶级,当前!=顶级 时才可创建账号
            //    if (!isByTopAgent)
            //    {
            //        //顶级代理人无法创建短信账户
            //        if (curAgent != topAgent)
            //        {
            //            isCreat = true;
            //        }
            //        creatAgent = curAgent;
            //    }
            //}
            //else if (method == 2)
            //{
            //    //Pc端可以无限制创建短信账户
            //    isCreat = true;
            //    if (!isByTopAgent)
            //    {
            //        //如果不走顶级代理账户:创建账户用当前Agent
            //        creatAgent = curAgent;
            //    }
            //    else
            //    {
            //        creatAgent = topAgent;
            //    }
            //}
            //if (isCreat&&(creatAgent != 0))
            //{
            bx_sms_account getSmsAccount = _smsContentRepository.Find(creatAgent);

            if (getSmsAccount != null)
            {
                //如果存在账号,则返回负的当前账号id
                return(getSmsAccount.id * (-1));
            }
            //否则,新创建账号,返回当前Id
            bx_sms_account bxSmsAccount = new bx_sms_account();

            bxSmsAccount.agent_id     = creatAgent;
            bxSmsAccount.avail_times  = 0;
            bxSmsAccount.total_times  = 0;
            bxSmsAccount.create_time  = DateTime.Now;
            bxSmsAccount.sms_account  = string.Format(_smsAccountConfig, creatAgent);
            bxSmsAccount.sms_password = string.Format(_smsAccountConfig, creatAgent).GetMd5();
            bxSmsAccount.status       = 1;//1可以使用
            int smsAcount = _smsContentRepository.Add(bxSmsAccount);

            return(smsAcount);
            //}
            //return 0;//无权限创建账号
        }
        /// <summary>
        /// 更新短信条数
        /// </summary>
        /// <param name="orderId"></param>
        /// <param name="agentId"></param>
        public int SmsRecharge(int orderId, int agentId, int quantity)
        {
            int            result = 0;
            bx_sms_account item   = _smsContentRepository.Find(agentId);

            item.total_times = item.total_times + quantity;
            item.avail_times = item.avail_times + quantity;
            result           = _smsContentRepository.Update(item);
            return(result);
        }
Exemplo n.º 3
0
        public bx_sms_account Find(int agent)
        {
            bx_sms_account smsAccount = new bx_sms_account();

            try
            {
                smsAccount = DataContextFactory.GetDataContext().bx_sms_account.FirstOrDefault(x => x.agent_id == agent);
            }
            catch (Exception ex)
            {
                logError.Info("发生异常:" + ex.Source + "\n" + ex.StackTrace + "\n" + ex.Message + "\n" + ex.InnerException);
            }
            return(smsAccount);
        }
Exemplo n.º 4
0
        public int Update(bx_sms_account bxSmsAccount)
        {
            int count = 0;

            try
            {
                DataContextFactory.GetDataContext().bx_sms_account.AddOrUpdate(bxSmsAccount);
                count = DataContextFactory.GetDataContext().SaveChanges();
            }
            catch (Exception ex)
            {
                logError.Info("发生异常:" + ex.Source + "\n" + ex.StackTrace + "\n" + ex.Message + "\n" + ex.InnerException);
            }
            return(count);
        }
Exemplo n.º 5
0
        public int Add(bx_sms_account bxSmsAccount)
        {
            int smsAccountId = 0;

            try
            {
                var t = DataContextFactory.GetDataContext().bx_sms_account.Add(bxSmsAccount);
                DataContextFactory.GetDataContext().SaveChanges();
                smsAccountId = t.id;
            }
            catch (Exception ex)
            {
                logError.Info("发生异常:" + ex.Source + "\n" + ex.StackTrace + "\n" + ex.Message + "\n" + ex.InnerException);
                smsAccountId = 0;
            }
            return(smsAccountId);
        }
        public static SmsAccount ConverToViewModel(this bx_sms_account smsAccount)
        {
            SmsAccount vm = new SmsAccount();

            if (smsAccount != null)
            {
                vm = new SmsAccount
                {
                    id           = smsAccount.id,
                    agent_id     = smsAccount.agent_id,
                    sms_account  = smsAccount.sms_account,
                    sms_password = smsAccount.sms_password,
                    total_times  = smsAccount.total_times,
                    avail_times  = smsAccount.avail_times,
                    status       = smsAccount.status,
                    create_time  = smsAccount.create_time
                }
            }
            ;
            return(vm);
        }
    }