/// <summary> /// 根据卡片类别调用名称和用户名,为用户创建卡片 /// </summary> /// <param name="callindex">卡片类别调用名称</param> /// <param name="username">用户名</param> /// <param name="token">token</param> /// <returns></returns> public int CreateUserCard(string callindex, string username) { BLL.Card cardBll = new BLL.Card(); BLL.CardCategory cardCategoryBll = new BLL.CardCategory(); BLL.UserCard ucBLL = new BLL.UserCard(); BLL.users usersBll = new BLL.users(); var user = usersBll.GetModel(username); var cardCategory = cardCategoryBll.GetModel(callindex); var card = new Model.Card(); card.CardCategoryId = cardCategory.CardCategoryId; card.Code = Common.Utils.GetCheckCode(7); card.CreateDate = DateTime.Now; card.StartDate = DateTime.Now; card.EndDate = card.StartDate.AddDays(double.Parse(cardCategory.Duration.ToString())); int cardId = cardBll.Add(card); var uc = new Model.UserCard(); uc.CardId = cardId; uc.UserId = user.id; uc.CardCategoryId = cardCategory.CardCategoryId; return(ucBLL.Add(uc)); }
public IHttpActionResult PaySuccess(string ordernum, string tradeno) { var result = new PayResult(); if (ordernum.StartsWith("R")) //充值订单 { BLL.user_recharge bll = new BLL.user_recharge(); Model.user_recharge model = bll.GetModel(ordernum); if (model == null) { result.msg = "该订单号不存在"; result.success = false; result.status = 201; } else { if (model.status == 1) { result.msg = "该订单已经支付,请不要重复支付"; result.success = false; result.status = 202; } //订单编号验证通过后执行 bool r = bll.Confirm(ordernum); if (r) { result.msg = "充值成功"; result.status = 200; result.success = true; } else { result.msg = "充值订单信息更新失败"; result.status = 204; result.success = false; } } } else if (ordernum.StartsWith("B")) { BLL.orders bll = new BLL.orders(); Model.orders model = bll.GetModel(ordernum); if (model == null) { result.msg = "该订单号不存在"; result.success = false; result.status = 201; } else { if (model.payment_status == 2) //已付款 { result.msg = "该订单已经支付,请不要重复支付"; result.success = false; result.status = 202; } //订单编号验证通过后执行 bool r = bll.UpdateField(ordernum, "trade_no='" + tradeno + "',status=2,payment_status=2,payment_time='" + DateTime.Now + "'"); if (r) { var articlebll = new BLL.article(); foreach (var g in model.order_goods) { //判断是否有卡片商品,如果有卡片商品,添加卡片和用户卡片 //todo:此处需要增加事务性操作 if (articlebll.IsCard(g.article_id)) { var article = articlebll.GetModel(g.article_id); string callindex = article.fields["cardcategorycallindex"]; var user = new BLL.users().GetModel(model.user_name); var cardcategory = new BLL.CardCategory().GetModel(callindex); var card = new Model.Card(); card.CardCategoryId = cardcategory.CardCategoryId; card.Code = Utils.GetCheckCode(7); card.CreateDate = DateTime.Now; card.StartDate = DateTime.Now; card.EndDate = DateTime.Now.AddDays((double)cardcategory.Duration); var cardBll = new BLL.Card(); int cardId = cardBll.Add(card); var usercardBll = new BLL.UserCard(); var usercard = new Model.UserCard(); usercard.CardId = cardId; usercard.CardCategoryId = cardcategory.CardCategoryId; usercard.UserId = user.id; usercardBll.Add(usercard); } } result.msg = "支付成功"; result.status = 200; result.success = true; } else { result.msg = "商品订单信息更新失败"; result.status = 204; result.success = false; } } } else { result.msg = "订单号不正确"; result.success = false; result.status = 203; } return(Ok(result)); }