添加导出门店财务流水
This commit is contained in:
parent
906fd620a9
commit
8aa7355485
@ -77,5 +77,12 @@ class StoreFinanceFlowController extends BaseAdminController
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
public function export()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
$file_path = StoreFinanceFlowLogic::export($params);
|
||||
return $this->success('导出成功', ['url' => $file_path]);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -3,8 +3,14 @@
|
||||
namespace app\admin\logic\store_finance_flow;
|
||||
|
||||
|
||||
use app\common\enum\OrderEnum;
|
||||
use app\common\enum\PayEnum;
|
||||
use app\common\model\store_finance_flow\StoreFinanceFlow;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\system_store\SystemStore;
|
||||
use app\common\model\system_store\SystemStoreStaff;
|
||||
use app\common\model\user\User;
|
||||
use app\common\service\xlsx\StoreFinanceFlowXlsx;
|
||||
use support\exception\BusinessException;
|
||||
use think\facade\Db;
|
||||
|
||||
@ -90,4 +96,59 @@ class StoreFinanceFlowLogic extends BaseLogic
|
||||
{
|
||||
return StoreFinanceFlow::findOrEmpty($params['id'])->toArray();
|
||||
}
|
||||
|
||||
public static function export($params)
|
||||
{
|
||||
$query = StoreFinanceFlow::where('financial_pm', 1);
|
||||
if (!empty($params['type'])) {
|
||||
if ($params['type'] == OrderEnum::ORDER_HANDLING_FEES || $params['type'] == OrderEnum::OTHER_ORDER_OBTAINS) {
|
||||
$query->where('financial_type', $params['type']);
|
||||
} elseif ($params['type'] == 11) {
|
||||
$query->whereIn('financial_type', [OrderEnum::ORDER_MARGIN, OrderEnum::MERCHANT_ORDER_OBTAINS]);
|
||||
} else {
|
||||
$query->whereIn('financial_type', [OrderEnum::VIP_ORDER_OBTAINS, OrderEnum::VILLAGE_ORDER_OBTAINS, OrderEnum::BRIGADE_ORDER_OBTAINS]);
|
||||
}
|
||||
}
|
||||
if (!empty($params['store_id'])) {
|
||||
$query->where('store_id', $params['store_id']);
|
||||
}
|
||||
if (!empty($params['start_time'])) {
|
||||
$query->where('create_time', '>=', strtotime($params['start_time']));
|
||||
}
|
||||
if (!empty($params['end_time'])) {
|
||||
$query->where('create_time', '<=', strtotime($params['end_time']));
|
||||
}
|
||||
if (!empty($params['user_id'])) {
|
||||
$query->where('user_id', $params['user_id']);
|
||||
}
|
||||
if (!empty($params['order_sn'])) {
|
||||
$query->where('order_sn', 'like', "%{$params['order_sn']}%");
|
||||
}
|
||||
$data = $query->order('id desc')->select()->toArray();
|
||||
$users = User::field('id,nickname,real_name')->whereIn('id', array_unique(array_column($data, 'user_id')))->select()->toArray();
|
||||
$users = reset_index($users, 'id');
|
||||
$stores = SystemStore::field('id,name')->whereIn('id', array_unique(array_column($data, 'store_id')))->select()->toArray();
|
||||
$stores = reset_index($stores, 'id');
|
||||
foreach ($data as &$item) {
|
||||
$user = $users[$item['user_id']] ?? [];
|
||||
if ($item['user_id'] <= 0 || empty($user)) {
|
||||
$item['nickname'] = '游客';
|
||||
} else {
|
||||
$item['nickname'] = $user['real_name']!=''?$user['real_name']:$user['nickname'].'|'.$item['user_id'];
|
||||
}
|
||||
$item['number'] = '+' . $item['number'];
|
||||
$store = $stores[$item['store_id']] ?? [];
|
||||
$item['store_name'] = $store['name'] ?? '';
|
||||
}
|
||||
if ($params['type'] == 3) {
|
||||
$title = '手续费';
|
||||
} elseif ($params['type'] == 11) {
|
||||
$title = '其他收益';
|
||||
} elseif ($params['type'] == 16) {
|
||||
$title = '损耗';
|
||||
} else {
|
||||
$title = '佣金';
|
||||
}
|
||||
return (new StoreFinanceFlowXlsx())->export($data, $title, '');
|
||||
}
|
||||
}
|
65
app/common/service/xlsx/StoreFinanceFlowXlsx.php
Normal file
65
app/common/service/xlsx/StoreFinanceFlowXlsx.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\service\xlsx;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use PhpOffice\PhpSpreadsheet\Style\Border;
|
||||
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
||||
use PhpOffice\PhpSpreadsheet\Style\Alignment;
|
||||
|
||||
class StoreFinanceFlowXlsx
|
||||
{
|
||||
public function export($data, $type)
|
||||
{
|
||||
$spreadsheet = new Spreadsheet();
|
||||
$sheet = $spreadsheet->getActiveSheet();
|
||||
$sheet->setCellValue('A1', '交易单号');
|
||||
$sheet->setCellValue('B1', '交易时间');
|
||||
$sheet->setCellValue('C1', '金额');
|
||||
$sheet->setCellValue('D1', '门店');
|
||||
$sheet->setCellValue('E1', '用户');
|
||||
$sheet->setCellValue('F1', '流水类型');
|
||||
|
||||
// 设置默认的单元格样式
|
||||
$defaultStyle = [
|
||||
'alignment' => [
|
||||
'horizontal' => Alignment::HORIZONTAL_CENTER,
|
||||
'vertical' => Alignment::VERTICAL_CENTER,
|
||||
],
|
||||
];
|
||||
// 应用默认样式到整个工作表
|
||||
$spreadsheet->getDefaultStyle()->applyFromArray($defaultStyle);
|
||||
|
||||
$column = 2;
|
||||
foreach ($data as $k => $item) {
|
||||
$sheet->setCellValue("A$column", $item['order_sn']);
|
||||
$sheet->setCellValue("B$column", $item['create_time']);
|
||||
$sheet->setCellValue("C$column", $item['number']);
|
||||
$sheet->setCellValue("D$column", $item['store_name']);
|
||||
$sheet->setCellValue("E$column", $item['nickname']);
|
||||
$sheet->setCellValue("F$column", $type);
|
||||
$column++;
|
||||
}
|
||||
|
||||
// 定义线框样式
|
||||
$styleArray = [
|
||||
'borders' => [
|
||||
'allBorders' => [
|
||||
'borderStyle' => Border::BORDER_THIN, // 线框样式
|
||||
'color' => ['argb' => '000000'], // 线框颜色
|
||||
],
|
||||
],
|
||||
];
|
||||
$sheet->getStyle('A1:F' . $column)->applyFromArray($styleArray);
|
||||
|
||||
$writer = new Xlsx($spreadsheet);
|
||||
$url = '/export/' . "门店财务流水 - $type " . date('YmdHi') . '.xlsx';
|
||||
$file_path = public_path() . $url;
|
||||
if (!is_dir(dirname($file_path))) {
|
||||
mkdir(dirname($file_path), 0777, true);
|
||||
}
|
||||
$writer->save($file_path);
|
||||
return getenv('APP_URL') . $url;
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user