Commit 75ea2f15 authored by 冯超鹏's avatar 冯超鹏

工单模块 app

parent 90f8e536
Pipeline #207 failed with stages
...@@ -19,11 +19,11 @@ class AlarmOrderController extends Controller ...@@ -19,11 +19,11 @@ class AlarmOrderController extends Controller
*/ */
public function index(Request $request) public function index(Request $request)
{ {
if($this->isadmin()) { $where = [];
$limit = 20; $limit = 20;
$offset = $limit * ($request->input('page') - 1); $offset = $limit * ($request->input('page') - 1);
if($request->input('isuser') == 'user'){ if($request->input('isuser') == 'user'){
$where = [];
$where[] = ['u.id','=',Auth::id()]; $where[] = ['u.id','=',Auth::id()];
} }
$orders = AlarmOrder::selectRaw(' $orders = AlarmOrder::selectRaw('
...@@ -31,7 +31,7 @@ class AlarmOrderController extends Controller ...@@ -31,7 +31,7 @@ class AlarmOrderController extends Controller
FROM_UNIXTIME(r.endtime) AS end_time, FROM_UNIXTIME(r.endtime) AS end_time,
alarm_order.*, alarm_order.*,
r.devicenumber, r.concentration, r.location, r.policestatus, r.shutoff_status, r.devicenumber, r.concentration, r.location, r.policestatus, r.shutoff_status,
d.devicecoord, d.username, d.devicecoord, d.username,t.tname,
u.name, u.phone_number, u.name, u.phone_number,
s.status_name s.status_name
') ')
...@@ -39,15 +39,12 @@ class AlarmOrderController extends Controller ...@@ -39,15 +39,12 @@ class AlarmOrderController extends Controller
->leftjoin('device AS d', 'd.id', '=', 'alarm_order.device_id') ->leftjoin('device AS d', 'd.id', '=', 'alarm_order.device_id')
->leftjoin('users AS u', 'alarm_order.user_id', '=', 'u.id') ->leftjoin('users AS u', 'alarm_order.user_id', '=', 'u.id')
->leftjoin('status AS s', 's.id', '=', 'alarm_order.reportpolice_id') ->leftjoin('status AS s', 's.id', '=', 'alarm_order.reportpolice_id')
->leftjoin('device_type AS t', 'r.policestatus', '=', 't.tid')
->offset($offset) ->offset($offset)
->where($where) ->where($where)
->limit($limit) ->limit($limit)
->get()->toArray(); ->get()->toArray();
return $this->jsonSuccessData($orders); return $this->jsonSuccessData($orders);
}else{
return $this->jsonErrorData(500, '没有权限,请联系管理员');
}
} }
...@@ -101,13 +98,28 @@ class AlarmOrderController extends Controller ...@@ -101,13 +98,28 @@ class AlarmOrderController extends Controller
* @param int $id * @param int $id
* @return \Illuminate\Http\Response * @return \Illuminate\Http\Response
*/ */
public function show($id) public function show(Request $request)
{ {
$order = AlarmOrder::select('*')
->join('reportpolice AS r', 'r.id', '=', 'alarm_order.reportpolice_id') $order = AlarmOrder::leftjoin('reportpolice AS r', 'r.id', '=', 'alarm_order.reportpolice_id')
->where('alarm_order.id', '=', $id) ->leftjoin('device AS d', 'd.id', '=', 'alarm_order.device_id')
->get(); ->leftjoin('users AS u', 'alarm_order.user_id', '=', 'u.id')
$this->jsonSuccessData($order); ->leftjoin('status AS s', 's.id', '=', 'alarm_order.reportpolice_id')
->leftjoin('device_type AS t', 'r.policestatus', '=', 't.tid')
->leftjoin('gas AS g', 'd.status', '=', 'g.id')
->leftjoin('danwei AS w', 'd.devicemonad', '=', 'w.id')
->where('alarm_order.id', '=', $request->input('id'))
->selectRaw('
FROM_UNIXTIME(r.starttime) AS start_time,
FROM_UNIXTIME(r.endtime) AS end_time,
alarm_order.*,
r.devicenumber, r.concentration, r.location, r.policestatus, r.shutoff_status,
d.devicecoord, d.username,t.tname,d.deviceinfo,g.gas,w.danwei,
u.name, u.phone_number,
s.status_name
')
->first();
return $this->jsonSuccessData($order);
} }
/** /**
...@@ -117,7 +129,7 @@ class AlarmOrderController extends Controller ...@@ -117,7 +129,7 @@ class AlarmOrderController extends Controller
* @param int $id * @param int $id
* @return \Illuminate\Http\Response * @return \Illuminate\Http\Response
*/ */
public function update(Request $request, $id) public function update(Request $request)
{ {
$data = $request->all(); $data = $request->all();
...@@ -126,9 +138,9 @@ class AlarmOrderController extends Controller ...@@ -126,9 +138,9 @@ class AlarmOrderController extends Controller
try { try {
AlarmOrderSchedule::insert(array_merge( AlarmOrderSchedule::insert(array_merge(
$data['schedule'], $data['schedule'],
['created_at' => Carbon::now(), 'alarm_order_id' => $id])); ['created_at' => Carbon::now(), 'alarm_order_id' => $data['id']]));
unset($data['schedule']); unset($data['schedule']);
$order = AlarmOrder::where('id', $id) $order = AlarmOrder::where('id', $data['id'])
->update(array_merge($data, ['updated_at' => Carbon::now()])); ->update(array_merge($data, ['updated_at' => Carbon::now()]));
DB::commit(); DB::commit();
} catch (QueryException $exception) { } catch (QueryException $exception) {
...@@ -137,7 +149,7 @@ class AlarmOrderController extends Controller ...@@ -137,7 +149,7 @@ class AlarmOrderController extends Controller
} }
}else{ }else{
$order = AlarmOrder::where('id', $id) $order = AlarmOrder::where('id', $data['id'])
->update(array_merge($data, ['updated_at' => Carbon::now()])); ->update(array_merge($data, ['updated_at' => Carbon::now()]));
} }
if($order) { if($order) {
......
...@@ -51,9 +51,9 @@ Route::group(['middleware' => 'auth:api'], function () { ...@@ -51,9 +51,9 @@ Route::group(['middleware' => 'auth:api'], function () {
// 报警工单 // 报警工单
Route::get('alarm_order', 'AlarmOrderController@index'); // 工单列表 Route::get('alarm_order', 'AlarmOrderController@index'); // 工单列表
Route::post('alarm_order', 'AlarmOrderController@store'); // 创建工单 Route::post('alarm_order', 'AlarmOrderController@store'); // 创建工单
Route::patch('alarm_order/{id}', 'AlarmOrderController@update'); // 修改工单 Route::post('alarm_order/order_ok', 'AlarmOrderController@update'); // 修改工单
Route::delete('alarm_order/{id}', 'AlarmOrderController@destroy'); // 删除工单 Route::delete('alarm_order/{id}', 'AlarmOrderController@destroy'); // 删除工单
Route::get('alarm_order/show/{id}', 'AlarmOrderController@show'); // 工单详情 Route::get('alarm_order/show', 'AlarmOrderController@show'); // 工单详情
}); });
//上传图片路由 //上传图片路由
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment