链街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.

100 lines
3.7 KiB

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