12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- namespace app\common\middleware;
- use app\common\model\FacilityModel;
- use app\common\model\Sysusermodel;
- class checkfacility
- {
- public function handle($request, \Closure $next)
- {
- if (!request()->isPost()) {
- return backjson3(500, "请求错误");
- }
- $param = $request->post();
- $token = request()->header('token');
- $suinfo = $this->checktoken($token);
- if (empty($suinfo)) {
- return backjson3(401, "认证失败,无法访问系统资源");
- }
- $finfo = $this->checkfilleData($param);
- if (empty($finfo)) {
- return backjson3(500, "设备信息错误");
- }
- $request->finfo = $finfo;
- $request->suinfo = $suinfo;
- return $next($request);
- }
- /**
- * 校验必填字段
- *
- * @return void
- * @author wj
- * @date 2023-09-02
- */
- private function checkfilleData($param)
- {
- $fillfields = ['facility_id', 'device_id_code', 'command'];
- foreach ($fillfields as $key => $value) {
- if (!isset($param[$value]) || empty($param[$value])) {
- return false;
- }
- }
- $facility_id = $param['facility_id'];
- $device_id_code = $param['device_id_code'];
- $m_f = new FacilityModel();
- $where = ['id' => $facility_id, 'code' => $device_id_code];
- $finfo = $m_f->getInfo($where, ['id']);
- if (empty($finfo)) {
- return false;
- }
- return $finfo;
- }
- /**
- * 验证用户token
- *
- * @return void
- * @author wj
- * @date 2023-09-04
- */
- private function checktoken($token)
- {
- if (empty($token)) {
- return false;
- }
- $m_su = new Sysusermodel();
- $suinfo = $m_su->getinfobytoken($token);
- if (empty($suinfo)) {
- return false;
- }
- return $suinfo;
- }
- }
|