app.aa.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. using BizCom;
  2. using SiteCore.Redis;
  3. using SQLData;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.Data.SqlClient;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Web.Script.Serialization;
  12. namespace SiteCore.Handler
  13. {
  14. public partial class app
  15. {
  16. string return_msg = "访问发生错误";
  17. string appid = "wx1a0ef3f44d756867";
  18. string appsecret = "0e1b1be9ee411f569f208105551e0a1d";
  19. private UserObj GetAaEntity()
  20. {
  21. string session_id = con.Request.Headers["session-id"];
  22. if (string.IsNullOrEmpty(session_id))
  23. {
  24. conLoginError("未授权登录");
  25. return null;
  26. }
  27. try
  28. {
  29. UserObj uo = aaRedis.RedisHelper.StringGet<UserObj>(session_id);
  30. if (uo == null)
  31. {
  32. conLoginError("请重新登录");
  33. return null;
  34. }
  35. return uo;
  36. }
  37. catch (Exception ex)
  38. {
  39. XLog.SaveLog(0, "GetErpEntity:" + ex.Message);
  40. conLoginError("请重新登录");
  41. return null;
  42. }
  43. }
  44. public void get_aa_openid()
  45. {
  46. if (UrlPostParmsCheck("code"))
  47. {
  48. string code = GetPostString("code");
  49. if (code == "123456")
  50. {
  51. string session_id = "u_" + con.Session.SessionID;
  52. UserObj userObj = new UserObj();
  53. userObj.openid = "789123";
  54. userObj.session_id = session_id;
  55. aaRedis.RedisHelper.StringSet<UserObj>(session_id, userObj,TimeSpan.FromDays(1));
  56. conSuccess(session_id);
  57. }
  58. return;
  59. HttpHelper http = new HttpHelper();
  60. HttpResult hResult = null;
  61. HttpItem item = new HttpItem()
  62. {
  63. URL = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + appid + "&secret=" + appsecret + "&code=" + code + "&grant_type=authorization_code"
  64. };
  65. hResult = http.GetHtml(item);
  66. string html = hResult.Html;
  67. //XLog.SaveLog(0, html);
  68. JavaScriptSerializer jss = new JavaScriptSerializer();
  69. Dictionary<string, object> jObj = jss.Deserialize<Dictionary<string, object>>(html);
  70. if (!jObj.ContainsKey("errcode"))
  71. {
  72. UserObj userObj = new UserObj();
  73. string session_id = "u_" + con.Session.SessionID;
  74. userObj.openid= jObj["openid"].ToString();
  75. userObj.session_id = session_id;
  76. aaRedis.RedisHelper.StringSet<UserObj>(session_id, userObj,TimeSpan.FromDays(1));
  77. //StringBuilder userStr = new StringBuilder();
  78. //userStr.Append("{");
  79. //userStr.AppendFormat("\"session2\":\"{0}\"", session_id);
  80. //userStr.Append("}");
  81. //conSuccess("1",session_id);
  82. conSuccess(session_id);
  83. }
  84. return;
  85. }
  86. conError("无法登录");
  87. }
  88. public void aa_take_order()
  89. {
  90. UserObj uo = GetAaEntity();
  91. if (uo == null) return;
  92. if (UrlPostParmsCheck("optime"))
  93. {
  94. string optime = GetPostString("optime");
  95. SqlParameter[] sqlParameter ={
  96. new SqlParameter("@opid", SqlDbType.VarChar,50),
  97. new SqlParameter("@optime", SqlDbType.VarChar, 30),
  98. new SqlParameter("@result",SqlDbType.NVarChar,100)
  99. };
  100. sqlParameter[0].Value = uo.openid;
  101. sqlParameter[1].Value = optime;
  102. sqlParameter[2].Direction = ParameterDirection.Output;
  103. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure,"sp_aa_takenumber", sqlParameter);
  104. string or = sqlParameter[2].Value.ToString();
  105. string[] oArr = or.Split('|');
  106. if (oArr[0] == "1") conSuccess(oArr[1]);
  107. else conError(oArr[1]);
  108. return;
  109. }
  110. conError(return_msg);
  111. }
  112. public void get_aa_user_cur()
  113. {
  114. UserObj uo = GetAaEntity();
  115. if (uo == null) return;
  116. if (UrlPostParmsCheck("optime"))
  117. {
  118. string optime = GetPostString("optime");
  119. StringBuilder sql = new StringBuilder();
  120. 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);
  121. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  122. conGridJson(dt.Rows.Count, Utils.Serialization.JsonString.DataTable2LowerAjaxJson(dt));
  123. return;
  124. }
  125. conError(return_msg);
  126. }
  127. public void del_aa_user_order()
  128. {
  129. UserObj uo = GetAaEntity();
  130. if (uo == null) return;
  131. if (UrlPostParmsCheck("oid"))
  132. {
  133. int oid = GetPostInt("oid");
  134. StringBuilder sql = new StringBuilder();
  135. sql.AppendFormat("delete from s_aaorder where openid='{0}' and id={1} and state=0", uo.openid, oid);
  136. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  137. conSuccess("已撤销");
  138. return;
  139. }
  140. conError(return_msg);
  141. }
  142. public void get_aa_cw_order()
  143. {
  144. UserObj uo = GetAaEntity();
  145. if (uo == null) return;
  146. if (UrlPostParmsCheck("optime"))
  147. {
  148. string optime = GetPostString("optime");
  149. StringBuilder sql = new StringBuilder();
  150. sql.AppendFormat("select id,code,starttime,name,state from s_aaorder where datediff(d,starttime,'{0}')=0 ", optime);
  151. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  152. conGridJson(dt.Rows.Count, Utils.Serialization.JsonString.DataTable2LowerAjaxJson(dt));
  153. return;
  154. }
  155. conError(return_msg);
  156. }
  157. public void get_aa_cw_cur()
  158. {
  159. UserObj uo = GetAaEntity();
  160. if (uo == null) return;
  161. if (UrlPostParmsCheck("optime"))
  162. {
  163. string optime = GetPostString("optime");
  164. StringBuilder sql = new StringBuilder();
  165. 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);
  166. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  167. conGridJson(dt.Rows.Count, Utils.Serialization.JsonString.DataTable2LowerAjaxJson(dt));
  168. return;
  169. }
  170. conError(return_msg);
  171. }
  172. public void aa_handle_num()
  173. {
  174. UserObj uo = GetAaEntity();
  175. if (uo == null) return;
  176. if (UrlPostParmsCheck("oid,optime"))
  177. {
  178. int oid = GetPostInt("oid");
  179. StringBuilder sql = new StringBuilder();
  180. sql.AppendFormat("update s_aaorder set state=1,suretime=getdate() where id={0}", oid);
  181. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  182. conSuccess("操作完成");
  183. return;
  184. }
  185. conError(return_msg);
  186. }
  187. public void set_aa_cw_num()
  188. {
  189. UserObj uo = GetAaEntity();
  190. if (uo == null ) return;//|| !uo.isleader
  191. if (UrlPostParmsCheck("def"))
  192. {
  193. int def = GetPostInt("def");
  194. StringBuilder sql = new StringBuilder();
  195. sql.AppendFormat("if (select count(0) from s_aasetnum where setTime is null)>0 begin ");
  196. sql.AppendFormat(" update s_aasetnum set num={0} where setTime is null ", def);
  197. sql.AppendFormat(" end else begin ");
  198. sql.AppendFormat(" insert into s_aasetnum(settime,num) values(null,{0}) ", def);
  199. sql.AppendFormat(" end ");
  200. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  201. conSuccess("操作完成");
  202. return;
  203. }
  204. conError(return_msg);
  205. }
  206. public void add_aa_cw_num()
  207. {
  208. UserObj uo = GetAaEntity();
  209. if (uo == null) return;//|| !uo.isleader
  210. if (UrlPostParmsCheck("num,optime"))
  211. {
  212. int num = GetPostInt("num");
  213. string optime = GetPostString("optime");
  214. StringBuilder sql = new StringBuilder();
  215. sql.AppendFormat("if (select count(0) from s_aasetnum where datediff(d,settime,'{0}')=0)>0 begin ",optime);
  216. sql.AppendFormat(" update s_aasetnum set num={0} where datediff(d,settime,'{1}')=0 ", num,optime);
  217. sql.AppendFormat(" end else begin ");
  218. sql.AppendFormat(" insert into s_aasetnum(num,settime) values({0},'{1}') ", num,optime);
  219. sql.AppendFormat(" end ");
  220. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  221. conSuccess("操作完成");
  222. return;
  223. }
  224. conError(return_msg);
  225. }
  226. public void del_aa_cw_num()
  227. {
  228. UserObj uo = GetAaEntity();
  229. if (uo == null) return;//|| !uo.isleader
  230. if (UrlPostParmsCheck("sid"))
  231. {
  232. int sid = GetPostInt("sid");
  233. string optime = GetPostString("optime");
  234. StringBuilder sql = new StringBuilder();
  235. sql.AppendFormat(" delete from s_aasetnum where id={0} ", sid);
  236. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  237. conSuccess("操作完成");
  238. return;
  239. }
  240. conError(return_msg);
  241. }
  242. public void get_aa_cw_num()
  243. {
  244. UserObj uo = GetAaEntity();
  245. if (uo == null) return;
  246. StringBuilder sql = new StringBuilder();
  247. sql.AppendFormat("select id,settime,num from s_aasetnum where settime is not null order by settime desc;");
  248. sql.AppendFormat("select top 1 num from s_aasetnum where settime is null");
  249. DataSet ds = DbHelper.DbConn.ExecuteDataset(sql.ToString());
  250. DataTable dt = ds.Tables[0];
  251. DataTable dt2 = ds.Tables[1];
  252. int num = 0;
  253. if(dt2 != null && dt2.Rows.Count > 0)
  254. {
  255. num = Convert.ToInt32(dt2.Rows[0]["num"]);
  256. }
  257. con.Response.Write("{" + string.Format("\"res\":1,\"def\":{0},\"data\":{1}", num, Utils.Serialization.JsonString.DataTable2LowerAjaxJson(dt)) + "}");
  258. return;
  259. }
  260. public void check_aa_cw_login()
  261. {
  262. UserObj uo = GetAaEntity();
  263. if (uo == null) return;
  264. if (UrlPostParmsCheck("pwd"))
  265. {
  266. string pwd = GetPostString("pwd");
  267. if (pwd == "yunduan123")
  268. {
  269. uo.isleader = true;
  270. aaRedis.RedisHelper.StringSet(uo.session_id, uo, TimeSpan.FromHours(5));
  271. conSuccess("1");
  272. return;
  273. }
  274. else
  275. {
  276. conError("错误访问码");
  277. return;
  278. }
  279. }
  280. conError(return_msg);
  281. }
  282. //public void compute_aa_time()
  283. //{
  284. // if(UrlPostParmsCheck("dtime"))
  285. // {
  286. // string _time = GetPostString("dtime");
  287. // //string dTime = Convert.ToDateTime(_time).;
  288. // string sql="select * from s_aaorder where "
  289. // }
  290. //}
  291. }
  292. }