Platform.php 1.8 KB

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