Files
ulthon_admin/app/admin/controller/test/Goods.php
2026-01-08 23:43:21 +08:00

120 lines
3.8 KiB
PHP

<?php
namespace app\admin\controller\test;
use app\common\controller\AdminController;
use app\admin\service\annotation\ControllerAnnotation;
use app\admin\service\annotation\NodeAnotation;
use think\App;
/**
* @ControllerAnnotation(title="test_goods")
*/
class Goods extends AdminController
{
/**
* 是否关联查询.
* @var bool
*/
protected $relationSearch = true;
use \app\admin\traits\Curd;
public function __construct(App $app)
{
parent::__construct($app);
$this->model = new \app\admin\model\TestGoods();
$select_list_status_list = [];
foreach ($this->model::SELECT_LIST_STATUS as $key => $value) {
$select_list_status_list[] = ['value' => $key, 'label' => $value];
}
$this->assign('select_list_status', $select_list_status_list, true);
$select_list_time_status_list = [];
foreach ($this->model::SELECT_LIST_TIME_STATUS as $key => $value) {
$select_list_time_status_list[] = ['value' => $key, 'label' => $value];
}
$this->assign('select_list_time_status', $select_list_time_status_list, true);
$select_list_is_recommend_list = [];
foreach ($this->model::SELECT_LIST_IS_RECOMMEND as $key => $value) {
$select_list_is_recommend_list[] = ['value' => $key, 'label' => $value];
}
$this->assign('select_list_is_recommend', $select_list_is_recommend_list, true);
$select_list_shop_type_list = [];
foreach ($this->model::SELECT_LIST_SHOP_TYPE as $key => $value) {
$select_list_shop_type_list[] = ['value' => $key, 'label' => $value];
}
$this->assign('select_list_shop_type', $select_list_shop_type_list, true);
}
/**
* @NodeAnotation(title="列表")
*/
public function index()
{
if ($this->request->isAjax()) {
if (input('selectFields')) {
return $this->selectList();
}
list($page, $limit, $where) = $this->buildTableParames();
$count = $this->model
->withJoin(['mallCate'], 'LEFT')
->where($where)
->count();
$list = $this->model
->withJoin(['mallCate'], 'LEFT')
->where($where)
->page($page, $limit)
->order($this->sort)
->select();
$data = [
'code' => 0,
'msg' => '',
'count' => $count,
'data' => $list,
];
return json($data);
}
return $this->fetch();
}
/**
* @NodeAnotation(title="导出")
*/
public function export()
{
list($page, $limit, $where) = $this->buildTableParames();
$this->model = $this->model->withJoin(['mallCate'], 'LEFT');
$fields = $this->request->param('fields', '{}', null);
$image_fields = $this->request->param('image_fields', '{}', null);
$select_fields = $this->request->param('select_fields', '{}', null);
$date_fields = $this->request->param('date_fields', '{}', null);
$fields = json_decode($fields, true);
$image_fields = json_decode($image_fields, true);
$select_fields = json_decode($select_fields, true);
$date_fields = json_decode($date_fields, true);
$content = \app\common\tools\ExportTools::excel($this->model, $where, $fields, $image_fields, $select_fields, $date_fields);
$export_file_name = $this->exportFileName;
if (empty($export_file_name)) {
$export_file_name = $this->model->getName();
}
return download($content, $export_file_name . date('YmdHis') . '.xlsx', true);
}
}