lihaiMiddleOffice/app/psi/lists/WarehouseOrderLists.php

94 lines
3.0 KiB
PHP

<?php
namespace app\psi\lists;
use app\common\enum\OrderEnum;
use app\common\lists\BaseDataLists;
use app\common\model\auth\Admin;
use app\common\model\psi\warehouse\Warehouse;
use app\common\model\supplier\Supplier;
use app\common\model\system_store\SystemStore;
use app\common\model\WarehouseOrder;
use app\common\lists\ListsSearchInterface;
/**
* PsiWarehouseOrder列表
* Class WarehouseOrderLists
* @package app\psi\lists
*/
class WarehouseOrderLists extends BaseDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author admin
* @date 2025/03/10 11:08
*/
public function setSearch(): array
{
return [
'=' => ['supplier_id', 'warehouse_id', 'store_id', 'id', 'oid', 'order_type'],
'%like' => ['code'],
'between_time' => 'create_time'
];
}
/**
* @notes 获取列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author admin
* @date 2025/03/10 11:08
*/
public function lists(): array
{
return WarehouseOrder::where($this->searchWhere)
->field(['id', 'warehouse_id', 'supplier_id', 'store_id', 'code', 'admin_id', 'batch', 'mark', 'nums', 'purchase', 'total_price', 'status', 'create_time', 'completed_amount', 'outstanding_amount', 'oid', 'order_type'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()->each(function ($item) {
if ($item->store_id) {
$item->system_store = SystemStore::where('id', $item->store_id)->value('name');
} else {
$item->system_store = '';
}
if ($item->admin_id) {
$item->admin_name = Admin::where('id', $item->admin_id)->value('name');
} else {
$item->admin_name = '';
}
if ($item->warehouse_id) {
$item->warehouse_name = Warehouse::where('id', $item->warehouse_id)->value('name');
} else {
$item->warehouse_name = '';
}
if ($item->supplier_id) {
$item->supplier_name = Supplier::where('id', $item->supplier_id)->value('name');
}else{
$item->supplier_name = '';
}
if (!empty($item['order_type'])) {
$item->order_type_name = OrderEnum::getOrderTypeName($item->order_type);
} else {
$item->order_type_name = '';
}
})
->toArray();
}
/**
* @notes 获取数量
* @return int
* @author admin
* @date 2025/03/10 11:08
*/
public function count(): int
{
return WarehouseOrder::where($this->searchWhere)->count();
}
}