ecstore二次开发新增定时任务crontab方法
ecstore二次开发新增定时任务crontab方法,下面以定时采集淘宝天猫评论来说明。
定时任务相关的文件和目录结构
文件中具体内容:
commmentcj/crontab.xml
同步淘宝天猫评论
*/10 * * * *
true
commentcj/lib/task/synctmallcomments
class commentcj_tasks_synctmallcomments implements base_interface_task{ #此类必须实现接口 base_interface_task
function rule() {
return '*/1 * * * *';
}
function exec($params=null) {
$this->sync_comments();
}
function description() {
return '同步淘宝天猫评论';
}
private function sync_comments()
{
$db = kernel::database();
$db -> exec("delete sdb_b2c_member_comments from sdb_b2c_member_comments ,
(select comment_id from sdb_b2c_member_comments group by comment having count(*)>1 ) as t2
where sdb_b2c_member_comments.comment_id=t2.comment_id");
$now = time()-300;
$sql = "SELECT goods_id,url,cjtime,price FROM sdb_b2c_goods WHERE disabled='false' AND url != '' AND (scctime< $now OR scctime = 0)";
$this->getComments($db->select($sql));
}
添加完成后台更新和维护下后台应用中心即可在定时任务列表中看到同步淘宝天猫评论。
如有任何疑问都可以直接联系QQ:2392521892来解答。
