123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- <?php
- namespace catchAdmin\yunying\controller;
- use catchAdmin\permissions\controller\User;
- use catcher\base\CatchRequest as Request;
- use catcher\CatchResponse;
- use catcher\base\CatchController;
- use catchAdmin\permissions\model\Users;
- use catchAdmin\device\model\Device;
- use catchAdmin\yunying\model\Vehicle as vehicleModel;
- use catchAdmin\permissions\model\Department;
- use catchAdmin\yunying\model\VehicleBrand;
- use catchAdmin\yunying\model\VehicleColor;
- use catchAdmin\yunying\model\StolenVehicle;
- use catchAdmin\yunying\model\VehiclePhoto;
- 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;
- }
-
-
- 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));
- }
-
-
- public function save(Request $request) : \think\Response
- {
- return CatchResponse::success($this->vehicleModel->storeBy($request->post()));
- }
-
-
- public function read($id) : \think\Response
- {
- $data = $this->vehicleModel->findBy($id)->toArray();
-
- $data['department_id'] = (new Department())->where('id',$data['department_id'])->value('department_name');
- $data['brand_id'] = (new VehicleBrand())->where('id',$data['brand_id'])->value('name');
- $data['color_id'] = (new VehicleColor())->where('id',$data['color_id'])->value('name');
-
- $stolen_info = (new StolenVehicle())->where('vehicle_id', $id)->find();
- if (!$stolen_info || in_array($stolen_info['result'], [2, 4])) {
- $data['status'] = '<font style="color:green">正常</font>';
- } else {
- $data['status'] = '<font style="color:red">被盗</font>';
- }
-
- $data['chezhu'] = (new Users())->where('id',$data['user_id'])->field('realname,phone,idcard')->find();
-
- $data['chezhu']['idcard'] = $data['chezhu']['idcard']?substr($data['chezhu']['idcard'],0,6)."****".substr($data['chezhu']['idcard'],14,4):'';
-
- $data['photos'] = (new VehiclePhoto())->where('vehicle_id',$id)->field('url,type')->select();
-
- $data['labels'] = (new Device())->where('bind_id',$id)->field('imei,rfid,online_time')->select();
-
- return CatchResponse::success($data);
- }
-
-
- public function update(Request $request, $id) : \think\Response
- {
- return CatchResponse::success($this->vehicleModel->updateBy($id, $request->post()));
- }
-
-
- public function delete($id) : \think\Response
- {
- return CatchResponse::success($this->vehicleModel->deleteBy($id));
- }
-
- public function export_vehicle(Excel $excel, VehiclesExport $VehicleExport)
- {
-
- return CatchResponse::success($excel->save($VehicleExport, Utils::publicPath('export/vehicles'), 'local', '车辆列表'));
- }
- }
|