0
0

DailyForm.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. namespace app\admin\controller;
  3. use think\App;
  4. use think\Db;
  5. class DailyForm extends Auth {
  6. public function __construct(App $app = null) {
  7. parent::__construct($app);
  8. $this->model = new \app\common\model\DailyForm();
  9. }
  10. public function index() {
  11. if (request()->isAjax()) {
  12. //分页参数
  13. $length = input('rows', 10, 'intval'); //每页条数
  14. $page = input('page', 1, 'intval'); //第几页
  15. $start = ($page - 1) * $length; //分页开始位置
  16. //排序
  17. $sortRow = input('sidx', 'sort', 'trim'); //排序列
  18. $sort = input('sord', 'asc', 'trim'); //排序方式
  19. $order = $sortRow . ' ' . $sort . ' ,id desc';
  20. $title = input('content', '', 'trim');
  21. if ($title) {
  22. $map[] = ['content', 'like', '%' . $title . '%'];
  23. }
  24. $enable = input('enable', '', 'trim');
  25. if ($enable != '') {
  26. $map[] = ['enable', '=', $enable];
  27. }
  28. $map[] = ['org_id', '=', $this->orgId];
  29. $map[] = ['del', '=', 0];
  30. $map = empty($map) ? true : $map;
  31. //数据查询
  32. $lists = Db::name('daily_form')
  33. ->where($map)->limit($start, $length)->order($order)->select();
  34. //数据返回
  35. $totalCount = Db::name('daily_form')->where($map)->count();
  36. $totalPage = ceil($totalCount / $length);
  37. $result['page'] = $page;
  38. $result['total'] = $totalPage;
  39. $result['records'] = $totalCount;
  40. $result['rows'] = $lists;
  41. return json($result);
  42. }
  43. else {
  44. $this->assign('meta_title', '工作项列表');
  45. $this->assign('m_name', '工作项');
  46. return $this->fetch();
  47. }
  48. }
  49. /**
  50. * 新增/编辑
  51. */
  52. public function add($id = 0) {
  53. if (request()->isPost()) {
  54. $model = $this->model;
  55. $res = $model->updates();
  56. if ($res) {
  57. $this->success('操作成功', url('index'));
  58. }
  59. else {
  60. $this->error($model->getError());
  61. }
  62. }
  63. else {
  64. $meta_title = '新增工作项';
  65. if ($id) {
  66. $info = Db::name('daily_form')->where('id', $id)->find();
  67. $this->assign('info', $info);
  68. $meta_title = '编辑工作项';
  69. }
  70. $this->assign('meta_title', $meta_title);
  71. return $this->fetch();
  72. }
  73. }
  74. /**
  75. * 删除记录
  76. * @param int $id
  77. */
  78. public function del($id = 0) {
  79. if (!$id) {
  80. $this->error('参数错误');
  81. }
  82. $res = Db::name('daily_form')->where('id', $id)->update(['del' => 1]);
  83. if ($res) {
  84. $this->success('删除成功');
  85. }
  86. else {
  87. $this->error('删除失败');
  88. }
  89. }
  90. /**
  91. * 改变字段值
  92. * @param int $fv
  93. * @param string $fn
  94. * @param int $fv
  95. */
  96. public function changeField($id = 0, $fn = '', $fv = 0) {
  97. if (!$fn || !$id) {
  98. $this->error('参数错误');
  99. }
  100. $res = Db::name('daily_form')->where('id', $id)->update([$fn => $fv]);
  101. if ($res) {
  102. $this->success('操作成功');
  103. }
  104. else {
  105. $this->error('操作失败');
  106. }
  107. }
  108. }