123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- <?php
- namespace app\admin\controller\asset;
- use app\admin\model\Asset;
- use app\admin\model\Asset as AssetModel;
- use ba\Random;
- use Throwable;
- use think\facade\Db;
- use app\common\controller\Backend;
- use think\facade\Cache;
- use app\common\controller\QrcodeComponent;
- class AssetInformation extends Backend
- {
- /**
- * 模型
- * @var object
- * @phpstan-var AdminModel
- */
- protected object $model;
- protected array|string $quickSearchField = ['asset_name'];
- public function initialize(): void
- {
- parent::initialize();
- $this->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;
- }
-
- }
|