2 changed files with 257 additions and 0 deletions
-
136app/Admin/Controllers/v3/OrderDeliveryReportController.php
-
121app/Admin/Repositories/v3/OrderDeliveryReport.php
@ -0,0 +1,136 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Controllers\v3; |
||||
|
|
||||
|
use App\Admin\Actions\Grid\v3\DataReportOption; |
||||
|
use App\Admin\Actions\Tools\GoodsReportExport; |
||||
|
use App\Admin\Common\Auth; |
||||
|
use App\Admin\Repositories\v3\GoodsReport; |
||||
|
|
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Controllers\AdminController; |
||||
|
use App\Models\v3\Market as MarketModel; |
||||
|
use App\Models\v3\Store as StoreModel; |
||||
|
|
||||
|
use Dcat\Admin\Grid\Filter; |
||||
|
|
||||
|
use Illuminate\Http\Request; |
||||
|
use Maatwebsite\Excel\Facades\Excel; |
||||
|
|
||||
|
class OrderDeliveryReportController extends AdminController |
||||
|
{ |
||||
|
/** |
||||
|
* 订单的配送统计 |
||||
|
*/ |
||||
|
protected $GoodsActivityReport = null; |
||||
|
public $marketId = 0; |
||||
|
public $newParams = []; |
||||
|
public $marketList = []; |
||||
|
public $storeList = []; |
||||
|
|
||||
|
/** |
||||
|
* Make a grid builder. |
||||
|
* |
||||
|
* @return Grid |
||||
|
*/ |
||||
|
protected function grid() |
||||
|
{ |
||||
|
$this->marketId = Auth::getMarket(); |
||||
|
|
||||
|
if($this->marketId){ |
||||
|
$this->newParams = ['market_id'=>$this->marketId]; |
||||
|
$builder = new GoodsReport($this->newParams); |
||||
|
$this->marketList = MarketModel::getMarketArray([['id','=',$this->marketId]]); |
||||
|
$this->storeList = StoreModel::getStoreArray([['market_id','=',$this->marketId]]); |
||||
|
}else{ |
||||
|
$builder = new GoodsReport(); |
||||
|
$this->marketList = MarketModel::getMarketArray(); |
||||
|
$this->storeList = StoreModel::getStoreArray(); |
||||
|
} |
||||
|
return Grid::make($builder, function (Grid $grid) { |
||||
|
$marketList = $this->marketList; |
||||
|
$storeList = $this->storeList; |
||||
|
$grid->column('goods_id')->sortable(); |
||||
|
$grid->column('cover_img')->image('',50); |
||||
|
$grid->column('name','商品名称'); |
||||
|
|
||||
|
$grid->column('market_id')->display(function($marketId){ |
||||
|
$item = MarketModel::getMarketInfo($marketId,'name'); |
||||
|
return $item->name ?? ''; |
||||
|
}); |
||||
|
$grid->column('store_id')->display(function($storeId){ |
||||
|
$item = StoreModel::getStoreInfo($storeId,'name'); |
||||
|
return $item->name ?? ''; |
||||
|
})->width('12%'); |
||||
|
$grid->column('price'); |
||||
|
$grid->column('original_price'); |
||||
|
$grid->column('number'); |
||||
|
$grid->column('created_at')->display(function($createdAt){ |
||||
|
return date('Y-m-d H:I:s',$createdAt) ?? ''; |
||||
|
}); |
||||
|
$grid->column('global_order_id')->help('统计订单状态为已完成的商品'); |
||||
|
|
||||
|
$grid->filter(function (Filter $filter) use($marketList,$storeList) { |
||||
|
// 更改为 panel 布局
|
||||
|
$filter->panel(); |
||||
|
$filter->equal('start_time','开始时间')->date()->width(2); |
||||
|
$filter->equal('end_time','结束时间')->date()->width(2); |
||||
|
$filter->equal('goods_id','商品ID')->width(2); |
||||
|
$filter->equal('name','商品名称')->width(2); |
||||
|
if(!$this->marketId){ |
||||
|
$filter->equal('market_id','市场')->select($marketList)->width(2); |
||||
|
} |
||||
|
$filter->equal('store_id','店铺')->select($storeList)->width(2); |
||||
|
}); |
||||
|
|
||||
|
$grid->tools([ |
||||
|
new DataReportOption('today','goods_report','今日'), |
||||
|
new DataReportOption('yesterday','goods_report','昨日'), |
||||
|
new DataReportOption('this_week','goods_report','本周'), |
||||
|
new DataReportOption('last_week','goods_report','上周'), |
||||
|
new DataReportOption('this_month','goods_report','本月'), |
||||
|
new DataReportOption('last_month','goods_report','上月'), |
||||
|
new GoodsReportExport() |
||||
|
]); |
||||
|
|
||||
|
// 每页1条
|
||||
|
$grid->paginate(10); |
||||
|
$grid->disableCreateButton(); |
||||
|
$grid->disableBatchActions(); |
||||
|
$grid->disableBatchDelete(); |
||||
|
|
||||
|
$grid->toolsWithOutline(); |
||||
|
|
||||
|
$grid->disableDeleteButton(); |
||||
|
$grid->disableEditButton(); |
||||
|
$grid->disableQuickEditButton(); |
||||
|
$grid->disableViewButton(); |
||||
|
$grid->disableActions(); |
||||
|
|
||||
|
$grid->disableRowSelector(); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 数据导出 |
||||
|
* @return \Symfony\Component\HttpFoundation\BinaryFileResponse |
||||
|
*/ |
||||
|
public function export(Request $request) |
||||
|
{ |
||||
|
$this->marketId = Auth::getMarket(); |
||||
|
$params = [ |
||||
|
'name' => request()->input('name', ''), |
||||
|
'market_id' => $this->marketId ? $this->marketId : request()->input('market_id',0), |
||||
|
'store_id' => request()->input('store_id',0), |
||||
|
'start_time' => request()->input('start_time',''), |
||||
|
'end_time' => request()->input('end_time',''), |
||||
|
]; |
||||
|
|
||||
|
$name = date('Y-m-d-His',time()); |
||||
|
$data = new \App\Admin\Actions\Exporter\GoodsSales($params); |
||||
|
if(empty($data)){ |
||||
|
return $this->error('没有数据!'); |
||||
|
} |
||||
|
return Excel::download($data, $name.'.xlsx'); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,121 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Repositories\v3; |
||||
|
|
||||
|
use App\Models\LanzuOrderGoods as Model; |
||||
|
use Dcat\Admin\Grid\Model as GridModel; |
||||
|
use Dcat\Admin\Repositories\EloquentRepository; |
||||
|
use Illuminate\Support\Facades\DB; |
||||
|
use App\Models\ImsCjdcOrderMain as OrderMainModel; |
||||
|
use App\Models\ImsCjdcOrder as OrderModel; |
||||
|
|
||||
|
class OrderDeliveryReport extends EloquentRepository |
||||
|
{ |
||||
|
public $params = []; |
||||
|
/** |
||||
|
* Model. |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
protected $eloquentClass = Model::class; |
||||
|
|
||||
|
public function __construct($params = []) |
||||
|
{ |
||||
|
$this->params = $params; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取统计列表数据 |
||||
|
*/ |
||||
|
public function get(GridModel $model) |
||||
|
{ |
||||
|
// 获取当前页数
|
||||
|
$currentPage = $model->getCurrentPage(); |
||||
|
// 获取每页显示行数
|
||||
|
$perPage = $model->getPerPage(); |
||||
|
|
||||
|
$where = []; |
||||
|
if(!empty($this->params) && isset($this->params['market_id']) && !empty($this->params['market_id'])){ |
||||
|
$where = ['market_id'=>$this->params['market_id']]; |
||||
|
} |
||||
|
|
||||
|
$selects = Model::$tableName.'.goods_id,'.Model::$tableName.'.name,price,original_price,'.Model::$tableName.'.cover_img,'.OrderMainModel::$tableName.'.market_id,'.OrderModel::$tableName.'.store_id,number,'.OrderMainModel::$tableName.'.created_at,global_order_id'; |
||||
|
$orderGoods = $this->getDataModel($selects,$where); |
||||
|
$list = $orderGoods->orderBy(OrderMainModel::$tableName.'.id','desc')->paginate($perPage); |
||||
|
$list = $list->toArray(); |
||||
|
|
||||
|
return $model->makePaginator( |
||||
|
$list['total'] ?? 0,$list['data'] ?? [] |
||||
|
); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
public function getDataModel($selects,$params = []) |
||||
|
{ |
||||
|
// 获取筛选参数
|
||||
|
$goodsId = $params['goods_id'] ?? request()->input('goods_id',0); |
||||
|
$name = $params['name'] ?? request()->input('name', ''); |
||||
|
$marketId = $params['market_id'] ?? request()->input('market_id',0); |
||||
|
$storeId = $params['store_id'] ?? request()->input('store_id',0); |
||||
|
|
||||
|
$startTime = $params['start_time'] ?? request()->input('start_time',''); |
||||
|
$endTime = $params['end_time'] ?? request()->input('end_time',''); |
||||
|
|
||||
|
$orderGoods = Model::select(DB::raw($selects)) |
||||
|
->join(OrderModel::$tableName,Model::$tableName.'.order_id','=',OrderModel::$tableName.'.id') |
||||
|
->join(OrderMainModel::$tableName,OrderModel::$tableName.'.order_main_id','=',OrderMainModel::$tableName.'.global_order_id') |
||||
|
->where(Model::$tableName.'.activity_type',1) |
||||
|
->where(Model::$tableName.'.status',1) |
||||
|
->whereIn(OrderMainModel::$tableName.'.state',[4,5,10,11]); |
||||
|
|
||||
|
if($goodsId){ |
||||
|
$goodsIds = explode(',',$goodsId); |
||||
|
$orderGoods->whereIn(Model::$tableName.'.goods_id',$goodsIds); |
||||
|
} |
||||
|
if($name){ |
||||
|
$orderGoods->where(Model::$tableName.'.name','like',"%$name%"); |
||||
|
} |
||||
|
if($marketId){ |
||||
|
$orderGoods->where('market_id',$marketId); |
||||
|
} |
||||
|
if($storeId){ |
||||
|
$orderGoods->where('store_id',$storeId); |
||||
|
} |
||||
|
if($startTime){ |
||||
|
$startTime = $startTime.' 00:00:00'; |
||||
|
|
||||
|
$orderGoods->where(Model::$tableName.'.created_at','>=',strtotime($startTime)); |
||||
|
} |
||||
|
if($endTime){ |
||||
|
$endTime = $endTime.' 23:59:59'; |
||||
|
|
||||
|
$orderGoods->where(Model::$tableName.'.created_at','<=',strtotime($endTime)); |
||||
|
} |
||||
|
|
||||
|
return $orderGoods; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取总数 |
||||
|
*/ |
||||
|
public function getCountData($params = []) |
||||
|
{ |
||||
|
$selects = "SUM(lanzu_order_goods.number) as total,SUM((original_price-price)*number) as subsidy_total,FROM_UNIXTIME(lanzu_order_goods.created_at,'%Y-%m-%d') as dtime"; |
||||
|
$orderGoods = $this->getDataModel($selects,$params); |
||||
|
$total = $orderGoods->orderBy('dtime','asc')->groupBy('dtime')->get()->toArray(); |
||||
|
|
||||
|
return $total ?? []; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 分市场获取 |
||||
|
*/ |
||||
|
public function getMarketData($params = []) |
||||
|
{ |
||||
|
$selects = "SUM(lanzu_order_goods.number) as total,SUM((original_price-price)*number) as subsidy_total,market_id"; |
||||
|
$orderGoods = $this->getDataModel($selects,$params); |
||||
|
$total = $orderGoods->groupBy('market_id')->get()->toArray(); |
||||
|
|
||||
|
return $total ?? []; |
||||
|
} |
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue