horseman_id ?? 0; $startTime = $this->start_time ?? null; $endTime = $this->end_time ?? null; $marketId = $this->market_id ?? 0; $model = OrderMainModel::where('type', OrderMainModel::ORDER_TYPE_ONLINE) ->where('shipping_type', OrderMainModel::ORDER_SHIPPING_TYPE_MARKET) ->whereIn('state',OrderMainModel::ORDER_STATE_FINISH) ->where('created_at','>=',strtotime('2020-10-01 00:00:00'));; if($horsemanId > 0){ $model->where('horseman_id',$horsemanId); } if($startTime){ $startTime = $startTime.' 00:00:00'; $model->where('created_at','>=',strtotime($startTime)); } if($endTime){ $endTime = $endTime.' 23:59:59'; $model->where('created_at','<=',strtotime($endTime)); } return Grid::make($model, function (Grid $grid) use($marketId){ $marketList = MarketModel::getMarketArray(); $grid->column('global_order_id','订单编号'); $grid->column('market_id','下单市场')->display(function($marketId) use($marketList){ return $marketList[$marketId] ?? ''; }); $grid->column('state','状态') ->using( OrderMainModel::STATE_LIST ); $grid->column('delivery_money','配送费')->display(function($delivery_money){ $baseFee = config('admin.delivery.base_fee',0); return $delivery_money + $baseFee; }); $grid->column('created_at','下单时间')->display(function($createdAt){ return date('Y-m-d H:i:s',$createdAt); }); // 搜索 $grid->filter(function (Grid\Filter $filter) use($marketList, $marketId){ $filter->equal('user_id','下单用户懒ID')->width(4); $filter->equal('global_order_id','订单编号')->width(4); if(!$marketId){ $filter->equal('market_id','下单市场')->select($marketList)->width(4); } $filter->whereBetween('created_at',function($q){ $start = $this->input['start'] ?? null; $end = $this->input['end'] ?? null; if($start !== null){ $q->where('created_at','>=',strtotime($start)); } if($end !== null){ $q->where('created_at','<=',strtotime($end)); } })->datetime()->width(7); }); $grid->model()->orderBy('id','desc'); // 每页10条 $grid->paginate(10); $grid->disableActions(); $grid->disableRowSelector(); }); } public function default() { // 获取外部传递的参数 $horsemanId = $this->payload['horseman_id'] ?? 0; $startTime = $this->payload['start_time'] ?? request()->input('start_time', null); $endTime = $this->payload['end_time'] ?? request()->input('end_time', null); $marketId = $this->payload['market_id'] ?? 0; return [ 'horseman_id' => $horsemanId, 'start_time' => $startTime, 'end_time' => $endTime, 'market_id' => $marketId, ]; } }