/// <summary> /// 新增 /// </summary> /// <param name="model"></param> /// <returns></returns> public string Add(Musercoupon model) { MwxResult mwxResult = new MwxResult() { errcode = -1 }; try { DateTime dateTimeNow = System.DateTime.Now; model.isDelete = "0"; model.isEffective = "1"; model.great_time = dateTimeNow; model.modify_time = dateTimeNow; model.id = PublicTools.GetRandomNumberByTime(); if (new UserCouponService().Add(model)) { mwxResult.errcode = 0; mwxResult.errmsg = "操作成功!"; } else { mwxResult.errmsg = "操作失败!"; } } catch (Exception ex) { mwxResult.errmsg = "操作失败!"; } return(JsonHelper.GetJson <MwxResult>(mwxResult)); }
/// <summary> /// 新增文章 /// </summary> /// <param name="model"></param> /// <returns></returns> public string AddNews(Mnews model, HttpPostedFileBase productimgurl = null, string path = "", int type = 1) { MwxResult mwxResult = new MwxResult() { errcode = -1 }; string savePath = string.Empty; //// 存图片 if (productimgurl != null) { string fileSave = FileOpert.UploadImg(productimgurl, path + "uploadFile\\" + System.DateTime.Now.ToString("yyyy") + "\\", out savePath); if (string.IsNullOrEmpty(fileSave)) { model.img = savePath.Replace(path, ""); } } try { if (string.IsNullOrEmpty(model.id)) { DateTime dateTimeNow = System.DateTime.Now; model.isDelete = "0"; model.isEffective = "1"; model.great_time = dateTimeNow; model.modify_time = dateTimeNow; model.type = type; model.id = PublicTools.GetRandomNumberByTime(); if (new NewsService().AddNews(model)) { mwxResult.errcode = 0; mwxResult.errmsg = "操作成功!"; } else { mwxResult.errmsg = "操作失败!"; } } else { if (new NewsService().UpdateNews(model)) { mwxResult.errcode = 0; mwxResult.errmsg = "操作成功!"; } else { mwxResult.errmsg = "操作失败!"; } } } catch (Exception ex) { mwxResult.errmsg = "操作失败!"; } return(JsonHelper.GetJson <MwxResult>(mwxResult)); }
/// <summary> /// 新增产品 /// </summary> /// <param name="mproduct"></param> /// <param name="productimgurl"></param> /// <param name="path"></param> /// <returns></returns> public string AddProduct(Mproduct mproduct, HttpPostedFileBase productimgurl, string path) { MwxResult mwxResult = new MwxResult() { errcode = -1 }; //// 实现步骤 //// 1.数据合法性验证 //// 2.图片入库 //// 3.数据落地 string savePath = string.Empty; mwxResult.errmsg = this.CheckedProduct(mproduct); if (productimgurl == null) { mwxResult.errmsg = "产品图片不能为空!"; return(JsonHelper.GetJson <MwxResult>(mwxResult)); } if (!string.IsNullOrEmpty(mwxResult.errmsg)) { return(JsonHelper.GetJson <MwxResult>(mwxResult)); } //// 存图片 string fileSave = FileOpert.UploadImg(productimgurl, path + "uploadFile\\" + System.DateTime.Now.ToString("yyyy") + "\\", out savePath); if (string.IsNullOrEmpty(fileSave)) { mproduct.productimgurl = savePath.Replace(path, ""); } else { //// 构建错误信息并返回 mwxResult.errmsg = fileSave; return(JsonHelper.GetJson <MwxResult>(mwxResult)); } mproduct.productid = PublicTools.GetRandomNumberByTime(); ///// 入库 bool addResult = new ProductService().AddProduct(mproduct); if (addResult) { mwxResult.errmsg = "新增成功!"; mwxResult.errcode = 0; CacheData.allRecommendPro = null; CacheData.allRecommendProList = null; } else { mwxResult.errmsg = "新增失败!"; } return(JsonHelper.GetJson <MwxResult>(mwxResult)); }
/// <summary> /// 检查订单数据的合法性 /// </summary> /// <param name="model"></param> /// <returns></returns> private string CheckOrderInfro(List <Morder> model) { //// 移除购买数量小于1的产品 if (model == null) { model.RemoveAll(P => P.buyNum < 1); } if (model == null || model.Count < 1) { return("请选中需要购买的产品!"); } if (model.Exists(p => string.IsNullOrEmpty(p.productId))) { return("产品信息有误,请重新下单!"); } if (model.Exists(p => string.IsNullOrEmpty(p.userId))) { return("数据信息有误,请重新下单!"); } if (model.Exists(p => p.buyNum < 1)) { return("所购买的产品数量必须大于0,请重新下单!"); } if (model.Exists(p => p.sellPrice <= 0)) { return("产品价格有误,请重新下单!"); } //// 初始化订单数据 //// 生成主订单号 DateTime dateTimeNow = System.DateTime.Now; string orderGroupId = PublicTools.GetRandomNumberByTime(); model.ForEach(c => { c.orderid = PublicTools.GetRandomNumberByTime(); c.orderGroupId = orderGroupId; c.payType = 1; c.payTypeDesc = "货到付款"; c.orderState = 4; c.orderStateDesc = "下单成功,等待送货"; c.isDelete = "0"; c.isEffective = "1"; c.great_time = dateTimeNow; c.modify_time = dateTimeNow; }); return(string.Empty); }
/// <summary> /// 新增地址 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool AddMailAddress(MmailAddress model) { try { model.isDefault = "1"; model.addressId = PublicTools.GetRandomNumberByTime(); return(opertService.AddMailAddress(model)); } catch (Exception ex) { return(false); } }
/// <summary> /// 新增平台用户 /// </summary> /// <param name="madminuser"></param> /// <returns></returns> public string AddUserMeth(MsendGoodsUser model) { MwxResult mwxResult = new MwxResult() { errcode = -1 }; try { //// 数据合法性检查 string checkAdminUser = this.CheckSendUser(model); if (!string.IsNullOrEmpty(checkAdminUser)) { mwxResult.errmsg = checkAdminUser; } bool doResult = false; if (string.IsNullOrEmpty(model.id)) { //// 时间相关参数赋值 model.great_time = System.DateTime.Now; model.modify_time = model.great_time; model.id = PublicTools.GetRandomNumberByTime(); doResult = new SndGoodsUserService().AddSndGoodsUser(model); } else { doResult = new SndGoodsUserService().ChangSndGoodsUserInfor(model); } //// 数据落地入库 if (!doResult) { mwxResult.errmsg = "操作失败"; } else { mwxResult.errcode = 0; mwxResult.errmsg = "操作成功"; } } catch (Exception ex) { mwxResult.errmsg = "操作失败:系统异常!"; } return(JsonHelper.GetJson <MwxResult>(mwxResult)); }
/// <summary> /// 根据code获取用户信息 /// </summary> /// <param name="code"></param> /// <returns></returns> public MWXUserInfo GetWXUserInfoByOpenid(string openid) { //// 实现逻辑步骤 //// 1、根据openid 到数据库中查询用户数据信息 //// 2、如果数据库未查询到数据信息,那么根据openid到微信查询对应的用户信息 //// 3、对步骤5获取的用户数据信息入库 //// 4、返回最终查询到的用户信息对象 //// 用户信息模型 MWXUserInfo model = null; if (!string.IsNullOrEmpty(openid)) { //// 1、根据openid 到数据库中查询用户数据信息 model = new WXuserService().GetWXUserInfoByOpenid(openid); if (model == null) { //// 2、如果数据库未查询到数据信息,那么根据openid到微信查询对应的用户信息 model = new WXApiOpert().GetUserInfo(openid); if (model != null) { model.great_time = System.DateTime.Now; model.modify_time = System.DateTime.Now; } //// LogOpert.AddWeiXinMessage("微信中根据openid获取到的用户信息为:" + JsonHelper.GetJson<MWXUserInfo>(model)); if (model != null) { //// 3、对步骤5获取的用户数据信息入库 异步入库 AddWXUser handler = new AddWXUser(new WXuserService().AddWXuser); model.wxuserid = PublicTools.GetRandomNumberByTime(); handler.BeginInvoke(model, null, null); //// LogOpert.AddWeiXinMessage("用户信息异步数据入库:" + JsonHelper.GetJson<MWXUserInfo>(model)); } } else { //// LogOpert.AddWeiXinMessage("数据库中根据openid获取到的用户信息为:" + JsonHelper.GetJson<MWXUserInfo>(model)); } } //// 4、返回最终查询到的用户信息对象 return(model); }
/// <summary> /// 新增平台用户 /// </summary> /// <param name="madminuser"></param> /// <returns></returns> public string AddUserMeth(Madminuser madminuser) { MwxResult mwxResult = new MwxResult() { errcode = -1 }; try { //// 数据合法性检查 string checkAdminUser = this.CheckAdminUser(madminuser); if (!string.IsNullOrEmpty(checkAdminUser)) { mwxResult.errmsg = checkAdminUser; } //// 时间相关参数赋值 madminuser.great_time = System.DateTime.Now; madminuser.modify_time = madminuser.great_time; madminuser.adminuserid = PublicTools.GetRandomNumberByTime(); madminuser.isEffective = 1; madminuser.password = PublicTools.MD5CryptoService(madminuser.password); //// 数据落地入库 if (!new AdminuserService().AddAdminUser(madminuser)) { mwxResult.errmsg = "操作失败"; } else { mwxResult.errcode = 0; mwxResult.errmsg = "操作成功"; } } catch (Exception ex) { mwxResult.errmsg = "操作失败:系统异常!"; } return(JsonHelper.GetJson <MwxResult>(mwxResult)); }
/// <summary> /// 新增平台用户 /// </summary> /// <param name="model"></param> /// <returns></returns> public string Add(MTFCEvidenceInfor model) { MwxResult mwxResult = new MwxResult() { errcode = -1 }; try { //// 数据合法性检查 string checkResult = this.CheckAddInfor(model); if (!string.IsNullOrEmpty(checkResult)) { mwxResult.errmsg = checkResult; } else { //// 时间相关参数赋值 model.great_time = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); model.Id = PublicTools.GetRandomNumberByTime(); //// 数据落地入库 if (!new TFCEvidenceInforService().Add(model)) { mwxResult.errmsg = "提交失败"; } else { mwxResult.errcode = 0; mwxResult.errmsg = "提交成功"; } } } catch (Exception) { mwxResult.errmsg = "提交失败:系统异常!"; } return(JsonHelper.GetJson <MwxResult>(mwxResult)); }
/// <summary> /// 新增微信菜单 /// </summary> /// <param name="model"></param> /// <returns></returns> public string AddWxmenu(Mwxmenu model) { MwxResult mwxResult = new MwxResult() { errcode = -1 }; try { //// 时间相关参数赋值 model.url = string.IsNullOrEmpty(model.url) ? "" : model.url; model.id = PublicTools.GetRandomNumberByTime(); model.type = "view"; model.great_time = System.DateTime.Now; model.modify_time = model.great_time; model.isDelete = 0; model.isEffective = 1; if (model.superId == "0") { model.superId = ""; } //// 数据落地入库 if (!new WxmenuService().AddWxmenu(model)) { mwxResult.errmsg = "操作失败"; } else { mwxResult.errcode = 0; mwxResult.errmsg = "操作成功"; } } catch (Exception ex) { mwxResult.errmsg = "操作失败:系统异常!"; } return(JsonHelper.GetJson <MwxResult>(mwxResult)); }
/// <summary> /// 加入到购物车 /// </summary> /// <param name="model"></param> /// <returns></returns> public string AddShopCart(MshoppingCart model) { MwxResult mwxResult = new MwxResult() { errcode = -1 }; try { bool addResult = true; ShoppingCartService opert = new ShoppingCartService(); //// 补全产品信息 Mproduct product = new ProductBus().GetProductById(model.productId); if (product == null || string.IsNullOrEmpty(product.productid)) { addResult = false; } else { string productformatunit = product.productformatunit == "0" ? "个" : product.productformatunit == "1" ? "袋" : product.productformatunit == "2" ? "斤" : product.productformatunit == "3" ? "瓶" : product.productformatunit == "4" ? "升" : product.productformatunit == "5" ? "听" : product.productformatunit == "4" ? "升" : product.productformatunit == "6" ? "件" : product.productformatunit == "7" ? "盒" : product.productformatunit == "8" ? "包" : product.productformatunit == "9" ? "提" : "双"; model.origPrice = product.origprice; model.productformat = $"{product.productformat}/{productformatunit}"; model.productname = product.productname; model.sellPrice = product.sellprice; //// 首先根据产id和用户 ID获取一次购物车信息 MshoppingCart shopCartModel = opert.GetShoppingCartListByUserIdAndProductId(model.userId, model.productId); if (model.buyNum > 0) { ///// 加购物车 if (shopCartModel != null && !string.IsNullOrEmpty(shopCartModel.shoppingCartId)) { ///// 数量加1 addResult = opert.UpdatePriceAndNum(shopCartModel.shoppingCartId, model.userId, model.origPrice, model.sellPrice, model.totalPrice + (model.sellPrice * model.buyNum), model.buyNum); } else { //// 新增 model.shoppingCartId = PublicTools.GetRandomNumberByTime(); addResult = opert.Add(model); } } else { //// 减购物车 if (shopCartModel != null && !string.IsNullOrEmpty(shopCartModel.shoppingCartId)) { if (shopCartModel.buyNum <= (-model.buyNum)) { //// 直接删除 addResult = opert.DeleteShoppingCartById(shopCartModel.shoppingCartId, shopCartModel.userId); } else { ///// 数量减1 addResult = opert.UpdatePriceAndNum(shopCartModel.shoppingCartId, model.userId, model.origPrice, model.sellPrice, model.totalPrice + shopCartModel.totalPrice, model.buyNum); } } } } if (addResult) { mwxResult.errmsg = "操作成功!"; mwxResult.errcode = 0; } else { mwxResult.errmsg = "操作失败!"; } } catch (Exception ex) { mwxResult.errmsg = "操作失败!"; LogOpert.AddWeiXinMessage("系统异常:" + ex.Message); } return(JsonHelper.GetJson <MwxResult>(mwxResult)); }