public ActionResult SaveExchangePlayCardConfig(ExchangePlayCardConfig model) { result = new Return_Msg(); int appId = Context.GetRequestInt("appId", 0); if (dzaccount == null) { result.Msg = "登录信息超时"; return(Json(result)); } XcxAppAccountRelation xcx = XcxAppAccountRelationBLL.SingleModel.GetModelByaccountidAndAppid(appId, dzaccount.Id.ToString()); if (xcx == null) { result.Msg = "小程序未授权"; return(Json(result)); } XcxTemplate xcxTemplate = XcxTemplateBLL.SingleModel.GetModel($"id={xcx.TId}"); if (xcxTemplate == null) { result.Msg = "找不到小程序模板"; return(Json(result)); } if (xcxTemplate.Type == (int)TmpType.小程序专业模板) { FunctionList functionList = new FunctionList(); int industr = xcx.VersionId; functionList = FunctionListBLL.SingleModel.GetModel($"TemplateType={xcxTemplate.Type} and VersionId={industr}"); if (functionList == null) { result.Msg = "功能权限未设置"; return(Json(result)); } OperationMgr operationMgr = new OperationMgr(); if (!string.IsNullOrEmpty(functionList.OperationMgr)) { operationMgr = JsonConvert.DeserializeObject <OperationMgr>(functionList.OperationMgr); } if (operationMgr.Integral == 1) { result.Msg = "请先升级到更高版本才能开启此功能"; return(Json(result)); } } Store store = StoreBLL.SingleModel.GetModelByRid(appId); if (store == null) { result.Msg = $"店铺配置不存在"; return(Json(result)); } ExchangePlayCardConfig exchangePlayCardConfig = new ExchangePlayCardConfig(); store.funJoinModel = JsonConvert.DeserializeObject <StoreConfigModel>(store.configJson) ?? new StoreConfigModel();//若为 null 则new一个新的配置 if (store.funJoinModel != null) { store.funJoinModel.ExchangePlayCardConfig = JsonConvert.SerializeObject(model); store.configJson = JsonConvert.SerializeObject(store.funJoinModel); } if (StoreBLL.SingleModel.Update(store, "configJson")) { result.Msg = $"保存成功"; return(Json(result)); } else { result.Msg = $"保存失败"; return(Json(result)); } }
public ExchangePlayCardRelation GetExchangePlayCardRelation(int userId, int appId, out int resultCode) { bool blackout = false;//是否断签 resultCode = 200; Store storeModel = StoreBLL.SingleModel.GetModelByAId(appId); if (storeModel == null || string.IsNullOrEmpty(storeModel.configJson)) { resultCode = 404;//店铺配置信息没有找到 return(null); } ExchangePlayCardConfig exchangePlayCardConfig = new ExchangePlayCardConfig(); storeModel.funJoinModel = JsonConvert.DeserializeObject <StoreConfigModel>(storeModel.configJson); if (string.IsNullOrEmpty(storeModel.funJoinModel.ExchangePlayCardConfig)) { resultCode = 403;//签到配置信息没有找到 return(null); } exchangePlayCardConfig = JsonConvert.DeserializeObject <ExchangePlayCardConfig>(storeModel.funJoinModel.ExchangePlayCardConfig); if (exchangePlayCardConfig.State == 0) { resultCode = 302;//签到开关关闭 return(null); } #region 表示空白从未打卡过 ExchangePlayCardRelation exchangePlayCardRelation = base.GetModel($"userId={userId} and Aid={appId}"); if (exchangePlayCardRelation == null) { exchangePlayCardRelation = new ExchangePlayCardRelation() { Aid = appId, UserId = userId, UpdateTime = DateTime.Now }; for (int i = 0; i < 7; i++) { exchangePlayCardRelation.listPlayCardLog.Add(new ExchangePlayCardLog() { Aid = appId, UserId = userId, AddTime = DateTime.Now.AddMinutes(i), Played = false, Points = exchangePlayCardConfig.DayGivePoints }); } return(exchangePlayCardRelation); } #endregion ExchangePlayCardLog exchangePlayCardLog = ExchangePlayCardLogBLL.SingleModel.GetModel($"userId={userId} and Aid={appId}"); if (exchangePlayCardLog != null) { //判断是否断签 double day = CommondHelper.DateDiff(Convert.ToDateTime(exchangePlayCardLog.AddTime.ToString("yyyy-MM-dd")), Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd"))).TotalDays; if (day > 1)//大于1表示断签了隔了至少一天没有签到 { blackout = true; } } if (blackout) { //断签则将连续签到天数归零以及上次赠送积分的连续签到的天数归零 exchangePlayCardRelation.ConnectDay = 0; exchangePlayCardRelation.LastConnectDay = 0; exchangePlayCardRelation.UpdateTime = DateTime.Now; if (!base.Update(exchangePlayCardRelation, "ConnectDay,LastConnectDay,UpdateTime")) { resultCode = 500;//说明异常 } for (int i = 0; i < 7; i++) { exchangePlayCardRelation.listPlayCardLog.Add(new ExchangePlayCardLog() { Aid = appId, UserId = userId, AddTime = DateTime.Now.AddMinutes(i), Played = false, Points = exchangePlayCardConfig.DayGivePoints }); } return(exchangePlayCardRelation); } //没有断签 返回连续签到信息 int tempDay = exchangePlayCardRelation.ConnectDay; if (tempDay > 7) { tempDay = exchangePlayCardRelation.ConnectDay % 7; } exchangePlayCardRelation.listPlayCardLog = ExchangePlayCardLogBLL.SingleModel.GetList($"userId={userId} and Aid={appId}", tempDay, 1, "*", "AddTime desc"); if (tempDay < 7) { exchangePlayCardRelation.listPlayCardLog = exchangePlayCardRelation.listPlayCardLog.OrderBy(x => x.AddTime).ToList(); for (int i = 0; i < 7 - tempDay; i++) { exchangePlayCardRelation.listPlayCardLog.Add(new ExchangePlayCardLog() { Aid = appId, UserId = userId, AddTime = DateTime.Now.AddMinutes(i), Played = false, Points = exchangePlayCardConfig.DayGivePoints }); } } ExchangePlayCardLog todayPlayCardLog = ExchangePlayCardLogBLL.SingleModel.GetModel($"userId={userId} and Aid={appId} and to_days(AddTime) = to_days(now())"); //测试用 ExchangePlayCardLog todayPlayCardLog = _exchangePlayCardLogBLL.GetModel($"userId={userId} and Aid={appId} and AddTime>NOW()-INTERVAL 2 MINUTE");// if (todayPlayCardLog != null)//2分钟之内 { //今天已经签到 exchangePlayCardRelation.TodayPlayCard = true; } return(exchangePlayCardRelation); }
public ActionResult ExchangeRuleList(int appId = 0) { if (appId <= 0) { return(View("PageError", new Return_Msg() { Msg = "参数错误!", code = "500" })); } if (dzaccount == null) { return(Redirect("/dzhome/login")); } XcxAppAccountRelation xcx = XcxAppAccountRelationBLL.SingleModel.GetModelByaccountidAndAppid(appId, dzaccount.Id.ToString()); if (xcx == null) { return(View("PageError", new Return_Msg() { Msg = "小程序未授权!", code = "403" })); } XcxTemplate xcxTemplate = XcxTemplateBLL.SingleModel.GetModel($"id={xcx.TId}"); if (xcxTemplate == null) { return(View("PageError", new Return_Msg() { Msg = "小程序模板不存在!", code = "500" })); } Store storeModel = StoreBLL.SingleModel.GetModelByAId(appId); if (storeModel == null) { return(View("PageError", new Return_Msg() { Msg = "店铺信息错误!", code = "403" })); } int integralSwtich = 0;//积分开关 int versionId = 0; if (xcxTemplate.Type == (int)TmpType.小程序专业模板) { FunctionList functionList = new FunctionList(); versionId = xcx.VersionId; functionList = FunctionListBLL.SingleModel.GetModel($"TemplateType={xcxTemplate.Type} and VersionId={versionId}"); if (functionList == null) { return(View("PageError", new Return_Msg() { Msg = "功能权限未设置!", code = "500" })); } if (!string.IsNullOrEmpty(functionList.OperationMgr)) { OperationMgr operationMgr = JsonConvert.DeserializeObject <OperationMgr>(functionList.OperationMgr); integralSwtich = operationMgr.Integral; } } ViewBag.integralSwtich = integralSwtich; ViewBag.versionId = versionId; ViewBag.PageType = xcxTemplate.Type; ViewBag.appId = appId; List <ExchangeRule> listRule = ExchangeRuleBLL.SingleModel.GetList($"appId={appId} and state=0"); listRule.ForEach(x => { if (x.ruleType == 1 && !string.IsNullOrEmpty(x.goodids)) { List <EntGoods> listgoods = EntGoodsBLL.SingleModel.GetList($" id in({x.goodids})"); listgoods.ForEach(y => { x.goodslist.Add(new PickGood { Id = y.id, GoodsName = y.name, ImgUrl = y.img, sel = true, showtime = y.showUpdateTime }); }); } }); ExchangePlayCardConfig exchangePlayCardConfig = new ExchangePlayCardConfig(); if (string.IsNullOrEmpty(storeModel.configJson)) { storeModel.funJoinModel = new StoreConfigModel(); } else { storeModel.funJoinModel = JsonConvert.DeserializeObject <StoreConfigModel>(storeModel.configJson); } if (!string.IsNullOrEmpty(storeModel.funJoinModel.ExchangePlayCardConfig)) { exchangePlayCardConfig = JsonConvert.DeserializeObject <ExchangePlayCardConfig>(storeModel.funJoinModel.ExchangePlayCardConfig); } ViewBag.ExchangePlayCardConfig = exchangePlayCardConfig; return(View(listRule)); }
public ExchangePlayCardRelation PlayCard(int userId, int appId, out int resultCode) { //插入打卡记录,根据规则进行积分更新相加,最后更新签到信息 resultCode = 200; Store storeModel = StoreBLL.SingleModel.GetModelByAId(appId); if (storeModel == null || string.IsNullOrEmpty(storeModel.configJson)) { resultCode = 500;//店铺配置信息没有找到 return(null); } ExchangePlayCardLog todayPlayCardLog = ExchangePlayCardLogBLL.SingleModel.GetModel($"userId={userId} and Aid={appId} and to_days(AddTime) = to_days(now())"); if (todayPlayCardLog != null) { resultCode = 403;//今天已签到 return(null); } ExchangePlayCardConfig exchangePlayCardConfig = new ExchangePlayCardConfig(); storeModel.funJoinModel = JsonConvert.DeserializeObject <StoreConfigModel>(storeModel.configJson); if (string.IsNullOrEmpty(storeModel.funJoinModel.ExchangePlayCardConfig)) { resultCode = 404;//签到配置信息没有找到 return(null); } exchangePlayCardConfig = JsonConvert.DeserializeObject <ExchangePlayCardConfig>(storeModel.funJoinModel.ExchangePlayCardConfig); if (exchangePlayCardConfig.State == 0) { resultCode = 302;//签到开关关闭 return(null); } TransactionModel transactionModel = new TransactionModel(); bool havePlayCardRelation = true; ExchangePlayCardRelation exchangePlayCardRelation = base.GetModel($"userId={userId} and Aid={appId}"); if (exchangePlayCardRelation == null) { exchangePlayCardRelation = new ExchangePlayCardRelation(); exchangePlayCardRelation.UserId = userId; exchangePlayCardRelation.Aid = appId; exchangePlayCardRelation.ConnectDay = 1; exchangePlayCardRelation.LastConnectDay = 0; exchangePlayCardRelation.UpdateTime = DateTime.Now; havePlayCardRelation = false; transactionModel.Add(base.BuildAddSql(exchangePlayCardRelation)); } else { exchangePlayCardRelation.ConnectDay += 1; exchangePlayCardRelation.UpdateTime = DateTime.Now; } //获取签到送积分规则 int curSumIntegral = 0; curSumIntegral += exchangePlayCardConfig.DayGivePoints;//每天签到送多少积分 int tempDay = exchangePlayCardRelation.ConnectDay - exchangePlayCardRelation.LastConnectDay; if (tempDay < 0) { resultCode = 502;//签到天数错误 return(null); } ExchangePlayCardLog exchangePlayCardLog = new ExchangePlayCardLog(); exchangePlayCardLog.AddTime = DateTime.Now; exchangePlayCardLog.Aid = appId; exchangePlayCardLog.UserId = userId; if (tempDay >= exchangePlayCardConfig.ConnectDay && havePlayCardRelation) { curSumIntegral += exchangePlayCardConfig.ConnectDayGivePoints; exchangePlayCardLog.Remark = $"满足连续签到{exchangePlayCardConfig.ConnectDayGivePoints}"; exchangePlayCardRelation.LastConnectDay += exchangePlayCardConfig.ConnectDay;//记录上次连续赠送积分的天数断签后清零 } if (curSumIntegral < 0) { resultCode = 503;//签到送积分计算错误 return(null); } exchangePlayCardLog.Points = curSumIntegral; exchangePlayCardLog.Remark += $"每天签到送{exchangePlayCardConfig.DayGivePoints}"; transactionModel.Add(ExchangePlayCardLogBLL.SingleModel.BuildAddSql(exchangePlayCardLog)); if (havePlayCardRelation) { transactionModel.Add(base.BuildUpdateSql(exchangePlayCardRelation, "ConnectDay,UpdateTime,LastConnectDay")); } ExchangeUserIntegral exchangeUserIntegral = ExchangeUserIntegralBLL.SingleModel.GetModel($"userId={userId}"); if (exchangeUserIntegral != null) { exchangeUserIntegral.integral = exchangeUserIntegral.integral + curSumIntegral; exchangeUserIntegral.UpdateDate = DateTime.Now; transactionModel.Add(ExchangeUserIntegralBLL.SingleModel.BuildUpdateSql(exchangeUserIntegral, "integral,UpdateDate")); } else { //表示新增 exchangeUserIntegral = new ExchangeUserIntegral { UserId = userId, integral = curSumIntegral, AddTime = DateTime.Now, UpdateDate = DateTime.Now }; transactionModel.Add(ExchangeUserIntegralBLL.SingleModel.BuildAddSql(exchangeUserIntegral)); } //积分变动日志 transactionModel.Add(ExchangeUserIntegralLogBLL.SingleModel.BuildAddSql(new ExchangeUserIntegralLog { ruleId = -1, appId = appId, integral = curSumIntegral, ruleType = -1, userId = userId, actiontype = 0, curintegral = curSumIntegral, AddTime = DateTime.Now, UpdateDate = DateTime.Now, ordertype = 3 })); if (!base.ExecuteTransactionDataCorect(transactionModel.sqlArray)) { resultCode = -1; return(null); } exchangePlayCardRelation = base.GetModel($"userId={userId} and Aid={appId}"); exchangePlayCardRelation.TodayPlayCard = true; int tempDay2 = exchangePlayCardRelation.ConnectDay; if (tempDay2 > 7) { tempDay2 = exchangePlayCardRelation.ConnectDay % 7; } exchangePlayCardRelation.listPlayCardLog = ExchangePlayCardLogBLL.SingleModel.GetList($"userId={userId} and Aid={appId}", tempDay2, 1, "*", "AddTime desc"); if (tempDay2 < 7) { exchangePlayCardRelation.listPlayCardLog = exchangePlayCardRelation.listPlayCardLog.OrderBy(x => x.AddTime).ToList(); for (int i = 0; i < 7 - tempDay2; i++) { exchangePlayCardRelation.listPlayCardLog.Add(new ExchangePlayCardLog() { Aid = appId, UserId = userId, AddTime = DateTime.Now.AddMinutes(i), Played = false, Points = exchangePlayCardConfig.DayGivePoints }); } } return(exchangePlayCardRelation); }