123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <?php
- /**
- * @Created by PhpStorm
- * @author: Kirin
- * @day: 2024/11/19
- * @time: 12:48
- */
- namespace app\controller\api;
- use app\common\ApiBaseController;
- use app\services\system\CityAreaServices;
- use app\services\system\attachment\SystemAttachmentServices;
- use Psr\SimpleCache\InvalidArgumentException;
- use qiniu\services\CacheService;
- use qiniu\services\UploadService;
- use think\db\exception\DataNotFoundException;
- use think\db\exception\DbException;
- use think\db\exception\ModelNotFoundException;
- class Pub extends ApiBaseController
- {
- /**
- * 获取版本信息
- * @return mixed
- */
- public function version()
- {
- $version = sys_config('app_version', '');
- $apk = sys_config('app_apk', '');
- return $this->success(compact('version', 'apk'));
- }
- /**
- * 图片上传
- * @param SystemAttachmentServices $services
- * @return mixed
- * @throws InvalidArgumentException
- */
- public function upload_image(SystemAttachmentServices $services)
- {
- $request = $this->request;
- $data = $request->postMore([
- ['filename', 'file'],
- ]);
- if (!$data['filename']) return $this->error('参数有误');
- if (CacheService::has('start_uploads_' . $request->uid()) && CacheService::get('start_uploads_' . $request->uid()) >= 100) return $this->error('非法操作');
- $upload = UploadService::init();
- $info = $upload->to('store/comment')->validate()->move($data['filename']);
- if ($info === false) {
- return $this->error($upload->getError());
- }
- $res = $upload->getUploadInfo();
- $services->attachmentAdd($res['name'], $res['size'], $res['type'], $res['dir'], $res['thumb_path'], 1, (int)sys_config('upload_type', 1), $res['time'], 3);
- if (CacheService::has('start_uploads_' . $request->uid()))
- $start_uploads = (int)CacheService::get('start_uploads_' . $request->uid());
- else
- $start_uploads = 0;
- $start_uploads++;
- CacheService::set('start_uploads_' . $request->uid(), $start_uploads, 86400);
- $res['dir'] = path_to_url($res['dir']);
- if (strpos($res['dir'], 'http') === false) $res['dir'] = sys_config('site_url') . $res['dir'];
- return $this->success('图片上传成功!', ['name' => $res['name'], 'url' => $res['dir']]);
- }
- /**
- * 获取城市
- * @param CityAreaServices $services
- * @return mixed
- * @throws DataNotFoundException
- * @throws DbException
- * @throws ModelNotFoundException
- */
- public function city(CityAreaServices $services)
- {
- $pid = $this->request->get('pid', 0);
- $type = $this->request->get('type', 0);
- return $this->success($services->getCityTreeList((int)$pid, (int)$type));
- }
- /**
- * 解析(获取导入微信地址)
- * @param CityAreaServices $services
- * @return mixed
- * @throws DataNotFoundException
- * @throws DbException
- * @throws ModelNotFoundException
- */
- public function cityList(CityAreaServices $services)
- {
- $address = $this->request->param('address', '');
- if (!$address)
- return app('json')->fail('地址不存在');
- $city = $services->searchCity(compact('address'));
- if (!$city) return app('json')->fail('地址暂未录入,请联系管理员');
- $where = [['id', 'in', array_merge([$city['id']], explode('/', trim($city->path, '/')))]];
- return app('json')->success($services->getCityList($where, 'id as value,id,name as label,parent_id as pid', ['children']));
- }
- }
|