您现在的位置是:首页 > cms教程 > Ecshop商城教程Ecshop商城教程
ecshop商品订单自动确认二次开发教程
周放大2024-01-16Ecshop商城教程已有人查阅
导读通过本教程可以实现ECSHOP商城订单自动确认!1、运行sql代码,生成数据库CREATE TABLE `ecs_order_auto_confirm`
通过本教程可以实现ECSHOP商城订单自动确认!
1、运行sql代码,生成数据库
CREATE TABLE `ecs_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;
2./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 '.$GLOBALS['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 ".$GLOBALS['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 '.$GLOBALS['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 '.$GLOBALS['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);
2.新建php文件/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'] = '超神学院'; /* 网址 */ $modules[$i]['website'] = 'http://www.ebingou.cn'; /* 版本号 */ $modules[$i]['version'] = '1.0.0'; /* 配置信息 */ $modules[$i]['config'] = array( array('name' => 'order_auto_confirm_count', 'type' => 'select', 'value' => '10'), ); return;}$time = gmtime();$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 */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);}?>
3.新建php文件/languages/zh_cn/cron/order_auto_confirm.php
global $_LANG;$_LANG['order_auto_confirm'] = '订单定期自动确定';
$_LANG['order_auto_confirm_desc'] = '定期自动确定订单';$_LANG['order_auto_confirm_count'] = '每次处理记录个数';$_LANG['order_auto_confirm_count_range']['5'] = '5';$_LANG['order_auto_confirm_count_range']['10'] = '10';$_LANG['order_auto_confirm_count_range']['15'] = '15';$_LANG['order_auto_confirm_count_range']['20'] = '20';?>
4.在/languages/zh_cn/admin/order.php里加入:
/* 订单自动确认 */$_LANG['order_auto_croned'] = '此订单于 %s 已被确认';$_LANG['order_auto_cron'] = '此订单于 %s 进行定时确认';$_LANG['order_auto'] = '将此订单加入自动定时确认';$_LANG['order_auto_time'] = '自动确认时间:';
5./admin/themes/order_info.htm 在:{$lang.base_info}后面加入:
<!--{if $order.status == 0 && $order.pay_status == 0 }-->
<script type="text/javascript" src="../js/calendar.php?lang={$cfg_lang}"></script>
<link href="../js/calendar/calendar.css" rel="stylesheet" type="text/css" />
<div id="order_auto_cron" style="display: inline-block; width: 300px;">
<!--{if !$cron}-->
<a href="javascript:;" id="ccd" onclick="document.getElementById('select_time').style.display=''; this.style.display='none';">{$lang.order_auto}</a>
<span id="select_time" style="display: none;">{$lang.order_auto_time}
<input type="text" id="order_cron_time" value="" onclick="return showCalendar('order_cron_time', '%Y-%m-%d %H:%M:%S', '24', false, 'order_cron_time');" name="order_cron_time">
<input type="button" value="保存" id="ccd_save" class="button" onclick="order_cron({$order.order_id}, 'add');">
<a href="javascript:;" onclick="document.getElementById('select_time').style.display='none'; document.getElementById('ccd').style.display='';">{$lang.op_cancel}</a>
</span>
<!--{elseif $cron.order_status == 0}-->
{$cron.execute_time}
<a href="javascript:;" onclick="if(confirm('确定要删除定时执行任务吗?')){order_cron({$order.order_id}, 'cancel');}else{return false;}">{$lang.op_cancel}</a>
<!--{else $cron.order_status == 1}-->
{$cron.update_time}
<!--{/if}-->
</div>
<!--{/if}-->
在此页面的JS里面加入:
function order_cron(order_id, act){ var order_cron_time = 0; if(act == 'add'){ order_cron_time = document.getElementById('order_cron_time').value; if(!order_cron_time){ alert('无法获取时间'); return false; } } Ajax.call('order.php?act=order_cron', 'order_id=' + order_id + '&act1=' + act + '&order_cron_time=' + order_cron_time, order_cron_response, 'POST', 'JSON');}function order_cron_response(res){ if (res.error == 0){ alert('保存成功'); } else{ alert(res.message); } return false;}
6.需保证在themes\default\library\page_footer.lbi文件中存在
{insert name='query_info'}
7.到后台"系统设置"->"计划任务"点击安装
大功告成,以后订单按时自动确认了
1、运行sql代码,生成数据库
CREATE TABLE `ecs_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;
2./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 '.$GLOBALS['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 ".$GLOBALS['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 '.$GLOBALS['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 '.$GLOBALS['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);
2.新建php文件/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'] = '超神学院'; /* 网址 */ $modules[$i]['website'] = 'http://www.ebingou.cn'; /* 版本号 */ $modules[$i]['version'] = '1.0.0'; /* 配置信息 */ $modules[$i]['config'] = array( array('name' => 'order_auto_confirm_count', 'type' => 'select', 'value' => '10'), ); return;}$time = gmtime();$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 */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);}?>
3.新建php文件/languages/zh_cn/cron/order_auto_confirm.php
global $_LANG;$_LANG['order_auto_confirm'] = '订单定期自动确定';
$_LANG['order_auto_confirm_desc'] = '定期自动确定订单';$_LANG['order_auto_confirm_count'] = '每次处理记录个数';$_LANG['order_auto_confirm_count_range']['5'] = '5';$_LANG['order_auto_confirm_count_range']['10'] = '10';$_LANG['order_auto_confirm_count_range']['15'] = '15';$_LANG['order_auto_confirm_count_range']['20'] = '20';?>
4.在/languages/zh_cn/admin/order.php里加入:
/* 订单自动确认 */$_LANG['order_auto_croned'] = '此订单于 %s 已被确认';$_LANG['order_auto_cron'] = '此订单于 %s 进行定时确认';$_LANG['order_auto'] = '将此订单加入自动定时确认';$_LANG['order_auto_time'] = '自动确认时间:';
5./admin/themes/order_info.htm 在:{$lang.base_info}后面加入:
<!--{if $order.status == 0 && $order.pay_status == 0 }-->
<script type="text/javascript" src="../js/calendar.php?lang={$cfg_lang}"></script>
<link href="../js/calendar/calendar.css" rel="stylesheet" type="text/css" />
<div id="order_auto_cron" style="display: inline-block; width: 300px;">
<!--{if !$cron}-->
<a href="javascript:;" id="ccd" onclick="document.getElementById('select_time').style.display=''; this.style.display='none';">{$lang.order_auto}</a>
<span id="select_time" style="display: none;">{$lang.order_auto_time}
<input type="text" id="order_cron_time" value="" onclick="return showCalendar('order_cron_time', '%Y-%m-%d %H:%M:%S', '24', false, 'order_cron_time');" name="order_cron_time">
<input type="button" value="保存" id="ccd_save" class="button" onclick="order_cron({$order.order_id}, 'add');">
<a href="javascript:;" onclick="document.getElementById('select_time').style.display='none'; document.getElementById('ccd').style.display='';">{$lang.op_cancel}</a>
</span>
<!--{elseif $cron.order_status == 0}-->
{$cron.execute_time}
<a href="javascript:;" onclick="if(confirm('确定要删除定时执行任务吗?')){order_cron({$order.order_id}, 'cancel');}else{return false;}">{$lang.op_cancel}</a>
<!--{else $cron.order_status == 1}-->
{$cron.update_time}
<!--{/if}-->
</div>
<!--{/if}-->
在此页面的JS里面加入:
function order_cron(order_id, act){ var order_cron_time = 0; if(act == 'add'){ order_cron_time = document.getElementById('order_cron_time').value; if(!order_cron_time){ alert('无法获取时间'); return false; } } Ajax.call('order.php?act=order_cron', 'order_id=' + order_id + '&act1=' + act + '&order_cron_time=' + order_cron_time, order_cron_response, 'POST', 'JSON');}function order_cron_response(res){ if (res.error == 0){ alert('保存成功'); } else{ alert(res.message); } return false;}
6.需保证在themes\default\library\page_footer.lbi文件中存在
{insert name='query_info'}
7.到后台"系统设置"->"计划任务"点击安装
大功告成,以后订单按时自动确认了
本文标签:
很赞哦! ()
图文教程
ecshop后台开发模块步骤实例
第一步首先我们用phpmyadmin建一个支付表,表名:ecs_pay表字段:pay_id,pay_name,pay_info,pay_bank,pay_credit,pay_state第二步添加到后台左侧导航栏并配置权限和相关语言包
ecshop模板机制原理和数据处理介绍
一、模板引擎:ECshop给我的第一印象是用的smarty模板引擎,可是很快就发现有些不一样,使用smarty模板引擎的系统通常会至少会包括smarty的核心文件:smarty.class.php、smarty_Co
ecshop商品页怎么显示当前登录会员等级价格
很多会员经常问这样一个问题,怎么让ECSHOP模板的商品详情页面显示当前会员等级的价格?这个其实不是很复杂,下面给大家说一下实现方法
ecshop4.0h5网路错误解决方案实例
ECSHOP4.0安装以后很多人出现ECSHOP H5网路错误,pc端和和H5 通信失败问题,代码号排查解决ECSHOP4.0 h5网路错误方案。
相关源码
-
(PC+WAP)蓝色新能源环保太阳能光伏模板pbootcms下载新能源环保行业网站解决方案为太阳能光伏系统企业打造的专业网站模板,助力新能源企业高效展示产品与服务PbootCMS内核开发,源码开放可修改PC与手机端自适应设计查看源码 -
帝国cms7.5品牌连锁店招商加盟商机网站模版源码本模板为招商加盟、创业投资、品牌连锁等商业领域设计,采用帝国CMS7.5内核构建,整体风格简洁大气,突出商业信任感与专业度,适合各类招商加盟项目展示、品牌连锁店宣传等商业应用场景。查看源码 -
(自适应)pbootcms家政服务保洁保姆打扫卫生网站模板下载本模板基于PbootCMS内核开发,为家政服务企业量身定制。设计风格温馨亲切,突出家政行业的专业与贴心服务特性,多方位展示企业服务项目与优势。查看源码 -
(PC+WAP)蓝色智能环保机械设备网站营销型pbootcms模板下载本模板基于PbootCMS系统开发,为环保设备制造企业设计,特别适合展示环保机械、智能装备等产品。采用响应式技术,确保各类设备参数和技术方案在不同终端上都能清晰展示。查看源码 -
pbootcms模板(自适应手机版)红色响应式单位机构类网站自适应响应式单位机构网站模板 | PbootCMS内核开发为机构组织设计的响应式网站模板,采用PbootCMS内核开发,支持一键替换行业内容,满足多元化场景需求。查看源码 -
(自适应)代理记账财务会计咨询服务个人公司网站模板该响应式网站模板为代理记账、财政咨询及财务会计类企业设计,基于PbootCMS内核开发。通过自适应手机端的HTML5技术,帮助企业高效构建专业财税服务平台查看源码
| 分享笔记 (共有 篇笔记) |
