multi-store/app/admin/lists/ActivityZoneLists.php

84 lines
2.3 KiB
PHP

<?php
namespace app\admin\lists;
use app\admin\lists\BaseAdminDataLists;
use app\common\model\ActivityZone;
use app\common\lists\ListsSearchInterface;
use app\common\model\store_product\StoreProduct;
use app\common\model\store_product_unit\StoreProductUnit;
/**
* ActivityZone列表
* Class ActivityZoneLists
* @package app\admin\lists
*/
class ActivityZoneLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author admin
* @date 2024/12/20 10:52
*/
public function setSearch(): array
{
return [
'=' => ['form_id'],
];
}
/**
* @notes 获取列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author admin
* @date 2024/12/20 10:52
*/
public function lists(): array
{
$query = ActivityZone::where($this->searchWhere);
if (!empty($this->params['store_name'])) {
$productIds = StoreProduct::where('store_name', 'like', "%{$this->params['store_name']}%")->column('id');
$query->whereIn('product_id', $productIds);
}
$list = $query->with('product')
->field(['id', 'form_id', 'product_id'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()
->toArray();
$unitIds = array_unique(array_column($list, 'unit'));
$unit = StoreProductUnit::whereIn('id', $unitIds)->field('id,name')->withTrashed()->select()->toArray();
$unit = reset_index($unit, 'id');
foreach ($list as &$item) {
$item['unit_name'] = $unit[$item['unit']]['name'] ?? '';
}
return $list;
}
/**
* @notes 获取数量
* @return int
* @author admin
* @date 2024/12/20 10:52
*/
public function count(): int
{
$query = ActivityZone::where($this->searchWhere);
if (!empty($this->params['store_name'])) {
$productIds = StoreProduct::where('store_name', 'like', "%{$this->params['store_name']}%")->column('id');
$query->whereIn('product_id', $productIds);
}
return $query->count();
}
}