<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Administrator
 * Date: 17-12-19
 * Time: 下午3:14
 * To change this template use File | Settings | File Templates.
 */
class Product_SwapProductController extends Ec_Controller_Action
{
    public function preDispatch()
    {
        $this->tplDirectory = "product/views/product/";
        //$this->serviceClass = new Service_SwapOrderDetail();
        $userAuth = new Zend_Session_Namespace('userAuthorization');
        $this->user_id = $userAuth->userId;
    }

    /*产品列表*/
    public function listAction(){
        if ($this->_request->isPost()) {
            $page = $this->_request->getParam('page', 1);
            $pageSize = $this->_request->getParam('pageSize', 20);

            $page = $page ? $page : 1;
            $pageSize = $pageSize ? $pageSize : 20;

            $return = array(
                "state" => 0,
                "message" => "No Data"
            );
            $condition['product_barcode'] = $this->_request->getParam('product_barcode', "");
            $condition['product_sku'] = $this->_request->getParam('product_sku', "");
            $condition['customer_code'] = $this->_request->getParam('customer_code', "");

            $count = Service_SwapProduct::getByCondition($condition, 'count(*)');
            $return['total'] = $count;

            if ($count) {

                $rows = Service_SwapProduct::getByCondition($condition,"*", $pageSize, $page);
                $return['data'] = $rows;
                $return['state'] = 1;
                $return['message'] = "";
            }
            die(Zend_Json::encode($return));
        }
        echo Ec::renderTpl($this->tplDirectory . "swap_product_index.tpl", 'layout');
    }
}
