您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

详解ecshop后台订单自动确认开发

2025/12/18 6:14:00发布27次查看
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'] = 'http://www.wodeqingchun.com';    /* 版本号 */$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);}?>
四、
/languages/zh_cn/admin/order.php里加入:
$_lang['order_auto_croned'] = '此订单于 %s 已被确认';$_lang['order_auto_cron']   = '此订单于 %s 进行定时确认';$_lang['order_auto']        = '将此订单加入自动定时确认';$_lang['order_auto_time']   = '自动确认时间:';
五、
/admin/themes/order_info.htm在:{$lang.base_info}后面加入:
在此页面的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;}
还有/themes/default/footer.dwt里是否含有:
{insert name='query_info'}
这一句,比较重要,前人把这句去掉了,害最模板到处找原因。共涉及5个文件,两个新添加的
以上就是详解ecshop后台订单自动确认开发的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product