7 changed files with 298 additions and 7 deletions
-
31app/Admin/Actions/Exporter/OrderDelivery.php
-
83app/Admin/Actions/Exporter/OrderDeliveryDetailSheet.php
-
88app/Admin/Actions/Exporter/OrderDeliveryTotalSheet.php
-
88app/Admin/Actions/Tools/OrderDeliveryExport.php
-
11app/Admin/Controllers/v3/OrderDeliveryReportController.php
-
3app/Admin/Repositories/v3/OrderDeliveryReport.php
-
1app/Admin/routes.php
@ -0,0 +1,31 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Actions\Exporter; |
||||
|
|
||||
|
use Maatwebsite\Excel\Concerns\Exportable; |
||||
|
use Maatwebsite\Excel\Concerns\WithMultipleSheets; |
||||
|
|
||||
|
class OrderDelivery implements WithMultipleSheets |
||||
|
{ |
||||
|
use Exportable; |
||||
|
|
||||
|
protected $params = []; |
||||
|
public function __construct(array $params) |
||||
|
{ |
||||
|
$this->params = $params; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return array |
||||
|
*/ |
||||
|
public function sheets(): array |
||||
|
{ |
||||
|
$sheets = []; |
||||
|
|
||||
|
$sheets[] = new OrderDeliveryTotalSheet($this->params);// 统计
|
||||
|
$sheets[] = new OrderDeliveryDetailSheet($this->params);// 明细
|
||||
|
|
||||
|
return $sheets; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,83 @@ |
|||||
|
<?php |
||||
|
namespace App\Admin\Actions\Exporter; |
||||
|
|
||||
|
use Maatwebsite\Excel\Concerns\FromArray; |
||||
|
use Maatwebsite\Excel\Concerns\WithStrictNullComparison; |
||||
|
use Maatwebsite\Excel\Concerns\ShouldAutoSize; |
||||
|
use Maatwebsite\Excel\Concerns\WithTitle; |
||||
|
|
||||
|
use App\Admin\Repositories\v3\OrderDeliveryReport; |
||||
|
use App\Models\v3\LanzuEmployees as EmployeesModel; |
||||
|
use App\Models\ImsCjdcOrderMain as OrderMainModel; |
||||
|
use App\Models\v3\Market as MarketModel; |
||||
|
use Maatwebsite\Excel\Concerns\WithStyles; |
||||
|
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; |
||||
|
|
||||
|
/** |
||||
|
* 配送统计总配送费 |
||||
|
*/ |
||||
|
class OrderDeliveryDetailSheet implements FromArray, WithStrictNullComparison, ShouldAutoSize, WithTitle, WithStyles |
||||
|
{ |
||||
|
private $params; |
||||
|
|
||||
|
public function __construct(array $params) |
||||
|
{ |
||||
|
$this->params = $params; |
||||
|
} |
||||
|
|
||||
|
public function array(): array |
||||
|
{ |
||||
|
$titles = [[ |
||||
|
'配送人员', |
||||
|
'订单编号', |
||||
|
'下单市场', |
||||
|
'下单时间', |
||||
|
'订单配送费', |
||||
|
]]; |
||||
|
$data = $this->getData($this->params); |
||||
|
$markets = MarketModel::getMarketArray(); |
||||
|
$list = []; |
||||
|
foreach ($data as $value){ |
||||
|
$global_order_id = $value['global_order_id'] ?? ''; |
||||
|
$delivery_money = $value['delivery_money'] ?? 0; |
||||
|
$list[] = [ |
||||
|
$value['name'] ?? '', |
||||
|
' '.$global_order_id, |
||||
|
$markets[$value['market_id']] ?? '', |
||||
|
date('Y-m_d H:i:s',$value['created_at']), |
||||
|
$delivery_money+3.5 |
||||
|
]; |
||||
|
} |
||||
|
return array_merge($titles,$list); |
||||
|
} |
||||
|
|
||||
|
public function styles(Worksheet $sheet) |
||||
|
{ |
||||
|
return [ |
||||
|
1 => ['font' => ['size' => 12]], |
||||
|
]; |
||||
|
} |
||||
|
/** |
||||
|
* 获取数据 |
||||
|
*/ |
||||
|
public function getData($option = []) |
||||
|
{ |
||||
|
$params = $option; |
||||
|
$repository = new OrderDeliveryReport(); |
||||
|
$selects = EmployeesModel::TABLE_NAME.'.name,global_order_id,'.OrderMainModel::$tableName.'.market_id,'.OrderMainModel::$tableName.'.created_at,delivery_money'; |
||||
|
|
||||
|
$orderGoods = $repository->getDataModel($selects,$params); |
||||
|
$list = $orderGoods->get()->toArray(); |
||||
|
|
||||
|
return $list; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* sheet 表名称 |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function title(): string |
||||
|
{ |
||||
|
return '配送明细'; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,88 @@ |
|||||
|
<?php |
||||
|
namespace App\Admin\Actions\Exporter; |
||||
|
|
||||
|
use Maatwebsite\Excel\Concerns\FromArray; |
||||
|
use Maatwebsite\Excel\Concerns\WithStrictNullComparison; |
||||
|
use Maatwebsite\Excel\Concerns\ShouldAutoSize; |
||||
|
use Maatwebsite\Excel\Concerns\WithTitle; |
||||
|
use Maatwebsite\Excel\Concerns\WithHeadings; |
||||
|
use Maatwebsite\Excel\Concerns\WithStyles; |
||||
|
|
||||
|
use App\Admin\Repositories\v3\OrderDeliveryReport; |
||||
|
use App\Models\v3\LanzuEmployees as EmployeesModel; |
||||
|
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; |
||||
|
|
||||
|
/** |
||||
|
* 配送统计总配送费 |
||||
|
*/ |
||||
|
class OrderDeliveryTotalSheet implements FromArray, WithStrictNullComparison, ShouldAutoSize, WithTitle, WithHeadings, WithStyles |
||||
|
{ |
||||
|
private $params; |
||||
|
|
||||
|
public function __construct(array $params) |
||||
|
{ |
||||
|
$this->params = $params; |
||||
|
} |
||||
|
public function headings(): array |
||||
|
{ |
||||
|
$startTime = $this->params['start_time'] ?? null; |
||||
|
$endTime = $this->params['end_time'] ?? null; |
||||
|
if(empty($startTime) && empty($endTime)){ |
||||
|
return ['统计全部']; |
||||
|
} |
||||
|
|
||||
|
if(empty($startTime)){ |
||||
|
$startTime = '2020-10-01'; |
||||
|
}else{ |
||||
|
$endTime = date('Y-m-d'); |
||||
|
} |
||||
|
|
||||
|
return [ |
||||
|
'统计时间:'.$startTime.' 至 '.$endTime |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
public function array(): array |
||||
|
{ |
||||
|
$titles = [[ |
||||
|
'配送人员', |
||||
|
'总配送费', |
||||
|
]]; |
||||
|
$data = $this->getData($this->params); |
||||
|
return array_merge($titles,$data); |
||||
|
} |
||||
|
|
||||
|
public function styles(Worksheet $sheet) |
||||
|
{ |
||||
|
$sheet->mergeCells('A1:B1'); |
||||
|
|
||||
|
return [ |
||||
|
1 => ['font' => ['bold' => true,'size' => 12]], |
||||
|
2 => ['font' => ['size' => 12]], |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取数据 |
||||
|
*/ |
||||
|
public function getData($option = []) |
||||
|
{ |
||||
|
$params = $option; |
||||
|
$repository = new OrderDeliveryReport(); |
||||
|
$selects = EmployeesModel::TABLE_NAME.'.name,SUM( CASE WHEN delivery_money=0 THEN 3.5 when delivery_money>0 THEN delivery_money+3.5 ELSE 0 END) as total_delivery'; |
||||
|
|
||||
|
$orderGoods = $repository->getDataModel($selects,$params); |
||||
|
$list = $orderGoods->groupBy(EmployeesModel::TABLE_NAME.'.name')->get()->toArray(); |
||||
|
|
||||
|
return $list; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* sheet 表名称 |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function title(): string |
||||
|
{ |
||||
|
return '配送统计'; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,88 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Actions\Tools; |
||||
|
|
||||
|
use Dcat\Admin\Actions\Response; |
||||
|
use Dcat\Admin\Traits\HasPermissions; |
||||
|
use Dcat\Admin\Tree\AbstractTool; |
||||
|
use Illuminate\Contracts\Auth\Authenticatable; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
use Illuminate\Http\Request; |
||||
|
|
||||
|
class OrderDeliveryExport extends AbstractTool |
||||
|
{ |
||||
|
|
||||
|
/** |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected $title = '<span class="feather icon-download">导出<span>'; |
||||
|
|
||||
|
/** |
||||
|
* Handle the action request. |
||||
|
* |
||||
|
* @param Request $request |
||||
|
* |
||||
|
* @return Response |
||||
|
*/ |
||||
|
public function handle(Request $request) |
||||
|
{ |
||||
|
$url = '/delivery_report_export?'; |
||||
|
$name = $request->get('name', ''); |
||||
|
$horsemanId = $request->get('horseman_id',0); |
||||
|
$marketId = $request->get('market_id',0); |
||||
|
$storeId = $request->get('user_id',0); |
||||
|
$startTime = $request->get('start_time',''); |
||||
|
$endTime = $request->get('end_time',''); |
||||
|
|
||||
|
if(!empty($name)){ |
||||
|
$url .= '&name='.$name; |
||||
|
} |
||||
|
if(!empty($horsemanId)){ |
||||
|
$url .= '&horseman_id='.$marketId; |
||||
|
} |
||||
|
if(!empty($marketId)){ |
||||
|
$url .= '&market_id='.$marketId; |
||||
|
} |
||||
|
if(!empty($storeId)){ |
||||
|
$url .= '&user_id='.$storeId; |
||||
|
} |
||||
|
if(!empty($startTime)){ |
||||
|
$url .= '&start_time='.$startTime; |
||||
|
} |
||||
|
|
||||
|
if(!empty($endTime)){ |
||||
|
$url .= '&end_time='.$endTime; |
||||
|
} |
||||
|
return $this->response() |
||||
|
->success('导出中~') |
||||
|
->redirect($url); |
||||
|
} |
||||
|
public function parameters() |
||||
|
{ |
||||
|
return [ |
||||
|
'name' => request()->input('name', ''), |
||||
|
'horseman_id' => request()->input('horseman_id',0), |
||||
|
'market_id' => request()->input('market_id',0), |
||||
|
'user_id' => request()->input('user_id',0), |
||||
|
'start_time' => request()->input('start_time',''), |
||||
|
'end_time' => request()->input('end_time',''), |
||||
|
]; |
||||
|
} |
||||
|
/** |
||||
|
* @return string|array|void |
||||
|
*/ |
||||
|
public function confirm() |
||||
|
{ |
||||
|
return '确定导出数据吗?'; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param Model|Authenticatable|HasPermissions|null $user |
||||
|
* |
||||
|
* @return bool |
||||
|
*/ |
||||
|
protected function authorize($user): bool |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue