Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
L
laravelzh
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
冯超鹏
laravelzh
Commits
3b92c396
Commit
3b92c396
authored
Dec 15, 2020
by
Administrator
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
工单接口
parent
b8bbed4a
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
75 additions
and
22 deletions
+75
-22
AlarmOrderController.php
app/Http/Controllers/AlarmOrderController.php
+60
-21
AlarmOrder.php
app/Models/AlarmOrder.php
+2
-0
AlarmOrderSchedule.php
app/Models/AlarmOrderSchedule.php
+12
-0
app.php
config/app.php
+1
-1
No files found.
app/Http/Controllers/AlarmOrderController.php
View file @
3b92c396
...
...
@@ -2,6 +2,8 @@
namespace
App\Http\Controllers
;
use
Carbon\Carbon
;
use
Illuminate\Database\QueryException
;
use
Illuminate\Http\Request
;
use
App\Models\AlarmOrder
;
use
Illuminate\Support\Facades\DB
;
...
...
@@ -19,8 +21,17 @@ class AlarmOrderController extends Controller
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'
)
$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,
d.devicecoord, d.username,
u.name, u.phone_number
'
)
->
leftjoin
(
'reportpolice AS r'
,
'r.id'
,
'='
,
'alarm_order.reportpolice_id'
)
->
leftjoin
(
'device AS d'
,
'd.id'
,
'='
,
'alarm_order.device_id'
)
->
leftjoin
(
'users AS u'
,
'alarm_order.user_id'
,
'='
,
'u.id'
)
->
offset
(
$offset
)
->
limit
(
$limit
)
->
get
()
->
toArray
();
...
...
@@ -45,18 +56,27 @@ class AlarmOrderController extends Controller
substr
(
$request
->
input
(
'device_num'
),
-
4
)
.
$request
->
input
(
'policestatus'
)
.
$request
->
input
(
'shutoff_status'
);
DB
::
beginTransaction
();
try
{
$order
=
new
AlarmOrder
();
$insertId
=
$order
->
sharedLock
()
->
insertGetId
([
$insertId
=
$order
->
insertGetId
([
'order_num'
=>
$orderNum
,
'reportpolice_id'
=>
$reportpolice_id
,
'created_at'
=>
Carbon
::
now
(),
]);
// 进度表新增
$orderSchedule
=
new
AlarmOrderSchedule
();
$orderSchedule
->
lockForUpdate
();
$orderSchedule
->
alarm_order_id
=
$insertId
;
$orderSchedule
->
schedule
=
1
;
$orderSchedule
->
created_at
=
Carbon
::
now
();
$orderSchedule
->
save
();
DB
::
commit
();
}
catch
(
QueryException
$exception
)
{
DB
::
rollBack
();
return
$this
->
jsonErrorData
(
'工单创建失败'
);
}
if
(
$insertId
)
{
return
$this
->
jsonSuccessData
(
'已生成工单!'
);
...
...
@@ -89,12 +109,31 @@ class AlarmOrderController extends Controller
*/
public
function
update
(
Request
$request
,
$id
)
{
$data
=
$request
->
all
();
if
(
isset
(
$data
[
'schedule'
]))
{
DB
::
beginTransaction
();
try
{
AlarmOrderSchedule
::
insert
(
array_merge
(
$data
[
'schedule'
],
[
'created_at'
=>
Carbon
::
now
(),
'alarm_order_id'
=>
$id
]));
unset
(
$data
[
'schedule'
]);
$order
=
AlarmOrder
::
where
(
'id'
,
$id
)
->
update
(
$request
->
all
());
->
update
(
array_merge
(
$data
,
[
'updated_at'
=>
Carbon
::
now
()]));
DB
::
commit
();
}
catch
(
QueryException
$exception
)
{
DB
::
rollBack
();
return
$this
->
jsonErrorData
(
500
,
'工单更新失败!'
);
}
}
else
{
$order
=
AlarmOrder
::
where
(
'id'
,
$id
)
->
update
(
array_merge
(
$data
,
[
'updated_at'
=>
Carbon
::
now
()]));
}
if
(
$order
)
{
$this
->
jsonSuccessData
(
'工单更新成功'
);
return
$this
->
jsonSuccessData
(
'工单更新成功'
);
}
else
{
$this
->
jsonErrorData
(
500
,
'更新订单
失败!'
);
return
$this
->
jsonErrorData
(
500
,
'工单更新
失败!'
);
}
}
...
...
@@ -108,9 +147,9 @@ class AlarmOrderController extends Controller
{
$state
=
AlarmOrder
::
destroy
(
$id
);
if
(
$state
)
{
$this
->
jsonSuccessData
(
'删除成功'
);
return
$this
->
jsonSuccessData
(
'删除成功'
);
}
else
{
$this
->
jsonErrorData
(
500
,
'删除工单失败!'
);
return
$this
->
jsonErrorData
(
500
,
'删除工单失败!'
);
}
}
}
app/Models/AlarmOrder.php
View file @
3b92c396
...
...
@@ -8,6 +8,7 @@ use Illuminate\Support\Carbon;
class
AlarmOrder
extends
Model
{
protected
$table
=
'alarm_order'
;
public
$timestamps
=
false
;
// 获取报警记录
public
function
reportpolices
()
...
...
@@ -25,4 +26,5 @@ class AlarmOrder extends Model
return
Carbon
::
parse
(
$value
)
->
toDateTimeString
();
}
}
app/Models/AlarmOrderSchedule.php
View file @
3b92c396
...
...
@@ -3,8 +3,20 @@
namespace
App\Models
;
use
Illuminate\Database\Eloquent\Model
;
use
Illuminate\Support\Carbon
;
class
AlarmOrderSchedule
extends
Model
{
protected
$table
=
'alarm_order_schedule'
;
public
$timestamps
=
false
;
public
function
getCreatedAtAttribute
(
$value
)
{
return
Carbon
::
parse
(
$value
)
->
toDateTimeString
();
}
public
function
getUpdatedAtAttribute
(
$value
)
{
return
Carbon
::
parse
(
$value
)
->
toDateTimeString
();
}
}
config/app.php
View file @
3b92c396
...
...
@@ -67,7 +67,7 @@ return [
|
*/
'timezone'
=>
'
UT
C'
,
'timezone'
=>
'
PR
C'
,
/*
|--------------------------------------------------------------------------
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment