柳暗花明笔记

    kohana minion 用来做定时任务好方便

    所属分类:[ php&web ] 猫哲学家 发表于:2014-12-24 11:16 浏览:866

    class Task_UpdateOrderStatus extends Minion_Task {

    /**
    * Generates a help list for all tasks
    *
    * @return null
    */
    protected $_options = array();

    protected function _execute(array $params) {

    $more_than_time = (int) Kohana::$config->load('site.update_order');

    $more_than_time = $more_than_time == 0 ? 14400 : $more_than_time;

    $results = DB::select('id')
    ->from('orders')
    ->where('order_status_id', '=', 3)
    // ->where('now - payment_time', '>=', $more_than_time)
    ->where('payment_time', '<=', time() - $more_than_time)
    ->execute()
    ->as_array();

    if (empty($results)) {
    exit('No Order To Update.');
    }

    foreach ($results as $r)
    {
    $order_id = $r['id'];
    $order = ORM::factory('Order', $order_id);
    if ($order->loaded())
    {
    $order->update_status(5, 'Order is in process.');
    }
    }

    Util::add_dblog('UPDATE_ORDER_STATUS', count($results).' Batch update order status.');
    }

    }

    crontab执行

    /var/www/moviemyshare.com/modules/minion/minion --task=UpdateOrderStatus

    标签: kohana 
    上一编文章 centos linux命令crontab tail 下一编文章 php好用的register_shutdown_function
    最近文章
    发表评论