AdminOrderController.php 1.9 KB
<?php
/**
 * Created by PhpStorm.
 * User: ruidiudiu
 * Date: 2018/11/23
 * Time: 11:58
 */

namespace app\portal\controller;


use app\portal\model\EquipmentModel;
use app\portal\model\OrderModel;
use cmf\controller\AdminBaseController;
use EasyWeChat\Payment\Order;

/**
 * Class AdminOrderController
 * @package app\portal\controller
 * @adminMenuRoot(
 *     'name'   =>'订单统计',
 *     'action' =>'index',
 *     'parent' =>'',
 *     'display'=> true,
 *     'order'  => 1,
 *     'icon'   =>'th',
 *     'remark' =>'订单统计'
 * )
 */
class AdminOrderController extends AdminBaseController{

    public function index(){
        $param=$this->request->param();
        $where=array();
        if (!empty($param['order_no'])){
            $where['order_no']=['like','%'.$param['order_no'].'%'];
        }
        if (!empty($param['hospital'])){
            $where['hospital']=$param['hospital'];
        }

        if (!empty($param['start_number'])&&!empty($param['end_number'])){
            $where['serial_number']=['between',[$param['start_number'],$param['end_number']]];
        }
        $Order=new OrderModel();
        $data=$Order->alias('a')
            ->field('a.*,b.serial_number,b.hospital')
            ->join('equipment b','a.mac_address=b.mac_address')
            ->where($where)
            ->order('start_time','desc')
            ->paginate(10)->each(function ($item){
                $item['time']=($item['end_time']-$item['start_time']);
                return $item;
            });
        $this->assign('data',$data);
        $this->assign('hospital', isset($param['hospital']) ? $param['hospital'] : '');
        $this->assign('order_no', isset($param['order_no']) ? $param['order_no'] : '');
        $this->assign('start_number', isset($param['start_number']) ? $param['start_number'] : '');
        $this->assign('end_number', isset($param['end_number']) ? $param['end_number'] : '');
        return $this->fetch();
    }
}