增加始发站起售时间提醒

This commit is contained in:
木鱼(iFish) 2015-08-03 15:07:49 +08:00
parent 24e59380a8
commit 301ad8f403
11 changed files with 150 additions and 37 deletions

View File

@ -200,6 +200,9 @@ namespace ChatRoomServer.Main
private void ChatServer_NewSessionConnected(ChatSession session) private void ChatServer_NewSessionConnected(ChatSession session)
{ {
if (session.IsSessionBlocked)
return;
var cmd = session.Command; var cmd = session.Command;
if (cmd == "room" && session.PathSegements.Length >= 4) if (cmd == "room" && session.PathSegements.Length >= 4)

View File

@ -46,6 +46,7 @@ namespace ChatRoomServer.Main
if ((AppServer as ChatServer).BlockUsers?.TryGetValue(UserName, out dt) == true) if ((AppServer as ChatServer).BlockUsers?.TryGetValue(UserName, out dt) == true)
{ {
IsSessionBlocked = true;
Block(dt); Block(dt);
return true; return true;
} }
@ -101,13 +102,10 @@ namespace ChatRoomServer.Main
db.SaveChanges(); db.SaveChanges();
_connectId = ucl.Id; _connectId = ucl.Id;
//已经封锁?
if (user.Status == UserStatus.Blocked)
{
Block(blockRule.UnblockTime);
}
} }
public bool IsSessionBlocked { get; private set; }
public void Block(DateTime? unblockTime) public void Block(DateTime? unblockTime)
{ {
TrySend(new MessageItem(SystemMessageType.OperationBlocked, content: "很抱歉,您的账户已经被封锁,暂时无法在聊天室暂住。封锁解除时间:" + (unblockTime == null ? "无限期" : unblockTime.Value.ToString()))); TrySend(new MessageItem(SystemMessageType.OperationBlocked, content: "很抱歉,您的账户已经被封锁,暂时无法在聊天室暂住。封锁解除时间:" + (unblockTime == null ? "无限期" : unblockTime.Value.ToString())));
@ -212,7 +210,7 @@ namespace ChatRoomServer.Main
Content = item.Content, Content = item.Content,
Ip = RemoteEndPoint.ToString(), Ip = RemoteEndPoint.ToString(),
RoomId = PathSegements[1], RoomId = PathSegements[1],
SendTime = DateTime.Now, SendTime = item.Time,
UserName = UserName UserName = UserName
}; };
db.MsgLogs.Add(msg); db.MsgLogs.Add(msg);

View File

@ -56,7 +56,8 @@ namespace ChatRoomServer.Main.Room
public void Remove(ChatSession session) public void Remove(ChatSession session)
{ {
RoomSessionContext context; RoomSessionContext context;
_contexts.TryRemove(session, out context); if (!_contexts.TryRemove(session, out context))
return;
var count = _contexts.Count; var count = _contexts.Count;
var enumerator = _contexts.GetEnumerator(); var enumerator = _contexts.GetEnumerator();

View File

@ -15,9 +15,30 @@ namespace ChatRoomServer.Www.Controllers
using FSLib.MvcWeb; using FSLib.MvcWeb;
using FSLib.Network.Http; using FSLib.Network.Http;
[EnableCors("http://12306.liebao.cn,http://test.fishlee.net", "*", "*", "")]
public class AnnouncementController : Controller public class AnnouncementController : Controller
{ {
/// <summary>
/// Called when authorization occurs.
/// </summary>
/// <param name="filterContext">Information about the current request and action.</param>
protected override void OnAuthorization(AuthorizationContext filterContext)
{
base.OnAuthorization(filterContext);
var origin = filterContext.RequestContext.HttpContext.Request.Headers["Origin"];
if (!origin.IsNullOrEmpty())
{
if (!Regex.IsMatch(origin, @"^https?://.*?\.(fishlee\.net|liebao\.cn)$", RegexOptions.IgnoreCase))
{
filterContext.Result = new EmptyResult();
return;
}
filterContext.HttpContext.Response.AppendHeader("Access-Control-Allow-Origin", origin);
}
}
[AllowAnonymous] [AllowAnonymous]
[HttpGet, OutputCache(Duration = 1200, VaryByHeader = "Origin")] [HttpGet, OutputCache(Duration = 1200, VaryByHeader = "Origin")]
public async Task<ContentResult> List() public async Task<ContentResult> List()

View File

@ -75,10 +75,27 @@
} }
.result .train-seats .train-notontime { .result .train-seats .train-notontime {
font-size: 20px; font-size: 16px;
color: #999; color: #999;
} }
.result .train-seats .train-nostarttip {
display: block;
margin-top: 5px;
}
.result .train-seats .train-nostarttip-insell {
color: #7F7FE0;
}
.result .train-seats .train-nostarttip-early {
color: #7F7FE0;
}
.result .train-seats .train-nostarttip-later {
color: green;
}
.result .train-seats .row2 { .result .train-seats .row2 {
} }

View File

@ -725,6 +725,7 @@
{{?(t.available==0||t.available==-1)&&!hasSeat}} {{?(t.available==0||t.available==-1)&&!hasSeat}}
{{?t.selltime}} {{?t.selltime}}
<span class="train-notontime">{{=ext.utility.formatSellDate(t.selltime)}} 起售</span> <span class="train-notontime">{{=ext.utility.formatSellDate(t.selltime)}} 起售</span>
{{=t.preStationInfo||""}}
{{??t.limitSellInfo}} {{??t.limitSellInfo}}
<span class="train-limitsell">本车次{{!t.limitSellInfo}}</span> <span class="train-limitsell">本车次{{!t.limitSellInfo}}</span>
{{??}} {{??}}

View File

@ -5,6 +5,8 @@
var ev = require("../platform/EventObject.js"); var ev = require("../platform/EventObject.js");
var dynamicjs = require("../otn/dynamicjs.js"); var dynamicjs = require("../otn/dynamicjs.js");
var sessmgr = require("../account/sessionMgr.js"); var sessmgr = require("../account/sessionMgr.js");
var stationData = require("../station/station_data.js");
var utility = require('../utility.js');
var extensionVersion = parseInt(document.body.dataset["targetExtensionVersion"].replace(/\./g, "")); var extensionVersion = parseInt(document.body.dataset["targetExtensionVersion"].replace(/\./g, ""));
@ -68,20 +70,20 @@
available: t.queryLeftNewDTO.canWebBuy === 'Y' ? 1 : 0, available: t.queryLeftNewDTO.canWebBuy === 'Y' ? 1 : 0,
start: { start: {
code: t.queryLeftNewDTO.start_station_telecode, code: t.queryLeftNewDTO.start_station_telecode,
name: t.queryLeftNewDTO.start_station_name, name: t.queryLeftNewDTO.start_station_name
}, },
from: { from: {
code: t.queryLeftNewDTO.from_station_telecode, code: t.queryLeftNewDTO.from_station_telecode,
fromStationNo: t.queryLeftNewDTO.from_station_no, fromStationNo: t.queryLeftNewDTO.from_station_no,
name: t.queryLeftNewDTO.from_station_name, name: t.queryLeftNewDTO.from_station_name,
endpoint: t.queryLeftNewDTO.from_station_telecode == t.queryLeftNewDTO.start_station_telecode, endpoint: t.queryLeftNewDTO.from_station_telecode === t.queryLeftNewDTO.start_station_telecode,
time: t.queryLeftNewDTO.start_time time: t.queryLeftNewDTO.start_time
}, },
to: { to: {
code: t.queryLeftNewDTO.to_station_telecode, code: t.queryLeftNewDTO.to_station_telecode,
toStationNo: t.queryLeftNewDTO.to_station_no, toStationNo: t.queryLeftNewDTO.to_station_no,
name: t.queryLeftNewDTO.to_station_name, name: t.queryLeftNewDTO.to_station_name,
endpoint: t.queryLeftNewDTO.end_station_telecode == t.queryLeftNewDTO.to_station_telecode, endpoint: t.queryLeftNewDTO.end_station_telecode === t.queryLeftNewDTO.to_station_telecode,
time: t.queryLeftNewDTO.arrive_time time: t.queryLeftNewDTO.arrive_time
}, },
elapsedTime: { elapsedTime: {
@ -154,6 +156,41 @@
} }
} }
//处理跨站购票预售提醒
_.each(trainData.available, function (t) {
//非预售,或预售的非当天的,始发站的,则跳过
if (!t.selltime || Math.floor(new Date().getTime() / 86400000) !== Math.floor(t.selltime.getTime() / 86400000))
return;
//查询始发站起售时间
var firstStationSellTime = stationData.sellTime[t.start.code];
if (!firstStationSellTime)
return;
//判断始发站和当前站时间间隔。如果间隔超过指定的时间,则放弃建议
var spanSellCurrent = Math.floor((t.selltime.getTime() % 86400000) / 1000) + 8 * 3600; //需要加上时区
var spanSellNow = Math.floor((new Date().getTime() % 86400000) / 1000) + 8 * 3600;
var spanSellStart = utility.toTimeSpan(firstStationSellTime, true);
var timeDifference = Math.abs((spanSellCurrent - spanSellStart) / 60);
var isEarly = spanSellStart < spanSellCurrent;
var isStartInSell = spanSellNow >= spanSellStart;
var tCode = t.code[0];
//if (
// (tCode === 'G' && timeDifference > 120) //高铁超过2小时
// ||
// (tCode === 'D' && timeDifference > 180) //动车超过3小时
// ||
// ((tCode === 'Z' || tCode === 'T') && timeDifference > 360) //直达/特快超过6小时
// ||
// timeDifference > 600 //其它类型车次大于10小时
// )
// return;
t.preStationInfo = "<span class='train-nostarttip train-nostarttip-" + (isStartInSell ? "insell" : isEarly ? "early" : "later") + "'>";
t.preStationInfo += "始发站【<a href='javascript:;' data-ts-code='" + t.start.code + "' data-train-code='" + t.code + "' data-command='suggest-swtichrelate'>" + t.start.name + "</a>】起售时间为【" + firstStationSellTime + "】," + (isStartInSell ? "已经在售" : isEarly ? "比当前车站起售时间早,可先去看看" : "可稍后留意");
t.preStationInfo += "</span>";
});
return trainData; return trainData;
}; };

View File

@ -410,7 +410,7 @@
}).blur(function () { }).blur(function () {
queryTable.hide(); queryTable.hide();
}).keydown(function (e) { }).keydown(function (e) {
if (e.keyCode == 13) { if (e.keyCode === 13) {
var s = this.value; var s = this.value;
if (s) if (s)
exports.addTrainToList(s); exports.addTrainToList(s);
@ -666,6 +666,23 @@
initDateLoop(); initDateLoop();
initSeatOrder(); initSeatOrder();
initProfileOperation(); initProfileOperation();
//自动切换选项
$(document).on("click", "a[data-command='suggest-swtichrelate']", function () {
var code = this.dataset.tsCode;
var trainCode = this.dataset.trainCode;
//自动显示高级选项
if (!$("div.options-param").is(":visible")) {
$("div.options-param").click();
}
exports.addTrainToList(trainCode);
var ipt = $("#from_city");
ipt[0].dataset.code = code;
ipt[0].value = $.trim($(this).text());
ipt.change();
});
}; };
init(); init();
}); });

View File

@ -9,7 +9,7 @@
var port = require("../platform/extensionPort.js"); var port = require("../platform/extensionPort.js");
var loadSystemNotice = function () { var loadSystemNotice = function () {
$.get(loadUrl).done(function (json) { $.getJSON(loadUrl).done(function (json) {
var nowDate = new Date().getTime(); var nowDate = new Date().getTime();
json.lastLoad = new Date().getTime(); json.lastLoad = new Date().getTime();
if (savedNotice.lastReadId) { if (savedNotice.lastReadId) {

View File

@ -53,10 +53,12 @@
} }
for (var k in o) { for (var k in o) {
if (o.hasOwnProperty(k)) {
if (new RegExp("(" + k + ")").test(format)) { if (new RegExp("(" + k + ")").test(format)) {
format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length)); format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
} }
} }
}
return format; return format;
}; };
exports.formatSellDate = function (date) { exports.formatSellDate = function (date) {
@ -149,6 +151,22 @@
return encodeHTMLRules[m] || m; return encodeHTMLRules[m] || m;
}); });
}; };
/*
* 分析时间字符串并转换为相当于当天的秒数
*/
exports.toTimeSpan = function (str, includeHour) {
includeHour = typeof includeHour === 'undefined' ? true : includeHour;
var m = /(\d{1,2}):(\d{1,2})(:(\d{1,2}))?/i.exec(str);
if (!m) return null;
var th = m[4] || includeHour ? parseInt(m[1], 10) : 0;
var tm = parseInt(m[2], 10);
var ts = m[4] && !includeHour ? parseInt(m[4], 10) : 0;
return th * 3600 + tm * 60 + ts;
};
$.fn.toBase64Data = function () { $.fn.toBase64Data = function () {
var arr = []; var arr = [];
this.each(function () { this.each(function () {