代码修改后的版本,全部提交
This commit is contained in:
439
Mtxfw.VipSite/API/api.ashx.cs
Normal file
439
Mtxfw.VipSite/API/api.ashx.cs
Normal file
@@ -0,0 +1,439 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.SessionState;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.IO;
|
||||
using System.Configuration;
|
||||
using System.Web.Script.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using Mtxfw.Utility.DataAccess;
|
||||
using Mtxfw.Utility;
|
||||
using Mtxfw.Model;
|
||||
using System.Drawing;
|
||||
using ThoughtWorks.QRCode.Codec;
|
||||
using System.Net;
|
||||
using System.Drawing.Imaging;
|
||||
|
||||
namespace Mtxfw.VipSite.api
|
||||
{
|
||||
/// <summary>
|
||||
/// api 的摘要说明
|
||||
/// </summary>
|
||||
public class api : IHttpHandler, IRequiresSessionState
|
||||
{
|
||||
public string url_http = ""; //System.Configuration.ConfigurationManager.AppSettings["http_url"].ToString(); //接口地址
|
||||
public void ProcessRequest(HttpContext context)
|
||||
{
|
||||
#region 取得处事类型
|
||||
|
||||
//取得处事类型
|
||||
string action = DTRequest.GetQueryString("action");
|
||||
switch (action)
|
||||
{
|
||||
case "index_about_id":
|
||||
index_about_id(context); //获取首页企业介绍文章id
|
||||
break;
|
||||
case "index_icon_list":
|
||||
index_icon_list(context); //首页icon图标列表
|
||||
break;
|
||||
case "user_sign_list":
|
||||
user_sign_list(context); //获取用户签到列表
|
||||
break;
|
||||
case "user_sign_info":
|
||||
user_sign_info(context); //获取用户签到状态
|
||||
break;
|
||||
case "user_sign_in":
|
||||
user_sign_in(context); //用户签到接口
|
||||
break;
|
||||
case "public_img_upload":
|
||||
public_img_upload(context);
|
||||
break;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
#region (POST)获取首页企业介绍文章id
|
||||
|
||||
private void index_about_id(HttpContext context)
|
||||
{
|
||||
context.Response.ContentType = "application/json";
|
||||
Sql db = new Sql();
|
||||
|
||||
var model = db.FindFirst<Model.Article>(u => u.gtype == 0 && (u.Title.Contains("企业简介")||u.Title.Contains("企业介绍")));
|
||||
if (model != null)
|
||||
{
|
||||
var result = new { status = 1, about_id = model.id, model= model, msg = "数据获取成功" };
|
||||
context.Response.Write(JsonConvert.SerializeObject(result));
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
var result = new { status = 0, msg = "没有查询到企业介绍或企业简介相关文章数据" };
|
||||
context.Response.Write(JsonConvert.SerializeObject(result));
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region (POST)首页icon图标列表
|
||||
|
||||
private void index_icon_list(HttpContext context)
|
||||
{
|
||||
context.Response.ContentType = "application/json";
|
||||
|
||||
XmlClass xml = new XmlClass();
|
||||
string path = System.Web.HttpContext.Current.Server.MapPath("~/xmlconfig/index_icon.xml");
|
||||
DataTable dt = xml.Xml_Reader(path, "DataRoot");
|
||||
int icon1 = Utils.StrToInt(dt.Rows[0]["icon_1"].ToString(), 0); //企业介绍icon
|
||||
int icon2 = Utils.StrToInt(dt.Rows[0]["icon_2"].ToString(), 0); //操作教程icon
|
||||
int icon3 = Utils.StrToInt(dt.Rows[0]["icon_3"].ToString(), 0); //发图素材icon
|
||||
int icon4 = Utils.StrToInt(dt.Rows[0]["icon_4"].ToString(), 0); //健康知识icon
|
||||
int icon5 = Utils.StrToInt(dt.Rows[0]["icon_5"].ToString(), 0); //客服专区icon
|
||||
|
||||
var result = new { status = 1, is_icon1 = icon1, is_icon2 = icon2, is_icon3 = icon3, is_icon4 = icon4, is_icon5 = icon5, msg = "数据获取成功" };
|
||||
context.Response.Write(JsonConvert.SerializeObject(result));
|
||||
return;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region (POST)获取用户签到列表
|
||||
|
||||
private void user_sign_list(HttpContext context)
|
||||
{
|
||||
context.Response.ContentType = "application/json";
|
||||
int userId = Utils.StrToInt(DTRequest.GetFormString("userId").Trim(), 0);
|
||||
if (userId == 0)
|
||||
{
|
||||
context.Response.Write("{\"status\":0, \"msg\":\"用户登录超时,请重新登录!\"}");
|
||||
return;
|
||||
}
|
||||
DAL.user_info daoUser = new DAL.user_info();
|
||||
Mtxfw.Model.user_info modelUser = daoUser.GetModel(userId);
|
||||
if (modelUser == null)
|
||||
{
|
||||
context.Response.Write("{\"status\":0, \"msg\":\"用户登录超时,请重新登录!\"}");
|
||||
return;
|
||||
}
|
||||
|
||||
Sql db = new Sql();
|
||||
|
||||
List<UserSignLog> listSignIn= db.FindAll<Model.UserSignLog>(t => t.UserId == userId,"id desc");
|
||||
|
||||
List<qiandao> listQd= db.FindAll<Model.qiandao>(t => t.Q_MemberId == userId,"Q_Id desc");
|
||||
|
||||
List<user_Results_jl2> listResult= db.FindAll<Model.user_Results_jl2>(t => t.MemberId == userId &&t.utype==3,"Id desc");
|
||||
|
||||
//查询当前用户当天是否已经签到
|
||||
if (listSignIn.Count > 0 && listQd.Count > 0)
|
||||
{
|
||||
foreach (var item in listSignIn)
|
||||
{
|
||||
// 去除第一个逗号之前的内容(包括逗号)
|
||||
int index = item.Remark.IndexOf(",");
|
||||
if (index >= 0)
|
||||
{
|
||||
item.Remark = item.Remark.Substring(index + 1);
|
||||
}
|
||||
}
|
||||
List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
|
||||
foreach (var item in listResult)
|
||||
{
|
||||
Dictionary<string, object> dic = new Dictionary<string, object>();
|
||||
dic.Add("id", item.Id);
|
||||
dic.Add("Point", item.Addmoney);
|
||||
dic.Add("AfterPoint", item.Totalmoney);
|
||||
if (!item.Addmoney.ToString().Contains("-"))
|
||||
{
|
||||
dic.Add("ClassId", 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
dic.Add("ClassId", 2);
|
||||
}
|
||||
dic.Add("add_time", item.addtime);
|
||||
dic.Add("CreateDay", item.addtime.ToString("yyyy-MM-dd"));
|
||||
dic.Add("Remark", item.BZContent);
|
||||
list.Add(dic);
|
||||
}
|
||||
var result = new { status = 1, listSignIn = listSignIn, listQd = listQd,listResult = list, msg = "数据获取成功" };
|
||||
context.Response.Write(JsonConvert.SerializeObject(result));
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
context.Response.Write("{\"status\":0, \"msg\":\"暂无签到信息\"}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region (POST)获取用户签到状态
|
||||
|
||||
private void user_sign_info(HttpContext context)
|
||||
{
|
||||
context.Response.ContentType = "application/json";
|
||||
int userId = Utils.StrToInt(DTRequest.GetFormString("userId").Trim(), 0);
|
||||
if (userId == 0)
|
||||
{
|
||||
context.Response.Write("{\"status\":0, \"msg\":\"用户登录超时,请重新登录!\"}");
|
||||
return;
|
||||
}
|
||||
DAL.user_info daoUser = new DAL.user_info();
|
||||
Mtxfw.Model.user_info modelUser = daoUser.GetModel(userId);
|
||||
if (modelUser == null)
|
||||
{
|
||||
context.Response.Write("{\"status\":0, \"msg\":\"用户登录超时,请重新登录!\"}");
|
||||
return;
|
||||
}
|
||||
|
||||
DateTime today = DateTime.Today; //格式 年-月-日
|
||||
DateTime tomorrow = today.AddDays(1); // 2026-02-02 00:00:00
|
||||
|
||||
Sql db = new Sql();
|
||||
|
||||
var blnQiandao = db.Exists<qiandao>(q =>
|
||||
q.Q_MemberId == userId &&
|
||||
q.Q_SJ >= today && // 大于等于今天零点
|
||||
q.Q_SJ < tomorrow // 小于明天零点(注意用 < 不是 <=)
|
||||
);
|
||||
|
||||
//utype == 3 兑换券
|
||||
var blnResultJL2 = db.Exists<user_Results_jl2>(q =>
|
||||
q.MemberId == userId &&
|
||||
q.gtype == 0 &&
|
||||
q.utype == 3 &&
|
||||
q.addtime >= today && // 大于等于今天零点
|
||||
q.addtime < tomorrow // 小于明天零点(注意用 < 不是 <=)
|
||||
);
|
||||
|
||||
var blnSignLog = db.Exists<Model.UserSignLog>(t =>
|
||||
t.UserId == userId && t.CreateTime >= today && t.CreateTime < tomorrow);
|
||||
|
||||
//查询当前用户当天是否已经签到
|
||||
if (blnQiandao && blnSignLog && blnResultJL2)
|
||||
{
|
||||
context.Response.Write("{\"status\":1,\"point\":\""+modelUser.umoney30+"\", \"msg\":\"当天已签到\"}");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
context.Response.Write("{\"status\":0,\"point\":\""+modelUser.umoney30+"\", \"msg\":\"当天未签到\"}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region (POST)用户签到接口
|
||||
|
||||
private void user_sign_in(HttpContext context)
|
||||
{
|
||||
context.Response.ContentType = "application/json";
|
||||
int userId = Utils.StrToInt(DTRequest.GetFormString("userId").Trim(), 0);
|
||||
if (userId == 0)
|
||||
{
|
||||
context.Response.Write("{\"status\":0,\"msg\":\"用户登录超时,请重新登录!\"}");
|
||||
return;
|
||||
}
|
||||
DAL.user_info daoUser = new DAL.user_info();
|
||||
Mtxfw.Model.user_info modelUser = daoUser.GetModel(userId);
|
||||
if (modelUser == null)
|
||||
{
|
||||
context.Response.Write("{\"status\":0,\"msg\":\"用户登录超时,请重新登录!\"}");
|
||||
return;
|
||||
}
|
||||
|
||||
DateTime today = DateTime.Today; //格式 年-月-日
|
||||
DateTime tomorrow = today.AddDays(1); // 2026-02-02 00:00:00
|
||||
|
||||
Sql db = new Sql();
|
||||
|
||||
var blnQiandao = db.Exists<qiandao>(q =>
|
||||
q.Q_MemberId == userId &&
|
||||
q.Q_SJ >= today && // 大于等于今天零点
|
||||
q.Q_SJ < tomorrow // 小于明天零点(注意用 < 不是 <=)
|
||||
);
|
||||
//utype == 3 兑换券
|
||||
var blnResultJL2 = db.Exists<user_Results_jl2>(q =>
|
||||
q.MemberId == userId &&
|
||||
q.gtype == 0 &&
|
||||
q.utype == 3 &&
|
||||
q.addtime >= today && // 大于等于今天零点
|
||||
q.addtime < tomorrow // 小于明天零点(注意用 < 不是 <=)
|
||||
);
|
||||
|
||||
var blnSignLog = db.Exists<Model.UserSignLog>(t =>
|
||||
t.UserId == userId && t.CreateTime >= today && t.CreateTime < tomorrow);
|
||||
|
||||
//查询当前用户当天是否已经签到
|
||||
if (blnQiandao && blnSignLog && blnResultJL2)
|
||||
{
|
||||
context.Response.Write("{\"status\":0,\"msg\":\"当天已完成签到!\"}");
|
||||
return;
|
||||
}
|
||||
|
||||
XmlClass xml = new XmlClass();
|
||||
string path = System.Web.HttpContext.Current.Server.MapPath("~/xmlconfig/sign_in.xml");
|
||||
DataTable dt = xml.Xml_Reader(path, "DataRoot");
|
||||
decimal dayNum = Utils.StrToDecimal(dt.Rows[0]["signin_value"].ToString(), 0.00M);
|
||||
decimal sevenDayNum = Utils.StrToDecimal(dt.Rows[0]["seven_day_value"].ToString(), 0.00M);
|
||||
|
||||
Model.qiandao modelQianDao = new qiandao();
|
||||
|
||||
//判断是否连续7天签到
|
||||
int lastDay = 0;
|
||||
// 多字段排序:先按时间降序,再按ID升序
|
||||
UserSignLog lastSignModel = db.FindFirst<UserSignLog>( q => q.UserId == userId && q.ClassId == 1," number_day asc");
|
||||
if (lastSignModel != null)
|
||||
{
|
||||
lastDay = Utils.StrToInt(lastSignModel.NumberDay.ToString(), 0);
|
||||
}
|
||||
|
||||
decimal point = 0.00M;
|
||||
decimal afterPoint = 0.00M;
|
||||
decimal beforePoint = Convert.ToDecimal(modelUser.umoney30);
|
||||
int intNumberDay = 0;
|
||||
if (lastDay + 1 == 7)
|
||||
{
|
||||
point = sevenDayNum;
|
||||
}
|
||||
else
|
||||
{
|
||||
point = dayNum;
|
||||
}
|
||||
|
||||
if (lastDay + 1 > 7)
|
||||
{
|
||||
intNumberDay = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
intNumberDay = lastDay + 1;
|
||||
}
|
||||
|
||||
afterPoint = beforePoint + point;
|
||||
|
||||
try
|
||||
{
|
||||
//记录表1
|
||||
string strIntro = String.Format("用户编号:{0},日期:{1},第{2}天签到成功,获得{3}兑换券",userId,DateTime.Now.ToString("yyyy-MM-dd"),intNumberDay,point);
|
||||
Model.qiandao modelQD = new qiandao();
|
||||
modelQD.Q_MemberId = userId;
|
||||
modelQD.Q_SJ = DateTime.Now;
|
||||
modelQD.gtype = 3; //gtype=3 --> 兑换券
|
||||
modelQD.Q_Num = Utils.StrToInt(point.ToString(),0);
|
||||
modelQD.Q_Intro= strIntro;
|
||||
int resultQd = db.Insert(modelQD);
|
||||
|
||||
//记录表2
|
||||
string remark = String.Format("用户编号:{0},日期:{1},第{2}天签到成功,获得{3}兑换券,更新前兑换券数量:{4},更新后兑换券数量:{5}",userId,DateTime.Now.ToString("yyyy-MM-dd"),intNumberDay,point,beforePoint,afterPoint);
|
||||
Model.UserSignLog modelSignLog = new Model.UserSignLog();
|
||||
modelSignLog.UserId = userId;
|
||||
modelSignLog.BeforePoint = beforePoint;
|
||||
modelSignLog.Point = point;
|
||||
modelSignLog.AfterPoint = afterPoint;
|
||||
modelSignLog.NumberDay = intNumberDay;
|
||||
modelSignLog.ClassId = 1; //1=用户签到
|
||||
modelSignLog.CreateTime = DateTime.Now;
|
||||
modelSignLog.CreateDay = DateTime.Now.ToString("yyyy-MM-dd");
|
||||
modelSignLog.Remark = remark;
|
||||
int resultId = db.Insert(modelSignLog);
|
||||
|
||||
//记录表3
|
||||
DateTime dtnow = DateTime.Now;
|
||||
Model.user_Results_jl2 modelResultLog = new Model.user_Results_jl2();
|
||||
modelResultLog.MemberId = userId;
|
||||
modelResultLog.addtime = dtnow;
|
||||
modelResultLog.updatetime = dtnow;
|
||||
modelResultLog.Addmoney = Convert.ToDouble(point);
|
||||
modelResultLog.Totalmoney= Convert.ToDouble(afterPoint);
|
||||
modelResultLog.Seef = -1;
|
||||
modelResultLog.BZContent = String.Format("日期:{0},第{1}天签到成功,获得{2}兑换券,更新前兑换券数量:{3},更新后兑换券数量:{4}",DateTime.Now.ToString("yyyy-MM-dd"),intNumberDay,point,beforePoint,afterPoint);
|
||||
modelResultLog.IFDelete = 0;
|
||||
modelResultLog.gtype = 0; //类型,0总公司 1分公司 2分公司
|
||||
modelResultLog.utype = 3; //3表示兑换劵记录
|
||||
int resultJL = db.Insert(modelResultLog);
|
||||
|
||||
if (resultQd > 0 && resultId > 0 && resultJL > 0)
|
||||
{
|
||||
double dblPoint = modelUser.umoney30 + Convert.ToDouble(point);
|
||||
modelUser.umoney30 = dblPoint;
|
||||
db.Update(modelUser);
|
||||
|
||||
string todayRemark = String.Format("签到成功,今天是第{0}天签到,获得{1}兑换券!", intNumberDay,point);
|
||||
context.Response.Write("{\"status\":1,\"point\":\""+dblPoint+"\",\"remark\":\""+todayRemark+"\",\"msg\":\"签到成功\"}");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
context.Response.Write("{\"status\":0,\"msg\":\"签到失败\"}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Singleton.Error("用户签到失败,系统出现错误:"+ex.ToString());
|
||||
context.Response.Write("{\"status\":0,\"msg\":\"签到失败,系统出现异常!\"}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region (POST)通用接口 - 单张图片上传接口
|
||||
|
||||
private void public_img_upload(HttpContext context)
|
||||
{
|
||||
HttpFileCollection files = HttpContext.Current.Request.Files;
|
||||
int num = 0;
|
||||
string imgUrl = String.Empty;
|
||||
|
||||
for (int i = 0; i < files.Count; i++)
|
||||
{
|
||||
HttpPostedFile file = files[i];
|
||||
if (System.IO.Path.GetExtension(file.FileName) == ".jpg" ||
|
||||
System.IO.Path.GetExtension(file.FileName) == ".png" ||
|
||||
System.IO.Path.GetExtension(file.FileName) == ".JPG" ||
|
||||
System.IO.Path.GetExtension(file.FileName) == ".PNG")
|
||||
{
|
||||
if (string.IsNullOrEmpty(file.FileName) == false)
|
||||
{
|
||||
System.Random random = new Random();
|
||||
string str_name = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(file.FileName);
|
||||
string toThumImg = "/upload/images/" + str_name;
|
||||
imgUrl += url_http + toThumImg + ",";
|
||||
file.SaveAs(HttpContext.Current.Server.MapPath("~/upload/images/") + str_name);
|
||||
num++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
context.Response.Write("{\"status\":0, \"msg\":\"文件上传失败,格式不支持!\"}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (imgUrl.EndsWith(","))
|
||||
{
|
||||
imgUrl = imgUrl.TrimEnd(',');
|
||||
}
|
||||
|
||||
context.Response.Write("{\"status\":1,\"img_num\":" + num + ", \"img_url\":\"" + imgUrl +
|
||||
"\", \"msg\":\"文件上传成功!\"}");
|
||||
return;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
public bool IsReusable
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user