You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
2.7 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use Illuminate\Http\Request;
  4. use App\Common\ReturnData;
  5. use App\Common\Helper;
  6. use App\Http\Model\Slide;
  7. use App\Http\Logic\SlideLogic;
  8. class SlideController extends CommonController
  9. {
  10. public function __construct()
  11. {
  12. parent::__construct();
  13. }
  14. public function getLogic()
  15. {
  16. return new SlideLogic();
  17. }
  18. public function slideList(Request $request)
  19. {
  20. //参数
  21. $where = array();
  22. $limit = $request->input('limit', 10);
  23. $offset = $request->input('offset', 0);
  24. if($request->input('group_id', null) !== null){$where['group_id'] = $request->input('group_id');}
  25. if($request->input('type', null) !== null){$where['type'] = $request->input('type');}
  26. $res = $this->getLogic()->getList($where, array('id', 'desc'), '*', $offset, $limit);
  27. if($res == false)
  28. {
  29. return ReturnData::create(ReturnData::SYSTEM_FAIL);
  30. }
  31. foreach($res['list'] as $k=>$v)
  32. {
  33. if(!empty($res['list'][$k]->pic)){$res['list'][$k]->pic = http_host().$v->pic;}
  34. }
  35. return ReturnData::create(ReturnData::SUCCESS,$res);
  36. }
  37. //详情
  38. public function slideDetail(Request $request)
  39. {
  40. //参数
  41. if(!checkIsNumber($request->input('id', null))){return ReturnData::create(ReturnData::PARAMS_ERROR);}
  42. $res = $this->getLogic()->getOne($where);
  43. if(!$res){return ReturnData::create(ReturnData::PARAMS_ERROR);}
  44. if(!empty($res->pic)){$res->pic = http_host().$res->pic;}
  45. return ReturnData::create(ReturnData::SUCCESS,$res);
  46. }
  47. //添加
  48. public function slideAdd(Request $request)
  49. {
  50. if(Helper::isPostRequest())
  51. {
  52. $res = $this->getLogic()->add($_POST);
  53. return $res;
  54. }
  55. }
  56. //修改
  57. public function slideUpdate(Request $request)
  58. {
  59. if(!checkIsNumber($request->input('id', null))){return ReturnData::create(ReturnData::PARAMS_ERROR);}
  60. if(Helper::isPostRequest())
  61. {
  62. unset($_POST['id']);
  63. $where['id'] = $id;
  64. $res = $this->getLogic()->edit($_POST,$where);
  65. return $res;
  66. }
  67. }
  68. //删除
  69. public function slideDelete(Request $request)
  70. {
  71. if(!checkIsNumber($request->input('id', null))){return ReturnData::create(ReturnData::PARAMS_ERROR);}
  72. if(Helper::isPostRequest())
  73. {
  74. unset($_POST['id']);
  75. $where['id'] = $id;
  76. $res = $this->getLogic()->del($where);
  77. return $res;
  78. }
  79. }
  80. }