spyEvent.php 1.11 KB
<?php
use Phalcon\Mvc\Model;

class SpyEvent extends \Phalcon\Mvc\Model
{
    public function getSource()
    {
        return "spy_event";
    }


    public function spyTimeAfter($project,$customer_id){
        return  self::query()
            ->columns(['customer_id', 'st.id, st.item_id', 'st.item_name', 'st.item_image', 'st.quantity', 'st.price', 'st.item_url', 'st.item_image'])
            ->rightJoin('spyStore', 'st.spy_event_id = SpyEvent.id', 'st')
            ->where("project_id = :project_id:")
            ->andWhere("action ='order_add'")
            ->andWhere("customer_id =$customer_id")
            ->bind(array("project_id" => $project->id))
            ->execute();

    }

    public function getSpyUsers($project, $modelsManager){

        $now = date("Y-m-d H:i:s");
        $date = new DateTime($now);
        $date->modify('-3 hours');
        $date = $date->format('Y-m-d H:i:s');

        $phql = "SELECT DISTINCT (customer_id) as id FROM SpyEvent WHERE project_id = {$project->id} AND action = 'order_add' AND date <=  '{$date}' ";

        return $modelsManager->executeQuery($phql)->toArray();

    }
}