Skip to content

Commit

Permalink
新增秒杀
Browse files Browse the repository at this point in the history
  • Loading branch information
taoshihan1991 committed Dec 3, 2020
1 parent d822a79 commit e93b42c
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 29 deletions.
4 changes: 2 additions & 2 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ var (
)
var serverCmd = &cobra.Command{
Use: "server",
Short: "example:miaosha server port 8081",
Short: "example:miaosha server port 8082",
Example: "go-fly server -c config/",
Run: func(cmd *cobra.Command, args []string) {
run()
},
}

func init() {
serverCmd.PersistentFlags().StringVarP(&port, "port", "p", "8081", "监听端口号")
serverCmd.PersistentFlags().StringVarP(&port, "port", "p", "8082", "监听端口号")
serverCmd.PersistentFlags().BoolVarP(&daemon, "daemon", "d", false, "是否为守护进程模式")
}
func run() {
Expand Down
13 changes: 6 additions & 7 deletions front/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,18 @@
<title>菜地秒杀-天天低价/限时限量</title>
<link rel="stylesheet" type="text/css" href="css/detail.css"/>
<script src="js/jquery-1.10.2.js"></script>
<script src="js/leftTime.min.js"></script>
<script src="js/config.js"></script>
<script src="js/detail.js"></script>
</head>
<body>
<div>
<div class="title">电采暖取暖器</div>
<div class="price">秒杀价: ¥1</div>
<div class="title" id="title">电采暖取暖器</div>
<div class="price" >秒杀价: ¥<span id="price"></span></div>
<div class="count-time">
<span class="time-item d">00</span>
<span class="time-item h">00</span>
<span class="time-item m">00</span>
<span class="time-item s">00</span>
<span class="time-item d" id="d">00</span>
<span class="time-item h" id="h">00</span>
<span class="time-item m" id="m">00</span>
<span class="time-item s" id="s">00</span>
</div>
<div class="buyBtn"><a href="javascript:void(0)" class="btn btn-disabled">立即抢购</a></div>
</div>
Expand Down
41 changes: 27 additions & 14 deletions front/static/js/detail.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
$.leftTime(countTime,function(d){
if(d.status){
var $dateShow1=$(".count-time");
$dateShow1.find(".d").html(d.d);
$dateShow1.find(".h").html(d.h);
$dateShow1.find(".m").html(d.m);
$dateShow1.find(".s").html(d.s);
//d.status 状态
//d.d 天
//d.h 时
//d.m 分
//d.s 秒
}
});
function fix(num, length) {
console.log(num);
// 数字转化为字符串 进行拼接
return num.toString().length<length?'0'+num:num;
}

$(function () {
$.ajax({
type: "GET",
url: api+"/product?id=1",
success: function(res) {
var data=res.data;
$("#title").html(data.title);
$("#price").html(data.price);
$.leftTime(countTime,function(d){
if(d.status){
var $dateShow1=$(".count-time");
$dateShow1.find(".d").html(d.d);
$dateShow1.find(".h").html(d.h);
$dateShow1.find(".m").html(d.m);
$dateShow1.find(".s").html(d.s);
}
});
}
});

})
109 changes: 104 additions & 5 deletions front/static/js/leftTime.min.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,104 @@
(function(y,g){Date.prototype.format=function(a){var d={"M+":this.getMonth()+1,"d+":this.getDate(),"h+":this.getHours(),"m+":this.getMinutes(),"s+":this.getSeconds(),"q+":Math.floor((this.getMonth()+3)/3),S:this.getMilliseconds()};/(y+)/.test(a)&&(a=a.replace(RegExp.$1,(this.getFullYear()+"").substr(4-RegExp.$1.length)));for(var c in d)(new RegExp("("+c+")")).test(a)&&(a=a.replace(RegExp.$1,1==RegExp.$1.length?d[c]:("00"+d[c]).substr((""+d[c]).length)));return a};g.leftTime=function(a,d,c){function w(a){return-1!=
a.indexOf("-")||-1!=a.indexOf("/")?!0:!1}function g(a){return/^(20|21|22|23|[0-1]\d):[0-5]\d$/.test(y.trim(a))?!0:!1}function r(a){10>a&&c&&(a="0"+a);return a}function z(){if("string"===typeof a||"number"===typeof a){var b=(new Date).getTime(),c;"string"===typeof a||12<=a.toString().length?(a="string"===typeof a&&1==w(a)?a.replace(/-/g,"/"):a,c=(new Date(a)).getTime(),b=c-b):(c=a-A.count,b=1E3*c,A.count++);0<b?(h=Math.floor(b/1E3/60/60/24),k=Math.floor(b/1E3/60/60%24),l=Math.floor(b/1E3/60%60),m=
Math.floor(b/1E3%60),n=!0):(window.clearInterval(e),m=l=k=h=0,n=!1)}else"object"===typeof a&&(b=(new Date).getTime()+(0<t?-1*t:Math.abs(t)),c=0,u<f?(c=f,v=1):u>=f&&u<p?(c=p,v=2):u>=p&&(v=3),b=c-b,0<b?(h=Math.floor(b/1E3/60/60/24),k=Math.floor(b/1E3/60/60%24),l=Math.floor(b/1E3/60%60),m=Math.floor(b/1E3%60),n=!0):(window.clearInterval(e),m=l=k=h=0,n=!1));b={d:r(h),h:r(k),m:r(l),s:r(m)};b.status=n;b.step=v;if(d&&"function"===typeof d)return d(b)}var e=this.timer;c||0==c||(c=!0);var A={count:0},h=0,
k=0,l=0,m=0,v=0,n=!1;if("object"===typeof a){a.init||1==a.init||(a.init=!1);var t=0,x,q=0;if(0!=a.setday||"0"!=a.setday)q=864E5*parseInt(a.setday);a.nowdate&&null!=a.nowdate&&void 0!=a.nowdate&&"undefined"!=a.nowdate?(t=(new Date).getTime()-parseInt(a.nowdate),x=new Date(a.nowdate)):(a.nowdate=(new Date).getTime(),x=new Date);var q=new Date(parseInt(a.nowdate)+q),f=0,p=0;0==a.startdate||"0"==a.startdate||a.init||("string"===typeof a.startdate?w(a.startdate)?f=(new Date(a.startdate.replace(/-/g,"/"))).getTime():
g(a.startdate)&&(f=(new Date(q.format("yyyy/MM/dd")+" "+a.startdate)).getTime()):"number"===typeof a.startdate&&(f=a.startdate));if(0!=a.enddate||"0"!=a.enddate)"string"===typeof a.enddate?w(a.enddate)?p=(new Date(a.enddate.replace(/-/g,"/"))).getTime():g(a.enddate)&&(p=(new Date(q.format("yyyy/MM/dd")+" "+a.enddate)).getTime()):"number"===typeof a.enddate&&(f=a.enddate);var u=x.getTime()}z();e=setInterval(z,1E3);if("undefined"!=e||null!=e||void 0!=e)return e};y.extend(g)})(jQuery||zepto,{});
(function(y, g) {
Date.prototype.format = function(a) {
var d = {
"M+": this.getMonth() + 1,
"d+": this.getDate(),
"h+": this.getHours(),
"m+": this.getMinutes(),
"s+": this.getSeconds(),
"q+": Math.floor((this.getMonth() + 3) / 3),
S: this.getMilliseconds()
};
/(y+)/.test(a) && (a = a.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length)));
for (var c in d)
(new RegExp("(" + c + ")")).test(a) && (a = a.replace(RegExp.$1, 1 == RegExp.$1.length ? d[c] : ("00" + d[c]).substr(("" + d[c]).length)));
return a
}
;
g.leftTime = function(a, d, c) {
function w(a) {
return -1 != a.indexOf("-") || -1 != a.indexOf("/") ? !0 : !1
}
function g(a) {
return /^(20|21|22|23|[0-1]\d):[0-5]\d$/.test(y.trim(a)) ? !0 : !1
}
function r(a) {
10 > a && c && (a = "0" + a);
return a
}
function z() {
if ("string" === typeof a || "number" === typeof a) {
var b = (new Date).getTime(), c;
"string" === typeof a || 12 <= a.toString().length ? (a = "string" === typeof a && 1 == w(a) ? a.replace(/-/g, "/") : a,
c = (new Date(a)).getTime(),
b = c - b) : (c = a - A.count,
b = 1E3 * c,
A.count++);
0 < b ? (h = Math.floor(b / 1E3 / 60 / 60 / 24),
k = Math.floor(b / 1E3 / 60 / 60 % 24),
l = Math.floor(b / 1E3 / 60 % 60),
m = Math.floor(b / 1E3 % 60),
n = !0) : (window.clearInterval(e),
m = l = k = h = 0,
n = !1)
} else
"object" === typeof a && (b = (new Date).getTime() + (0 < t ? -1 * t : Math.abs(t)),
c = 0,
u < f ? (c = f,
v = 1) : u >= f && u < p ? (c = p,
v = 2) : u >= p && (v = 3),
b = c - b,
0 < b ? (h = Math.floor(b / 1E3 / 60 / 60 / 24),
k = Math.floor(b / 1E3 / 60 / 60 % 24),
l = Math.floor(b / 1E3 / 60 % 60),
m = Math.floor(b / 1E3 % 60),
n = !0) : (window.clearInterval(e),
m = l = k = h = 0,
n = !1));
b = {
d: r(h),
h: r(k),
m: r(l),
s: r(m)
};
b.status = n;
b.step = v;
if (d && "function" === typeof d)
return d(b)
}
var e = this.timer;
c || 0 == c || (c = !0);
var A = {
count: 0
}
, h = 0
, k = 0
, l = 0
, m = 0
, v = 0
, n = !1;
if ("object" === typeof a) {
a.init || 1 == a.init || (a.init = !1);
var t = 0, x, q = 0;
if (0 != a.setday || "0" != a.setday)
q = 864E5 * parseInt(a.setday);
a.nowdate && null != a.nowdate && void 0 != a.nowdate && "undefined" != a.nowdate ? (t = (new Date).getTime() - parseInt(a.nowdate),
x = new Date(a.nowdate)) : (a.nowdate = (new Date).getTime(),
x = new Date);
var q = new Date(parseInt(a.nowdate) + q)
, f = 0
, p = 0;
0 == a.startdate || "0" == a.startdate || a.init || ("string" === typeof a.startdate ? w(a.startdate) ? f = (new Date(a.startdate.replace(/-/g, "/"))).getTime() : g(a.startdate) && (f = (new Date(q.format("yyyy/MM/dd") + " " + a.startdate)).getTime()) : "number" === typeof a.startdate && (f = a.startdate));
if (0 != a.enddate || "0" != a.enddate)
"string" === typeof a.enddate ? w(a.enddate) ? p = (new Date(a.enddate.replace(/-/g, "/"))).getTime() : g(a.enddate) && (p = (new Date(q.format("yyyy/MM/dd") + " " + a.enddate)).getTime()) : "number" === typeof a.enddate && (f = a.enddate);
var u = x.getTime()
}
z();
e = setInterval(z, 1E3);
if ("undefined" != e || null != e || void 0 != e)
return e
}
;
y.extend(g)
}
)(jQuery || zepto, {});
1 change: 0 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD87
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
github.com/go-playground/validator/v10 v10.2.0 h1:KgJ0snyC2R9VXYN2rneOtQcw5aHQB1Vv0sFl1UcHBOY=
github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI=
github.com/go-redis/redis v6.15.9+incompatible h1:K0pv1D7EQUjfyoMql+r/jZqCLizCGKFlFgcHWWmHQjg=
github.com/go-redis/redis/v8 v8.4.0 h1:J5NCReIgh3QgUJu398hUncxDExN4gMOHI11NVbVicGQ=
github.com/go-redis/redis/v8 v8.4.0/go.mod h1:A1tbYoHSa1fXwN+//ljcCYYJeLmVrwL9hbQN45Jdy0M=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
Expand Down

0 comments on commit e93b42c

Please sign in to comment.