feat: 添加导出功能和优化查询逻辑

This commit is contained in:
mkm 2024-09-19 12:03:59 +08:00
parent 88c9fd557c
commit 18a7332f47

View File

@ -8,13 +8,14 @@ use app\common\model\store_cash_finance_flow\StoreCashFinanceFlow;
use app\common\lists\ListsSearchInterface;
use app\common\model\auth\Admin;
use app\common\model\system_store\SystemStore;
use app\common\lists\ListsExcelInterface;
/**
* 现金流水列表
* Class StoreCashFinanceFlowLists
* @package app\admin\listsstore_cash_finance_flow
*/
class StoreCashFinanceFlowLists extends BaseAdminDataLists implements ListsSearchInterface
class StoreCashFinanceFlowLists extends BaseAdminDataLists implements ListsSearchInterface, ListsExcelInterface
{
@ -27,7 +28,7 @@ class StoreCashFinanceFlowLists extends BaseAdminDataLists implements ListsSearc
public function setSearch(): array
{
return [
'=' => ['store_id','status'],
'=' => ['store_id', 'status'],
"between_time" => 'create_time'
];
}
@ -45,13 +46,14 @@ class StoreCashFinanceFlowLists extends BaseAdminDataLists implements ListsSearc
public function lists(): array
{
return StoreCashFinanceFlow::where($this->searchWhere)
->field(['id', 'store_id', 'cash_price', 'receivable', 'receipts', 'admin_id', 'file', 'remark','create_time', 'status'])
->field(['id', 'store_id', 'cash_price', 'receivable', 'receipts', 'admin_id', 'file', 'remark', 'create_time', 'status'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()->each(function ($item) {
$item->store_name =SystemStore::where('id', $item->store_id)->value('name');
if($item->admin_id>0){
$item->admin_name =Admin::where('id', $item->admin_id)->value('name');
$item->store_name = SystemStore::where('id', $item->store_id)->value('name');
$item->admin_name='';
if ($item->admin_id > 0) {
$item->admin_name = Admin::where('id', $item->admin_id)->value('name');
}
})
->toArray();
@ -68,5 +70,35 @@ class StoreCashFinanceFlowLists extends BaseAdminDataLists implements ListsSearc
{
return StoreCashFinanceFlow::where($this->searchWhere)->count();
}
/**
* @notes 导出文件名
* @return string
* @date 2022/11/24 16:17
*/
public function setFileName(): string
{
return '现金流水';
}
/**
* @notes 导出字段
* @return string[]
* @date 2022/11/24 16:17
*/
public function setExcelFields(): array
{
$data = [
'store_name' => '门店',
'create_time' => '时间',
'cash_price' => '交易金额',
'receivable' => '应收金额',
'receipts' => '实收金额',
'admin_name' => '操作人员',
'remark' => '备注',
'status'=>'状态',
];
return $data;
}
}