Platform.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. }
  14. // 列表页
  15. public function index()
  16. {
  17. if ($this->request->isAjax()) {
  18. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  19. $total = $this->model
  20. ->where($where)
  21. ->order($sort, $order)
  22. ->count();
  23. $list = $this->model
  24. ->where($where)
  25. ->order($sort, $order)
  26. ->limit($offset, $limit)
  27. ->select();
  28. $result = [
  29. "total" => $total,
  30. "rows" => $list,
  31. ];
  32. return json($result);
  33. }
  34. return $this->view->fetch();
  35. }
  36. // 添加/编辑
  37. public function add()
  38. {
  39. if ($this->request->isPost()) {
  40. $params = $this->request->post("row/a");
  41. if ($params) {
  42. $params['createtime'] = time(); // 自动填充时间戳
  43. $result = $this->model->save($params);
  44. if ($result) {
  45. $this->success();
  46. } else {
  47. $this->error(__('Operation failed'));
  48. }
  49. }
  50. $this->error(__('Parameter %s can not be empty', ''));
  51. }
  52. return $this->view->fetch();
  53. }
  54. // 删除
  55. public function del($ids = "")
  56. {
  57. if ($ids) {
  58. $this->model->destroy($ids);
  59. $this->success();
  60. }
  61. $this->error(__('Parameter %s can not be empty', 'ids'));
  62. }
  63. }