$code, 'show' => $show, 'msg' => $msg, 'data' => $data ); return json($result, $httpStatus); } /** * @notes 抛出JSON * @param string $msg * @param array $data * @param int $code * @param int $show * @author 令狐冲 * @date 2021/6/29 20:29 */ public static function throw(string $msg = 'fail', array $data = [], int $code = 0, int $show = 1): Json { $data = array('code' => $code, 'show' => $show, 'msg' => $msg, 'data' => $data); $response = Response::create($data, 'json', 200); throw new HttpResponseException($response); } /** * @notes 数据列表 * @param \app\common\lists\BaseDataLists $lists * @return \think\response\Json * @author 令狐冲 * @date 2021/7/28 11:15 */ public static function dataLists(BaseDataLists $lists): Json { //获取导出信息 if ($lists->export == ExportEnum::INFO && $lists instanceof ListsExcelInterface) { return self::data($lists->excelInfo()); } //获取导出文件的下载链接 if ($lists->export == ExportEnum::EXPORT && $lists instanceof ListsExcelInterface) { $exportDownloadUrl = $lists->createExcel($lists->setExcelFields(), $lists->lists()); return self::success('', ['url' => $exportDownloadUrl], 2); } $data = [ 'lists' => $lists->lists(), 'count' => $lists->count(), 'page_no' => $lists->pageNo, 'page_size' => $lists->pageSize, ]; $data['extend'] = []; if ($lists instanceof ListsExtendInterface) { $data['extend'] = $lists->extend(); } return self::success('', $data, 1, 0); } }