public ActionResult UpdateSortExchangeActivity(List <ExchangeActivity> list) { result = new Return_Msg(); if (list == null || list.Count <= 0) { result.Msg = "数据不能为空"; return(Json(result)); } ExchangeActivity model = new ExchangeActivity(); TransactionModel tranModel = new TransactionModel(); string sql = string.Empty; foreach (ExchangeActivity item in list) { model = ExchangeActivityBLL.SingleModel.GetModel(item.id); if (model == null) { result.Msg = $"Id={item.id}不存在数据库里"; return(Json(result)); } if (model.appId != item.appId) { result.Msg = $"Id={item.id}权限不足"; return(Json(result)); } model.SortNumber = item.SortNumber; model.UpdateDate = DateTime.Now; sql = ExchangeActivityBLL.SingleModel.BuildUpdateSql(model, "SortNumber,UpdateDate"); tranModel.Add(sql); } if (tranModel.sqlArray != null && tranModel.sqlArray.Length > 0) { if (ExchangeActivityBLL.SingleModel.ExecuteTransactionDataCorect(tranModel.sqlArray)) { result.isok = true; result.Msg = "操作成功"; return(Json(result)); } else { result.Msg = "操作失败"; return(Json(result)); } } else { result.Msg = "没有需要更新的数据"; return(Json(result)); } }
public ActionResult DelOrDownExchangeActivity(int appId, int Id) { int actionType = Context.GetRequestInt("actionType", 0); if (appId <= 0) { return(Json(new { isok = false, msg = "appId非法" }, JsonRequestBehavior.AllowGet)); } if (dzaccount == null) { return(Json(new { isok = false, msg = "登录信息超时" }, JsonRequestBehavior.AllowGet)); } XcxAppAccountRelation xcx = XcxAppAccountRelationBLL.SingleModel.GetModelByaccountidAndAppid(appId, dzaccount.Id.ToString()); if (xcx == null) { return(Json(new { isok = false, msg = "小程序未授权" }, JsonRequestBehavior.AllowGet)); } ExchangeActivity model = ExchangeActivityBLL.SingleModel.GetModel(Id); if (model == null) { return(Json(new { isok = false, msg = "数据不存在!" }, JsonRequestBehavior.AllowGet)); } if (model.appId != appId) { return(Json(new { isok = false, msg = "没有权限!" }, JsonRequestBehavior.AllowGet)); } string field = "UpdateDate,"; if (actionType == 0) { //表示 上架或者下架 model.state = model.state == 0 ? 1 : 0; model.UpdateDate = DateTime.Now; field += "state"; } else { //表示删除 model.isdel = 1; model.UpdateDate = DateTime.Now; field += "isdel"; } return(Json(new { isok = true, msg = ExchangeActivityBLL.SingleModel.Update(model, field) ? "操作成功" : "操作失败" }, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 积分兑换商品 只有返回为2才表示成功 /// </summary> /// <param name="exchangeActivity">兑换商品</param> /// <param name="userId"></param> /// <param name="appId"></param> /// <param name="address">收货地址</param> /// <returns>0→积分不足,1→生成订单失败,2→成功,3→系统异常</returns> public int SubUserIntegral(ExchangeActivity exchangeActivity, int userId, int appId, string address, int way = 0) { //.先生成订单,生成成功后拿到 订单Id //1.根据订单Id更新订单状态 2.扣除积分以及3.插入积分记录日志 放在事务里执行 ExchangeUserIntegral exchangeUserIntegral = GetModel($"userId={userId}"); if (exchangeUserIntegral == null || exchangeUserIntegral.integral < exchangeActivity.integral) { return(-1);//积分不足(请先进行消费获得积分)! } ExchangeActivityOrder exchangeActivityOrder = new ExchangeActivityOrder { appId = appId, UserId = userId, ActivityId = exchangeActivity.id, integral = exchangeActivity.integral, PayWay = 0, BuyCount = 1, address = address, state = 0, AddTime = DateTime.Now, activityImg = exchangeActivity.activityimg, activityName = exchangeActivity.activityname, originalPrice = exchangeActivity.originalPrice, Way = way }; int orderId = Convert.ToInt32(ExchangeActivityOrderBLL.SingleModel.Add(exchangeActivityOrder)); if (orderId <= 0) { return(-2);//支付失败(生成订单失败) } var TranModel = new TransactionModel(); List <string> listSql = new List <string>(); //减积分商品库存 exchangeActivity.stock--; listSql.Add(ExchangeActivityBLL.SingleModel.BuildUpdateSql(exchangeActivity, "stock")); #region 生成积分兑换商品订单操作 //对外订单号规则:年月日时分 + 商品ID最后3位数字 var idStr = exchangeActivity.id.ToString(); if (idStr.Length >= 3) { idStr = idStr.Substring(idStr.Length - 3, 3); } else { idStr.PadLeft(3, '0'); } idStr = $"{DateTime.Now.ToString("yyyyMMddHHmm")}{idStr}"; exchangeActivityOrder.Id = orderId; exchangeActivityOrder.OrderNum = idStr; exchangeActivityOrder.state = 2; exchangeActivityOrder.PayTime = DateTime.Now; listSql.Add(ExchangeActivityOrderBLL.SingleModel.BuildUpdateSql(exchangeActivityOrder, "state,PayTime,OrderNum")); #endregion #region 扣除用户积分操作 exchangeUserIntegral.integral = exchangeUserIntegral.integral - exchangeActivity.integral; exchangeUserIntegral.UpdateDate = DateTime.Now; listSql.Add(BuildUpdateSql(exchangeUserIntegral, "integral,UpdateDate")); #endregion #region 插入积分兑换商品后扣除积分的日志 ExchangeUserIntegralLog userIntegralLog = new ExchangeUserIntegralLog { ruleId = 0, appId = appId, integral = -1, price = 0, ruleType = -1, goodids = "-1", orderId = orderId, usegoodids = "-1", userId = userId, actiontype = -1, curintegral = exchangeActivity.integral, AddTime = DateTime.Now, UpdateDate = DateTime.Now, ordertype = 1, buyPrice = exchangeActivity.price }; listSql.Add(ExchangeUserIntegralLogBLL.SingleModel.BuildAddSql(userIntegralLog)); #endregion if (listSql.Count > 0) { TranModel.Add(listSql.ToArray()); if (ExchangeActivityOrderBLL.SingleModel.ExecuteTransactionDataCorect(TranModel.sqlArray, TranModel.ParameterArray)) { return(orderId); } } return(-3); }
public ActionResult ExchangeActivitySaveSet(ExchangeActivity exChangeModel) { int appId = Context.GetRequestInt("appId", 0); if (appId <= 0) { return(Json(new { isok = false, msg = "appId非法" }, JsonRequestBehavior.AllowGet)); } if (dzaccount == null) { return(Json(new { isok = false, msg = "登录信息超时" }, JsonRequestBehavior.AllowGet)); } XcxAppAccountRelation xcx = XcxAppAccountRelationBLL.SingleModel.GetModelByaccountidAndAppid(appId, dzaccount.Id.ToString()); if (xcx == null) { return(Json(new { isok = false, msg = "小程序未授权" }, JsonRequestBehavior.AllowGet)); } XcxTemplate xcxTemplate = XcxTemplateBLL.SingleModel.GetModel($"id={xcx.TId}"); if (xcxTemplate == null) { return(Json(new { isok = false, msg = "找不到该小程序模板" }, JsonRequestBehavior.AllowGet)); } if (exChangeModel.activityname.Length <= 0 || exChangeModel.activityname.Length > 100) { return(Json(new { isok = false, msg = "活动名称不能为空并且小于100字符" }, JsonRequestBehavior.AllowGet)); } if (!Regex.IsMatch(exChangeModel.integral.ToString(), @"^\+?[0-9]*$")) { return(Json(new { isok = false, msg = "所需积分必须为整数" }, JsonRequestBehavior.AllowGet)); } if (!Regex.IsMatch(exChangeModel.stock.ToString(), @"^\+?[0-9]*$")) { return(Json(new { isok = false, msg = "库存必须为正整数" }, JsonRequestBehavior.AllowGet)); } if (!Regex.IsMatch(exChangeModel.perexgcount.ToString(), @"^\+?[1-9][0-9]*$")) { return(Json(new { isok = false, msg = "每人可兑换数量必须为正整数且大于0" }, JsonRequestBehavior.AllowGet)); } if (!Regex.IsMatch(exChangeModel.freight.ToString(), @"^\+?[0-9]*$")) { return(Json(new { isok = false, msg = "运费不合法!" }, JsonRequestBehavior.AllowGet)); } if (exChangeModel.exchangeway == 1) { //表示积分+金额兑换需要验证金额 if (!Regex.IsMatch(exChangeModel.price.ToString(), @"^\+?[1-9][0-9]*$") || exChangeModel.price <= 0) { return(Json(new { isok = false, msg = "金额不合法!" }, JsonRequestBehavior.AllowGet)); } } //图片 string activityimg = Context.GetRequest("activityimg", string.Empty); string imgs = Context.GetRequest("imgs", string.Empty); bool result = false; string[] Imgs = imgs.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); if (exChangeModel.id > 0) { //表示更新 ExchangeActivity model = ExchangeActivityBLL.SingleModel.GetModel(exChangeModel.id); if (model == null) { return(Json(new { isok = false, msg = "数据不存在!" }, JsonRequestBehavior.AllowGet)); } exChangeModel.UpdateDate = DateTime.Now; result = ExchangeActivityBLL.SingleModel.Update(exChangeModel); } else { 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) { return(Json(new { isok = false, msg = $"功能权限未设置" }, JsonRequestBehavior.AllowGet)); } OperationMgr operationMgr = new OperationMgr(); if (!string.IsNullOrEmpty(functionList.OperationMgr)) { operationMgr = JsonConvert.DeserializeObject <OperationMgr>(functionList.OperationMgr); } if (operationMgr.Integral == 1) { return(Json(new { isok = false, msg = $"请先升级到更高版本才能开启此功能" }, JsonRequestBehavior.AllowGet)); } } //表示新增 if (activityimg.Length <= 0) { return(Json(new { isok = false, msg = "请上传活动图片!" }, JsonRequestBehavior.AllowGet)); } if (Imgs.Length <= 0 || Imgs.Length > 5) { return(Json(new { isok = false, msg = "轮播图至少一张最多5张!" }, JsonRequestBehavior.AllowGet)); } exChangeModel.appId = appId; exChangeModel.apptype = xcxTemplate.Type; exChangeModel.AddTime = DateTime.Now; exChangeModel.UpdateDate = DateTime.Now; int id = Convert.ToInt32(ExchangeActivityBLL.SingleModel.Add(exChangeModel)); result = id > 0; exChangeModel.id = id; } if (result) { if (!string.IsNullOrEmpty(activityimg)) { //添加店铺Logo C_AttachmentBLL.SingleModel.Add(new C_Attachment { itemId = exChangeModel.id, createDate = DateTime.Now, filepath = activityimg, itemType = (int)AttachmentItemType.小程序积分活动图片, thumbnail = Utility.AliOss.AliOSSHelper.GetAliImgThumbKey(activityimg, 300, 300), status = 0 }); } if (Imgs.Length > 0) { foreach (string img in Imgs) { //判断上传图片是否以http开头,不然为破图-蔡华兴 if (!string.IsNullOrWhiteSpace(img) && img.IndexOf("http") == 0) { C_AttachmentBLL.SingleModel.Add(new C_Attachment { itemId = exChangeModel.id, createDate = DateTime.Now, filepath = img, itemType = (int)AttachmentItemType.小程序积分活动轮播图, thumbnail = img, status = 0 }); } } } return(Json(new { isok = true, msg = "操作成功!", obj = exChangeModel.id }, JsonRequestBehavior.AllowGet)); } return(Json(new { isok = true, msg = "操作失败!" }, JsonRequestBehavior.AllowGet)); }
public ActionResult ExchangeActivitySet(int appId, int Id = 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" })); } ViewBag.PageType = xcxTemplate.Type; ExchangeActivity exchange = new ExchangeActivity(); if (Id > 0) { //表示更新 exchange = ExchangeActivityBLL.SingleModel.GetModel(Id); if (exchange == null) { return(View("PageError", new Return_Msg() { Msg = "数据不存在!", code = "500" })); } if (exchange.appId != appId) { return(View("PageError", new Return_Msg() { Msg = "暂无权限!", code = "403" })); } List <C_Attachment> activityimgList = C_AttachmentBLL.SingleModel.GetListByCache(exchange.id, (int)AttachmentItemType.小程序积分活动图片); if (activityimgList != null && activityimgList.Count > 0) { ViewBag.activityimg = new List <object>() { new { id = activityimgList[0].id, url = activityimgList[0].filepath } }; } List <object> imgs = new List <object>(); List <C_Attachment> imgList = C_AttachmentBLL.SingleModel.GetListByCache(exchange.id, (int)AttachmentItemType.小程序积分活动轮播图); if (imgList != null && imgList.Count > 0) { imgList.ForEach(x => { imgs.Add(new { id = x.id, url = x.filepath }); }); ViewBag.imgs = imgs; } } else { //表示新增 exchange = new ExchangeActivity(); } ViewBag.appId = appId; return(View(exchange)); }