DeviceController.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace app\admin\controller\device;
  3. use app\admin\validate\device\DeviceValidate;
  4. use app\controller\Curd;
  5. use app\model\Device;
  6. use app\model\SysSerial;
  7. use support\Request;
  8. use support\Response;
  9. class DeviceController extends Curd
  10. {
  11. public function __construct()
  12. {
  13. $this->model = new Device();
  14. $this->validate = true;
  15. $this->validateClass = new DeviceValidate();
  16. }
  17. public function select(Request $request): Response
  18. {
  19. [$where, $format, $limit, $field, $order] = $this->selectInput($request);
  20. $order = $request->get('order', 'desc');
  21. $field = $field ?? 'device_addtimes';
  22. $query = $this->doSelect($where, $field, $order);
  23. return $this->doFormat($query, $format, $limit);
  24. }
  25. protected function insertInput(Request $request): array
  26. {
  27. $data = $this->inputFilter($request->post());
  28. $data['device_id'] = $this->generateDeviceId();
  29. return $data;
  30. }
  31. /**
  32. * @Desc 生成设备ID
  33. * @Author Gorden
  34. * @Date 2024/3/26 13:32
  35. *
  36. * @return string
  37. * @throws \support\exception\BusinessException
  38. */
  39. private function generateDeviceId()
  40. {
  41. $id = SysSerial::getSerial();
  42. return "DE".str_pad($id,16,'0',STR_PAD_LEFT).random_string(8);
  43. }
  44. }