Commit b8bbed4a authored by Administrator's avatar Administrator

工单模块

parent 44f4648b
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\AlarmOrder;
use Illuminate\Support\Facades\DB;
use App\Models\AlarmOrderSchedule;
class AlarmOrderController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
{
if($this->isadmin()) {
$limit = 20;
$offset = $limit * ($request->input('page') - 1);
$orders = AlarmOrder::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')
->leftjoin('reportpolice AS r', 'r.id', '=', 'alarm_order.reportpolice_id')
->offset($offset)
->limit($limit)
->get()->toArray();
return $this->jsonSuccessData($orders);
}else{
return $this->jsonErrorData(500, '没有权限,请联系管理员');
}
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$reportpolice_id = $request->input('reportpolice_id');
$orderNum = date('YmdHis') .
substr($request->input('device_num'), -4).
$request->input('policestatus').
$request->input('shutoff_status');
$order = new AlarmOrder();
$insertId = $order->sharedLock()->insertGetId([
'order_num' => $orderNum,
'reportpolice_id' => $reportpolice_id,
]);
// 进度表新增
$orderSchedule = new AlarmOrderSchedule();
$orderSchedule->lockForUpdate();
$orderSchedule->alarm_order_id = $insertId;
$orderSchedule->schedule = 1;
$orderSchedule->save();
if($insertId) {
return $this->jsonSuccessData('已生成工单!');
}else{
return $this->jsonErrorData('工单创建失败');
}
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
$order = AlarmOrder::select('*')
->join('reportpolice AS r', 'r.id', '=', 'alarm_order.reportpolice_id')
->where('alarm_order.id', '=', $id)
->get();
$this->jsonSuccessData($order);
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$order = AlarmOrder::where('id', $id)
->update($request->all());
if($order) {
$this->jsonSuccessData('工单更新成功');
}else{
$this->jsonErrorData(500, '更新订单失败!');
}
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
$state = AlarmOrder::destroy($id);
if($state) {
$this->jsonSuccessData('删除成功');
}else{
$this->jsonErrorData(500, '删除工单失败!');
}
}
}
...@@ -28,7 +28,7 @@ class Controller extends BaseController ...@@ -28,7 +28,7 @@ class Controller extends BaseController
'msg' => $message, 'msg' => $message,
'data' => $data 'data' => $data
]; ];
return json_encode($content); return json_encode($content, JSON_UNESCAPED_UNICODE);
} }
/** /**
......
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Carbon;
class AlarmOrder extends Model
{
protected $table = 'alarm_order';
// 获取报警记录
public function reportpolices()
{
return $this->hasOne('Reportpolice');
}
public function getCreatedAtAttribute($value)
{
return Carbon::parse($value)->toDateTimeString();
}
public function getUpdatedAtAttribute($value)
{
return Carbon::parse($value)->toDateTimeString();
}
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class AlarmOrderSchedule extends Model
{
protected $table = 'alarm_order_schedule';
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Reportpolice extends Model
{
//
}
...@@ -67,7 +67,7 @@ return [ ...@@ -67,7 +67,7 @@ return [
| |
*/ */
'timezone' =>'PRC', 'timezone' =>'UTC',
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
......
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateAlarmOrderTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('alarm_order', function (Blueprint $table) {
$table->increments('id')->comment('主键');
$table->string('order_num', 32)->unique()->comment('工单号');
$table->integer('user_id')->comment('用户ID');
$table->integer('device_id')->comment('设备ID');
$table->integer('reportpolice_id')->comment('报警记录id');
$table->tinyInteger('is_live')->comment('1到达现场,2未到达现场');
$table->tinyInteger('is_verified')->comment('1属实,2不属实');
$table->string('content')->comment('反馈内容');
$table->tinyInteger('state')->comment('工单状态,0:进行中, 1完成,2,异常终止。');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('alarm_order');
}
}
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateAlarmOrderScheduleTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('alarm_order_schedule', function (Blueprint $table) {
$table->increments('id');
$table->integer('alarm_order_id')->comment('报警工单ID');
$table->tinyInteger('schedule')->comment('进度ID');
$table->string('content')->comment('进度详情');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('alarm_order_schedule');
}
}
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddShutOffToReportpoliceTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('reportpolice', function (Blueprint $table) {
$table->tinyInteger('shutoff_status')->comment('切断装置状态,0初始化状态,1开启,2关闭');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('reportpolice', function (Blueprint $table) {
$table->dropColumn('shutoff_status');
});
}
}
...@@ -31,6 +31,11 @@ ...@@ -31,6 +31,11 @@
<span>{{ scope.row.status_name }}</span> <span>{{ scope.row.status_name }}</span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="切断装置状态" width="150">
<template slot-scope="scope">
<span>{{ shutoffStatus(scope.row.shutoff_status) }}</span>
</template>
</el-table-column>
<el-table-column label="设备状态" width="155"> <el-table-column label="设备状态" width="155">
<template slot-scope="scope"> <template slot-scope="scope">
<el-tag :type="scope.row.status==1 ? 'danger' : 'success' " effect="dark">{{ scope.row.status==1 ? '报警' : '正常' }}</el-tag> <el-tag :type="scope.row.status==1 ? 'danger' : 'success' " effect="dark">{{ scope.row.status==1 ? '报警' : '正常' }}</el-tag>
...@@ -41,6 +46,11 @@ ...@@ -41,6 +46,11 @@
<el-tag :type="scope.row.status==1 ? 'danger' : 'success' " effect="dark">{{ scope.row.status==1 ? '当前正在报警' : '已结束报警' }}</el-tag> <el-tag :type="scope.row.status==1 ? 'danger' : 'success' " effect="dark">{{ scope.row.status==1 ? '当前正在报警' : '已结束报警' }}</el-tag>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="操作">
<template>
<el-button type="primary" effect="dark">生成工单</el-button>
</template>
</el-table-column>
</el-table> </el-table>
<el-tooltip placement="top" content="tooltip"> <el-tooltip placement="top" content="tooltip">
<back-to-top :custom-style="myBackToTopStyle" :visibility-height="300" :back-position="50" transition-name="fade" /> <back-to-top :custom-style="myBackToTopStyle" :visibility-height="300" :back-position="50" transition-name="fade" />
...@@ -73,6 +83,13 @@ export default { ...@@ -73,6 +83,13 @@ export default {
this.police(); // 列表 this.police(); // 列表
}, },
methods: { methods: {
shutoffStatus(id) {
const shutoff = [];
shutoff[0] = '初始化';
shutoff[1] = '开启';
shutoff[2] = '关闭';
return shutoff[id];
},
police() { police() {
police() police()
.then(response => { .then(response => {
......
...@@ -47,6 +47,13 @@ Route::group(['middleware' => 'auth:api'], function () { ...@@ -47,6 +47,13 @@ Route::group(['middleware' => 'auth:api'], function () {
Route::get('user/paperBasketList','UserController@paperBasketList');//返回废纸篓和用户状态 Route::get('user/paperBasketList','UserController@paperBasketList');//返回废纸篓和用户状态
Route::get('user/userLocation','UserController@userLocation');//返回用户安装位置 Route::get('user/userLocation','UserController@userLocation');//返回用户安装位置
Route::get('user/textcountuser','UserController@textcountuser');//用户测试接口 Route::get('user/textcountuser','UserController@textcountuser');//用户测试接口
// 报警工单
Route::get('alarm_order', 'AlarmOrderController@index'); // 工单列表
Route::post('alarm_order', 'AlarmOrderController@store'); // 创建工单
Route::patch('alarm_order/{id}', 'AlarmOrderController@update'); // 修改工单
Route::delete('alarm_order/{id}', 'AlarmOrderController@destroy'); // 删除工单
Route::get('alarm_order/show/{id}', 'AlarmOrderController@show'); // 工单详情
}); });
//上传图片路由 //上传图片路由
...@@ -130,108 +137,4 @@ Route::group(['middleware'=>'auth:api'],function (){ ...@@ -130,108 +137,4 @@ Route::group(['middleware'=>'auth:api'],function (){
Route::post('huinapphome/setseachdata','UinappHomeController@setseachdata');//指定查询 Route::post('huinapphome/setseachdata','UinappHomeController@setseachdata');//指定查询
Route::get('huinapphome/devicetype','UinappHomeController@devicetype');//测试添加页面选择数组数据 Route::get('huinapphome/devicetype','UinappHomeController@devicetype');//测试添加页面选择数组数据
}); });
// Fake APIs
Route::get('/table/list', function () {
$rowsNumber = mt_rand(20, 30);
$data = [];
for ($rowIndex = 0; $rowIndex < $rowsNumber; $rowIndex++) {
$row = [
'author' => Faker::randomString(mt_rand(5, 10)),
'display_time' => Faker::randomDateTime()->format('Y-m-d H:i:s'),
'id' => mt_rand(100000, 100000000),
'pageviews' => mt_rand(100, 10000),
'status' => Faker::randomInArray(['deleted', 'published', 'draft']),
'title' => Faker::randomString(mt_rand(20, 50)),
];
$data[] = $row;
}
return response()->json(new JsonResponse(['items' => $data]));
});
Route::get('/orders', function () {
$rowsNumber = 8;
$data = [];
for ($rowIndex = 0; $rowIndex < $rowsNumber; $rowIndex++) {
$row = [
'order_no' => 'LARAVUE' . mt_rand(1000000, 9999999),
'price' => mt_rand(10000, 999999),
'status' => Faker::randomInArray(['success', 'pending']),
];
$data[] = $row;
}
return response()->json(new JsonResponse(['items' => $data]));
});
Route::get('/articles', function () {
$rowsNumber = 10;
$data = [];
for ($rowIndex = 0; $rowIndex < $rowsNumber; $rowIndex++) {
$row = [
'id' => mt_rand(100, 10000),
'display_time' => Faker::randomDateTime()->format('Y-m-d H:i:s'),
'title' => Faker::randomString(mt_rand(20, 50)),
'author' => Faker::randomString(mt_rand(5, 10)),
'comment_disabled' => Faker::randomBoolean(),
'content' => Faker::randomString(mt_rand(100, 300)),
'content_short' => Faker::randomString(mt_rand(30, 50)),
'status' => Faker::randomInArray(['deleted', 'published', 'draft']),
'forecast' => mt_rand(100, 9999) / 100,
'image_uri' => 'https://via.placeholder.com/400x300',
'importance' => mt_rand(1, 3),
'pageviews' => mt_rand(10000, 999999),
'reviewer' => Faker::randomString(mt_rand(5, 10)),
'timestamp' => Faker::randomDateTime()->getTimestamp(),
'type' => Faker::randomInArray(['US', 'VI', 'JA']),
];
$data[] = $row;
}
return response()->json(new JsonResponse(['items' => $data, 'total' => mt_rand(1000, 10000)]));
});
Route::get('articles/{id}', function ($id) {
$article = [
'id' => $id,
'display_time' => Faker::randomDateTime()->format('Y-m-d H:i:s'),
'title' => Faker::randomString(mt_rand(20, 50)),
'author' => Faker::randomString(mt_rand(5, 10)),
'comment_disabled' => Faker::randomBoolean(),
'content' => Faker::randomString(mt_rand(100, 300)),
'content_short' => Faker::randomString(mt_rand(30, 50)),
'status' => Faker::randomInArray(['deleted', 'published', 'draft']),
'forecast' => mt_rand(100, 9999) / 100,
'image_uri' => 'https://via.placeholder.com/400x300',
'importance' => mt_rand(1, 3),
'pageviews' => mt_rand(10000, 999999),
'reviewer' => Faker::randomString(mt_rand(5, 10)),
'timestamp' => Faker::randomDateTime()->getTimestamp(),
'type' => Faker::randomInArray(['US', 'VI', 'JA']),
];
return response()->json(new JsonResponse($article));
});
Route::get('articles/{id}/pageviews', function ($id) {
$pageviews = [
'PC' => mt_rand(10000, 999999),
'Mobile' => mt_rand(10000, 999999),
'iOS' => mt_rand(10000, 999999),
'android' => mt_rand(10000, 999999),
];
$data = [];
foreach ($pageviews as $device => $pageview) {
$data[] = [
'key' => $device,
'pv' => $pageview,
];
}
return response()->json(new JsonResponse(['pvData' => $data]));
});
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