lihaiMiddleOffice/app/psi/lists/OutboundProductLists.php

161 lines
6.5 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\OutboundOrder;
use app\common\model\OutboundProduct;
use app\common\lists\ListsSearchInterface;
use app\common\model\psi\warehouse\Warehouse;
use app\common\model\store_category\StoreCategory;
use app\common\model\store_product\StoreProduct;
use app\common\model\store_product_unit\StoreProductUnit;
use app\common\model\supplier\Supplier;
use app\common\model\system_store\SystemStore;
use app\common\model\WarehouseOrder;
use app\common\model\WarehouseProduct;
/**
* PsiOutboundProduct列表
* Class OutboundProductLists
* @package app\psi\lists
*/
class OutboundProductLists extends BaseDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author admin
* @date 2025/03/10 11:08
*/
public function setSearch(): array
{
return [
'=' => ['warehouse_id', 'store_id'],
'%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
{
if ($this->request->get('product_name')) {
$product_name = $this->request->get('product_name');
$ids = StoreProduct::where('store_name', 'like', '%' . $product_name . '%')->withTrashed()->column('id');
if ($ids) {
$this->searchWhere[] = ['product_id', 'in', $ids];
$this->ids = $ids;
} else {
return [];
}
}
if ($this->request->get('bar_code')) {
$bar_code = $this->request->get('bar_code');
$ids = StoreProduct::where('bar_code', 'like', '%' . $bar_code . '%')->withTrashed()->column('id');
if ($ids) {
$this->searchWhere[] = ['product_id', 'in', $ids];
$this->ids = $ids;
} else {
return [];
}
}
$query = OutboundProduct::where($this->searchWhere);
if (isset($this->params['is_group']) && $this->params['is_group'] == 1) {
$query->group('product_id')->field(['id', 'code', 'pay_type', 'oid', 'admin_id', 'supplier_id', 'store_id', 'warehouse_id', 'product_id', 'batch', 'sum(nums) nums', 'price', 'purchase', 'cost', 'sum(total_price) total_price', 'manufacture', 'expiration_date', 'status', 'mark', 'create_time', 'is_pay', 'order_type', 'vip_price']);
} else {
$query->field(['id', 'code', 'pay_type', 'oid', 'admin_id', 'supplier_id', 'store_id', 'warehouse_id', 'product_id', 'batch', 'nums', 'price', 'purchase', 'cost', 'total_price', 'manufacture', 'expiration_date', 'status', 'mark', 'create_time', 'is_pay', 'order_type', 'vip_price']);
}
return $query
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()->each(function ($item) {
$item->store_name = '';
$item->image = '';
$item->price = $item['price'] ?? 0;
$item->purchase = $item['purchase'] ?? 0;
$item->unit_name = '';
$item->store_info = '';
$item->top_cate_name = '';
$item->order_type_name = '';
if ($item->store_id > 0) {
$item->system_store_name = SystemStore::where('id', $item->store_id)->value('name');
} else {
$item->system_store_name = '';
}
if ($item->status == 0) {
$item->status_name = '未确认';
} elseif ($item->status == 1) {
$item->status_name = '已确认';
} else {
$item->status_name = '库存不足';
}
if ($item->admin_id) {
$item->admin_name = Admin::where('id', $item->admin_id)->value('name');
} else {
$item->admin_name = '';
}
if ($item->product_id) {
$find = StoreProduct::where('id', $item->product_id)->field('price,purchase,image,store_name,unit,store_info,top_cate_id')->withTrashed()->find();
if ($find) {
$item->store_name = $item->product_id . '|' . $find->store_name;
$item->image = $find->image;
$item->unit_name = StoreProductUnit::where('id', $find->unit)->value('name');
$item->store_info = $find->store_info;
$item->top_cate_name = StoreCategory::where('id', $find->top_cate_id)->value('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 = '';
}
$item->expiration_date = $item->expiration_date ? date('Y-m-d', $item->expiration_date) : '';
$item->manufacture = $item->manufacture ? date('Y-m-d', $item->manufacture) : '';
if (!empty($item['order_type'])) {
$item->order_type_name = OrderEnum::getOrderTypeName($item->order_type);
} else {
$beforehandOrderId = OutboundOrder::where('id', $item['oid'])->value('oid');
if ($beforehandOrderId) {
$item->order_type_name = '';
}
}
if ($item->order_type == 5) {
$item->outbound = '无须出库';
}
$item->type_name = $item->getTypeName();
})
->toArray();
}
/**
* @notes 获取数量
* @return int
* @author admin
* @date 2025/03/10 11:08
*/
public function count(): int
{
return OutboundProduct::where($this->searchWhere)->count();
}
}