ComplianceServer/oldcode/WEB/Controllers/TS/FriendscircleController.cs

192 lines
7.2 KiB
C#

using Ninject;
using System;
using System.Data;
using System.Web;
using System.Web.Mvc;
using WX.CRM.Common;
using WX.CRM.IBLL.TS;
using WX.CRM.Model.MAP;
using WX.CRM.WebHelper;
namespace WX.CRM.WEB.Controllers.TS
{
public class FriendscircleController : BaseController
{
[Inject]
public IWX_TS_CMD wx_ts_cmd { get; set; }
//
// GET: /Friendscircle/
[AuthorizeRedirect(Roles = InitRights.CONST_微信朋友圈发送管理)]
public ActionResult Index()
{
ToolBar tool = new ToolBar();
string[] toolbtn = new ToolButtonView().ToolButtonRight(InitRights., userRightId);
tool.AllowButton(toolbtn);
tool.AddOtherButton("Other1", "发送一条朋友圈", "icon-friendScirle", "SendOne_Click", true);
ViewBag.ToolBar = tool;
Pager pager = new Pager() { page = 1, rows = 10 };
string tableId = "tablist";
Table tab = new Table(tableId);
tab.AddHeadCol("pici", "7%", "批次");
tab.AddHeadCol("alias", "7%", "微信号");
tab.AddHeadCol("content", "", "内容");
tab.AddHeadCol("imgpath", "", "图片");
tab.AddHeadCol("ctime", "10%", "创建时间");
tab.AddHeadCol("exectime", "10%", "设定执行的时间");
tab.AddHeadCol("status", "5%", "推送状态");
//tab.AddHeadCol("stime", "5%", "实际开始执行时间");
//tab.AddHeadCol("etime", "5%", "实际结束时间");
tab.AddHeadCol("erromsg", "5%", "错误信息");
tab.AddHeadRow();
ViewBag.gridTable = tab.GetHead() + Pagination.GetPage(pager, tableId, "10,20,50");
return View();
}
/// <summary>
/// 按照条件获取数据
/// </summary>
/// <param name="pager"></param>
/// <param name="queryStr"></param>
/// <returns></returns>
[AuthorizeRedirect(Roles = InitRights.CONST_微信朋友圈发送管理)]
public JsonResult GetHtmlList(Pager pager, string alias, DateTime? stime, DateTime? etime, string columns)
{
Table table = new Table(columns, true);
table.gridPager = pager;
if (etime.HasValue)
{
etime = etime.Value.AddDays(1);
}
DataTable dataTable = wx_ts_cmd.GetFirneScirccleLog(stime, etime, alias, ref pager);
foreach (DataRow row in dataTable.Rows)
{
table.AddCol(row["pici"]);
table.AddCol(row["alias"]);
table.AddCol(string.Format("<font style='color:green;'>{0}</font>", row["txt"]));
string imgpath = row["imgpath"].ToString();
if (!string.IsNullOrEmpty(imgpath))
{
string imghtml = "<ul class='nbul'>";
foreach (var item in imgpath.Split(','))
{
imghtml += "<li><img style='max-height:120px;max-width:120px;' src='/fsfile/" + item + "'/></li>";
}
imghtml += "</ul>";
table.AddCol(imghtml);
}
else
{
table.AddCol("");
}
table.AddCol(row["ctime"]);
table.AddCol(row["executetime"]);
if (row["snedstuts"] != DBNull.Value)
{
table.AddCol(getSendStatus(Convert.ToInt32(row["snedstuts"])));
}
else
{
table.AddCol("其他");
}
//table.AddCol(row["starttime"]);
//table.AddCol(row["endtime"]);
string errMsg = string.Format("{0}", row["erromsg"]);
if (errMsg.IndexOf("\"ActionStatus\":\"OK\"") > -1)
table.AddCol("");
else
table.AddCol(string.Format("<font style='color:red;'>{0}</font>", row["erromsg"]));
table.AddRow();
}
var json = new
{
totalPages = pager.totalPages,
totalRows = pager.totalRows,
rowsList = table.GetRows()
};
return Json(json, JsonRequestBehavior.AllowGet);
}
private string getSendStatus(int sendstatus)
{
switch (sendstatus)
{
case 0: return "<font style=\"color:#AAAAAA\">未推送</font>";
case 1: return "<font style=\"color:blue\">发送成功</font>";
case 2: return "<font style=\"color:red\">发送失败</font>";
default: return "其他";
}
}
[AuthorizeToolBar(InitRights.CONST_微信朋友圈发送管理, InitToolBar.CONST_Other1)]
public ActionResult SendFriendScircle()
{
return View();
}
[AuthorizeToolBar(InitRights.CONST_微信朋友圈发送管理, InitToolBar.CONST_Other1)]
public JsonResult SendFriendScircleSave(WX_FriendScirclePhone model)
{
ValidationErrors errors = new ValidationErrors();
if (!ModelState.IsValid)
{
return JsonHandler.ValidateFailMessage();
}
bool result = wx_ts_cmd.CreateFriendscircle(model.content, model.timeType, model.exe_date, model.exe_time, model.imgPath, ref errors);
return JsonHandler.UpdateMessage(errors, result);
}
[AuthorizeToolBar(InitRights.CONST_微信朋友圈发送管理, InitToolBar.CONST_Other1)]
[HttpPost]
public JsonResult UploadImage()
{
bool result = false;
string content = "";
try
{
HttpRequestBase requestBase = Request;
int dindex = requestBase.Files[0].FileName.LastIndexOf('.');
string dex = requestBase.Files[0].FileName.Substring(dindex, requestBase.Files[0].FileName.Length - dindex);
content = DateTime.Now.Ticks + dex;
string filename = Server.MapPath("/") + "/fsfile/" + content;
requestBase.Files[0].SaveAs(filename);
result = true;
}
catch (Exception ex)
{
LogHelper.Error(ex.ToString());
}
return Json(new { result = result, filename = content }, JsonRequestBehavior.AllowGet);
}
[AuthorizeToolBar(InitRights.CONST_微信朋友圈发送管理, InitToolBar.CONST_Other1)]
[HttpPost]
public JsonResult DeleteImag(string imagefile)
{
bool result = false;
try
{
string filename = Server.MapPath("/") + "/fsfile/" + imagefile;
if (System.IO.File.Exists(filename))
{
System.IO.File.Delete(filename);
}
result = true;
}
catch (Exception ex)
{
LogHelper.Error(ex);
}
return Json(new { result = result }, JsonRequestBehavior.AllowGet);
}
}
}