1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <?php
- namespace app\adminapi\controller\v1\course;
- use app\adminapi\controller\AuthController;
- use app\models\course\OrganModel;
- use crmeb\services\{UtilService as Util};
- use think\Request;
- class Organ extends AuthController
- {
- /**
- * 显示资源列表
- *
- * @return \think\Response
- */
- public function index()
- {
- $where = Util::getMore([
- ['page', 1],
- ['limit', 10]
- ], $this->request);
- $list = OrganModel::systemPage($where);
- return $this->success($list);
- }
- /**
- * 保存新建的资源
- *
- * @param \think\Request $request
- * @return \think\Response
- */
- public function save(Request $request)
- {
- $data = Util::postMore([
- ['id', 0],
- ['name', ''],
- ['image', ''],
- ['contact', ''],
- ['latlng', ''],
- ['intro', '']
- ]);
- $data['latlng'] = explode(',', $data['latlng']);
- if (!isset($data['latlng'][0]) || !isset($data['latlng'][1])) return $this->fail('请选择经纬度');
- $data['latitude'] = $data['latlng'][0];
- $data['longitude'] = $data['latlng'][1];
- unset($data['latlng']);
- $data['add_time'] = time();
- if ($data['id']) {
- $id = $data['id'];
- unset($data['id']);
- $res = OrganModel::edit($data, $id, 'id');
- if($res)
- return $this->success('修改成功!', ['id' => $id]);
- else
- return $this->fail('修改失败!');
- } else {
- $res = OrganModel::create($data);
- return $this->success('添加成功!', ['id' => $res->id]);
- }
- }
- /**
- * 显示指定的资源
- *
- * @param int $id
- * @return \think\Response
- */
- public function read($id)
- {
- $info = OrganModel::getOne($id);
- $info['latlng'] = $info['latitude'] . ',' . $info['longitude'];
- return $this->success(compact('info'));
- }
- /**
- * 删除指定资源
- *
- * @param int $id
- * @return \think\Response
- */
- public function delete($id)
- {
- if (!$id) return $this->fail('数据不存在');
- $res = OrganModel::get($id);
- if (!$res) return $this->fail('数据不存在!');
- if ($res['is_del']) return $this->fail('已删除!');
- $data['is_del'] = 1;
- if (OrganModel::edit($data, $id))
- return $this->success('删除成功!');
- else
- return $this->fail('删除失败,请稍候再试!');
- }
- }
|