/// <summary> /// 编辑门店产品 /// </summary> /// <returns></returns> public ActionResult subgoodedit() { int id = Context.GetRequestInt("id", 0); int subid = Context.GetRequestInt("subid", 0); if (id <= 0 || subid <= 0) { return(View("PageError", new Return_Msg() { Msg = "参数错误!", code = "500" })); } EntGoods entModelOld = EntGoodsBLL.SingleModel.GetModel(id); if (entModelOld == null || entModelOld.state == 0 || entModelOld.tag == 0) { return(View("PageError", new Return_Msg() { Msg = "总店产品不可用!", code = "500" })); } SubStoreEntGoods subModel = SubStoreEntGoodsBLL.SingleModel.GetModel(subid); if (subModel == null || subModel.SubState == 0) { if (subModel.SubTag == 1) { return(View("PageError", new Return_Msg() { Msg = "下架后才可以编辑!", code = "500" })); } return(View("PageError", new Return_Msg() { Msg = "产品不可用!", code = "500" })); } entModelOld.specificationdetail = subModel.SubSpecificationdetail; entModelOld.stock = subModel.SubStock; entModelOld.sort = subModel.SubSort; //拼团 if (entModelOld.goodtype == (int)EntGoodsType.拼团产品) { EntGroupsRelation group = EntGroupsRelationBLL.SingleModel.GetModelByGroupGoodType(entModelOld.id, entModelOld.aid); if (group == null) { return(View("PageError", new Return_Msg() { Msg = "拼团不可编辑!", code = "500" })); } entModelOld.EntGroups = group; } return(View(entModelOld)); }
public ActionResult GetGoodInfo() { returnObj = new Return_Msg_APP(); returnObj.isok = false; int goodid = Context.GetRequestInt("goodid", 0); int storeId = Context.GetRequestInt("storeId", 0); int aid = Context.GetRequestInt("aid", 0); if (goodid == 0 || storeId < 0 || (storeId > 0 && aid == 0)) { returnObj.Msg = "非法请求"; return(Json(returnObj, JsonRequestBehavior.AllowGet)); } int xtype = _xcxAppAccountRelationBLL.GetXcxTemplateType(aid); if (xtype == 0) { returnObj.Msg = "小程序没授权"; return(Json(returnObj, JsonRequestBehavior.AllowGet)); } EntGroupsRelation relationmodel = EntGroupsRelationBLL.SingleModel.GetModelByGroupGoodType(goodid, aid, storeId); if (relationmodel == null) { returnObj.Msg = "该拼团已不存在"; return(Json(returnObj, JsonRequestBehavior.AllowGet)); } //已团数量 int groupnum = 0; List <object> userlist = EntGroupSponsorBLL.SingleModel.GetGoupsUserImgs(relationmodel.Id, ref groupnum, xtype, relationmodel.EntGoodsId); List <EntGroupSponsor> groupSponsorList = EntGroupSponsorBLL.SingleModel.GetHaveSuccessGroup(relationmodel.Id, 10, goodid); switch (xtype) { case (int)TmpType.小程序专业模板: break; case (int)TmpType.小程序多门店模板: EntGoods goodModel = EntGoodsBLL.SingleModel.GetModel(goodid); if (goodModel == null || goodModel.state == 0) { returnObj.Msg = "产品不存在或已删除"; return(Json(returnObj, JsonRequestBehavior.AllowGet)); } if (storeId > 0) { SubStoreEntGoods subGood = SubStoreEntGoodsBLL.SingleModel.GetModelByAppIdStoreIdGoodsId(aid, storeId, goodid); if (subGood == null) { returnObj.Msg = "产品不存在或已下架"; return(Json(returnObj, JsonRequestBehavior.AllowGet)); } goodModel.specificationdetail = subGood.SubSpecificationdetail; goodModel.stock = subGood.SubStock; } if (!string.IsNullOrEmpty(goodModel.plabels)) { goodModel.plabelstr = EntGoodsBLL.SingleModel.GetPlabelStr(goodModel.plabels); goodModel.plabelstr_array = goodModel.plabelstr.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList(); } goodModel.EntGroups.GroupUserList = userlist; goodModel.EntGroups.GroupsNum = groupnum; goodModel.EntGroups.GroupSponsorList = groupSponsorList; returnObj.dataObj = goodModel; break; } returnObj.isok = true; return(Json(returnObj, JsonRequestBehavior.AllowGet)); }
public ActionResult subgoodedit(int appId, EntGoods model) { string act = Context.GetRequest("act", ""); int storeId = Context.GetRequestInt("storeId", 0); int subid = Context.GetRequestInt("subid", 0); int pid = Context.GetRequestInt("id", 0); if (act == "batch") { int actval = Context.GetRequestInt("actval", -1); if (actval < 0 || storeId < 0) { return(Json(new { isok = true, msg = "非法参数" })); } string ids = Context.GetRequest("ids", string.Empty); if (string.IsNullOrEmpty(ids)) { return(Json(new { isok = true, msg = "请先选择产品" })); } string sql = $"update substoreentgoods set SubTag=@tag where StoreId={storeId} and find_in_set(id,@ids)>0"; SqlMySql.ExecuteTransaction(EntGoodsBLL.SingleModel.connName, sql, CommandType.Text, new MySqlParameter[] { new MySqlParameter("@ids", ids), new MySqlParameter("@tag", actval) }); return(Json(new { isok = true, msg = "设置成功" })); } else if (act == "del") { SubStoreEntGoods subModel = SubStoreEntGoodsBLL.SingleModel.GetModel(subid); if (subModel == null) { return(Json(new { isok = false, msg = "产品不存在" })); } subModel.SubState = 0; var TranModel = new TransactionModel(); TranModel.Add(SubStoreEntGoodsBLL.SingleModel.BuildUpdateSql(subModel, "SubState")); bool result = SubStoreEntGoodsBLL.SingleModel.ExecuteTransactionDataCorect(TranModel.sqlArray, TranModel.ParameterArray); return(Json(new { isok = result, msg = "删除" + (result ? "成功" : "失败") })); } else if (act == "tag") { int tag = Context.GetRequestInt("tag", -1); if (pid <= 0 || tag < 0) { return(Json(new { isok = false, msg = "参数错误" })); } SubStoreEntGoods subModel = SubStoreEntGoodsBLL.SingleModel.GetModel(subid); if (subModel == null || subModel.SubState == 0) { return(Json(new { isok = false, msg = "产品不存在或已删除" })); } EntGoods entGood = EntGoodsBLL.SingleModel.GetModel(pid); if (entGood == null || entGood.state == 0) { return(Json(new { isok = false, msg = "总店产品不存在或已删除" })); } if (tag != -1) { //如果总店产品下架,分店下架的产品不能再上架 if (entGood.tag == 0 && subModel.SubTag == 0 && tag == 1) { return(Json(new { isok = false, msg = "总店产品已下架,分店产品不能再上架" })); } subModel.SubTag = tag; var TranModel = new TransactionModel(); TranModel.Add(SubStoreEntGoodsBLL.SingleModel.BuildUpdateSql(subModel, "SubTag")); string actionName = (tag == 0 ? "下架" : "上架"); bool result = SubStoreEntGoodsBLL.SingleModel.ExecuteTransactionDataCorect(TranModel.sqlArray, TranModel.ParameterArray); return(Json(new { isok = result, msg = actionName + (result ? "成功" : "失败") })); } return(Json(new { isok = false, msg = "操作失败!" })); } else if (act == "edit") { SubStoreEntGoods subModel = SubStoreEntGoodsBLL.SingleModel.GetModel(subid); if (subModel == null || subModel.SubState == 0) { return(Json(new { isok = true, msg = "产品不可用" })); } EntGoods entModelOld = EntGoodsBLL.SingleModel.GetModel(model.id); if (entModelOld == null || entModelOld.state == 0 || entModelOld.tag == 0) { return(Json(new { isok = true, msg = "总店产品不可用" })); } var TranModel = new TransactionModel(); TranModel.Add(EntGoodsBLL.SingleModel.GetSyncSql(entModelOld, model, subModel)); bool reault = SubStoreEntGoodsBLL.SingleModel.ExecuteTransactionDataCorect(TranModel.sqlArray, TranModel.ParameterArray); if (reault) { return(Json(new { isok = true, msg = "修改成功" })); } } return(Json(new { isok = false, msg = "操作失败" })); }
/// <summary> /// 添加门店产品 /// </summary> /// <param name="appId"></param> /// <param name="storeId"></param> /// <returns></returns> public ActionResult AddStoreProduct(int appId = 0, int storeId = 0) { string ids = Context.GetRequest("ids", string.Empty); if (appId == 0 || storeId == 0 || ids == "") { return(Json(new { isok = false, msg = "非法请求" })); } string[] idsArray = ids.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (idsArray.Length <= 0) { return(Json(new { isok = false, msg = "请选择要添加的产品" })); } SubStoreEntGoods subGoodsModel; List <string> addSqlList = new List <string>(); foreach (string id in idsArray) { int pid = 0; if (int.TryParse(id, out pid)) { EntGoods goodModel = EntGoodsBLL.SingleModel.GetModel(pid); if (goodModel != null && !SubStoreEntGoodsBLL.SingleModel.Exists($"pid={pid} and aid={appId} and storeid={storeId} and SubState=1")) { subGoodsModel = new SubStoreEntGoods() { Aid = goodModel.aid, Pid = goodModel.id, StoreId = storeId, SubSpecificationdetail = goodModel.specificationdetail, SubState = 1, SubTag = 1, SubsalesCount = 0, SubStock = goodModel.stock, }; addSqlList.Add(SubStoreEntGoodsBLL.SingleModel.BuildAddSql(subGoodsModel)); #region 拼团 if (goodModel.goodtype == (int)EntGoodsType.拼团产品) { EntGroupsRelation entgroups = EntGroupsRelationBLL.SingleModel.GetModelByGroupGoodType(goodModel.id, goodModel.aid); if (entgroups == null) { return(Json(new { isok = false, msg = "团商品已失效!" })); } entgroups.AddTime = DateTime.Now; entgroups.RId = goodModel.aid; entgroups.EntGoodsId = goodModel.id;//占位 entgroups.StoreId = storeId; string addsql = EntGroupsRelationBLL.SingleModel.BuildAddSql(entgroups); //获取最新插入的多门店产品ID //addsql = addsql.Replace("-9999", "(select last_insert_id())"); //log4net.LogHelper.WriteInfo(this.GetType(),addsql); addSqlList.Add(addsql); } #endregion } } } if (SubStoreEntGoodsBLL.SingleModel.ExecuteTransaction(addSqlList.ToArray())) { return(Json(new { isok = true, msg = $"选择{idsArray.Length}个产品,添加成功{addSqlList.Count}个" })); } else { return(Json(new { isok = false, msg = "添加失败!" })); } }