| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 | 
							- <?php
 
- namespace app\admin\controller\device;
 
- use app\admin\validate\device\DeviceValidate;
 
- use app\controller\Curd;
 
- use app\model\Device;
 
- use app\model\SysSerial;
 
- use support\Request;
 
- use support\Response;
 
- class DeviceController extends Curd
 
- {
 
-     public function __construct()
 
-     {
 
-         $this->model = new Device();
 
-         $this->validate = true;
 
-         $this->validateClass = new DeviceValidate();
 
-     }
 
-     public function select(Request $request): Response
 
-     {
 
-         [$where, $format, $limit, $field, $order] = $this->selectInput($request);
 
-         $order = $request->get('order', 'desc');
 
-         $field = $field ?? 'device_addtimes';
 
-         $query = $this->doSelect($where, $field, $order);
 
-         return $this->doFormat($query, $format, $limit);
 
-     }
 
-     /* 设备列表(下拉选项)*/
 
-     public function selectList()
 
-     {
 
-         $class = get_class($this->model);
 
-         $data = $class::where('device_status', 'ACTIVED')
 
-             ->select('device_id', 'device_name','device_identify')
 
-             ->get()
 
-             ->toArray();
 
-         return json_success('', $data);
 
-     }
 
-     protected function insertInput(Request $request): array
 
-     {
 
-         $data = $this->inputFilter($request->post());
 
-         $data['device_id'] = $this->generateDeviceId();
 
-         return $data;
 
-     }
 
-     /**
 
-      * @Desc 生成设备ID
 
-      * @Author Gorden
 
-      * @Date 2024/3/26 13:32
 
-      *
 
-      * @return string
 
-      * @throws \support\exception\BusinessException
 
-      */
 
-     private function generateDeviceId()
 
-     {
 
-         $id = SysSerial::getSerial();
 
-         return "DE".str_pad($id,16,'0',STR_PAD_LEFT).random_string(8);
 
-     }
 
- }
 
 
  |