PlatformController.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace app\admin\controller;
  3. use think\exception\ValidateException;
  4. use app\model\Platform;
  5. class PlatformController extends Base
  6. {
  7. function index()
  8. {
  9. $keyword = input('post.keyword', '', 'serach_in');
  10. $query = new Platform;
  11. if (!empty($keyword)) {
  12. $query->where('title', 'like', '%' . $keyword . '%');
  13. }
  14. $res = $query->order('sort asc,id asc')
  15. ->paginate(getpage())
  16. ->toArray();
  17. foreach ($res['data'] as &$vo) {
  18. $vo['logo'] = toimg($vo['logo']);
  19. $vo['loginbgimg'] = toimg($vo['loginbgimg']);
  20. $vo['loginurl'] = gethost() . '/admin?i=' . $vo['id'];
  21. if ($vo['endtime']) {
  22. $vo['endtime'] = time_format($vo['endtime']);
  23. } else {
  24. $vo['endtime'] = '永久';
  25. }
  26. }
  27. $data['data'] = $res;
  28. return $this->json($data);
  29. }
  30. function listUpdate()
  31. {
  32. $data = only('id,status,sort');
  33. if (!$data['id']) throw new ValidateException('参数错误');
  34. Platform::update($data);
  35. return $this->json(['msg' => '操作成功']);
  36. }
  37. public function update()
  38. {
  39. $id = $this->request->post('id');
  40. $data = input('post.');
  41. unset($data['create_time']);
  42. if ($data['endtime']) {
  43. $data['endtime'] = strtotime($data['endtime']);
  44. } else {
  45. $data['endtime'] = (int) $data['endtime'];
  46. }
  47. if (empty($id)) {
  48. try {
  49. $res = Platform::create($data);
  50. } catch (\Exception $e) {
  51. throw new ValidateException($e->getMessage());
  52. }
  53. return $this->json(['msg' => '添加成功', 'data' => $res->id]);
  54. } else {
  55. try {
  56. Platform::update($data);
  57. } catch (\Exception $e) {
  58. throw new ValidateException($e->getMessage());
  59. }
  60. return $this->json(['msg' => '修改成功']);
  61. }
  62. }
  63. function getInfo()
  64. {
  65. $id = $this->request->post('id', '', 'serach_in');
  66. if (!$id) throw new ValidateException('参数错误');
  67. $data = Platform::getInfo($id);
  68. return $this->json(['data' => $data]);
  69. }
  70. function delete()
  71. {
  72. return $this->del(new Platform());
  73. }
  74. }