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.

97 lines
2.5 KiB

7 years ago
4 years ago
7 years ago
7 years ago
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use Illuminate\Support\Facades\Log;
  4. use Illuminate\Support\Facades\DB;
  5. use Illuminate\Http\Request;
  6. use App\Common\ReturnData;
  7. use App\Common\Helper;
  8. use App\Common\Token;
  9. use App\Http\Model\Page;
  10. use App\Http\Logic\PageLogic;
  11. class PageController extends BaseController
  12. {
  13. public function __construct()
  14. {
  15. parent::__construct();
  16. }
  17. public function getLogic()
  18. {
  19. return logic('Page');
  20. }
  21. public function pageList(Request $request)
  22. {
  23. //参数
  24. $limit = $request->input('limit', 10);
  25. $offset = $request->input('offset', 0);
  26. $res = $this->getLogic()->getList('', array('listorder', 'asc'), '*', $offset, $limit);
  27. if($res['count']>0)
  28. {
  29. foreach($res['list'] as $k=>$v)
  30. {
  31. $res['list'][$k]->page_detail_url = route('weixin_singlepage',array('id'=>$v->filename));
  32. }
  33. }
  34. return ReturnData::create(ReturnData::SUCCESS,$res);
  35. }
  36. public function pageDetail(Request $request)
  37. {
  38. //参数
  39. if(!checkIsNumber($request->input('id',null))){return ReturnData::create(ReturnData::PARAMS_ERROR);}
  40. $id = $request->input('id');
  41. $where['id'] = $id;
  42. $res = $this->getLogic()->getOne($where);
  43. if(!$res)
  44. {
  45. return ReturnData::create(ReturnData::RECORD_NOT_EXIST);
  46. }
  47. return ReturnData::create(ReturnData::SUCCESS,$res);
  48. }
  49. //添加
  50. public function pageAdd(Request $request)
  51. {
  52. if(Helper::isPostRequest())
  53. {
  54. return $this->getLogic()->add($_POST);
  55. }
  56. }
  57. //修改
  58. public function pageUpdate(Request $request)
  59. {
  60. if(!checkIsNumber($request->input('id',null))){return ReturnData::create(ReturnData::PARAMS_ERROR);}
  61. $id = $request->input('id');
  62. if(Helper::isPostRequest())
  63. {
  64. unset($_POST['id']);
  65. $where['id'] = $id;
  66. //$where['user_id'] = Token::$uid;
  67. return $this->getLogic()->edit($_POST,$where);
  68. }
  69. }
  70. //删除
  71. public function pageDelete(Request $request)
  72. {
  73. if(!checkIsNumber($request->input('id',null))){return ReturnData::create(ReturnData::PARAMS_ERROR);}
  74. $id = $request->input('id');
  75. if(Helper::isPostRequest())
  76. {
  77. $where['id'] = $id;
  78. //$where['user_id'] = Token::$uid;
  79. return $this->getLogic()->del($where);
  80. }
  81. }
  82. }