model = new AssetModel(); } public function index() : void { if ($this->request->param('select')) { $this->select(); } list($where, $alias, $limit) = $this->queryBuilder(); $res = $this->model ->field('asset_name,is_open_assetGroup') ->withJoin($this->withJoinTable, $this->withJoinType) ->alias($alias) ->where($where) ->group('asset_name,is_open_assetGroup') ->paginate($limit); $this->success('', [ 'list' => $res->items(), 'total' => $res->total(), 'remark' => get_route_remark(), ]); } public function edit(): void { if ($this->request->isPost()) { $data = $this->request->post(); if (!$data) { $this->error(__('Parameter %s can not be empty', [''])); } $data = $this->excludeFields($data); $result = false; $this->model->startTrans(); try { $asset_name = $data['asset_name']; $is_open_assetGroup = $data['is_open_assetGroup']; $result = Db::query("update yx_asset set is_open_assetGroup = $is_open_assetGroup where asset_name = '$asset_name'"); $this->model->commit(); } catch (Throwable $e) { $this->model->rollback(); $this->error($e->getMessage()); } if ($result !== false) { $this->success(__('Update successful')); } else { $this->error(__('No rows updated')); } } } /** * 缓存仪器类型 * @return void */ // public function getDataSelect(): void // { // $cacheKey = 'DataSelect'; // 缓存键名 // // 检查缓存是否存在 // if (Cache::has($cacheKey)) { // // 从缓存中获取数据 // $dataSelect = Cache::get($cacheKey); // } else { // // 缓存不存在,执行查询操作 // $dataSelect = $this->dataSelect(); // // // 将数据存入缓存,并设置过期时间 // Cache::set($cacheKey, $dataSelect, 3600); // 缓存有效期为1小时 // } // $this->success('ok', $dataSelect); // } //获取仪器类型查重 public function getDataSelect() { // $data = Db::name('asset')->field('asset_name, origin')->select(); // $uniqueArray = []; // $id=0; // foreach ($data as $row) { // $asset_name = $row['asset_name']; // $origin = $row['origin']; // if (!in_array($asset_name, $uniqueArray)) { // $uniqueArray[] = $asset_name; // $uniquedata[$id]['value'] = $asset_name; // $uniquedata[$id]['origin'] = $origin; // $id++; // } // } // $result = Db::query("SELECT // asset_name AS value // FROM // yx_asset // where is_open_assetGroup = 1 // AND asset_name NOT LIKE '%无人机%' // AND asset_name NOT LIKE '%rtk%' // AND asset_name NOT LIKE '%gnss%' // AND asset_name NOT LIKE '%全站仪%' // AND asset_name NOT LIKE '%水准仪%' // GROUP BY // asset_name"); // array_unshift($result,["value" =>"无人机"]); // array_unshift($result,["value" =>"RTK"]); // array_unshift($result,["value" =>"全站仪"]); // array_unshift($result,["value" =>"水准仪"]); // $this->success('ok', $result); $result = Db::query("SELECT asset_name AS value FROM yx_asset where is_open_assetGroup = 1 GROUP BY asset_name"); $this->success('ok', $result); // return $result; } }