Platform.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace app\admin\controller\platform;
  3. use app\common\controller\Backend;
  4. class Platform extends Backend
  5. {
  6. // 模型对象
  7. protected $model = null;
  8. public function _initialize()
  9. {
  10. parent::_initialize();
  11. // $this->model = new \app\admin\model\third\Platform;
  12. // $this->model = model('Platform');
  13. $this->model = model('app\common\model\Platform');
  14. }
  15. // 列表页
  16. public function index()
  17. {
  18. if ($this->request->isAjax()) {
  19. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  20. $total = $this->model
  21. ->where($where)
  22. ->order($sort, $order)
  23. ->count();
  24. $list = $this->model
  25. ->where($where)
  26. ->order($sort, $order)
  27. ->limit($offset, $limit)
  28. ->select();
  29. $result = [
  30. "total" => $total,
  31. "rows" => $list,
  32. ];
  33. return json($result);
  34. }
  35. return $this->view->fetch();
  36. }
  37. // 添加/编辑
  38. public function add()
  39. {
  40. if ($this->request->isPost()) {
  41. $params = $this->request->post("row/a");
  42. if ($params) {
  43. $params['createtime'] = time(); // 自动填充时间戳
  44. $result = $this->model->save($params);
  45. if ($result) {
  46. $this->success();
  47. } else {
  48. $this->error(__('Operation failed'));
  49. }
  50. }
  51. $this->error(__('Parameter %s can not be empty', ''));
  52. }
  53. return $this->view->fetch();
  54. }
  55. // 删除
  56. public function del($ids = "")
  57. {
  58. if ($ids) {
  59. $this->model->destroy($ids);
  60. $this->success();
  61. }
  62. $this->error(__('Parameter %s can not be empty', 'ids'));
  63. }
  64. }