1、定时任务所在文档:ewei_shopv2\core\inc\page.php
这里以修改拼团定时任务为例:
if (p('groups')) {
/*
* 拼团未付款订单自动取消
* */
$groups_order_lasttime = strtotime(m('cache')->getString('groups_order_cancelorder', 'global'));
$groups_order_interval = m('common')->getSysset('task')['groups_order_cancelorder_time'];
if (empty($groups_order_interval)) {
$groups_order_interval = 60;
}
//ycs 修改时间间隔为1s
//$groups_order_interval *= 60;
$groups_order_interval = 1;
//如果上次自动关闭时间小
$groups_order_current = time();
if ($groups_order_lasttime + $groups_order_interval <= $groups_order_current) {
m('cache')->set('groups_order_cancelorder', date('Y-m-d H:i:s', $groups_order_current), 'global');
ihttp_request($_W['siteroot'] . "addons/ewei_shopv2/plugin/groups/task/order.php", null, null, 10);
}
/*
* 拼团失败自动退款
* */
$groups_team_lasttime = strtotime(m('cache')->getString('groups_team_refund', 'global'));
$groups_team_interval = m('common')->getSysset('task')['groups_team_refund_time'];
if (empty($groups_team_interval)) {
$groups_team_interval = 60;
}
//ycs 修改时间间隔为1s
//$groups_team_interval *= 60;
$groups_team_interval = 1;
//如果上次自动关闭时间小
$groups_team_current = time();
if ($groups_team_lasttime + $groups_team_interval <= $groups_team_current) {
m('cache')->set('groups_team_refund', date('Y-m-d H:i:s', $groups_team_current), 'global');
ihttp_request($_W['siteroot'] . "addons/ewei_shopv2/plugin/groups/task/refund.php?uniacid={$_W['uniacid']}", null, null, 10);
}
/*
* 拼团发货自动收货
* */
$groups_receive_lasttime = strtotime(m('cache')->getString('groups_receive', 'global'));
$groups_receive_interval = m('common')->getSysset('task')['groups_receive_time'];
if (empty($groups_receive_interval)) {
$groups_receive_interval = 60;
}
//ycs 修改时间间隔为1s
//$groups_receive_interval *= 60;
$groups_receive_interval = 1;
//如果上次自动关闭时间小
$groups_receive_current = time();
if ($groups_receive_lasttime + $groups_receive_interval <= $groups_receive_current) {
m('cache')->set('groups_receive', date('Y-m-d H:i:s', $groups_receive_current), 'global');
ihttp_request($_W['siteroot'] . "addons/ewei_shopv2/plugin/groups/task/receive.php", null, null, 10);
}
}
2、定时任务是由用户在手机端打开网页或由管理员在后台点击网页触发。
可以将具体的定时任务添加到宝塔的计划任务定时执行。
比如添加拼团的3个定时任务的url为:
//拼团未付款订单自动取消
http://域名/addons/ewei_shopv2/plugin/groups/task/order.php
//拼团失败自动退款
http://域名/addons/ewei_shopv2/plugin/groups/task/refund.php
//拼团发货自动收货
http://域名/addons/ewei_shopv2/plugin/groups/task/receive.php