130 lines
3.9 KiB
PHP
130 lines
3.9 KiB
PHP
<?php
|
|
|
|
|
|
namespace Yunshop\AreaDividend\area;
|
|
|
|
use app\common\helpers\PaginationHelper;
|
|
use Yunshop\AreaDividend\models\AreaDividend;
|
|
|
|
class DividendLogController extends CommonController
|
|
{
|
|
public function index()
|
|
{
|
|
|
|
$search = \YunShop::request()->search?:[];
|
|
|
|
if ($search) {
|
|
$search = array_filter($search, function ($item) {
|
|
return $item !== '';// && $item !== 0;
|
|
});
|
|
}
|
|
|
|
$list = AreaDividend::getDividends($search)->agent($this->getAreaName())->orderBy('id', 'desc')->paginate(20);
|
|
$pager = PaginationHelper::show($list->total(), $list->currentPage(), $list->perPage());
|
|
|
|
|
|
if ($search['statistics'] == 1) {
|
|
$statisti = $this->getAreaName();
|
|
$statisti['total'] = AreaDividend::getDividends($search)->agent($this->getAreaName())->sum('dividend_amount');
|
|
}
|
|
|
|
if(!$search['time']){
|
|
$search['time']['start'] = date("Y-m-d H:i:s",time());
|
|
$search['time']['end'] = date("Y-m-d H:i:s",time());
|
|
}
|
|
|
|
return view('Yunshop\AreaDividend::area.dividend-list', [
|
|
'list' => $list,
|
|
'pager' => $pager,
|
|
'search' => $search,
|
|
'statisti' => $statisti,
|
|
'appointment' => app('plugins')->isEnabled('appointment')
|
|
])->render();
|
|
}
|
|
|
|
protected function getAreaName()
|
|
{
|
|
|
|
$address = [
|
|
'province_name' =>$this->agent_model->province_name,
|
|
'city_name' =>$this->agent_model->city_name,
|
|
'district_name' =>$this->agent_model->district_name,
|
|
'street_name' =>$this->agent_model->street_name,
|
|
];
|
|
|
|
|
|
|
|
|
|
return [
|
|
'member_id' => $this->agent_model->member_id,
|
|
'agent_level'=> $this->agent_model->agent_level,
|
|
'agent_area' => rtrim(implode('-', $address), '-'),
|
|
];
|
|
}
|
|
|
|
public function export()
|
|
{
|
|
// dd('QwQ');
|
|
|
|
$file_name = date('Ymdhis', time()) . '区域分红';
|
|
|
|
$search = \YunShop::request()->search?:[];
|
|
|
|
if ($search) {
|
|
$search = array_filter($search, function ($item) {
|
|
return $item !== '';// && $item !== 0;
|
|
});
|
|
}
|
|
|
|
$list = AreaDividend::getDividends($search)->agent($this->getAreaName())->orderBy('id', 'desc')
|
|
->get()
|
|
->toArray();
|
|
|
|
$export_data[0] = [
|
|
'ID',
|
|
'分红时间',
|
|
'订单号',
|
|
'订单金额(元)',
|
|
'分红结算金额',
|
|
'分红金额',
|
|
'分红金额',
|
|
];
|
|
|
|
foreach ($list as $key => $item) {
|
|
|
|
$export_data[$key + 1] = [
|
|
$item['id'],
|
|
$item['created_at'],
|
|
$item['order_sn'],
|
|
$item['order_amount'],
|
|
$item['amount'],
|
|
$item['dividend_rate'].'%',
|
|
$item['lower_level_rate'].'%',
|
|
$item['dividend_amount'],
|
|
$item['status_name'],
|
|
|
|
];
|
|
}
|
|
return \app\exports\ExcelService::fromArrayExport($export_data,$file_name);
|
|
|
|
// 商城更新,无法使用
|
|
// \Excel::create($file_name, function ($excel) use ($export_data) {
|
|
// // Set the title
|
|
// $excel->setTitle('Office 2005 XLSX Document');
|
|
//
|
|
// // Chain the setters
|
|
// $excel->setCreator('芸众商城')
|
|
// ->setLastModifiedBy("芸众商城")
|
|
// ->setSubject("Office 2005 XLSX Test Document")
|
|
// ->setDescription("Test document for Office 2005 XLSX, generated using PHP classes.")
|
|
// ->setKeywords("office 2005 openxml php")
|
|
// ->setCategory("report file");
|
|
//
|
|
// $excel->sheet('info', function ($sheet) use ($export_data) {
|
|
// $sheet->rows($export_data);
|
|
// });
|
|
//
|
|
//
|
|
// })->export('xls');
|
|
}
|
|
} |