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 TestGetRedPack(string openid = "0") { //RedPack.CreateRedPack(2,"2018-08") ; //var a = RedPack.GetMoneys(); //var a = RedPack.GetMoneys2(); string nowday = DateTime.Now.ToString("yyyy-MM-dd"); string nowmonth = DateTime.Now.ToString("yyyy-MM"); if (string.IsNullOrEmpty(openid)) { for (int s = 51; s <= 52; s++) { openid = "xjy" + s.ToString(); for (int i = 1; i <= 10; i++) { string sql = string.Format("SELECT COUNT(1) FROM RedPackScanRecord WHERE OpenId ='{0}' AND CONVERT(VARCHAR(10),ScanDate,121) = '{1}' ", openid, nowday); int nowdayscan = SqlHelper2.GetCount(CommandType.Text, sql); var money = RedPack.GetMoney(nowdayscan, openid, nowmonth); //增加扫描红包记录 sql = string.Format(@"INSERT INTO dbo.RedPackScanRecord ( OpenId ,Money ,ScanCode ,IsPay ,PayId,IsFirst,ScanMonth) VALUES ( '{0}' , -- OpenId - varchar(50) {1} , -- Money - float '{2}' , -- ScanCode - varchar(50) 0 , -- IsPay - int 0 , -- PayId - int {4},'{3}') ; ", openid, money, "", nowmonth, nowdayscan == 0 ? 1 : 0); SqlHelper2.ExecuteNonQuery(CommandType.Text, sql); } } } else { string sql = string.Format("SELECT COUNT(1) FROM RedPackScanRecord WHERE OpenId ='{0}' AND CONVERT(VARCHAR(10),ScanDate,121) = '{1}' ", openid, nowday); int nowdayscan = SqlHelper2.GetCount(CommandType.Text, sql); var money = RedPack.GetMoney(nowdayscan, openid, nowmonth); //增加扫描红包记录 sql = string.Format(@"INSERT INTO dbo.RedPackScanRecord ( OpenId ,Money ,ScanCode ,IsPay ,PayId,IsFirst,ScanMonth) VALUES ( '{0}' , -- OpenId - varchar(50) {1} , -- Money - float '{2}' , -- ScanCode - varchar(50) 0 , -- IsPay - int 0 , -- PayId - int {4},'{3}') ; ", openid, money, "", nowmonth, nowdayscan == 0 ? 1 : 0); SqlHelper2.ExecuteNonQuery(CommandType.Text, sql); } return(""); }
public string AddLiuYanInfo(dynamic requestData) { LogHelper.WriteMsgByDay("WeiXinController-AddLiuYanInfo-log:" + requestData.ToString()); string keyType = requestData.KeyType; string keyId = requestData.KeyId; string parentId = requestData.ParentId; string liuYan = requestData.LiuYan; string openId = requestData.OpenId; if (string.IsNullOrEmpty(openId) || string.IsNullOrEmpty(liuYan) || string.IsNullOrEmpty(keyId) || string.IsNullOrEmpty(keyType)) { return("参数不能为空"); } else { string sql = string.Format(@"INSERT INTO dbo.CpkLiuYan ( ParentId ,KeyId ,KeyType ,OpenId , LiuYan ) VALUES ({0},{1},'{2}','{3}','{4}')", parentId, keyId, keyType, openId, liuYan); SqlHelper2.ExecuteNonQuery(CommandType.Text, sql); return("succ"); } }
public string CreateOrEdit(dynamic requestData) { LogHelper.WriteMsgByDay("ZhuanTiController-CreateOrEdit-log:" + requestData.ToString()); ReturnJson r = new ReturnJson(); int zhuantiid = requestData.ZhuanTiId; //专题id,新建时为0,编辑时为实际id string action = requestData.Action; //接口类型 分Create Edit string zhuantiname = requestData.ZhuanTiName; //专题名称 var contentList = requestData.ContentList; //专题内容列表 if (string.IsNullOrEmpty(zhuantiname)) { r.message = "专题名称不能为空"; } else if (zhuantiname.Length > 14) { zhuantiname = zhuantiname.Substring(0, 14); } else { string sql = ""; sql = string.Format("SELECT 1 FROM dbo.CpkZhuanTi WHERE ZhuanTiName = '{0}' ", zhuantiname); int c = dataContext.GetCount(CommandType.Text, sql); if (action == "Create") { if (c > 0) //判断是否存在 { r.message = "该专题名称已存在"; } } else { if (c > 1) //判断是否存在 { r.message = "该专题名称已存在"; } } if (string.IsNullOrEmpty(r.message)) //以上验证都通过时 { //现将该专题已存在的内容及菜品关系 逻辑删除 sql = string.Format(@"UPDATE dbo.CpkZhuanTiContent SET IsEnable = 0 WHERE ZhuanTiId ={0}", zhuantiid); SqlHelper2.ExecuteNonQuery(CommandType.Text, sql); foreach (var item in contentList) //循环内容列表 { string content = item["Content"].ToString().Replace("\"", "'"); //富文本内容 string caiPinId = item["CaiPinId"]; //内容关联的菜品 //LogHelper.WriteMsgByDay("CaiPinController-content-log:" + content); if (content.IndexOf("base64") > 0) { foreach (string a in ImageHandle.GetHtmlImageUrlList(content)) { //LogHelper.WriteMsgByDay("CaiPinController-string a-log:" + a); //LogHelper.WriteMsgByDay("CaiPinController-Common.ImageHandle.DNS-log:" + Common.ImageHandle.DNS); if (a.IndexOf(Common.ImageHandle.DNS) < 0) { string[] asplit = a.Split(','); //LogHelper.WriteMsgByDay("CaiPinController-asplit-log:" + asplit.ToString()); string imgtype = asplit[0].Substring(11, asplit[0].Length - 18); //LogHelper.WriteMsgByDay("CaiPinController-imgtype-log:" + imgtype); string filepath = Common.ImageHandle.Base64StringToImage(asplit[1], imgtype, "/Images"); content = content.Replace(a, filepath); } } } //新增编辑都是如下逻辑,因为编辑时上面已逻辑删除之前的内容 //新增专题基本信息 CpkZhuanTi m = new CpkZhuanTi(); m.ZhuanTiId = zhuantiid; m.ZhuanTiName = zhuantiname; m.UpdateDate = DateTime.Now; db.CpkZhuanTi.AddOrUpdate(m); //根据zhuantiid新增或者编辑 db.SaveChanges(); zhuantiid = m.ZhuanTiId; //新增专题内容 CpkZhuanTiContent mContent = new CpkZhuanTiContent(); mContent.ZtContentId = 0; mContent.ZhuanTiId = zhuantiid; mContent.Content = content; db.CpkZhuanTiContent.AddOrUpdate(mContent); db.SaveChanges(); // sql = string.Format(@"INSERT INTO dbo.CpkZhuanTiContent // ( ZhuanTiId , Content) // VALUES ( {0} , '{1}' ); select SCOPE_IDENTITY() ", zhuantiid, content); // int ztContentId = Convert.ToInt32(SqlHelper2.ExecuteScalar(CommandType.Text, sql)); int ztContentId = mContent.ZtContentId; //新增专题内容关联的菜品 sql = string.Format(@"INSERT INTO dbo.CpkCpZtContentRelation ( ZtContentId , CaiPinId ) SELECT {0},CaiPinId FROM dbo.CpkCaiPinBasicInfo WHERE CaiPinId IN ({1}); DELETE FROM dbo.CpkZhuanTiContent WHERE ZhuanTiId ={2} AND IsEnable = 0 ", ztContentId, caiPinId, zhuantiid); SqlHelper2.ExecuteNonQuery(CommandType.Text, sql); } r.status = "succ"; r.message = action + "成功"; } } return(JsonConvert.SerializeObject(r)); }
public async Task <string> ScanPressureTest(dynamic requestData) { RScanJson r = new RScanJson(); string kaiGuan = ConfigurationManager.AppSettings["kaiguan"]; //if (kaiGuan == "ON") //{ string openid = requestData.OpenId; string scode = requestData.Scode; try { if (string.IsNullOrEmpty(openid) || string.IsNullOrEmpty(scode)) { r.message = "参数有误"; } else { #region 1.判断是否注册,是否是队员 int isRegist = RedPack.GetIsRegist(openid); if (isRegist == 1) { r.isRegist = 1; } else if (isRegist == -1) //表示是队员 返回 { r.isRegist = 0; r.message = "队员不能扫码"; return(JsonConvert.SerializeObject(r)); } #endregion #region 2.获取用户扫描但是未提现的金额总和 string sql = ""; sql = string.Format(@"SELECT ISNULL(SUM(Money),0) Total FROM dbo.RedPackScanRecord WHERE OpenId = '{0}' AND IsPay = 0 ", openid); r.kTxMoney = Convert.ToDouble(SqlHelper2.ExecuteScalar(CommandType.Text, sql)); if (r.kTxMoney > 1) { r.isKeTiXian = 1; } #endregion //当天 string nowDay = DateTime.Now.ToString("yyyy-MM-dd"); //当月 string nowMonth = DateTime.Now.ToString("yyyy-MM"); //string a = CheckRule(openid, scode); //验证二维码是否有效 sql = string.Format(@"SELECT a.IsScan,b.Money,convert(varchar(19),b.ScanDate,121) ScanDate FROM dbo.RedPackCode a LEFT JOIN dbo.RedPackScanRecord b ON a.Code=b.ScanCode WHERE a.Code = '{0}' ", scode); DataTable dt = SqlHelper2.ExecuteDataTable(sql); if (dt.Rows.Count == 0) { r.code_status = "非活动码"; r.message = "此码不属于本次活动"; RedPack.AddAlertLog(openid, scode + ":" + r.message, "scan"); } //配合压测 mark掉 //else if (Convert.ToInt16(dt.Rows[0]["IsScan"]) == 1) //{ // r.code_status = "已被扫"; // r.money = Convert.ToDouble(dt.Rows[0]["Money"]); // r.scan_date = dt.Rows[0]["ScanDate"].ToString(); // r.message = "该二维码已被扫描"; // RedPack.AddAlertLog(openid, scode + ":" + r.message, "scan"); //} else { //验证当天扫描是否超过10次 sql = string.Format("SELECT COUNT(1) FROM RedPackScanRecord WHERE OpenId ='{0}' AND CONVERT(VARCHAR(10),ScanDate,121) = '{1}' ", openid, nowDay); int nowDayScan = SqlHelper2.GetCount(CommandType.Text, sql); if (nowDayScan >= 10) { r.message = "当天扫描是已超过10次"; RedPack.AddAlertLog(openid, r.message, "scan"); } else { sql = string.Format("SELECT COUNT(1) FROM RedPackScanRecord WHERE OpenId ='{0}' ", openid); int allScan = SqlHelper2.GetCount(CommandType.Text, sql); //去抽红包 double money = RedPack.GetMoney(allScan, openid, nowMonth); #region 增加扫描红包记录 sql = string.Format(@"INSERT INTO dbo.RedPackScanRecord ( OpenId ,Money ,ScanCode ,IsPay ,PayId,IsFirst,ScanMonth) VALUES ( '{0}' , -- OpenId - varchar(50) {1} , -- Money - float '{2}' , -- ScanCode - varchar(50) 0 , -- IsPay - int 0 , -- PayId - int {4},'{3}') ; UPDATE dbo.RedPackCode SET IsScan =1,UseDate = GETDATE() WHERE Code = '{2}'; UPDATE dbo.RedPackConfig SET LeiJiMoney = LeiJiMoney + {1} WHERE Month = '{3}' ", openid, money, scode, nowMonth, nowDayScan == 0 ? 1 : 0); LogHelper.WriteMsg("sacn增加扫描红包记录-openid:" + openid + ",sql:" + sql); SqlHelper2.ExecuteNonQuery(CommandType.Text, sql); #endregion r.scan_date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); r.money = money; //返回本次中奖金额 //获取用户扫描但是未提现的金额总和 sql = string.Format(@"SELECT ISNULL(SUM(Money),0) Total FROM dbo.RedPackScanRecord WHERE OpenId = '{0}' AND IsPay = 0 ", openid); r.kTxMoney = Convert.ToDouble(SqlHelper2.ExecuteScalar(CommandType.Text, sql)); if (r.kTxMoney > 1) { r.isKeTiXian = 1; } r.result_status = "succ"; //返回成功状态 } } } } catch (Exception ex) { r.message = "有异常"; RedPack.AddAlertLog(openid, ex.ToString(), "scan-error"); } //} //else //{ // r.message = "活动现处于关闭状态,谢谢~"; //} return(JsonConvert.SerializeObject(r)); }
//-------------------------使用用户创建的事务 public static int ExecuteNonQuery(SqlTransaction trans, string sql, params SqlParameter[] parms) { return(SqlHelper2.ExecuteNonQuery(trans, CommandType.Text, sql, parms)); }
//-------------------------使用用户创建的connection public static int ExecuteNonQuery(SqlConnection conn, string sql, params SqlParameter[] parms) { return(SqlHelper2.ExecuteNonQuery(conn, CommandType.Text, sql, parms)); }
//-------------------------使用用户创建的事务 public static int ExecuteNonQuery(SqlTransaction trans, string procName, params SqlParameter[] parms) { return(SqlHelper2.ExecuteNonQuery(trans, CommandType.StoredProcedure, procName, parms)); }
//-------------------------使用用户创建的connection public static int ExecuteNonQuery(SqlConnection conn, string procName, params SqlParameter[] parms) { return(SqlHelper2.ExecuteNonQuery(conn, CommandType.StoredProcedure, procName, parms)); }