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.
|
|
<?php
namespace App\Admin\Repositories;
use App\Models\ImsCjdcOrderMain as Model;use Dcat\Admin\Grid;use Dcat\Admin\Repositories\EloquentRepository;use Illuminate\Support\Facades\DB;use Illuminate\Support\Facades\Session;
class ImsCjdcOrderMain extends EloquentRepository{ /** * Model. * * @var string */ protected $eloquentClass = Model::class;
public function get(Grid\Model $model) { $builder = new \App\Models\ImsCjdcOrderMain(); $time = request()->input('time'); $state = request()->input('order_state')??false; $builder = $builder::leftJoin('lanzu_user','lanzu_user.id','lanzu_order_main.user_id') ->with('market') ->select('lanzu_order_main.*','lanzu_user.nick_name') ->where('type',1) ->orderBy('lanzu_order_main.id','desc');//只取线上订单数据
if ($time){ $builder = $builder->where('lanzu_order_main.created_at','>',$time); }
if ($state==3){ $builder = $builder->where('state',$state)->where('shipping_type',1)->where('horseman_id',0); }elseif ($state==311){ $builder = $builder->where('state',3)->where('shipping_type',1)->where('horseman_id','>',0); }else{ $state !=false?$builder->where('state',$state):false; } $this->setSort($model); $this->setPaginate($model);
$query = $builder; $model->getQueries()->unique()->each(function ($value) use (&$query) { if ($value['method'] == 'paginate') { $value['arguments'][1] = $this->getGridColumns(); } elseif ($value['method'] == 'get') { $value['arguments'] = [$this->getGridColumns()]; }elseif ($value['method']=='whereBetween'){ if ($value['arguments'][0]=='created_at'){ $value['arguments'][0] = 'lanzu_order_main.created_at'; $value['arguments'][1][0] = strtotime($value['arguments'][1][0]); $value['arguments'][1][1] = strtotime($value['arguments'][1][1]); } }elseif ($value['method']=='where'){ if ($value['arguments'][0]=='store_id'){ $query->leftJoin('lanzu_order','lanzu_order.order_main_id','lanzu_order_main.global_order_id'); $value['arguments'][0]='lanzu_order.store_id'; } } $query = call_user_func_array([$query, $value['method']], $value['arguments'] ?? []); });
$query = $query->toArray(); //如果订单状态为配送中 将state设置为31
foreach ($query['data'] as &$value){ if ($value['state']==3&&$value['shipping_type']==1&&!empty($value['horseman_id'])){ $value['state'] = 311; } }
$query = $model->makePaginator($query['total'],$query['data']); return $query; }}
|