1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- namespace catchAdmin\yunying\controller;
- use catcher\base\CatchRequest as Request;
- use catcher\CatchResponse;
- use catcher\base\CatchController;
- use catchAdmin\yunying\model\Vehicle as vehicleModel;
- use catcher\library\excel\Excel;
- use catchAdmin\yunying\excel\VehiclesExport;
- use catcher\Utils;
- class Vehicle extends CatchController
- {
- protected $vehicleModel;
-
- public function __construct(VehicleModel $vehicleModel)
- {
- $this->vehicleModel = $vehicleModel;
- }
-
- /**
- * 列表
- * @time 2022年01月20日 10:42
- * @param Request $request
- */
- public function index(Request $request) : \think\Response
- {
- $field = $request->get('field')?:'id';
- $order = $request->get('order')?:'desc';
- return CatchResponse::paginate($this->vehicleModel->getVehicleList($field,$order));
- }
-
- /**
- * 保存信息
- * @time 2022年01月20日 10:42
- * @param Request $request
- */
- public function save(Request $request) : \think\Response
- {
- return CatchResponse::success($this->vehicleModel->storeBy($request->post()));
- }
-
- /**
- * 读取
- * @time 2022年01月20日 10:42
- * @param $id
- */
- public function read($id) : \think\Response
- {
- return CatchResponse::success($this->vehicleModel->findBy($id));
- }
-
- /**
- * 更新
- * @time 2022年01月20日 10:42
- * @param Request $request
- * @param $id
- */
- public function update(Request $request, $id) : \think\Response
- {
- return CatchResponse::success($this->vehicleModel->updateBy($id, $request->post()));
- }
-
- /**
- * 删除
- * @time 2022年01月20日 10:42
- * @param $id
- */
- public function delete($id) : \think\Response
- {
- return CatchResponse::success($this->vehicleModel->deleteBy($id));
- }
- /**
- * 导出
- *
- * @time 2022年01月22日
- * @param Excel $excel
- * @param VehicleExport $vehicleExport
- * @throws \PhpOffice\PhpSpreadsheet\Exception
- * @return \think\response\Json
- */
- public function export_vehicle(Excel $excel, VehiclesExport $VehicleExport)
- {
- // var_dump(Utils::publicPath('export/users'));//导出路径
- return CatchResponse::success($excel->save($VehicleExport, Utils::publicPath('export/vehicles'), 'local', '车辆列表'));
- }
- }
|