public string CreateVisitor(dynamic requestData) { RJson r = new RJson(); string telephone = requestData.Phone; string openid = requestData.OpenId; string jobType = requestData.JobType; if (string.IsNullOrEmpty(telephone) || string.IsNullOrEmpty(openid) || string.IsNullOrEmpty(jobType)) { r.message = "参数不能为空"; return(JsonConvert.SerializeObject(r)); } try { RegistMember member = new RegistMember(); member.MemberTelePhone = telephone; member.MemberState = 1; member.RegistDate = DateTime.Now; member.TotalIntegral = 0; member.LeaveIntegral = 0; member.IsEnable = 0; member.Remark = requestData.Remark; db.RegistMember.Add(member); db.SaveChanges(); #region 存入用户OpenId OpenIdAssociated openbase = new OpenIdAssociated(); openbase.OpenId = requestData.OpenId; openbase.UserId = member.MemberId; openbase.UserType = 2; openbase.Nickname = requestData.Nickname; openbase.HeadImgUrl = requestData.HeadImgUrl; openbase.CreateDate = DateTime.Now; db.OpenIdAssociated.Add(openbase); db.SaveChanges(); #endregion //当新增完会员之后 在会员简历表里同步新增一条数据 var sql = string.Format(@"INSERT INTO MemberProfile (MemberId ,JobType) VALUES ({0},'{1}') ", member.MemberId, jobType); SqlHelper2.ExecuteNonQuery(CommandType.Text, sql); r.result_status = "succ"; r.data = member.MemberId.ToString(); } catch (Exception ex) { r.message = ex.Message.ToString(); } return(JsonConvert.SerializeObject(r)); }
public string TiXian(dynamic requestData) { RJson r = new RJson(); string openid = requestData.OpenId; try { string kaiguan = ConfigurationManager.AppSettings["kaiguan"]; if (kaiguan == "ON") { if (string.IsNullOrEmpty(openid)) { r.message = "参数错误"; } else { int isRegist = RedPack.GetIsRegist(openid); if (isRegist == 0) { r.message = "您还未注册,注册后方可提现"; } else if (isRegist == -2) //表示是岗位是调味品供货商 的会员 { r.message = "调味品供货商"; } else if (isRegist == -1) //表示是队员 返回 { r.message = "队员不能参与活动"; } else { r = RedPack.PayAction(openid); } } } else { r.message = "活动现处于关闭状态,谢谢~"; } } catch (Exception ex) { r.message = "有异常"; RedPack.AddAlertLog(openid, ex.ToString(), "tixian-error"); } return(JsonConvert.SerializeObject(r)); }
/// <summary> /// 付款操作 /// </summary> /// <param name="openid">微信openid</param> /// <returns></returns> public static RJson PayAction(string openid) { RJson r = new RJson(); //r.message = "test"; //r.result_status = "succ"; //return r; string ids = "0"; //付款ids默认0 int payFlag = 0; //付款未成功 try { //openid = "o_-IA0YU6JgzTvKINab0B30y0L_Y";//我的openid用于测试 //openid = "o11Z-joTwit-1j2QLx_-vAzwsvvQ"; //获取用户扫描但是未提现的金额总和 string sql = string.Format(@"SELECT ISNULL(STUFF((SELECT ','+ CONVERT(VARCHAR(20),Id) FROM dbo.RedPackScanRecord WHERE OpenId = '{0}' AND IsPay = 0 for xml path('')),1,1,''),0) Ids, ISNULL(SUM(Money),0) Total FROM RedPackScanRecord WHERE OpenId = '{0}' AND IsPay = 0", openid); var dt = SqlHelper2.ExecuteDataTable(sql); ids = dt.Rows[0][0].ToString(); double totalTxMoney = Convert.ToDouble(dt.Rows[0][1]); //未提现金额 if (ids == "0") { r.message = "无可提取的额度"; } else if (totalTxMoney < 1) { r.message = "不足一元不能提取成功"; } else { //先置为已提现 sql = string.Format(@"UPDATE dbo.RedPackScanRecord SET IsPay =1 WHERE Id IN ({0})", ids); LogHelper.WriteMsg("先置为已提现-openid:" + openid + ",ids:" + ids); SqlHelper2.ExecuteNonQuery(CommandType.Text, sql); string strPayResult = CorpPay((totalTxMoney * 100).ToString(), openid); //实际付款 LogHelper.WriteMsg("付款结果-openid:" + openid + ",ids:" + ids + ",结果:" + strPayResult); PayResultModel model = XmlHelpler.GetWxPayResult(strPayResult); //付款结果转类 int payid = 0; if (model.result_code == "SUCCESS") //支付成功,增加纪录 { payFlag = 1; sql = string.Format(@"INSERT INTO dbo.RedPackPayRecord ( OpenId , PayAmout , WxResult_Code , WxPartner_Trade_No , WxPayment_No , WxPayment_Time , WxReturnXML , ScanRecordId ) VALUES ( '{0}' , -- OpenId - varchar(50) {1} , -- PayAmout - float '{2}' , '{3}' , '{4}' , '{5}' , '{6}' , '{7}' ); UPDATE dbo.RedPackScanRecord SET IsPay =1 ,PayId = (SELECT scope_identity()) WHERE Id IN ({7}) ", openid, totalTxMoney, model.result_code, model.partner_trade_no, model.payment_no, model.payment_time, strPayResult, ids); LogHelper.WriteMsg("支付成功,增加纪录-openid:" + openid + ",ids:" + ids + ",sql:" + sql); SqlHelper2.ExecuteNonQuery(CommandType.Text, sql); //payid = Convert.ToInt32(SqlHelper2.ExecuteScalar(CommandType.Text, sql)); //sql = string.Format(@"UPDATE dbo.RedPackScanRecord SET IsPay =1 ,PayId = {0} WHERE Id IN ({1})", // payid, ids); //SqlHelper2.ExecuteNonQuery(CommandType.Text, sql); r.message = "提取成功"; r.result_status = "succ"; } else { //付款失败 置为IsPay =0未付款 sql = string.Format(@"UPDATE dbo.RedPackScanRecord SET IsPay =0 WHERE Id IN ({0})", ids); LogHelper.WriteMsg("支付失败,增加纪录-openid:" + openid + ",ids:" + ids + ",sql:" + sql); SqlHelper2.ExecuteNonQuery(CommandType.Text, sql); //支付失败 增加报警信息 AddAlertLog(openid, "红包" + ids + "支付时:" + strPayResult, "pay"); r.message = "提取失败,请联系管理员"; } } //double totalTxMoney = Convert.ToDouble(SqlHelper2.ExecuteScalar(CommandType.Text, sql)); } catch (Exception ex) { //LogHelper.WriteMsg("PayAction异常-openid:" + openid + ",结果:" + ex.ToString());//支付失败 增加报警信息 AddAlertLog(openid, ex.ToString(), "error"); //支付失败 增加报警信息 r.message = "提取失败,请联系管理员"; } return(r); }