| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319 |
- using BizCom;
- using SiteCore.Redis;
- using SQLData;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Data.SqlClient;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Web.Script.Serialization;
- namespace SiteCore.Handler
- {
- public partial class app
- {
- string return_msg = "访问发生错误";
- string appid = "wx1a0ef3f44d756867";
- string appsecret = "0e1b1be9ee411f569f208105551e0a1d";
- private UserObj GetAaEntity()
- {
- string session_id = con.Request.Headers["session-id"];
- if (string.IsNullOrEmpty(session_id))
- {
- conLoginError("未授权登录");
- return null;
- }
- try
- {
- UserObj uo = aaRedis.RedisHelper.StringGet<UserObj>(session_id);
- if (uo == null)
- {
- conLoginError("请重新登录");
- return null;
- }
- return uo;
- }
- catch (Exception ex)
- {
- XLog.SaveLog(0, "GetErpEntity:" + ex.Message);
- conLoginError("请重新登录");
- return null;
- }
- }
- public void get_aa_openid()
- {
- if (UrlPostParmsCheck("code"))
- {
- string code = GetPostString("code");
- if (code == "123456")
- {
- string session_id = "u_" + con.Session.SessionID;
- UserObj userObj = new UserObj();
- userObj.openid = "789123";
- userObj.session_id = session_id;
- aaRedis.RedisHelper.StringSet<UserObj>(session_id, userObj,TimeSpan.FromDays(1));
- conSuccess(session_id);
- }
- return;
- HttpHelper http = new HttpHelper();
- HttpResult hResult = null;
- HttpItem item = new HttpItem()
- {
- URL = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + appid + "&secret=" + appsecret + "&code=" + code + "&grant_type=authorization_code"
- };
- hResult = http.GetHtml(item);
- string html = hResult.Html;
- //XLog.SaveLog(0, html);
- JavaScriptSerializer jss = new JavaScriptSerializer();
- Dictionary<string, object> jObj = jss.Deserialize<Dictionary<string, object>>(html);
- if (!jObj.ContainsKey("errcode"))
- {
- UserObj userObj = new UserObj();
- string session_id = "u_" + con.Session.SessionID;
- userObj.openid= jObj["openid"].ToString();
- userObj.session_id = session_id;
- aaRedis.RedisHelper.StringSet<UserObj>(session_id, userObj,TimeSpan.FromDays(1));
- //StringBuilder userStr = new StringBuilder();
- //userStr.Append("{");
- //userStr.AppendFormat("\"session2\":\"{0}\"", session_id);
- //userStr.Append("}");
- //conSuccess("1",session_id);
- conSuccess(session_id);
- }
- return;
- }
- conError("无法登录");
- }
- public void aa_take_order()
- {
- UserObj uo = GetAaEntity();
- if (uo == null) return;
- if (UrlPostParmsCheck("optime"))
- {
- string optime = GetPostString("optime");
- SqlParameter[] sqlParameter ={
- new SqlParameter("@opid", SqlDbType.VarChar,50),
- new SqlParameter("@optime", SqlDbType.VarChar, 30),
- new SqlParameter("@result",SqlDbType.NVarChar,100)
- };
- sqlParameter[0].Value = uo.openid;
- sqlParameter[1].Value = optime;
- sqlParameter[2].Direction = ParameterDirection.Output;
- DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure,"sp_aa_takenumber", sqlParameter);
- string or = sqlParameter[2].Value.ToString();
- string[] oArr = or.Split('|');
- if (oArr[0] == "1") conSuccess(oArr[1]);
- else conError(oArr[1]);
- return;
- }
- conError(return_msg);
- }
-
- public void get_aa_user_cur()
- {
- UserObj uo = GetAaEntity();
- if (uo == null) return;
- if (UrlPostParmsCheck("optime"))
- {
- string optime = GetPostString("optime");
- StringBuilder sql = new StringBuilder();
- sql.AppendFormat("select (select count(0) from S_AaOrder as a where a.state=0 and a.code<code) as pc,id,code,starttime,state from S_AaOrder where openid='{0}' and datediff(d,StartTime,'{1}')=0 ;", uo.openid, optime);
- DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
- conGridJson(dt.Rows.Count, Utils.Serialization.JsonString.DataTable2LowerAjaxJson(dt));
- return;
- }
- conError(return_msg);
- }
- public void del_aa_user_order()
- {
- UserObj uo = GetAaEntity();
- if (uo == null) return;
- if (UrlPostParmsCheck("oid"))
- {
- int oid = GetPostInt("oid");
- StringBuilder sql = new StringBuilder();
- sql.AppendFormat("delete from s_aaorder where openid='{0}' and id={1} and state=0", uo.openid, oid);
- DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
- conSuccess("已撤销");
- return;
- }
- conError(return_msg);
- }
- public void get_aa_cw_order()
- {
- UserObj uo = GetAaEntity();
- if (uo == null) return;
- if (UrlPostParmsCheck("optime"))
- {
- string optime = GetPostString("optime");
- StringBuilder sql = new StringBuilder();
- sql.AppendFormat("select id,code,starttime,name,state from s_aaorder where datediff(d,starttime,'{0}')=0 ", optime);
- DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
- conGridJson(dt.Rows.Count, Utils.Serialization.JsonString.DataTable2LowerAjaxJson(dt));
- return;
- }
- conError(return_msg);
- }
- public void get_aa_cw_cur()
- {
- UserObj uo = GetAaEntity();
- if (uo == null) return;
- if (UrlPostParmsCheck("optime"))
- {
- string optime = GetPostString("optime");
- StringBuilder sql = new StringBuilder();
- sql.AppendFormat("select top 1 id,code,starttime,name from s_aaorder where datediff(d,starttime,'{0}')=0 and state=0 order by code asc", optime);
- DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
- conGridJson(dt.Rows.Count, Utils.Serialization.JsonString.DataTable2LowerAjaxJson(dt));
- return;
- }
- conError(return_msg);
- }
- public void aa_handle_num()
- {
- UserObj uo = GetAaEntity();
- if (uo == null) return;
- if (UrlPostParmsCheck("oid,optime"))
- {
- int oid = GetPostInt("oid");
- StringBuilder sql = new StringBuilder();
- sql.AppendFormat("update s_aaorder set state=1,suretime=getdate() where id={0}", oid);
- DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
- conSuccess("操作完成");
- return;
- }
- conError(return_msg);
- }
- public void set_aa_cw_num()
- {
- UserObj uo = GetAaEntity();
- if (uo == null ) return;//|| !uo.isleader
- if (UrlPostParmsCheck("def"))
- {
- int def = GetPostInt("def");
- StringBuilder sql = new StringBuilder();
- sql.AppendFormat("if (select count(0) from s_aasetnum where setTime is null)>0 begin ");
- sql.AppendFormat(" update s_aasetnum set num={0} where setTime is null ", def);
- sql.AppendFormat(" end else begin ");
- sql.AppendFormat(" insert into s_aasetnum(settime,num) values(null,{0}) ", def);
- sql.AppendFormat(" end ");
- DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
- conSuccess("操作完成");
- return;
- }
- conError(return_msg);
- }
- public void add_aa_cw_num()
- {
- UserObj uo = GetAaEntity();
- if (uo == null) return;//|| !uo.isleader
- if (UrlPostParmsCheck("num,optime"))
- {
- int num = GetPostInt("num");
- string optime = GetPostString("optime");
- StringBuilder sql = new StringBuilder();
- sql.AppendFormat("if (select count(0) from s_aasetnum where datediff(d,settime,'{0}')=0)>0 begin ",optime);
- sql.AppendFormat(" update s_aasetnum set num={0} where datediff(d,settime,'{1}')=0 ", num,optime);
- sql.AppendFormat(" end else begin ");
- sql.AppendFormat(" insert into s_aasetnum(num,settime) values({0},'{1}') ", num,optime);
- sql.AppendFormat(" end ");
- DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
- conSuccess("操作完成");
- return;
- }
- conError(return_msg);
- }
- public void del_aa_cw_num()
- {
- UserObj uo = GetAaEntity();
- if (uo == null) return;//|| !uo.isleader
- if (UrlPostParmsCheck("sid"))
- {
- int sid = GetPostInt("sid");
- string optime = GetPostString("optime");
- StringBuilder sql = new StringBuilder();
- sql.AppendFormat(" delete from s_aasetnum where id={0} ", sid);
- DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
- conSuccess("操作完成");
- return;
- }
- conError(return_msg);
- }
- public void get_aa_cw_num()
- {
- UserObj uo = GetAaEntity();
- if (uo == null) return;
- StringBuilder sql = new StringBuilder();
- sql.AppendFormat("select id,settime,num from s_aasetnum where settime is not null order by settime desc;");
- sql.AppendFormat("select top 1 num from s_aasetnum where settime is null");
- DataSet ds = DbHelper.DbConn.ExecuteDataset(sql.ToString());
- DataTable dt = ds.Tables[0];
- DataTable dt2 = ds.Tables[1];
- int num = 0;
- if(dt2 != null && dt2.Rows.Count > 0)
- {
- num = Convert.ToInt32(dt2.Rows[0]["num"]);
- }
- con.Response.Write("{" + string.Format("\"res\":1,\"def\":{0},\"data\":{1}", num, Utils.Serialization.JsonString.DataTable2LowerAjaxJson(dt)) + "}");
- return;
- }
- public void check_aa_cw_login()
- {
- UserObj uo = GetAaEntity();
- if (uo == null) return;
- if (UrlPostParmsCheck("pwd"))
- {
- string pwd = GetPostString("pwd");
- if (pwd == "yunduan123")
- {
- uo.isleader = true;
- aaRedis.RedisHelper.StringSet(uo.session_id, uo, TimeSpan.FromHours(5));
- conSuccess("1");
- return;
- }
- else
- {
- conError("错误访问码");
- return;
- }
- }
- conError(return_msg);
- }
- //public void compute_aa_time()
- //{
- // if(UrlPostParmsCheck("dtime"))
- // {
- // string _time = GetPostString("dtime");
- // //string dTime = Convert.ToDateTime(_time).;
- // string sql="select * from s_aaorder where "
- // }
-
- //}
- }
- }
|