<?php
namespace Smi\Controller;

use Think\Controller;

header("Content-Type:text/html;CharSet=UTF-8");
class StorageTransportController extends BaseController
{
    /**
     * 调货记录
     */
    public function orderList()
    {
        $where = 1;
        $order = "st.`id` DESC";
        $l = 10;//确定每页记录数
        $count = M("storageTransport")
            ->join("st LEFT JOIN `am_region_village` v ON st.`village_id`=v.`id`")
            ->join("LEFT JOIN `am_region_county` county ON v.`county_id`=county.`id`")
            ->join("LEFT JOIN `am_region_city` city ON county.`city_id`=city.`id`")
            ->join("LEFT JOIN `am_region_province` p ON city.`province_id`=p.`id`")
            ->join("LEFT JOIN `am_storage_dpc` dpc ON st.`deliveryman`=dpc.`id`")
            ->field("st.*,dpc.`name` AS `deliveryman`,v.`name` AS `village`,county.`name` AS `county`,city.`name` AS `city`,p.`name` AS `province`")
            ->where($where)
            ->count();// 查询满足要求的总记录数
        // 实例化分页类 传入总记录数和每页显示的记录数($l)
        $Page = new \Think\Page($count, $l);
        $show = $Page->show();// 分页显示输出
        $list = M("storageTransport")
            ->join("st LEFT JOIN `am_region_village` v ON st.`village_id`=v.`id`")
            ->join("LEFT JOIN `am_region_county` county ON v.`county_id`=county.`id`")
            ->join("LEFT JOIN `am_region_city` city ON county.`city_id`=city.`id`")
            ->join("LEFT JOIN `am_region_province` p ON city.`province_id`=p.`id`")
            ->join("LEFT JOIN `am_storage_dpc` dpc ON st.`deliveryman`=dpc.`id`")
            ->join("LEFT JOIN `am_goods` g ON st.`good_id`=g.`id`")
            ->field("st.*,dpc.`name` AS `deliveryman`,v.`name` AS `village`,county.`name` AS `county`,city.`name` AS `city`,p.`name` AS `province`,g.`goods_name`")
            ->where($where)
            ->order($order)
            ->limit($Page->firstRow . ',' . $Page->listRows)
            ->select();
        $this->assign('page', $show);// 赋值分页输出
        // 定义变量并显示模板
        $this->assign("list", $list);
        $this->display("orderList");die;
    }
}