public object AnalyseOrder([FromBody] AnalyseOrderModel am) { try { var addr = Server.GetUserIp(Request.HttpContext); if (Server.IpHandle(addr) == 0) { return(new[] { "your ip can't using our api , please contact administrator" }); } var account = HttpContext.Session.GetString("user_account"); // if (account == null) // { // return new // { // result = 401 , // msg = "not login" // }; // } // var re = OrderServer.AnalyseOrder(am); return(re); } catch (Exception e) { return(new { result = e.HResult, msg = e.Message }); } }
/// <summary> /// 分析销售情况 /// </summary> /// <param name="am">分析模型</param> /// <returns></returns> public static object AnalyseOrder(AnalyseOrderModel am) { using (var con = new SqlConnection(Server.SqlConString)) { con.Open(); var message = ""; var sqlCom = new SqlCommand("sp_AnalyseOrder", con) { CommandType = CommandType.StoredProcedure }; sqlCom.Parameters.AddRange(new[] { new SqlParameter { ParameterName = "@theaterId", Direction = ParameterDirection.Input, SqlDbType = SqlDbType.Int, Value = am.TheaterId }, new SqlParameter { ParameterName = "@userId", Direction = ParameterDirection.Input, SqlDbType = SqlDbType.Int, Value = am.UserId }, new SqlParameter { ParameterName = "@tradeDate", Direction = ParameterDirection.Input, SqlDbType = SqlDbType.Date, Value = am.TradeDate }, new SqlParameter { ParameterName = "@dateLength", Direction = ParameterDirection.Input, SqlDbType = SqlDbType.Int, Value = am.DateLength }, new SqlParameter { ParameterName = "@programmeId", Direction = ParameterDirection.Input, SqlDbType = SqlDbType.Int, Value = am.ProgrammeId }, new SqlParameter { ParameterName = "@message", Direction = ParameterDirection.Output, Size = 30, SqlDbType = SqlDbType.VarChar, Value = message }, new SqlParameter { ParameterName = "@return", Direction = ParameterDirection.ReturnValue, SqlDbType = SqlDbType.Int } }); sqlCom.ExecuteNonQuery(); var msg = (string)sqlCom.Parameters["@message"].Value; object data = null; var reader = sqlCom.ExecuteReader(); while (reader.Read()) { data = new { tradeTimes = reader[0] == DBNull.Value ? 0 : (int)reader[0], sumPrice = reader[1] == DBNull.Value ? 0 : (decimal)reader[1], sumProfit = reader[2] == DBNull.Value ? 0 : (decimal)reader[1], }; } return(new { result = (int)sqlCom.Parameters["@return"].Value, msg, data }); } }