/// <summary> /// 用户发起拼团支付 /// </summary> /// <param name="isstart">1开团 2参团</param> /// <param name="gid"></param> /// <param name="uid"></param> /// <returns></returns> public ResultModel PayGroup(int isstart, int gid, int uid, decimal totalfee) { try { using (brnshopEntities context = new brnshopEntities()) { if (isstart == 1) { var groupCount = context.bsp_groups.Where(t => t.startuid == uid & t.groupinfoid == gid).Count(); if (groupCount > 0) { return(ResultModel.Fail("您已参与过该团")); } } else { var groupCount = context.bsp_groupdetails.Where(t => t.uid == uid & t.groupid == gid).Count(); if (groupCount > 0) { return(ResultModel.Fail("您已参与过该团")); } } var user = context.bsp_users.SingleOrDefault(t => t.uid == uid); WXPayHelper wXPayHelper = new WXPayHelper(); var unifiedorderResult = wXPayHelper.unifiedorderForGroup(isstart, gid, uid, "拼团", user.openid, totalfee); if (!unifiedorderResult.Item1) { return(ResultModel.Fail("拼团支付调用微信下单接口失败,详情见日志")); } SortedDictionary <string, object> payDic = unifiedorderResult.Item2 as SortedDictionary <string, object>; var timestamp = WXPayHelper.GetTimeStamp(); string aSign = $@"appId={payDic["appid"]}&nonceStr={payDic["nonce_str"].ToString()}&package=prepay_id={payDic["prepay_id"].ToString()}&signType=MD5&timeStamp={timestamp}&key={WXPayHelper.apisecret}"; WxpayDataForApi model = new WxpayDataForApi(); model.appId = payDic["appid"].ToString(); model.nonceStr = payDic["nonce_str"].ToString(); model.package = $@"prepay_id={payDic["prepay_id"].ToString()}"; model.paySign = EncryptHelp.EncryptMD5(aSign); model.signType = WxPayAPI.WxPayData.SIGN_TYPE_MD5; model.timeStamp = timestamp; return(ResultModel.Success("", model)); } } catch (Exception ex) { Logger._.Error("PayGroup方法,", ex); return(ResultModel.Error(ex.ToString())); } }
/// <summary> /// 用户领用优惠券接口 /// </summary> /// <param name="uid"></param> /// <param name="couponTypeid"></param> public ResultModel RecpientCoupon(int uid, int couponTypeid, bool isFromGroup = false) { using (brnshopEntities context = new brnshopEntities()) { try { var coupontype = context.bsp_coupontypes.SingleOrDefault(t => t.coupontypeid == couponTypeid); var coupon = context.bsp_coupons.SingleOrDefault(t => t.uid == uid && t.coupontypeid == couponTypeid & t.createtime >= coupontype.sendstarttime & t.createtime <= coupontype.sendendtime); if (coupon != null && !isFromGroup) { return(ResultModel.Fail("您已经领取了该优惠券")); } var newcoupon = new bsp_coupons(); newcoupon.uid = uid; newcoupon.activateip = WXPayHelper.GetPublicIp(); newcoupon.activatetime = DateTime.Now; newcoupon.couponsn = WXPayHelper.GetTimeStamp(); newcoupon.coupontypeid = couponTypeid; newcoupon.createip = ""; newcoupon.createoid = 0; newcoupon.createtime = DateTime.Now; newcoupon.createuid = uid; newcoupon.useip = ""; newcoupon.usetime = DateTime.Parse("1997-01-01"); newcoupon.isuse = 0; if (coupontype.useexpiretime == 0) { newcoupon.expiretime = coupontype.useendtime; } else { newcoupon.expiretime = DateTime.Now.AddSeconds(coupontype.useexpiretime); } context.bsp_coupons.Add(newcoupon); context.SaveChanges(); return(ResultModel.Success()); } catch (Exception ex) { Logger._.Error(ex); return(ResultModel.Error()); } } }