添加财务账单列表
This commit is contained in:
parent
cbf01610b6
commit
99cdb5e150
92
app/common/lists/StoreBillLists.php
Normal file
92
app/common/lists/StoreBillLists.php
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\common\lists;
|
||||||
|
|
||||||
|
use app\admin\lists\BaseAdminDataLists;
|
||||||
|
use app\common\model\store_finance_flow\StoreFinanceFlow;
|
||||||
|
use think\db\Query;
|
||||||
|
|
||||||
|
class StoreBillLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||||
|
{
|
||||||
|
|
||||||
|
public function setSearch(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function lists(): array
|
||||||
|
{
|
||||||
|
$this->params['type'] = !empty($this->params['type']) ? $this->params['type'] : 1;
|
||||||
|
return StoreFinanceFlow::where('1=1')
|
||||||
|
->when(!empty($this->request->adminInfo['store_id']), function ($query) {
|
||||||
|
$query->where('store_id', $this->request->adminInfo['store_id']);
|
||||||
|
})
|
||||||
|
->when(!empty($this->params['start_time']), function ($query) {
|
||||||
|
$query->whereTime('create_time', '>=', $this->params['start_time']);
|
||||||
|
})
|
||||||
|
->when(!empty($this->params['end_time']), function ($query) {
|
||||||
|
if ($this->params['end_time'] == $this->params['start_time']) {
|
||||||
|
$this->params['end_time'] = strtotime($this->params['end_time']) + 86399;
|
||||||
|
}
|
||||||
|
$query->whereTime('create_time', '<=', $this->params['end_time']);
|
||||||
|
})
|
||||||
|
->when(!empty($this->params['type']), function (Query $query) {
|
||||||
|
$income = 1;
|
||||||
|
$expense = 0;
|
||||||
|
if (!empty($this->request->adminInfo['store_id'])) {
|
||||||
|
$income = 0;
|
||||||
|
$expense = 1;
|
||||||
|
}
|
||||||
|
switch ($this->params['type']) {
|
||||||
|
case 2:
|
||||||
|
$query->fieldRaw("*,sum(IF(financial_pm=$income,number,0)) as income,sum(IF(financial_pm=$expense,number,0)) as expense,YEAR(FROM_UNIXTIME(create_time)) as year,WEEK(FROM_UNIXTIME(create_time), 1) as week")->group("year,week");
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
$query->fieldRaw("*,sum(IF(financial_pm=$income,number,0)) as income,sum(IF(financial_pm=$expense,number,0)) as expense,FROM_UNIXTIME(create_time, '%Y-%m') as time")->group("time");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$query->fieldRaw("*,sum(IF(financial_pm=$income,number,0)) as income,sum(IF(financial_pm=$expense,number,0)) as expense,FROM_UNIXTIME(create_time, '%Y-%m-%d') as time")->group("time");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
->limit($this->limitOffset, $this->limitLength)
|
||||||
|
->order(['id' => 'desc'])
|
||||||
|
->select()->each(function ($item) {
|
||||||
|
$item->month = date('m', strtotime($item->create_time));
|
||||||
|
})
|
||||||
|
->toArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function count(): int
|
||||||
|
{
|
||||||
|
return StoreFinanceFlow::where('1=1')
|
||||||
|
->when(!empty($this->request->adminInfo['store_id']), function ($query) {
|
||||||
|
$query->where('store_id', $this->request->adminInfo['store_id']);
|
||||||
|
})
|
||||||
|
->when(!empty($this->params['start_time']), function ($query) {
|
||||||
|
$query->whereTime('create_time', '>=', $this->params['start_time']);
|
||||||
|
})
|
||||||
|
->when(!empty($this->params['end_time']), function ($query) {
|
||||||
|
if ($this->params['end_time'] == $this->params['start_time']) {
|
||||||
|
$this->params['end_time'] = strtotime($this->params['end_time']) + 86399;
|
||||||
|
}
|
||||||
|
$query->whereTime('create_time', '<=', $this->params['end_time']);
|
||||||
|
})
|
||||||
|
->when(!empty($this->params['type']), function (Query $query) {
|
||||||
|
switch ($this->params['type']) {
|
||||||
|
case 2:
|
||||||
|
$query->fieldRaw("*,sum(number) as total_amount,YEAR(FROM_UNIXTIME(create_time)) as year,WEEK(FROM_UNIXTIME(create_time), 1) as week")->group("year,week,financial_pm");
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
$query->fieldRaw("*,sum(number) as total_amount,FROM_UNIXTIME(create_time, '%Y-%m') as time")->group("time,financial_pm");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$query->fieldRaw("*,sum(number) as total_amount,FROM_UNIXTIME(create_time, '%Y-%m-%d') as time")->group("time,financial_pm");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
->count();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
71
app/store/controller/finance/StoreBillController.php
Normal file
71
app/store/controller/finance/StoreBillController.php
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\store\controller\finance;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
#[ApiDoc\title('账单记录')]
|
||||||
|
class StoreBillController extends BaseAdminController
|
||||||
|
{
|
||||||
|
|
||||||
|
#[
|
||||||
|
ApiDoc\Title('列表'),
|
||||||
|
ApiDoc\url('/store/finance/storeBill/lists'),
|
||||||
|
ApiDoc\Method('GET'),
|
||||||
|
ApiDoc\NotHeaders(),
|
||||||
|
ApiDoc\Author('中国队长'),
|
||||||
|
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\Header(ref: [Definitions::class, "token"]),
|
||||||
|
ApiDoc\Query(ref: [Definitions::class, "page"]),
|
||||||
|
ApiDoc\ResponseSuccess("data", type: "array"),
|
||||||
|
]
|
||||||
|
public function lists()
|
||||||
|
{
|
||||||
|
return $this->dataLists(new StoreBillLists());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[
|
||||||
|
ApiDoc\Title('详情'),
|
||||||
|
ApiDoc\url('/store/finance/storeBill/detail'),
|
||||||
|
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 detail(StoreFinanceFlowLogic $logic)
|
||||||
|
{
|
||||||
|
$id = $this->request->post('id');
|
||||||
|
$remark = $this->request->post('remark');
|
||||||
|
$logic->remark($id, $remark);
|
||||||
|
return $this->success('操作成功', [], 1, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user