增加每日推送的导出和排序
This commit is contained in:
@@ -4,6 +4,7 @@ namespace app\admin\controller\mall;
|
||||
|
||||
use Throwable;
|
||||
use app\common\library\MallDailyPushBackfill;
|
||||
use app\common\library\MallDailyPushExport;
|
||||
use app\common\controller\Backend;
|
||||
use support\Response;
|
||||
use Webman\Http\Request;
|
||||
@@ -35,6 +36,11 @@ class DailyPush extends Backend
|
||||
'create_time',
|
||||
];
|
||||
|
||||
/**
|
||||
* exportCount 与 export 共用导出权限
|
||||
*/
|
||||
protected array $noNeedPermission = ['exportCount'];
|
||||
|
||||
public function initialize(): void
|
||||
{
|
||||
parent::initialize();
|
||||
@@ -59,6 +65,73 @@ class DailyPush extends Backend
|
||||
return $this->_index();
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出筛选结果条数预览
|
||||
*/
|
||||
public function exportCount(Request $request): Response
|
||||
{
|
||||
$response = $this->initializeBackend($request);
|
||||
if ($response !== null) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
if (!$this->auth->check('mall/dailyPush/export')) {
|
||||
return $this->error(__('You have no permission'), [], 401);
|
||||
}
|
||||
|
||||
try {
|
||||
[$where, $alias] = $this->buildExportQueryParts();
|
||||
$count = $this->model->alias($alias)->where($where)->count();
|
||||
$exporter = new MallDailyPushExport();
|
||||
return $this->success('', [
|
||||
'count' => $count,
|
||||
'max_limit' => $exporter->getMaxExportLimit(),
|
||||
]);
|
||||
} catch (Throwable $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出 Excel(CSV 流式写入,兼容 Excel 打开)
|
||||
*/
|
||||
public function export(Request $request): Response
|
||||
{
|
||||
$response = $this->initializeBackend($request);
|
||||
if ($response !== null) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$fieldsRaw = $request->post('fields', $request->get('fields', []));
|
||||
$fields = is_array($fieldsRaw) ? $fieldsRaw : explode(',', strval($fieldsRaw));
|
||||
$limitRaw = strval($request->post('export_limit', $request->get('export_limit', '1000')));
|
||||
if (!is_numeric($limitRaw)) {
|
||||
return $this->error(__('Parameter error'));
|
||||
}
|
||||
$limit = intval($limitRaw);
|
||||
if ($limit < 1) {
|
||||
return $this->error(__('Parameter error'));
|
||||
}
|
||||
|
||||
try {
|
||||
[$where, $alias, $order] = $this->buildExportQueryParts();
|
||||
$lang = strval($request->header('think-lang', 'zh-cn'));
|
||||
$exporter = new MallDailyPushExport();
|
||||
return $exporter->export($this->model, $where, $alias, $order, $fields, $limit, $lang);
|
||||
} catch (Throwable $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{0: array, 1: array, 2: array}
|
||||
*/
|
||||
private function buildExportQueryParts(): array
|
||||
{
|
||||
[$where, $alias, , $order] = $this->queryBuilder();
|
||||
return [$where, $alias, $order];
|
||||
}
|
||||
|
||||
/**
|
||||
* 按历史 mall_daily_push 记录回补用户信息
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user