12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?php
- namespace app\admin\controller;
- use think\exception\ValidateException;
- use app\model\Platform;
- class PlatformController extends Base
- {
- function index()
- {
- $keyword = input('post.keyword', '', 'serach_in');
- $query = new Platform;
- if (!empty($keyword)) {
- $query->where('title', 'like', '%' . $keyword . '%');
- }
- $res = $query->order('sort asc,id asc')
- ->paginate(getpage())
- ->toArray();
- foreach ($res['data'] as &$vo) {
- $vo['logo'] = toimg($vo['logo']);
- $vo['loginbgimg'] = toimg($vo['loginbgimg']);
- $vo['loginurl'] = gethost() . '/admin?i=' . $vo['id'];
- if ($vo['endtime']) {
- $vo['endtime'] = time_format($vo['endtime']);
- } else {
- $vo['endtime'] = '永久';
- }
- }
- $data['data'] = $res;
- return $this->json($data);
- }
- function listUpdate()
- {
- $data = only('id,status,sort');
- if (!$data['id']) throw new ValidateException('参数错误');
- Platform::update($data);
- return $this->json(['msg' => '操作成功']);
- }
- public function update()
- {
- $id = $this->request->post('id');
- $data = input('post.');
- unset($data['create_time']);
- if ($data['endtime']) {
- $data['endtime'] = strtotime($data['endtime']);
- } else {
- $data['endtime'] = (int) $data['endtime'];
- }
- if (empty($id)) {
- try {
- $res = Platform::create($data);
- } catch (\Exception $e) {
- throw new ValidateException($e->getMessage());
- }
- return $this->json(['msg' => '添加成功', 'data' => $res->id]);
- } else {
- try {
- Platform::update($data);
- } catch (\Exception $e) {
- throw new ValidateException($e->getMessage());
- }
- return $this->json(['msg' => '修改成功']);
- }
- }
- function getInfo()
- {
- $id = $this->request->post('id', '', 'serach_in');
- if (!$id) throw new ValidateException('参数错误');
- $data = Platform::getInfo($id);
- return $this->json(['data' => $data]);
- }
- function delete()
- {
- return $this->del(new Platform());
- }
- }
|