作者 郭文星

132

<?php
namespace app\admin\controller;
use app\admin\controller\Index;
use app\common\controller\Backend;
use think\Db;
use think\exception\DbException;
use think\exception\PDOException;
use think\exception\ValidateException;
/**
* 车辆管理
... ... @@ -26,7 +23,7 @@ class Car extends Backend
{
parent::_initialize();
$this->model = new \app\admin\model\Car;
$this->view->assign("statusList", $this->model->getStatusList());
}
... ... @@ -55,19 +52,19 @@ class Car extends Backend
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$list = $this->model
->with(['route','driver','seat'])
->with(['route','seat','driver'])
->where($where)
->order($sort, $order)
->paginate($limit);
foreach ($list as $row) {
$row->visible(['id','car_model','license_plate','colour','reservation_time','start_time','create_time']);
$row->visible(['id','car_model','license_plate','seat','colour','driving_license','driver_license','reservation_time','start_time','create_time','status','carmodel_id']);
$row->visible(['route']);
$row->getRelation('route')->visible(['name']);
$row->visible(['driver']);
$row->getRelation('driver')->visible(['name']);
$row->visible(['seat']);
$row->getRelation('seat')->visible(['name']);
$row->visible(['driver']);
$row->getRelation('driver')->visible(['name']);
}
$result = array("total" => $list->total(), "rows" => $list->items());
... ... @@ -76,7 +73,6 @@ class Car extends Backend
}
return $this->view->fetch();
}
/**
* 添加
*
... ... @@ -112,8 +108,7 @@ class Car extends Backend
// }
$route=Db::name("route")->where("id",$params['route_id'])->find();
$driver=Db::name("driver")->where("id",$params['driver_id'])->find();
$result = $this->model->allowField(true)->insertGetId($params);
$result = $this->model->allowField(true)->save($params);
$index=new Index();
$data=[
"start_address"=>$route["start_address"],
... ... @@ -169,8 +164,7 @@ class Car extends Backend
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
$row->validateFailException()->validate($validate);
}
$result = $row->allowField(true)->insertGetId($params);
$this->getAccessToken($result);
$result = $row->allowField(true)->save($params);
Db::commit();
} catch (ValidateException|PDOException|Exception $e) {
Db::rollback();
... ... @@ -182,5 +176,4 @@ class Car extends Backend
$this->success();
}
}
... ...
... ... @@ -153,7 +153,7 @@ class Index extends Backend
$response = Response::create()->header("Content-Type", $mimetype);
// 写入到文件
if ($config['writefile']) {
$qrcodePath = ROOT_PATH . 'public/uploads/store_qrcode/';
$qrcodePath = ROOT_PATH . 'public/uploads/';
if (!is_dir($qrcodePath)) {
@mkdir($qrcodePath);
}
... ...
... ... @@ -8,11 +8,19 @@ return [
'Driver_id' => '司机',
'Seat' => '座位数',
'Colour' => '车辆颜色',
'Seat_id' => '座位价格',
'Driving_license' => '行驶证',
'Driver_license' => '驾照',
'Seat_id' => '座位id',
'Reservation_time' => '预约时间',
'Start_time' => '发车时间',
'Create_time' => '创建时间',
'Status' => '车辆认证',
'Status 1' => '已审核',
'Set status to 1' => '设为已审核',
'Status 2' => '未审核',
'Set status to 2' => '设为未审核',
'Carmodel_id' => '车型',
'Route.name' => '线路名称',
'Driver.name' => '司机名称',
'Seat.name' => '座位名称'
'Seat.name' => '座位名称',
'Driver.name' => '司机名称'
];
... ...
... ... @@ -27,12 +27,16 @@ class Car extends Model
protected $append = [
'reservation_time_text',
'start_time_text',
'create_time_text'
'create_time_text',
'status_text'
];
public function getStatusList()
{
return ['1' => __('Status 1'), '2' => __('Status 2')];
}
public function getReservationTimeTextAttr($value, $data)
... ... @@ -55,6 +59,14 @@ class Car extends Model
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
}
public function getStatusTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
$list = $this->getStatusList();
return isset($list[$value]) ? $list[$value] : '';
}
protected function setReservationTimeAttr($value)
{
return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
... ... @@ -77,14 +89,14 @@ class Car extends Model
}
public function driver()
public function seat()
{
return $this->belongsTo('Driver', 'driver_id', 'id', [], 'LEFT')->setEagerlyType(0);
return $this->belongsTo('Seat', 'seat_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
public function seat()
public function driver()
{
return $this->belongsTo('Seat', 'seat_id', 'id', [], 'LEFT')->setEagerlyType(0);
return $this->belongsTo('Driver', 'driver_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
}
... ...
... ... @@ -37,6 +37,34 @@
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Driving_license')}:</label>
<div class="col-xs-12 col-sm-8">
<div class="input-group">
<input id="c-driving_license" class="form-control" size="50" name="row[driving_license]" type="text">
<div class="input-group-addon no-border no-padding">
<span><button type="button" id="faupload-driving_license" class="btn btn-danger faupload" data-input-id="c-driving_license" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/bmp,image/webp" data-multiple="false" data-preview-id="p-driving_license"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>
<span><button type="button" id="fachoose-driving_license" class="btn btn-primary fachoose" data-input-id="c-driving_license" data-mimetype="image/*" data-multiple="false"><i class="fa fa-list"></i> {:__('Choose')}</button></span>
</div>
<span class="msg-box n-right" for="c-driving_license"></span>
</div>
<ul class="row list-inline faupload-preview" id="p-driving_license"></ul>
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Driver_license')}:</label>
<div class="col-xs-12 col-sm-8">
<div class="input-group">
<input id="c-driver_license" class="form-control" size="50" name="row[driver_license]" type="text">
<div class="input-group-addon no-border no-padding">
<span><button type="button" id="faupload-driver_license" class="btn btn-danger faupload" data-input-id="c-driver_license" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/bmp,image/webp" data-multiple="false" data-preview-id="p-driver_license"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>
<span><button type="button" id="fachoose-driver_license" class="btn btn-primary fachoose" data-input-id="c-driver_license" data-mimetype="image/*" data-multiple="false"><i class="fa fa-list"></i> {:__('Choose')}</button></span>
</div>
<span class="msg-box n-right" for="c-driver_license"></span>
</div>
<ul class="row list-inline faupload-preview" id="p-driver_license"></ul>
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Seat_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-seat_id" data-rule="required" data-source="seat/index" class="form-control selectpage" name="row[seat_id]" type="text" value="">
... ... @@ -45,13 +73,13 @@
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Reservation_time')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-reservation_time" class="form-control datetimepicker" data-date-format="HH:mm" data-use-current="true" name="row[reservation_time]" type="text" value="{:date('Y-m-d H:i:s')}">
<input id="c-reservation_time" class="form-control datetimepicker" data-date-format=" HH:mm" data-use-current="true" name="row[reservation_time]" type="text" value="{:date('Y-m-d H:i:s')}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Start_time')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-start_time" class="form-control datetimepicker" data-date-format="HH:mm" data-use-current="true" name="row[start_time]" type="text" value="{:date('Y-m-d H:i:s')}">
<input id="c-start_time" class="form-control datetimepicker" data-date-format=" HH:mm" data-use-current="true" name="row[start_time]" type="text" value="{:date('Y-m-d H:i:s')}">
</div>
</div>
<div class="form-group">
... ... @@ -60,6 +88,24 @@
<input id="c-create_time" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[create_time]" type="text" value="{:date('Y-m-d H:i:s')}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Status')}:</label>
<div class="col-xs-12 col-sm-8">
<div class="radio">
{foreach name="statusList" item="vo"}
<label for="row[status]-{$key}"><input id="row[status]-{$key}" name="row[status]" type="radio" value="{$key}" {in name="key" value="1"}checked{/in} /> {$vo}</label>
{/foreach}
</div>
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Carmodel_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-carmodel_id" data-rule="required" data-source="carmodel/index" class="form-control selectpage" name="row[carmodel_id]" type="text" value="">
</div>
</div>
<div class="form-group layer-footer">
<label class="control-label col-xs-12 col-sm-2"></label>
<div class="col-xs-12 col-sm-8">
... ...
... ... @@ -37,6 +37,34 @@
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Driving_license')}:</label>
<div class="col-xs-12 col-sm-8">
<div class="input-group">
<input id="c-driving_license" class="form-control" size="50" name="row[driving_license]" type="text" value="{$row.driving_license|htmlentities}">
<div class="input-group-addon no-border no-padding">
<span><button type="button" id="faupload-driving_license" class="btn btn-danger faupload" data-input-id="c-driving_license" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/bmp,image/webp" data-multiple="false" data-preview-id="p-driving_license"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>
<span><button type="button" id="fachoose-driving_license" class="btn btn-primary fachoose" data-input-id="c-driving_license" data-mimetype="image/*" data-multiple="false"><i class="fa fa-list"></i> {:__('Choose')}</button></span>
</div>
<span class="msg-box n-right" for="c-driving_license"></span>
</div>
<ul class="row list-inline faupload-preview" id="p-driving_license"></ul>
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Driver_license')}:</label>
<div class="col-xs-12 col-sm-8">
<div class="input-group">
<input id="c-driver_license" class="form-control" size="50" name="row[driver_license]" type="text" value="{$row.driver_license|htmlentities}">
<div class="input-group-addon no-border no-padding">
<span><button type="button" id="faupload-driver_license" class="btn btn-danger faupload" data-input-id="c-driver_license" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/bmp,image/webp" data-multiple="false" data-preview-id="p-driver_license"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>
<span><button type="button" id="fachoose-driver_license" class="btn btn-primary fachoose" data-input-id="c-driver_license" data-mimetype="image/*" data-multiple="false"><i class="fa fa-list"></i> {:__('Choose')}</button></span>
</div>
<span class="msg-box n-right" for="c-driver_license"></span>
</div>
<ul class="row list-inline faupload-preview" id="p-driver_license"></ul>
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Seat_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-seat_id" data-rule="required" data-source="seat/index" class="form-control selectpage" name="row[seat_id]" type="text" value="{$row.seat_id|htmlentities}">
... ... @@ -45,13 +73,13 @@
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Reservation_time')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-reservation_time" class="form-control datetimepicker" data-date-format="HH:mm" data-use-current="true" name="row[reservation_time]" type="text" value="{:$row.reservation_time?datetime($row.reservation_time):''}">
<input id="c-reservation_time" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[reservation_time]" type="text" value="{:$row.reservation_time?datetime($row.reservation_time):''}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Start_time')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-start_time" class="form-control datetimepicker" data-date-format="HH:mm" data-use-current="true" name="row[start_time]" type="text" value="{:$row.start_time?datetime($row.start_time):''}">
<input id="c-start_time" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[start_time]" type="text" value="{:$row.start_time?datetime($row.start_time):''}">
</div>
</div>
<div class="form-group">
... ... @@ -60,6 +88,24 @@
<input id="c-create_time" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[create_time]" type="text" value="{:$row.create_time?datetime($row.create_time):''}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Status')}:</label>
<div class="col-xs-12 col-sm-8">
<div class="radio">
{foreach name="statusList" item="vo"}
<label for="row[status]-{$key}"><input id="row[status]-{$key}" name="row[status]" type="radio" value="{$key}" {in name="key" value="$row.status"}checked{/in} /> {$vo}</label>
{/foreach}
</div>
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Carmodel_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-carmodel_id" data-rule="required" data-source="carmodel/index" class="form-control selectpage" name="row[carmodel_id]" type="text" value="{$row.carmodel_id|htmlentities}">
</div>
</div>
<div class="form-group layer-footer">
<label class="control-label col-xs-12 col-sm-2"></label>
<div class="col-xs-12 col-sm-8">
... ...
<div class="panel panel-default panel-intro">
{:build_heading()}
<div class="panel-heading">
{:build_heading(null,FALSE)}
<ul class="nav nav-tabs" data-field="status">
<li class="{:$Think.get.status === null ? 'active' : ''}"><a href="#t-all" data-value="" data-toggle="tab">{:__('All')}</a></li>
{foreach name="statusList" item="vo"}
<li class="{:$Think.get.status === (string)$key ? 'active' : ''}"><a href="#t-{$key}" data-value="{$key}" data-toggle="tab">{$vo}</a></li>
{/foreach}
</ul>
</div>
<div class="panel-body">
<div id="myTabContent" class="tab-content">
... ... @@ -12,7 +22,14 @@
<a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('car/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>
<div class="dropdown btn-group {:$auth->check('car/multi')?'':'hide'}">
<a class="btn btn-primary btn-more dropdown-toggle btn-disabled disabled" data-toggle="dropdown"><i class="fa fa-cog"></i> {:__('More')}</a>
<ul class="dropdown-menu text-left" role="menu">
{foreach name="statusList" item="vo"}
<li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:" data-params="status={$key}">{:__('Set status to ' . $key)}</a></li>
{/foreach}
</ul>
</div>
</div>
... ...
... ... @@ -31,13 +31,12 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
{field: 'car_model', title: __('Car_model'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
{field: 'license_plate', title: __('License_plate'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
{field: 'colour', title: __('Colour'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
{field: 'route.name', title: __('Route.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
{field: 'driver.name', title: __('Driver.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
{field: 'seat.name', title: __('Seat.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
{field: 'reservation_time', title: __('Reservation_time'), datetimeFormat:"HH:mm",operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
{field: 'start_time', title: __('Start_time'), datetimeFormat:"HH:mm", operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
{field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
{field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
{field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.status},
{field: 'route.name', title: __('Route.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
{field: 'driver.name', title: __('Driver.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
]
]
... ...