123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- <?php
- namespace catchAdmin\alarm\controller;
- use catcher\base\CatchRequest as Request;
- use catcher\CatchResponse;
- use catcher\base\CatchController;
- use catchAdmin\alarm\model\AlarmRecords as alarmRecordsModel;
- use think\facade\Db;
- class AlarmRecords extends CatchController
- {
- protected $alarmRecordsModel;
-
- public function __construct(AlarmRecordsModel $alarmRecordsModel)
- {
- $this->alarmRecordsModel = $alarmRecordsModel;
- }
-
- /**
- * 列表
- * @time 2021年05月27日 11:20
- * @param Request $request
- */
- public function index(Request $request) : \think\Response
- {
- return CatchResponse::paginate($this->alarmRecordsModel->getList());
- }
-
- /**
- * 保存信息
- * @time 2021年05月27日 11:20
- * @param Request $request
- */
- public function save(Request $request) : \think\Response
- {
- return CatchResponse::success($this->alarmRecordsModel->storeBy($request->post()));
- }
-
- /**
- * 保存处理记录
- * @time 2021年05月27日 11:20
- * @param Request $request
- */
- public function handleAlarm(Request $request) : \think\Response
- {
- $params=$request->post();
- $params['end_time']=time();
- $params['state']='end';
- $params['handler_id']=$request->user()->id;
- $res=$this->alarmRecordsModel
- ->where('device_number',$params['device_number'])
- ->where('state','start')
- ->whereIn('alarm_reason',['press','fence_in','fence_out'])
- ->update($params);
- if($res){
- //2表示已出警'
- $count=$this->alarmRecordsModel
- ->where('device_number',$params['device_number'])
- ->where('state','start')
- ->where('alarm_reason','low_bat')
- ->count();
- if(!$count){
- Db::table('devices')->where('imei', $params['device_number'])->update(['alarm_state' => 0]);
- }
-
- }
- return CatchResponse::success($res);
- }
-
- /**
- * 读取
- * @time 2021年05月27日 11:20
- * @param $id
- */
- public function read($id) : \think\Response
- {
- return CatchResponse::success($this->alarmRecordsModel->findBy($id));
- }
-
- /**
- * 更新
- * @time 2021年05月27日 11:20
- * @param Request $request
- * @param $id
- */
- public function update(Request $request, $id) : \think\Response
- {
- $params=$request->post();
- $params['end_time']=time();
- $params['state']='end';
- $params['handler_id']=$request->user()->id;
- $res=$this->alarmRecordsModel->updateBy($id, $params);
- if($res){
- $device_number=$this->alarmRecordsModel->where('id', $id)->value('device_number');
- $where = ['device_number'=>$device_number,'state'=>'start'];
- $count=$this->alarmRecordsModel->where($where)->count();
- if(!$count){
- Db::table('devices')->where('imei', $device_number)->update(['alarm_state' => 0]);
- }
- }
-
- return CatchResponse::success($res);
- }
-
- /**
- * 删除
- * @time 2021年05月27日 11:20
- * @param $id
- */
- public function delete($id) : \think\Response
- {
- return CatchResponse::success($this->alarmRecordsModel->deleteBy($id));
- }
- }
|