AssetInformation.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. namespace app\admin\controller\asset;
  3. use app\admin\model\Asset;
  4. use app\admin\model\Asset as AssetModel;
  5. use ba\Random;
  6. use Throwable;
  7. use think\facade\Db;
  8. use app\common\controller\Backend;
  9. use think\facade\Cache;
  10. use app\common\controller\QrcodeComponent;
  11. class AssetInformation extends Backend
  12. {
  13. /**
  14. * 模型
  15. * @var object
  16. * @phpstan-var AdminModel
  17. */
  18. protected object $model;
  19. protected array|string $quickSearchField = ['asset_name'];
  20. public function initialize(): void
  21. {
  22. parent::initialize();
  23. $this->model = new AssetModel();
  24. }
  25. public function index() : void
  26. {
  27. if ($this->request->param('select')) {
  28. $this->select();
  29. }
  30. list($where, $alias, $limit) = $this->queryBuilder();
  31. $res = $this->model
  32. ->field('asset_name,is_open_assetGroup')
  33. ->withJoin($this->withJoinTable, $this->withJoinType)
  34. ->alias($alias)
  35. ->where($where)
  36. ->group('asset_name,is_open_assetGroup')
  37. ->paginate($limit);
  38. $this->success('', [
  39. 'list' => $res->items(),
  40. 'total' => $res->total(),
  41. 'remark' => get_route_remark(),
  42. ]);
  43. }
  44. public function edit(): void
  45. {
  46. if ($this->request->isPost()) {
  47. $data = $this->request->post();
  48. if (!$data) {
  49. $this->error(__('Parameter %s can not be empty', ['']));
  50. }
  51. $data = $this->excludeFields($data);
  52. $result = false;
  53. $this->model->startTrans();
  54. try {
  55. $asset_name = $data['asset_name'];
  56. $is_open_assetGroup = $data['is_open_assetGroup'];
  57. $result = Db::query("update yx_asset set is_open_assetGroup = $is_open_assetGroup where asset_name = '$asset_name'");
  58. $this->model->commit();
  59. } catch (Throwable $e) {
  60. $this->model->rollback();
  61. $this->error($e->getMessage());
  62. }
  63. if ($result !== false) {
  64. $this->success(__('Update successful'));
  65. } else {
  66. $this->error(__('No rows updated'));
  67. }
  68. }
  69. }
  70. /**
  71. * 缓存仪器类型
  72. * @return void
  73. */
  74. // public function getDataSelect(): void
  75. // {
  76. // $cacheKey = 'DataSelect'; // 缓存键名
  77. // // 检查缓存是否存在
  78. // if (Cache::has($cacheKey)) {
  79. // // 从缓存中获取数据
  80. // $dataSelect = Cache::get($cacheKey);
  81. // } else {
  82. // // 缓存不存在,执行查询操作
  83. // $dataSelect = $this->dataSelect();
  84. //
  85. // // 将数据存入缓存,并设置过期时间
  86. // Cache::set($cacheKey, $dataSelect, 3600); // 缓存有效期为1小时
  87. // }
  88. // $this->success('ok', $dataSelect);
  89. // }
  90. //获取仪器类型查重
  91. public function getDataSelect()
  92. {
  93. // $data = Db::name('asset')->field('asset_name, origin')->select();
  94. // $uniqueArray = [];
  95. // $id=0;
  96. // foreach ($data as $row) {
  97. // $asset_name = $row['asset_name'];
  98. // $origin = $row['origin'];
  99. // if (!in_array($asset_name, $uniqueArray)) {
  100. // $uniqueArray[] = $asset_name;
  101. // $uniquedata[$id]['value'] = $asset_name;
  102. // $uniquedata[$id]['origin'] = $origin;
  103. // $id++;
  104. // }
  105. // }
  106. // $result = Db::query("SELECT
  107. // asset_name AS value
  108. // FROM
  109. // yx_asset
  110. // where is_open_assetGroup = 1
  111. // AND asset_name NOT LIKE '%无人机%'
  112. // AND asset_name NOT LIKE '%rtk%'
  113. // AND asset_name NOT LIKE '%gnss%'
  114. // AND asset_name NOT LIKE '%全站仪%'
  115. // AND asset_name NOT LIKE '%水准仪%'
  116. // GROUP BY
  117. // asset_name");
  118. // array_unshift($result,["value" =>"无人机"]);
  119. // array_unshift($result,["value" =>"RTK"]);
  120. // array_unshift($result,["value" =>"全站仪"]);
  121. // array_unshift($result,["value" =>"水准仪"]);
  122. // $this->success('ok', $result);
  123. $result = Db::query("SELECT
  124. asset_name AS value
  125. FROM
  126. yx_asset
  127. where is_open_assetGroup = 1
  128. GROUP BY
  129. asset_name");
  130. $this->success('ok', $result);
  131. // return $result;
  132. }
  133. }