调整账单导出

This commit is contained in:
luofei 2024-06-07 14:22:28 +08:00
parent d0bbd71dde
commit a4ae19a64a
3 changed files with 45 additions and 24 deletions

View File

@ -3,10 +3,12 @@
namespace app\common\lists;
use app\admin\lists\BaseAdminDataLists;
use app\common\enum\OrderEnum;
use app\common\enum\PayEnum;
use app\common\model\store_finance_flow\StoreFinanceFlow;
use think\db\Query;
class StoreBillLists extends BaseAdminDataLists implements ListsSearchInterface
class StoreBillLists extends BaseAdminDataLists implements ListsSearchInterface, ListsExcelInterface
{
public function setSearch(): array
@ -18,7 +20,7 @@ class StoreBillLists extends BaseAdminDataLists implements ListsSearchInterface
public function lists(): array
{
$this->params['type'] = !empty($this->params['type']) ? $this->params['type'] : 1;
return StoreFinanceFlow::where('1=1')
return StoreFinanceFlow::with(['user', 'staff'])
->when(!empty($this->request->adminInfo['store_id']), function ($query) {
$query->where('store_id', $this->request->adminInfo['store_id']);
})
@ -54,6 +56,13 @@ class StoreBillLists extends BaseAdminDataLists implements ListsSearchInterface
->order(['id' => 'desc'])
->select()->each(function ($item) {
$item->month = date('m', strtotime($item->create_time));
if (!empty($this->request->adminInfo['store_id'])) {
$item->pm_type = $item->financial_pm == 0 ? '收入' : '支出';
} else {
$item->pm_type = $item->financial_pm == 0 ? '支出' : '收入';
}
$item['pay_type_name'] = PayEnum::getPaySceneDesc($item['pay_type']);
$item['financial_type_name'] = OrderEnum::getFinancialType($item['financial_type']);
})
->toArray();
}
@ -95,4 +104,24 @@ class StoreBillLists extends BaseAdminDataLists implements ListsSearchInterface
->count();
}
public function setExcelFields(): array
{
return [
'financial_record_sn' => '交易单号',
'order_sn' => '关联订单',
'create_time' => '交易时间',
'number' => '交易金额',
'pm_type' => '支出收入',
'nickname' => '交易人',
'staff_name' => '关联店员',
'financial_type_name' => '交易类型',
'pay_type_name' => '支付方式',
];
}
public function setFileName(): string
{
return '账单导出';
}
}

View File

@ -4,6 +4,8 @@ namespace app\common\model\store_finance_flow;
use app\common\model\BaseModel;
use app\common\model\system_store\SystemStoreStaff;
use app\common\model\user\User;
use think\model\concern\SoftDelete;
@ -18,5 +20,14 @@ class StoreFinanceFlow extends BaseModel
protected $name = 'store_finance_flow';
protected $deleteTime = 'delete_time';
public function user()
{
return $this->hasOne(User::class, 'id', 'user_id')->bind(['nickname']);
}
public function staff()
{
return $this->hasOne(SystemStoreStaff::class, 'id', 'staff_id')->bind(['staff_name']);
}
}

View File

@ -5,7 +5,6 @@ namespace app\store\controller\finance;
use app\admin\lists\store_finance_flow\StoreFinanceFlowLists;
use app\common\controller\Definitions;
use app\common\lists\StoreBillLists;
use app\common\logic\StoreFinanceFlowLogic;
use app\store\controller\BaseAdminController;
use hg\apidoc\annotation as ApiDoc;
@ -22,6 +21,7 @@ class StoreBillController extends BaseAdminController
ApiDoc\Query(name: 'type', type: 'int', require: false, desc: '类型1日账单2周账单3月账单'),
ApiDoc\Query(name: 'start_time', type: 'string', require: false, desc: '开始时间'),
ApiDoc\Query(name: 'end_time', type: 'string', require: false, desc: '结束时间'),
ApiDoc\Query(name: 'export', type: 'int', require: false, desc: '是否导出2是'),
ApiDoc\Header(ref: [Definitions::class, "token"]),
ApiDoc\Query(ref: [Definitions::class, "page"]),
ApiDoc\ResponseSuccess("data", type: "array"),
@ -51,23 +51,4 @@ class StoreBillController extends BaseAdminController
return $this->dataLists(new StoreFinanceFlowLists());
}
#[
ApiDoc\Title('下载'),
ApiDoc\url('/store/finance/storeBill/download'),
ApiDoc\Method('GET'),
ApiDoc\NotHeaders(),
ApiDoc\Author('中国队长'),
ApiDoc\Param(name: 'id', type: 'int', require: true, desc: 'id'),
ApiDoc\Param(name: 'remark', type: 'string', require: true, desc: '备注'),
ApiDoc\Header(ref: [Definitions::class, "token"]),
ApiDoc\ResponseSuccess("data", type: "array"),
]
public function download(StoreFinanceFlowLogic $logic)
{
$id = $this->request->post('id');
$remark = $this->request->post('remark');
$logic->remark($id, $remark);
return $this->success('操作成功', [], 1, 1);
}
}