链街Dcat后台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
3.1 KiB

  1. <?php
  2. namespace App\Admin\Renderable;
  3. use Dcat\Admin\Grid;
  4. use App\Admin\Common\Type;
  5. use Dcat\Admin\Grid\LazyRenderable;
  6. use App\Models\ImsCjdcOrderMain as OrderMainModel;
  7. use App\Models\v3\Market as MarketModel;
  8. class OrderDeliveryById extends LazyRenderable
  9. {
  10. protected $title = '配送记录';
  11. public function grid(): Grid
  12. {
  13. // 获取外部传递的参数
  14. $horsemanId = $this->horseman_id ?? 0;
  15. $startTime = $this->start_time ?? null;
  16. $endTime = $this->end_time ?? null;
  17. $model = OrderMainModel::where('type',1)->where('shipping_type',1)->whereIn('state',OrderMainModel::ORDER_STATE_REBATES);
  18. if($horsemanId > 0){
  19. $model->where('horseman_id',$horsemanId);
  20. }
  21. if($startTime){
  22. $model->where('created_at','>=',$startTime);
  23. }
  24. if($endTime){
  25. $model->where('created_at','<=',$endTime);
  26. }
  27. return Grid::make($model, function (Grid $grid) {
  28. $marketList = MarketModel::getMarketArray();
  29. $grid->column('horseman_id','配送员ID');
  30. // $grid->column('user_id','配送员姓名');
  31. $grid->column('global_order_id','订单编号');
  32. $grid->column('market_id','下单市场')->display(function($marketId) use($marketList){
  33. return $marketList[$marketId] ?? '';
  34. });
  35. $grid->column('state','状态')
  36. ->using(
  37. OrderMainModel::STATE_LIST
  38. );
  39. $grid->column('created_at','下单时间')->display(function($createdAt){
  40. return date('Y-m-d H:i:s',$createdAt);
  41. });
  42. // 搜索
  43. $grid->filter(function (Grid\Filter $filter) use($marketList){
  44. $filter->equal('user_id','下单用户懒ID')->width(3);
  45. $filter->equal('global_order_id','订单编号')->width(3);
  46. $filter->equal('market_id','下单市场')->select($marketList)->width(4);
  47. $filter->whereBetween('created_at',function($q){
  48. $start = $this->input['start'] ?? null;
  49. $end = $this->input['end'] ?? null;
  50. if($start !== null){
  51. $q->where('created_at','>=',strtotime($start));
  52. }
  53. if($end !== null){
  54. $q->where('created_at','<=',strtotime($end));
  55. }
  56. })->datetime()->width(7);
  57. });
  58. $grid->model()->orderBy('id','desc');
  59. // 每页10条
  60. $grid->paginate(10);
  61. $grid->disableActions();
  62. $grid->disableRowSelector();
  63. });
  64. }
  65. public function default()
  66. {
  67. // 获取外部传递的参数
  68. $horsemanId = $this->payload['horseman_id'] ?? 0;
  69. $startTime = $this->payload['start_time'] ? request()->input('start_time') : null;
  70. $endTime = $this->payload['end_time'] ? request()->input('end_time') : null;
  71. return [
  72. 'horseman_id' => $horsemanId,
  73. 'start_time' => $startTime,
  74. 'end_time' => $endTime,
  75. ];
  76. }
  77. }