/// <summary> /// 注册赠送模板 /// </summary> /// <param name="accountModel"></param> public void AddFreeTemplate(Account accountModel) { string typeids = $"{(int)TmpType.小程序单页模板},{(int)TmpType.小程序企业模板},{(int)TmpType.小程序专业模板}"; List <XcxTemplate> templist = XcxTemplateBLL.SingleModel.GetListByTypes(typeids); if (templist == null || templist.Count <= 0 || accountModel == null) { return; } XcxAppAccountRelation usertemplate = GetModelByaccound(accountModel.Id.ToString()); if (usertemplate != null) { return; } TransactionModel tran = new TransactionModel(); DateTime nowtime = DateTime.Now; int version = 0; int month = 100 * 12; foreach (XcxTemplate item in templist) { version = 0; if (item.Type == (int)TmpType.小程序专业模板) { version = 3; month = 3; } else { month = 100 * 12; } tran.Add($@"insert into XcxAppAccountRelation(TId,AccountId,AddTime,Url,price,outtime,agentid,VersionId) values({item.Id}, '{accountModel.Id}', '{nowtime}', '{item.Link}', {item.Price}, '{nowtime.AddMonths(month)}',0,{version})"); AgentdepositLog pricemodellog = new AgentdepositLog(); pricemodellog.addtime = DateTime.Now; pricemodellog.afterDeposit = 0; pricemodellog.agentid = 0; pricemodellog.beforeDeposit = 0; pricemodellog.cost = 0; pricemodellog.costdetail = $"客户免费使用小程序模板:{(version == 3 ? "专业基础版" : item.TName)}"; pricemodellog.type = 0; pricemodellog.tid = item.Id; tran.Add(AgentdepositLogBLL.SingleModel.BuildAddSql(pricemodellog)); } if (!ExecuteTransactionDataCorect(tran.sqlArray, tran.ParameterArray)) { log4net.LogHelper.WriteInfo(this.GetType(), "赠送免费版:失败," + Newtonsoft.Json.JsonConvert.SerializeObject(tran)); } }
/// <summary> /// 赠送代理平台模板 /// </summary> /// <param name="accountModel"></param> public void AddTemplate(Account accountModel, Agentinfo agentInfo) { if (agentInfo == null && agentInfo.userLevel == 0) { return; } string typeids = $"{(int)TmpType.小未平台}"; List <XcxTemplate> templist = XcxTemplateBLL.SingleModel.GetListByTypes(typeids); if (templist == null || templist.Count <= 0 || accountModel == null) { return; } List <XcxAppAccountRelation> usertemplate = GetListByTidAccountId($"'{accountModel.Id.ToString()}'", templist[0].Id); if (usertemplate != null && usertemplate.Count > 0) { return; } TransactionModel tran = new TransactionModel(); DateTime nowtime = DateTime.Now; foreach (XcxTemplate item in templist) { tran.Add($@"insert into XcxAppAccountRelation(TId,AccountId,AddTime,Url,price,outtime,agentid) values({item.Id}, '{accountModel.Id}', '{nowtime}', '{item.Link}', {item.Price}, '{agentInfo.addtime.AddYears(1)}',0)"); AgentdepositLog pricemodellog = new AgentdepositLog(); pricemodellog.addtime = DateTime.Now; pricemodellog.afterDeposit = 0; pricemodellog.agentid = 0; pricemodellog.beforeDeposit = 0; pricemodellog.cost = 0; pricemodellog.costdetail = $"客户免费使用小程序模板:" + item.TName; pricemodellog.type = 0; pricemodellog.tid = item.Id; tran.Add(AgentdepositLogBLL.SingleModel.BuildAddSql(pricemodellog)); } if (!ExecuteTransactionDataCorect(tran.sqlArray, tran.ParameterArray)) { log4net.LogHelper.WriteInfo(this.GetType(), "赠送免费版:失败," + Newtonsoft.Json.JsonConvert.SerializeObject(tran)); } }
/// <summary> /// 续期 /// </summary> /// <param name="platApplyAppModel"></param> /// <param name="accountid"></param> /// <param name="uselength"></param> /// <param name="tid"></param> /// <param name="msg"></param> /// <returns></returns> public bool AddTimeLength(PlatApplyApp platApplyAppModel, string accountid, int uselength, int tid, ref string msg) { DateTime nowtime = DateTime.Now; TransactionModel tran = new TransactionModel(); #region 基础验证 bool success = false; if (platApplyAppModel == null) { msg = "申请记录为空"; return(false); } //名片管理登陆账号 PlatMyCard mycardmodel = PlatMyCardBLL.SingleModel.GetModel(platApplyAppModel.MycardId); if (mycardmodel == null) { msg = "名片过期"; return(false); } //判断是否已开通 if (string.IsNullOrEmpty(mycardmodel.LoginId)) { msg = "该用户还没开通小程序"; return(false); } //店铺数据 PlatStore platStore = PlatStoreBLL.SingleModel.GetModel(platApplyAppModel.StoreId); if (platStore == null) { msg = "店铺过期,请刷新重试"; return(false); } #endregion #region 使用中的模板数据 XcxAppAccountRelation xcxrelation = XcxAppAccountRelationBLL.SingleModel.GetModel(platStore.Aid); if (xcxrelation == null) { msg = "模板数据过期"; return(false); } if (xcxrelation.outtime < nowtime) { xcxrelation.outtime = nowtime.AddYears(uselength); } else { xcxrelation.outtime = xcxrelation.outtime.AddYears(uselength); } tran.Add($"update XcxAppAccountRelation set outtime='{xcxrelation.outtime}',state=1 where id={xcxrelation.Id}"); #endregion //用户基础数据,获取普通预存款 AccountRelation accountrelation = AccountRelationBLL.SingleModel.GetModelByAccountId(accountid); //代理数据 Agentinfo agentinfo = AgentinfoBLL.SingleModel.GetModelByAccoundId(accountid); #region 模板跟模板价格 XcxTemplate tempinfo = XcxTemplateBLL.SingleModel.GetModelByType((int)TmpType.小未平台子模版); if (tempinfo != null && agentinfo != null) { List <XcxTemplate> xcxlist = XcxTemplateBLL.SingleModel.GetRealPriceTemplateList($" id in ({tempinfo.Id})", agentinfo.id); if (xcxlist != null && xcxlist.Count > 0) { //代理过期检验 AgentinfoBLL.SingleModel.CheckOutTime(ref xcxlist, agentinfo, 0, ref msg); tempinfo = xcxlist[0]; } } if (tempinfo == null) { msg = "模板数据为空"; return(false); } #endregion #region 扣费 //扣除总费用 int sum = tempinfo.Price * uselength; //变更前金额 int deposit = 0; //变更后的金额 int afterdeposit = 0; //扣除代理费用 if (agentinfo != null) { //变更前金额 deposit = agentinfo.deposit; //判断余额是否满足扣费 if (deposit + accountrelation.Deposit < sum) { msg = "余额不足"; return(false); } //变更后金额 if (deposit >= sum) { afterdeposit = deposit - sum; tran.Add($"UPDATE Agentinfo set deposit={afterdeposit} ,updateitme='{nowtime}' where id={agentinfo.id}"); } else if (accountrelation.Deposit >= sum) { afterdeposit = accountrelation.Deposit - sum; tran.Add($"UPDATE AccountRelation set deposit={afterdeposit} ,updatetime='{nowtime}' where id={accountrelation.Id}"); } else { //先扣除普通用户预存,再扣除代理商预存 afterdeposit = agentinfo.deposit - (sum - accountrelation.Deposit); tran.Add($"UPDATE Agentinfo set deposit={afterdeposit} ,updateitme='{nowtime}' where id={agentinfo.id}"); tran.Add($"UPDATE AccountRelation set deposit=0 ,updatetime='{nowtime}' where id={accountrelation.Id}"); } } //扣除普通账号预存款 else { sum = 100 * uselength; //变更前金额 deposit = accountrelation.Deposit; //判断余额是否满足扣费 if (deposit < sum) { msg = "余额不足"; return(false); } //变更后金额 afterdeposit = deposit - sum; tran.Add($"UPDATE AccountRelation set deposit={afterdeposit} ,updatetime='{nowtime}' where id={accountrelation.Id}"); } #endregion #region 开通流水 AgentdepositLog agentLog = new AgentdepositLog(); agentLog.agentid = agentinfo != null ? agentinfo.id : 0; agentLog.addtime = nowtime; agentLog.templateCount = 1; agentLog.customerid = xcxrelation.AccountId.ToString(); agentLog.tid = tempinfo.Id; agentLog.type = agentinfo != null ? (int)AgentDepositLogType.代理商续费 : (int)AgentDepositLogType.普通用户续费模板; agentLog.templateCount = 1; agentLog.beforeDeposit = deposit; agentLog.cost = sum; agentLog.acid = agentinfo != null ? 0 : accountrelation.Id; agentLog.Rid = platApplyAppModel.BindAId; agentLog.afterDeposit = afterdeposit; string desc = $"客户:{mycardmodel.Name} 续期模板:{tempinfo.TName} 续期年限:{uselength}年"; agentLog.costdetail = desc; tran.Add(AgentdepositLogBLL.SingleModel.BuildAddSql(agentLog)); #endregion success = base.ExecuteTransactionDataCorect(tran.sqlArray, tran.ParameterArray); //清除缓存 XcxAppAccountRelationBLL.SingleModel.RemoveRedis(xcxrelation.Id); return(success); }
/// <summary> /// 开通独立小程序 /// </summary> /// <param name="platApplyAppModel"></param> /// <param name="accountid"></param> /// <param name="uselength"></param> /// <param name="tid"></param> /// <param name="msg"></param> /// <returns></returns> public bool OpenStore(PlatApplyApp platApplyAppModel, string accountid, int uselength, int tid, ref string msg) { DateTime nowtime = DateTime.Now; TransactionModel tran = new TransactionModel(); bool success = false; if (platApplyAppModel == null) { msg = "申请记录为空"; return(false); } //用户基础数据,获取普通预存款 AccountRelation accountrelation = AccountRelationBLL.SingleModel.GetModelByAccountId(accountid); Agentinfo agentinfo = AgentinfoBLL.SingleModel.GetModelByAccoundId(accountid); #region 模板跟模板价格 XcxTemplate tempinfo = XcxTemplateBLL.SingleModel.GetModelByType((int)TmpType.小未平台子模版); if (tempinfo != null && agentinfo != null) { List <XcxTemplate> xcxlist = XcxTemplateBLL.SingleModel.GetRealPriceTemplateList($" id in ({tempinfo.Id})", agentinfo.id); if (xcxlist != null && xcxlist.Count > 0) { //代理过期检验 AgentinfoBLL.SingleModel.CheckOutTime(ref xcxlist, agentinfo, 0, ref msg); tempinfo = xcxlist[0]; } } if (tempinfo == null) { msg = "模板数据为空"; return(false); } #endregion #region 扣费 //扣除总费用 int sum = tempinfo.Price * uselength; //变更前金额 int deposit = 0; //变更后的金额 int afterdeposit = 0; //扣除代理费用 if (agentinfo != null) { //首次开通免费 if (AgentdepositLogBLL.SingleModel.IsFirstOpen(agentinfo.id, 2, 0)) { sum = 0; uselength = 1; } //变更前金额 deposit = agentinfo.deposit; //判断余额是否满足扣费 if (deposit + accountrelation.Deposit < sum) { msg = "余额不足"; return(false); } //变更后金额,先扣除普通用户账号预存款 if (accountrelation.Deposit > 0) { if (accountrelation.Deposit >= sum) { afterdeposit = accountrelation.Deposit - sum; tran.Add($"UPDATE AccountRelation set deposit={afterdeposit} ,updatetime='{nowtime}' where id={accountrelation.Id}"); } else { //先扣除普通用户预存,再扣除代理商预存 afterdeposit = agentinfo.deposit - (sum - accountrelation.Deposit); tran.Add($"UPDATE Agentinfo set deposit={afterdeposit} ,updateitme='{nowtime}' where id={agentinfo.id}"); tran.Add($"UPDATE AccountRelation set deposit=0 ,updatetime='{nowtime}' where id={accountrelation.Id}"); } } else { afterdeposit = deposit - sum; tran.Add($"UPDATE Agentinfo set deposit={afterdeposit} ,updateitme='{nowtime}' where id={agentinfo.id}"); } } //扣除普通账号预存款 else { //首次开通免费 if (AgentdepositLogBLL.SingleModel.IsFirstOpen(0, 13, accountrelation.Id)) { sum = 0; } else { sum = 100 * uselength; } //变更前金额 deposit = accountrelation.Deposit; //判断余额是否满足扣费 if (deposit < sum) { msg = "余额不足"; return(false); } //变更后金额 afterdeposit = deposit - sum; tran.Add($"UPDATE AccountRelation set deposit={afterdeposit} ,updatetime='{nowtime}' where id={accountrelation.Id}"); } #endregion //名片管理登陆账号 PlatMyCard mycardmodel = PlatMyCardBLL.SingleModel.GetModel(platApplyAppModel.MycardId); if (mycardmodel == null) { msg = "名片过期"; return(false); } //判断是否已开通 if (!string.IsNullOrEmpty(mycardmodel.LoginId)) { msg = "该用户已开通过,请刷新看看"; return(false); } //开通后台账号 Account account = AccountBLL.SingleModel.WeiXinRegister("", 0, "", true, "", "", "小未平台开通独立小程序"); if (account == null) { msg = "注册后台账号失败"; return(false); } mycardmodel.LoginId = account.LoginId; mycardmodel.UpdateTime = nowtime; tran.Add(PlatMyCardBLL.SingleModel.BuildUpdateSql(mycardmodel, "LoginId,UpdateTime")); //申请开通记录 platApplyAppModel.UserId = mycardmodel.UserId; platApplyAppModel.OpenState = 1; platApplyAppModel.OpenTime = nowtime; platApplyAppModel.UpdateTime = nowtime; tran.Add(base.BuildUpdateSql(platApplyAppModel, "OpenState,OpenTime,UpdateTime,UserId")); //开通独立小程序模板 tran.Add($@"insert into XcxAppAccountRelation(TId,AccountId,AddTime,Url,price,outtime,agentid) values({tempinfo.Id}, '{account.Id}', '{nowtime}', '{tempinfo.Link}', {tempinfo.Price}, '{nowtime.AddYears(uselength)}',{(agentinfo != null ? agentinfo.id : 0)})"); //绑定店铺 PlatStore platstoremodel = PlatStoreBLL.SingleModel.GetModel(platApplyAppModel.StoreId); if (platstoremodel == null) { msg = "店铺已过期,请刷新重试"; return(false); } tran.Add($"update PlatStore set aid=(select last_insert_id()),UpdateTime='{nowtime}' where id={platstoremodel.Id}"); #region 开通流水 AgentdepositLog agentLog = new AgentdepositLog(); agentLog.agentid = agentinfo != null ? agentinfo.id : 0; agentLog.addtime = nowtime; agentLog.templateCount = 1; agentLog.customerid = account.Id.ToString(); agentLog.tid = tempinfo.Id; agentLog.type = agentinfo != null ? (int)AgentDepositLogType.开通客户模板 : (int)AgentDepositLogType.普通用户开通模板; agentLog.templateCount = 1; agentLog.beforeDeposit = deposit; agentLog.cost = sum; agentLog.Rid = platApplyAppModel.BindAId; agentLog.acid = agentinfo != null ? 0 : accountrelation.Id; agentLog.afterDeposit = afterdeposit; string desc = $"客户:{mycardmodel.Name} 开通模板:{tempinfo.TName} 开通数量:1"; agentLog.costdetail = desc; tran.Add(AgentdepositLogBLL.SingleModel.BuildAddSql(agentLog)); #endregion //执行事务 success = base.ExecuteTransactionDataCorect(tran.sqlArray, tran.ParameterArray); return(success); }
public void TestTemplate() { Return_Msg msg = new Return_Msg(); msg.isok = false; msg.Msg = "好可惜,试用失败"; int tid = Context.GetRequestInt("tid", 0); int opensinglepagefree = Context.GetRequestInt("opensinglepagefree", 0); if (tid <= 0) { msg.Msg = "亲,试用模板ID不能为0"; if (opensinglepagefree <= 0) { Context.SuperResponseWrite(JsonConvert.SerializeObject(msg)); } return; } XcxTemplate xcxtempmodel = XcxTemplateBLL.SingleModel.GetModel(tid); if (xcxtempmodel == null) { msg.Msg = "哎呀模板不见了,请联系我们可爱的客服"; if (opensinglepagefree <= 0) { Context.SuperResponseWrite(JsonConvert.SerializeObject(msg)); } return; } if (dzuserId == null) { msg.code = "-10"; msg.Msg = "亲您要先登录"; if (opensinglepagefree <= 0) { Context.SuperResponseWrite(JsonConvert.SerializeObject(msg)); } return; } Account accountmodel = AccountBLL.SingleModel.GetModel(dzuserId); if (accountmodel == null) { msg.Msg = "亲您要先登录"; msg.code = "-10"; if (opensinglepagefree <= 0) { Context.SuperResponseWrite(JsonConvert.SerializeObject(msg)); } return; } if (string.IsNullOrEmpty(accountmodel.ConsigneePhone)) { msg.Msg = "亲请先绑定手机号"; msg.code = "-1"; if (opensinglepagefree <= 0) { Context.SuperResponseWrite(JsonConvert.SerializeObject(msg)); } return; } //模板过期时间 DateTime outtime = DateTime.Now.AddDays(7); //0:免费使用,1:试用7天 int freeuse = 0; //判断模板是否免费 if (!string.IsNullOrEmpty(_freexcxtype) && _freexcxtype.Contains("," + xcxtempmodel.Type.ToString() + ",")) { //配置文件中配置可以免费使用的模板类型 //免费使用模板100年 outtime = DateTime.Now.AddYears(100); } else if (!string.IsNullOrEmpty(_testxcxtype) && _testxcxtype.Contains("," + xcxtempmodel.Type.ToString() + ",")) { freeuse = 1; //配置文件中配置可以试用的模板类型 //限制单页版和官网版小程序可以试用 msg.Msg = "亲,该模板暂不提供试用"; if (opensinglepagefree <= 0) { Context.SuperResponseWrite(JsonConvert.SerializeObject(msg)); } return; } else { msg.Msg = "暂不支持此功能,请刷新重试"; if (opensinglepagefree <= 0) { Context.SuperResponseWrite(JsonConvert.SerializeObject(msg)); } return; } XcxAppAccountRelation xcxrelationmodel = XcxAppAccountRelationBLL.SingleModel.GetModelByaccountidAndTid(accountmodel.Id.ToString(), tid, 1); if (xcxrelationmodel != null) { msg.Msg = "亲,您已经开通该模板了!"; msg.code = "-2"; msg.isok = true; msg.dataObj = "http://dz.vzan.com/dzhome/casetemplate"; if (opensinglepagefree <= 0) { Context.SuperResponseWrite(JsonConvert.SerializeObject(msg)); } return; } xcxrelationmodel = new XcxAppAccountRelation(); xcxrelationmodel.TId = tid; xcxrelationmodel.AccountId = accountmodel.Id; xcxrelationmodel.price = xcxtempmodel.Price; xcxrelationmodel.Url = xcxtempmodel.Link; xcxrelationmodel.Desc = xcxtempmodel.Desc; xcxrelationmodel.AddTime = DateTime.Now; xcxrelationmodel.outtime = outtime; AgentdepositLog pricemodellog = new AgentdepositLog(); pricemodellog.addtime = DateTime.Now; pricemodellog.afterDeposit = 0; pricemodellog.agentid = 0; pricemodellog.beforeDeposit = 0; pricemodellog.cost = 0; pricemodellog.costdetail = $"客户{(freeuse == 0 ? "免费使用" : "试用")}小程序模板:" + xcxtempmodel.TName; pricemodellog.type = 0; pricemodellog.tid = xcxtempmodel.Id; if (Convert.ToInt32(XcxAppAccountRelationBLL.SingleModel.Add(xcxrelationmodel)) > 0) { if (Convert.ToInt32(AgentdepositLogBLL.SingleModel.Add(pricemodellog)) > 0) { msg.Msg = "欢迎" + (freeuse == 0 ? "使用" : "试用!"); msg.isok = true; msg.dataObj = "http://dz.vzan.com/dzhome/casetemplate"; if (opensinglepagefree <= 0) { Context.SuperResponseWrite(JsonConvert.SerializeObject(msg)); } return; } } if (opensinglepagefree <= 0) { Context.SuperResponseWrite(JsonConvert.SerializeObject(msg)); } return; }
/// <summary> /// 普通用户开通体验版 /// </summary> /// <param name="agentInfo"></param> /// <param name="tIds"></param> /// <param name="userAccount"></param> /// <param name="erroMsg"></param> /// <param name="dayLength"></param> /// <returns></returns> public bool OpenExperience(string tIds, Account userAccount, ref string erroMsg, int dayLength = 3) { TransactionModel tranModel = new TransactionModel(); //判断要开通的模板是否还没体验过 bool canOpen = IsOpenExperience(tIds, userAccount.Id.ToString()); if (canOpen) { erroMsg = "模板已开通过,请刷新重试"; return(false); } List <XcxTemplate> xcxList = XcxTemplateBLL.SingleModel.GetListByIds(tIds); //添加模板记录 foreach (XcxTemplate xcx in xcxList) { AgentdepositLog agentLog = new AgentdepositLog(); agentLog.agentid = 0; agentLog.addtime = DateTime.Now; agentLog.templateCount = 1; agentLog.customerid = userAccount.Id.ToString(); agentLog.tid = xcx.Id; agentLog.type = 2; agentLog.templateCount = 1; agentLog.costdetail = $"开通体验{xcx.TName}模板"; tranModel.Add(AgentdepositLogBLL.SingleModel.BuildAddSql(agentLog)); XcxAppAccountRelation xcxappaccountrelation = new XcxAppAccountRelation() { TId = xcx.Id, AccountId = userAccount.Id, AddTime = DateTime.Now, agentId = 0, Url = xcx.Link, price = xcx.Price, TimeLength = xcx.year, outtime = DateTime.Now.AddDays(dayLength), SCount = xcx.SCount, IsExperience = true, }; xcxappaccountrelation.Id = Convert.ToInt32(base.Add(xcxappaccountrelation)); if (xcx.Type == (int)TmpType.小程序多门店模板) { tranModel.Add(FootBathBLL.SingleModel.GetAddFootbathSQL(xcxappaccountrelation.AccountId, xcx.SCount - 1, xcxappaccountrelation.Id, xcxappaccountrelation.outtime).ToArray()); } } //执行事务 bool success = false; try { success = base.ExecuteTransactionDataCorect(tranModel.sqlArray, tranModel.ParameterArray); } catch (Exception ex) { erroMsg = ex.Message; } return(success); }
public bool UpdateDistribution(Distribution distribution, int deposit, List <XcxTemplate> list, out string errormsg) { TransactionModel tranModel = new TransactionModel(); MySqlParameter[] pone = null; bool result = false; errormsg = string.Empty; tranModel.Add($"update Distribution set name='{distribution.name}',remark ='{distribution.remark}' where id={distribution.id}"); //分销商预存款 Agentinfo agentinfo = AgentinfoBLL.SingleModel.GetModel(distribution.AgentId); if (agentinfo.deposit != deposit) { //充值 int cost = Math.Abs(deposit - agentinfo.deposit); //if (agentinfo == null) //{ // errormsg = "分销商代理数据不存在"; // return result; //} //if (cost <= 0) //{ // errormsg = "预存款充值不能小于0"; // return result; //} tranModel.Add($"update Agentinfo set deposit={deposit} where id={distribution.AgentId}"); AgentdepositLog agentdepositLog = new AgentdepositLog(); agentdepositLog.agentid = agentinfo.id; agentdepositLog.addtime = DateTime.Now; agentdepositLog.beforeDeposit = agentinfo.deposit; agentdepositLog.cost = cost; agentdepositLog.afterDeposit = deposit; agentdepositLog.type = 1; tranModel.Add(AgentdepositLogBLL.SingleModel.BuildAddSql(agentdepositLog, out pone), pone); //代理商预存款 Agentinfo agentinfop = AgentinfoBLL.SingleModel.GetModel(distribution.parentAgentId); if (agentinfo == null) { errormsg = "代理商数据不存在"; return(result); } List <Distribution> dlist = GetListByAgentId(agentinfop.id); if (dlist != null && dlist.Count > 0) { string agentids = string.Join(",", dlist.Select(s => s.AgentId)); List <Agentinfo> cagentinfolist = AgentinfoBLL.SingleModel.GetListByIds(agentids); if (cagentinfolist != null && cagentinfolist.Count > 0) { List <Agentinfo> otheragent = cagentinfolist.Where(w => w.id != agentinfo.id).ToList(); int tempcost = deposit; //其他分销代理的预存款 if (otheragent != null && otheragent.Count > 0) { tempcost += otheragent.Sum(s => s.deposit); } if (agentinfop.deposit <= tempcost && deposit > 0) { errormsg = "代理商预存款不足"; return(false); } } } //tranModel.Add($"update Agentinfo set deposit={agentinfop.deposit - cost} where id={agentinfop.id}"); //agentdepositLog = new AgentdepositLog(); //agentdepositLog.agentid = agentinfop.id; //agentdepositLog.addtime = DateTime.Now; //agentdepositLog.beforeDeposit = agentinfop.deposit; //agentdepositLog.cost = cost; //agentdepositLog.afterDeposit = agentinfop.deposit - cost; //agentdepositLog.type = 13; //agentdepositLog.customerid = agentinfop.useraccountid; //agentdepositLog.costdetail = $"为分销代理商{distribution.name}充值{(cost * 0.01).ToString("0.00")}"; //tranModel.Add(_agentdepositLogBll.BuildAddSql(agentdepositLog, out pone), pone); } foreach (var template in list) { Xcxtemplate_Price xcxtemplatePrice = Xcxtemplate_PriceBLL.SingleModel.GetModel($"tid ={template.Id} and agentid={distribution.AgentId} and VersionId={template.VersionId}"); if (xcxtemplatePrice == null) { xcxtemplatePrice = new Xcxtemplate_Price(); xcxtemplatePrice.price = template.Price; xcxtemplatePrice.agentid = distribution.AgentId.ToString(); xcxtemplatePrice.tid = template.Id.ToString(); xcxtemplatePrice.state = 0; xcxtemplatePrice.VersionId = template.VersionId; if (template.Type == (int)TmpType.小程序多门店模板 || template.Type == (int)TmpType.小程序餐饮多门店模板 || template.Type == (int)TmpType.智慧餐厅) { xcxtemplatePrice.SPrice = template.SPrice; xcxtemplatePrice.SCount = template.SCount; } Xcxtemplate_PriceBLL.SingleModel.Add(xcxtemplatePrice); continue; } tranModel.Add($"update xcxtemplate_Price set price={template.Price} {((template.Type == (int)TmpType.小程序多门店模板 || template.Type == (int)TmpType.小程序餐饮多门店模板 || template.Type == (int)TmpType.智慧餐厅) ? $",SPrice={template.SPrice},SCount={template.SCount}" : "")} where tid ={template.Id} and agentid={distribution.AgentId} and VersionId={template.VersionId}"); } try { result = base.ExecuteTransactionDataCorect(tranModel.sqlArray, tranModel.ParameterArray); } catch (Exception) { log4net.LogHelper.WriteInfo(this.GetType(), Newtonsoft.Json.JsonConvert.SerializeObject(tranModel.sqlArray)); } return(result); }
public bool AddDistribution(Account account, int parentAgentId, int agenttype, string username, List <XcxTemplate> templateList, int deposit, string remark, ref string msg) { bool result = false; TransactionModel tranModel = new TransactionModel(); MySqlParameter[] pone = null; //代理商扣费 Agentinfo agentinfop = AgentinfoBLL.SingleModel.GetModel(parentAgentId); if (agentinfop == null) { msg = "代理商不存在"; return(false); } List <Distribution> dlist = GetListByAgentId(agentinfop.id); if (dlist != null && dlist.Count > 0) { string agentids = string.Join(",", dlist.Select(s => s.AgentId)); List <Agentinfo> cagentinfolist = AgentinfoBLL.SingleModel.GetListByIds(agentids); if (cagentinfolist != null && cagentinfolist.Count > 0) { int cost = cagentinfolist.Sum(s => s.deposit) + deposit; if (agentinfop.deposit <= cost && deposit > 0) { msg = "代理商预存款不足"; return(false); } } } //tranModel.Add($"update Agentinfo set deposit={cost} where id={agentinfop.id}"); //AgentdepositLog agentdepositLog = new AgentdepositLog(); //agentdepositLog.agentid = agentinfop.id; //agentdepositLog.addtime = DateTime.Now; //agentdepositLog.beforeDeposit = agentinfop.deposit; //agentdepositLog.cost = deposit; //agentdepositLog.afterDeposit = cost; //agentdepositLog.type = 13; //agentdepositLog.customerid = agentinfop.useraccountid; //agentdepositLog.costdetail = $"为分销代理商{username}充值{(deposit*0.01).ToString("0.00")}"; //tranModel.Add(_agentdepositLogBll.BuildAddSql(agentdepositLog, out pone), pone); //插入代理表 Agentinfo agent = new Agentinfo(); agent.state = 1; agent.deposit = deposit; agent.addtime = DateTime.Now; agent.updateitme = DateTime.Now; agent.useraccountid = account.Id.ToString(); agent.userLevel = 1; agent.AgentType = agenttype; agent.id = Convert.ToInt32(AgentinfoBLL.SingleModel.Add(agent)); if (agent.id <= 0) { return(result); } tranModel.Add($"update Agentinfo set deposit={deposit} where id={agent.id}"); AgentdepositLog agentdepositLog = new AgentdepositLog(); agentdepositLog.agentid = agent.id; agentdepositLog.addtime = DateTime.Now; agentdepositLog.beforeDeposit = 0; agentdepositLog.cost = agent.deposit; agentdepositLog.afterDeposit = agentdepositLog.beforeDeposit + agent.deposit; agentdepositLog.type = 1; tranModel.Add(AgentdepositLogBLL.SingleModel.BuildAddSql(agentdepositLog, out pone), pone); //插入小程序模板与代理关系表 自定义价格 foreach (var template in templateList) { Xcxtemplate_Price xcxtemplate_Price = Xcxtemplate_PriceBLL.SingleModel.GetModel($"tid={template.Id} and agentid={agent.id} and VersionId={template.VersionId}"); if (xcxtemplate_Price == null) { xcxtemplate_Price = new Xcxtemplate_Price(); xcxtemplate_Price.price = template.Price; xcxtemplate_Price.tid = template.Id.ToString(); xcxtemplate_Price.agentid = agent.id.ToString(); xcxtemplate_Price.VersionId = template.VersionId; if (template.Price <= 0) { xcxtemplate_Price.LimitCount = template.LimitCount <= 0?10: template.LimitCount; } tranModel.Add(Xcxtemplate_PriceBLL.SingleModel.BuildAddSql(xcxtemplate_Price, out pone), pone); } else { tranModel.Add($"update xcxtemplate_Price set price={template.Price} where tid={template.Id} and agentid={agent.id} and VersionId={template.VersionId}"); } } //插入分销商表 Distribution distribution = new Distribution(); distribution.name = username; distribution.AgentId = agent.id; distribution.useraccountid = account.Id.ToString(); distribution.parentAgentId = parentAgentId; distribution.state = 1; distribution.remark = remark; distribution.addtime = DateTime.Now; distribution.modifyDate = DateTime.Now; tranModel.Add(base.BuildAddSql(distribution, out pone), pone); try { result = base.ExecuteTransactionDataCorect(tranModel.sqlArray, tranModel.ParameterArray); } catch (Exception) { log4net.LogHelper.WriteInfo(this.GetType(), Newtonsoft.Json.JsonConvert.SerializeObject(tranModel.sqlArray)); } if (!result) { agent.state = -2; AgentinfoBLL.SingleModel.Update(agent, "state"); } return(result); }