这篇文章将为大家详细讲解有关如何实现ecshop后台订单自动确认功能,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
ecshop栏目介绍ecshop后台订单自动确认开发
CREATE TABLE `order_auto_confirm` (
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`order_id` INT(10) UNSIGNED NOT NULL DEFAULT '0',
`order_sn` VARCHAR(20) NOT NULL,
`execute_time` INT(10) UNSIGNED NOT NULL DEFAULT '0',
`order_status` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' COMMENT '0未确定,1已经确定',
`addtime` INT(10) UNSIGNED NOT NULL DEFAULT '0',
`update_time` INT(10) UNSIGNED NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE INDEX `order_id` (`order_id`),
INDEX `execute_time` (`execute_time`)
)
COMMENT='订单定期自动确定'
COLLATE='utf8_general_ci'
ENGINE=MyISAM;一、
/admin/order.php加入以下代码:
elseif($_REQUEST['act'] == 'order_cron')
{
$act1 = empty($_POST['act1']) ? 0 : $_POST['act1'];
if(empty($act1) || !in_array($act1, array('add', 'cancel'))) make_json_response('', -1, '未知请求act1'); $order_id = intval($_POST['order_id']);
$order = order_info($order_id);
if(empty($order)) make_json_response('', -2, '没有此订单ID'); if($order['order_status']) make_json_response('', -3, '此订单已经确认,不用自动确认'); if($order['pay_status']) make_json_response('', -4, '此订单支付状态已经变动,无法添加任务'); if($act1 == 'add'){
$order_cron_time = empty($_POST['order_cron_time']) ? 0 : $_POST['order_cron_time']; if(empty($order_cron_time)) make_json_response('', -10, '请求的时间错误'); $sql = 'select order_id from '.$ecs->table('order_auto_confirm').' where order_id='.$order_id;
$rs = $db->getRow($sql);
if($rs['order_id'] == $order_id){
make_json_response('', -30, '此订单任务已经存在,不能重复添加');
}
$execute_time = local_strtotime($order_cron_time);
$sql = "insert into ".$ecs->table('order_auto_confirm')."(order_id, order_sn, execute_time, order_status, addtime) values(".$order_id.",'".$order['order_sn']."',".$execute_time.", 0, ".local_gettime().")";
$result = $db->query($sql);
if($result){
make_json_response('', 0, '');
}
make_json_response('', -9, '添加任务计划失败');
}elseif($act1 == 'cancel'){
$sql = 'delete from '.$ecs->table('order_auto_confirm').' where order_id='.$order_id.' and order_status=0 ';
$db->query($sql);
make_json_response('', 0, '');
}
}二、
在elseif($_REQUEST['act'] == 'info')里加入:
//取自动确定订单信息
$sql = 'select order_status, execute_time, addtime, update_time from '.$ecs->table('order_auto_confirm').' where order_id='.$order['order_id'];
$cron= $db->getRow($sql);
if(!empty($cron)){
if($cron['order_status'] == 1)
$cron['update_time'] = sprintf($_LANG['order_auto_croned'], local_date('Y-m-d H:i:s', $cron['update_time']));
else
$cron['execute_time']= sprintf($_LANG['order_auto_cron'], local_date('Y-m-d H:i:s', $cron['execute_time']));
}
$smarty->assign('cron', $cron);三、
/includes/modules/cron/order_auto_confirm.php
if (!defined('IN_ECS'))
{
die('Hacking attempt');
}
require_once(ROOT_PATH . 'includes/lib_order.php');
$cron_lang = ROOT_PATH . 'languages/' .$GLOBALS['_CFG']['lang']. '/cron/order_auto_confirm.php';
if (file_exists($cron_lang))
{
global $_LANG; include_once($cron_lang);
}/* 模块的基本信息 */
if (isset($set_modules) && $set_modules == TRUE)
{
$i = isset($modules) ? count($modules) : 0; /* 代码 */
$modules[$i]['code'] = basename(__FILE__, '.php'); /* 描述对应的语言项 */
$modules[$i]['desc'] = 'order_auto_confirm_desc'; /* 作者 */
$modules[$i]['author'] = 'wjzhhr'; /* 网址 */
$modules[$i]['website'] = ''; /* 版本号 */
$modules[$i]['version'] = '1.0.0'; /* 配置信息 */
$modules[$i]['config'] = array(
array('name' => 'order_auto_confirm_count', 'type' => 'select', 'value' => '10'),
); return;
}
$time = gmtime();
//$time = local_gettime();
$limit = empty($cron['order_auto_confirm_count']) ? 5 : $cron['order_auto_confirm_count'];
$sql = "SELECT * FROM " . $GLOBALS['ecs']->table('order_auto_confirm') . " WHERE execute_time <= ".$time." and order_status=0 LIMIT $limit";
$autodb= $db->getAll($sql);
$i = 0;
foreach ($autodb as $key => $val)
{
$order_id = $val['order_id'];
$order_sn = $val['order_sn'];
/* 标记订单为已确认 */
$update_status = update_order($order_id, array('order_status' => OS_CONFIRMED, 'confirm_time' => gmtime()));
update_order_amount($order_id); /* 记录log */
$action_note = "计划任务:定期自动确定订单,订单号:".$order_sn.",执行状态:".($update_status ? '成功' : '失败');
order_action($order_sn, OS_CONFIRMED, SS_UNSHIPPED, PS_UNPAYED, $action_note, 'system_cron'); /* 如果原来状态不是“未确认”,且使用库存,且下订单时减库存,则减少库存 */
if ($val['order_status'] != OS_UNCONFIRMED && $_CFG['use_storage'] == '1' && $_CFG['stock_dec_time'] == SDT_PLACE)
{
change_order_goods_storage($order_id, true, SDT_PLACE);
} if($update_status)
{
$i += 1;
$sql = "update " . $GLOBALS['ecs']->table('order_auto_confirm') . " set order_status=1, update_time=".$time." where order_id=".$order_id;
$db->query($sql);
}
}$string = '此次共更新:'.$i.'条数据';
echo $string;file_put_contents('./a.txt', $time . '----' . date('Y-m-d H:i:s').$string."\r\n", FILE_APPEND);
/**
* 更新订单总金额
* @param int $order_id 订单id
* @return bool
//zuimoban.com
*/
function update_order_amount($order_id)
{
include_once(ROOT_PATH . 'includes/lib_order.php');
//更新订单总金额
$sql = "UPDATE " . $GLOBALS['ecs']->table('order_info') .
" SET order_amount = " . order_due_field() .
" WHERE order_id = '$order_id' LIMIT 1"; return $GLOBALS['db']->query($sql);
}
?>
郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。